For Programming Embedded Systems Q04 Which lines use a varia
For Programming Embedded Systems
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?
A) Lines 61-66
B) Lines 13-15
C) Lines 4-9
D) Lines 40-44
I. #include \"rims.h\" 2 3 4. typedef struct task state BL LedOff; break; default: int state; unsigned long period; unsigned long elapsedTime: int (*TickFct) (int); taski state ) I Transitions switch (state) case BL Ledoff: 11. task tasks [2] break; case BL Ledon: 13. const unsigned char tasksNum 2; 14. const unsigned long periodBlinkLed = 1500; 15. const unsigned long periodThreeLeds 500; break; default: break; ) // State actions 17, const unsigned long tasksPeriodGCD = 500; return state 19. int TickFct BlinkLed (int state) 20. int TickFct ThreeLeds (int state) 22. unsigned char process!ngRdyTasks = 0; 23. void TimerISR 98. enum TL States TL TO, TL T1, TL T2 TL State; 100 99. int TickFct ThreeLeds (int state) ( 101 VARIABLES MUST BE DECLARED STATIC/ unsigned char i; if (processingRdyTasks) /*e.g., static int x = 0; */ /*variables for state machine go here. printf (\"Period too short \ \"): 103 switch (state) case -1: process!ngRdyTasks = 1; for (1 = 0; 1 = 107 108 109 tasks [i].period) case TL TO: tasks [1]. state = 1 tasks[i].TickFct (tasks[i].state); state = TL T1; tasks[i].elapsedTime0 break; case TL T1: 112 113 tasks [1].elapsedTime += tasksPeriodGCD; processingRdyTasks - 0; state = TL T2 115 116 38. int main) break; case TL T2: unsigned char i=0; tasks [1]. state =-1; tasks [1].period = periodBlinkLed; tasks [1] .elapsedTime tasks [1] ·period; tasks [1].TickFct 6T1ckFct BlinkLed; 118 119 120 121 122 123 1 state = TL T0; break; default: state --1; tasks [1] , state = -1; tasks [1].period periodThreeLeas; tasks [1].elapsedTime = tasks [1].period; tasks [1].TICkFct = &TICkfct; ThreeLeas; 125 switch (state) 127 128 129 130 case TL TO: get Timerset (tasksPeriodGCD); break case TL T1: TimerOn () while (1) Sleep return 0 133 135 137 139 h break case TL T2: 61. enum BL States BL Ledoff, BL Ledon BL State; 62. int TickFct BlinkLed (int state) *VARIABLES MUST BE DECLARED STATIC break; 64. /*e.g., static Int X = 0; */ 65. /*variables for state machine go here/ default: break switch (state) case-1: return state state = BL LedOff break; 146 case BL Ledoff: state = BL Ledon; break; case BL Ledon: 1Solution
D ) Lines 40 - 44 are unsed to initialize the task array.
By incrementing the variable, all tasks are stored in the tasks array, in the given index.
Later it would be easy to access the tasks by just given the index of the array.
Hard code numbering cannot solve the problem, a number when stored in a variable, the program can automatically increment it or decrement it. the program keeps track of variables. If hard code numbering has to be used, the steps to add tasks to task array are to be duplicated by giving hard coded value as index of the task.

