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;
}
Example #2
0
/*********************************************************************
*
*       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();
}
Example #3
0
/*********************************************************************
*
*       IP_OS_WaitNetEvent
*
*  Function description
*    Called from IP_Task() only.
*    Blocks until the timeout expires or a NET-event occurs,
*    meaning IP_OS_SignalNetEvent() is called from an other task or ISR.
*/
void IP_OS_WaitNetEvent(unsigned ms) {
  OS_EVENT_WaitTimed(&_EventNet, ms + 1);
}
Example #4
0
/**********************************************************
*
*        USB_OS_WaitTimed
*
* Function description
*   Block the task until USB_OS_Signal is called
*   or a time out occurs
*   This routine is called from a task.
*
*/
int USB_OS_WaitTimed(unsigned EPIndex, unsigned ms) {
    int r;
    r = (int)OS_EVENT_WaitTimed(&_aEvent[EPIndex], ms + 1);
    return r;
}