/******************************************************************************* * Function Name: BLEIOT_UART_Stop ******************************************************************************** * * Summary: * Disables the SCB component and its interrupt. * It also disables all TX interrupt sources so as not to cause an unexpected * interrupt trigger because after the component is enabled, the TX FIFO * is empty. * * Parameters: * None * * Return: * None * *******************************************************************************/ void BLEIOT_UART_Stop(void) { #if (BLEIOT_UART_SCB_IRQ_INTERNAL) BLEIOT_UART_DisableInt(); #endif /* (BLEIOT_UART_SCB_IRQ_INTERNAL) */ /* Call Stop function specific to current operation mode */ BLEIOT_UART_ScbModeStop(); /* Disable SCB IP */ BLEIOT_UART_CTRL_REG &= (uint32) ~BLEIOT_UART_CTRL_ENABLED; /* Disable all TX interrupt sources so as not to cause an unexpected * interrupt trigger because after the component is enabled, the TX FIFO * is empty. * For SCB IP v0, it is critical as it does not mask-out interrupt * sources when they are disabled. This can cause a code lock-up in the * interrupt handler because TX FIFO cannot be loaded after the block * is disabled. */ BLEIOT_UART_SetTxInterruptMode(BLEIOT_UART_NO_INTR_SOURCES); #if (BLEIOT_UART_SCB_IRQ_INTERNAL) BLEIOT_UART_ClearPendingInt(); #endif /* (BLEIOT_UART_SCB_IRQ_INTERNAL) */ }
/******************************************************************************* * Function Name: BLEIOT_UART_UartGetByte ******************************************************************************** * * Summary: * Retrieves the next data element from the receive buffer, returns the * received byte and error condition. * - The RX software buffer is disabled: returns the data element retrieved * from the RX FIFO. Undefined data will be returned if the RX FIFO is * empty. * - The RX software buffer is enabled: returns data element from the * software receive buffer. * * Parameters: * None * * Return: * Bits 7-0 contain the next data element from the receive buffer and * other bits contain the error condition. * * Side Effects: * The errors bits may not correspond with reading characters due to RX FIFO * and software buffer usage. * RX software buffer is disabled: The internal software buffer overflow * is not returned as status by this function. * Check SCB_rxBufferOverflow to capture that error condition. * *******************************************************************************/ uint32 BLEIOT_UART_UartGetByte(void) { uint32 rxData; uint32 tmpStatus; #if (BLEIOT_UART_CHECK_RX_SW_BUFFER) { BLEIOT_UART_DisableInt(); } #endif if (0u != BLEIOT_UART_SpiUartGetRxBufferSize()) { /* Enables interrupt to receive more bytes: at least one byte is in * buffer. */ #if (BLEIOT_UART_CHECK_RX_SW_BUFFER) { BLEIOT_UART_EnableInt(); } #endif /* Get received byte */ rxData = BLEIOT_UART_SpiUartReadRxData(); } else { /* Reads a byte directly from RX FIFO: underflow is raised in the case * of empty. Otherwise the first received byte will be read. */ rxData = BLEIOT_UART_RX_FIFO_RD_REG; /* Enables interrupt to receive more bytes. * The RX_NOT_EMPTY interrupt is cleared by the interrupt routine * in case the byte was received and read by code above. */ #if (BLEIOT_UART_CHECK_RX_SW_BUFFER) { BLEIOT_UART_EnableInt(); } #endif } /* Get and clear RX error mask */ tmpStatus = (BLEIOT_UART_GetRxInterruptSource() & BLEIOT_UART_INTR_RX_ERR); BLEIOT_UART_ClearRxInterruptSource(BLEIOT_UART_INTR_RX_ERR); /* Puts together data and error status: * MP mode and accept address: 9th bit is set to notify mark. */ rxData |= ((uint32) (tmpStatus << 8u)); return (rxData); }