Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. #include \"rins.h\" 2 3 4. typedef struct task state = BL LedOff; break; int

ID: 3684449 • Letter: 1

Question

1. #include "rins.h" 2 3 4. typedef struct task state = BL LedOff; break; int state; unsigned long period; unsigned long elapsedTime; int (*TickFct) (int); default: state =-1; 7 ) // Transitions 9 task; 84 switch (state) [ case BL Ledoff: 11. task tasks [2]; break; 13. const unsigned char tasksNum 2; 14. const unsigned long periodBlinkLed = 1500; 15. const unsigned long periodThreeLeds = 500; case BL LedOn: break; default: 17. const unsigned long tasks PeriodGCD = 500; break; ) // State actions 19. int TickFct BlinkLed (int state) 20. int TickFct ThreeLeds (int state) return state: 22. unsigned char processingRdyTasks = 0; 23. void TimerISR ) [ 98. enum TL States TL TO, TL T1, TL T2 TL State 99. int TickFct ThreeLeds (int state) unsigned char i; if (processingRdyTasks) /*VARIABLES MUST BE DECLARED STATIC /te.g., static int x 0;*/ /*variables for state machine go here. printf("Period too short "); 102 103 process!ngRdyTasks for (i -0 i 105 state = TL T0; break; tasks [i].period) 107 108 tasks [1].state = case TL TO tasks[i].TickFct (tasks [i].state); tasks [1j, elapsedTime 0; state = TL T1; 110 tasks [1].elapsedTime tasks PeriodGCD, break; += 112 113 case TL T1: process!ngRdyTasks 0; = state = TL T2 ; 115 116 break; unsigned char i-0; tasks [1].state =-1; tasks [1].period = periodBlinkLed; tasks [1].elapsedTime = tasks [1].period; tasks [1].TickFct=&TickFct; BlinkLed; case TL T2: 118 119 120 121 122 state = TL T0; 44. break; 122 123 124 125 126 127 default: tasks [1]. state =-1; tasks [i].period = periodThreeLeds ; tasks [1].elapsedTime = tasks [1].period; tasks [1].TickFct = &TickFct; ThreeLeds ; switch (state) ( case TL TO: 129 TimerSet (tasksPeriodGCD) 130 54 TimerOn () break; case TL T1: B5-0; 133 135 137 while (1)Sleep) ) return 0; break; case TL T2: 138 61. enum BL States { BL Ledoff, BL Ledon } BL State 62. int TickFct_BlinkLed (int state) /*VARIABLES MUST BE DECLARED STATIC/ 140 64. /*e.g., static int x = 0;*/ 65. /*variables for state machine go here break; default: 143 switch (state) case-1: break; 145 return state; state = BL LedOff; break; case BL Ledoff: state = BL Ledon ; break; case BL LedOn:

Explanation / Answer

Q-01. Which lines encapsulate the state machines data? : Lines 4-9 is a structure of variables, and the functions which operate on them. Therefore, that is the answer.

Q-02 Which structure variable points to the tick function? : Line 8 int (*TickFct) (int); is the function pointer which points to the tick function.

Q-03 Which lines create an array of tasks? : Line 11 task tasks[2]; will create an array of 2 tasks.

Q-04 Which lines use a variable to select the priority of a task array being initialized? Why is this variable incremented? Why is a variable used instead of hard code numbering? : Line 40 - 44 will intialize the priority of a task to -1. Variable is incremented, to keep changing the priority when required. If hardcoded, the priorities will be fixed and cannot be changed.