Download uC/OS-II, The Real Time Kernel

Transcript
trying to accomplish in OSEventWaitListInit() is to indicate that no task is waiting on the ECB.
OSEventWaitListInit() is passed a pointer to an event control block which is assigned when the semaphore,
message mailbox or message queue is created.
void OSEventWaitListInit (OS_EVENT *pevent)
{
INT8U i;
pevent->OSEventGrp = 0x00;
for (i = 0; i < OS_EVENT_TBL_SIZE; i++) {
pevent->OSEventTbl[i] = 0x00;
}
}
Listing 6.5, Initializing the wait list.
6.02 Making a task ready, OSEventTaskRdy()
Listing 6.6 shows the code for OSEventTaskRdy(). This function is called by OSSemPost(), OSMboxPost(),
OSQPost() and OSQPostFront() when an ECB is signaled and the highest priority task waiting on the ECB
needs to be made ready-to-run. In other words, OSEventTaskRdy() removes the highest priority task (HPT) from
the wait list of the ECB and makes this task ready-to-run. Figure 6-4 is used to illustrate the first four operation
performed in OSEventTaskRdy().
OSEventTaskRdy() starts by determining the index into the .OSEventRdyTbl[] of the HPT L6.6/F6-4(1), a
number between 0 and OS_LOWEST_PRIO/8+1. The bit mask of the HPT in .OSEventGrp is then obtained
L6.6/F6-4(2), see table 6.1 for possible values. We then determine the bit position of the task in .OSEventTbl[]
L6.6/F6-4(3), a value between0 and OS_LOWEST_PRIO/8+1 . Next, the bit mask of the HPT in .OSEventTbl[]
is determined L6.6/F6-4(4), see table 6.1 for possible values. The priority of the task being made ready-to-run is
determined by combining the x and y indexes L6.6(5). At this point, we can now extract the task from the wait list
L6.6(6).
The Task Control Block (TCB) of the task being readied contains information that also needs to be changed. We can
thus obtain a pointer to that TCB knowing the task’s priority L6.6(7). Because the HPT is not waiting anymore, we
need to make sure that OSTimeTick() will not attempt to decrement the .OSTCBDly value of that task. We
prevent this by forcing this field to 0 L6,6(8). We then force the pointer to the ECB to NULL because the HPT will no
longer be waiting on this ECB L6.6(9). A message is sent to the HPT if OSEventTaskRdy() is called by either
OSMboxPost() or OSQPost(). This message is passed as an argument and needs to be placed in the task’s TCB
L6.6(10). When OSEventTaskRdy() is called, the msk argument contains the appropriate bit mask to clear the bit
in .OSTCBStat which corresponds to the type of event signaled (OS_STAT_SEM, OS_STAT_MBOX or
OS_STAT_Q, see uCOS_II.H) L6.6(11). Finally, if the .OSTCBStat indicates that the task is ready-to-run L6.6(12),
we insert this task in µC/OS-II’s ready list L6.6(13). Note that the task may not be ready-to-run because it could have
been explicitly suspended (see section 4.07, Suspending a Task, OSTaskSuspend() and section 4.08, Resuming a Task,
OSTaskResume()).
You should note that OSEventTaskRdy() is called with interrupts disabled.
void OSEventTaskRdy (OS_EVENT *pevent, void *msg, INT8U msk)
{
OS_TCB *ptcb;
INT8U
x;
INT8U
y;
INT8U
bitx;
INT8U
bity;