bool_t osWaitForEvent(OsEvent *event, systime_t timeout) { bool_t ret; //Wait until the specified event is in the signaled //state or the timeout interval elapses if(timeout == 0) { //Non-blocking call ret = OS_EVENT_Get(event); } else if(timeout == INFINITE_DELAY) { //Infinite timeout period OS_EVENT_Wait(event); ret = TRUE; } else { //Wait until the specified event becomes set ret = !OS_EVENT_WaitTimed(event, OS_MS_TO_SYSTICKS(timeout)); } //The return value specifies whether the event is set return ret; }
/********************************************************************* * * _StatusTask * */ static void _StatusTask(void) { static USB_HOOK _Hook; OS_EVENT_Create(&_Event); USB_RegisterSCHook(&_Hook, _OnStatusChange, &_Data32, sizeof(_Data32)); while(1) { printf("Current state = %s %s %s %s %s\n", (_State & USB_STAT_ATTACHED) ? "Attached " : "", (_State & USB_STAT_READY) ? "Ready " : "", (_State & USB_STAT_ADDRESSED) ? "Addressed " : "", (_State & USB_STAT_CONFIGURED)? "Configured" : "", (_State & USB_STAT_SUSPENDED) ? "Suspended " : "" ); OS_EVENT_Wait(&_Event); } }
/********************************************************************* * * IP_OS_WaitItemTimed() * * Function description * Suspend a task which needs to wait for a object. * This object is identified by a pointer to it and can be of any type, e.g. socket. * * Context * Function is called from an application task. */ void IP_OS_WaitItemTimed(void * pWaitItem, unsigned Timeout) { TCP_WAIT TCPWait; // // Create the wait object which contains the OS-Event object // TCPWait.pPrev = NULL; TCPWait.pWaitItem = pWaitItem; OS_EVENT_Create(&TCPWait.Event); // // Add to doubly-linked list with temp. disabled interrupts // IP_OS_DisableInterrupt(); TCPWait.pNext = _pTCPWait; _pTCPWait = &TCPWait; if (TCPWait.pNext) { TCPWait.pNext->pPrev = &TCPWait; } IP_OS_EnableInterrupt(); // // Unlock mutex and suspend this task // IP_OS_Unlock(); if (Timeout == 0) { OS_EVENT_Wait(&TCPWait.Event); } else { OS_EVENT_WaitTimed(&TCPWait.Event, Timeout); } // // Remove it from doubly linked list with temp. disabled interrupts // IP_OS_DisableInterrupt(); if (TCPWait.pPrev) { TCPWait.pPrev->pNext = TCPWait.pNext; } else { _pTCPWait = TCPWait.pNext; } if (TCPWait.pNext) { TCPWait.pNext->pPrev = TCPWait.pPrev; } IP_OS_EnableInterrupt(); // // Delete the event object & lock the mutex again // OS_EVENT_Delete(&TCPWait.Event); IP_OS_Lock(); }
/********************************************************************* * * IP_OS_WaitRxEvent */ void IP_OS_WaitRxEvent(void) { OS_EVENT_Wait(&_EventRx); }
/********************************************************** * * USB_OS_Wait * * Function description * Block the task until USB_OS_SignalRx is called * Add. info * This routine is called from a task. */ void USB_OS_Wait(unsigned EPIndex) { OS_EVENT_Wait(&_aEvent[EPIndex]); }