Based on the above attached code answer the following with clear explanation: qn
ID: 3580407 • Letter: B
Question
Based on the above attached code answer the following with clear explanation:
qn1) Which task has the highest priority?
qn2) If the common resource was also required by an Interrupt Service Routine (ISR), could the following code fragment be used inside the ISR?
OSMutexPend(ResourceMutex, 0, &err);
LocalCounter = ++Counter; // Increment and make local copy
OSMutexPost(ResourceMutex);
Provide an explanation for your answer.
qn3) Explain how the example application could be modified so that only one task procedure is required, yet still achieve the same outcome, with one task incrementing the common resource and the other task decrementing the common resource. No code is required, just an explanation.
A Real Time Operating System (RTOS) is often used for embedded systems to simplify complex designs while maintaining reliability. A RTOs usually allows for multiple task priority levels and is preemptive. An example application using the RTOs HC/OS-ll s shown in the following code fragment OS STK Task Prio 10 Stkl 1000 OS STK Task Prio20stkl1000 li OS EVENT Resource Mutex MUTEX for common reaource alt 32 counter 0; Common e used by both tasks void Task Prio10 (void pdata alt 32 Local Counter; while (1) OSMut exPend Resource Mutex 0, 5 err); Local Counter ++Counteri Increment and make local copy OSMuttexPost (ResourceMutex); void Task Prio20 (void pdata alt 32 Local Counter While (1) OSMut expend Resource Mutex 0, &err;) Local Counter Counter ement and make local copy OSMutexPost (Resource Mutex) void main void. INT8U erri Init OSMut excreate (9, Serr); OSTaskCreate (Task Prio10, (void 0, & Task Prio10 Stk, 1999 10) OSTaskCreate (Task Prio20 void 0, & Task Prio20stk1999 1, 20); osStart C); The following questions relate to the code fragment above.Explanation / Answer
OS_STK TaskPrio10Stk[1000];
OS_STK TaskPrio20Stk[1000];
Solution:
A.1.) Mutual Exclusion Semaphores are used to gain exclusive access to resources by the tasks. In this case we have two tasks as mentioned. To reduce the priority inversion, the kernel in this case increases the priority of the lower priorty task to the higher priority task until the lower priority task is down. Here, in this case the first task i.e TaskPrio10Stk has the highest priority.
A.2.)The code can be used inside the ISR. OSMutexPend() notices that a higher priority task needs a resource and raises the priority of task,which forces a context switch.OSMutexPost() returns task to its original priority and notices task1 to access resource. Here a mutex is used by the application to reduce the priority inversion problem.
A.3.) In ths case, if only one task procedure is required, we need not address the priority inversion problem. We would only create one task and as long as the condition is satisfied, the common resource would be incremented. An ISR would be placed i.e which decrements the common resource if there is an interrupt .
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.