Beispiel #1
0
/*****************************************************************************
 *
 * Description:
 *    This function takes a counting semaphore, i.e. decreasing the semaphore 
 *    counting. If the semaphore counter is zero the function will block until 
 *    another process or an ISR gives the semaphore or a timeout occurs. 
 *
 * Params:
 *    [in]  pSem    - A pointer to an initialized semaphore structure. 
 *    [in]  timeout - After timeout ticks the operation will timeout. A 
 *                    timeout of zero means no timeout at all. 
 *    [out] pError  - The return status of the function. 
 *
 * Returns:
 *    TRUE if semaphore was taken and FALSE if timeout or error. 
 *
 * Error codes:
 *    OS_OK         - The function completed successfully. 
 *    OS_ERROR_ISR  - The function was called from an interrupt service 
 *                    routine. 
 *    OS_ERROR_NULL - A NULL pointer was supplied to the function where it was 
 *                    not allowed. 
 *
 ****************************************************************************/
tBool
osSemTake(tCntSem* pSem,
          tU32     timeout,
          tU8*     pError)
{
  tU8 ret;
  volatile tSR localSR;  /* declare temporary local space for status word */

  *pError = OS_OK;
  if(pSem == NULL)
  {
    *pError = OS_ERROR_NULL;

    return FALSE;
  }

  m_os_dis_int();
  
  if(isrNesting > 0)
  {
    m_os_ena_int();
    *pError = OS_ERROR_ISR;

    return FALSE;
  }

  if(pSem->cnt > 0)
  {
    pSem->cnt--;
  }
  else
  {
    eventWait((tOSEvent*)pSem, timeout);
    m_os_ena_int();
    schedule();
    m_os_dis_int();
    ret = eventWaitReturn((tOSEvent*)pSem);
    if(ret == OS_ERROR_TIMEOUT){
      m_os_ena_int();
      return FALSE;
    }
  }

  m_os_ena_int();
  return TRUE;
}
Beispiel #2
0
int mmapLogWaitEvent(int timeout)
{
    return eventWait(g_mmap_log.event, timeout);
}