mbed library sources. Supersedes mbed-src.
Fork of mbed-dev by
Diff: targets/TARGET_NUVOTON/TARGET_M451/serial_api.c
- Revision:
- 161:2cc1468da177
- Parent:
- 153:fa9ff456f731
- Child:
- 165:e614a9f1c9e2
diff -r d5399cc887bb -r 2cc1468da177 targets/TARGET_NUVOTON/TARGET_M451/serial_api.c --- a/targets/TARGET_NUVOTON/TARGET_M451/serial_api.c Tue Mar 14 16:40:56 2017 +0000 +++ b/targets/TARGET_NUVOTON/TARGET_M451/serial_api.c Thu Mar 30 13:45:57 2017 +0100 @@ -255,7 +255,7 @@ void serial_baud(serial_t *obj, int baudrate) { // Flush Tx FIFO. Otherwise, output data may get lost on this change. - while (! UART_IS_TX_EMPTY(((UART_T *) obj->serial.uart))); + while (! UART_IS_TX_EMPTY(((UART_T *) NU_MODBASE(obj->serial.uart)))); obj->serial.baudrate = baudrate; UART_Open((UART_T *) NU_MODBASE(obj->serial.uart), baudrate); @@ -263,7 +263,7 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits) { // Flush Tx FIFO. Otherwise, output data may get lost on this change. - while (! UART_IS_TX_EMPTY(((UART_T *) obj->serial.uart))); + while (! UART_IS_TX_EMPTY(((UART_T *) NU_MODBASE(obj->serial.uart)))); // TODO: Assert for not supported parity and data bits obj->serial.databits = data_bits; @@ -325,7 +325,7 @@ void serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id) { // Flush Tx FIFO. Otherwise, output data may get lost on this change. - while (! UART_IS_TX_EMPTY(((UART_T *) obj->serial.uart))); + while (! UART_IS_TX_EMPTY(((UART_T *) NU_MODBASE(obj->serial.uart)))); const struct nu_modinit_s *modinit = get_modinit(obj->serial.uart, uart_modinit_tab); MBED_ASSERT(modinit != NULL); @@ -502,7 +502,9 @@ MBED_ASSERT(modinit != NULL); MBED_ASSERT(modinit->modname == obj->serial.uart); - PDMA->CHCTL |= 1 << obj->serial.dma_chn_id_tx; // Enable this DMA channel + PDMA_T *pdma_base = dma_modbase(); + + pdma_base->CHCTL |= 1 << obj->serial.dma_chn_id_tx; // Enable this DMA channel PDMA_SetTransferMode(obj->serial.dma_chn_id_tx, ((struct nu_uart_var *) modinit->var)->pdma_perp_tx, // Peripheral connected to this PDMA 0, // Scatter-gather disabled @@ -515,7 +517,7 @@ // NUC472: End of source address // M451: Start of source address PDMA_SAR_INC, // Source address incremental - (uint32_t) obj->serial.uart, // Destination address + (uint32_t) NU_MODBASE(obj->serial.uart), // Destination address PDMA_DAR_FIX); // Destination address fixed PDMA_SetBurstType(obj->serial.dma_chn_id_tx, PDMA_REQ_SINGLE, // Single mode @@ -563,7 +565,9 @@ MBED_ASSERT(modinit != NULL); MBED_ASSERT(modinit->modname == obj->serial.uart); - PDMA->CHCTL |= 1 << obj->serial.dma_chn_id_rx; // Enable this DMA channel + PDMA_T *pdma_base = dma_modbase(); + + pdma_base->CHCTL |= 1 << obj->serial.dma_chn_id_rx; // Enable this DMA channel PDMA_SetTransferMode(obj->serial.dma_chn_id_rx, ((struct nu_uart_var *) modinit->var)->pdma_perp_rx, // Peripheral connected to this PDMA 0, // Scatter-gather disabled @@ -572,7 +576,7 @@ (rx_width == 8) ? PDMA_WIDTH_8 : (rx_width == 16) ? PDMA_WIDTH_16 : PDMA_WIDTH_32, rx_length); PDMA_SetTransferAddr(obj->serial.dma_chn_id_rx, - (uint32_t) obj->serial.uart, // Source address + (uint32_t) NU_MODBASE(obj->serial.uart), // Source address PDMA_SAR_FIX, // Source address fixed (uint32_t) rx, // NOTE: // NUC472: End of destination address @@ -593,14 +597,16 @@ void serial_tx_abort_asynch(serial_t *obj) { // Flush Tx FIFO. Otherwise, output data may get lost on this change. - while (! UART_IS_TX_EMPTY(((UART_T *) obj->serial.uart))); + while (! UART_IS_TX_EMPTY(((UART_T *) NU_MODBASE(obj->serial.uart)))); if (obj->serial.dma_usage_tx != DMA_USAGE_NEVER) { + PDMA_T *pdma_base = dma_modbase(); + if (obj->serial.dma_chn_id_tx != DMA_ERROR_OUT_OF_CHANNELS) { PDMA_DisableInt(obj->serial.dma_chn_id_tx, PDMA_INT_TRANS_DONE); // FIXME: On NUC472, next PDMA transfer will fail with PDMA_STOP() called. Cause is unknown. //PDMA_STOP(obj->serial.dma_chn_id_tx); - PDMA->CHCTL &= ~(1 << obj->serial.dma_chn_id_tx); + pdma_base->CHCTL &= ~(1 << obj->serial.dma_chn_id_tx); } UART_DISABLE_INT(((UART_T *) NU_MODBASE(obj->serial.uart)), UART_INTEN_TXPDMAEN_Msk); } @@ -615,11 +621,13 @@ void serial_rx_abort_asynch(serial_t *obj) { if (obj->serial.dma_usage_rx != DMA_USAGE_NEVER) { + PDMA_T *pdma_base = dma_modbase(); + if (obj->serial.dma_chn_id_rx != DMA_ERROR_OUT_OF_CHANNELS) { PDMA_DisableInt(obj->serial.dma_chn_id_rx, PDMA_INT_TRANS_DONE); // FIXME: On NUC472, next PDMA transfer will fail with PDMA_STOP() called. Cause is unknown. //PDMA_STOP(obj->serial.dma_chn_id_rx); - PDMA->CHCTL &= ~(1 << obj->serial.dma_chn_id_rx); + pdma_base->CHCTL &= ~(1 << obj->serial.dma_chn_id_rx); } UART_DISABLE_INT(((UART_T *) NU_MODBASE(obj->serial.uart)), UART_INTEN_RXPDMAEN_Msk); }