WILC_Uint32 FIFO_InitBuffer(tHANDLE * hBuffer,WILC_Uint32 u32BufferLength) { WILC_Uint32 u32Error = 0; tstrFifoHandler * pstrFifoHandler = WILC_MALLOC(sizeof(tstrFifoHandler)); if(pstrFifoHandler) { WILC_memset(pstrFifoHandler,0,sizeof(tstrFifoHandler)); pstrFifoHandler->pu8Buffer = WILC_MALLOC(u32BufferLength); if(pstrFifoHandler->pu8Buffer) { tstrWILC_SemaphoreAttrs strSemBufferAttrs; pstrFifoHandler->u32BufferLength = u32BufferLength; WILC_memset(pstrFifoHandler->pu8Buffer,0,u32BufferLength); //create semaphore WILC_SemaphoreFillDefault(&strSemBufferAttrs); strSemBufferAttrs.u32InitCount = 1; WILC_SemaphoreCreate(&pstrFifoHandler->SemBuffer, &strSemBufferAttrs); *hBuffer = pstrFifoHandler; } else { *hBuffer = NULL; u32Error = 1; } } else { u32Error = 1; } return u32Error; }
WILC_ErrNo WILC_SemaphoreCreate(WILC_SemaphoreHandle* pHandle, tstrWILC_SemaphoreAttrs* pstrAttrs) { tstrWILC_SemaphoreAttrs strDefaultAttrs; if(pstrAttrs == WILC_NULL) { WILC_SemaphoreFillDefault(&strDefaultAttrs); pstrAttrs = &strDefaultAttrs; } sema_init(pHandle,pstrAttrs->u32InitCount); return WILC_SUCCESS; }
/*! * @author syounan * @date 1 Sep 2010 * @note copied from FLO glue implementatuion * @version 1.0 */ WILC_ErrNo WILC_MsgQueueCreate(WILC_MsgQueueHandle *pHandle, tstrWILC_MsgQueueAttrs *pstrAttrs) { tstrWILC_SemaphoreAttrs strSemAttrs; WILC_SemaphoreFillDefault(&strSemAttrs); strSemAttrs.u32InitCount = 0; spin_lock_init(&pHandle->strCriticalSection); if ((WILC_SemaphoreCreate(&pHandle->hSem, &strSemAttrs) == WILC_SUCCESS)) { pHandle->pstrMessageList = NULL; pHandle->u32ReceiversCount = 0; pHandle->bExiting = WILC_FALSE; return WILC_SUCCESS; } else { return WILC_FAIL; } }
/*! * @author syounan * @date 1 Sep 2010 * @note copied from FLO glue implementatuion * @version 1.0 */ WILC_ErrNo WILC_MsgQueueRecv(WILC_MsgQueueHandle *pHandle, void *pvRecvBuffer, WILC_Uint32 u32RecvBufferSize, WILC_Uint32 *pu32ReceivedLength, tstrWILC_MsgQueueAttrs *pstrAttrs) { Message *pstrMessage; WILC_ErrNo s32RetStatus = WILC_SUCCESS; tstrWILC_SemaphoreAttrs strSemAttrs; unsigned long flags; if ((pHandle == NULL) || (u32RecvBufferSize == 0) || (pvRecvBuffer == NULL) || (pu32ReceivedLength == NULL)) { WILC_ERRORREPORT(s32RetStatus, WILC_INVALID_ARGUMENT); } if (pHandle->bExiting == WILC_TRUE) { WILC_ERRORREPORT(s32RetStatus, WILC_FAIL); } spin_lock_irqsave(&pHandle->strCriticalSection, flags); pHandle->u32ReceiversCount++; spin_unlock_irqrestore(&pHandle->strCriticalSection, flags); WILC_SemaphoreFillDefault(&strSemAttrs); #ifdef CONFIG_WILC_MSG_QUEUE_TIMEOUT if (pstrAttrs != WILC_NULL) { strSemAttrs.u32TimeOut = pstrAttrs->u32Timeout; } #endif s32RetStatus = WILC_SemaphoreAcquire(&(pHandle->hSem), &strSemAttrs); if (s32RetStatus == WILC_TIMEOUT) { /* timed out, just exit without consumeing the message */ spin_lock_irqsave(&pHandle->strCriticalSection, flags); pHandle->u32ReceiversCount--; spin_unlock_irqrestore(&pHandle->strCriticalSection, flags); } else { /* other non-timeout scenarios */ WILC_ERRORCHECK(s32RetStatus); if (pHandle->bExiting) { WILC_ERRORREPORT(s32RetStatus, WILC_FAIL); } spin_lock_irqsave(&pHandle->strCriticalSection, flags); pstrMessage = pHandle->pstrMessageList; if (pstrMessage == NULL) { spin_unlock_irqrestore(&pHandle->strCriticalSection, flags); WILC_ERRORREPORT(s32RetStatus, WILC_FAIL); } /* check buffer size */ if (u32RecvBufferSize < pstrMessage->u32Length) { spin_unlock_irqrestore(&pHandle->strCriticalSection, flags); WILC_SemaphoreRelease(&pHandle->hSem, WILC_NULL); WILC_ERRORREPORT(s32RetStatus, WILC_BUFFER_OVERFLOW); } /* consume the message */ pHandle->u32ReceiversCount--; WILC_memcpy(pvRecvBuffer, pstrMessage->pvBuffer, pstrMessage->u32Length); *pu32ReceivedLength = pstrMessage->u32Length; pHandle->pstrMessageList = pstrMessage->pstrNext; WILC_FREE(pstrMessage->pvBuffer); WILC_FREE(pstrMessage); spin_unlock_irqrestore(&pHandle->strCriticalSection, flags); } WILC_CATCH(s32RetStatus) { } return s32RetStatus; }