BLOG3 RTOS Tao Wang
First find a probelm,because first i thought there should be a sequence, transitioning between the three states: S0 (LED ON cnt=10), S1 (LED OFF button pressed), S2 (LED ON cnt = 10). However, I later felt this was unreasonable; there should only be one state for LED ON.
Therefore, we changed the state diagram so that the program can directly reach S1 LED ON or S2 LED OFF at the beginning, as long as their triggering conditions are met. Therefore, I removed the order constraint (armd) in the output task.
so,this is first version for output_task1,task2:
// ---------------- output1: receive "output1" ----------------
void output_task1() {
if(rtos_msg_poll()) {
int16 m = rtos_msg_read();
if(m == 1) {
armed = 1;
lcd_gotoxy(1,2);
printf(lcd_putc, "LED ON (cnt=10)");
}
}
}
// ---------------- output2: receive "output2"----------------
void output_task2() {
if(rtos_msg_poll()) {
int16 m = rtos_msg_read();
if(armed && m == 2) {
armed = 0;
lcd_gotoxy(1,1);
printf(lcd_putc, "LED OFF (button)");
}
}
}
And i just delet the armd,let it can from begin to S1,S2.this is new version:
void output_task1(){
if(rtos_msg_poll()>0){
if(rtos_msg_read() == output1){
lcd_gotoxy(1,2);
printf(lcd_putc, "LED ON (cnt=10)");
}
}
}
void output_task2(){
if(rtos_msg_poll()>0){
if(rtos_msg_read() == output2) {
lcd_gotoxy(1,2);
printf(lcd_putc, "LED OFF (button pressed)");
}
}
}
However, these two code snippets do share similarities. The main difference is that both define several input_tasks and output_tasks, and both use an FSM (Functional State Machine) to handle the state transitions of these input_tasks and output_tasks. However, I feel the difference lies in how our code's state machine transitions between states based on different triggering conditions, while the demo's state machine advances states sequentially.
Comments
Post a Comment