/***************************************************************************** * @fn HalUARTReadDMA * * @brief Read a buffer from the UART * * @param buf - valid data buffer at least 'len' bytes in size * len - max length number of bytes to copy to 'buf' * * @return length of buffer that was read *****************************************************************************/ static uint16 HalUARTReadDMA(uint8 *buf, uint16 len) { uint16 cnt; for (cnt = 0; cnt < len; cnt++) { if (!HAL_UART_DMA_NEW_RX_BYTE(dmaCfg.rxHead)) { break; } *buf++ = HAL_UART_DMA_GET_RX_BYTE(dmaCfg.rxHead); HAL_UART_DMA_CLR_RX_BYTE(dmaCfg.rxHead); HAL_UART_RX_IDX_T_INCR(dmaCfg.rxHead); } if (!DMA_PM && (UxUCR & UCR_FLOW)) { if (HalUARTRxAvailDMA() < HAL_UART_DMA_HIGH) { HAL_UART_DMA_SET_RDY_OUT(); // Re-enable the flow asap (i.e. not wait until next uart poll). } } return cnt; }
/***************************************************************************** * @fn HalUARTReadDMA * * @brief Read a buffer from the UART * * @param buf - valid data buffer at least 'len' bytes in size * len - max length number of bytes to copy to 'buf' * * @return length of buffer that was read *****************************************************************************/ static uint16 HalUARTReadDMA(uint8 *buf, uint16 len) { uint16 cnt; for (cnt = 0; cnt < len; cnt++) { if (!HAL_UART_DMA_NEW_RX_BYTE(dmaCfg.rxHead)) { break; } *buf++ = HAL_UART_DMA_GET_RX_BYTE(dmaCfg.rxHead); HAL_UART_DMA_CLR_RX_BYTE(dmaCfg.rxHead); HAL_UART_RX_IDX_T_INCR(dmaCfg.rxHead); } /* Update pointers after reading the bytes */ dmaCfg.rxTail = dmaCfg.rxHead; if (!DMA_PM && (UxUCR & UCR_FLOW)) { HAL_UART_DMA_SET_RDY_OUT(); // Re-enable the flow asap (i.e. not wait until next uart poll). } return cnt; }
/***************************************************************************** * @fn HalUARTReadDMA * * @brief Read a buffer from the UART * * @param buf - valid data buffer at least 'len' bytes in size * len - max length number of bytes to copy to 'buf' * * @return length of buffer that was read *****************************************************************************/ static uint16 HalUARTReadDMA(uint8 *buf, uint16 len) { uint16 cnt; for (cnt = 0; cnt < len; cnt++) { if (!HAL_UART_DMA_NEW_RX_BYTE(dmaCfg.rxHead)) { break; } *buf++ = HAL_UART_DMA_GET_RX_BYTE(dmaCfg.rxHead); HAL_UART_DMA_CLR_RX_BYTE(dmaCfg.rxHead); #if HAL_UART_DMA_RX_MAX == 256 (dmaCfg.rxHead)++; #else if (++(dmaCfg.rxHead) >= HAL_UART_DMA_RX_MAX) { dmaCfg.rxHead = 0; } #endif } PxOUT &= ~HAL_UART_Px_RTS; // Re-enable the flow on any read. return cnt; }