#include BOARD_H
#define COUNTER counter0
#define CLKDIV 64
#define COUNTMODE up_loop
#define COMPARE compare0
#define TOP 0xFF
#define STRCMP(s1,s2) __builtin_strcmp(s1,s2)
HW_ISR( (COUNTER,irq,overflow) )
{
static uint8_t phase ;
if ( phase == 0 )
hw( write, (COUNTER,COMPARE), duty );
else if ( phase == 1 )
hw( write, (COUNTER,COMPARE), ~duty );
duty++ ;
if ( (duty & TOP) == 0 ) {
phase = (phase + 1) & 3 ;
if ( !STRCMP(
HW_Q(COUNTMODE),
"up_loop") ) {
if ( phase == 2 )
hw( configure, (COUNTER,COMPARE), output, disconnected );
else if ( phase == 0 )
hw( configure, (COUNTER,COMPARE), output, set_at_bottom_clear_after_match );
}
}
}
int main ( )
{
sleep, enabled,
sleep_mode, idle );
clock, ioclk / CLKDIV,
direction, COUNTMODE,
bottom, 0,
top, TOP );
if ( !STRCMP(
HW_Q(COUNTMODE),
"updown_loop") )
hwa( configure, (COUNTER,COMPARE),
output, clear_after_match_up_set_after_match_down );
else
hwa( configure, (COUNTER,COMPARE),
output, set_at_bottom_clear_after_match );
hwa( enable, (COUNTER,irq,overflow) );
hw( enable, interrupts );
for(;;)
}