From b6d919df94a20c6d0e514d5d19d03f67b4679d5c Mon Sep 17 00:00:00 2001 From: Jake Carter Date: Mon, 9 Oct 2023 14:51:15 -0500 Subject: [PATCH 01/27] Fix DMA channel leak in UART RevA Initialize state struct --- .../PeriphDrivers/Source/UART/uart_reva.c | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/Libraries/PeriphDrivers/Source/UART/uart_reva.c b/Libraries/PeriphDrivers/Source/UART/uart_reva.c index 10f85e0374a..2034c52dc2c 100644 --- a/Libraries/PeriphDrivers/Source/UART/uart_reva.c +++ b/Libraries/PeriphDrivers/Source/UART/uart_reva.c @@ -98,6 +98,13 @@ int MXC_UART_RevA_Init(mxc_uart_reva_regs_t *uart, unsigned int baud) MXC_UART_SetFrequency((mxc_uart_regs_t *)uart, baud); + // Initialize state struct + for (int i = 0; i < MXC_UART_INSTANCES; i++) { + states[i].channelRx = -1; + states[i].channelTx = -1; + states[i].req = NULL; + } + return E_NO_ERROR; } @@ -942,6 +949,8 @@ int MXC_UART_RevA_TransactionDMA(mxc_uart_reva_req_t *req, mxc_dma_regs_t *dma) } } + states[uart_num].req = req; // Callback lookups are dependent saved state info + MXC_UART_DisableInt((mxc_uart_regs_t *)(req->uart), 0xFFFFFFFF); MXC_UART_ClearFlags((mxc_uart_regs_t *)(req->uart), 0xFFFFFFFF); @@ -996,21 +1005,15 @@ void MXC_UART_RevA_DMACallback(int ch, int error) mxc_uart_reva_req_t *temp_req; for (int i = 0; i < MXC_UART_INSTANCES; i++) { - if (states[i].channelTx == ch) { - //save the request - temp_req = states[i].req; - // Callback if not NULL - if (temp_req->callback != NULL) { - temp_req->callback((mxc_uart_req_t *)temp_req, E_NO_ERROR); - } - break; - } else if (states[i].channelRx == ch) { + if (states[i].channelTx == ch || states[i].channelRx == ch) { //save the request temp_req = states[i].req; // Callback if not NULL if (temp_req->callback != NULL) { temp_req->callback((mxc_uart_req_t *)temp_req, E_NO_ERROR); } + + MXC_DMA_ReleaseChannel(ch); break; } } From b9393ea5a6a0fe094fd2d92620e0122c8a11bb38 Mon Sep 17 00:00:00 2001 From: Jake Carter Date: Mon, 9 Oct 2023 17:27:54 -0500 Subject: [PATCH 02/27] Add MXC_DMA_CH_GET_IRQ for ME14 Add MXC_DMA_CH_GET_IRQ for ME14 --- Libraries/CMSIS/Device/Maxim/MAX32665/Include/max32665.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Libraries/CMSIS/Device/Maxim/MAX32665/Include/max32665.h b/Libraries/CMSIS/Device/Maxim/MAX32665/Include/max32665.h index 1f7bee65b1f..d236343d3ed 100644 --- a/Libraries/CMSIS/Device/Maxim/MAX32665/Include/max32665.h +++ b/Libraries/CMSIS/Device/Maxim/MAX32665/Include/max32665.h @@ -499,6 +499,9 @@ typedef enum { ((i) == 7) ? DMA15_IRQn : \ 0)) +#define MXC_DMA_CH_GET_IRQ(i) \ + (((i) > (MXC_DMA_CH_OFFSET - 1)) ? MXC_DMA1_CH_GET_IRQ(i % MXC_DMA_CH_OFFSET) : MXC_DMA0_CH_GET_IRQ(i)) + /* Create alias for MXC_DMA0 for backwards compatibility with code that was written for parts that only had one DMA instance. */ #define MXC_DMA MXC_DMA0 From 34276b4a6963b37d2752fa9ecb87c09144368497 Mon Sep 17 00:00:00 2001 From: Jake Carter Date: Mon, 9 Oct 2023 18:15:47 -0500 Subject: [PATCH 03/27] Checkpoint: auto interrupt handlers (not totally compatible with old code) --- .../PeriphDrivers/Source/UART/uart_reva.c | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/Libraries/PeriphDrivers/Source/UART/uart_reva.c b/Libraries/PeriphDrivers/Source/UART/uart_reva.c index 2034c52dc2c..4349801e6a8 100644 --- a/Libraries/PeriphDrivers/Source/UART/uart_reva.c +++ b/Libraries/PeriphDrivers/Source/UART/uart_reva.c @@ -37,6 +37,9 @@ #include "uart.h" #include "uart_reva.h" #include "dma.h" +#ifdef __arm__ +#include "nvic_table.h" +#endif /* **** Definitions **** */ #define MXC_UART_REVA_ERRINT_EN \ @@ -555,6 +558,43 @@ unsigned int MXC_UART_RevA_ReadRXFIFO(mxc_uart_reva_regs_t *uart, unsigned char return read; } +#if MXC_DMA_INSTANCES > 1 + +void MXC_UART_RevA_DMA0_Handler(void) +{ + MXC_DMA_Handler(MXC_DMA0); +} + +void MXC_UART_RevA_DMA1_Handler(void) +{ + MXC_DMA_Handler(MXC_DMA1); +} + +#endif + +void MXC_UART_RevA_DMA_SetupChannel(mxc_dma_regs_t *dma_instance, unsigned int channel) +{ +#ifdef __arm__ + + NVIC_EnableIRQ(MXC_DMA_CH_GET_IRQ(channel)); + +#if MXC_DMA_INSTANCES > 1 + /* (JC): This is not the cleanest or most scalable way to do this, + but I tried defining default handler's in the system file. + Some complications make this the most attractive short-term + option. We could handle multiple DMA instances better in the DMA API (See the mismatch between the size of "dma_resource" array and the number of channels per instance, to start)*/ + if (dma_instance == MXC_DMA0) { + MXC_NVIC_SetVector(MXC_DMA_CH_GET_IRQ(channel), MXC_UART_RevA_DMA0_Handler); + } else if (dma_instance == MXC_DMA1) { + MXC_NVIC_SetVector(MXC_DMA_CH_GET_IRQ(channel), MXC_UART_RevA_DMA1_Handler); + } +#else + MXC_NVIC_SetVector(MXC_UART_RevA_DMA0_Handler, MXC_DMA_Handler); +#endif // MXC_DMA_INSTANCES > 1 + +#endif // __arm__ +} + int MXC_UART_RevA_ReadRXFIFODMA(mxc_uart_reva_regs_t *uart, mxc_dma_regs_t *dma, unsigned char *bytes, unsigned int len, mxc_uart_dma_complete_cb_t callback, mxc_dma_config_t config) @@ -591,6 +631,12 @@ int MXC_UART_RevA_ReadRXFIFODMA(mxc_uart_reva_regs_t *uart, mxc_dma_regs_t *dma, srcdst.len = len; states[uart_num].channelRx = channel; + + /* + (JC) Since we're automatically acquiring a channel here, we need the + ISR for that channel to call MXC_DMA_Handler. + */ + MXC_UART_RevA_DMA_SetupChannel(dma, channel); MXC_DMA_ConfigChannel(config, srcdst); MXC_DMA_SetCallback(channel, MXC_UART_DMACallback); MXC_DMA_EnableInt(channel); @@ -661,6 +707,12 @@ unsigned int MXC_UART_RevA_WriteTXFIFODMA(mxc_uart_reva_regs_t *uart, mxc_dma_re srcdst.len = len; states[uart_num].channelTx = channel; + + /* + (JC) Since we're automatically acquiring a channel here, we need the + ISR for that channel to call MXC_DMA_Handler. + */ + MXC_UART_RevA_DMA_SetupChannel(dma, channel); MXC_DMA_ConfigChannel(config, srcdst); MXC_DMA_SetCallback(channel, MXC_UART_DMACallback); MXC_DMA_EnableInt(channel); From 77ecaefbd613832c21f8f35fc5ff05e85cac9d5c Mon Sep 17 00:00:00 2001 From: Jake Carter Date: Tue, 10 Oct 2023 17:07:36 -0500 Subject: [PATCH 04/27] UART_RevA: Add APIs for setting DMA handlers, expose to ME14 --- .../PeriphDrivers/Include/MAX32665/uart.h | 6 + .../PeriphDrivers/Source/UART/uart_me14.c | 21 +++ .../PeriphDrivers/Source/UART/uart_reva.c | 122 ++++++++++++++---- .../PeriphDrivers/Source/UART/uart_reva.h | 6 + 4 files changed, 132 insertions(+), 23 deletions(-) diff --git a/Libraries/PeriphDrivers/Include/MAX32665/uart.h b/Libraries/PeriphDrivers/Include/MAX32665/uart.h index 51ec08579ed..e5fe97f3d7b 100644 --- a/Libraries/PeriphDrivers/Include/MAX32665/uart.h +++ b/Libraries/PeriphDrivers/Include/MAX32665/uart.h @@ -700,6 +700,12 @@ uint32_t MXC_UART_GetAsyncTXCount(mxc_uart_req_t *req); */ uint32_t MXC_UART_GetAsyncRXCount(mxc_uart_req_t *req); +int MXC_UART_SetAutoDMAHandlers(mxc_uart_regs_t *uart, bool enable); +int MXC_UART_SetTXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel); +int MXC_UART_GetTXDMAChannel(mxc_uart_regs_t *uart); +int MXC_UART_SetRXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel); +int MXC_UART_GetRXDMAChannel(mxc_uart_regs_t *uart); + /**@} end of group uart */ #ifdef __cplusplus diff --git a/Libraries/PeriphDrivers/Source/UART/uart_me14.c b/Libraries/PeriphDrivers/Source/UART/uart_me14.c index 1163e378101..22a7bcf31a2 100644 --- a/Libraries/PeriphDrivers/Source/UART/uart_me14.c +++ b/Libraries/PeriphDrivers/Source/UART/uart_me14.c @@ -446,3 +446,24 @@ uint32_t MXC_UART_GetAsyncRXCount(mxc_uart_req_t *req) { return req->rxCnt; } + +int MXC_UART_SetAutoDMAHandlers(mxc_uart_regs_t *uart, bool enable) +{ + return MXC_UART_RevA_SetAutoDMAHandlers((mxc_uart_reva_regs_t *)uart, enable); +} +int MXC_UART_SetTXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel) +{ + return MXC_UART_RevA_SetTXDMAChannel((mxc_uart_reva_regs_t *)uart, channel); +} +int MXC_UART_GetTXDMAChannel(mxc_uart_regs_t *uart) +{ + return MXC_UART_RevA_GetTXDMAChannel((mxc_uart_reva_regs_t *)uart); +} +int MXC_UART_SetRXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel) +{ + return MXC_UART_RevA_SetRXDMAChannel((mxc_uart_reva_regs_t *)uart, channel); +} +int MXC_UART_GetRXDMAChannel(mxc_uart_regs_t *uart) +{ + return MXC_UART_RevA_GetRXDMAChannel((mxc_uart_reva_regs_t *)uart); +} diff --git a/Libraries/PeriphDrivers/Source/UART/uart_reva.c b/Libraries/PeriphDrivers/Source/UART/uart_reva.c index 4349801e6a8..ba9ccb05c69 100644 --- a/Libraries/PeriphDrivers/Source/UART/uart_reva.c +++ b/Libraries/PeriphDrivers/Source/UART/uart_reva.c @@ -59,6 +59,7 @@ typedef struct { mxc_uart_reva_req_t *req; int channelTx; int channelRx; + bool auto_dma_handlers; } uart_reva_req_state_t; uart_reva_req_state_t states[MXC_UART_INSTANCES]; @@ -106,6 +107,7 @@ int MXC_UART_RevA_Init(mxc_uart_reva_regs_t *uart, unsigned int baud) states[i].channelRx = -1; states[i].channelTx = -1; states[i].req = NULL; + states[i].auto_dma_handlers = false; } return E_NO_ERROR; @@ -572,10 +574,12 @@ void MXC_UART_RevA_DMA1_Handler(void) #endif -void MXC_UART_RevA_DMA_SetupChannel(mxc_dma_regs_t *dma_instance, unsigned int channel) +/* "Auto" handlers just need to call MXC_DMA_Handler with the correct +DMA instance. +*/ +void MXC_UART_RevA_DMA_SetupAutoHandlers(mxc_dma_regs_t *dma_instance, unsigned int channel) { #ifdef __arm__ - NVIC_EnableIRQ(MXC_DMA_CH_GET_IRQ(channel)); #if MXC_DMA_INSTANCES > 1 @@ -589,9 +593,13 @@ void MXC_UART_RevA_DMA_SetupChannel(mxc_dma_regs_t *dma_instance, unsigned int c MXC_NVIC_SetVector(MXC_DMA_CH_GET_IRQ(channel), MXC_UART_RevA_DMA1_Handler); } #else + // Only one DMA instance, we can point direct to MXC_DMA_Handler MXC_NVIC_SetVector(MXC_UART_RevA_DMA0_Handler, MXC_DMA_Handler); #endif // MXC_DMA_INSTANCES > 1 +#else +// TODO(JC): RISC-V + #endif // __arm__ } @@ -612,11 +620,24 @@ int MXC_UART_RevA_ReadRXFIFODMA(mxc_uart_reva_regs_t *uart, mxc_dma_regs_t *dma, return E_NULL_PTR; } + if (states[uart_num].auto_dma_handlers) { + /* Acquire channel */ #if TARGET_NUM == 32665 - channel = MXC_DMA_AcquireChannel(dma); + channel = MXC_DMA_AcquireChannel(dma); #else - channel = MXC_DMA_AcquireChannel(); + channel = MXC_DMA_AcquireChannel(); #endif + MXC_UART_RevA_SetRXDMAChannel(uart, channel); + /* (JC) Since we're automatically acquiring a channel here, we need the ISR for that channel to call MXC_DMA_Handler. */ + MXC_UART_RevA_DMA_SetupAutoHandlers(dma, channel); + } else { + /* Rely on application-defined handlers. */ + if (states[uart_num].channelRx < 0) + return E_BAD_STATE; + channel = states[uart_num].channelRx; + } + + // states[uart_num].channelRx = channel; config.ch = channel; @@ -628,15 +649,8 @@ int MXC_UART_RevA_ReadRXFIFODMA(mxc_uart_reva_regs_t *uart, mxc_dma_regs_t *dma, srcdst.ch = channel; srcdst.dest = bytes; - srcdst.len = len; - - states[uart_num].channelRx = channel; + srcdst.len = len; - /* - (JC) Since we're automatically acquiring a channel here, we need the - ISR for that channel to call MXC_DMA_Handler. - */ - MXC_UART_RevA_DMA_SetupChannel(dma, channel); MXC_DMA_ConfigChannel(config, srcdst); MXC_DMA_SetCallback(channel, MXC_UART_DMACallback); MXC_DMA_EnableInt(channel); @@ -670,12 +684,63 @@ unsigned int MXC_UART_RevA_WriteTXFIFO(mxc_uart_reva_regs_t *uart, unsigned char return written; } +int MXC_UART_RevA_SetAutoDMAHandlers(mxc_uart_reva_regs_t *uart, bool enable) +{ + int n = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); + if (n < 0) + return E_BAD_PARAM; + + states[n].auto_dma_handlers = enable; + + return E_NO_ERROR; +} + +int MXC_UART_RevA_SetTXDMAChannel(mxc_uart_reva_regs_t *uart, unsigned int channel) +{ + int n = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); + if (n < 0) + return E_BAD_PARAM; + + states[n].channelTx = channel; + + return E_NO_ERROR; +} + +int MXC_UART_RevA_GetTXDMAChannel(mxc_uart_reva_regs_t *uart) +{ + int n = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); + if (n < 0) + return E_BAD_PARAM; + + return states[n].channelTx; +} + +int MXC_UART_RevA_SetRXDMAChannel(mxc_uart_reva_regs_t *uart, unsigned int channel) +{ + int n = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); + if (n < 0) + return E_BAD_PARAM; + + states[n].channelRx = channel; + + return E_NO_ERROR; +} + +int MXC_UART_RevA_GetRXDMAChannel(mxc_uart_reva_regs_t *uart) +{ + int n = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); + if (n < 0) + return E_BAD_PARAM; + + return states[n].channelRx; +} + unsigned int MXC_UART_RevA_WriteTXFIFODMA(mxc_uart_reva_regs_t *uart, mxc_dma_regs_t *dma, unsigned char *bytes, unsigned int len, mxc_uart_dma_complete_cb_t callback, mxc_dma_config_t config) { - uint8_t channel; + uint8_t channel = -1; mxc_dma_srcdst_t srcdst; int uart_num = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); @@ -688,11 +753,22 @@ unsigned int MXC_UART_RevA_WriteTXFIFODMA(mxc_uart_reva_regs_t *uart, mxc_dma_re return E_NULL_PTR; } + if (states[uart_num].auto_dma_handlers) { + /* Acquire channel */ #if TARGET_NUM == 32665 - channel = MXC_DMA_AcquireChannel(dma); + channel = MXC_DMA_AcquireChannel(dma); #else - channel = MXC_DMA_AcquireChannel(); + channel = MXC_DMA_AcquireChannel(); #endif + MXC_UART_RevA_SetTXDMAChannel(uart, channel); // Set state variable + /* (JC) Since we're automatically acquiring a channel here, we need the ISR for that channel to call MXC_DMA_Handler.*/ + MXC_UART_RevA_DMA_SetupAutoHandlers(dma, channel); + } else { + /* Rely on application-defined handlers (from SetTXDMAChannel) */ + if (states[uart_num].channelTx < 0) + return E_BAD_STATE; + channel = MXC_UART_RevA_GetTXDMAChannel(uart); + } config.ch = channel; @@ -706,13 +782,6 @@ unsigned int MXC_UART_RevA_WriteTXFIFODMA(mxc_uart_reva_regs_t *uart, mxc_dma_re srcdst.source = bytes; srcdst.len = len; - states[uart_num].channelTx = channel; - - /* - (JC) Since we're automatically acquiring a channel here, we need the - ISR for that channel to call MXC_DMA_Handler. - */ - MXC_UART_RevA_DMA_SetupChannel(dma, channel); MXC_DMA_ConfigChannel(config, srcdst); MXC_DMA_SetCallback(channel, MXC_UART_DMACallback); MXC_DMA_EnableInt(channel); @@ -1065,7 +1134,14 @@ void MXC_UART_RevA_DMACallback(int ch, int error) temp_req->callback((mxc_uart_req_t *)temp_req, E_NO_ERROR); } - MXC_DMA_ReleaseChannel(ch); + if (states[i].auto_dma_handlers) { + MXC_DMA_ReleaseChannel(ch); + if (ch == states[i].channelRx) + states[i].channelRx = -1; + else + states[i].channelTx = -1; + } + break; } } diff --git a/Libraries/PeriphDrivers/Source/UART/uart_reva.h b/Libraries/PeriphDrivers/Source/UART/uart_reva.h index bba25f14aed..12add458966 100644 --- a/Libraries/PeriphDrivers/Source/UART/uart_reva.h +++ b/Libraries/PeriphDrivers/Source/UART/uart_reva.h @@ -112,4 +112,10 @@ int MXC_UART_RevA_TxAsyncCallback(mxc_uart_reva_regs_t *uart, int retVal); int MXC_UART_RevA_RxAsyncCallback(mxc_uart_reva_regs_t *uart, int retVal); void MXC_UART_RevA_DMACallback(int ch, int error); +int MXC_UART_RevA_SetAutoDMAHandlers(mxc_uart_reva_regs_t *uart, bool enable); +int MXC_UART_RevA_SetTXDMAChannel(mxc_uart_reva_regs_t *uart, unsigned int channel); +int MXC_UART_RevA_GetTXDMAChannel(mxc_uart_reva_regs_t *uart); +int MXC_UART_RevA_SetRXDMAChannel(mxc_uart_reva_regs_t *uart, unsigned int channel); +int MXC_UART_RevA_GetRXDMAChannel(mxc_uart_reva_regs_t *uart); + #endif // LIBRARIES_PERIPHDRIVERS_SOURCE_UART_UART_REVA_H_ From e2a9134cf7105af363d44f3fb1715ccf6e951a00 Mon Sep 17 00:00:00 2001 From: Jake Carter Date: Tue, 10 Oct 2023 17:41:20 -0500 Subject: [PATCH 05/27] clang-format --- .../Device/Maxim/MAX32665/Include/max32665.h | 5 +++-- .../PeriphDrivers/Source/UART/uart_reva.c | 18 +++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Libraries/CMSIS/Device/Maxim/MAX32665/Include/max32665.h b/Libraries/CMSIS/Device/Maxim/MAX32665/Include/max32665.h index d236343d3ed..91c533f2487 100644 --- a/Libraries/CMSIS/Device/Maxim/MAX32665/Include/max32665.h +++ b/Libraries/CMSIS/Device/Maxim/MAX32665/Include/max32665.h @@ -499,8 +499,9 @@ typedef enum { ((i) == 7) ? DMA15_IRQn : \ 0)) -#define MXC_DMA_CH_GET_IRQ(i) \ - (((i) > (MXC_DMA_CH_OFFSET - 1)) ? MXC_DMA1_CH_GET_IRQ(i % MXC_DMA_CH_OFFSET) : MXC_DMA0_CH_GET_IRQ(i)) +#define MXC_DMA_CH_GET_IRQ(i) \ + (((i) > (MXC_DMA_CH_OFFSET - 1)) ? MXC_DMA1_CH_GET_IRQ(i % MXC_DMA_CH_OFFSET) : \ + MXC_DMA0_CH_GET_IRQ(i)) /* Create alias for MXC_DMA0 for backwards compatibility with code that was written for parts that only had one DMA instance. */ diff --git a/Libraries/PeriphDrivers/Source/UART/uart_reva.c b/Libraries/PeriphDrivers/Source/UART/uart_reva.c index ba9ccb05c69..e4777d6bc43 100644 --- a/Libraries/PeriphDrivers/Source/UART/uart_reva.c +++ b/Libraries/PeriphDrivers/Source/UART/uart_reva.c @@ -598,7 +598,7 @@ void MXC_UART_RevA_DMA_SetupAutoHandlers(mxc_dma_regs_t *dma_instance, unsigned #endif // MXC_DMA_INSTANCES > 1 #else -// TODO(JC): RISC-V + // TODO(JC): RISC-V #endif // __arm__ } @@ -620,7 +620,7 @@ int MXC_UART_RevA_ReadRXFIFODMA(mxc_uart_reva_regs_t *uart, mxc_dma_regs_t *dma, return E_NULL_PTR; } - if (states[uart_num].auto_dma_handlers) { + if (states[uart_num].auto_dma_handlers) { /* Acquire channel */ #if TARGET_NUM == 32665 channel = MXC_DMA_AcquireChannel(dma); @@ -649,7 +649,7 @@ int MXC_UART_RevA_ReadRXFIFODMA(mxc_uart_reva_regs_t *uart, mxc_dma_regs_t *dma, srcdst.ch = channel; srcdst.dest = bytes; - srcdst.len = len; + srcdst.len = len; MXC_DMA_ConfigChannel(config, srcdst); MXC_DMA_SetCallback(channel, MXC_UART_DMACallback); @@ -700,7 +700,7 @@ int MXC_UART_RevA_SetTXDMAChannel(mxc_uart_reva_regs_t *uart, unsigned int chann int n = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); if (n < 0) return E_BAD_PARAM; - + states[n].channelTx = channel; return E_NO_ERROR; @@ -711,7 +711,7 @@ int MXC_UART_RevA_GetTXDMAChannel(mxc_uart_reva_regs_t *uart) int n = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); if (n < 0) return E_BAD_PARAM; - + return states[n].channelTx; } @@ -720,7 +720,7 @@ int MXC_UART_RevA_SetRXDMAChannel(mxc_uart_reva_regs_t *uart, unsigned int chann int n = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); if (n < 0) return E_BAD_PARAM; - + states[n].channelRx = channel; return E_NO_ERROR; @@ -731,7 +731,7 @@ int MXC_UART_RevA_GetRXDMAChannel(mxc_uart_reva_regs_t *uart) int n = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); if (n < 0) return E_BAD_PARAM; - + return states[n].channelRx; } @@ -1139,8 +1139,8 @@ void MXC_UART_RevA_DMACallback(int ch, int error) if (ch == states[i].channelRx) states[i].channelRx = -1; else - states[i].channelTx = -1; - } + states[i].channelTx = -1; + } break; } From bd4e60f0a5e398cac7e08c60ca63d4fb8f0d59a1 Mon Sep 17 00:00:00 2001 From: Jake Carter Date: Mon, 16 Oct 2023 14:54:26 -0500 Subject: [PATCH 06/27] Implement autohandlers for UART Rev B --- .../PeriphDrivers/Include/MAX78000/uart.h | 7 + .../PeriphDrivers/Source/UART/uart_ai85.c | 25 ++++ .../PeriphDrivers/Source/UART/uart_revb.c | 140 ++++++++++++++++-- .../PeriphDrivers/Source/UART/uart_revb.h | 6 + 4 files changed, 169 insertions(+), 9 deletions(-) diff --git a/Libraries/PeriphDrivers/Include/MAX78000/uart.h b/Libraries/PeriphDrivers/Include/MAX78000/uart.h index dd82b7632da..9e0260a033b 100644 --- a/Libraries/PeriphDrivers/Include/MAX78000/uart.h +++ b/Libraries/PeriphDrivers/Include/MAX78000/uart.h @@ -41,6 +41,7 @@ #define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX78000_UART_H_ /***** Definitions *****/ +#include #include "uart_regs.h" #include "mxc_sys.h" @@ -671,6 +672,12 @@ uint32_t MXC_UART_GetAsyncTXCount(mxc_uart_req_t *req); */ uint32_t MXC_UART_GetAsyncRXCount(mxc_uart_req_t *req); +int MXC_UART_SetAutoDMAHandlers(mxc_uart_regs_t *uart, bool enable); +int MXC_UART_SetTXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel); +int MXC_UART_GetTXDMAChannel(mxc_uart_regs_t *uart); +int MXC_UART_SetRXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel); +int MXC_UART_GetRXDMAChannel(mxc_uart_regs_t *uart); + /**@} end of group uart */ #ifdef __cplusplus diff --git a/Libraries/PeriphDrivers/Source/UART/uart_ai85.c b/Libraries/PeriphDrivers/Source/UART/uart_ai85.c index 574412c3815..3b89a9cfc3d 100644 --- a/Libraries/PeriphDrivers/Source/UART/uart_ai85.c +++ b/Libraries/PeriphDrivers/Source/UART/uart_ai85.c @@ -481,3 +481,28 @@ uint32_t MXC_UART_GetAsyncRXCount(mxc_uart_req_t *req) { return req->rxCnt; } + +int MXC_UART_SetAutoDMAHandlers(mxc_uart_regs_t *uart, bool enable) +{ + return MXC_UART_RevB_SetAutoDMAHandlers((mxc_uart_revb_regs_t *)uart, enable); +} + +int MXC_UART_SetTXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel) +{ + return MXC_UART_RevB_SetTXDMAChannel((mxc_uart_revb_regs_t *)uart, channel); +} + +int MXC_UART_GetTXDMAChannel(mxc_uart_regs_t *uart) +{ + return MXC_UART_RevB_GetTXDMAChannel((mxc_uart_revb_regs_t *)uart); +} + +int MXC_UART_SetRXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel) +{ + return MXC_UART_RevB_SetRXDMAChannel((mxc_uart_revb_regs_t *)uart, channel); +} + +int MXC_UART_GetRXDMAChannel(mxc_uart_regs_t *uart) +{ + return MXC_UART_RevB_GetTXDMAChannel((mxc_uart_revb_regs_t *)uart); +} diff --git a/Libraries/PeriphDrivers/Source/UART/uart_revb.c b/Libraries/PeriphDrivers/Source/UART/uart_revb.c index 54331393878..458d6cd3e95 100644 --- a/Libraries/PeriphDrivers/Source/UART/uart_revb.c +++ b/Libraries/PeriphDrivers/Source/UART/uart_revb.c @@ -37,6 +37,9 @@ #include "uart.h" #include "uart_revb.h" #include "dma.h" +#ifdef __arm__ +#include "nvic_table.h" +#endif /* **** Definitions **** */ #define MXC_UART_REVB_ERRINT_EN \ @@ -53,6 +56,7 @@ typedef struct { mxc_uart_revb_req_t *req; int channelTx; int channelRx; + bool auto_dma_handlers; } uart_revb_req_state_t; uart_revb_req_state_t states[MXC_UART_INSTANCES]; @@ -95,6 +99,14 @@ int MXC_UART_RevB_Init(mxc_uart_revb_regs_t *uart, unsigned int baud, mxc_uart_r return err; } + // Initialize state struct + for (int i = 0; i < MXC_UART_INSTANCES; i++) { + states[i].channelRx = -1; + states[i].channelTx = -1; + states[i].req = NULL; + states[i].auto_dma_handlers = false; + } + return E_NO_ERROR; } @@ -354,6 +366,22 @@ int MXC_UART_RevB_GetActive(mxc_uart_revb_regs_t *uart) int MXC_UART_RevB_AbortTransmission(mxc_uart_revb_regs_t *uart) { MXC_UART_ClearTXFIFO((mxc_uart_regs_t *)uart); + int uart_num = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); + + if (states[uart_num].channelTx >= 0) { + MXC_DMA_Stop(states[uart_num].channelTx); + } + if (states[uart_num].channelRx >= 0) { + MXC_DMA_Stop(states[uart_num].channelRx); + } + + if (states[uart_num].auto_dma_handlers) { + MXC_DMA_ReleaseChannel(states[uart_num].channelTx); + states[uart_num].channelTx = -1; + MXC_DMA_ReleaseChannel(states[uart_num].channelRx); + states[uart_num].channelRx = -1; + } + return E_NO_ERROR; } @@ -913,6 +941,68 @@ int MXC_UART_RevB_AsyncHandler(mxc_uart_revb_regs_t *uart) return E_NO_ERROR; } +int MXC_UART_RevB_SetAutoDMAHandlers(mxc_uart_revb_regs_t *uart, bool enable) +{ + int n = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); + if (n < 0) + return E_BAD_PARAM; + + states[n].auto_dma_handlers = enable; + + return E_NO_ERROR; +} + +void MXC_UART_RevB_DMA_SetupAutoHandlers(unsigned int channel) +{ +#ifdef __arm__ + NVIC_EnableIRQ(MXC_DMA_CH_GET_IRQ(channel)); + MXC_NVIC_SetVector(MXC_DMA_CH_GET_IRQ(channel), MXC_DMA_Handler); +#else + // TODO(JC): RISC-V + +#endif // __arm__ +} + +int MXC_UART_RevB_SetTXDMAChannel(mxc_uart_revb_regs_t *uart, unsigned int channel) +{ + int n = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); + if (n < 0) + return E_BAD_PARAM; + + states[n].channelTx = channel; + + return E_NO_ERROR; +} + +int MXC_UART_RevB_GetTXDMAChannel(mxc_uart_revb_regs_t *uart) +{ + int n = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); + if (n < 0) + return E_BAD_PARAM; + + return states[n].channelTx; +} + +int MXC_UART_RevB_SetRXDMAChannel(mxc_uart_revb_regs_t *uart, unsigned int channel) +{ + int n = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); + if (n < 0) + return E_BAD_PARAM; + + states[n].channelRx = channel; + + return E_NO_ERROR; +} + +int MXC_UART_RevB_GetRXDMAChannel(mxc_uart_revb_regs_t *uart) +{ + int n = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); + if (n < 0) + return E_BAD_PARAM; + + return states[n].channelRx; +} + int MXC_UART_RevB_ReadRXFIFODMA(mxc_uart_revb_regs_t *uart, unsigned char *bytes, unsigned int len, mxc_uart_dma_complete_cb_t callback, mxc_dma_config_t config) { @@ -929,7 +1019,16 @@ int MXC_UART_RevB_ReadRXFIFODMA(mxc_uart_revb_regs_t *uart, unsigned char *bytes return E_NULL_PTR; } - channel = MXC_DMA_AcquireChannel(); + if (states[uart_num].auto_dma_handlers) { + /* Acquire channel */ + channel = MXC_DMA_AcquireChannel(); + MXC_UART_RevB_SetRXDMAChannel(uart, channel); + MXC_UART_RevB_DMA_SetupAutoHandlers(channel); + } else { + if (states[uart_num].channelRx < 0) + return E_BAD_STATE; + channel = MXC_UART_RevB_GetRXDMAChannel(uart); + } config.ch = channel; @@ -972,7 +1071,16 @@ int MXC_UART_RevB_WriteTXFIFODMA(mxc_uart_revb_regs_t *uart, const unsigned char return E_NULL_PTR; } - channel = MXC_DMA_AcquireChannel(); + if (states[uart_num].auto_dma_handlers) { + /* Acquire channel */ + channel = MXC_DMA_AcquireChannel(); + MXC_UART_RevB_SetTXDMAChannel(uart, channel); + MXC_UART_RevB_DMA_SetupAutoHandlers(channel); + } else { + if (states[uart_num].channelTx < 0) + return E_BAD_STATE; + channel = MXC_UART_RevB_GetTXDMAChannel(uart); + } config.ch = channel; @@ -1021,8 +1129,10 @@ int MXC_UART_RevB_TransactionDMA(mxc_uart_revb_req_t *req) MXC_UART_DisableInt((mxc_uart_regs_t *)(req->uart), 0xFFFFFFFF); MXC_UART_ClearFlags((mxc_uart_regs_t *)(req->uart), 0xFFFFFFFF); - MXC_UART_ClearTXFIFO((mxc_uart_regs_t *)(req->uart)); - MXC_UART_ClearRXFIFO((mxc_uart_regs_t *)(req->uart)); + // Clearing the RX FIFOs here makes RX-only or TX-only + // transactions half-duplex. Commenting out for now. + // MXC_UART_ClearTXFIFO((mxc_uart_regs_t *)(req->uart)); + // MXC_UART_ClearRXFIFO((mxc_uart_regs_t *)(req->uart)); //Set DMA FIFO threshold (req->uart)->dma |= (1 << MXC_F_UART_REVB_DMA_RX_THD_VAL_POS); @@ -1061,10 +1171,17 @@ void MXC_UART_RevB_DMACallback(int ch, int error) for (int i = 0; i < MXC_UART_INSTANCES; i++) { if (states[i].channelTx == ch) { - //save the request - temp_req = states[i].req; + // Populate txLen. The number of "remainder" bytes is what's left on the + // DMA channel's count register. + states[i].req->txCnt = states[i].req->txLen - MXC_DMA->ch[ch].cnt; + //save the request + + if (states[i].auto_dma_handlers) { + MXC_DMA_ReleaseChannel(ch); + states[i].channelTx = -1; + } - MXC_DMA_ReleaseChannel(ch); + temp_req = states[i].req; // Callback if not NULL if (temp_req->callback != NULL) { @@ -1072,11 +1189,16 @@ void MXC_UART_RevB_DMACallback(int ch, int error) } break; } else if (states[i].channelRx == ch) { + states[i].req->rxCnt = states[i].req->rxLen - MXC_DMA->ch[ch].cnt; + + if (states[i].auto_dma_handlers) { + MXC_DMA_ReleaseChannel(ch); + states[i].channelRx = -1; + } + //save the request temp_req = states[i].req; - MXC_DMA_ReleaseChannel(ch); - // Callback if not NULL if (temp_req->callback != NULL) { temp_req->callback((mxc_uart_req_t *)temp_req, E_NO_ERROR); diff --git a/Libraries/PeriphDrivers/Source/UART/uart_revb.h b/Libraries/PeriphDrivers/Source/UART/uart_revb.h index 0ec4280c9a0..956b3975055 100644 --- a/Libraries/PeriphDrivers/Source/UART/uart_revb.h +++ b/Libraries/PeriphDrivers/Source/UART/uart_revb.h @@ -117,4 +117,10 @@ int MXC_UART_RevB_AsyncStop(mxc_uart_revb_regs_t *uart); int MXC_UART_RevB_AsyncCallback(mxc_uart_revb_regs_t *uart, int retVal); void MXC_UART_RevB_DMACallback(int ch, int error); +int MXC_UART_RevB_SetAutoDMAHandlers(mxc_uart_revb_regs_t *uart, bool enable); +int MXC_UART_RevB_SetTXDMAChannel(mxc_uart_revb_regs_t *uart, unsigned int channel); +int MXC_UART_RevB_GetTXDMAChannel(mxc_uart_revb_regs_t *uart); +int MXC_UART_RevB_SetRXDMAChannel(mxc_uart_revb_regs_t *uart, unsigned int channel); +int MXC_UART_RevB_GetRXDMAChannel(mxc_uart_revb_regs_t *uart); + #endif // LIBRARIES_PERIPHDRIVERS_SOURCE_UART_UART_REVB_H_ From fade8a5ad0158add66bb11f622a2bc0ae0325573 Mon Sep 17 00:00:00 2001 From: Jake Carter Date: Fri, 20 Oct 2023 12:36:07 -0500 Subject: [PATCH 07/27] Add function prototypes for all micros --- .../PeriphDrivers/Include/MAX32520/uart.h | 63 +++++++++++++++++++ .../PeriphDrivers/Include/MAX32570/uart.h | 63 +++++++++++++++++++ .../PeriphDrivers/Include/MAX32572/uart.h | 63 +++++++++++++++++++ .../PeriphDrivers/Include/MAX32650/uart.h | 63 +++++++++++++++++++ .../PeriphDrivers/Include/MAX32655/uart.h | 63 +++++++++++++++++++ .../PeriphDrivers/Include/MAX32660/uart.h | 63 +++++++++++++++++++ .../PeriphDrivers/Include/MAX32662/uart.h | 63 +++++++++++++++++++ .../PeriphDrivers/Include/MAX32665/uart.h | 57 +++++++++++++++++ .../PeriphDrivers/Include/MAX32670/uart.h | 63 +++++++++++++++++++ .../PeriphDrivers/Include/MAX32672/uart.h | 63 +++++++++++++++++++ .../PeriphDrivers/Include/MAX32675/uart.h | 63 +++++++++++++++++++ .../PeriphDrivers/Include/MAX32680/uart.h | 63 +++++++++++++++++++ .../PeriphDrivers/Include/MAX32690/uart.h | 63 +++++++++++++++++++ .../PeriphDrivers/Include/MAX78000/uart.h | 58 +++++++++++++++++ .../PeriphDrivers/Include/MAX78002/uart.h | 63 +++++++++++++++++++ 15 files changed, 934 insertions(+) diff --git a/Libraries/PeriphDrivers/Include/MAX32520/uart.h b/Libraries/PeriphDrivers/Include/MAX32520/uart.h index b578a0a04f4..723c716c0b0 100644 --- a/Libraries/PeriphDrivers/Include/MAX32520/uart.h +++ b/Libraries/PeriphDrivers/Include/MAX32520/uart.h @@ -612,6 +612,69 @@ uint32_t MXC_UART_GetAsyncTXCount(mxc_uart_req_t *req); */ uint32_t MXC_UART_GetAsyncRXCount(mxc_uart_req_t *req); +/** + * @brief Enable or disable automatic DMA interrupt handlers for the UART module. + * + * The @ref MXC_UART_TransactionDMA functions require special interrupt handlers to work. + * + * When "Auto" DMA handlers are enabled, the UART drivers will acquire DMA channels + * and assign the appropriate handlers automatically. The acquired channels are + * released after each transaction. + * + * If "Auto" DMA handlers are disabled, the user must acquire DMA channels manually + * and assign them to the drivers with the @ref MXC_UART_SetTXDMAChannel and + * @ref MXC_UART_SetRXDMAChannel functions. + * + * @param uart Pointer to the UART module's registers. + * @param enable true to enable Auto DMA handlers, false to disable. + * @return 0 on success, or a non-zero error code on failure. + */ +int MXC_UART_SetAutoDMAHandlers(mxc_uart_regs_t *uart, bool enable); + +/** + * @brief Set the TX (Transmit) DMA channel for a UART module. + * + * This function assigns the DMA channel for transmitting data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @param channel The DMA channel number to be used for @ref MXC_UART_TransactionDMA. + */ +int MXC_UART_SetTXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel); + +/** + * @brief Get the TX (Transmit) DMA channel for a UART module. + * + * This function retrieves the currently assigned DMA channel for transmitting data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @return The currently assigned TX DMA channel. + */ +int MXC_UART_GetTXDMAChannel(mxc_uart_regs_t *uart); + +/** + * @brief Set the RX (Receive) DMA channel for a UART module. + * + * This function assigns the DMA channel for receiving data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @param channel The DMA channel number to be used for @ref MXC_UART_TransactionDMA. + */ +int MXC_UART_SetRXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel); + +/** + * @brief Get the RX (Receive) DMA channel for a UART module. + * + * This function retrieves the currently configured DMA channel for receiving data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @return The currently configured RX DMA channel. + */ +int MXC_UART_GetRXDMAChannel(mxc_uart_regs_t *uart); + /**@} end of group uart */ #ifdef __cplusplus diff --git a/Libraries/PeriphDrivers/Include/MAX32570/uart.h b/Libraries/PeriphDrivers/Include/MAX32570/uart.h index 8833306a16b..c59443bb32d 100644 --- a/Libraries/PeriphDrivers/Include/MAX32570/uart.h +++ b/Libraries/PeriphDrivers/Include/MAX32570/uart.h @@ -700,6 +700,69 @@ uint32_t MXC_UART_GetAsyncTXCount(mxc_uart_req_t *req); */ uint32_t MXC_UART_GetAsyncRXCount(mxc_uart_req_t *req); +/** + * @brief Enable or disable automatic DMA interrupt handlers for the UART module. + * + * The @ref MXC_UART_TransactionDMA functions require special interrupt handlers to work. + * + * When "Auto" DMA handlers are enabled, the UART drivers will acquire DMA channels + * and assign the appropriate handlers automatically. The acquired channels are + * released after each transaction. + * + * If "Auto" DMA handlers are disabled, the user must acquire DMA channels manually + * and assign them to the drivers with the @ref MXC_UART_SetTXDMAChannel and + * @ref MXC_UART_SetRXDMAChannel functions. + * + * @param uart Pointer to the UART module's registers. + * @param enable true to enable Auto DMA handlers, false to disable. + * @return 0 on success, or a non-zero error code on failure. + */ +int MXC_UART_SetAutoDMAHandlers(mxc_uart_regs_t *uart, bool enable); + +/** + * @brief Set the TX (Transmit) DMA channel for a UART module. + * + * This function assigns the DMA channel for transmitting data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @param channel The DMA channel number to be used for @ref MXC_UART_TransactionDMA. + */ +int MXC_UART_SetTXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel); + +/** + * @brief Get the TX (Transmit) DMA channel for a UART module. + * + * This function retrieves the currently assigned DMA channel for transmitting data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @return The currently assigned TX DMA channel. + */ +int MXC_UART_GetTXDMAChannel(mxc_uart_regs_t *uart); + +/** + * @brief Set the RX (Receive) DMA channel for a UART module. + * + * This function assigns the DMA channel for receiving data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @param channel The DMA channel number to be used for @ref MXC_UART_TransactionDMA. + */ +int MXC_UART_SetRXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel); + +/** + * @brief Get the RX (Receive) DMA channel for a UART module. + * + * This function retrieves the currently configured DMA channel for receiving data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @return The currently configured RX DMA channel. + */ +int MXC_UART_GetRXDMAChannel(mxc_uart_regs_t *uart); + /**@} end of group uart */ #ifdef __cplusplus diff --git a/Libraries/PeriphDrivers/Include/MAX32572/uart.h b/Libraries/PeriphDrivers/Include/MAX32572/uart.h index 381171e581c..5db1f6835f2 100644 --- a/Libraries/PeriphDrivers/Include/MAX32572/uart.h +++ b/Libraries/PeriphDrivers/Include/MAX32572/uart.h @@ -655,6 +655,69 @@ int MXC_UART_AbortAsync(mxc_uart_regs_t *uart); */ int MXC_UART_AsyncHandler(mxc_uart_regs_t *uart); +/** + * @brief Enable or disable automatic DMA interrupt handlers for the UART module. + * + * The @ref MXC_UART_TransactionDMA functions require special interrupt handlers to work. + * + * When "Auto" DMA handlers are enabled, the UART drivers will acquire DMA channels + * and assign the appropriate handlers automatically. The acquired channels are + * released after each transaction. + * + * If "Auto" DMA handlers are disabled, the user must acquire DMA channels manually + * and assign them to the drivers with the @ref MXC_UART_SetTXDMAChannel and + * @ref MXC_UART_SetRXDMAChannel functions. + * + * @param uart Pointer to the UART module's registers. + * @param enable true to enable Auto DMA handlers, false to disable. + * @return 0 on success, or a non-zero error code on failure. + */ +int MXC_UART_SetAutoDMAHandlers(mxc_uart_regs_t *uart, bool enable); + +/** + * @brief Set the TX (Transmit) DMA channel for a UART module. + * + * This function assigns the DMA channel for transmitting data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @param channel The DMA channel number to be used for @ref MXC_UART_TransactionDMA. + */ +int MXC_UART_SetTXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel); + +/** + * @brief Get the TX (Transmit) DMA channel for a UART module. + * + * This function retrieves the currently assigned DMA channel for transmitting data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @return The currently assigned TX DMA channel. + */ +int MXC_UART_GetTXDMAChannel(mxc_uart_regs_t *uart); + +/** + * @brief Set the RX (Receive) DMA channel for a UART module. + * + * This function assigns the DMA channel for receiving data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @param channel The DMA channel number to be used for @ref MXC_UART_TransactionDMA. + */ +int MXC_UART_SetRXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel); + +/** + * @brief Get the RX (Receive) DMA channel for a UART module. + * + * This function retrieves the currently configured DMA channel for receiving data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @return The currently configured RX DMA channel. + */ +int MXC_UART_GetRXDMAChannel(mxc_uart_regs_t *uart); + /**@} end of group uart */ #ifdef __cplusplus diff --git a/Libraries/PeriphDrivers/Include/MAX32650/uart.h b/Libraries/PeriphDrivers/Include/MAX32650/uart.h index 35f1f0e0a63..9e6bc22c9d3 100644 --- a/Libraries/PeriphDrivers/Include/MAX32650/uart.h +++ b/Libraries/PeriphDrivers/Include/MAX32650/uart.h @@ -664,6 +664,69 @@ uint32_t MXC_UART_GetAsyncTXCount(mxc_uart_req_t *req); */ uint32_t MXC_UART_GetAsyncRXCount(mxc_uart_req_t *req); +/** + * @brief Enable or disable automatic DMA interrupt handlers for the UART module. + * + * The @ref MXC_UART_TransactionDMA functions require special interrupt handlers to work. + * + * When "Auto" DMA handlers are enabled, the UART drivers will acquire DMA channels + * and assign the appropriate handlers automatically. The acquired channels are + * released after each transaction. + * + * If "Auto" DMA handlers are disabled, the user must acquire DMA channels manually + * and assign them to the drivers with the @ref MXC_UART_SetTXDMAChannel and + * @ref MXC_UART_SetRXDMAChannel functions. + * + * @param uart Pointer to the UART module's registers. + * @param enable true to enable Auto DMA handlers, false to disable. + * @return 0 on success, or a non-zero error code on failure. + */ +int MXC_UART_SetAutoDMAHandlers(mxc_uart_regs_t *uart, bool enable); + +/** + * @brief Set the TX (Transmit) DMA channel for a UART module. + * + * This function assigns the DMA channel for transmitting data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @param channel The DMA channel number to be used for @ref MXC_UART_TransactionDMA. + */ +int MXC_UART_SetTXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel); + +/** + * @brief Get the TX (Transmit) DMA channel for a UART module. + * + * This function retrieves the currently assigned DMA channel for transmitting data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @return The currently assigned TX DMA channel. + */ +int MXC_UART_GetTXDMAChannel(mxc_uart_regs_t *uart); + +/** + * @brief Set the RX (Receive) DMA channel for a UART module. + * + * This function assigns the DMA channel for receiving data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @param channel The DMA channel number to be used for @ref MXC_UART_TransactionDMA. + */ +int MXC_UART_SetRXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel); + +/** + * @brief Get the RX (Receive) DMA channel for a UART module. + * + * This function retrieves the currently configured DMA channel for receiving data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @return The currently configured RX DMA channel. + */ +int MXC_UART_GetRXDMAChannel(mxc_uart_regs_t *uart); + /**@} end of group uart */ #ifdef __cplusplus diff --git a/Libraries/PeriphDrivers/Include/MAX32655/uart.h b/Libraries/PeriphDrivers/Include/MAX32655/uart.h index 5f829080fcb..d76b9d16a6c 100644 --- a/Libraries/PeriphDrivers/Include/MAX32655/uart.h +++ b/Libraries/PeriphDrivers/Include/MAX32655/uart.h @@ -676,6 +676,69 @@ uint32_t MXC_UART_GetAsyncTXCount(mxc_uart_req_t *req); */ uint32_t MXC_UART_GetAsyncRXCount(mxc_uart_req_t *req); +/** + * @brief Enable or disable automatic DMA interrupt handlers for the UART module. + * + * The @ref MXC_UART_TransactionDMA functions require special interrupt handlers to work. + * + * When "Auto" DMA handlers are enabled, the UART drivers will acquire DMA channels + * and assign the appropriate handlers automatically. The acquired channels are + * released after each transaction. + * + * If "Auto" DMA handlers are disabled, the user must acquire DMA channels manually + * and assign them to the drivers with the @ref MXC_UART_SetTXDMAChannel and + * @ref MXC_UART_SetRXDMAChannel functions. + * + * @param uart Pointer to the UART module's registers. + * @param enable true to enable Auto DMA handlers, false to disable. + * @return 0 on success, or a non-zero error code on failure. + */ +int MXC_UART_SetAutoDMAHandlers(mxc_uart_regs_t *uart, bool enable); + +/** + * @brief Set the TX (Transmit) DMA channel for a UART module. + * + * This function assigns the DMA channel for transmitting data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @param channel The DMA channel number to be used for @ref MXC_UART_TransactionDMA. + */ +int MXC_UART_SetTXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel); + +/** + * @brief Get the TX (Transmit) DMA channel for a UART module. + * + * This function retrieves the currently assigned DMA channel for transmitting data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @return The currently assigned TX DMA channel. + */ +int MXC_UART_GetTXDMAChannel(mxc_uart_regs_t *uart); + +/** + * @brief Set the RX (Receive) DMA channel for a UART module. + * + * This function assigns the DMA channel for receiving data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @param channel The DMA channel number to be used for @ref MXC_UART_TransactionDMA. + */ +int MXC_UART_SetRXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel); + +/** + * @brief Get the RX (Receive) DMA channel for a UART module. + * + * This function retrieves the currently configured DMA channel for receiving data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @return The currently configured RX DMA channel. + */ +int MXC_UART_GetRXDMAChannel(mxc_uart_regs_t *uart); + /**@} end of group uart */ #ifdef __cplusplus diff --git a/Libraries/PeriphDrivers/Include/MAX32660/uart.h b/Libraries/PeriphDrivers/Include/MAX32660/uart.h index 27be4d5d73e..de822258fda 100644 --- a/Libraries/PeriphDrivers/Include/MAX32660/uart.h +++ b/Libraries/PeriphDrivers/Include/MAX32660/uart.h @@ -702,6 +702,69 @@ uint32_t MXC_UART_GetAsyncTXCount(mxc_uart_req_t *req); */ uint32_t MXC_UART_GetAsyncRXCount(mxc_uart_req_t *req); +/** + * @brief Enable or disable automatic DMA interrupt handlers for the UART module. + * + * The @ref MXC_UART_TransactionDMA functions require special interrupt handlers to work. + * + * When "Auto" DMA handlers are enabled, the UART drivers will acquire DMA channels + * and assign the appropriate handlers automatically. The acquired channels are + * released after each transaction. + * + * If "Auto" DMA handlers are disabled, the user must acquire DMA channels manually + * and assign them to the drivers with the @ref MXC_UART_SetTXDMAChannel and + * @ref MXC_UART_SetRXDMAChannel functions. + * + * @param uart Pointer to the UART module's registers. + * @param enable true to enable Auto DMA handlers, false to disable. + * @return 0 on success, or a non-zero error code on failure. + */ +int MXC_UART_SetAutoDMAHandlers(mxc_uart_regs_t *uart, bool enable); + +/** + * @brief Set the TX (Transmit) DMA channel for a UART module. + * + * This function assigns the DMA channel for transmitting data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @param channel The DMA channel number to be used for @ref MXC_UART_TransactionDMA. + */ +int MXC_UART_SetTXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel); + +/** + * @brief Get the TX (Transmit) DMA channel for a UART module. + * + * This function retrieves the currently assigned DMA channel for transmitting data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @return The currently assigned TX DMA channel. + */ +int MXC_UART_GetTXDMAChannel(mxc_uart_regs_t *uart); + +/** + * @brief Set the RX (Receive) DMA channel for a UART module. + * + * This function assigns the DMA channel for receiving data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @param channel The DMA channel number to be used for @ref MXC_UART_TransactionDMA. + */ +int MXC_UART_SetRXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel); + +/** + * @brief Get the RX (Receive) DMA channel for a UART module. + * + * This function retrieves the currently configured DMA channel for receiving data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @return The currently configured RX DMA channel. + */ +int MXC_UART_GetRXDMAChannel(mxc_uart_regs_t *uart); + /**@} end of group uart */ #ifdef __cplusplus diff --git a/Libraries/PeriphDrivers/Include/MAX32662/uart.h b/Libraries/PeriphDrivers/Include/MAX32662/uart.h index 6b951e62560..c21ed891f79 100644 --- a/Libraries/PeriphDrivers/Include/MAX32662/uart.h +++ b/Libraries/PeriphDrivers/Include/MAX32662/uart.h @@ -652,6 +652,69 @@ int MXC_UART_AbortAsync(mxc_uart_regs_t *uart); */ int MXC_UART_AsyncHandler(mxc_uart_regs_t *uart); +/** + * @brief Enable or disable automatic DMA interrupt handlers for the UART module. + * + * The @ref MXC_UART_TransactionDMA functions require special interrupt handlers to work. + * + * When "Auto" DMA handlers are enabled, the UART drivers will acquire DMA channels + * and assign the appropriate handlers automatically. The acquired channels are + * released after each transaction. + * + * If "Auto" DMA handlers are disabled, the user must acquire DMA channels manually + * and assign them to the drivers with the @ref MXC_UART_SetTXDMAChannel and + * @ref MXC_UART_SetRXDMAChannel functions. + * + * @param uart Pointer to the UART module's registers. + * @param enable true to enable Auto DMA handlers, false to disable. + * @return 0 on success, or a non-zero error code on failure. + */ +int MXC_UART_SetAutoDMAHandlers(mxc_uart_regs_t *uart, bool enable); + +/** + * @brief Set the TX (Transmit) DMA channel for a UART module. + * + * This function assigns the DMA channel for transmitting data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @param channel The DMA channel number to be used for @ref MXC_UART_TransactionDMA. + */ +int MXC_UART_SetTXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel); + +/** + * @brief Get the TX (Transmit) DMA channel for a UART module. + * + * This function retrieves the currently assigned DMA channel for transmitting data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @return The currently assigned TX DMA channel. + */ +int MXC_UART_GetTXDMAChannel(mxc_uart_regs_t *uart); + +/** + * @brief Set the RX (Receive) DMA channel for a UART module. + * + * This function assigns the DMA channel for receiving data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @param channel The DMA channel number to be used for @ref MXC_UART_TransactionDMA. + */ +int MXC_UART_SetRXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel); + +/** + * @brief Get the RX (Receive) DMA channel for a UART module. + * + * This function retrieves the currently configured DMA channel for receiving data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @return The currently configured RX DMA channel. + */ +int MXC_UART_GetRXDMAChannel(mxc_uart_regs_t *uart); + /**@} end of group uart */ #ifdef __cplusplus diff --git a/Libraries/PeriphDrivers/Include/MAX32665/uart.h b/Libraries/PeriphDrivers/Include/MAX32665/uart.h index e5fe97f3d7b..400b5df820b 100644 --- a/Libraries/PeriphDrivers/Include/MAX32665/uart.h +++ b/Libraries/PeriphDrivers/Include/MAX32665/uart.h @@ -700,10 +700,67 @@ uint32_t MXC_UART_GetAsyncTXCount(mxc_uart_req_t *req); */ uint32_t MXC_UART_GetAsyncRXCount(mxc_uart_req_t *req); +/** + * @brief Enable or disable automatic DMA interrupt handlers for the UART module. + * + * The @ref MXC_UART_TransactionDMA functions require special interrupt handlers to work. + * + * When "Auto" DMA handlers are enabled, the UART drivers will acquire DMA channels + * and assign the appropriate handlers automatically. The acquired channels are + * released after each transaction. + * + * If "Auto" DMA handlers are disabled, the user must acquire DMA channels manually + * and assign them to the drivers with the @ref MXC_UART_SetTXDMAChannel and + * @ref MXC_UART_SetRXDMAChannel functions. + * + * @param uart Pointer to the UART module's registers. + * @param enable true to enable Auto DMA handlers, false to disable. + * @return 0 on success, or a non-zero error code on failure. + */ int MXC_UART_SetAutoDMAHandlers(mxc_uart_regs_t *uart, bool enable); + +/** + * @brief Set the TX (Transmit) DMA channel for a UART module. + * + * This function assigns the DMA channel for transmitting data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @param channel The DMA channel number to be used for @ref MXC_UART_TransactionDMA. + */ int MXC_UART_SetTXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel); + +/** + * @brief Get the TX (Transmit) DMA channel for a UART module. + * + * This function retrieves the currently assigned DMA channel for transmitting data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @return The currently assigned TX DMA channel. + */ int MXC_UART_GetTXDMAChannel(mxc_uart_regs_t *uart); + +/** + * @brief Set the RX (Receive) DMA channel for a UART module. + * + * This function assigns the DMA channel for receiving data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @param channel The DMA channel number to be used for @ref MXC_UART_TransactionDMA. + */ int MXC_UART_SetRXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel); + +/** + * @brief Get the RX (Receive) DMA channel for a UART module. + * + * This function retrieves the currently configured DMA channel for receiving data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @return The currently configured RX DMA channel. + */ int MXC_UART_GetRXDMAChannel(mxc_uart_regs_t *uart); /**@} end of group uart */ diff --git a/Libraries/PeriphDrivers/Include/MAX32670/uart.h b/Libraries/PeriphDrivers/Include/MAX32670/uart.h index a68b89100e2..99b5c3e0b0a 100644 --- a/Libraries/PeriphDrivers/Include/MAX32670/uart.h +++ b/Libraries/PeriphDrivers/Include/MAX32670/uart.h @@ -678,6 +678,69 @@ uint32_t MXC_UART_GetAsyncTXCount(mxc_uart_req_t *req); */ uint32_t MXC_UART_GetAsyncRXCount(mxc_uart_req_t *req); +/** + * @brief Enable or disable automatic DMA interrupt handlers for the UART module. + * + * The @ref MXC_UART_TransactionDMA functions require special interrupt handlers to work. + * + * When "Auto" DMA handlers are enabled, the UART drivers will acquire DMA channels + * and assign the appropriate handlers automatically. The acquired channels are + * released after each transaction. + * + * If "Auto" DMA handlers are disabled, the user must acquire DMA channels manually + * and assign them to the drivers with the @ref MXC_UART_SetTXDMAChannel and + * @ref MXC_UART_SetRXDMAChannel functions. + * + * @param uart Pointer to the UART module's registers. + * @param enable true to enable Auto DMA handlers, false to disable. + * @return 0 on success, or a non-zero error code on failure. + */ +int MXC_UART_SetAutoDMAHandlers(mxc_uart_regs_t *uart, bool enable); + +/** + * @brief Set the TX (Transmit) DMA channel for a UART module. + * + * This function assigns the DMA channel for transmitting data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @param channel The DMA channel number to be used for @ref MXC_UART_TransactionDMA. + */ +int MXC_UART_SetTXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel); + +/** + * @brief Get the TX (Transmit) DMA channel for a UART module. + * + * This function retrieves the currently assigned DMA channel for transmitting data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @return The currently assigned TX DMA channel. + */ +int MXC_UART_GetTXDMAChannel(mxc_uart_regs_t *uart); + +/** + * @brief Set the RX (Receive) DMA channel for a UART module. + * + * This function assigns the DMA channel for receiving data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @param channel The DMA channel number to be used for @ref MXC_UART_TransactionDMA. + */ +int MXC_UART_SetRXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel); + +/** + * @brief Get the RX (Receive) DMA channel for a UART module. + * + * This function retrieves the currently configured DMA channel for receiving data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @return The currently configured RX DMA channel. + */ +int MXC_UART_GetRXDMAChannel(mxc_uart_regs_t *uart); + /**@} end of group uart */ #ifdef __cplusplus diff --git a/Libraries/PeriphDrivers/Include/MAX32672/uart.h b/Libraries/PeriphDrivers/Include/MAX32672/uart.h index 2e254010a5d..789bb630d4d 100644 --- a/Libraries/PeriphDrivers/Include/MAX32672/uart.h +++ b/Libraries/PeriphDrivers/Include/MAX32672/uart.h @@ -672,6 +672,69 @@ uint32_t MXC_UART_GetAsyncTXCount(mxc_uart_req_t *req); */ uint32_t MXC_UART_GetAsyncRXCount(mxc_uart_req_t *req); +/** + * @brief Enable or disable automatic DMA interrupt handlers for the UART module. + * + * The @ref MXC_UART_TransactionDMA functions require special interrupt handlers to work. + * + * When "Auto" DMA handlers are enabled, the UART drivers will acquire DMA channels + * and assign the appropriate handlers automatically. The acquired channels are + * released after each transaction. + * + * If "Auto" DMA handlers are disabled, the user must acquire DMA channels manually + * and assign them to the drivers with the @ref MXC_UART_SetTXDMAChannel and + * @ref MXC_UART_SetRXDMAChannel functions. + * + * @param uart Pointer to the UART module's registers. + * @param enable true to enable Auto DMA handlers, false to disable. + * @return 0 on success, or a non-zero error code on failure. + */ +int MXC_UART_SetAutoDMAHandlers(mxc_uart_regs_t *uart, bool enable); + +/** + * @brief Set the TX (Transmit) DMA channel for a UART module. + * + * This function assigns the DMA channel for transmitting data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @param channel The DMA channel number to be used for @ref MXC_UART_TransactionDMA. + */ +int MXC_UART_SetTXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel); + +/** + * @brief Get the TX (Transmit) DMA channel for a UART module. + * + * This function retrieves the currently assigned DMA channel for transmitting data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @return The currently assigned TX DMA channel. + */ +int MXC_UART_GetTXDMAChannel(mxc_uart_regs_t *uart); + +/** + * @brief Set the RX (Receive) DMA channel for a UART module. + * + * This function assigns the DMA channel for receiving data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @param channel The DMA channel number to be used for @ref MXC_UART_TransactionDMA. + */ +int MXC_UART_SetRXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel); + +/** + * @brief Get the RX (Receive) DMA channel for a UART module. + * + * This function retrieves the currently configured DMA channel for receiving data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @return The currently configured RX DMA channel. + */ +int MXC_UART_GetRXDMAChannel(mxc_uart_regs_t *uart); + /**@} end of group uart */ #ifdef __cplusplus diff --git a/Libraries/PeriphDrivers/Include/MAX32675/uart.h b/Libraries/PeriphDrivers/Include/MAX32675/uart.h index 1af6e1a661c..ec03544821d 100644 --- a/Libraries/PeriphDrivers/Include/MAX32675/uart.h +++ b/Libraries/PeriphDrivers/Include/MAX32675/uart.h @@ -673,6 +673,69 @@ uint32_t MXC_UART_GetAsyncTXCount(mxc_uart_req_t *req); */ uint32_t MXC_UART_GetAsyncRXCount(mxc_uart_req_t *req); +/** + * @brief Enable or disable automatic DMA interrupt handlers for the UART module. + * + * The @ref MXC_UART_TransactionDMA functions require special interrupt handlers to work. + * + * When "Auto" DMA handlers are enabled, the UART drivers will acquire DMA channels + * and assign the appropriate handlers automatically. The acquired channels are + * released after each transaction. + * + * If "Auto" DMA handlers are disabled, the user must acquire DMA channels manually + * and assign them to the drivers with the @ref MXC_UART_SetTXDMAChannel and + * @ref MXC_UART_SetRXDMAChannel functions. + * + * @param uart Pointer to the UART module's registers. + * @param enable true to enable Auto DMA handlers, false to disable. + * @return 0 on success, or a non-zero error code on failure. + */ +int MXC_UART_SetAutoDMAHandlers(mxc_uart_regs_t *uart, bool enable); + +/** + * @brief Set the TX (Transmit) DMA channel for a UART module. + * + * This function assigns the DMA channel for transmitting data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @param channel The DMA channel number to be used for @ref MXC_UART_TransactionDMA. + */ +int MXC_UART_SetTXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel); + +/** + * @brief Get the TX (Transmit) DMA channel for a UART module. + * + * This function retrieves the currently assigned DMA channel for transmitting data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @return The currently assigned TX DMA channel. + */ +int MXC_UART_GetTXDMAChannel(mxc_uart_regs_t *uart); + +/** + * @brief Set the RX (Receive) DMA channel for a UART module. + * + * This function assigns the DMA channel for receiving data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @param channel The DMA channel number to be used for @ref MXC_UART_TransactionDMA. + */ +int MXC_UART_SetRXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel); + +/** + * @brief Get the RX (Receive) DMA channel for a UART module. + * + * This function retrieves the currently configured DMA channel for receiving data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @return The currently configured RX DMA channel. + */ +int MXC_UART_GetRXDMAChannel(mxc_uart_regs_t *uart); + /**@} end of group uart */ #ifdef __cplusplus diff --git a/Libraries/PeriphDrivers/Include/MAX32680/uart.h b/Libraries/PeriphDrivers/Include/MAX32680/uart.h index f3f4b814435..48d75739701 100644 --- a/Libraries/PeriphDrivers/Include/MAX32680/uart.h +++ b/Libraries/PeriphDrivers/Include/MAX32680/uart.h @@ -675,6 +675,69 @@ uint32_t MXC_UART_GetAsyncTXCount(mxc_uart_req_t *req); */ uint32_t MXC_UART_GetAsyncRXCount(mxc_uart_req_t *req); +/** + * @brief Enable or disable automatic DMA interrupt handlers for the UART module. + * + * The @ref MXC_UART_TransactionDMA functions require special interrupt handlers to work. + * + * When "Auto" DMA handlers are enabled, the UART drivers will acquire DMA channels + * and assign the appropriate handlers automatically. The acquired channels are + * released after each transaction. + * + * If "Auto" DMA handlers are disabled, the user must acquire DMA channels manually + * and assign them to the drivers with the @ref MXC_UART_SetTXDMAChannel and + * @ref MXC_UART_SetRXDMAChannel functions. + * + * @param uart Pointer to the UART module's registers. + * @param enable true to enable Auto DMA handlers, false to disable. + * @return 0 on success, or a non-zero error code on failure. + */ +int MXC_UART_SetAutoDMAHandlers(mxc_uart_regs_t *uart, bool enable); + +/** + * @brief Set the TX (Transmit) DMA channel for a UART module. + * + * This function assigns the DMA channel for transmitting data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @param channel The DMA channel number to be used for @ref MXC_UART_TransactionDMA. + */ +int MXC_UART_SetTXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel); + +/** + * @brief Get the TX (Transmit) DMA channel for a UART module. + * + * This function retrieves the currently assigned DMA channel for transmitting data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @return The currently assigned TX DMA channel. + */ +int MXC_UART_GetTXDMAChannel(mxc_uart_regs_t *uart); + +/** + * @brief Set the RX (Receive) DMA channel for a UART module. + * + * This function assigns the DMA channel for receiving data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @param channel The DMA channel number to be used for @ref MXC_UART_TransactionDMA. + */ +int MXC_UART_SetRXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel); + +/** + * @brief Get the RX (Receive) DMA channel for a UART module. + * + * This function retrieves the currently configured DMA channel for receiving data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @return The currently configured RX DMA channel. + */ +int MXC_UART_GetRXDMAChannel(mxc_uart_regs_t *uart); + /**@} end of group uart */ #ifdef __cplusplus diff --git a/Libraries/PeriphDrivers/Include/MAX32690/uart.h b/Libraries/PeriphDrivers/Include/MAX32690/uart.h index 1838a5d7d42..5c8ed9173e6 100644 --- a/Libraries/PeriphDrivers/Include/MAX32690/uart.h +++ b/Libraries/PeriphDrivers/Include/MAX32690/uart.h @@ -678,6 +678,69 @@ uint32_t MXC_UART_GetAsyncTXCount(mxc_uart_req_t *req); */ uint32_t MXC_UART_GetAsyncRXCount(mxc_uart_req_t *req); +/** + * @brief Enable or disable automatic DMA interrupt handlers for the UART module. + * + * The @ref MXC_UART_TransactionDMA functions require special interrupt handlers to work. + * + * When "Auto" DMA handlers are enabled, the UART drivers will acquire DMA channels + * and assign the appropriate handlers automatically. The acquired channels are + * released after each transaction. + * + * If "Auto" DMA handlers are disabled, the user must acquire DMA channels manually + * and assign them to the drivers with the @ref MXC_UART_SetTXDMAChannel and + * @ref MXC_UART_SetRXDMAChannel functions. + * + * @param uart Pointer to the UART module's registers. + * @param enable true to enable Auto DMA handlers, false to disable. + * @return 0 on success, or a non-zero error code on failure. + */ +int MXC_UART_SetAutoDMAHandlers(mxc_uart_regs_t *uart, bool enable); + +/** + * @brief Set the TX (Transmit) DMA channel for a UART module. + * + * This function assigns the DMA channel for transmitting data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @param channel The DMA channel number to be used for @ref MXC_UART_TransactionDMA. + */ +int MXC_UART_SetTXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel); + +/** + * @brief Get the TX (Transmit) DMA channel for a UART module. + * + * This function retrieves the currently assigned DMA channel for transmitting data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @return The currently assigned TX DMA channel. + */ +int MXC_UART_GetTXDMAChannel(mxc_uart_regs_t *uart); + +/** + * @brief Set the RX (Receive) DMA channel for a UART module. + * + * This function assigns the DMA channel for receiving data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @param channel The DMA channel number to be used for @ref MXC_UART_TransactionDMA. + */ +int MXC_UART_SetRXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel); + +/** + * @brief Get the RX (Receive) DMA channel for a UART module. + * + * This function retrieves the currently configured DMA channel for receiving data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @return The currently configured RX DMA channel. + */ +int MXC_UART_GetRXDMAChannel(mxc_uart_regs_t *uart); + /**@} end of group uart */ #ifdef __cplusplus diff --git a/Libraries/PeriphDrivers/Include/MAX78000/uart.h b/Libraries/PeriphDrivers/Include/MAX78000/uart.h index 9e0260a033b..72b3f675afc 100644 --- a/Libraries/PeriphDrivers/Include/MAX78000/uart.h +++ b/Libraries/PeriphDrivers/Include/MAX78000/uart.h @@ -672,12 +672,70 @@ uint32_t MXC_UART_GetAsyncTXCount(mxc_uart_req_t *req); */ uint32_t MXC_UART_GetAsyncRXCount(mxc_uart_req_t *req); +/** + * @brief Enable or disable automatic DMA interrupt handlers for the UART module. + * + * The @ref MXC_UART_TransactionDMA functions require special interrupt handlers to work. + * + * When "Auto" DMA handlers are enabled, the UART drivers will acquire DMA channels + * and assign the appropriate handlers automatically. The acquired channels are + * released after each transaction. + * + * If "Auto" DMA handlers are disabled, the user must acquire DMA channels manually + * and assign them to the drivers with the @ref MXC_UART_SetTXDMAChannel and + * @ref MXC_UART_SetRXDMAChannel functions. + * + * @param uart Pointer to the UART module's registers. + * @param enable true to enable Auto DMA handlers, false to disable. + * @return 0 on success, or a non-zero error code on failure. + */ int MXC_UART_SetAutoDMAHandlers(mxc_uart_regs_t *uart, bool enable); + +/** + * @brief Set the TX (Transmit) DMA channel for a UART module. + * + * This function assigns the DMA channel for transmitting data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @param channel The DMA channel number to be used for @ref MXC_UART_TransactionDMA. + */ int MXC_UART_SetTXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel); + +/** + * @brief Get the TX (Transmit) DMA channel for a UART module. + * + * This function retrieves the currently assigned DMA channel for transmitting data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @return The currently assigned TX DMA channel. + */ int MXC_UART_GetTXDMAChannel(mxc_uart_regs_t *uart); + +/** + * @brief Set the RX (Receive) DMA channel for a UART module. + * + * This function assigns the DMA channel for receiving data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @param channel The DMA channel number to be used for @ref MXC_UART_TransactionDMA. + */ int MXC_UART_SetRXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel); + +/** + * @brief Get the RX (Receive) DMA channel for a UART module. + * + * This function retrieves the currently configured DMA channel for receiving data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @return The currently configured RX DMA channel. + */ int MXC_UART_GetRXDMAChannel(mxc_uart_regs_t *uart); + /**@} end of group uart */ #ifdef __cplusplus diff --git a/Libraries/PeriphDrivers/Include/MAX78002/uart.h b/Libraries/PeriphDrivers/Include/MAX78002/uart.h index c62b2e6f495..e23ab97586b 100644 --- a/Libraries/PeriphDrivers/Include/MAX78002/uart.h +++ b/Libraries/PeriphDrivers/Include/MAX78002/uart.h @@ -654,6 +654,69 @@ int MXC_UART_AbortAsync(mxc_uart_regs_t *uart); */ int MXC_UART_AsyncHandler(mxc_uart_regs_t *uart); +/** + * @brief Enable or disable automatic DMA interrupt handlers for the UART module. + * + * The @ref MXC_UART_TransactionDMA functions require special interrupt handlers to work. + * + * When "Auto" DMA handlers are enabled, the UART drivers will acquire DMA channels + * and assign the appropriate handlers automatically. The acquired channels are + * released after each transaction. + * + * If "Auto" DMA handlers are disabled, the user must acquire DMA channels manually + * and assign them to the drivers with the @ref MXC_UART_SetTXDMAChannel and + * @ref MXC_UART_SetRXDMAChannel functions. + * + * @param uart Pointer to the UART module's registers. + * @param enable true to enable Auto DMA handlers, false to disable. + * @return 0 on success, or a non-zero error code on failure. + */ +int MXC_UART_SetAutoDMAHandlers(mxc_uart_regs_t *uart, bool enable); + +/** + * @brief Set the TX (Transmit) DMA channel for a UART module. + * + * This function assigns the DMA channel for transmitting data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @param channel The DMA channel number to be used for @ref MXC_UART_TransactionDMA. + */ +int MXC_UART_SetTXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel); + +/** + * @brief Get the TX (Transmit) DMA channel for a UART module. + * + * This function retrieves the currently assigned DMA channel for transmitting data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @return The currently assigned TX DMA channel. + */ +int MXC_UART_GetTXDMAChannel(mxc_uart_regs_t *uart); + +/** + * @brief Set the RX (Receive) DMA channel for a UART module. + * + * This function assigns the DMA channel for receiving data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @param channel The DMA channel number to be used for @ref MXC_UART_TransactionDMA. + */ +int MXC_UART_SetRXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel); + +/** + * @brief Get the RX (Receive) DMA channel for a UART module. + * + * This function retrieves the currently configured DMA channel for receiving data + * when @ref is MXC_UART_SetAutoDMAHandlers disabled. + * + * @param uart Pointer to the UART module's registers. + * @return The currently configured RX DMA channel. + */ +int MXC_UART_GetRXDMAChannel(mxc_uart_regs_t *uart); + /**@} end of group uart */ #ifdef __cplusplus From 1a336eabbb338d1596ef662f2aa25fb8f3a72dea Mon Sep 17 00:00:00 2001 From: Jake Carter Date: Fri, 20 Oct 2023 12:47:29 -0500 Subject: [PATCH 08/27] Add RevB passthroughs --- .../PeriphDrivers/Source/UART/uart_ai87.c | 25 +++++++++++++++++++ .../PeriphDrivers/Source/UART/uart_me12.c | 25 +++++++++++++++++++ .../PeriphDrivers/Source/UART/uart_me15.c | 25 +++++++++++++++++++ .../PeriphDrivers/Source/UART/uart_me16.c | 25 +++++++++++++++++++ .../PeriphDrivers/Source/UART/uart_me17.c | 25 +++++++++++++++++++ .../PeriphDrivers/Source/UART/uart_me18.c | 25 +++++++++++++++++++ .../PeriphDrivers/Source/UART/uart_me21.c | 25 +++++++++++++++++++ 7 files changed, 175 insertions(+) diff --git a/Libraries/PeriphDrivers/Source/UART/uart_ai87.c b/Libraries/PeriphDrivers/Source/UART/uart_ai87.c index 44838b6762b..3c9fce843db 100644 --- a/Libraries/PeriphDrivers/Source/UART/uart_ai87.c +++ b/Libraries/PeriphDrivers/Source/UART/uart_ai87.c @@ -492,3 +492,28 @@ uint32_t MXC_UART_GetAsyncRXCount(mxc_uart_req_t *req) { return req->rxCnt; } + +int MXC_UART_SetAutoDMAHandlers(mxc_uart_regs_t *uart, bool enable) +{ + return MXC_UART_RevB_SetAutoDMAHandlers((mxc_uart_revb_regs_t *)uart, enable); +} + +int MXC_UART_SetTXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel) +{ + return MXC_UART_RevB_SetTXDMAChannel((mxc_uart_revb_regs_t *)uart, channel); +} + +int MXC_UART_GetTXDMAChannel(mxc_uart_regs_t *uart) +{ + return MXC_UART_RevB_GetTXDMAChannel((mxc_uart_revb_regs_t *)uart); +} + +int MXC_UART_SetRXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel) +{ + return MXC_UART_RevB_SetRXDMAChannel((mxc_uart_revb_regs_t *)uart, channel); +} + +int MXC_UART_GetRXDMAChannel(mxc_uart_regs_t *uart) +{ + return MXC_UART_RevB_GetTXDMAChannel((mxc_uart_revb_regs_t *)uart); +} diff --git a/Libraries/PeriphDrivers/Source/UART/uart_me12.c b/Libraries/PeriphDrivers/Source/UART/uart_me12.c index 63cda742260..75f03fc073d 100644 --- a/Libraries/PeriphDrivers/Source/UART/uart_me12.c +++ b/Libraries/PeriphDrivers/Source/UART/uart_me12.c @@ -387,3 +387,28 @@ int MXC_UART_AsyncHandler(mxc_uart_regs_t *uart) { return MXC_UART_RevB_AsyncHandler((mxc_uart_revb_regs_t *)uart); } + +int MXC_UART_SetAutoDMAHandlers(mxc_uart_regs_t *uart, bool enable) +{ + return MXC_UART_RevB_SetAutoDMAHandlers((mxc_uart_revb_regs_t *)uart, enable); +} + +int MXC_UART_SetTXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel) +{ + return MXC_UART_RevB_SetTXDMAChannel((mxc_uart_revb_regs_t *)uart, channel); +} + +int MXC_UART_GetTXDMAChannel(mxc_uart_regs_t *uart) +{ + return MXC_UART_RevB_GetTXDMAChannel((mxc_uart_revb_regs_t *)uart); +} + +int MXC_UART_SetRXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel) +{ + return MXC_UART_RevB_SetRXDMAChannel((mxc_uart_revb_regs_t *)uart, channel); +} + +int MXC_UART_GetRXDMAChannel(mxc_uart_regs_t *uart) +{ + return MXC_UART_RevB_GetTXDMAChannel((mxc_uart_revb_regs_t *)uart); +} diff --git a/Libraries/PeriphDrivers/Source/UART/uart_me15.c b/Libraries/PeriphDrivers/Source/UART/uart_me15.c index 73e852bb060..b56ce3fd59a 100644 --- a/Libraries/PeriphDrivers/Source/UART/uart_me15.c +++ b/Libraries/PeriphDrivers/Source/UART/uart_me15.c @@ -549,3 +549,28 @@ uint32_t MXC_UART_GetAsyncRXCount(mxc_uart_req_t *req) { return req->rxCnt; } + +int MXC_UART_SetAutoDMAHandlers(mxc_uart_regs_t *uart, bool enable) +{ + return MXC_UART_RevB_SetAutoDMAHandlers((mxc_uart_revb_regs_t *)uart, enable); +} + +int MXC_UART_SetTXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel) +{ + return MXC_UART_RevB_SetTXDMAChannel((mxc_uart_revb_regs_t *)uart, channel); +} + +int MXC_UART_GetTXDMAChannel(mxc_uart_regs_t *uart) +{ + return MXC_UART_RevB_GetTXDMAChannel((mxc_uart_revb_regs_t *)uart); +} + +int MXC_UART_SetRXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel) +{ + return MXC_UART_RevB_SetRXDMAChannel((mxc_uart_revb_regs_t *)uart, channel); +} + +int MXC_UART_GetRXDMAChannel(mxc_uart_regs_t *uart) +{ + return MXC_UART_RevB_GetTXDMAChannel((mxc_uart_revb_regs_t *)uart); +} \ No newline at end of file diff --git a/Libraries/PeriphDrivers/Source/UART/uart_me16.c b/Libraries/PeriphDrivers/Source/UART/uart_me16.c index 26b375e0883..8958d15425a 100644 --- a/Libraries/PeriphDrivers/Source/UART/uart_me16.c +++ b/Libraries/PeriphDrivers/Source/UART/uart_me16.c @@ -483,3 +483,28 @@ uint32_t MXC_UART_GetAsyncRXCount(mxc_uart_req_t *req) { return req->rxCnt; } + +int MXC_UART_SetAutoDMAHandlers(mxc_uart_regs_t *uart, bool enable) +{ + return MXC_UART_RevB_SetAutoDMAHandlers((mxc_uart_revb_regs_t *)uart, enable); +} + +int MXC_UART_SetTXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel) +{ + return MXC_UART_RevB_SetTXDMAChannel((mxc_uart_revb_regs_t *)uart, channel); +} + +int MXC_UART_GetTXDMAChannel(mxc_uart_regs_t *uart) +{ + return MXC_UART_RevB_GetTXDMAChannel((mxc_uart_revb_regs_t *)uart); +} + +int MXC_UART_SetRXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel) +{ + return MXC_UART_RevB_SetRXDMAChannel((mxc_uart_revb_regs_t *)uart, channel); +} + +int MXC_UART_GetRXDMAChannel(mxc_uart_regs_t *uart) +{ + return MXC_UART_RevB_GetTXDMAChannel((mxc_uart_revb_regs_t *)uart); +} diff --git a/Libraries/PeriphDrivers/Source/UART/uart_me17.c b/Libraries/PeriphDrivers/Source/UART/uart_me17.c index e70b725bf84..42e962714bd 100644 --- a/Libraries/PeriphDrivers/Source/UART/uart_me17.c +++ b/Libraries/PeriphDrivers/Source/UART/uart_me17.c @@ -516,3 +516,28 @@ uint32_t MXC_UART_GetAsyncRXCount(mxc_uart_req_t *req) { return req->rxCnt; } + +int MXC_UART_SetAutoDMAHandlers(mxc_uart_regs_t *uart, bool enable) +{ + return MXC_UART_RevB_SetAutoDMAHandlers((mxc_uart_revb_regs_t *)uart, enable); +} + +int MXC_UART_SetTXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel) +{ + return MXC_UART_RevB_SetTXDMAChannel((mxc_uart_revb_regs_t *)uart, channel); +} + +int MXC_UART_GetTXDMAChannel(mxc_uart_regs_t *uart) +{ + return MXC_UART_RevB_GetTXDMAChannel((mxc_uart_revb_regs_t *)uart); +} + +int MXC_UART_SetRXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel) +{ + return MXC_UART_RevB_SetRXDMAChannel((mxc_uart_revb_regs_t *)uart, channel); +} + +int MXC_UART_GetRXDMAChannel(mxc_uart_regs_t *uart) +{ + return MXC_UART_RevB_GetTXDMAChannel((mxc_uart_revb_regs_t *)uart); +} diff --git a/Libraries/PeriphDrivers/Source/UART/uart_me18.c b/Libraries/PeriphDrivers/Source/UART/uart_me18.c index dad49bff447..deebc442f79 100644 --- a/Libraries/PeriphDrivers/Source/UART/uart_me18.c +++ b/Libraries/PeriphDrivers/Source/UART/uart_me18.c @@ -556,3 +556,28 @@ uint32_t MXC_UART_GetAsyncRXCount(mxc_uart_req_t *req) { return req->rxCnt; } + +int MXC_UART_SetAutoDMAHandlers(mxc_uart_regs_t *uart, bool enable) +{ + return MXC_UART_RevB_SetAutoDMAHandlers((mxc_uart_revb_regs_t *)uart, enable); +} + +int MXC_UART_SetTXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel) +{ + return MXC_UART_RevB_SetTXDMAChannel((mxc_uart_revb_regs_t *)uart, channel); +} + +int MXC_UART_GetTXDMAChannel(mxc_uart_regs_t *uart) +{ + return MXC_UART_RevB_GetTXDMAChannel((mxc_uart_revb_regs_t *)uart); +} + +int MXC_UART_SetRXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel) +{ + return MXC_UART_RevB_SetRXDMAChannel((mxc_uart_revb_regs_t *)uart, channel); +} + +int MXC_UART_GetRXDMAChannel(mxc_uart_regs_t *uart) +{ + return MXC_UART_RevB_GetTXDMAChannel((mxc_uart_revb_regs_t *)uart); +} diff --git a/Libraries/PeriphDrivers/Source/UART/uart_me21.c b/Libraries/PeriphDrivers/Source/UART/uart_me21.c index ed3be9ca1dc..180e27153d7 100644 --- a/Libraries/PeriphDrivers/Source/UART/uart_me21.c +++ b/Libraries/PeriphDrivers/Source/UART/uart_me21.c @@ -553,3 +553,28 @@ uint32_t MXC_UART_GetAsyncRXCount(mxc_uart_req_t *req) { return req->rxCnt; } + +int MXC_UART_SetAutoDMAHandlers(mxc_uart_regs_t *uart, bool enable) +{ + return MXC_UART_RevB_SetAutoDMAHandlers((mxc_uart_revb_regs_t *)uart, enable); +} + +int MXC_UART_SetTXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel) +{ + return MXC_UART_RevB_SetTXDMAChannel((mxc_uart_revb_regs_t *)uart, channel); +} + +int MXC_UART_GetTXDMAChannel(mxc_uart_regs_t *uart) +{ + return MXC_UART_RevB_GetTXDMAChannel((mxc_uart_revb_regs_t *)uart); +} + +int MXC_UART_SetRXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel) +{ + return MXC_UART_RevB_SetRXDMAChannel((mxc_uart_revb_regs_t *)uart, channel); +} + +int MXC_UART_GetRXDMAChannel(mxc_uart_regs_t *uart) +{ + return MXC_UART_RevB_GetTXDMAChannel((mxc_uart_revb_regs_t *)uart); +} From 2d325ebac170ec74fff67af363c11a45e3421068 Mon Sep 17 00:00:00 2001 From: Jake Carter Date: Fri, 20 Oct 2023 12:53:04 -0500 Subject: [PATCH 09/27] Add stdbool to all uart.h --- Libraries/PeriphDrivers/Include/MAX32520/uart.h | 1 + Libraries/PeriphDrivers/Include/MAX32570/uart.h | 1 + Libraries/PeriphDrivers/Include/MAX32572/uart.h | 1 + Libraries/PeriphDrivers/Include/MAX32650/uart.h | 1 + Libraries/PeriphDrivers/Include/MAX32655/uart.h | 1 + Libraries/PeriphDrivers/Include/MAX32660/uart.h | 1 + Libraries/PeriphDrivers/Include/MAX32662/uart.h | 1 + Libraries/PeriphDrivers/Include/MAX32665/uart.h | 1 + Libraries/PeriphDrivers/Include/MAX32670/uart.h | 1 + Libraries/PeriphDrivers/Include/MAX32672/uart.h | 1 + Libraries/PeriphDrivers/Include/MAX32675/uart.h | 1 + Libraries/PeriphDrivers/Include/MAX32680/uart.h | 1 + Libraries/PeriphDrivers/Include/MAX32690/uart.h | 1 + Libraries/PeriphDrivers/Include/MAX78002/uart.h | 1 + 14 files changed, 14 insertions(+) diff --git a/Libraries/PeriphDrivers/Include/MAX32520/uart.h b/Libraries/PeriphDrivers/Include/MAX32520/uart.h index 723c716c0b0..a6655ad795d 100644 --- a/Libraries/PeriphDrivers/Include/MAX32520/uart.h +++ b/Libraries/PeriphDrivers/Include/MAX32520/uart.h @@ -41,6 +41,7 @@ #define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32520_UART_H_ /***** Definitions *****/ +#include #include "uart_regs.h" #include "mxc_sys.h" diff --git a/Libraries/PeriphDrivers/Include/MAX32570/uart.h b/Libraries/PeriphDrivers/Include/MAX32570/uart.h index c59443bb32d..e6b5ef96ceb 100644 --- a/Libraries/PeriphDrivers/Include/MAX32570/uart.h +++ b/Libraries/PeriphDrivers/Include/MAX32570/uart.h @@ -41,6 +41,7 @@ #define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32570_UART_H_ /***** Definitions *****/ +#include #include "uart_regs.h" #include "mxc_sys.h" diff --git a/Libraries/PeriphDrivers/Include/MAX32572/uart.h b/Libraries/PeriphDrivers/Include/MAX32572/uart.h index 5db1f6835f2..b42e0848b20 100644 --- a/Libraries/PeriphDrivers/Include/MAX32572/uart.h +++ b/Libraries/PeriphDrivers/Include/MAX32572/uart.h @@ -41,6 +41,7 @@ #define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32572_UART_H_ /***** Definitions *****/ +#include #include "uart_regs.h" #include "mxc_sys.h" diff --git a/Libraries/PeriphDrivers/Include/MAX32650/uart.h b/Libraries/PeriphDrivers/Include/MAX32650/uart.h index 9e6bc22c9d3..b166e1d2045 100644 --- a/Libraries/PeriphDrivers/Include/MAX32650/uart.h +++ b/Libraries/PeriphDrivers/Include/MAX32650/uart.h @@ -41,6 +41,7 @@ #define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32650_UART_H_ /***** Includes *****/ +#include #include #include "uart_regs.h" #include "mxc_sys.h" diff --git a/Libraries/PeriphDrivers/Include/MAX32655/uart.h b/Libraries/PeriphDrivers/Include/MAX32655/uart.h index d76b9d16a6c..fe6dc712ce7 100644 --- a/Libraries/PeriphDrivers/Include/MAX32655/uart.h +++ b/Libraries/PeriphDrivers/Include/MAX32655/uart.h @@ -41,6 +41,7 @@ #define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32655_UART_H_ /***** Definitions *****/ +#include #include "uart_regs.h" #include "mxc_sys.h" diff --git a/Libraries/PeriphDrivers/Include/MAX32660/uart.h b/Libraries/PeriphDrivers/Include/MAX32660/uart.h index de822258fda..5af26338da3 100644 --- a/Libraries/PeriphDrivers/Include/MAX32660/uart.h +++ b/Libraries/PeriphDrivers/Include/MAX32660/uart.h @@ -41,6 +41,7 @@ #define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32660_UART_H_ /***** Definitions *****/ +#include #include "uart_regs.h" #include "mxc_sys.h" #include "mxc_pins.h" diff --git a/Libraries/PeriphDrivers/Include/MAX32662/uart.h b/Libraries/PeriphDrivers/Include/MAX32662/uart.h index c21ed891f79..2311d6ab58e 100644 --- a/Libraries/PeriphDrivers/Include/MAX32662/uart.h +++ b/Libraries/PeriphDrivers/Include/MAX32662/uart.h @@ -41,6 +41,7 @@ #define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32662_UART_H_ /***** Definitions *****/ +#include #include "uart_regs.h" #include "mxc_sys.h" #include "mxc_pins.h" diff --git a/Libraries/PeriphDrivers/Include/MAX32665/uart.h b/Libraries/PeriphDrivers/Include/MAX32665/uart.h index 400b5df820b..6f3f873b87f 100644 --- a/Libraries/PeriphDrivers/Include/MAX32665/uart.h +++ b/Libraries/PeriphDrivers/Include/MAX32665/uart.h @@ -41,6 +41,7 @@ #define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32665_UART_H_ /***** Definitions *****/ +#include #include "uart_regs.h" #include "mxc_sys.h" #include "mxc_pins.h" diff --git a/Libraries/PeriphDrivers/Include/MAX32670/uart.h b/Libraries/PeriphDrivers/Include/MAX32670/uart.h index 99b5c3e0b0a..204e7d2a667 100644 --- a/Libraries/PeriphDrivers/Include/MAX32670/uart.h +++ b/Libraries/PeriphDrivers/Include/MAX32670/uart.h @@ -41,6 +41,7 @@ #define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32670_UART_H_ /***** Definitions *****/ +#include #include "uart_regs.h" #include "mxc_sys.h" diff --git a/Libraries/PeriphDrivers/Include/MAX32672/uart.h b/Libraries/PeriphDrivers/Include/MAX32672/uart.h index 789bb630d4d..515e0363541 100644 --- a/Libraries/PeriphDrivers/Include/MAX32672/uart.h +++ b/Libraries/PeriphDrivers/Include/MAX32672/uart.h @@ -41,6 +41,7 @@ #define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32672_UART_H_ /***** Definitions *****/ +#include #include "uart_regs.h" #include "mxc_sys.h" diff --git a/Libraries/PeriphDrivers/Include/MAX32675/uart.h b/Libraries/PeriphDrivers/Include/MAX32675/uart.h index ec03544821d..22f1b623ec9 100644 --- a/Libraries/PeriphDrivers/Include/MAX32675/uart.h +++ b/Libraries/PeriphDrivers/Include/MAX32675/uart.h @@ -41,6 +41,7 @@ #define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32675_UART_H_ /***** Definitions *****/ +#include #include "uart_regs.h" #include "mxc_sys.h" diff --git a/Libraries/PeriphDrivers/Include/MAX32680/uart.h b/Libraries/PeriphDrivers/Include/MAX32680/uart.h index 48d75739701..350d001605b 100644 --- a/Libraries/PeriphDrivers/Include/MAX32680/uart.h +++ b/Libraries/PeriphDrivers/Include/MAX32680/uart.h @@ -41,6 +41,7 @@ #define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32680_UART_H_ /***** Definitions *****/ +#include #include "uart_regs.h" #include "mxc_sys.h" diff --git a/Libraries/PeriphDrivers/Include/MAX32690/uart.h b/Libraries/PeriphDrivers/Include/MAX32690/uart.h index 5c8ed9173e6..92f47ce86ae 100644 --- a/Libraries/PeriphDrivers/Include/MAX32690/uart.h +++ b/Libraries/PeriphDrivers/Include/MAX32690/uart.h @@ -41,6 +41,7 @@ #define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32690_UART_H_ /***** Definitions *****/ +#include #include "uart_regs.h" #include "mxc_sys.h" diff --git a/Libraries/PeriphDrivers/Include/MAX78002/uart.h b/Libraries/PeriphDrivers/Include/MAX78002/uart.h index e23ab97586b..a1c1bd20966 100644 --- a/Libraries/PeriphDrivers/Include/MAX78002/uart.h +++ b/Libraries/PeriphDrivers/Include/MAX78002/uart.h @@ -41,6 +41,7 @@ #define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX78002_UART_H_ /***** Definitions *****/ +#include #include "uart_regs.h" #include "mxc_sys.h" From 07eef601412fbab361271635b107b57414cc1887 Mon Sep 17 00:00:00 2001 From: Jake Carter Date: Fri, 20 Oct 2023 13:07:02 -0500 Subject: [PATCH 10/27] Add RevA passthroughs --- .../PeriphDrivers/Source/UART/uart_me10.c | 21 +++++++++++++++++++ .../PeriphDrivers/Source/UART/uart_me11.c | 21 +++++++++++++++++++ .../PeriphDrivers/Source/UART/uart_me13.c | 21 +++++++++++++++++++ 3 files changed, 63 insertions(+) diff --git a/Libraries/PeriphDrivers/Source/UART/uart_me10.c b/Libraries/PeriphDrivers/Source/UART/uart_me10.c index cecb206cc31..cfd953da52a 100644 --- a/Libraries/PeriphDrivers/Source/UART/uart_me10.c +++ b/Libraries/PeriphDrivers/Source/UART/uart_me10.c @@ -520,3 +520,24 @@ uint32_t MXC_UART_GetAsyncRXCount(mxc_uart_req_t *req) { return req->rxCnt; } + +int MXC_UART_SetAutoDMAHandlers(mxc_uart_regs_t *uart, bool enable) +{ + return MXC_UART_RevA_SetAutoDMAHandlers((mxc_uart_reva_regs_t *)uart, enable); +} +int MXC_UART_SetTXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel) +{ + return MXC_UART_RevA_SetTXDMAChannel((mxc_uart_reva_regs_t *)uart, channel); +} +int MXC_UART_GetTXDMAChannel(mxc_uart_regs_t *uart) +{ + return MXC_UART_RevA_GetTXDMAChannel((mxc_uart_reva_regs_t *)uart); +} +int MXC_UART_SetRXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel) +{ + return MXC_UART_RevA_SetRXDMAChannel((mxc_uart_reva_regs_t *)uart, channel); +} +int MXC_UART_GetRXDMAChannel(mxc_uart_regs_t *uart) +{ + return MXC_UART_RevA_GetRXDMAChannel((mxc_uart_reva_regs_t *)uart); +} diff --git a/Libraries/PeriphDrivers/Source/UART/uart_me11.c b/Libraries/PeriphDrivers/Source/UART/uart_me11.c index e7db0c8f0d5..e77a97265da 100644 --- a/Libraries/PeriphDrivers/Source/UART/uart_me11.c +++ b/Libraries/PeriphDrivers/Source/UART/uart_me11.c @@ -410,3 +410,24 @@ uint32_t MXC_UART_GetAsyncRXCount(mxc_uart_req_t *req) { return req->rxCnt; } + +int MXC_UART_SetAutoDMAHandlers(mxc_uart_regs_t *uart, bool enable) +{ + return MXC_UART_RevA_SetAutoDMAHandlers((mxc_uart_reva_regs_t *)uart, enable); +} +int MXC_UART_SetTXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel) +{ + return MXC_UART_RevA_SetTXDMAChannel((mxc_uart_reva_regs_t *)uart, channel); +} +int MXC_UART_GetTXDMAChannel(mxc_uart_regs_t *uart) +{ + return MXC_UART_RevA_GetTXDMAChannel((mxc_uart_reva_regs_t *)uart); +} +int MXC_UART_SetRXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel) +{ + return MXC_UART_RevA_SetRXDMAChannel((mxc_uart_reva_regs_t *)uart, channel); +} +int MXC_UART_GetRXDMAChannel(mxc_uart_regs_t *uart) +{ + return MXC_UART_RevA_GetRXDMAChannel((mxc_uart_reva_regs_t *)uart); +} diff --git a/Libraries/PeriphDrivers/Source/UART/uart_me13.c b/Libraries/PeriphDrivers/Source/UART/uart_me13.c index d8e59da15d5..bb5fb499cae 100644 --- a/Libraries/PeriphDrivers/Source/UART/uart_me13.c +++ b/Libraries/PeriphDrivers/Source/UART/uart_me13.c @@ -459,3 +459,24 @@ uint32_t MXC_UART_GetAsyncRXCount(mxc_uart_req_t *req) { return req->rxCnt; } + +int MXC_UART_SetAutoDMAHandlers(mxc_uart_regs_t *uart, bool enable) +{ + return MXC_UART_RevA_SetAutoDMAHandlers((mxc_uart_reva_regs_t *)uart, enable); +} +int MXC_UART_SetTXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel) +{ + return MXC_UART_RevA_SetTXDMAChannel((mxc_uart_reva_regs_t *)uart, channel); +} +int MXC_UART_GetTXDMAChannel(mxc_uart_regs_t *uart) +{ + return MXC_UART_RevA_GetTXDMAChannel((mxc_uart_reva_regs_t *)uart); +} +int MXC_UART_SetRXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel) +{ + return MXC_UART_RevA_SetRXDMAChannel((mxc_uart_reva_regs_t *)uart, channel); +} +int MXC_UART_GetRXDMAChannel(mxc_uart_regs_t *uart) +{ + return MXC_UART_RevA_GetRXDMAChannel((mxc_uart_reva_regs_t *)uart); +} From 2d5ec9365e6ef24c5535322dc32e154b390f6ee9 Mon Sep 17 00:00:00 2001 From: Jake Carter Date: Fri, 20 Oct 2023 18:04:06 -0500 Subject: [PATCH 11/27] Fix req clobbering and callbacks for RevA Fix comment --- .../PeriphDrivers/Source/UART/uart_reva.c | 64 +++++++++++++------ 1 file changed, 45 insertions(+), 19 deletions(-) diff --git a/Libraries/PeriphDrivers/Source/UART/uart_reva.c b/Libraries/PeriphDrivers/Source/UART/uart_reva.c index e4777d6bc43..1b9bfcd6a6e 100644 --- a/Libraries/PeriphDrivers/Source/UART/uart_reva.c +++ b/Libraries/PeriphDrivers/Source/UART/uart_reva.c @@ -56,7 +56,8 @@ static void *RxAsyncRequests[MXC_UART_INSTANCES]; // Structure to save DMA state typedef struct { - mxc_uart_reva_req_t *req; + mxc_uart_reva_req_t *tx_req; + mxc_uart_reva_req_t *rx_req; int channelTx; int channelRx; bool auto_dma_handlers; @@ -106,7 +107,8 @@ int MXC_UART_RevA_Init(mxc_uart_reva_regs_t *uart, unsigned int baud) for (int i = 0; i < MXC_UART_INSTANCES; i++) { states[i].channelRx = -1; states[i].channelTx = -1; - states[i].req = NULL; + states[i].tx_req = NULL; + states[i].rx_req = NULL; states[i].auto_dma_handlers = false; } @@ -588,7 +590,7 @@ void MXC_UART_RevA_DMA_SetupAutoHandlers(mxc_dma_regs_t *dma_instance, unsigned Some complications make this the most attractive short-term option. We could handle multiple DMA instances better in the DMA API (See the mismatch between the size of "dma_resource" array and the number of channels per instance, to start)*/ if (dma_instance == MXC_DMA0) { - MXC_NVIC_SetVector(MXC_DMA_CH_GET_IRQ(channel), MXC_UART_RevA_DMA0_Handler); + MXC_NVIC_SetVector(MXC_DMA_CH_GET_IRQ(channel), MXC_UART_RevA_DMA0_Handler); } else if (dma_instance == MXC_DMA1) { MXC_NVIC_SetVector(MXC_DMA_CH_GET_IRQ(channel), MXC_UART_RevA_DMA1_Handler); } @@ -924,7 +926,7 @@ int MXC_UART_RevA_Busy(mxc_uart_reva_regs_t *uart) return E_BUSY; } // Check to see if there are any ongoing transactions and the UART has room in its FIFO - if ((states[uart_num].req == NULL) && !(uart->status & MXC_F_UART_REVA_STATUS_TX_FULL)) { + if ((states[uart_num].tx_req == NULL) && (states[uart_num].rx_req == NULL) && !(uart->status & MXC_F_UART_REVA_STATUS_TX_FULL)) { return E_NO_ERROR; } @@ -1070,13 +1072,13 @@ int MXC_UART_RevA_TransactionDMA(mxc_uart_reva_req_t *req, mxc_dma_regs_t *dma) } } - states[uart_num].req = req; // Callback lookups are dependent saved state info - MXC_UART_DisableInt((mxc_uart_regs_t *)(req->uart), 0xFFFFFFFF); MXC_UART_ClearFlags((mxc_uart_regs_t *)(req->uart), 0xFFFFFFFF); - MXC_UART_ClearRXFIFO((mxc_uart_regs_t *)(req->uart)); - MXC_UART_ClearTXFIFO((mxc_uart_regs_t *)(req->uart)); + /* Clearing the RX FIFOs here makes RX-only or TX-only transactions half-duplex... + Commenting out for now.*/ + // MXC_UART_ClearRXFIFO((mxc_uart_regs_t *)(req->uart)); + // MXC_UART_ClearTXFIFO((mxc_uart_regs_t *)(req->uart)); (req->uart)->dma |= (1 << MXC_F_UART_REVA_DMA_RXDMA_LEVEL_POS); // Set RX DMA threshold to 1 byte @@ -1089,8 +1091,14 @@ int MXC_UART_RevA_TransactionDMA(mxc_uart_reva_req_t *req, mxc_dma_regs_t *dma) MXC_DMA_Init(); #endif + // Reset rx/tx counters + req->rxCnt = 0; + req->txCnt = 0; + //tx if ((req->txData != NULL) && (req->txLen)) { + /* Save TX req, the DMA handler will use this later. */ + states[uart_num].tx_req = req; #if TARGET_NUM == 32665 if (MXC_UART_WriteTXFIFODMA((mxc_uart_regs_t *)(req->uart), dma, req->txData, req->txLen, NULL) != E_NO_ERROR) { @@ -1105,6 +1113,7 @@ int MXC_UART_RevA_TransactionDMA(mxc_uart_reva_req_t *req, mxc_dma_regs_t *dma) } if ((req->rxData != NULL) && (req->rxLen)) { + states[uart_num].rx_req = req; #if TARGET_NUM == 32665 if (MXC_UART_ReadRXFIFODMA((mxc_uart_regs_t *)(req->uart), dma, req->rxData, req->rxLen, NULL) != E_NO_ERROR) { @@ -1123,25 +1132,42 @@ int MXC_UART_RevA_TransactionDMA(mxc_uart_reva_req_t *req, mxc_dma_regs_t *dma) void MXC_UART_RevA_DMACallback(int ch, int error) { - mxc_uart_reva_req_t *temp_req; + mxc_uart_reva_req_t *temp_req = NULL; for (int i = 0; i < MXC_UART_INSTANCES; i++) { - if (states[i].channelTx == ch || states[i].channelRx == ch) { - //save the request - temp_req = states[i].req; - // Callback if not NULL - if (temp_req->callback != NULL) { - temp_req->callback((mxc_uart_req_t *)temp_req, E_NO_ERROR); + if (states[i].channelTx == ch) { + /* Populate txLen. The number of "remainder" bytes is what's left on the + DMA channel's count register. */ + states[i].tx_req->txCnt = states[i].tx_req->txLen - MXC_DMA->ch[ch].cnt; + + temp_req = states[i].tx_req; + + if (states[i].auto_dma_handlers) { + /* Release channel _before_ running callback in case + user wants to start another transaction inside it */ + MXC_DMA_ReleaseChannel(ch); + states[i].channelTx = -1; } + if (temp_req->callback != NULL && ((states[i].tx_req->rxCnt == states[i].tx_req->rxLen) || states[i].tx_req->rxData == NULL)) { + /* Only call TX callback if RX component is complete/disabled. Note that + we are checking the request associated with the _channel_ assignment, not + the other side of the state struct. */ + temp_req->callback((mxc_uart_req_t *)temp_req, E_NO_ERROR); + } + break; + } else if (states[i].channelRx == ch) { + /* Same as above, but for RX */ + states[i].rx_req->rxCnt = states[i].rx_req->rxLen - MXC_DMA->ch[ch].cnt; + temp_req = states[i].rx_req; if (states[i].auto_dma_handlers) { MXC_DMA_ReleaseChannel(ch); - if (ch == states[i].channelRx) - states[i].channelRx = -1; - else - states[i].channelTx = -1; + states[i].channelRx = -1; } + if (temp_req->callback != NULL && ((states[i].rx_req->txCnt == states[i].rx_req->txLen) || states[i].rx_req->txData == NULL)) { + temp_req->callback((mxc_uart_req_t *)temp_req, E_NO_ERROR); + } break; } } From a03f22b989200b4eba1d353fc32842bb143d3e5d Mon Sep 17 00:00:00 2001 From: Jake Carter Date: Fri, 20 Oct 2023 18:10:15 -0500 Subject: [PATCH 12/27] Fix req clobbering and callbacks for RevB --- .../PeriphDrivers/Source/UART/uart_revb.c | 49 ++++++++++--------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/Libraries/PeriphDrivers/Source/UART/uart_revb.c b/Libraries/PeriphDrivers/Source/UART/uart_revb.c index 458d6cd3e95..13863a72629 100644 --- a/Libraries/PeriphDrivers/Source/UART/uart_revb.c +++ b/Libraries/PeriphDrivers/Source/UART/uart_revb.c @@ -53,7 +53,8 @@ static void *AsyncTxRequests[MXC_UART_INSTANCES]; static void *AsyncRxRequests[MXC_UART_INSTANCES]; typedef struct { - mxc_uart_revb_req_t *req; + mxc_uart_revb_req_t *tx_req; + mxc_uart_revb_req_t *rx_req; int channelTx; int channelRx; bool auto_dma_handlers; @@ -103,7 +104,8 @@ int MXC_UART_RevB_Init(mxc_uart_revb_regs_t *uart, unsigned int baud, mxc_uart_r for (int i = 0; i < MXC_UART_INSTANCES; i++) { states[i].channelRx = -1; states[i].channelTx = -1; - states[i].req = NULL; + states[i].tx_req = NULL; + states[i].rx_req = NULL; states[i].auto_dma_handlers = false; } @@ -1140,26 +1142,27 @@ int MXC_UART_RevB_TransactionDMA(mxc_uart_revb_req_t *req) MXC_DMA_Init(); + // Reset rx/tx counters, + req->rxCnt = 0; + req->txCnt = 0; + //tx if ((req->txData != NULL) && (req->txLen)) { + /* Save TX req, the DMA handler will use this later. */ + states[uart_num].tx_req = req; if (MXC_UART_WriteTXFIFODMA((mxc_uart_regs_t *)(req->uart), req->txData, req->txLen, NULL) != E_NO_ERROR) { return E_BAD_PARAM; } - - // Save state for UART DMACallback function. - states[uart_num].req = req; } //rx if ((req->rxData != NULL) && (req->rxLen)) { + states[uart_num].rx_req = req; if (MXC_UART_ReadRXFIFODMA((mxc_uart_regs_t *)(req->uart), req->rxData, req->rxLen, NULL) != E_NO_ERROR) { return E_BAD_PARAM; } - - // Save state for UART DMACallback function. - states[uart_num].req = req; } return E_NO_ERROR; @@ -1171,36 +1174,36 @@ void MXC_UART_RevB_DMACallback(int ch, int error) for (int i = 0; i < MXC_UART_INSTANCES; i++) { if (states[i].channelTx == ch) { - // Populate txLen. The number of "remainder" bytes is what's left on the - // DMA channel's count register. - states[i].req->txCnt = states[i].req->txLen - MXC_DMA->ch[ch].cnt; - //save the request + /* Populate txLen. The number of "remainder" bytes is what's left on the + DMA channel's count register. */ + states[i].tx_req->txCnt = states[i].tx_req->txLen - MXC_DMA->ch[ch].cnt; + + temp_req = states[i].tx_req; if (states[i].auto_dma_handlers) { + /* Release channel _before_ running callback in case + user wants to start another transaction inside it */ MXC_DMA_ReleaseChannel(ch); states[i].channelTx = -1; } - temp_req = states[i].req; - - // Callback if not NULL - if (temp_req->callback != NULL) { + if (temp_req->callback != NULL && ((states[i].tx_req->rxCnt == states[i].tx_req->rxLen) || states[i].tx_req->rxData == NULL)) { + /* Only call TX callback if RX component is complete/disabled. Note that + we are checking the request associated with the _channel_ assignment, not + the other side of the state struct. */ temp_req->callback((mxc_uart_req_t *)temp_req, E_NO_ERROR); } break; } else if (states[i].channelRx == ch) { - states[i].req->rxCnt = states[i].req->rxLen - MXC_DMA->ch[ch].cnt; - + /* Same as above, but for RX */ + states[i].rx_req->rxCnt = states[i].rx_req->rxLen - MXC_DMA->ch[ch].cnt; + temp_req = states[i].rx_req; if (states[i].auto_dma_handlers) { MXC_DMA_ReleaseChannel(ch); states[i].channelRx = -1; } - //save the request - temp_req = states[i].req; - - // Callback if not NULL - if (temp_req->callback != NULL) { + if (temp_req->callback != NULL && ((states[i].rx_req->txCnt == states[i].rx_req->txLen) || states[i].rx_req->txData == NULL)) { temp_req->callback((mxc_uart_req_t *)temp_req, E_NO_ERROR); } break; From 2cd7d4ffd4a40f7489e81f3c398f9cbe0044256c Mon Sep 17 00:00:00 2001 From: Jake Carter Date: Fri, 20 Oct 2023 18:14:20 -0500 Subject: [PATCH 13/27] Fix build error --- Libraries/PeriphDrivers/Source/UART/uart_reva.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Libraries/PeriphDrivers/Source/UART/uart_reva.c b/Libraries/PeriphDrivers/Source/UART/uart_reva.c index 1b9bfcd6a6e..833265302f1 100644 --- a/Libraries/PeriphDrivers/Source/UART/uart_reva.c +++ b/Libraries/PeriphDrivers/Source/UART/uart_reva.c @@ -596,7 +596,7 @@ void MXC_UART_RevA_DMA_SetupAutoHandlers(mxc_dma_regs_t *dma_instance, unsigned } #else // Only one DMA instance, we can point direct to MXC_DMA_Handler - MXC_NVIC_SetVector(MXC_UART_RevA_DMA0_Handler, MXC_DMA_Handler); + MXC_NVIC_SetVector(MXC_DMA_CH_GET_IRQ(channel), MXC_DMA_Handler); #endif // MXC_DMA_INSTANCES > 1 #else From d9e94416e5d6fcd1ead3511c95499dd23fb12163 Mon Sep 17 00:00:00 2001 From: Jake Carter Date: Fri, 20 Oct 2023 18:30:12 -0500 Subject: [PATCH 14/27] clang-format --- Libraries/PeriphDrivers/Include/MAX78000/uart.h | 1 - Libraries/PeriphDrivers/Source/UART/uart_reva.c | 13 +++++++++---- Libraries/PeriphDrivers/Source/UART/uart_revb.c | 10 +++++++--- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Libraries/PeriphDrivers/Include/MAX78000/uart.h b/Libraries/PeriphDrivers/Include/MAX78000/uart.h index 72b3f675afc..6b3f1768cbf 100644 --- a/Libraries/PeriphDrivers/Include/MAX78000/uart.h +++ b/Libraries/PeriphDrivers/Include/MAX78000/uart.h @@ -735,7 +735,6 @@ int MXC_UART_SetRXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel); */ int MXC_UART_GetRXDMAChannel(mxc_uart_regs_t *uart); - /**@} end of group uart */ #ifdef __cplusplus diff --git a/Libraries/PeriphDrivers/Source/UART/uart_reva.c b/Libraries/PeriphDrivers/Source/UART/uart_reva.c index 833265302f1..51d709205cf 100644 --- a/Libraries/PeriphDrivers/Source/UART/uart_reva.c +++ b/Libraries/PeriphDrivers/Source/UART/uart_reva.c @@ -590,7 +590,7 @@ void MXC_UART_RevA_DMA_SetupAutoHandlers(mxc_dma_regs_t *dma_instance, unsigned Some complications make this the most attractive short-term option. We could handle multiple DMA instances better in the DMA API (See the mismatch between the size of "dma_resource" array and the number of channels per instance, to start)*/ if (dma_instance == MXC_DMA0) { - MXC_NVIC_SetVector(MXC_DMA_CH_GET_IRQ(channel), MXC_UART_RevA_DMA0_Handler); + MXC_NVIC_SetVector(MXC_DMA_CH_GET_IRQ(channel), MXC_UART_RevA_DMA0_Handler); } else if (dma_instance == MXC_DMA1) { MXC_NVIC_SetVector(MXC_DMA_CH_GET_IRQ(channel), MXC_UART_RevA_DMA1_Handler); } @@ -926,7 +926,8 @@ int MXC_UART_RevA_Busy(mxc_uart_reva_regs_t *uart) return E_BUSY; } // Check to see if there are any ongoing transactions and the UART has room in its FIFO - if ((states[uart_num].tx_req == NULL) && (states[uart_num].rx_req == NULL) && !(uart->status & MXC_F_UART_REVA_STATUS_TX_FULL)) { + if ((states[uart_num].tx_req == NULL) && (states[uart_num].rx_req == NULL) && + !(uart->status & MXC_F_UART_REVA_STATUS_TX_FULL)) { return E_NO_ERROR; } @@ -1149,7 +1150,9 @@ void MXC_UART_RevA_DMACallback(int ch, int error) states[i].channelTx = -1; } - if (temp_req->callback != NULL && ((states[i].tx_req->rxCnt == states[i].tx_req->rxLen) || states[i].tx_req->rxData == NULL)) { + if (temp_req->callback != NULL && + ((states[i].tx_req->rxCnt == states[i].tx_req->rxLen) || + states[i].tx_req->rxData == NULL)) { /* Only call TX callback if RX component is complete/disabled. Note that we are checking the request associated with the _channel_ assignment, not the other side of the state struct. */ @@ -1165,7 +1168,9 @@ void MXC_UART_RevA_DMACallback(int ch, int error) states[i].channelRx = -1; } - if (temp_req->callback != NULL && ((states[i].rx_req->txCnt == states[i].rx_req->txLen) || states[i].rx_req->txData == NULL)) { + if (temp_req->callback != NULL && + ((states[i].rx_req->txCnt == states[i].rx_req->txLen) || + states[i].rx_req->txData == NULL)) { temp_req->callback((mxc_uart_req_t *)temp_req, E_NO_ERROR); } break; diff --git a/Libraries/PeriphDrivers/Source/UART/uart_revb.c b/Libraries/PeriphDrivers/Source/UART/uart_revb.c index 13863a72629..3457f3b5d14 100644 --- a/Libraries/PeriphDrivers/Source/UART/uart_revb.c +++ b/Libraries/PeriphDrivers/Source/UART/uart_revb.c @@ -371,7 +371,7 @@ int MXC_UART_RevB_AbortTransmission(mxc_uart_revb_regs_t *uart) int uart_num = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); if (states[uart_num].channelTx >= 0) { - MXC_DMA_Stop(states[uart_num].channelTx); + MXC_DMA_Stop(states[uart_num].channelTx); } if (states[uart_num].channelRx >= 0) { MXC_DMA_Stop(states[uart_num].channelRx); @@ -1187,7 +1187,9 @@ void MXC_UART_RevB_DMACallback(int ch, int error) states[i].channelTx = -1; } - if (temp_req->callback != NULL && ((states[i].tx_req->rxCnt == states[i].tx_req->rxLen) || states[i].tx_req->rxData == NULL)) { + if (temp_req->callback != NULL && + ((states[i].tx_req->rxCnt == states[i].tx_req->rxLen) || + states[i].tx_req->rxData == NULL)) { /* Only call TX callback if RX component is complete/disabled. Note that we are checking the request associated with the _channel_ assignment, not the other side of the state struct. */ @@ -1203,7 +1205,9 @@ void MXC_UART_RevB_DMACallback(int ch, int error) states[i].channelRx = -1; } - if (temp_req->callback != NULL && ((states[i].rx_req->txCnt == states[i].rx_req->txLen) || states[i].rx_req->txData == NULL)) { + if (temp_req->callback != NULL && + ((states[i].rx_req->txCnt == states[i].rx_req->txLen) || + states[i].rx_req->txData == NULL)) { temp_req->callback((mxc_uart_req_t *)temp_req, E_NO_ERROR); } break; From fe51c36edaccedce608f3af534df9825ac64222c Mon Sep 17 00:00:00 2001 From: Jake Carter Date: Mon, 23 Oct 2023 17:38:46 -0500 Subject: [PATCH 15/27] Add newline at end of file --- Libraries/PeriphDrivers/Source/UART/uart_me15.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Libraries/PeriphDrivers/Source/UART/uart_me15.c b/Libraries/PeriphDrivers/Source/UART/uart_me15.c index b56ce3fd59a..fc3274e0ce0 100644 --- a/Libraries/PeriphDrivers/Source/UART/uart_me15.c +++ b/Libraries/PeriphDrivers/Source/UART/uart_me15.c @@ -573,4 +573,5 @@ int MXC_UART_SetRXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel) int MXC_UART_GetRXDMAChannel(mxc_uart_regs_t *uart) { return MXC_UART_RevB_GetTXDMAChannel((mxc_uart_revb_regs_t *)uart); -} \ No newline at end of file +} + From dc04d78fd1b005b7da86f3e75e341b9a0868417a Mon Sep 17 00:00:00 2001 From: Jake Carter Date: Mon, 23 Oct 2023 17:41:56 -0500 Subject: [PATCH 16/27] Fix -1 assigned to uint8_t --- Libraries/PeriphDrivers/Source/UART/uart_reva.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Libraries/PeriphDrivers/Source/UART/uart_reva.c b/Libraries/PeriphDrivers/Source/UART/uart_reva.c index 51d709205cf..346955c9f11 100644 --- a/Libraries/PeriphDrivers/Source/UART/uart_reva.c +++ b/Libraries/PeriphDrivers/Source/UART/uart_reva.c @@ -742,7 +742,7 @@ unsigned int MXC_UART_RevA_WriteTXFIFODMA(mxc_uart_reva_regs_t *uart, mxc_dma_re mxc_uart_dma_complete_cb_t callback, mxc_dma_config_t config) { - uint8_t channel = -1; + int channel = -1; mxc_dma_srcdst_t srcdst; int uart_num = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); From 2ea9524eaa2530e7cd94a89c37f7c4950ad4b027 Mon Sep 17 00:00:00 2001 From: EricB-ADI Date: Tue, 24 Oct 2023 13:44:06 +0000 Subject: [PATCH 17/27] clang-format bot reformatting. --- Libraries/PeriphDrivers/Source/UART/uart_me15.c | 1 - 1 file changed, 1 deletion(-) diff --git a/Libraries/PeriphDrivers/Source/UART/uart_me15.c b/Libraries/PeriphDrivers/Source/UART/uart_me15.c index fc3274e0ce0..35e835882a9 100644 --- a/Libraries/PeriphDrivers/Source/UART/uart_me15.c +++ b/Libraries/PeriphDrivers/Source/UART/uart_me15.c @@ -574,4 +574,3 @@ int MXC_UART_GetRXDMAChannel(mxc_uart_regs_t *uart) { return MXC_UART_RevB_GetTXDMAChannel((mxc_uart_revb_regs_t *)uart); } - From aba737e985043ccafc06bef952901d8a58ba885f Mon Sep 17 00:00:00 2001 From: Jake Carter Date: Wed, 25 Oct 2023 14:15:23 -0500 Subject: [PATCH 18/27] Remove UART FIFO clears in me21 file --- Libraries/PeriphDrivers/Source/UART/uart_me21.c | 9 --------- 1 file changed, 9 deletions(-) diff --git a/Libraries/PeriphDrivers/Source/UART/uart_me21.c b/Libraries/PeriphDrivers/Source/UART/uart_me21.c index 180e27153d7..7add8856a63 100644 --- a/Libraries/PeriphDrivers/Source/UART/uart_me21.c +++ b/Libraries/PeriphDrivers/Source/UART/uart_me21.c @@ -512,25 +512,16 @@ unsigned int MXC_UART_GetStatus(mxc_uart_regs_t *uart) int MXC_UART_Transaction(mxc_uart_req_t *req) { - MXC_UART_ClearRXFIFO(req->uart); - MXC_UART_ClearTXFIFO(req->uart); - return MXC_UART_RevB_Transaction((mxc_uart_revb_req_t *)req); } int MXC_UART_TransactionAsync(mxc_uart_req_t *req) { - MXC_UART_ClearRXFIFO(req->uart); - MXC_UART_ClearTXFIFO(req->uart); - return MXC_UART_RevB_TransactionAsync((mxc_uart_revb_req_t *)req); } int MXC_UART_TransactionDMA(mxc_uart_req_t *req) { - MXC_UART_ClearRXFIFO(req->uart); - MXC_UART_ClearTXFIFO(req->uart); - return MXC_UART_RevB_TransactionDMA((mxc_uart_revb_req_t *)req); } From 831c893012b439cbbb9cc00915c129b3b1d59a79 Mon Sep 17 00:00:00 2001 From: Jake Carter Date: Mon, 13 Nov 2023 15:54:16 -0600 Subject: [PATCH 19/27] Address Lorne review notes --- .../PeriphDrivers/Source/UART/uart_reva.c | 18 ++++++++---------- .../PeriphDrivers/Source/UART/uart_revb.c | 16 +++++++--------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/Libraries/PeriphDrivers/Source/UART/uart_reva.c b/Libraries/PeriphDrivers/Source/UART/uart_reva.c index 346955c9f11..a8819f2a860 100644 --- a/Libraries/PeriphDrivers/Source/UART/uart_reva.c +++ b/Libraries/PeriphDrivers/Source/UART/uart_reva.c @@ -104,13 +104,12 @@ int MXC_UART_RevA_Init(mxc_uart_reva_regs_t *uart, unsigned int baud) MXC_UART_SetFrequency((mxc_uart_regs_t *)uart, baud); // Initialize state struct - for (int i = 0; i < MXC_UART_INSTANCES; i++) { - states[i].channelRx = -1; - states[i].channelTx = -1; - states[i].tx_req = NULL; - states[i].rx_req = NULL; - states[i].auto_dma_handlers = false; - } + unsigned int i = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); + states[i].channelRx = -1; + states[i].channelTx = -1; + states[i].tx_req = NULL; + states[i].rx_req = NULL; + states[i].auto_dma_handlers = false; return E_NO_ERROR; } @@ -624,7 +623,7 @@ int MXC_UART_RevA_ReadRXFIFODMA(mxc_uart_reva_regs_t *uart, mxc_dma_regs_t *dma, if (states[uart_num].auto_dma_handlers) { /* Acquire channel */ -#if TARGET_NUM == 32665 +#if MXC_DMA_INSTANCES > 1 channel = MXC_DMA_AcquireChannel(dma); #else channel = MXC_DMA_AcquireChannel(); @@ -689,8 +688,7 @@ unsigned int MXC_UART_RevA_WriteTXFIFO(mxc_uart_reva_regs_t *uart, unsigned char int MXC_UART_RevA_SetAutoDMAHandlers(mxc_uart_reva_regs_t *uart, bool enable) { int n = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); - if (n < 0) - return E_BAD_PARAM; + MXC_ASSERT(n >= 0); states[n].auto_dma_handlers = enable; diff --git a/Libraries/PeriphDrivers/Source/UART/uart_revb.c b/Libraries/PeriphDrivers/Source/UART/uart_revb.c index 3457f3b5d14..6c4f5706eb9 100644 --- a/Libraries/PeriphDrivers/Source/UART/uart_revb.c +++ b/Libraries/PeriphDrivers/Source/UART/uart_revb.c @@ -101,13 +101,12 @@ int MXC_UART_RevB_Init(mxc_uart_revb_regs_t *uart, unsigned int baud, mxc_uart_r } // Initialize state struct - for (int i = 0; i < MXC_UART_INSTANCES; i++) { - states[i].channelRx = -1; - states[i].channelTx = -1; - states[i].tx_req = NULL; - states[i].rx_req = NULL; - states[i].auto_dma_handlers = false; - } + unsigned int i = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); + states[i].channelRx = -1; + states[i].channelTx = -1; + states[i].tx_req = NULL; + states[i].rx_req = NULL; + states[i].auto_dma_handlers = false; return E_NO_ERROR; } @@ -946,8 +945,7 @@ int MXC_UART_RevB_AsyncHandler(mxc_uart_revb_regs_t *uart) int MXC_UART_RevB_SetAutoDMAHandlers(mxc_uart_revb_regs_t *uart, bool enable) { int n = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); - if (n < 0) - return E_BAD_PARAM; + MXC_ASSERT(n >= 0); states[n].auto_dma_handlers = enable; From 8086917a94d1086114ceb8e239df627f194d0622 Mon Sep 17 00:00:00 2001 From: Jake Carter Date: Mon, 13 Nov 2023 16:32:21 -0600 Subject: [PATCH 20/27] Only acquire channel if we don't have one already --- Libraries/PeriphDrivers/Source/UART/uart_reva.c | 8 ++++---- Libraries/PeriphDrivers/Source/UART/uart_revb.c | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Libraries/PeriphDrivers/Source/UART/uart_reva.c b/Libraries/PeriphDrivers/Source/UART/uart_reva.c index a8819f2a860..4d91ad4d653 100644 --- a/Libraries/PeriphDrivers/Source/UART/uart_reva.c +++ b/Libraries/PeriphDrivers/Source/UART/uart_reva.c @@ -621,8 +621,8 @@ int MXC_UART_RevA_ReadRXFIFODMA(mxc_uart_reva_regs_t *uart, mxc_dma_regs_t *dma, return E_NULL_PTR; } - if (states[uart_num].auto_dma_handlers) { - /* Acquire channel */ + if (states[uart_num].auto_dma_handlers && states[uart_num].channelRx < 0) { + /* Acquire channel if we don't have one already */ #if MXC_DMA_INSTANCES > 1 channel = MXC_DMA_AcquireChannel(dma); #else @@ -753,8 +753,8 @@ unsigned int MXC_UART_RevA_WriteTXFIFODMA(mxc_uart_reva_regs_t *uart, mxc_dma_re return E_NULL_PTR; } - if (states[uart_num].auto_dma_handlers) { - /* Acquire channel */ + if (states[uart_num].auto_dma_handlers && states[uart_num].channelTx < 0) { + /* Acquire channel if we don't have one already */ #if TARGET_NUM == 32665 channel = MXC_DMA_AcquireChannel(dma); #else diff --git a/Libraries/PeriphDrivers/Source/UART/uart_revb.c b/Libraries/PeriphDrivers/Source/UART/uart_revb.c index 6c4f5706eb9..7fdffff5251 100644 --- a/Libraries/PeriphDrivers/Source/UART/uart_revb.c +++ b/Libraries/PeriphDrivers/Source/UART/uart_revb.c @@ -1019,8 +1019,8 @@ int MXC_UART_RevB_ReadRXFIFODMA(mxc_uart_revb_regs_t *uart, unsigned char *bytes return E_NULL_PTR; } - if (states[uart_num].auto_dma_handlers) { - /* Acquire channel */ + if (states[uart_num].auto_dma_handlers && states[uart_num].channelRx < 0) { + /* Acquire channel if we don't have one already */ channel = MXC_DMA_AcquireChannel(); MXC_UART_RevB_SetRXDMAChannel(uart, channel); MXC_UART_RevB_DMA_SetupAutoHandlers(channel); @@ -1071,8 +1071,8 @@ int MXC_UART_RevB_WriteTXFIFODMA(mxc_uart_revb_regs_t *uart, const unsigned char return E_NULL_PTR; } - if (states[uart_num].auto_dma_handlers) { - /* Acquire channel */ + if (states[uart_num].auto_dma_handlers && states[uart_num].channelTx < 0) { + /* Acquire channel if we don't have one already */ channel = MXC_DMA_AcquireChannel(); MXC_UART_RevB_SetTXDMAChannel(uart, channel); MXC_UART_RevB_DMA_SetupAutoHandlers(channel); From ad19c87a475219c2cb4bc9276982a6284db44dc5 Mon Sep 17 00:00:00 2001 From: Jake Carter Date: Mon, 13 Nov 2023 18:54:28 -0600 Subject: [PATCH 21/27] Update UART example projects --- Examples/MAX32672/UART/main.c | 41 ++++++++------------ Examples/MAX78000/UART/main.c | 70 ++++++++++++++--------------------- Examples/MAX78002/UART/main.c | 34 ++++++----------- 3 files changed, 54 insertions(+), 91 deletions(-) diff --git a/Examples/MAX32672/UART/main.c b/Examples/MAX32672/UART/main.c index 4a1da080be2..7c07c020551 100644 --- a/Examples/MAX32672/UART/main.c +++ b/Examples/MAX32672/UART/main.c @@ -61,16 +61,9 @@ /***** Globals *****/ volatile int READ_FLAG; -volatile int DMA_FLAG; /***** Functions *****/ -#ifdef DMA -void DMA_Handler(void) -{ - MXC_DMA_Handler(); - DMA_FLAG = 0; -} -#else // DMA +#ifndef DMA void Reading_UART_Handler(void) { MXC_UART_AsyncHandler(READING_UART); @@ -103,11 +96,7 @@ int main(void) } memset(RxData, 0x0, BUFF_SIZE); -#ifdef DMA - MXC_DMA_ReleaseChannel(0); - MXC_NVIC_SetVector(DMA0_IRQn, DMA_Handler); - NVIC_EnableIRQ(DMA0_IRQn); -#else // DMA +#ifndef DMA NVIC_ClearPendingIRQ(MXC_UART_GET_IRQ(READING_UART_IDX)); NVIC_DisableIRQ(MXC_UART_GET_IRQ(READING_UART_IDX)); MXC_NVIC_SetVector(MXC_UART_GET_IRQ(READING_UART_IDX), Reading_UART_Handler); @@ -132,6 +121,12 @@ int main(void) } printf("-->Writing UART Initialized\n\n"); +#ifdef DMA + // Automatically set up DMA handlers/ISRs + MXC_UART_SetAutoDMAHandlers(READING_UART, true); + MXC_UART_SetAutoDMAHandlers(WRITING_UART, true); +#endif + // Set Parameters for UART transaction requests mxc_uart_req_t read_req; read_req.uart = READING_UART; @@ -150,16 +145,16 @@ int main(void) printf("-->Starting transaction\n"); // Initiate Reading UART transaction + READ_FLAG = 1; + MXC_UART_ClearRXFIFO(READING_UART); // Clear any previously pending data #ifdef DMA - DMA_FLAG = 1; error = MXC_UART_TransactionDMA(&read_req); #else // DMA - READ_FLAG = 1; error = MXC_UART_TransactionAsync(&read_req); #endif // DMA if (error != E_NO_ERROR) { - printf("-->Error starting async read: %d\n", error); + printf("-->Error starting read: %d\n", error); printf("-->Example Failed\n"); return error; } @@ -172,21 +167,15 @@ int main(void) return error; } -#ifdef DMA - // Wait for Reading DMA transaction to complete - while (DMA_FLAG) {} -#else // DMA - - // Wait for Async Read transaction to complete + // Wait for read transaction to complete while (READ_FLAG) {} + printf("-->Transaction complete\n\n"); + if (READ_FLAG != E_NO_ERROR) { - printf("-->Error with UART_ReadAsync callback; %d\n", READ_FLAG); + printf("-->Error from UART read callback; %d\n", READ_FLAG); fail++; } -#endif // DMA - - printf("-->Transaction complete\n\n"); // Verify data received matches data transmitted if ((error = memcmp(RxData, TxData, BUFF_SIZE)) != 0) { diff --git a/Examples/MAX78000/UART/main.c b/Examples/MAX78000/UART/main.c index 54c6d5683cc..68617a780c2 100644 --- a/Examples/MAX78000/UART/main.c +++ b/Examples/MAX78000/UART/main.c @@ -57,29 +57,22 @@ /***** Globals *****/ volatile int READ_FLAG; -volatile int DMA_FLAG; #if defined(BOARD_EVKIT_V1) -#define READING_UART 1 -#define WRITING_UART 2 +#define READING_UART MXC_UART1 +#define WRITING_UART MXC_UART2 #elif defined(BOARD_FTHR_REVA) -#define READING_UART 2 -#define WRITING_UART 3 +#define READING_UART MXC_UART2 +#define WRITING_UART MXC_UART3 #else #warning "This example has been written for the MAX78000 Ev Kit or FTHR board." #endif /***** Functions *****/ -#ifdef DMA -void DMA_Handler(void) +#ifndef DMA +void Reading_UART_Handler(void) { - MXC_DMA_Handler(); - DMA_FLAG = 0; -} -#else -void UART_Handler(void) -{ - MXC_UART_AsyncHandler(MXC_UART_GET_UART(READING_UART)); + MXC_UART_AsyncHandler(READING_UART); } #endif @@ -109,27 +102,22 @@ int main(void) memset(RxData, 0x0, BUFF_SIZE); -#ifdef DMA - MXC_DMA_Init(); - MXC_DMA_ReleaseChannel(0); - MXC_NVIC_SetVector(DMA0_IRQn, DMA_Handler); - NVIC_EnableIRQ(DMA0_IRQn); -#else - NVIC_ClearPendingIRQ(MXC_UART_GET_IRQ(READING_UART)); - NVIC_DisableIRQ(MXC_UART_GET_IRQ(READING_UART)); - MXC_NVIC_SetVector(MXC_UART_GET_IRQ(READING_UART), UART_Handler); - NVIC_EnableIRQ(MXC_UART_GET_IRQ(READING_UART)); +#ifndef DMA + NVIC_ClearPendingIRQ(MXC_UART_GET_IRQ(READING_UART_IDX)); + NVIC_DisableIRQ(MXC_UART_GET_IRQ(READING_UART_IDX)); + MXC_NVIC_SetVector(MXC_UART_GET_IRQ(READING_UART_IDX), Reading_UART_Handler); + NVIC_EnableIRQ(MXC_UART_GET_IRQ(READING_UART_IDX)); #endif // Initialize the UART - if ((error = MXC_UART_Init(MXC_UART_GET_UART(READING_UART), UART_BAUD, MXC_UART_APB_CLK)) != + if ((error = MXC_UART_Init(READING_UART, UART_BAUD, MXC_UART_APB_CLK)) != E_NO_ERROR) { printf("-->Error initializing UART: %d\n", error); printf("-->Example Failed\n"); return error; } - if ((error = MXC_UART_Init(MXC_UART_GET_UART(WRITING_UART), UART_BAUD, MXC_UART_APB_CLK)) != + if ((error = MXC_UART_Init(WRITING_UART, UART_BAUD, MXC_UART_APB_CLK)) != E_NO_ERROR) { printf("-->Error initializing UART: %d\n", error); printf("-->Example Failed\n"); @@ -138,25 +126,28 @@ int main(void) printf("-->UART Initialized\n\n"); +#ifdef DMA + // Automatically set up DMA handlers/ISRs + MXC_UART_SetAutoDMAHandlers(READING_UART, true); + MXC_UART_SetAutoDMAHandlers(WRITING_UART, true); +#endif + mxc_uart_req_t read_req; - read_req.uart = MXC_UART_GET_UART(READING_UART); + read_req.uart = READING_UART; read_req.rxData = RxData; read_req.rxLen = BUFF_SIZE; read_req.txLen = 0; read_req.callback = readCallback; mxc_uart_req_t write_req; - write_req.uart = MXC_UART_GET_UART(WRITING_UART); + write_req.uart = WRITING_UART; write_req.txData = TxData; write_req.txLen = BUFF_SIZE; write_req.rxLen = 0; write_req.callback = NULL; READ_FLAG = 1; - DMA_FLAG = 1; - - MXC_UART_ClearRXFIFO(MXC_UART_GET_UART(READING_UART)); - + MXC_UART_ClearRXFIFO(READING_UART); // Clear any previously pending data #ifdef DMA error = MXC_UART_TransactionDMA(&read_req); #else @@ -164,7 +155,7 @@ int main(void) #endif if (error != E_NO_ERROR) { - printf("-->Error starting async read: %d\n", error); + printf("-->Error starting read: %d\n", error); printf("-->Example Failed\n"); return error; } @@ -177,21 +168,16 @@ int main(void) return error; } -#ifdef DMA - - while (DMA_FLAG) {} - -#else - + // Wait for read transaction to complete while (READ_FLAG) {} + printf("-->Transaction complete\n\n"); + if (READ_FLAG != E_NO_ERROR) { - printf("-->Error with UART_ReadAsync callback; %d\n", READ_FLAG); + printf("-->Error from UART read callback; %d\n", READ_FLAG); fail++; } -#endif - if ((error = memcmp(RxData, TxData, BUFF_SIZE)) != 0) { printf("-->Error verifying Data: %d\n", error); fail++; diff --git a/Examples/MAX78002/UART/main.c b/Examples/MAX78002/UART/main.c index 66ac5ccec70..01806349b67 100644 --- a/Examples/MAX78002/UART/main.c +++ b/Examples/MAX78002/UART/main.c @@ -57,16 +57,9 @@ /***** Globals *****/ volatile int READ_FLAG; -volatile int DMA_FLAG; /***** Functions *****/ -#ifdef DMA -void DMA_Handler(void) -{ - MXC_DMA_Handler(); - DMA_FLAG = 0; -} -#else +#ifndef DMA void UART1_Handler(void) { MXC_UART_AsyncHandler(MXC_UART1); @@ -99,11 +92,7 @@ int main(void) memset(RxData, 0x0, BUFF_SIZE); -#ifdef DMA - MXC_DMA_ReleaseChannel(0); - MXC_NVIC_SetVector(DMA0_IRQn, DMA_Handler); - NVIC_EnableIRQ(DMA0_IRQn); -#else +#ifndef DMA NVIC_ClearPendingIRQ(UART1_IRQn); NVIC_DisableIRQ(UART1_IRQn); MXC_NVIC_SetVector(UART1_IRQn, UART1_Handler); @@ -125,6 +114,12 @@ int main(void) printf("-->UART Initialized\n\n"); +#ifdef DMA + // Automatically set up DMA handlers/ISRs + MXC_UART_SetAutoDMAHandlers(READING_UART, true); + MXC_UART_SetAutoDMAHandlers(WRITING_UART, true); +#endif + mxc_uart_req_t read_req; read_req.uart = MXC_UART1; read_req.rxData = RxData; @@ -142,8 +137,7 @@ int main(void) write_req.callback = NULL; READ_FLAG = 1; - DMA_FLAG = 1; - + MXC_UART_ClearRXFIFO(MXC_UART1); // Clear any previously pending data #ifdef DMA error = MXC_UART_TransactionDMA(&read_req); #else @@ -164,20 +158,14 @@ int main(void) return error; } -#ifdef DMA - - while (DMA_FLAG) {} - -#else - while (READ_FLAG) {} if (READ_FLAG != E_NO_ERROR) { - printf("-->Error with UART_ReadAsync callback; %d\n", READ_FLAG); + printf("-->Error from UART read callback; %d\n", READ_FLAG); fail++; } -#endif + printf("-->Transaction complete\n\n"); if ((error = memcmp(RxData, TxData, BUFF_SIZE)) != 0) { printf("-->Error verifying Data: %d\n", error); From 34db845346d0cd3b2dc574ea0b2dffcc4570d175 Mon Sep 17 00:00:00 2001 From: Jake Carter Date: Wed, 29 Nov 2023 17:48:23 -0600 Subject: [PATCH 22/27] Use MXC_ASSERT instead of runtime checks --- .../PeriphDrivers/Source/UART/uart_reva.c | 108 +++++------------- .../PeriphDrivers/Source/UART/uart_revb.c | 104 +++++------------ .../PeriphDrivers/Source/UART/uart_revc.c | 76 +++--------- 3 files changed, 72 insertions(+), 216 deletions(-) diff --git a/Libraries/PeriphDrivers/Source/UART/uart_reva.c b/Libraries/PeriphDrivers/Source/UART/uart_reva.c index 4d91ad4d653..8c9c3f8750f 100644 --- a/Libraries/PeriphDrivers/Source/UART/uart_reva.c +++ b/Libraries/PeriphDrivers/Source/UART/uart_reva.c @@ -116,9 +116,7 @@ int MXC_UART_RevA_Init(mxc_uart_reva_regs_t *uart, unsigned int baud) int MXC_UART_RevA_ReadyForSleep(mxc_uart_reva_regs_t *uart) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) if (TxAsyncRequests[MXC_UART_GET_IDX((mxc_uart_regs_t *)uart)] != NULL) { return E_BUSY; @@ -136,9 +134,7 @@ int MXC_UART_RevA_SetFrequency(mxc_uart_reva_regs_t *uart, unsigned int baud) int prescale; int decimalDiv; - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) if (uart->ctrl & MXC_F_UART_REVA_CTRL_CLKSEL) { #ifdef IBRO_FREQ @@ -251,9 +247,7 @@ int MXC_UART_RevA_GetFrequency(mxc_uart_reva_regs_t *uart) int MXC_UART_RevA_SetDataSize(mxc_uart_reva_regs_t *uart, int dataSize) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) if (dataSize < 5 || dataSize > 8) { return E_BAD_PARAM; @@ -268,9 +262,7 @@ int MXC_UART_RevA_SetDataSize(mxc_uart_reva_regs_t *uart, int dataSize) int MXC_UART_RevA_SetStopBits(mxc_uart_reva_regs_t *uart, mxc_uart_stop_t stopBits) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) switch (stopBits) { case MXC_UART_STOP_1: @@ -293,9 +285,7 @@ int MXC_UART_RevA_SetStopBits(mxc_uart_reva_regs_t *uart, mxc_uart_stop_t stopBi int MXC_UART_RevA_SetParity(mxc_uart_reva_regs_t *uart, mxc_uart_parity_t parity) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) switch (parity) { case MXC_UART_PARITY_DISABLE: @@ -374,9 +364,7 @@ int MXC_UART_RevA_SetParity(mxc_uart_reva_regs_t *uart, mxc_uart_parity_t parity int MXC_UART_RevA_SetFlowCtrl(mxc_uart_reva_regs_t *uart, mxc_uart_flow_t flowCtrl, int rtsThreshold) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) switch (flowCtrl) { case MXC_UART_FLOW_DIS: @@ -417,9 +405,7 @@ int MXC_UART_RevA_SetClockSource(mxc_uart_reva_regs_t *uart, int usePCLK) { int baudRate; - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) baudRate = MXC_UART_GetFrequency((mxc_uart_regs_t *)uart); if (baudRate < 0) { // return error code @@ -437,9 +423,7 @@ int MXC_UART_RevA_SetClockSource(mxc_uart_reva_regs_t *uart, int usePCLK) int MXC_UART_RevA_SetNullModem(mxc_uart_reva_regs_t *uart, int nullModem) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) nullModem = (nullModem > 0) << MXC_F_UART_REVA_CTRL_NULL_MODEM_POS; @@ -450,9 +434,7 @@ int MXC_UART_RevA_SetNullModem(mxc_uart_reva_regs_t *uart, int nullModem) int MXC_UART_RevA_SendBreak(mxc_uart_reva_regs_t *uart) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) MXC_SETFIELD(uart->ctrl, MXC_F_UART_REVA_CTRL_BREAK, 1 << MXC_F_UART_REVA_CTRL_BREAK_POS); @@ -461,9 +443,7 @@ int MXC_UART_RevA_SendBreak(mxc_uart_reva_regs_t *uart) int MXC_UART_RevA_GetActive(mxc_uart_reva_regs_t *uart) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) if (uart->status & (MXC_F_UART_REVA_STATUS_TX_BUSY | MXC_F_UART_REVA_STATUS_RX_BUSY)) { return E_BUSY; @@ -480,9 +460,7 @@ int MXC_UART_RevA_AbortTransmission(mxc_uart_reva_regs_t *uart) int MXC_UART_RevA_ReadCharacterRaw(mxc_uart_reva_regs_t *uart) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) if (uart->status & MXC_F_UART_REVA_STATUS_RX_EMPTY) { return E_UNDERFLOW; @@ -493,9 +471,7 @@ int MXC_UART_RevA_ReadCharacterRaw(mxc_uart_reva_regs_t *uart) int MXC_UART_RevA_WriteCharacterRaw(mxc_uart_reva_regs_t *uart, uint8_t character) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) // Return error if the FIFO is full if (uart->status & MXC_F_UART_REVA_STATUS_TX_FULL) { @@ -803,9 +779,7 @@ unsigned int MXC_UART_RevA_GetTXFIFOAvailable(mxc_uart_reva_regs_t *uart) int MXC_UART_RevA_ClearRXFIFO(mxc_uart_reva_regs_t *uart) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) uart->ctrl |= MXC_F_UART_REVA_CTRL_RX_FLUSH; @@ -816,9 +790,7 @@ int MXC_UART_RevA_ClearRXFIFO(mxc_uart_reva_regs_t *uart) int MXC_UART_RevA_ClearTXFIFO(mxc_uart_reva_regs_t *uart) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) uart->ctrl |= MXC_F_UART_REVA_CTRL_TX_FLUSH; @@ -829,9 +801,7 @@ int MXC_UART_RevA_ClearTXFIFO(mxc_uart_reva_regs_t *uart) int MXC_UART_RevA_SetRXThreshold(mxc_uart_reva_regs_t *uart, unsigned int numBytes) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + if (numBytes < 1 || numBytes > MXC_UART_FIFO_DEPTH) { return E_BAD_PARAM; @@ -851,9 +821,7 @@ unsigned int MXC_UART_RevA_GetRXThreshold(mxc_uart_reva_regs_t *uart) int MXC_UART_RevA_SetTXThreshold(mxc_uart_reva_regs_t *uart, unsigned int numBytes) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + if (numBytes < 1 || numBytes > MXC_UART_FIFO_DEPTH) { return E_BAD_PARAM; @@ -878,9 +846,7 @@ unsigned int MXC_UART_RevA_GetFlags(mxc_uart_reva_regs_t *uart) int MXC_UART_RevA_ClearFlags(mxc_uart_reva_regs_t *uart, unsigned int flags) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + uart->int_fl = flags; @@ -889,9 +855,7 @@ int MXC_UART_RevA_ClearFlags(mxc_uart_reva_regs_t *uart, unsigned int flags) int MXC_UART_RevA_EnableInt(mxc_uart_reva_regs_t *uart, unsigned int intEn) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + uart->int_en |= intEn; @@ -900,9 +864,7 @@ int MXC_UART_RevA_EnableInt(mxc_uart_reva_regs_t *uart, unsigned int intEn) int MXC_UART_RevA_DisableInt(mxc_uart_reva_regs_t *uart, unsigned int intDis) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + uart->int_en &= ~intDis; @@ -1178,9 +1140,7 @@ void MXC_UART_RevA_DMACallback(int ch, int error) int MXC_UART_RevA_RxAsyncCallback(mxc_uart_reva_regs_t *uart, int retVal) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) mxc_uart_reva_req_t *req = (mxc_uart_reva_req_t *)RxAsyncRequests[MXC_UART_GET_IDX((mxc_uart_regs_t *)uart)]; @@ -1194,9 +1154,7 @@ int MXC_UART_RevA_RxAsyncCallback(mxc_uart_reva_regs_t *uart, int retVal) int MXC_UART_RevA_TxAsyncCallback(mxc_uart_reva_regs_t *uart, int retVal) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) mxc_uart_reva_req_t *req = (mxc_uart_reva_req_t *)TxAsyncRequests[MXC_UART_GET_IDX((mxc_uart_regs_t *)uart)]; @@ -1242,9 +1200,7 @@ int MXC_UART_RevA_AsyncCallback(mxc_uart_reva_regs_t *uart, int retVal) int MXC_UART_RevA_TxAsyncStop(mxc_uart_reva_regs_t *uart) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) MXC_UART_DisableInt((mxc_uart_regs_t *)uart, MXC_F_UART_REVA_INT_EN_TX_FIFO_THRESH); TxAsyncRequests[MXC_UART_GET_IDX((mxc_uart_regs_t *)uart)] = NULL; @@ -1254,9 +1210,7 @@ int MXC_UART_RevA_TxAsyncStop(mxc_uart_reva_regs_t *uart) int MXC_UART_RevA_RxAsyncStop(mxc_uart_reva_regs_t *uart) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) MXC_UART_DisableInt((mxc_uart_regs_t *)uart, (MXC_UART_REVA_ERRINT_EN | MXC_F_UART_REVA_INT_EN_RX_FIFO_THRESH)); @@ -1269,9 +1223,7 @@ int MXC_UART_RevA_AsyncStop(mxc_uart_reva_regs_t *uart) { int uartNum; - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) uartNum = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); @@ -1294,9 +1246,7 @@ int MXC_UART_RevA_TxAbortAsync(mxc_uart_reva_regs_t *uart) { int uartNum; - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) uartNum = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); @@ -1313,9 +1263,7 @@ int MXC_UART_RevA_RxAbortAsync(mxc_uart_reva_regs_t *uart) { int uartNum; - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) uartNum = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); @@ -1353,9 +1301,7 @@ int MXC_UART_RevA_AsyncHandler(mxc_uart_reva_regs_t *uart) unsigned int flags, numToWrite, numToRead; mxc_uart_reva_req_t *req; - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) flags = MXC_UART_GetFlags((mxc_uart_regs_t *)uart); diff --git a/Libraries/PeriphDrivers/Source/UART/uart_revb.c b/Libraries/PeriphDrivers/Source/UART/uart_revb.c index 7fdffff5251..3f9eedfec33 100644 --- a/Libraries/PeriphDrivers/Source/UART/uart_revb.c +++ b/Libraries/PeriphDrivers/Source/UART/uart_revb.c @@ -71,9 +71,7 @@ int MXC_UART_RevB_Init(mxc_uart_revb_regs_t *uart, unsigned int baud, mxc_uart_r { int err; - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) // Initialize UART if ((err = MXC_UART_SetRXThreshold((mxc_uart_regs_t *)uart, 1)) != @@ -113,9 +111,7 @@ int MXC_UART_RevB_Init(mxc_uart_revb_regs_t *uart, unsigned int baud, mxc_uart_r int MXC_UART_RevB_ReadyForSleep(mxc_uart_revb_regs_t *uart) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) if (AsyncTxRequests[MXC_UART_GET_IDX((mxc_uart_regs_t *)uart)] != NULL) { return E_BUSY; @@ -132,9 +128,7 @@ int MXC_UART_RevB_SetFrequency(mxc_uart_revb_regs_t *uart, unsigned int baud, mxc_uart_revb_clock_t clock) { unsigned clkDiv = 0, mod = 0; - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) // OSR default value uart->osr = 5; @@ -186,9 +180,7 @@ int MXC_UART_RevB_GetFrequency(mxc_uart_revb_regs_t *uart) { int periphClock = 0; - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) if ((uart->ctrl & MXC_F_UART_REVB_CTRL_BCLKSRC) == MXC_S_UART_REVB_CTRL_BCLKSRC_EXTERNAL_CLOCK) { @@ -213,9 +205,7 @@ int MXC_UART_RevB_GetFrequency(mxc_uart_revb_regs_t *uart) int MXC_UART_RevB_SetDataSize(mxc_uart_revb_regs_t *uart, int dataSize) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) if (dataSize < 5 || dataSize > 8) { return E_BAD_PARAM; @@ -230,9 +220,7 @@ int MXC_UART_RevB_SetDataSize(mxc_uart_revb_regs_t *uart, int dataSize) int MXC_UART_RevB_SetStopBits(mxc_uart_revb_regs_t *uart, mxc_uart_stop_t stopBits) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) switch (stopBits) { case MXC_UART_STOP_1: @@ -255,9 +243,7 @@ int MXC_UART_RevB_SetStopBits(mxc_uart_revb_regs_t *uart, mxc_uart_stop_t stopBi int MXC_UART_RevB_SetParity(mxc_uart_revb_regs_t *uart, mxc_uart_parity_t parity) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) switch (parity) { case MXC_UART_PARITY_DISABLE: @@ -299,9 +285,7 @@ int MXC_UART_RevB_SetParity(mxc_uart_revb_regs_t *uart, mxc_uart_parity_t parity int MXC_UART_RevB_SetFlowCtrl(mxc_uart_revb_regs_t *uart, mxc_uart_flow_t flowCtrl, int rtsThreshold) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) switch (flowCtrl) { case MXC_UART_FLOW_DIS: @@ -324,9 +308,7 @@ int MXC_UART_RevB_SetFlowCtrl(mxc_uart_revb_regs_t *uart, mxc_uart_flow_t flowCt int MXC_UART_RevB_SetClockSource(mxc_uart_revb_regs_t *uart, mxc_uart_revb_clock_t clock) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) switch (clock) { case MXC_UART_REVB_APB_CLK: @@ -353,9 +335,7 @@ int MXC_UART_RevB_SetClockSource(mxc_uart_revb_regs_t *uart, mxc_uart_revb_clock int MXC_UART_RevB_GetActive(mxc_uart_revb_regs_t *uart) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) if (uart->status & (MXC_F_UART_REVB_STATUS_TX_BUSY | MXC_F_UART_REVB_STATUS_RX_BUSY)) { return E_BUSY; @@ -388,9 +368,7 @@ int MXC_UART_RevB_AbortTransmission(mxc_uart_revb_regs_t *uart) int MXC_UART_RevB_ReadCharacterRaw(mxc_uart_revb_regs_t *uart) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) if (uart->status & MXC_F_UART_REVB_STATUS_RX_EM) { return E_UNDERFLOW; @@ -401,9 +379,7 @@ int MXC_UART_RevB_ReadCharacterRaw(mxc_uart_revb_regs_t *uart) int MXC_UART_RevB_WriteCharacterRaw(mxc_uart_revb_regs_t *uart, uint8_t character) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) // Require the TX FIFO to be empty, so that we write out the expected character // Return error if the FIFO is full @@ -418,9 +394,7 @@ int MXC_UART_RevB_WriteCharacterRaw(mxc_uart_revb_regs_t *uart, uint8_t characte int MXC_UART_RevB_ReadCharacter(mxc_uart_revb_regs_t *uart) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) if (uart->status & MXC_F_UART_REVB_STATUS_RX_EM) { return E_UNDERFLOW; @@ -431,9 +405,7 @@ int MXC_UART_RevB_ReadCharacter(mxc_uart_revb_regs_t *uart) int MXC_UART_RevB_WriteCharacter(mxc_uart_revb_regs_t *uart, uint8_t character) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) // Require the TX FIFO to be empty, so that we write out the expected character // Return error if the FIFO is full @@ -451,9 +423,7 @@ int MXC_UART_RevB_Read(mxc_uart_revb_regs_t *uart, uint8_t *buffer, int *len) int read = 0; int retVal; - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) if (buffer == NULL) { return E_NULL_PTR; @@ -483,9 +453,7 @@ int MXC_UART_RevB_Write(mxc_uart_revb_regs_t *uart, const uint8_t *byte, int *le int written = 0; int retVal; - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) if (byte == NULL) { return E_NULL_PTR; @@ -553,9 +521,7 @@ unsigned int MXC_UART_RevB_GetTXFIFOAvailable(mxc_uart_revb_regs_t *uart) int MXC_UART_RevB_ClearRXFIFO(mxc_uart_revb_regs_t *uart) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) uart->ctrl |= MXC_F_UART_REVB_CTRL_RX_FLUSH; while (!(uart->status & MXC_F_UART_REVB_STATUS_RX_EM)) {} @@ -565,9 +531,7 @@ int MXC_UART_RevB_ClearRXFIFO(mxc_uart_revb_regs_t *uart) int MXC_UART_RevB_ClearTXFIFO(mxc_uart_revb_regs_t *uart) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) uart->ctrl |= MXC_F_UART_REVB_CTRL_TX_FLUSH; while (uart->ctrl & MXC_F_UART_REVB_CTRL_TX_FLUSH) {} @@ -577,9 +541,7 @@ int MXC_UART_RevB_ClearTXFIFO(mxc_uart_revb_regs_t *uart) int MXC_UART_RevB_SetRXThreshold(mxc_uart_revb_regs_t *uart, unsigned int numBytes) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) if (numBytes < 1 || numBytes > MXC_UART_FIFO_DEPTH) { return E_BAD_PARAM; @@ -603,9 +565,7 @@ unsigned int MXC_UART_RevB_GetFlags(mxc_uart_revb_regs_t *uart) int MXC_UART_RevB_ClearFlags(mxc_uart_revb_regs_t *uart, unsigned int flags) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) uart->int_fl = flags; @@ -614,9 +574,7 @@ int MXC_UART_RevB_ClearFlags(mxc_uart_revb_regs_t *uart, unsigned int flags) int MXC_UART_RevB_EnableInt(mxc_uart_revb_regs_t *uart, unsigned int intEn) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) uart->int_en |= intEn; @@ -625,9 +583,7 @@ int MXC_UART_RevB_EnableInt(mxc_uart_revb_regs_t *uart, unsigned int intEn) int MXC_UART_RevB_DisableInt(mxc_uart_revb_regs_t *uart, unsigned int intDis) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) uart->int_en &= ~intDis; @@ -826,9 +782,7 @@ int MXC_UART_RevB_AsyncCallback(mxc_uart_revb_regs_t *uart, int retVal) int MXC_UART_RevB_AsyncStopTx(mxc_uart_revb_regs_t *uart) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) MXC_UART_DisableInt((mxc_uart_regs_t *)uart, MXC_F_UART_REVB_INT_EN_TX_HE); @@ -837,9 +791,7 @@ int MXC_UART_RevB_AsyncStopTx(mxc_uart_revb_regs_t *uart) int MXC_UART_RevB_AsyncStopRx(mxc_uart_revb_regs_t *uart) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) MXC_UART_DisableInt((mxc_uart_regs_t *)uart, MXC_UART_REVB_ERRINT_EN); @@ -848,9 +800,7 @@ int MXC_UART_RevB_AsyncStopRx(mxc_uart_revb_regs_t *uart) int MXC_UART_RevB_AsyncStop(mxc_uart_revb_regs_t *uart) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) MXC_UART_DisableInt((mxc_uart_regs_t *)uart, 0xFFFFFFFF); @@ -859,9 +809,7 @@ int MXC_UART_RevB_AsyncStop(mxc_uart_revb_regs_t *uart) int MXC_UART_RevB_AbortAsync(mxc_uart_revb_regs_t *uart) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) MXC_UART_AsyncStop((mxc_uart_regs_t *)uart); MXC_UART_AsyncCallback((mxc_uart_regs_t *)uart, E_ABORT); diff --git a/Libraries/PeriphDrivers/Source/UART/uart_revc.c b/Libraries/PeriphDrivers/Source/UART/uart_revc.c index ff41c9ae314..e9ce933e435 100644 --- a/Libraries/PeriphDrivers/Source/UART/uart_revc.c +++ b/Libraries/PeriphDrivers/Source/UART/uart_revc.c @@ -69,9 +69,7 @@ int MXC_UART_RevC_Init(mxc_uart_revc_regs_t *uart, unsigned int baud) { int err; - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) // Initialize UART // Set RX threshold to 1 byte @@ -101,9 +99,7 @@ int MXC_UART_RevC_Init(mxc_uart_revc_regs_t *uart, unsigned int baud) int MXC_UART_RevC_ReadyForSleep(mxc_uart_revc_regs_t *uart) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) if (AsyncRequests[MXC_UART_GET_IDX((mxc_uart_regs_t *)uart)] != NULL) { return E_BUSY; @@ -116,9 +112,7 @@ int MXC_UART_RevC_SetFrequency(mxc_uart_revc_regs_t *uart, unsigned int baud) { int div = 0, baud0 = 0, baud1 = 0; - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) // Set the baud rate // Calculate divisor @@ -145,9 +139,7 @@ int MXC_UART_RevC_GetFrequency(mxc_uart_revc_regs_t *uart) int MXC_UART_RevC_SetDataSize(mxc_uart_revc_regs_t *uart, int dataSize) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) if (dataSize < 5 || dataSize > 8) { return E_BAD_PARAM; @@ -162,9 +154,7 @@ int MXC_UART_RevC_SetDataSize(mxc_uart_revc_regs_t *uart, int dataSize) int MXC_UART_RevC_SetStopBits(mxc_uart_revc_regs_t *uart, mxc_uart_stop_t stopBits) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) switch (stopBits) { case MXC_UART_STOP_1: @@ -187,9 +177,7 @@ int MXC_UART_RevC_SetStopBits(mxc_uart_revc_regs_t *uart, mxc_uart_stop_t stopBi int MXC_UART_RevC_SetParity(mxc_uart_revc_regs_t *uart, mxc_uart_parity_t parity) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) switch (parity) { case MXC_UART_PARITY_DISABLE: @@ -237,9 +225,7 @@ int MXC_UART_RevC_SetParity(mxc_uart_revc_regs_t *uart, mxc_uart_parity_t parity int MXC_UART_RevC_GetActive(mxc_uart_revc_regs_t *uart) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) if (uart->status & (MXC_F_UART_REVC_STATUS_TX_BUSY | MXC_F_UART_REVC_STATUS_RX_BUSY)) { return E_BUSY; @@ -250,18 +236,14 @@ int MXC_UART_RevC_GetActive(mxc_uart_revc_regs_t *uart) int MXC_UART_RevC_AbortTransmission(mxc_uart_revc_regs_t *uart) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) return MXC_UART_ClearTXFIFO((mxc_uart_regs_t *)uart); } int MXC_UART_RevC_ReadCharacterRaw(mxc_uart_revc_regs_t *uart) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) if (uart->status & MXC_F_UART_REVC_STATUS_RX_EMPTY) { return E_UNDERFLOW; @@ -272,9 +254,7 @@ int MXC_UART_RevC_ReadCharacterRaw(mxc_uart_revc_regs_t *uart) int MXC_UART_RevC_WriteCharacterRaw(mxc_uart_revc_regs_t *uart, uint8_t character) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) // Return error if the FIFO is full if (uart->status & MXC_F_UART_REVC_STATUS_TX_FULL) { @@ -437,9 +417,7 @@ unsigned int MXC_UART_RevC_GetTXFIFOAvailable(mxc_uart_revc_regs_t *uart) int MXC_UART_RevC_ClearRXFIFO(mxc_uart_revc_regs_t *uart) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) uart->ctrl |= MXC_F_UART_REVC_CTRL_RX_FLUSH; @@ -450,9 +428,7 @@ int MXC_UART_RevC_ClearRXFIFO(mxc_uart_revc_regs_t *uart) int MXC_UART_RevC_ClearTXFIFO(mxc_uart_revc_regs_t *uart) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) uart->ctrl |= MXC_F_UART_REVC_CTRL_TX_FLUSH; @@ -463,9 +439,7 @@ int MXC_UART_RevC_ClearTXFIFO(mxc_uart_revc_regs_t *uart) int MXC_UART_RevC_SetRXThreshold(mxc_uart_revc_regs_t *uart, unsigned int numBytes) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) if (numBytes < 1 || numBytes > MXC_UART_FIFO_DEPTH) { return E_BAD_PARAM; @@ -489,9 +463,7 @@ unsigned int MXC_UART_RevC_GetFlags(mxc_uart_revc_regs_t *uart) int MXC_UART_RevC_ClearFlags(mxc_uart_revc_regs_t *uart, unsigned int flags) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) uart->int_fl &= ~flags; @@ -500,9 +472,7 @@ int MXC_UART_RevC_ClearFlags(mxc_uart_revc_regs_t *uart, unsigned int flags) int MXC_UART_RevC_EnableInt(mxc_uart_revc_regs_t *uart, unsigned int intEn) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) uart->int_en |= intEn; @@ -511,9 +481,7 @@ int MXC_UART_RevC_EnableInt(mxc_uart_revc_regs_t *uart, unsigned int intEn) int MXC_UART_RevC_DisableInt(mxc_uart_revc_regs_t *uart, unsigned int intDis) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) uart->int_en &= ~intDis; @@ -740,9 +708,7 @@ void MXC_UART_RevC_DMACallback(int ch, int error) int MXC_UART_RevC_AsyncCallback(mxc_uart_revc_regs_t *uart, int retVal) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) mxc_uart_revc_req_t *req = (mxc_uart_revc_req_t *)AsyncRequests[MXC_UART_GET_IDX((mxc_uart_regs_t *)uart)]; @@ -756,9 +722,7 @@ int MXC_UART_RevC_AsyncCallback(mxc_uart_revc_regs_t *uart, int retVal) int MXC_UART_RevC_AsyncStop(mxc_uart_revc_regs_t *uart) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) MXC_UART_DisableInt((mxc_uart_regs_t *)uart, 0xFFFFFFFF); AsyncRequests[MXC_UART_GET_IDX((mxc_uart_regs_t *)uart)] = NULL; @@ -768,9 +732,7 @@ int MXC_UART_RevC_AsyncStop(mxc_uart_revc_regs_t *uart) int MXC_UART_RevC_AbortAsync(mxc_uart_revc_regs_t *uart) { - if (MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) MXC_UART_AsyncCallback((mxc_uart_regs_t *)uart, E_ABORT); MXC_UART_AsyncStop((mxc_uart_regs_t *)uart); From 81837cc5e93092c6ea106dc848ded8b08de27271 Mon Sep 17 00:00:00 2001 From: Jake Carter Date: Wed, 29 Nov 2023 17:48:54 -0600 Subject: [PATCH 23/27] Disable MXC_ASSERT for bootloader examples --- Examples/MAX32655/Bootloader/Makefile | 2 +- Examples/MAX32665/Bootloader/Makefile | 2 +- Examples/MAX32690/Bootloader/Makefile | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Examples/MAX32655/Bootloader/Makefile b/Examples/MAX32655/Bootloader/Makefile index a780185d5f8..1ec6f28fec0 100644 --- a/Examples/MAX32655/Bootloader/Makefile +++ b/Examples/MAX32655/Bootloader/Makefile @@ -242,7 +242,7 @@ MXC_OPTIMIZE_CFLAGS ?= -Og # Set compiler flags PROJ_CFLAGS += -Wall # Enable warnings -PROJ_CFLAGS += -DMXC_ASSERT_ENABLE +# PROJ_CFLAGS += -DMXC_ASSERT_ENABLE # Set hardware floating point acceleration. # Options are: diff --git a/Examples/MAX32665/Bootloader/Makefile b/Examples/MAX32665/Bootloader/Makefile index ba87cf69828..9c7f460828b 100644 --- a/Examples/MAX32665/Bootloader/Makefile +++ b/Examples/MAX32665/Bootloader/Makefile @@ -242,7 +242,7 @@ MXC_OPTIMIZE_CFLAGS ?= -Og # Set compiler flags PROJ_CFLAGS += -Wall # Enable warnings -PROJ_CFLAGS += -DMXC_ASSERT_ENABLE +# PROJ_CFLAGS += -DMXC_ASSERT_ENABLE # Set hardware floating point acceleration. # Options are: diff --git a/Examples/MAX32690/Bootloader/Makefile b/Examples/MAX32690/Bootloader/Makefile index 6a02bf53c6c..59c189b2d9a 100644 --- a/Examples/MAX32690/Bootloader/Makefile +++ b/Examples/MAX32690/Bootloader/Makefile @@ -242,7 +242,7 @@ MXC_OPTIMIZE_CFLAGS ?= -Og # Set compiler flags PROJ_CFLAGS += -Wall # Enable warnings -PROJ_CFLAGS += -DMXC_ASSERT_ENABLE +# # PROJ_CFLAGS += -DMXC_ASSERT_ENABLE # Set hardware floating point acceleration. # Options are: From 566f0573f6c6cef6de16e5c4afcaf4e3bc971ed8 Mon Sep 17 00:00:00 2001 From: Jake Carter Date: Wed, 29 Nov 2023 19:32:06 -0600 Subject: [PATCH 24/27] Fix variable mismatch, swap for more asserts --- .../PeriphDrivers/Source/UART/uart_reva.c | 74 ++++++++----------- .../PeriphDrivers/Source/UART/uart_revb.c | 72 +++++++----------- .../PeriphDrivers/Source/UART/uart_revc.c | 12 +-- 3 files changed, 64 insertions(+), 94 deletions(-) diff --git a/Libraries/PeriphDrivers/Source/UART/uart_reva.c b/Libraries/PeriphDrivers/Source/UART/uart_reva.c index ad4921d6a95..84fac966d73 100644 --- a/Libraries/PeriphDrivers/Source/UART/uart_reva.c +++ b/Libraries/PeriphDrivers/Source/UART/uart_reva.c @@ -607,9 +607,7 @@ int MXC_UART_RevA_ReadRXFIFODMA(mxc_uart_reva_regs_t *uart, mxc_dma_regs_t *dma, int uart_num = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); - if (uart_num < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(uart_num >= 0) if (bytes == NULL) { return E_NULL_PTR; @@ -739,9 +737,7 @@ unsigned int MXC_UART_RevA_WriteTXFIFODMA(mxc_uart_reva_regs_t *uart, mxc_dma_re int uart_num = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); - if (uart_num < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(uart_num >= 0) if (bytes == NULL) { return E_NULL_PTR; @@ -986,9 +982,7 @@ int MXC_UART_RevA_TransactionAsync(mxc_uart_reva_req_t *req) unsigned int numToWrite, numToRead; int uart_num = MXC_UART_GET_IDX((mxc_uart_regs_t *)(req->uart)); - if (uart_num < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(uart_num >= 0) if (req->txLen) { if (TxAsyncRequests[uart_num] != NULL) { @@ -1040,9 +1034,7 @@ int MXC_UART_RevA_TransactionDMA(mxc_uart_reva_req_t *req, mxc_dma_regs_t *dma) { int uart_num = MXC_UART_GET_IDX((mxc_uart_regs_t *)(req->uart)); - if (uart_num < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(uart_num >= 0) if (req->txLen) { if (req->txData == NULL) { @@ -1164,15 +1156,15 @@ void MXC_UART_RevA_DMACallback(int ch, int error) int MXC_UART_RevA_RxAsyncCallback(mxc_uart_reva_regs_t *uart, int retVal) { mxc_uart_reva_req_t *req; - int uartNum = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); + int uart_num = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); MXC_ASSERT(uart_num >= 0) - if (RxAsyncRequests[uartNum] == NULL) { + if (RxAsyncRequests[uart_num] == NULL) { return E_BAD_STATE; } - req = (mxc_uart_reva_req_t *)RxAsyncRequests[uartNum]; + req = (mxc_uart_reva_req_t *)RxAsyncRequests[uart_num]; if (req->callback != NULL) { req->callback((mxc_uart_req_t *)req, retVal); @@ -1184,15 +1176,15 @@ int MXC_UART_RevA_RxAsyncCallback(mxc_uart_reva_regs_t *uart, int retVal) int MXC_UART_RevA_TxAsyncCallback(mxc_uart_reva_regs_t *uart, int retVal) { mxc_uart_reva_req_t *req; - int uartNum = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); + int uart_num = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); MXC_ASSERT(uart_num >= 0) - if (TxAsyncRequests[uartNum] == NULL) { + if (TxAsyncRequests[uart_num] == NULL) { return E_BAD_STATE; } - req = (mxc_uart_reva_req_t *)TxAsyncRequests[uartNum]; + req = (mxc_uart_reva_req_t *)TxAsyncRequests[uart_num]; if (req->callback != NULL) { req->callback((mxc_uart_req_t *)req, retVal); @@ -1205,10 +1197,8 @@ int MXC_UART_RevA_AsyncCallback(mxc_uart_reva_regs_t *uart, int retVal) { int err; - int uartNum = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); - if (uartNum < 0) { - return E_BAD_PARAM; - } + int uart_num = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); + MXC_ASSERT(uart_num >= 0) // Call TX callback err = MXC_UART_TxAsyncCallback((mxc_uart_regs_t *)uart, retVal); @@ -1217,7 +1207,7 @@ int MXC_UART_RevA_AsyncCallback(mxc_uart_reva_regs_t *uart, int retVal) } // Call RX callback if the TX and RX requests are not the same request - if (TxAsyncRequests[uartNum] != RxAsyncRequests[uartNum]) { + if (TxAsyncRequests[uart_num] != RxAsyncRequests[uart_num]) { err = MXC_UART_RxAsyncCallback((mxc_uart_regs_t *)uart, retVal); } @@ -1247,17 +1237,17 @@ int MXC_UART_RevA_RxAsyncStop(mxc_uart_reva_regs_t *uart) int MXC_UART_RevA_AsyncStop(mxc_uart_reva_regs_t *uart) { - int uartNum = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); + int uart_num = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); mxc_uart_reva_req_t *req; MXC_ASSERT(uart_num >= 0) - req = (mxc_uart_reva_req_t *)TxAsyncRequests[uartNum]; + req = (mxc_uart_reva_req_t *)TxAsyncRequests[uart_num]; if (req != NULL) { MXC_UART_TxAsyncStop((mxc_uart_regs_t *)uart); } - req = (mxc_uart_reva_req_t *)RxAsyncRequests[uartNum]; + req = (mxc_uart_reva_req_t *)RxAsyncRequests[uart_num]; if (req != NULL) { MXC_UART_RxAsyncStop((mxc_uart_regs_t *)uart); } @@ -1267,11 +1257,11 @@ int MXC_UART_RevA_AsyncStop(mxc_uart_reva_regs_t *uart) int MXC_UART_RevA_TxAbortAsync(mxc_uart_reva_regs_t *uart) { - int uartNum = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); + int uart_num = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); MXC_ASSERT(uart_num >= 0) - mxc_uart_reva_req_t *req = (mxc_uart_reva_req_t *)TxAsyncRequests[uartNum]; + mxc_uart_reva_req_t *req = (mxc_uart_reva_req_t *)TxAsyncRequests[uart_num]; if (req != NULL) { MXC_UART_TxAsyncCallback((mxc_uart_regs_t *)uart, E_ABORT); @@ -1283,11 +1273,11 @@ int MXC_UART_RevA_TxAbortAsync(mxc_uart_reva_regs_t *uart) int MXC_UART_RevA_RxAbortAsync(mxc_uart_reva_regs_t *uart) { - int uartNum = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); + int uart_num = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); MXC_ASSERT(uart_num >= 0) - mxc_uart_reva_req_t *req = (mxc_uart_reva_req_t *)RxAsyncRequests[uartNum]; + mxc_uart_reva_req_t *req = (mxc_uart_reva_req_t *)RxAsyncRequests[uart_num]; if (req != NULL) { MXC_UART_RxAsyncCallback((mxc_uart_regs_t *)uart, E_ABORT); @@ -1317,7 +1307,7 @@ int MXC_UART_RevA_AbortAsync(mxc_uart_reva_regs_t *uart) int MXC_UART_RevA_AsyncHandler(mxc_uart_reva_regs_t *uart) { - int uartNum = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); + int uart_num = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); unsigned int flags, numToWrite, numToRead; mxc_uart_reva_req_t *req; @@ -1332,13 +1322,13 @@ int MXC_UART_RevA_AsyncHandler(mxc_uart_reva_regs_t *uart) MXC_UART_AsyncCallback((mxc_uart_regs_t *)uart, E_COMM_ERR); - RxAsyncRequests[uartNum] = NULL; - TxAsyncRequests[uartNum] = NULL; + RxAsyncRequests[uart_num] = NULL; + TxAsyncRequests[uart_num] = NULL; return E_INVALID; } - req = (mxc_uart_reva_req_t *)TxAsyncRequests[uartNum]; + req = (mxc_uart_reva_req_t *)TxAsyncRequests[uart_num]; if ((flags & MXC_F_UART_REVA_INT_FL_TX_FIFO_THRESH) && (req != NULL) && (req->txLen)) { numToWrite = MXC_UART_GetTXFIFOAvailable((mxc_uart_regs_t *)(req->uart)); @@ -1348,7 +1338,7 @@ int MXC_UART_RevA_AsyncHandler(mxc_uart_reva_regs_t *uart) MXC_UART_ClearFlags((mxc_uart_regs_t *)(req->uart), MXC_F_UART_REVA_INT_FL_TX_FIFO_THRESH); } - req = (mxc_uart_reva_req_t *)RxAsyncRequests[uartNum]; + req = (mxc_uart_reva_req_t *)RxAsyncRequests[uart_num]; if ((flags & MXC_F_UART_REVA_INT_FL_RX_FIFO_THRESH) && (req != NULL) && (req->rxLen)) { numToRead = MXC_UART_GetRXFIFOAvailable((mxc_uart_regs_t *)(req->uart)); @@ -1358,14 +1348,14 @@ int MXC_UART_RevA_AsyncHandler(mxc_uart_reva_regs_t *uart) MXC_UART_ClearFlags((mxc_uart_regs_t *)(req->uart), MXC_F_UART_REVA_INT_FL_RX_FIFO_THRESH); } - if (RxAsyncRequests[uartNum] == TxAsyncRequests[uartNum]) { + if (RxAsyncRequests[uart_num] == TxAsyncRequests[uart_num]) { if ((req != NULL) && (req->rxCnt == req->rxLen) && (req->txCnt == req->txLen)) { MXC_UART_DisableInt((mxc_uart_regs_t *)uart, (MXC_F_UART_REVA_INT_EN_TX_FIFO_THRESH | MXC_UART_REVA_ERRINT_EN | MXC_F_UART_REVA_INT_EN_RX_FIFO_THRESH)); - RxAsyncRequests[uartNum] = NULL; - TxAsyncRequests[uartNum] = NULL; + RxAsyncRequests[uart_num] = NULL; + TxAsyncRequests[uart_num] = NULL; if (req->callback != NULL) { req->callback((mxc_uart_req_t *)req, E_NO_ERROR); @@ -1375,10 +1365,10 @@ int MXC_UART_RevA_AsyncHandler(mxc_uart_reva_regs_t *uart) return E_NO_ERROR; } - req = TxAsyncRequests[uartNum]; + req = TxAsyncRequests[uart_num]; if (req != NULL && req->txCnt == req->txLen) { MXC_UART_DisableInt((mxc_uart_regs_t *)uart, MXC_F_UART_REVA_INT_EN_TX_FIFO_THRESH); - TxAsyncRequests[uartNum] = NULL; + TxAsyncRequests[uart_num] = NULL; if (req->callback != NULL) { req->callback((mxc_uart_req_t *)req, E_NO_ERROR); @@ -1387,11 +1377,11 @@ int MXC_UART_RevA_AsyncHandler(mxc_uart_reva_regs_t *uart) return E_NO_ERROR; } - req = RxAsyncRequests[uartNum]; + req = RxAsyncRequests[uart_num]; if (req != NULL && req->rxCnt == req->rxLen) { MXC_UART_DisableInt((mxc_uart_regs_t *)uart, (MXC_UART_REVA_ERRINT_EN | MXC_F_UART_REVA_INT_EN_RX_FIFO_THRESH)); - RxAsyncRequests[uartNum] = NULL; + RxAsyncRequests[uart_num] = NULL; if (req->callback != NULL) { req->callback((mxc_uart_req_t *)req, E_NO_ERROR); diff --git a/Libraries/PeriphDrivers/Source/UART/uart_revb.c b/Libraries/PeriphDrivers/Source/UART/uart_revb.c index dfea740e7a5..face251ddcb 100644 --- a/Libraries/PeriphDrivers/Source/UART/uart_revb.c +++ b/Libraries/PeriphDrivers/Source/UART/uart_revb.c @@ -681,21 +681,19 @@ int MXC_UART_RevB_Transaction(mxc_uart_revb_req_t *req) int MXC_UART_RevB_TransactionAsync(mxc_uart_revb_req_t *req) { uint32_t numToWrite, numToRead; - int uartNum = MXC_UART_GET_IDX((mxc_uart_regs_t *)(req->uart)); + int uart_num = MXC_UART_GET_IDX((mxc_uart_regs_t *)(req->uart)); - if (uartNum < 0) { - return E_INVALID; - } + MXC_ASSERT(uart_num >= 0) - if (!AsyncTxRequests[uartNum] && !AsyncRxRequests[uartNum]) { + if (!AsyncTxRequests[uart_num] && !AsyncRxRequests[uart_num]) { /* No requests pending, clear the interrupt state */ MXC_UART_DisableInt((mxc_uart_regs_t *)(req->uart), 0xFFFFFFFF); MXC_UART_ClearFlags((mxc_uart_regs_t *)(req->uart), 0xFFFFFFFF); - } else if (AsyncRxRequests[uartNum] && req->rxLen) { + } else if (AsyncRxRequests[uart_num] && req->rxLen) { /* RX request pending */ return E_BUSY; - } else if (AsyncTxRequests[uartNum] && req->txLen) { + } else if (AsyncTxRequests[uart_num] && req->txLen) { /* TX request pending */ return E_BUSY; } @@ -721,7 +719,7 @@ int MXC_UART_RevB_TransactionAsync(mxc_uart_revb_req_t *req) if ((MXC_UART_GetTXFIFOAvailable((mxc_uart_regs_t *)(req->uart)) >= (MXC_UART_FIFO_DEPTH / 2)) && (req->txCnt == req->txLen)) { - NVIC_SetPendingIRQ(MXC_UART_GET_IRQ(uartNum)); + NVIC_SetPendingIRQ(MXC_UART_GET_IRQ(uart_num)); } } @@ -751,14 +749,12 @@ int MXC_UART_RevB_TransactionAsync(mxc_uart_revb_req_t *req) int MXC_UART_RevB_AsyncTxCallback(mxc_uart_revb_regs_t *uart, int retVal) { - int uartNum = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); - if (uartNum < 0) { - return E_BAD_PARAM; - } + int uart_num = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); + MXC_ASSERT(uart_num >= 0) - mxc_uart_req_t *req = (mxc_uart_req_t *)AsyncTxRequests[uartNum]; + mxc_uart_req_t *req = (mxc_uart_req_t *)AsyncTxRequests[uart_num]; if ((req != NULL) && (req->callback != NULL)) { - AsyncTxRequests[uartNum] = NULL; + AsyncTxRequests[uart_num] = NULL; req->callback(req, retVal); } @@ -767,14 +763,12 @@ int MXC_UART_RevB_AsyncTxCallback(mxc_uart_revb_regs_t *uart, int retVal) int MXC_UART_RevB_AsyncRxCallback(mxc_uart_revb_regs_t *uart, int retVal) { - int uartNum = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); - if (uartNum < 0) { - return E_BAD_PARAM; - } + int uart_num = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); + MXC_ASSERT(uart_num >= 0) - mxc_uart_req_t *req = (mxc_uart_req_t *)AsyncRxRequests[uartNum]; + mxc_uart_req_t *req = (mxc_uart_req_t *)AsyncRxRequests[uart_num]; if ((req != NULL) && (req->callback != NULL)) { - AsyncRxRequests[uartNum] = NULL; + AsyncRxRequests[uart_num] = NULL; req->callback(req, retVal); } @@ -783,15 +777,13 @@ int MXC_UART_RevB_AsyncRxCallback(mxc_uart_revb_regs_t *uart, int retVal) int MXC_UART_RevB_AsyncCallback(mxc_uart_revb_regs_t *uart, int retVal) { - int uartNum = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); - if (uartNum < 0) { - return E_BAD_PARAM; - } + int uart_num = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); + MXC_ASSERT(uart_num >= 0) MXC_UART_RevB_AsyncTxCallback(uart, retVal); /* Only call the callback once if it's for the same request */ - if (AsyncRxRequests[uartNum] != AsyncTxRequests[uartNum]) { + if (AsyncRxRequests[uart_num] != AsyncTxRequests[uart_num]) { MXC_UART_RevB_AsyncRxCallback(uart, retVal); } @@ -840,16 +832,14 @@ int MXC_UART_RevB_AsyncHandler(mxc_uart_revb_regs_t *uart) uint32_t numToWrite, numToRead, flags; mxc_uart_req_t *req; - int uartNum = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); + int uart_num = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); - if (uartNum < 0) { - return E_INVALID; - } + MXC_ASSERT(uart_num >= 0) flags = MXC_UART_GetFlags((mxc_uart_regs_t *)uart); /* Unexpected interrupt */ - if (!AsyncTxRequests[uartNum] && !AsyncRxRequests[uartNum]) { + if (!AsyncTxRequests[uart_num] && !AsyncRxRequests[uart_num]) { MXC_UART_ClearFlags((mxc_uart_regs_t *)uart, uart->int_fl); return E_INVALID; } @@ -860,7 +850,7 @@ int MXC_UART_RevB_AsyncHandler(mxc_uart_revb_regs_t *uart) return E_INVALID; } - req = (mxc_uart_req_t *)AsyncTxRequests[uartNum]; + req = (mxc_uart_req_t *)AsyncTxRequests[uart_num]; if ((req != NULL) && (req->txLen)) { numToWrite = MXC_UART_GetTXFIFOAvailable((mxc_uart_regs_t *)(req->uart)); numToWrite = numToWrite > (req->txLen - req->txCnt) ? req->txLen - req->txCnt : numToWrite; @@ -869,7 +859,7 @@ int MXC_UART_RevB_AsyncHandler(mxc_uart_revb_regs_t *uart) MXC_UART_ClearFlags(req->uart, MXC_F_UART_REVB_INT_FL_TX_HE); } - req = (mxc_uart_req_t *)AsyncRxRequests[uartNum]; + req = (mxc_uart_req_t *)AsyncRxRequests[uart_num]; if ((req != NULL) && (flags & MXC_F_UART_REVB_INT_FL_RX_THD) && (req->rxLen)) { numToRead = MXC_UART_GetRXFIFOAvailable((mxc_uart_regs_t *)(req->uart)); numToRead = numToRead > (req->rxLen - req->rxCnt) ? req->rxLen - req->rxCnt : numToRead; @@ -883,7 +873,7 @@ int MXC_UART_RevB_AsyncHandler(mxc_uart_revb_regs_t *uart) MXC_UART_ClearFlags((mxc_uart_regs_t *)(req->uart), MXC_F_UART_REVB_INT_FL_RX_THD); } - if (AsyncRxRequests[uartNum] == AsyncTxRequests[uartNum]) { + if (AsyncRxRequests[uart_num] == AsyncTxRequests[uart_num]) { if ((req != NULL) && (req->rxCnt == req->rxLen) && (req->txCnt == req->txLen)) { MXC_UART_AsyncStop((mxc_uart_regs_t *)uart); MXC_UART_AsyncCallback((mxc_uart_regs_t *)uart, E_NO_ERROR); @@ -891,14 +881,14 @@ int MXC_UART_RevB_AsyncHandler(mxc_uart_revb_regs_t *uart) return E_NO_ERROR; } - req = (mxc_uart_req_t *)AsyncRxRequests[uartNum]; + req = (mxc_uart_req_t *)AsyncRxRequests[uart_num]; if ((req != NULL) && (req->rxCnt == req->rxLen)) { MXC_UART_RevB_AsyncStopRx(uart); MXC_UART_RevB_AsyncRxCallback(uart, E_NO_ERROR); return E_NO_ERROR; } - req = (mxc_uart_req_t *)AsyncTxRequests[uartNum]; + req = (mxc_uart_req_t *)AsyncTxRequests[uart_num]; if ((req != NULL) && (req->txCnt == req->txLen)) { MXC_UART_RevB_AsyncStopTx(uart); MXC_UART_RevB_AsyncTxCallback(uart, E_NO_ERROR); @@ -977,9 +967,7 @@ int MXC_UART_RevB_ReadRXFIFODMA(mxc_uart_revb_regs_t *uart, unsigned char *bytes int uart_num = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); - if (uart_num < 0) { - return E_INVALID; - } + MXC_ASSERT(uart_num >= 0) if (bytes == NULL) { return E_NULL_PTR; @@ -1029,9 +1017,7 @@ int MXC_UART_RevB_WriteTXFIFODMA(mxc_uart_revb_regs_t *uart, const unsigned char int uart_num = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); - if (uart_num < 0) { - return E_INVALID; - } + MXC_ASSERT(uart_num >= 0) if (bytes == NULL) { return E_NULL_PTR; @@ -1076,9 +1062,7 @@ int MXC_UART_RevB_TransactionDMA(mxc_uart_revb_req_t *req) { int uart_num = MXC_UART_GET_IDX((mxc_uart_regs_t *)(req->uart)); - if (uart_num < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(uart_num >= 0) if (req->txLen) { if (req->txData == NULL) { diff --git a/Libraries/PeriphDrivers/Source/UART/uart_revc.c b/Libraries/PeriphDrivers/Source/UART/uart_revc.c index 435339be357..02b4c0dc1c0 100644 --- a/Libraries/PeriphDrivers/Source/UART/uart_revc.c +++ b/Libraries/PeriphDrivers/Source/UART/uart_revc.c @@ -652,9 +652,7 @@ int MXC_UART_RevC_TransactionDMA(mxc_uart_revc_req_t *req) { int uart_num = MXC_UART_GET_IDX((mxc_uart_regs_t *)(req->uart)); - if (uart_num < 0) { - return E_BAD_PARAM; - } + MXC_ASSERT(uart_num >= 0) if (req->txLen) { if (req->txData == NULL) { @@ -760,15 +758,13 @@ int MXC_UART_RevC_AbortAsync(mxc_uart_revc_regs_t *uart) int MXC_UART_RevC_AsyncHandler(mxc_uart_revc_regs_t *uart) { - int uartNum = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); + int uart_num = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); int flags, numToWrite, numToRead; mxc_uart_revc_req_t *req; - if (uartNum < 0) { - return E_INVALID; - } + MXC_ASSERT(uart_num >= 0) - req = (mxc_uart_revc_req_t *)AsyncRequests[uartNum]; + req = (mxc_uart_revc_req_t *)AsyncRequests[uart_num]; flags = MXC_UART_GetFlags((mxc_uart_regs_t *)uart); From b332e72c8326bb05c378719c0b7c9692207f3fde Mon Sep 17 00:00:00 2001 From: Jake Carter Date: Wed, 29 Nov 2023 19:40:53 -0600 Subject: [PATCH 25/27] Disable MXC_ASSERT for SCPA_OTP_Dump --- Examples/MAX32662/SCPA_OTP_Dump/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/MAX32662/SCPA_OTP_Dump/Makefile b/Examples/MAX32662/SCPA_OTP_Dump/Makefile index 0dd49ceb749..bf69351f598 100644 --- a/Examples/MAX32662/SCPA_OTP_Dump/Makefile +++ b/Examples/MAX32662/SCPA_OTP_Dump/Makefile @@ -260,7 +260,7 @@ MXC_OPTIMIZE_CFLAGS ?= -Og # Set compiler flags PROJ_CFLAGS += -Wall # Enable warnings -PROJ_CFLAGS += -DMXC_ASSERT_ENABLE +# PROJ_CFLAGS += -DMXC_ASSERT_ENABLE # Set hardware floating point acceleration. # Options are: From 63fca53f84161e904d0881e4a221edfa524216cd Mon Sep 17 00:00:00 2001 From: Jake Carter Date: Wed, 29 Nov 2023 19:43:18 -0600 Subject: [PATCH 26/27] clang-format --- Examples/MAX78000/UART/main.c | 6 ++---- Libraries/PeriphDrivers/Source/UART/uart_reva.c | 12 +----------- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/Examples/MAX78000/UART/main.c b/Examples/MAX78000/UART/main.c index a307782af1c..b9401e8cc9b 100644 --- a/Examples/MAX78000/UART/main.c +++ b/Examples/MAX78000/UART/main.c @@ -128,15 +128,13 @@ int main(void) #endif // Initialize the UART - if ((error = MXC_UART_Init(READING_UART, UART_BAUD, MXC_UART_APB_CLK)) != - E_NO_ERROR) { + if ((error = MXC_UART_Init(READING_UART, UART_BAUD, MXC_UART_APB_CLK)) != E_NO_ERROR) { printf("-->Error initializing UART: %d\n", error); printf("-->Example Failed\n"); return error; } - if ((error = MXC_UART_Init(WRITING_UART, UART_BAUD, MXC_UART_APB_CLK)) != - E_NO_ERROR) { + if ((error = MXC_UART_Init(WRITING_UART, UART_BAUD, MXC_UART_APB_CLK)) != E_NO_ERROR) { printf("-->Error initializing UART: %d\n", error); printf("-->Example Failed\n"); return error; diff --git a/Libraries/PeriphDrivers/Source/UART/uart_reva.c b/Libraries/PeriphDrivers/Source/UART/uart_reva.c index 84fac966d73..f12ae17ee8e 100644 --- a/Libraries/PeriphDrivers/Source/UART/uart_reva.c +++ b/Libraries/PeriphDrivers/Source/UART/uart_reva.c @@ -815,8 +815,6 @@ int MXC_UART_RevA_ClearTXFIFO(mxc_uart_reva_regs_t *uart) int MXC_UART_RevA_SetRXThreshold(mxc_uart_reva_regs_t *uart, unsigned int numBytes) { - - if (numBytes < 1 || numBytes > MXC_UART_FIFO_DEPTH) { return E_BAD_PARAM; } @@ -835,8 +833,6 @@ unsigned int MXC_UART_RevA_GetRXThreshold(mxc_uart_reva_regs_t *uart) int MXC_UART_RevA_SetTXThreshold(mxc_uart_reva_regs_t *uart, unsigned int numBytes) { - - if (numBytes < 1 || numBytes > MXC_UART_FIFO_DEPTH) { return E_BAD_PARAM; } @@ -860,8 +856,6 @@ unsigned int MXC_UART_RevA_GetFlags(mxc_uart_reva_regs_t *uart) int MXC_UART_RevA_ClearFlags(mxc_uart_reva_regs_t *uart, unsigned int flags) { - - uart->int_fl = flags; return E_NO_ERROR; @@ -869,8 +863,6 @@ int MXC_UART_RevA_ClearFlags(mxc_uart_reva_regs_t *uart, unsigned int flags) int MXC_UART_RevA_EnableInt(mxc_uart_reva_regs_t *uart, unsigned int intEn) { - - uart->int_en |= intEn; return E_NO_ERROR; @@ -878,8 +870,6 @@ int MXC_UART_RevA_EnableInt(mxc_uart_reva_regs_t *uart, unsigned int intEn) int MXC_UART_RevA_DisableInt(mxc_uart_reva_regs_t *uart, unsigned int intDis) { - - uart->int_en &= ~intDis; return E_NO_ERROR; @@ -1179,7 +1169,7 @@ int MXC_UART_RevA_TxAsyncCallback(mxc_uart_reva_regs_t *uart, int retVal) int uart_num = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); MXC_ASSERT(uart_num >= 0) - + if (TxAsyncRequests[uart_num] == NULL) { return E_BAD_STATE; } From 85020c87c34b66a42e59fc34d8f5e8a27f962506 Mon Sep 17 00:00:00 2001 From: Jake Carter Date: Wed, 29 Nov 2023 19:49:48 -0600 Subject: [PATCH 27/27] PURGE THE ASSERTS --- .../PeriphDrivers/Source/UART/uart_reva.c | 65 +---------------- .../PeriphDrivers/Source/UART/uart_revb.c | 70 ------------------- .../PeriphDrivers/Source/UART/uart_revc.c | 36 ---------- 3 files changed, 2 insertions(+), 169 deletions(-) diff --git a/Libraries/PeriphDrivers/Source/UART/uart_reva.c b/Libraries/PeriphDrivers/Source/UART/uart_reva.c index f12ae17ee8e..00e376b91d5 100644 --- a/Libraries/PeriphDrivers/Source/UART/uart_reva.c +++ b/Libraries/PeriphDrivers/Source/UART/uart_reva.c @@ -92,6 +92,8 @@ int MXC_UART_RevA_Init(mxc_uart_reva_regs_t *uart, unsigned int baud) { int err; + MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) + // Initialize UART // Set RX threshold to 1 byte if ((err = (MXC_UART_SetRXThreshold((mxc_uart_regs_t *)uart, 1))) != E_NO_ERROR) { @@ -134,8 +136,6 @@ int MXC_UART_RevA_Init(mxc_uart_reva_regs_t *uart, unsigned int baud) int MXC_UART_RevA_ReadyForSleep(mxc_uart_reva_regs_t *uart) { - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - if (TxAsyncRequests[MXC_UART_GET_IDX((mxc_uart_regs_t *)uart)] != NULL) { return E_BUSY; } @@ -152,8 +152,6 @@ int MXC_UART_RevA_SetFrequency(mxc_uart_reva_regs_t *uart, unsigned int baud) int prescale; int decimalDiv; - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - if (uart->ctrl & MXC_F_UART_REVA_CTRL_CLKSEL) { #ifdef IBRO_FREQ periphClock = IBRO_FREQ; @@ -265,8 +263,6 @@ int MXC_UART_RevA_GetFrequency(mxc_uart_reva_regs_t *uart) int MXC_UART_RevA_SetDataSize(mxc_uart_reva_regs_t *uart, int dataSize) { - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - if (dataSize < 5 || dataSize > 8) { return E_BAD_PARAM; } @@ -280,8 +276,6 @@ int MXC_UART_RevA_SetDataSize(mxc_uart_reva_regs_t *uart, int dataSize) int MXC_UART_RevA_SetStopBits(mxc_uart_reva_regs_t *uart, mxc_uart_stop_t stopBits) { - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - switch (stopBits) { case MXC_UART_STOP_1: MXC_SETFIELD(uart->ctrl, MXC_F_UART_REVA_CTRL_STOPBITS, @@ -303,8 +297,6 @@ int MXC_UART_RevA_SetStopBits(mxc_uart_reva_regs_t *uart, mxc_uart_stop_t stopBi int MXC_UART_RevA_SetParity(mxc_uart_reva_regs_t *uart, mxc_uart_parity_t parity) { - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - switch (parity) { case MXC_UART_PARITY_DISABLE: MXC_SETFIELD(uart->ctrl, MXC_F_UART_REVA_CTRL_PARITY_EN, @@ -382,8 +374,6 @@ int MXC_UART_RevA_SetParity(mxc_uart_reva_regs_t *uart, mxc_uart_parity_t parity int MXC_UART_RevA_SetFlowCtrl(mxc_uart_reva_regs_t *uart, mxc_uart_flow_t flowCtrl, int rtsThreshold) { - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - switch (flowCtrl) { case MXC_UART_FLOW_DIS: MXC_SETFIELD(uart->ctrl, MXC_F_UART_REVA_CTRL_FLOW_CTRL, @@ -423,8 +413,6 @@ int MXC_UART_RevA_SetClockSource(mxc_uart_reva_regs_t *uart, int usePCLK) { int baudRate; - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - baudRate = MXC_UART_GetFrequency((mxc_uart_regs_t *)uart); if (baudRate < 0) { // return error code return baudRate; @@ -441,8 +429,6 @@ int MXC_UART_RevA_SetClockSource(mxc_uart_reva_regs_t *uart, int usePCLK) int MXC_UART_RevA_SetNullModem(mxc_uart_reva_regs_t *uart, int nullModem) { - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - nullModem = (nullModem > 0) << MXC_F_UART_REVA_CTRL_NULL_MODEM_POS; MXC_SETFIELD(uart->ctrl, MXC_F_UART_REVA_CTRL_NULL_MODEM, nullModem); @@ -452,8 +438,6 @@ int MXC_UART_RevA_SetNullModem(mxc_uart_reva_regs_t *uart, int nullModem) int MXC_UART_RevA_SendBreak(mxc_uart_reva_regs_t *uart) { - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - MXC_SETFIELD(uart->ctrl, MXC_F_UART_REVA_CTRL_BREAK, 1 << MXC_F_UART_REVA_CTRL_BREAK_POS); return E_NO_ERROR; @@ -461,8 +445,6 @@ int MXC_UART_RevA_SendBreak(mxc_uart_reva_regs_t *uart) int MXC_UART_RevA_GetActive(mxc_uart_reva_regs_t *uart) { - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - if (uart->status & (MXC_F_UART_REVA_STATUS_TX_BUSY | MXC_F_UART_REVA_STATUS_RX_BUSY)) { return E_BUSY; } @@ -478,8 +460,6 @@ int MXC_UART_RevA_AbortTransmission(mxc_uart_reva_regs_t *uart) int MXC_UART_RevA_ReadCharacterRaw(mxc_uart_reva_regs_t *uart) { - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - if (uart->status & MXC_F_UART_REVA_STATUS_RX_EMPTY) { return E_UNDERFLOW; } @@ -489,8 +469,6 @@ int MXC_UART_RevA_ReadCharacterRaw(mxc_uart_reva_regs_t *uart) int MXC_UART_RevA_WriteCharacterRaw(mxc_uart_reva_regs_t *uart, uint8_t character) { - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - // Return error if the FIFO is full if (uart->status & MXC_F_UART_REVA_STATUS_TX_FULL) { return E_OVERFLOW; @@ -607,8 +585,6 @@ int MXC_UART_RevA_ReadRXFIFODMA(mxc_uart_reva_regs_t *uart, mxc_dma_regs_t *dma, int uart_num = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); - MXC_ASSERT(uart_num >= 0) - if (bytes == NULL) { return E_NULL_PTR; } @@ -680,7 +656,6 @@ unsigned int MXC_UART_RevA_WriteTXFIFO(mxc_uart_reva_regs_t *uart, unsigned char int MXC_UART_RevA_SetAutoDMAHandlers(mxc_uart_reva_regs_t *uart, bool enable) { int n = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); - MXC_ASSERT(n >= 0); states[n].auto_dma_handlers = enable; @@ -690,8 +665,6 @@ int MXC_UART_RevA_SetAutoDMAHandlers(mxc_uart_reva_regs_t *uart, bool enable) int MXC_UART_RevA_SetTXDMAChannel(mxc_uart_reva_regs_t *uart, unsigned int channel) { int n = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); - if (n < 0) - return E_BAD_PARAM; states[n].channelTx = channel; @@ -701,8 +674,6 @@ int MXC_UART_RevA_SetTXDMAChannel(mxc_uart_reva_regs_t *uart, unsigned int chann int MXC_UART_RevA_GetTXDMAChannel(mxc_uart_reva_regs_t *uart) { int n = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); - if (n < 0) - return E_BAD_PARAM; return states[n].channelTx; } @@ -710,8 +681,6 @@ int MXC_UART_RevA_GetTXDMAChannel(mxc_uart_reva_regs_t *uart) int MXC_UART_RevA_SetRXDMAChannel(mxc_uart_reva_regs_t *uart, unsigned int channel) { int n = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); - if (n < 0) - return E_BAD_PARAM; states[n].channelRx = channel; @@ -721,8 +690,6 @@ int MXC_UART_RevA_SetRXDMAChannel(mxc_uart_reva_regs_t *uart, unsigned int chann int MXC_UART_RevA_GetRXDMAChannel(mxc_uart_reva_regs_t *uart) { int n = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); - if (n < 0) - return E_BAD_PARAM; return states[n].channelRx; } @@ -737,8 +704,6 @@ unsigned int MXC_UART_RevA_WriteTXFIFODMA(mxc_uart_reva_regs_t *uart, mxc_dma_re int uart_num = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); - MXC_ASSERT(uart_num >= 0) - if (bytes == NULL) { return E_NULL_PTR; } @@ -793,8 +758,6 @@ unsigned int MXC_UART_RevA_GetTXFIFOAvailable(mxc_uart_reva_regs_t *uart) int MXC_UART_RevA_ClearRXFIFO(mxc_uart_reva_regs_t *uart) { - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - uart->ctrl |= MXC_F_UART_REVA_CTRL_RX_FLUSH; while (uart->ctrl & MXC_F_UART_REVA_CTRL_RX_FLUSH) {} @@ -804,8 +767,6 @@ int MXC_UART_RevA_ClearRXFIFO(mxc_uart_reva_regs_t *uart) int MXC_UART_RevA_ClearTXFIFO(mxc_uart_reva_regs_t *uart) { - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - uart->ctrl |= MXC_F_UART_REVA_CTRL_TX_FLUSH; while (uart->ctrl & MXC_F_UART_REVA_CTRL_TX_FLUSH) {} @@ -884,7 +845,6 @@ int MXC_UART_RevA_Busy(mxc_uart_reva_regs_t *uart) { int uart_num = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); // Holds the current index of tx_states - MXC_ASSERT(uart_num >= 0); if ((uart->status & MXC_F_UART_REVA_STATUS_TX_BUSY) || (uart->status & MXC_F_UART_REVA_STATUS_RX_BUSY)) { return E_BUSY; @@ -972,8 +932,6 @@ int MXC_UART_RevA_TransactionAsync(mxc_uart_reva_req_t *req) unsigned int numToWrite, numToRead; int uart_num = MXC_UART_GET_IDX((mxc_uart_regs_t *)(req->uart)); - MXC_ASSERT(uart_num >= 0) - if (req->txLen) { if (TxAsyncRequests[uart_num] != NULL) { return E_BAD_STATE; @@ -1024,8 +982,6 @@ int MXC_UART_RevA_TransactionDMA(mxc_uart_reva_req_t *req, mxc_dma_regs_t *dma) { int uart_num = MXC_UART_GET_IDX((mxc_uart_regs_t *)(req->uart)); - MXC_ASSERT(uart_num >= 0) - if (req->txLen) { if (req->txData == NULL) { return E_BAD_PARAM; @@ -1148,8 +1104,6 @@ int MXC_UART_RevA_RxAsyncCallback(mxc_uart_reva_regs_t *uart, int retVal) mxc_uart_reva_req_t *req; int uart_num = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); - MXC_ASSERT(uart_num >= 0) - if (RxAsyncRequests[uart_num] == NULL) { return E_BAD_STATE; } @@ -1168,8 +1122,6 @@ int MXC_UART_RevA_TxAsyncCallback(mxc_uart_reva_regs_t *uart, int retVal) mxc_uart_reva_req_t *req; int uart_num = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); - MXC_ASSERT(uart_num >= 0) - if (TxAsyncRequests[uart_num] == NULL) { return E_BAD_STATE; } @@ -1188,7 +1140,6 @@ int MXC_UART_RevA_AsyncCallback(mxc_uart_reva_regs_t *uart, int retVal) int err; int uart_num = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); - MXC_ASSERT(uart_num >= 0) // Call TX callback err = MXC_UART_TxAsyncCallback((mxc_uart_regs_t *)uart, retVal); @@ -1206,8 +1157,6 @@ int MXC_UART_RevA_AsyncCallback(mxc_uart_reva_regs_t *uart, int retVal) int MXC_UART_RevA_TxAsyncStop(mxc_uart_reva_regs_t *uart) { - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - MXC_UART_DisableInt((mxc_uart_regs_t *)uart, MXC_F_UART_REVA_INT_EN_TX_FIFO_THRESH); TxAsyncRequests[MXC_UART_GET_IDX((mxc_uart_regs_t *)uart)] = NULL; @@ -1216,8 +1165,6 @@ int MXC_UART_RevA_TxAsyncStop(mxc_uart_reva_regs_t *uart) int MXC_UART_RevA_RxAsyncStop(mxc_uart_reva_regs_t *uart) { - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - MXC_UART_DisableInt((mxc_uart_regs_t *)uart, (MXC_UART_REVA_ERRINT_EN | MXC_F_UART_REVA_INT_EN_RX_FIFO_THRESH)); RxAsyncRequests[MXC_UART_GET_IDX((mxc_uart_regs_t *)uart)] = NULL; @@ -1230,8 +1177,6 @@ int MXC_UART_RevA_AsyncStop(mxc_uart_reva_regs_t *uart) int uart_num = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); mxc_uart_reva_req_t *req; - MXC_ASSERT(uart_num >= 0) - req = (mxc_uart_reva_req_t *)TxAsyncRequests[uart_num]; if (req != NULL) { MXC_UART_TxAsyncStop((mxc_uart_regs_t *)uart); @@ -1249,8 +1194,6 @@ int MXC_UART_RevA_TxAbortAsync(mxc_uart_reva_regs_t *uart) { int uart_num = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); - MXC_ASSERT(uart_num >= 0) - mxc_uart_reva_req_t *req = (mxc_uart_reva_req_t *)TxAsyncRequests[uart_num]; if (req != NULL) { @@ -1265,8 +1208,6 @@ int MXC_UART_RevA_RxAbortAsync(mxc_uart_reva_regs_t *uart) { int uart_num = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); - MXC_ASSERT(uart_num >= 0) - mxc_uart_reva_req_t *req = (mxc_uart_reva_req_t *)RxAsyncRequests[uart_num]; if (req != NULL) { @@ -1301,8 +1242,6 @@ int MXC_UART_RevA_AsyncHandler(mxc_uart_reva_regs_t *uart) unsigned int flags, numToWrite, numToRead; mxc_uart_reva_req_t *req; - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - flags = MXC_UART_GetFlags((mxc_uart_regs_t *)uart); if (flags & MXC_UART_REVA_ERRINT_FL & uart->int_en) { diff --git a/Libraries/PeriphDrivers/Source/UART/uart_revb.c b/Libraries/PeriphDrivers/Source/UART/uart_revb.c index face251ddcb..7aa70cd1907 100644 --- a/Libraries/PeriphDrivers/Source/UART/uart_revb.c +++ b/Libraries/PeriphDrivers/Source/UART/uart_revb.c @@ -129,8 +129,6 @@ int MXC_UART_RevB_Init(mxc_uart_revb_regs_t *uart, unsigned int baud, mxc_uart_r int MXC_UART_RevB_ReadyForSleep(mxc_uart_revb_regs_t *uart) { - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - if (AsyncTxRequests[MXC_UART_GET_IDX((mxc_uart_regs_t *)uart)] != NULL) { return E_BUSY; } @@ -146,7 +144,6 @@ int MXC_UART_RevB_SetFrequency(mxc_uart_revb_regs_t *uart, unsigned int baud, mxc_uart_revb_clock_t clock) { unsigned clkDiv = 0, mod = 0; - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) // OSR default value uart->osr = 5; @@ -198,8 +195,6 @@ int MXC_UART_RevB_GetFrequency(mxc_uart_revb_regs_t *uart) { int periphClock = 0; - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - if ((uart->ctrl & MXC_F_UART_REVB_CTRL_BCLKSRC) == MXC_S_UART_REVB_CTRL_BCLKSRC_EXTERNAL_CLOCK) { periphClock = UART_EXTCLK_FREQ; @@ -223,8 +218,6 @@ int MXC_UART_RevB_GetFrequency(mxc_uart_revb_regs_t *uart) int MXC_UART_RevB_SetDataSize(mxc_uart_revb_regs_t *uart, int dataSize) { - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - if (dataSize < 5 || dataSize > 8) { return E_BAD_PARAM; } @@ -238,8 +231,6 @@ int MXC_UART_RevB_SetDataSize(mxc_uart_revb_regs_t *uart, int dataSize) int MXC_UART_RevB_SetStopBits(mxc_uart_revb_regs_t *uart, mxc_uart_stop_t stopBits) { - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - switch (stopBits) { case MXC_UART_STOP_1: MXC_SETFIELD(uart->ctrl, MXC_F_UART_REVB_CTRL_STOPBITS, @@ -261,8 +252,6 @@ int MXC_UART_RevB_SetStopBits(mxc_uart_revb_regs_t *uart, mxc_uart_stop_t stopBi int MXC_UART_RevB_SetParity(mxc_uart_revb_regs_t *uart, mxc_uart_parity_t parity) { - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - switch (parity) { case MXC_UART_PARITY_DISABLE: MXC_SETFIELD(uart->ctrl, MXC_F_UART_REVB_CTRL_PAR_EN, 0 << MXC_F_UART_REVB_CTRL_PAR_EN_POS); @@ -303,8 +292,6 @@ int MXC_UART_RevB_SetParity(mxc_uart_revb_regs_t *uart, mxc_uart_parity_t parity int MXC_UART_RevB_SetFlowCtrl(mxc_uart_revb_regs_t *uart, mxc_uart_flow_t flowCtrl, int rtsThreshold) { - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - switch (flowCtrl) { case MXC_UART_FLOW_DIS: MXC_SETFIELD(uart->ctrl, MXC_F_UART_REVB_CTRL_HFC_EN, 0 << MXC_F_UART_REVB_CTRL_HFC_EN_POS); @@ -326,8 +313,6 @@ int MXC_UART_RevB_SetFlowCtrl(mxc_uart_revb_regs_t *uart, mxc_uart_flow_t flowCt int MXC_UART_RevB_SetClockSource(mxc_uart_revb_regs_t *uart, mxc_uart_revb_clock_t clock) { - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - switch (clock) { case MXC_UART_REVB_APB_CLK: break; @@ -353,8 +338,6 @@ int MXC_UART_RevB_SetClockSource(mxc_uart_revb_regs_t *uart, mxc_uart_revb_clock int MXC_UART_RevB_GetActive(mxc_uart_revb_regs_t *uart) { - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - if (uart->status & (MXC_F_UART_REVB_STATUS_TX_BUSY | MXC_F_UART_REVB_STATUS_RX_BUSY)) { return E_BUSY; } @@ -386,8 +369,6 @@ int MXC_UART_RevB_AbortTransmission(mxc_uart_revb_regs_t *uart) int MXC_UART_RevB_ReadCharacterRaw(mxc_uart_revb_regs_t *uart) { - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - if (uart->status & MXC_F_UART_REVB_STATUS_RX_EM) { return E_UNDERFLOW; } @@ -397,8 +378,6 @@ int MXC_UART_RevB_ReadCharacterRaw(mxc_uart_revb_regs_t *uart) int MXC_UART_RevB_WriteCharacterRaw(mxc_uart_revb_regs_t *uart, uint8_t character) { - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - // Require the TX FIFO to be empty, so that we write out the expected character // Return error if the FIFO is full if (uart->status & MXC_F_UART_REVB_STATUS_TX_FULL) { @@ -412,8 +391,6 @@ int MXC_UART_RevB_WriteCharacterRaw(mxc_uart_revb_regs_t *uart, uint8_t characte int MXC_UART_RevB_ReadCharacter(mxc_uart_revb_regs_t *uart) { - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - if (uart->status & MXC_F_UART_REVB_STATUS_RX_EM) { return E_UNDERFLOW; } @@ -423,8 +400,6 @@ int MXC_UART_RevB_ReadCharacter(mxc_uart_revb_regs_t *uart) int MXC_UART_RevB_WriteCharacter(mxc_uart_revb_regs_t *uart, uint8_t character) { - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - // Require the TX FIFO to be empty, so that we write out the expected character // Return error if the FIFO is full if (uart->status & MXC_F_UART_REVB_STATUS_TX_FULL) { @@ -441,8 +416,6 @@ int MXC_UART_RevB_Read(mxc_uart_revb_regs_t *uart, uint8_t *buffer, int *len) int read = 0; int retVal; - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - if (buffer == NULL) { return E_NULL_PTR; } @@ -471,8 +444,6 @@ int MXC_UART_RevB_Write(mxc_uart_revb_regs_t *uart, const uint8_t *byte, int *le int written = 0; int retVal; - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - if (byte == NULL) { return E_NULL_PTR; } @@ -539,8 +510,6 @@ unsigned int MXC_UART_RevB_GetTXFIFOAvailable(mxc_uart_revb_regs_t *uart) int MXC_UART_RevB_ClearRXFIFO(mxc_uart_revb_regs_t *uart) { - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - uart->ctrl |= MXC_F_UART_REVB_CTRL_RX_FLUSH; while (!(uart->status & MXC_F_UART_REVB_STATUS_RX_EM)) {} @@ -549,8 +518,6 @@ int MXC_UART_RevB_ClearRXFIFO(mxc_uart_revb_regs_t *uart) int MXC_UART_RevB_ClearTXFIFO(mxc_uart_revb_regs_t *uart) { - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - uart->ctrl |= MXC_F_UART_REVB_CTRL_TX_FLUSH; while (uart->ctrl & MXC_F_UART_REVB_CTRL_TX_FLUSH) {} @@ -559,8 +526,6 @@ int MXC_UART_RevB_ClearTXFIFO(mxc_uart_revb_regs_t *uart) int MXC_UART_RevB_SetRXThreshold(mxc_uart_revb_regs_t *uart, unsigned int numBytes) { - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - if (numBytes < 1 || numBytes > MXC_UART_FIFO_DEPTH) { return E_BAD_PARAM; } @@ -583,8 +548,6 @@ unsigned int MXC_UART_RevB_GetFlags(mxc_uart_revb_regs_t *uart) int MXC_UART_RevB_ClearFlags(mxc_uart_revb_regs_t *uart, unsigned int flags) { - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - uart->int_fl = flags; return E_NO_ERROR; @@ -592,8 +555,6 @@ int MXC_UART_RevB_ClearFlags(mxc_uart_revb_regs_t *uart, unsigned int flags) int MXC_UART_RevB_EnableInt(mxc_uart_revb_regs_t *uart, unsigned int intEn) { - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - uart->int_en |= intEn; return E_NO_ERROR; @@ -601,8 +562,6 @@ int MXC_UART_RevB_EnableInt(mxc_uart_revb_regs_t *uart, unsigned int intEn) int MXC_UART_RevB_DisableInt(mxc_uart_revb_regs_t *uart, unsigned int intDis) { - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - uart->int_en &= ~intDis; return E_NO_ERROR; @@ -683,8 +642,6 @@ int MXC_UART_RevB_TransactionAsync(mxc_uart_revb_req_t *req) uint32_t numToWrite, numToRead; int uart_num = MXC_UART_GET_IDX((mxc_uart_regs_t *)(req->uart)); - MXC_ASSERT(uart_num >= 0) - if (!AsyncTxRequests[uart_num] && !AsyncRxRequests[uart_num]) { /* No requests pending, clear the interrupt state */ MXC_UART_DisableInt((mxc_uart_regs_t *)(req->uart), 0xFFFFFFFF); @@ -750,7 +707,6 @@ int MXC_UART_RevB_TransactionAsync(mxc_uart_revb_req_t *req) int MXC_UART_RevB_AsyncTxCallback(mxc_uart_revb_regs_t *uart, int retVal) { int uart_num = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); - MXC_ASSERT(uart_num >= 0) mxc_uart_req_t *req = (mxc_uart_req_t *)AsyncTxRequests[uart_num]; if ((req != NULL) && (req->callback != NULL)) { @@ -764,7 +720,6 @@ int MXC_UART_RevB_AsyncTxCallback(mxc_uart_revb_regs_t *uart, int retVal) int MXC_UART_RevB_AsyncRxCallback(mxc_uart_revb_regs_t *uart, int retVal) { int uart_num = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); - MXC_ASSERT(uart_num >= 0) mxc_uart_req_t *req = (mxc_uart_req_t *)AsyncRxRequests[uart_num]; if ((req != NULL) && (req->callback != NULL)) { @@ -778,7 +733,6 @@ int MXC_UART_RevB_AsyncRxCallback(mxc_uart_revb_regs_t *uart, int retVal) int MXC_UART_RevB_AsyncCallback(mxc_uart_revb_regs_t *uart, int retVal) { int uart_num = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); - MXC_ASSERT(uart_num >= 0) MXC_UART_RevB_AsyncTxCallback(uart, retVal); @@ -792,8 +746,6 @@ int MXC_UART_RevB_AsyncCallback(mxc_uart_revb_regs_t *uart, int retVal) int MXC_UART_RevB_AsyncStopTx(mxc_uart_revb_regs_t *uart) { - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - MXC_UART_DisableInt((mxc_uart_regs_t *)uart, MXC_F_UART_REVB_INT_EN_TX_HE); return E_NO_ERROR; @@ -801,8 +753,6 @@ int MXC_UART_RevB_AsyncStopTx(mxc_uart_revb_regs_t *uart) int MXC_UART_RevB_AsyncStopRx(mxc_uart_revb_regs_t *uart) { - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - MXC_UART_DisableInt((mxc_uart_regs_t *)uart, MXC_UART_REVB_ERRINT_EN); return E_NO_ERROR; @@ -810,8 +760,6 @@ int MXC_UART_RevB_AsyncStopRx(mxc_uart_revb_regs_t *uart) int MXC_UART_RevB_AsyncStop(mxc_uart_revb_regs_t *uart) { - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - MXC_UART_DisableInt((mxc_uart_regs_t *)uart, 0xFFFFFFFF); return E_NO_ERROR; @@ -819,8 +767,6 @@ int MXC_UART_RevB_AsyncStop(mxc_uart_revb_regs_t *uart) int MXC_UART_RevB_AbortAsync(mxc_uart_revb_regs_t *uart) { - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - MXC_UART_AsyncStop((mxc_uart_regs_t *)uart); MXC_UART_AsyncCallback((mxc_uart_regs_t *)uart, E_ABORT); @@ -834,8 +780,6 @@ int MXC_UART_RevB_AsyncHandler(mxc_uart_revb_regs_t *uart) int uart_num = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); - MXC_ASSERT(uart_num >= 0) - flags = MXC_UART_GetFlags((mxc_uart_regs_t *)uart); /* Unexpected interrupt */ @@ -922,8 +866,6 @@ void MXC_UART_RevB_DMA_SetupAutoHandlers(unsigned int channel) int MXC_UART_RevB_SetTXDMAChannel(mxc_uart_revb_regs_t *uart, unsigned int channel) { int n = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); - if (n < 0) - return E_BAD_PARAM; states[n].channelTx = channel; @@ -933,8 +875,6 @@ int MXC_UART_RevB_SetTXDMAChannel(mxc_uart_revb_regs_t *uart, unsigned int chann int MXC_UART_RevB_GetTXDMAChannel(mxc_uart_revb_regs_t *uart) { int n = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); - if (n < 0) - return E_BAD_PARAM; return states[n].channelTx; } @@ -942,8 +882,6 @@ int MXC_UART_RevB_GetTXDMAChannel(mxc_uart_revb_regs_t *uart) int MXC_UART_RevB_SetRXDMAChannel(mxc_uart_revb_regs_t *uart, unsigned int channel) { int n = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); - if (n < 0) - return E_BAD_PARAM; states[n].channelRx = channel; @@ -953,8 +891,6 @@ int MXC_UART_RevB_SetRXDMAChannel(mxc_uart_revb_regs_t *uart, unsigned int chann int MXC_UART_RevB_GetRXDMAChannel(mxc_uart_revb_regs_t *uart) { int n = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); - if (n < 0) - return E_BAD_PARAM; return states[n].channelRx; } @@ -967,8 +903,6 @@ int MXC_UART_RevB_ReadRXFIFODMA(mxc_uart_revb_regs_t *uart, unsigned char *bytes int uart_num = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); - MXC_ASSERT(uart_num >= 0) - if (bytes == NULL) { return E_NULL_PTR; } @@ -1017,8 +951,6 @@ int MXC_UART_RevB_WriteTXFIFODMA(mxc_uart_revb_regs_t *uart, const unsigned char int uart_num = MXC_UART_GET_IDX((mxc_uart_regs_t *)uart); - MXC_ASSERT(uart_num >= 0) - if (bytes == NULL) { return E_NULL_PTR; } @@ -1062,8 +994,6 @@ int MXC_UART_RevB_TransactionDMA(mxc_uart_revb_req_t *req) { int uart_num = MXC_UART_GET_IDX((mxc_uart_regs_t *)(req->uart)); - MXC_ASSERT(uart_num >= 0) - if (req->txLen) { if (req->txData == NULL) { return E_BAD_PARAM; diff --git a/Libraries/PeriphDrivers/Source/UART/uart_revc.c b/Libraries/PeriphDrivers/Source/UART/uart_revc.c index 02b4c0dc1c0..75b785d958b 100644 --- a/Libraries/PeriphDrivers/Source/UART/uart_revc.c +++ b/Libraries/PeriphDrivers/Source/UART/uart_revc.c @@ -117,8 +117,6 @@ int MXC_UART_RevC_Init(mxc_uart_revc_regs_t *uart, unsigned int baud) int MXC_UART_RevC_ReadyForSleep(mxc_uart_revc_regs_t *uart) { - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - if (AsyncRequests[MXC_UART_GET_IDX((mxc_uart_regs_t *)uart)] != NULL) { return E_BUSY; } @@ -130,8 +128,6 @@ int MXC_UART_RevC_SetFrequency(mxc_uart_revc_regs_t *uart, unsigned int baud) { int div = 0, baud0 = 0, baud1 = 0; - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - // Set the baud rate // Calculate divisor div = PeripheralClock / baud; @@ -157,8 +153,6 @@ int MXC_UART_RevC_GetFrequency(mxc_uart_revc_regs_t *uart) int MXC_UART_RevC_SetDataSize(mxc_uart_revc_regs_t *uart, int dataSize) { - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - if (dataSize < 5 || dataSize > 8) { return E_BAD_PARAM; } @@ -172,8 +166,6 @@ int MXC_UART_RevC_SetDataSize(mxc_uart_revc_regs_t *uart, int dataSize) int MXC_UART_RevC_SetStopBits(mxc_uart_revc_regs_t *uart, mxc_uart_stop_t stopBits) { - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - switch (stopBits) { case MXC_UART_STOP_1: MXC_SETFIELD(uart->ctrl, MXC_F_UART_REVC_CTRL_STOPBITS, @@ -195,8 +187,6 @@ int MXC_UART_RevC_SetStopBits(mxc_uart_revc_regs_t *uart, mxc_uart_stop_t stopBi int MXC_UART_RevC_SetParity(mxc_uart_revc_regs_t *uart, mxc_uart_parity_t parity) { - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - switch (parity) { case MXC_UART_PARITY_DISABLE: MXC_SETFIELD(uart->ctrl, MXC_F_UART_REVC_CTRL_PARITY_EN, @@ -243,8 +233,6 @@ int MXC_UART_RevC_SetParity(mxc_uart_revc_regs_t *uart, mxc_uart_parity_t parity int MXC_UART_RevC_GetActive(mxc_uart_revc_regs_t *uart) { - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - if (uart->status & (MXC_F_UART_REVC_STATUS_TX_BUSY | MXC_F_UART_REVC_STATUS_RX_BUSY)) { return E_BUSY; } @@ -254,15 +242,11 @@ int MXC_UART_RevC_GetActive(mxc_uart_revc_regs_t *uart) int MXC_UART_RevC_AbortTransmission(mxc_uart_revc_regs_t *uart) { - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - return MXC_UART_ClearTXFIFO((mxc_uart_regs_t *)uart); } int MXC_UART_RevC_ReadCharacterRaw(mxc_uart_revc_regs_t *uart) { - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - if (uart->status & MXC_F_UART_REVC_STATUS_RX_EMPTY) { return E_UNDERFLOW; } @@ -272,8 +256,6 @@ int MXC_UART_RevC_ReadCharacterRaw(mxc_uart_revc_regs_t *uart) int MXC_UART_RevC_WriteCharacterRaw(mxc_uart_revc_regs_t *uart, uint8_t character) { - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - // Return error if the FIFO is full if (uart->status & MXC_F_UART_REVC_STATUS_TX_FULL) { return E_OVERFLOW; @@ -435,8 +417,6 @@ unsigned int MXC_UART_RevC_GetTXFIFOAvailable(mxc_uart_revc_regs_t *uart) int MXC_UART_RevC_ClearRXFIFO(mxc_uart_revc_regs_t *uart) { - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - uart->ctrl |= MXC_F_UART_REVC_CTRL_RX_FLUSH; while (uart->ctrl & MXC_F_UART_REVC_CTRL_RX_FLUSH) {} @@ -446,8 +426,6 @@ int MXC_UART_RevC_ClearRXFIFO(mxc_uart_revc_regs_t *uart) int MXC_UART_RevC_ClearTXFIFO(mxc_uart_revc_regs_t *uart) { - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - uart->ctrl |= MXC_F_UART_REVC_CTRL_TX_FLUSH; while (uart->ctrl & MXC_F_UART_REVC_CTRL_TX_FLUSH) {} @@ -457,8 +435,6 @@ int MXC_UART_RevC_ClearTXFIFO(mxc_uart_revc_regs_t *uart) int MXC_UART_RevC_SetRXThreshold(mxc_uart_revc_regs_t *uart, unsigned int numBytes) { - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - if (numBytes < 1 || numBytes > MXC_UART_FIFO_DEPTH) { return E_BAD_PARAM; } @@ -481,8 +457,6 @@ unsigned int MXC_UART_RevC_GetFlags(mxc_uart_revc_regs_t *uart) int MXC_UART_RevC_ClearFlags(mxc_uart_revc_regs_t *uart, unsigned int flags) { - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - uart->int_fl &= ~flags; return E_NO_ERROR; @@ -490,8 +464,6 @@ int MXC_UART_RevC_ClearFlags(mxc_uart_revc_regs_t *uart, unsigned int flags) int MXC_UART_RevC_EnableInt(mxc_uart_revc_regs_t *uart, unsigned int intEn) { - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - uart->int_en |= intEn; return E_NO_ERROR; @@ -499,8 +471,6 @@ int MXC_UART_RevC_EnableInt(mxc_uart_revc_regs_t *uart, unsigned int intEn) int MXC_UART_RevC_DisableInt(mxc_uart_revc_regs_t *uart, unsigned int intDis) { - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - uart->int_en &= ~intDis; return E_NO_ERROR; @@ -724,8 +694,6 @@ void MXC_UART_RevC_DMACallback(int ch, int error) int MXC_UART_RevC_AsyncCallback(mxc_uart_revc_regs_t *uart, int retVal) { - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - mxc_uart_revc_req_t *req = (mxc_uart_revc_req_t *)AsyncRequests[MXC_UART_GET_IDX((mxc_uart_regs_t *)uart)]; @@ -738,8 +706,6 @@ int MXC_UART_RevC_AsyncCallback(mxc_uart_revc_regs_t *uart, int retVal) int MXC_UART_RevC_AsyncStop(mxc_uart_revc_regs_t *uart) { - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - MXC_UART_DisableInt((mxc_uart_regs_t *)uart, 0xFFFFFFFF); AsyncRequests[MXC_UART_GET_IDX((mxc_uart_regs_t *)uart)] = NULL; @@ -748,8 +714,6 @@ int MXC_UART_RevC_AsyncStop(mxc_uart_revc_regs_t *uart) int MXC_UART_RevC_AbortAsync(mxc_uart_revc_regs_t *uart) { - MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - MXC_UART_AsyncCallback((mxc_uart_regs_t *)uart, E_ABORT); MXC_UART_AsyncStop((mxc_uart_regs_t *)uart);