Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1. #include rims h state = BL Ledoff; 4. typedef struct task [ default: state =-1; II Transitions int state: unsigned long period: unsigned long
1. #include "rims "h" state = BL Ledoff; 4. typedef struct task [ default: state =-1; II Transitions int state: unsigned long period: unsigned long elapsedTime int (TickFct) (int) switch (state) case BL. Ledoff: 11. task taskS [2]: 12 13. const unsigned char tasksNum2 14, const unsigned long periodBlinkted 1500; 15. const unsigned long periodThreeLeds-500; break: case BL Ledon: B0-1i break: default: break: 17, const unsigned long tasksPeriodGCD 500; II State actions return state: 19. int TickFct BlinkLed (int state) 20-int Tickect threeLeds (int state); 95 96 22. unsigned char processingRdyTasks-0 23. void TimerISRO [ 24. unsigned char i 25. if (processingRdyTasks) 26 98.enum TL States (TL_TO, TL_T1, TL_22 TL State 99 int TickFct ThreeLeds (int state) VARIABLES MUST BE DECLARED STATIC/ /te.g., static int x = 0;*/ /variables for state machine go here./ 102 103 104 105 printf "Period too short In")i switch (state) 28 processingRdyTasks 1 state TL T0: break: 30 if (tasksti].elapsedTime 107 108 109 110 tasks [i) period case TL TO: tasks [ 1 ] . state tasks [ 1 . TickFct ( tasks [ 1 ]-state) ; state TL T1; 32 tasks [1]elapsedine 0; break: case TL1: tasks [i].elapsedTime tasksPeriodGCD 113 114 115 116 36 rocessingRdyTasks 0 state TL T2 38. int main) break: case TL T2: 40 unsigned char i-0: 41. tasks [1],state=-1; 42 118 119 120 tasks[i] period periodB1inkted: tasks[i].elapsedTime-tasks []-period tasks[i] rickFct -TickFct Blinkted: break: default: 122 123 state =-1 ; tasks [1].state =-1; tasks[i] period-periodThreeLeds: 49 tasks[i].elapsedtime-tasks [i) period 50. tasks [1].rickfct-GTickretThreeLeds ; switch (state) t case TL TO: 85-1 - 129 130 131 53. TimerSet (tasksPeriodGCD) 54 Timeron (O: break: case TL T1: B6-1i B7-0: break: case TL T2: B5-0: 56 while (1)Sleep): 136 137 138 139 140 141 142 143 144 145 146 147 59urn o 61. enum BL StatesBL Ledoff, BL Ledon BL State: 62. int TickFct BlinkLed (int state) 63 /*VARIABLES MUST BE DECLARED STATIC 64. /*e.g., static int x = 0; 65. /*variables for state machine go here/ 66 witch (state) break: break: return state default: 68 state-BL ledoff; 70 case BL Ledoff: state BL Ledon: break: case BL Ledon
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started