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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!