From 3ecb9401c18adb8f403dbd065828f47b79acfc14 Mon Sep 17 00:00:00 2001 From: Jake Carter Date: Mon, 29 Apr 2024 16:23:38 -0600 Subject: [PATCH 1/6] Initialize UART internal state struct --- .../PeriphDrivers/Source/UART/uart_reva.c | 29 +++++++++++++++++++ .../PeriphDrivers/Source/UART/uart_revb.c | 29 +++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/Libraries/PeriphDrivers/Source/UART/uart_reva.c b/Libraries/PeriphDrivers/Source/UART/uart_reva.c index 2256afe35a1..59147ec3dfe 100644 --- a/Libraries/PeriphDrivers/Source/UART/uart_reva.c +++ b/Libraries/PeriphDrivers/Source/UART/uart_reva.c @@ -19,6 +19,7 @@ ******************************************************************************/ #include +#include #include "mxc_device.h" #include "mxc_assert.h" #include "uart.h" @@ -52,8 +53,28 @@ typedef struct { uart_reva_req_state_t states[MXC_UART_INSTANCES]; +#define DEFAULT_UART_REVA_REQ_STATE {\ + .tx_req = NULL,\ + .rx_req = NULL,\ + .channelTx = -1,\ + .channelRx = -1,\ + .auto_dma_handlers = false\ + } + +bool g_is_state_initialized = false; + /* **** Function Prototypes **** */ +/* Internal function for initializing the internal state array. */ +inline void MXC_UART_RevB_Init_State(void) +{ + uart_reva_req_state_t default_state = DEFAULT_UART_REVA_REQ_STATE; + for (int i = 0; i < MXC_UART_INSTANCES; i++) { + states[i] = default_state; + } + g_is_state_initialized = true; +} + /* ************************************************************************* */ /* Control/Configuration functions */ /* ************************************************************************* */ @@ -63,6 +84,14 @@ int MXC_UART_RevA_Init(mxc_uart_reva_regs_t *uart, unsigned int baud) MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) + if (!g_is_state_initialized) { + // The first UART instance that is initialized will be responsible for + // initializing the global state array. We do this at run-time because + // the number of UART instances is variable, which makes it difficult for + // the pre-processor to handle at compile-time. + MXC_UART_RevB_Init_State(); + } + // Initialize UART // Set RX threshold to 1 byte if ((err = (MXC_UART_SetRXThreshold((mxc_uart_regs_t *)uart, 1))) != E_NO_ERROR) { diff --git a/Libraries/PeriphDrivers/Source/UART/uart_revb.c b/Libraries/PeriphDrivers/Source/UART/uart_revb.c index da82f678825..003e027b45a 100644 --- a/Libraries/PeriphDrivers/Source/UART/uart_revb.c +++ b/Libraries/PeriphDrivers/Source/UART/uart_revb.c @@ -20,6 +20,7 @@ ******************************************************************************/ #include +#include #include "mxc_device.h" #include "mxc_assert.h" #include "uart.h" @@ -50,8 +51,28 @@ typedef struct { uart_revb_req_state_t states[MXC_UART_INSTANCES]; +#define DEFAULT_UART_REVB_REQ_STATE {\ + .tx_req = NULL,\ + .rx_req = NULL,\ + .channelTx = -1,\ + .channelRx = -1,\ + .auto_dma_handlers = false\ + } + +bool g_is_state_initialized = false; + /* **** Function Prototypes **** */ +/* Internal function for initializing the internal state array. */ +inline void MXC_UART_RevB_Init_State(void) +{ + uart_revb_req_state_t default_state = DEFAULT_UART_REVB_REQ_STATE; + for (int i = 0; i < MXC_UART_INSTANCES; i++) { + states[i] = default_state; + } + g_is_state_initialized = true; +} + /* ************************************************************************* */ /* Control/Configuration functions */ /* ************************************************************************* */ @@ -61,6 +82,14 @@ int MXC_UART_RevB_Init(mxc_uart_revb_regs_t *uart, unsigned int baud, mxc_uart_r MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) + if (!g_is_state_initialized) { + // The first UART instance that is initialized will be responsible for + // initializing the global state array. We do this at run-time because + // the number of UART instances is variable, which makes it difficult for + // the pre-processor to handle at compile-time. + MXC_UART_RevB_Init_State(); + } + // Initialize UART if ((err = MXC_UART_SetRXThreshold((mxc_uart_regs_t *)uart, 1)) != E_NO_ERROR) { // Set RX threshold to 1 byte From 576f1cc843a5c955b73eb24b9bebcfbacc9bcdf2 Mon Sep 17 00:00:00 2001 From: Jake Carter Date: Mon, 29 Apr 2024 16:30:50 -0600 Subject: [PATCH 2/6] clang-format --- Libraries/PeriphDrivers/Source/UART/uart_reva.c | 10 ++++------ Libraries/PeriphDrivers/Source/UART/uart_revb.c | 10 ++++------ 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/Libraries/PeriphDrivers/Source/UART/uart_reva.c b/Libraries/PeriphDrivers/Source/UART/uart_reva.c index 59147ec3dfe..2739e2c91a8 100644 --- a/Libraries/PeriphDrivers/Source/UART/uart_reva.c +++ b/Libraries/PeriphDrivers/Source/UART/uart_reva.c @@ -53,12 +53,10 @@ typedef struct { uart_reva_req_state_t states[MXC_UART_INSTANCES]; -#define DEFAULT_UART_REVA_REQ_STATE {\ - .tx_req = NULL,\ - .rx_req = NULL,\ - .channelTx = -1,\ - .channelRx = -1,\ - .auto_dma_handlers = false\ +#define DEFAULT_UART_REVA_REQ_STATE \ + { \ + .tx_req = NULL, .rx_req = NULL, .channelTx = -1, .channelRx = -1, \ + .auto_dma_handlers = false \ } bool g_is_state_initialized = false; diff --git a/Libraries/PeriphDrivers/Source/UART/uart_revb.c b/Libraries/PeriphDrivers/Source/UART/uart_revb.c index 003e027b45a..3bd52baa176 100644 --- a/Libraries/PeriphDrivers/Source/UART/uart_revb.c +++ b/Libraries/PeriphDrivers/Source/UART/uart_revb.c @@ -51,12 +51,10 @@ typedef struct { uart_revb_req_state_t states[MXC_UART_INSTANCES]; -#define DEFAULT_UART_REVB_REQ_STATE {\ - .tx_req = NULL,\ - .rx_req = NULL,\ - .channelTx = -1,\ - .channelRx = -1,\ - .auto_dma_handlers = false\ +#define DEFAULT_UART_REVB_REQ_STATE \ + { \ + .tx_req = NULL, .rx_req = NULL, .channelTx = -1, .channelRx = -1, \ + .auto_dma_handlers = false \ } bool g_is_state_initialized = false; From d39ce1503e5e8233adba996ed2da2f2d7ba76bbc Mon Sep 17 00:00:00 2001 From: Jake Carter Date: Tue, 30 Apr 2024 13:50:49 -0600 Subject: [PATCH 3/6] Remove inline --- Libraries/PeriphDrivers/Source/UART/uart_reva.c | 2 +- Libraries/PeriphDrivers/Source/UART/uart_revb.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Libraries/PeriphDrivers/Source/UART/uart_reva.c b/Libraries/PeriphDrivers/Source/UART/uart_reva.c index 2739e2c91a8..26f8f1c80d4 100644 --- a/Libraries/PeriphDrivers/Source/UART/uart_reva.c +++ b/Libraries/PeriphDrivers/Source/UART/uart_reva.c @@ -64,7 +64,7 @@ bool g_is_state_initialized = false; /* **** Function Prototypes **** */ /* Internal function for initializing the internal state array. */ -inline void MXC_UART_RevB_Init_State(void) +void MXC_UART_RevB_Init_State(void) { uart_reva_req_state_t default_state = DEFAULT_UART_REVA_REQ_STATE; for (int i = 0; i < MXC_UART_INSTANCES; i++) { diff --git a/Libraries/PeriphDrivers/Source/UART/uart_revb.c b/Libraries/PeriphDrivers/Source/UART/uart_revb.c index 3bd52baa176..19e4c2f12cf 100644 --- a/Libraries/PeriphDrivers/Source/UART/uart_revb.c +++ b/Libraries/PeriphDrivers/Source/UART/uart_revb.c @@ -62,7 +62,7 @@ bool g_is_state_initialized = false; /* **** Function Prototypes **** */ /* Internal function for initializing the internal state array. */ -inline void MXC_UART_RevB_Init_State(void) +void MXC_UART_RevB_Init_State(void) { uart_revb_req_state_t default_state = DEFAULT_UART_REVB_REQ_STATE; for (int i = 0; i < MXC_UART_INSTANCES; i++) { From 972fc1b3680953ef14cbd08c809ead022b7f5c7d Mon Sep 17 00:00:00 2001 From: Jake Carter Date: Tue, 11 Jun 2024 18:18:14 -0600 Subject: [PATCH 4/6] Use array initializer syntax --- .../PeriphDrivers/Source/UART/uart_reva.c | 34 +++++-------------- .../PeriphDrivers/Source/UART/uart_revb.c | 34 +++++-------------- 2 files changed, 16 insertions(+), 52 deletions(-) diff --git a/Libraries/PeriphDrivers/Source/UART/uart_reva.c b/Libraries/PeriphDrivers/Source/UART/uart_reva.c index 26f8f1c80d4..337a4d7faca 100644 --- a/Libraries/PeriphDrivers/Source/UART/uart_reva.c +++ b/Libraries/PeriphDrivers/Source/UART/uart_reva.c @@ -51,28 +51,18 @@ typedef struct { bool auto_dma_handlers; } uart_reva_req_state_t; -uart_reva_req_state_t states[MXC_UART_INSTANCES]; - -#define DEFAULT_UART_REVA_REQ_STATE \ - { \ - .tx_req = NULL, .rx_req = NULL, .channelTx = -1, .channelRx = -1, \ - .auto_dma_handlers = false \ +uart_reva_req_state_t states[MXC_UART_INSTANCES] = { + [0 ... MXC_UART_INSTANCES - 1] = { + .tx_req = NULL, + .rx_req = NULL, + .channelTx = -1, + .channelRx = -1, + .auto_dma_handlers = false } - -bool g_is_state_initialized = false; +}; /* **** Function Prototypes **** */ -/* Internal function for initializing the internal state array. */ -void MXC_UART_RevB_Init_State(void) -{ - uart_reva_req_state_t default_state = DEFAULT_UART_REVA_REQ_STATE; - for (int i = 0; i < MXC_UART_INSTANCES; i++) { - states[i] = default_state; - } - g_is_state_initialized = true; -} - /* ************************************************************************* */ /* Control/Configuration functions */ /* ************************************************************************* */ @@ -82,14 +72,6 @@ int MXC_UART_RevA_Init(mxc_uart_reva_regs_t *uart, unsigned int baud) MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - if (!g_is_state_initialized) { - // The first UART instance that is initialized will be responsible for - // initializing the global state array. We do this at run-time because - // the number of UART instances is variable, which makes it difficult for - // the pre-processor to handle at compile-time. - MXC_UART_RevB_Init_State(); - } - // Initialize UART // Set RX threshold to 1 byte if ((err = (MXC_UART_SetRXThreshold((mxc_uart_regs_t *)uart, 1))) != E_NO_ERROR) { diff --git a/Libraries/PeriphDrivers/Source/UART/uart_revb.c b/Libraries/PeriphDrivers/Source/UART/uart_revb.c index 19e4c2f12cf..e6cccc2c30c 100644 --- a/Libraries/PeriphDrivers/Source/UART/uart_revb.c +++ b/Libraries/PeriphDrivers/Source/UART/uart_revb.c @@ -49,28 +49,18 @@ typedef struct { bool auto_dma_handlers; } uart_revb_req_state_t; -uart_revb_req_state_t states[MXC_UART_INSTANCES]; - -#define DEFAULT_UART_REVB_REQ_STATE \ - { \ - .tx_req = NULL, .rx_req = NULL, .channelTx = -1, .channelRx = -1, \ - .auto_dma_handlers = false \ +uart_revb_req_state_t states[MXC_UART_INSTANCES] = { + [0 ... MXC_UART_INSTANCES - 1] = { + .tx_req = NULL, + .rx_req = NULL, + .channelTx = -1, + .channelRx = -1, + .auto_dma_handlers = false } - -bool g_is_state_initialized = false; +}; /* **** Function Prototypes **** */ -/* Internal function for initializing the internal state array. */ -void MXC_UART_RevB_Init_State(void) -{ - uart_revb_req_state_t default_state = DEFAULT_UART_REVB_REQ_STATE; - for (int i = 0; i < MXC_UART_INSTANCES; i++) { - states[i] = default_state; - } - g_is_state_initialized = true; -} - /* ************************************************************************* */ /* Control/Configuration functions */ /* ************************************************************************* */ @@ -80,14 +70,6 @@ int MXC_UART_RevB_Init(mxc_uart_revb_regs_t *uart, unsigned int baud, mxc_uart_r MXC_ASSERT(MXC_UART_GET_IDX((mxc_uart_regs_t *)uart) >= 0) - if (!g_is_state_initialized) { - // The first UART instance that is initialized will be responsible for - // initializing the global state array. We do this at run-time because - // the number of UART instances is variable, which makes it difficult for - // the pre-processor to handle at compile-time. - MXC_UART_RevB_Init_State(); - } - // Initialize UART if ((err = MXC_UART_SetRXThreshold((mxc_uart_regs_t *)uart, 1)) != E_NO_ERROR) { // Set RX threshold to 1 byte From 1b7e140a4b8b79170988e0b9f36337df935ef761 Mon Sep 17 00:00:00 2001 From: Jake Carter Date: Tue, 11 Jun 2024 18:20:54 -0600 Subject: [PATCH 5/6] Remove stdbool.h --- Libraries/PeriphDrivers/Source/UART/uart_reva.c | 1 - Libraries/PeriphDrivers/Source/UART/uart_revb.c | 1 - 2 files changed, 2 deletions(-) diff --git a/Libraries/PeriphDrivers/Source/UART/uart_reva.c b/Libraries/PeriphDrivers/Source/UART/uart_reva.c index 337a4d7faca..0c59e15fd40 100644 --- a/Libraries/PeriphDrivers/Source/UART/uart_reva.c +++ b/Libraries/PeriphDrivers/Source/UART/uart_reva.c @@ -19,7 +19,6 @@ ******************************************************************************/ #include -#include #include "mxc_device.h" #include "mxc_assert.h" #include "uart.h" diff --git a/Libraries/PeriphDrivers/Source/UART/uart_revb.c b/Libraries/PeriphDrivers/Source/UART/uart_revb.c index e6cccc2c30c..74faa522fbb 100644 --- a/Libraries/PeriphDrivers/Source/UART/uart_revb.c +++ b/Libraries/PeriphDrivers/Source/UART/uart_revb.c @@ -20,7 +20,6 @@ ******************************************************************************/ #include -#include #include "mxc_device.h" #include "mxc_assert.h" #include "uart.h" From af1d518bc4203121b3700730fdbc0a7f2e9ae3f0 Mon Sep 17 00:00:00 2001 From: Jake Carter Date: Tue, 11 Jun 2024 18:25:00 -0600 Subject: [PATCH 6/6] clang-format --- Libraries/PeriphDrivers/Source/UART/uart_reva.c | 2 ++ Libraries/PeriphDrivers/Source/UART/uart_revb.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/Libraries/PeriphDrivers/Source/UART/uart_reva.c b/Libraries/PeriphDrivers/Source/UART/uart_reva.c index 0c59e15fd40..759a1e7ebe0 100644 --- a/Libraries/PeriphDrivers/Source/UART/uart_reva.c +++ b/Libraries/PeriphDrivers/Source/UART/uart_reva.c @@ -50,6 +50,7 @@ typedef struct { bool auto_dma_handlers; } uart_reva_req_state_t; +// clang-format off uart_reva_req_state_t states[MXC_UART_INSTANCES] = { [0 ... MXC_UART_INSTANCES - 1] = { .tx_req = NULL, @@ -59,6 +60,7 @@ uart_reva_req_state_t states[MXC_UART_INSTANCES] = { .auto_dma_handlers = false } }; +// clang-format on /* **** Function Prototypes **** */ diff --git a/Libraries/PeriphDrivers/Source/UART/uart_revb.c b/Libraries/PeriphDrivers/Source/UART/uart_revb.c index 74faa522fbb..ecdbeddeefa 100644 --- a/Libraries/PeriphDrivers/Source/UART/uart_revb.c +++ b/Libraries/PeriphDrivers/Source/UART/uart_revb.c @@ -48,6 +48,7 @@ typedef struct { bool auto_dma_handlers; } uart_revb_req_state_t; +// clang-format off uart_revb_req_state_t states[MXC_UART_INSTANCES] = { [0 ... MXC_UART_INSTANCES - 1] = { .tx_req = NULL, @@ -57,6 +58,7 @@ uart_revb_req_state_t states[MXC_UART_INSTANCES] = { .auto_dma_handlers = false } }; +// clang-format on /* **** Function Prototypes **** */