Lua获取当前等待信号量,消息队列,消息邮箱等通信组件的任务和任务个数,含等待的最高优先级任务
[Lua] 纯文本查看 复制代码 if(OSLowestPrio <= 63) then
OSEventCnt = pg_read16(pcb + 8)
OSEventGrp = pg_read8(pcb + 0x0a)
for i=0, OS_EVENT_TBL_SIZE, 1 do
off = (OSEventGrp & (1<<i) ) >> i
if(off == 1) then
for j=0, 7, 1 do
OSEventTbl1 = pg_read8(pcb + 0x0b + i)
off = (OSEventTbl1 & (1<<j) ) >> j
if(off == 1) then
TaskCount = TaskCount + 1
TaskBuffer[TaskCount] = j + i*8
end
end
end
end
else
OSEventCnt = pg_read16(pcb + 8)
OSEventGrp = pg_read16(pcb + 0x0a)
OSEventTbl1 = pg_read16(pcb + 0x0c)
for i=0, OS_EVENT_TBL_SIZE, 1 do
off = (OSEventGrp & (1<<i) ) >> i
if(off == 1) then
for j=0, 15, 1 do
OSEventTbl1 = pg_read16(pcb + 0x0b + 2*i)
off = (OSEventTbl1 & (1<<j) ) >> j
if(off == 1) then
TaskCount = TaskCount + 1
TaskBuffer[TaskCount] = j + i*8
end
end
end
end
end
C获取就绪的最高优先级任务:
[C] 纯文本查看 复制代码 /*
*********************************************************************************************************
* MAKE TASK READY TO RUN BASED ON EVENT OCCURING
*
* Description: This function is called by other uC/OS-II services and is used to ready a task that was
* waiting for an event to occur.
*
* Arguments : pevent is a pointer to the event control block corresponding to the event.
*
* pmsg is a pointer to a message. This pointer is used by message oriented services
* such as MAILBOXEs and QUEUEs. The pointer is not used when called by other
* service functions.
*
* msk is a mask that is used to clear the status byte of the TCB. For example,
* OSSemPost() will pass OS_STAT_SEM, OSMboxPost() will pass OS_STAT_MBOX etc.
*
* pend_stat is used to indicate the readied task's pending status:
*
* OS_STAT_PEND_OK Task ready due to a post (or delete), not a timeout or
* an abort.
* OS_STAT_PEND_ABORT Task ready due to an abort.
*
* Returns : none
*
* Note : This function is INTERNAL to uC/OS-II and your application should not call it.
*********************************************************************************************************
*/
#if (OS_EVENT_EN)
INT8U OS_EventTaskRdy (OS_EVENT *pevent,
void *pmsg,
INT8U msk,
INT8U pend_stat)
{
OS_TCB *ptcb;
INT8U y;
INT8U x;
INT8U prio;
#if OS_LOWEST_PRIO > 63u
OS_PRIO *ptbl;
#endif
#if OS_LOWEST_PRIO <= 63u
y = OSUnMapTbl[pevent->OSEventGrp]; /* Find HPT waiting for message */
x = OSUnMapTbl[pevent->OSEventTbl[y]];
prio = (INT8U)((y << 3u) + x); /* Find priority of task getting the msg */
#else
if ((pevent->OSEventGrp & 0xFFu) != 0u) { /* Find HPT waiting for message */
y = OSUnMapTbl[ pevent->OSEventGrp & 0xFFu];
} else {
y = OSUnMapTbl[(OS_PRIO)(pevent->OSEventGrp >> 8u) & 0xFFu] + 8u;
}
ptbl = &pevent->OSEventTbl[y];
if ((*ptbl & 0xFFu) != 0u) {
x = OSUnMapTbl[*ptbl & 0xFFu];
} else {
x = OSUnMapTbl[(OS_PRIO)(*ptbl >> 8u) & 0xFFu] + 8u;
}
prio = (INT8U)((y << 4u) + x); /* Find priority of task getting the msg */
#endif
ptcb = OSTCBPrioTbl[prio]; /* Point to this task's OS_TCB */
ptcb->OSTCBDly = 0u; /* Prevent OSTimeTick() from readying task */
#if ((OS_Q_EN > 0u) && (OS_MAX_QS > 0u)) || (OS_MBOX_EN > 0u)
ptcb->OSTCBMsg = pmsg; /* Send message directly to waiting task */
#else
pmsg = pmsg; /* Prevent compiler warning if not used */
#endif
ptcb->OSTCBStat &= (INT8U)~msk; /* Clear bit associated with event type */
ptcb->OSTCBStatPend = pend_stat; /* Set pend status of post or abort */
/* See if task is ready (could be susp'd) */
if ((ptcb->OSTCBStat & OS_STAT_SUSPEND) == OS_STAT_RDY) {
OSRdyGrp |= ptcb->OSTCBBitY; /* Put task in the ready to run list */
OSRdyTbl[y] |= ptcb->OSTCBBitX;
OS_TRACE_TASK_READY(ptcb);
}
OS_EventTaskRemove(ptcb, pevent); /* Remove this task from event wait list */
#if (OS_EVENT_MULTI_EN > 0u)
if (ptcb->OSTCBEventMultiPtr != (OS_EVENT **)0) { /* Remove this task from events' wait lists */
OS_EventTaskRemoveMulti(ptcb, ptcb->OSTCBEventMultiPtr);
ptcb->OSTCBEventMultiPtr = (OS_EVENT **)0; /* No longer pending on multi list */
ptcb->OSTCBEventMultiRdy = (OS_EVENT *)pevent;/* Return event as first multi-pend event ready*/
}
#endif
return (prio);
}
#endif
|