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)");

      }

   }

}





First, in our design, we have:

One "count input" input1_task

One "key input" input2_task

A 3-state FSM: s0 / s1 / s2

Two output tasks

The goal is to demonstrate:

How the two input events drive the state transition

How the output tasks perform actions based on the state machine messages
this is the result screenshoot:



In the demo:

One button input task

One ADC input task

One 5-state FSM: STATE_STARTUP / STATE_1 / STATE_2 / STATE_3 / STATE_4

Two output tasks

Each task is monitored using an LCD.

Key demonstrations:

Message passing between RTOS tasks

Sequential cyclic state machine transitions.

this is the result screenshoot:


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.


Another difference is that we also use kernel in our code, which allows us to disable input2 by entering a command.










Comments

Popular posts from this blog

Blog 1 - Igor Kapusniak