Example #1
0
/*---------------------------------------------------------------------------*
 * Routine:  sys_arch_mbox_fetch
 *---------------------------------------------------------------------------*
 * Description:
 *      Blocks the thread until a message arrives in the mailbox, but does
 *      not block the thread longer than "timeout" milliseconds (similar to
 *      the sys_arch_sem_wait() function). The "msg" argument is a result
 *      parameter that is set by the function (i.e., by doing "*msg =
 *      ptr"). The "msg" parameter maybe NULL to indicate that the message
 *      should be dropped.
 *
 *      The return values are the same as for the sys_arch_sem_wait() function:
 *      Number of milliseconds spent waiting or SYS_ARCH_TIMEOUT if there was a
 *      timeout.
 *
 *      Note that a function with a similar name, sys_mbox_fetch(), is
 *      implemented by lwIP.
 * Inputs:
 *      sys_mbox_t mbox         -- Handle of mailbox
 *      void **msg              -- Pointer to pointer to msg received
 *      u32_t timeout           -- Number of milliseconds until timeout
 * Outputs:
 *      u32_t                   -- SYS_ARCH_TIMEOUT if timeout, else number
 *                                  of milliseconds until received.
 *---------------------------------------------------------------------------*/
u32_t sys_arch_mbox_fetch( sys_mbox_t *pxMailBox, void **ppvBuffer, u32_t ulTimeOut ) {
	void *pvDummy;
	BT_TICK ulStartTime, ulEndTime, ulElapsed;
	BT_u32 ulReturn;

	ulStartTime = BT_GetKernelTick();

	if( NULL == ppvBuffer ) {
		ppvBuffer = &pvDummy;
	}


	if( ulTimeOut != 0UL ) {
		if( BT_TRUE == BT_QueueReceive( *pxMailBox, &( *ppvBuffer ), ulTimeOut ) ) {
			ulEndTime = BT_GetKernelTick();
			ulElapsed = ( ulEndTime - ulStartTime );

			ulReturn = ulElapsed;
		}
		else {
			/* Timed out. */
			*ppvBuffer = NULL;
			ulReturn = SYS_ARCH_TIMEOUT;
		}
	}
	else {
		while( BT_TRUE != BT_QueueReceive( *pxMailBox, &( *ppvBuffer ), 0 ) );
		ulEndTime = BT_GetKernelTick();
		ulElapsed = ( ulEndTime - ulStartTime );

		if( ulElapsed == 0UL ) {
			ulElapsed = 1UL;
		}

		ulReturn = ulElapsed;
	}

	return ulReturn;
}
Example #2
0
/*---------------------------------------------------------------------------*
 * Routine:  sys_arch_mbox_tryfetch
 *---------------------------------------------------------------------------*
 * Description:
 *      Similar to sys_arch_mbox_fetch, but if message is not ready
 *      immediately, we'll return with SYS_MBOX_EMPTY.  On success, 0 is
 *      returned.
 * Inputs:
 *      sys_mbox_t mbox         -- Handle of mailbox
 *      void **msg              -- Pointer to pointer to msg received
 * Outputs:
 *      u32_t                   -- SYS_MBOX_EMPTY if no messages.  Otherwise,
 *                                  return ERR_OK.
 *---------------------------------------------------------------------------*/
u32_t sys_arch_mbox_tryfetch( sys_mbox_t *pxMailBox, void **ppvBuffer ) {
	void *pvDummy;
	unsigned long ulReturn;
	long lResult;

	if( ppvBuffer== NULL ) {
		ppvBuffer = &pvDummy;
	}

	lResult = BT_QueueReceive( *pxMailBox, &( *ppvBuffer ), 0UL );

	if( lResult == BT_TRUE ) {
		ulReturn = ERR_OK;
	}
	else {
		ulReturn = SYS_MBOX_EMPTY;
	}

	return ulReturn;
}
Example #3
0
BT_s32 BT_FifoRead(BT_HANDLE hFifo, BT_u32 ulElements, void *pData, BT_u32 ulFlags) {

	BT_ERROR Error 	= BT_ERR_NONE;
	BT_u8 *pSrc 	= pData;
	BT_u32 ulRead 	= 0;

	if(!isFifoHandle(hFifo)) {
		return BT_ERR_INVALID_HANDLE_TYPE;
	}

	for(ulRead = 0; ulRead < ulElements; ulRead++) {
		if(BT_FifoIsEmpty(hFifo, &Error)) {
			if (ulFlags & BT_FIFO_NONBLOCKING) {
				break;
			}
		}
		BT_QueueReceive(hFifo->hQueue, pData, BT_INFINITE_TIMEOUT);
		pSrc += hFifo->ulElementWidth;
	}

	return ulRead;
}