unsigned int threadb ( unsigned int event ) { static unsigned int send_char; static unsigned int char_to_send; static unsigned int led_state; static unsigned int timer_count; switch(event) { case INIT: { send_char=1; char_to_send=MY_CHAR; led_state=0; change_led_state(MY_LED,led_state); return(0); } case LOOP: { if(send_char) { if(uart_tx_if_ready(char_to_send)) send_char=0; } return(0); } case TIMER: { send_char=1; char_to_send=MY_CHAR; timer_count=4; return(0); } case HEARTBEAT: { if(timer_count) { timer_count--; led_state=(led_state+1)&1; change_led_state(MY_LED,led_state); } return(0); } default: { break; } } return(0); }
unsigned int threada ( unsigned int event ) { unsigned int nowtick; unsigned int tickdiff; switch(event) { case INIT: { ta_send_char=1; ta_char_to_send=0x31; ta_tick_last=get_timer_tick(); ta_led_state=0; change_led_state(0,ta_led_state); return(0); } case HEARTBEAT: { if(ta_send_char) { if(uart_tx_if_ready(ta_char_to_send)) ta_send_char=0; } nowtick=get_timer_tick(); tickdiff=(nowtick-ta_tick_last)&TIMER_TICK_MASK; if(tickdiff>=10000000) { ta_tick_last=(ta_tick_last+10000000)&TIMER_TICK_MASK; ta_send_char=1; //ta_char_to_send= ta_led_state=(ta_led_state+1)&1; change_led_state(0,ta_led_state); } return(0); } default: { break; } } return(0); }
unsigned int threadd ( unsigned int event ) { static unsigned int led_state; static unsigned int timer_count; switch(event) { case INIT: { led_state=0; change_led_state(MY_LED,led_state); return(0); } case LOOP: { return(0); } case TIMER: { timer_count=4; return(0); } case HEARTBEAT: { if(timer_count) { timer_count--; led_state=(led_state+1)&1; change_led_state(MY_LED,led_state); } return(0); } default: { break; } } return(0); }
unsigned int threadb ( unsigned int event ) { unsigned int nowtick; switch(event) { case INIT: { tb_send_char=1; tb_char_to_send=0x32; tb_tick_last=get_timer_tick(); tb_led_state=0; change_led_state(1,tb_led_state); return(0); } case HEARTBEAT: { if(tb_send_char) { if(uart_tx_if_ready(tb_char_to_send)) tb_send_char=0; } nowtick=get_timer_tick(); if((nowtick-tb_tick_last)>=5000000) { tb_tick_last+=5000000; tb_send_char=1; //tb_char_to_send= tb_led_state=(tb_led_state+1)&1; change_led_state(1,tb_led_state); } return(0); } default: { break; } } return(0); }
__interrupt void toggle(void) { P1IE &= ~BTN; // Disable IRQ to avoid bouncing P1IFG &= ~BTN; // Clear Interrupt // only toggle if button wasn't pressed if (!last_btn_state) { change_led_state(); } // disable irq and enable after timeout start_timer(); }