/*FUNCTION********************************************************************** * * Function Name : OSA_MsgQGet * Description : This function checks the queue's status, if it is not empty, * get message from it and return kStatus_OSA_Success, otherwise, timeout will * be used for wait. The parameter timeout indicates how long should wait in * milliseconds. Pass OSA_WAIT_FOREVER to wait indefinitely, pass 0 will return * kStatus_OSA_Timeout immediately if queue is empty. * This function returns kStatus_OSA_Success if message is got successfully, * returns kStatus_OSA_Timeout if message queue is empty within the specified * 'timeout', returns kStatus_OSA_Error if any errors occur during waiting, * returns kStatus_OSA_Idle if message queue is empty and 'timeout' is * not exhausted, because wait functions should not block with bare metal. * *END**************************************************************************/ osa_status_t OSA_MsgQGet(msg_queue_handler_t handler, void *pMessage, uint32_t timeout) { assert(handler); osa_status_t retVal = kStatus_OSA_Error; uint32_t *from_ptr, *to_ptr; uint16_t msgSize; INT_SYS_DisableIRQGlobal(); /* Check if the queue is not empty */ if(!handler->isEmpty) { from_ptr = &handler->queueMem[handler->head * handler->size]; to_ptr = (uint32_t*)(pMessage); /* Copy entire message into the queue, based on the size configured at creation */ msgSize = handler->size; while(msgSize--) { *to_ptr++ = *from_ptr++; } /* Adjust head pointer and wrap in case the end of the buffer is reached */ ++handler->head; if(handler->head == handler->number) { handler->head = 0; } /* If queue is empty, clear the semaphore. */ if(handler->head == handler->tail) { handler->isEmpty = true; /* Set semapohre to 0 because the queue is empty. */ (void)OSA_SemaWait(&handler->queueSem, 0); } INT_SYS_EnableIRQGlobal(); retVal = kStatus_OSA_Success; } else { INT_SYS_EnableIRQGlobal(); /* Wait for the semaphore if the queue was empty */ retVal = OSA_SemaWait(&handler->queueSem, timeout); } return retVal; }
uint32_t OS_Sem_wait(os_sem_handle handle, uint32_t timeout) { osa_status_t status = kStatus_OSA_Idle; uint32_t re; #if (USE_RTOS) if (0==timeout) { timeout = OSA_WAIT_FOREVER; } #endif do { status = OSA_SemaWait((semaphore_t*) handle, timeout); } while (kStatus_OSA_Idle == status); switch(status) { case kStatus_OSA_Success: re = (uint32_t) OS_SEM_OK; break; case kStatus_OSA_Timeout: re = (uint32_t) OS_SEM_TIMEOUT; break; default: re = (uint32_t) OS_SEM_ERROR; break; } return re; }
/*FUNCTION********************************************************************** * * Function Name : TSI_DRV_MeasureBlocking * Description : This function gets (measure) capacitance of enabled electrodes * from the TSI module using a blocking method. * *END**************************************************************************/ tsi_status_t TSI_DRV_MeasureBlocking(uint32_t instance) { assert(instance < TSI_INSTANCE_COUNT); osa_status_t syncStatus; tsi_status_t status; tsi_state_t * tsiState = g_tsiStatePtr[instance]; /* Start the measurement process */ if ((status = TSI_DRV_Measure(instance)) != kStatus_TSI_Success) { return status; } tsiState->isBlockingMeasure = true; do { syncStatus = OSA_SemaWait(&tsiState->irqSync, 1000); /* 1 second timeout. */ }while(syncStatus == kStatus_OSA_Idle); if (syncStatus != kStatus_OSA_Success) { /* Abort the measurement so it doesn't continue unexpectedly.*/ TSI_DRV_AbortMeasure(instance); return kStatus_TSI_Error; } return kStatus_TSI_Success; }
/*FUNCTION********************************************************************** * * Function Name : LPSCI_DRV_ReceiveDataBlocking * Description : This function receives data from LPSCI using a blocking * method. It does not return until the receive is complete. * *END**************************************************************************/ lpsci_status_t LPSCI_DRV_ReceiveDataBlocking(uint32_t instance, uint8_t * rxBuff, uint32_t rxSize, uint32_t timeout) { assert(rxBuff); assert(instance < HW_UART0_INSTANCE_COUNT); lpsci_state_t * lpsciState = (lpsci_state_t *)g_lpsciStatePtr[instance]; lpsci_status_t retVal = kStatus_LPSCI_Success; osa_status_t syncStatus; lpsciState->isRxBlocking = true; retVal = LPSCI_DRV_StartReceiveData(instance, rxBuff, rxSize); if (retVal == kStatus_LPSCI_Success) { /* Wait until all the data is received or for timeout.*/ do { syncStatus = OSA_SemaWait(&lpsciState->rxIrqSync, timeout); }while(syncStatus == kStatus_OSA_Idle); if (syncStatus != kStatus_OSA_Success) { /* Abort the transfer so it doesn't continue unexpectedly.*/ LPSCI_DRV_CompleteSendData(instance); retVal = kStatus_LPSCI_Timeout; } } return retVal; }
/*FUNCTION********************************************************************** * * Function Name : LPSCI_DRV_SendDataBlocking * Description : This function sends data out through the LPSCI module using a * blocking method. It does not return until the transmit is complete. * *END**************************************************************************/ lpsci_status_t LPSCI_DRV_SendDataBlocking(uint32_t instance, const uint8_t * txBuff, uint32_t txSize, uint32_t timeout) { assert(txBuff); assert(instance < HW_UART0_INSTANCE_COUNT); lpsci_state_t * lpsciState = (lpsci_state_t *)g_lpsciStatePtr[instance]; lpsci_status_t retVal = kStatus_LPSCI_Success; osa_status_t syncStatus; lpsciState->isTxBlocking = true; /* Start the transmission process */ retVal = LPSCI_DRV_StartSendData(instance, txBuff, txSize); if (retVal == kStatus_LPSCI_Success) { /* Wait until the transmit is complete. */ do { syncStatus = OSA_SemaWait(&lpsciState->txIrqSync, timeout); }while(syncStatus == kStatus_OSA_Idle); if (syncStatus != kStatus_OSA_Success) { /* Abort the transfer so it doesn't continue unexpectedly.*/ LPSCI_DRV_CompleteSendData(instance); retVal = kStatus_LPSCI_Timeout; } } return retVal; }
/*FUNCTION********************************************************************** * * Function Name : DSPI_DRV_MasterTransferBlocking * Description : Perform a blocking SPI master mode transfer. * This function simultaneously sends and receives data on the SPI bus, as SPI is naturally * a full-duplex bus. The function will not return until the transfer is complete. * *END**************************************************************************/ dspi_status_t DSPI_DRV_MasterTransferBlocking(uint32_t instance, const dspi_device_t * device, const uint8_t * sendBuffer, uint8_t * receiveBuffer, size_t transferByteCount, uint32_t timeout) { /* instantiate local variable of type dspi_master_state_t and point to global state */ dspi_master_state_t * dspiState = (dspi_master_state_t *)g_dspiStatePtr[instance]; SPI_Type *base = g_dspiBase[instance]; dspi_status_t error = kStatus_DSPI_Success; /* If the transfer count is zero, then return immediately.*/ if (transferByteCount == 0) { return error; } /* As this is a synchronous transfer, set up the sync status variable*/ osa_status_t syncStatus; /* fill in members of the run-time state struct*/ dspiState->isTransferBlocking = true; /* Indicates this is a blocking transfer */ dspiState->sendBuffer = (const uint8_t *)sendBuffer; dspiState->receiveBuffer = (uint8_t *)receiveBuffer; dspiState->remainingSendByteCount = transferByteCount; dspiState->remainingReceiveByteCount = transferByteCount; /* start the transfer process*/ if (DSPI_DRV_MasterStartTransfer(instance, device) == kStatus_DSPI_Busy) { return kStatus_DSPI_Busy; } /* As this is a synchronous transfer, wait until the transfer is complete.*/ do { syncStatus = OSA_SemaWait(&dspiState->irqSync, timeout); }while(syncStatus == kStatus_OSA_Idle); /* If a timeout occurs, stop the transfer by setting the isTransferInProgress to false and * disabling interrupts, then return the timeout error status. */ if (syncStatus != kStatus_OSA_Success) { /* The transfer is complete.*/ dspiState->isTransferInProgress = false; /* Disable interrupt requests*/ /* RX FIFO Drain request: RFDF_RE */ DSPI_HAL_SetRxFifoDrainDmaIntMode(base, kDspiGenerateIntReq, false); /* Disable TX FIFO Fill request */ DSPI_HAL_SetTxFifoFillDmaIntMode(base, kDspiGenerateIntReq, false); error = kStatus_DSPI_Timeout; } return error; }
/*FUNCTION********************************************************************** * * Function Name : SPI_DRV_MasterTransferBlocking * Description : Performs a blocking SPI master mode transfer. * This function simultaneously sends and receives data on the SPI bus, as SPI is naturally * a full-duplex bus. The function will not return until the transfer is complete. * *END**************************************************************************/ spi_status_t SPI_DRV_MasterTransferBlocking(uint32_t instance, const spi_master_user_config_t * device, const uint8_t * sendBuffer, uint8_t * receiveBuffer, size_t transferByteCount, uint32_t timeout) { /* instantiate local variable of type spi_master_state_t and point to global state */ spi_master_state_t * spiState = (spi_master_state_t *)g_spiStatePtr[instance]; spi_status_t errorStatus = kStatus_SPI_Success; SPI_Type *base = g_spiBase[instance]; /* fill in members of the run-time state struct*/ spiState->isTransferBlocking = true; /* Indicates this is a blocking transfer */ spiState->sendBuffer = (const uint8_t *)sendBuffer; spiState->receiveBuffer = (uint8_t *)receiveBuffer; spiState->remainingSendByteCount = transferByteCount; spiState->remainingReceiveByteCount = transferByteCount; /* start the transfer process*/ errorStatus = SPI_DRV_MasterStartTransfer(instance, device); if (errorStatus != kStatus_SPI_Success) { return errorStatus; } /* As this is a synchronous transfer, wait until the transfer is complete.*/ osa_status_t syncStatus; do { syncStatus = OSA_SemaWait(&spiState->irqSync, timeout); }while(syncStatus == kStatus_OSA_Idle); /* If a timeout occurs, stop the transfer by setting the isTransferInProgress to false and * disabling interrupts, then return the timeout error status. */ if (syncStatus != kStatus_OSA_Success) { /* The transfer is complete.*/ spiState->isTransferInProgress = false; /* Disable interrupts */ SPI_HAL_SetIntMode(base, kSpiRxFullAndModfInt, false); SPI_HAL_SetIntMode(base, kSpiTxEmptyInt, false); #if FSL_FEATURE_SPI_16BIT_TRANSFERS if (g_spiFifoSize[instance] != 0) { /* Now disable the SPI FIFO interrupts */ SPI_HAL_SetFifoIntCmd(base, kSpiTxFifoNearEmptyInt, false); SPI_HAL_SetFifoIntCmd(base, kSpiRxFifoNearFullInt, false); } #endif errorStatus = kStatus_SPI_Timeout; } return errorStatus; }
/*FUNCTION********************************************************************** * * Function Name : SND_WaitEvent * Description : This function is used for appliaction to wait for the semaphore * to copy data in/out the sai buffer. *END**************************************************************************/ void SND_WaitEvent(sound_card_t *card) { osa_status_t syncStatus; audio_buffer_t *buffer = &card->buffer; do { syncStatus = OSA_SemaWait(&buffer->sem, OSA_WAIT_FOREVER); }while(syncStatus == kStatus_OSA_Idle); }
/*FUNCTION********************************************************************** * * Function Name : DSPI_DRV_DmaMasterTransferBlocking * Description : Performs a blocking SPI master mode transfer with DMA support. * * This function simultaneously sends and receives data on the SPI bus, as SPI is naturally * a full-duplex bus. The function does not return until the transfer is complete. * *END**************************************************************************/ dspi_status_t DSPI_DRV_DmaMasterTransferBlocking(uint32_t instance, const dspi_dma_device_t * device, const uint8_t * sendBuffer, uint8_t * receiveBuffer, size_t transferByteCount, uint32_t timeout) { /* instantiate local variable of type dspi_dma_master_state_t and point to global state */ dspi_dma_master_state_t * dspiDmaState = (dspi_dma_master_state_t *)g_dspiStatePtr[instance]; SPI_Type *base = g_dspiBase[instance]; dspi_status_t error = kStatus_DSPI_Success; /* If the transfer count is zero, then return immediately.*/ if (transferByteCount == 0) { return kStatus_DSPI_InvalidParameter; } dspiDmaState->isTransferBlocking = true; /* Indicates this is a blocking transfer */ /* As this is a synchronous transfer, set up the sync status variable*/ osa_status_t syncStatus; if (DSPI_DRV_DmaMasterStartTransfer(instance, device, sendBuffer, receiveBuffer, transferByteCount) == kStatus_DSPI_Busy) { return kStatus_DSPI_Busy; } /* As this is a synchronous transfer, wait until the transfer is complete.*/ do { syncStatus = OSA_SemaWait(&dspiDmaState->irqSync, timeout); } while(syncStatus == kStatus_OSA_Idle); /* If a timeout occurs, stop the transfer by setting the isTransferInProgress to false and * disabling DMA requests and interrupts, then return the timeout error status. */ if (syncStatus != kStatus_OSA_Success) { /* The transfer is complete.*/ dspiDmaState->isTransferInProgress = false; /* Disable the Receive FIFO Drain DMA Request */ DSPI_HAL_SetRxFifoDrainDmaIntMode(base, kDspiGenerateDmaReq, false); /* Disable TFFF DMA request */ DSPI_HAL_SetTxFifoFillDmaIntMode(base, kDspiGenerateDmaReq, false); /* Disable End of Queue request */ DSPI_HAL_SetIntMode(base, kDspiEndOfQueue, false); error = kStatus_DSPI_Timeout; } return error; }
/** * set wakeup source * @param wakeupSrc entity which will wake up the MCU */ power_status_t power_SetWakeSource( power_wake_src_t wakeSrc ) { if ( kStatus_OSA_Success == OSA_SemaWait( &power_wakeSrcSema, 0 ) ) { currentWakeSrc = wakeSrc; return POWER_STATUS_SUCCESS; } else { return POWER_STATUS_ERROR; } }
/** * take semaphore to signalize the wake-up happened * @return status flag */ power_status_t power_TakeFromSTSema() { osa_status_t status = OSA_SemaWait( &power_STSema, 0 ); if ( kStatus_OSA_Success == status ) { return POWER_STATUS_SUCCESS; } else { return POWER_STATUS_ERROR; } }
static int nio_dummy_write(void *dev_context, void *fp_context, const void *buf, size_t nbytes, int *error) { NIO_DUMMY_DEV_CONTEXT_STRUCT *devc = (NIO_DUMMY_DEV_CONTEXT_STRUCT*)dev_context; NIO_DUMMY_FP_CONTEXT_STRUCT *fpc = (NIO_DUMMY_FP_CONTEXT_STRUCT*)fp_context; fpc->wcnt += nbytes; OSA_SemaWait(&devc->lock, OSA_WAIT_FOREVER); devc->total += nbytes; devc->wtotal += nbytes; OSA_SemaPost(&devc->lock); /* todo: replace with OSA yield. Not part of OSA yet */ OSA_TimeDelay(1); return 0; }
/** * task in charge for putting HEXIWEAR to sleep * @param param optional parameter */ static void power_Task( void* param ) { while (1) { osa_status_t status = OSA_SemaWait( &power_sema, OSA_WAIT_FOREVER ); if ( kStatus_OSA_Success == status ) { while ( POWER_STATUS_SUCCESS != power_Sleep() ) { OSA_TimeDelay( 100 ); } } else { catch( CATCH_SEMAPHORE ); } } }
/*FUNCTION********************************************************************** * * Function Name : LPUART_DRV_ReceiveDataBlocking * Description : This function receives data from LPUART module using blocking * method, the function does not return until the receive is complete. * *END**************************************************************************/ lpuart_status_t LPUART_DRV_ReceiveDataBlocking(uint32_t instance, uint8_t * rxBuff, uint32_t rxSize, uint32_t timeout) { assert(rxBuff); assert(instance < LPUART_INSTANCE_COUNT); lpuart_state_t * lpuartState = (lpuart_state_t *)g_lpuartStatePtr[instance]; LPUART_Type * base = g_lpuartBase[instance]; lpuart_status_t retVal = kStatus_LPUART_Success; osa_status_t syncStatus; /* Indicates this is a blocking transaction. */ lpuartState->isRxBlocking = true; retVal = LPUART_DRV_StartReceiveData(instance, rxBuff, rxSize); if (retVal == kStatus_LPUART_Success) { /* Wait until the receive is complete. */ do { syncStatus = OSA_SemaWait(&lpuartState->rxIrqSync, timeout); } while(syncStatus == kStatus_OSA_Idle); if (syncStatus != kStatus_OSA_Success) { /* Disable receive data full and rx overrun interrupt. */ LPUART_BWR_CTRL_RIE(base, 0U); LPUART_HAL_SetIntMode(base, kLpuartIntRxOverrun, false); /* Update the information of the module driver state */ lpuartState->isRxBusy = false; retVal = kStatus_LPUART_Timeout; } } return retVal; }
/*FUNCTION********************************************************************** * * Function Name : LPUART_DRV_SendDataBlocking * Description : This function sends data out through the LPUART module using * blocking method. The function does not return until the transmit is complete. * *END**************************************************************************/ lpuart_status_t LPUART_DRV_SendDataBlocking(uint32_t instance, const uint8_t * txBuff, uint32_t txSize, uint32_t timeout) { assert(txBuff); assert(instance < LPUART_INSTANCE_COUNT); lpuart_state_t * lpuartState = (lpuart_state_t *)g_lpuartStatePtr[instance]; LPUART_Type * base = g_lpuartBase[instance]; lpuart_status_t retVal = kStatus_LPUART_Success; osa_status_t syncStatus; /* Indicates this is a blocking transaction. */ lpuartState->isTxBlocking = true; /* Start the transmission process */ retVal = LPUART_DRV_StartSendData(instance, txBuff, txSize); if (retVal == kStatus_LPUART_Success) { /* Wait until the transmit is complete. */ do { syncStatus = OSA_SemaWait(&lpuartState->txIrqSync, timeout); } while(syncStatus == kStatus_OSA_Idle); if (syncStatus != kStatus_OSA_Success) { /* Disable transmission complete interrupt */ LPUART_BWR_CTRL_TIE(base, 0U); /* Update the information of the module driver state */ lpuartState->isTxBusy = false; retVal = kStatus_LPUART_Timeout; } } return retVal; }
/*FUNCTION********************************************************************** * * Function Name : UART_DRV_EdmaSendDataBlocking * Description : Sends (transmits) data out through the UART-DMA module * using a blocking method. * *END**************************************************************************/ uart_status_t UART_DRV_EdmaSendDataBlocking(uint32_t instance, const uint8_t * txBuff, uint32_t txSize, uint32_t timeout) { assert(txBuff); assert(instance < UART_INSTANCE_COUNT); uart_edma_state_t * uartEdmaState = (uart_edma_state_t *)g_uartStatePtr[instance]; uart_status_t retVal = kStatus_UART_Success; osa_status_t syncStatus; /* Indicates current transaction is blocking. */ uartEdmaState->isTxBlocking = true; /* Start the transmission process */ retVal = UART_DRV_EdmaStartSendData(instance, txBuff, txSize); if (retVal == kStatus_UART_Success) { /* Wait until the transmit is complete. */ do { syncStatus = OSA_SemaWait(&uartEdmaState->txIrqSync, timeout); }while(syncStatus == kStatus_OSA_Idle); if (syncStatus != kStatus_OSA_Success) { /* Stop DMA channel. */ EDMA_DRV_StopChannel(&uartEdmaState->edmaUartTx); /* Update the information of the module driver state */ uartEdmaState->isTxBusy = false; retVal = kStatus_UART_Timeout; } } return retVal; }
/*FUNCTION********************************************************************** * * Function Name : UART_DRV_EdmaReceiveDataBlocking * Description : This function gets (receives) data from the UART module using * a blocking method. A blocking (also known as synchronous) function means that * the function does not return until the receive is complete. This blocking * function is used to send data through the UART port. * *END**************************************************************************/ uart_status_t UART_DRV_EdmaReceiveDataBlocking(uint32_t instance, uint8_t * rxBuff, uint32_t rxSize, uint32_t timeout) { assert(rxBuff); assert(instance < UART_INSTANCE_COUNT); uart_edma_state_t * uartEdmaState = (uart_edma_state_t *)g_uartStatePtr[instance]; uart_status_t retVal = kStatus_UART_Success; osa_status_t syncStatus; /* Indicates current transaction is blocking. */ uartEdmaState->isRxBlocking = true; retVal = UART_DRV_EdmaStartReceiveData(instance, rxBuff, rxSize); if (retVal == kStatus_UART_Success) { /* Wait until all the data is received or for timeout.*/ do { syncStatus = OSA_SemaWait(&uartEdmaState->rxIrqSync, timeout); }while(syncStatus == kStatus_OSA_Idle); if (syncStatus != kStatus_OSA_Success) { /* Stop DMA channel. */ EDMA_DRV_StopChannel(&uartEdmaState->edmaUartRx); /* Update the information of the module driver state */ uartEdmaState->isRxBusy = false; retVal = kStatus_UART_Timeout; } } return retVal; }