Advertisement
RobertBerger

FreeRTOS task2

Apr 27th, 2022
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. /* traffic light FSM */
  2. #if 1
  3. void vTask2(void *pvParameters) {
  4. const char *pcTaskName = "Task 2 is running\n";
  5. int *pxPedestrianMessage;
  6. int pedestrianVal;
  7. current_state = STATE_0;
  8.  
  9. /* As per most tasks, this task is implemented in an infinite loop. */
  10. for (;;) {
  11. /* Print out the name of this task. */
  12. vPrintString(pcTaskName);
  13. /* here we are in STATE_0 */
  14. long_delay();
  15. FSM(EVENT_FOR_STATE_1);
  16. short_delay();
  17. FSM(EVENT_FOR_STATE_2);
  18. short_delay();
  19. FSM(EVENT_FOR_STATE_3);
  20. short_delay();
  21. FSM(EVENT_FOR_STATE_4);
  22. long_delay();
  23. FSM(EVENT_FOR_STATE_5);
  24. short_delay();
  25. FSM(EVENT_FOR_STATE_6);
  26. short_delay();
  27. #if 1
  28. /* don't block on message */
  29. if (xQueueReceive( xQPedestrian, &( pxPedestrianMessage ), ( portTickType ) 0 )) {
  30. /* pxPedestrianMessage either enables or disables
  31. * the pedestrian functionality
  32. */
  33. if ((int) pxPedestrianMessage == 1) {
  34. FSM(EVENT_FOR_STATE_8);
  35. long_delay();
  36. FSM(EVENT_FOR_STATE_9);
  37. short_delay();
  38. }
  39. }
  40. #endif
  41. FSM(EVENT_FOR_STATE_7);
  42. short_delay();
  43. FSM(EVENT_FOR_STATE_0);
  44. /* here we are back to STATE_0
  45. * let's re-enable the shell in case it was disabled before
  46. */
  47. if (GetUseInputVal() == 0) {
  48. SetUseInputVal(1);
  49. }
  50. }
  51. }
  52. #else
  53. void vTask2(void *pvParameters) {
  54. const char *pcTaskName = "Task 2 is running\n";
  55. int *pxPedestrianMessage;
  56. int pedestrianVal;
  57. current_state = STATE_0;
  58.  
  59. vPrintString(pcTaskName);
  60.  
  61. /* As per most tasks, this task is implemented in an infinite loop. */
  62. for (;;) {
  63. /* Print out the name of this task. */
  64.  
  65. /* here we are in STATE_0 */
  66. /* @@@ todo: add the appropriate delays and states */
  67.  
  68. /* @@@ todo: replace this with a queue */
  69. /*FSM(EVENT_FOR_STATE_7);*/
  70. /* short_delay(); */
  71. /*FSM(EVENT_FOR_STATE_0);*/
  72. /* here we are back to STATE_0
  73. * let's re-enable the shell in case it was disabled before
  74. */
  75. if (GetUseInputVal() == 0) {
  76. SetUseInputVal(1);
  77. }
  78. }
  79. }
  80. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement