Question
Embedded System Programming The following code example executes four tasks (scheduled in ISR that is not presented). Now suppose that execution time of TASK2 is
Embedded System Programming
The following code example executes four tasks (scheduled in ISR that is not presented). Now suppose that execution time of TASK2 is 3 milliseconds and TASK1 should be executed with time interval of 1 ms. TASK2 is a passive task requiring no synchronization with TASK1.
Which is the problem and which are the alternative ways to fix the problem? (Code is not needed, just write explanations.)
#define NUM_OF_TASKS 4
#define TASK1 0
#define TASK2 1
#define TASK3 2
#define TASK4 3
struct tasks {
unsigned short timcount; /* Count value */
unsigned short timval; /* interval in milliseconds */
unsigned char disabled; /* set as not schedulable */
unsigned char taskrunning; /* already running */
unsigned char runtask; /* mark to be redy for execution */
};
void init_tasks ( void ){
uint8_t ii; task[0].timval=1; task[1].timval=10; task[2].timval=30; task[3].timval=40;
for(ii=0;ii task[ii].timcount=task[ii].timval; task[ii].taskrunning=0; task[ii].runtask=0; task[ii].disabled=0; } } // in main we have the following code while(1) { for(i=0;i if(task[i].runtask ) { task[i].runtask=0; task[i].taskrunning=1; switch(i) { case 0: run_task1();break; case 1: run_task2();break; case 2: run_task3();break; case 3: run_task4();break; } } }
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