/********************************************************************************************************* ** 函数名称: pause ** 功能描述: 等待一个信号的到来 ** 输 入 : NONE ** 输 出 : ERROR ** 全局变量: ** 调用模块: API 函数 *********************************************************************************************************/ LW_API INT pause (VOID) { INTREG iregInterLevel; PLW_CLASS_TCB ptcbCur; REGISTER PLW_CLASS_PCB ppcb; __THREAD_CANCEL_POINT(); /* 测试取消点 */ LW_TCB_GET_CUR_SAFE(ptcbCur); /* 当前任务控制块 */ MONITOR_EVT_LONG1(MONITOR_EVENT_ID_SIGNAL, MONITOR_EVENT_SIGNAL_PAUSE, ptcbCur->TCB_ulId, LW_NULL); iregInterLevel = __KERNEL_ENTER_IRQ(); /* 进入内核 */ ptcbCur->TCB_usStatus |= LW_THREAD_STATUS_SIGNAL; /* 等待信号 */ ppcb = _GetPcb(ptcbCur); __DEL_FROM_READY_RING(ptcbCur, ppcb); /* 从就绪表中删除 */ __KERNEL_EXIT_IRQ(iregInterLevel); /* 退出内核 */ _ErrorHandle(EINTR); return (PX_ERROR); }
LW_API ULONG API_MsgQueueClear (LW_OBJECT_HANDLE ulId) { INTREG iregInterLevel; REGISTER UINT16 usIndex; REGISTER PLW_CLASS_EVENT pevent; REGISTER PLW_CLASS_MSGQUEUE pmsgqueue; usIndex = _ObjectGetIndex(ulId); #if LW_CFG_ARG_CHK_EN > 0 if (!_ObjectClassOK(ulId, _OBJECT_MSGQUEUE)) { /* 类型是否正确 */ _DebugHandle(__ERRORMESSAGE_LEVEL, "msgqueue handle invalidate.\r\n"); _ErrorHandle(ERROR_KERNEL_HANDLE_NULL); return (ERROR_KERNEL_HANDLE_NULL); } if (_Event_Index_Invalid(usIndex)) { /* 下标是否正正确 */ _DebugHandle(__ERRORMESSAGE_LEVEL, "msgqueue handle invalidate.\r\n"); _ErrorHandle(ERROR_KERNEL_HANDLE_NULL); return (ERROR_KERNEL_HANDLE_NULL); } #endif pevent = &_K_eventBuffer[usIndex]; iregInterLevel = __KERNEL_ENTER_IRQ(); /* 进入内核 */ if (_Event_Type_Invalid(usIndex, LW_TYPE_EVENT_MSGQUEUE)) { __KERNEL_EXIT_IRQ(iregInterLevel); /* 退出内核 */ _DebugHandle(__ERRORMESSAGE_LEVEL, "msgqueue handle invalidate.\r\n"); _ErrorHandle(ERROR_MSGQUEUE_TYPE); return (ERROR_MSGQUEUE_TYPE); } pmsgqueue = (PLW_CLASS_MSGQUEUE)pevent->EVENT_pvPtr; pevent->EVENT_ulCounter = 0ul; pmsgqueue->MSGQUEUE_pucInputPtr = pmsgqueue->MSGQUEUE_pucBufferLowAddr; pmsgqueue->MSGQUEUE_pucOutputPtr = pmsgqueue->MSGQUEUE_pucBufferLowAddr; __KERNEL_EXIT_IRQ(iregInterLevel); /* 退出内核 */ MONITOR_EVT_LONG1(MONITOR_EVENT_ID_MSGQ, MONITOR_EVENT_MSGQ_CLEAR, ulId, LW_NULL); return (ERROR_NONE); }
LW_API ULONG API_SemaphoreBDelete (LW_OBJECT_HANDLE *pulId) { INTREG iregInterLevel; REGISTER UINT16 usIndex; REGISTER PLW_CLASS_EVENT pevent; REGISTER PLW_CLASS_TCB ptcb; REGISTER PLW_LIST_RING *ppringList; /* 等待队列地址 */ REGISTER LW_OBJECT_HANDLE ulId; ulId = *pulId; usIndex = _ObjectGetIndex(ulId); if (LW_CPU_GET_CUR_NESTING()) { /* 不能在中断中调用 */ _DebugHandle(__ERRORMESSAGE_LEVEL, "called from ISR.\r\n"); _ErrorHandle(ERROR_KERNEL_IN_ISR); return (ERROR_KERNEL_IN_ISR); } #if LW_CFG_ARG_CHK_EN > 0 if (!_ObjectClassOK(ulId, _OBJECT_SEM_B)) { /* 类型是否正确 */ _DebugHandle(__ERRORMESSAGE_LEVEL, "semaphore handle invalidate.\r\n"); _ErrorHandle(ERROR_KERNEL_HANDLE_NULL); return (ERROR_KERNEL_HANDLE_NULL); } if (_Event_Index_Invalid(usIndex)) { /* 下标是否正正确 */ _DebugHandle(__ERRORMESSAGE_LEVEL, "semaphore handle invalidate.\r\n"); _ErrorHandle(ERROR_KERNEL_HANDLE_NULL); return (ERROR_KERNEL_HANDLE_NULL); } #endif pevent = &_K_eventBuffer[usIndex]; iregInterLevel = __KERNEL_ENTER_IRQ(); /* 进入内核 */ if (_Event_Type_Invalid(usIndex, LW_TYPE_EVENT_SEMB)) { __KERNEL_EXIT_IRQ(iregInterLevel); /* 退出内核 */ _DebugHandle(__ERRORMESSAGE_LEVEL, "semaphore handle invalidate.\r\n"); _ErrorHandle(ERROR_EVENT_TYPE); return (ERROR_EVENT_TYPE); } _ObjectCloseId(pulId); /* 清除句柄 */ pevent->EVENT_ucType = LW_TYPE_EVENT_UNUSED; /* 事件类型为空 */ while (_EventWaitNum(pevent)) { /* 是否存在正在等待的任务 */ if (pevent->EVENT_ulOption & LW_OPTION_WAIT_PRIORITY) { /* 优先级等待队列 */ _EVENT_DEL_Q_PRIORITY(ppringList); /* 检查需要激活的队列 */ /* 激活优先级等待线程 */ ptcb = _EventReadyPriorityLowLevel(pevent, LW_NULL, ppringList); } else { _EVENT_DEL_Q_FIFO(ppringList); /* 查找 FIFO 队列指针地址 */ /* 激活FIFO等待线程 */ ptcb = _EventReadyFifoLowLevel(pevent, LW_NULL, ppringList); } KN_INT_ENABLE(iregInterLevel); /* 打开中断 */ ptcb->TCB_ucIsEventDelete = LW_EVENT_DELETE; /* 事件已经被删除 */ _EventReadyHighLevel(ptcb, LW_THREAD_STATUS_SEM); /* 处理 TCB */ iregInterLevel = KN_INT_DISABLE(); /* 关闭中断 */ } pevent->EVENT_pvTcbOwn = LW_NULL; _Free_Event_Object(pevent); /* 交还控制块 */ __KERNEL_EXIT_IRQ(iregInterLevel); /* 退出内核 */ __LW_OBJECT_DELETE_HOOK(ulId); MONITOR_EVT_LONG1(MONITOR_EVENT_ID_SEMB, MONITOR_EVENT_SEM_DELETE, ulId, LW_NULL); _DebugFormat(__LOGMESSAGE_LEVEL, "semaphore \"%s\" has been delete.\r\n", pevent->EVENT_cEventName); return (ERROR_NONE); }