1. Engineering
  2. Computer Science
  3. embedded system programming the following code example executes four tasks...

Question: embedded system programming the following code example executes four tasks...

Question details

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<NUM_OF_TASKS;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<NUM_OF_TASKS;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;

                               }

                   }                      

             }

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution