示例#1
0
/*---------------------------------------------------------------------------*
 * Routine:  sys_mbox_trypost
 *---------------------------------------------------------------------------*
 * Description:
 *      Try to post the "msg" to the mailbox.  Returns immediately with
 *      error if cannot.
 * Inputs:
 *      sys_mbox_t mbox         -- Handle of mailbox
 *      void *msg               -- Pointer to data to post
 * Outputs:
 *      err_t                   -- ERR_OK if message posted, else ERR_MEM
 *                                  if not.
 *---------------------------------------------------------------------------*/
err_t sys_mbox_trypost( sys_mbox_t *pxMailBox, void *pxMessageToPost ) {
	BT_ERROR xReturn;

	xReturn = BT_QueueSend( *pxMailBox, &pxMessageToPost, 0 );

	if( xReturn == BT_TRUE ) {
		xReturn = ERR_OK;
	}
	else {
		/* The queue was already full. */
		xReturn = ERR_MEM;
		SYS_STATS_INC( mbox.err );
	}

	return xReturn;
}
示例#2
0
BT_s32 BT_FifoWrite(BT_HANDLE hFifo, BT_u32 ulElements, const void *pData, BT_u32 ulFlags) {

	BT_ERROR 		Error 		= BT_ERR_NONE;
	const BT_u8    *pSrc 		= pData;
	BT_u32 			ulWritten 	= 0;

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

	for(ulWritten = 0; ulWritten < ulElements; ulWritten++) {
		if (ulFlags & BT_FIFO_NONBLOCKING) {						// We should prevent overflow, and block!
			if (BT_FifoIsFull(hFifo->hQueue, &Error)) {
				break;
			}
		}

		BT_QueueSend(hFifo->hQueue, pSrc, -1);
		pSrc += hFifo->ulElementWidth;
	}

	return ulWritten;
}