diff --git a/drivers/serial/uart_cc32xx.c b/drivers/serial/uart_cc32xx.c index 84daf6daf4e..89810b4c1fc 100644 --- a/drivers/serial/uart_cc32xx.c +++ b/drivers/serial/uart_cc32xx.c @@ -17,6 +17,14 @@ #include #include +struct uart_cc32xx_dev_config { + unsigned long base; + uint32_t sys_clk_freq; +#ifdef CONFIG_UART_INTERRUPT_DRIVEN + uart_irq_config_func_t irq_config_func; +#endif +}; + struct uart_cc32xx_dev_data_t { uint32_t prcm; uint32_t baud_rate; @@ -42,7 +50,7 @@ static void uart_cc32xx_isr(const struct device *dev); */ static int uart_cc32xx_init(const struct device *dev) { - const struct uart_device_config *config = dev->config; + const struct uart_cc32xx_dev_config *config = dev->config; const struct uart_cc32xx_dev_data_t *data = dev->data; MAP_PRCMPeripheralClkEnable(data->prcm, @@ -51,19 +59,18 @@ static int uart_cc32xx_init(const struct device *dev) MAP_PRCMPeripheralReset(data->prcm); /* This also calls MAP_UARTEnable() to enable the FIFOs: */ - MAP_UARTConfigSetExpClk((unsigned long)config->base, + MAP_UARTConfigSetExpClk(config->base, MAP_PRCMPeripheralClockGet(data->prcm), data->baud_rate, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); - MAP_UARTFlowControlSet((unsigned long)config->base, - UART_FLOWCONTROL_NONE); + MAP_UARTFlowControlSet(config->base, UART_FLOWCONTROL_NONE); /* Re-disable the FIFOs: */ - MAP_UARTFIFODisable((unsigned long)config->base); + MAP_UARTFIFODisable(config->base); #ifdef CONFIG_UART_INTERRUPT_DRIVEN /* Clear any pending UART RX interrupts: */ - MAP_UARTIntClear((unsigned long)config->base, UART_INT_RX); + MAP_UARTIntClear(config->base, UART_INT_RX); config->irq_config_func(dev); @@ -71,17 +78,17 @@ static int uart_cc32xx_init(const struct device *dev) * with first tx fifo empty interrupt when they first call * uart_irq_tx_enable(). */ - MAP_UARTCharPutNonBlocking((unsigned long)config->base, PRIME_CHAR); + MAP_UARTCharPutNonBlocking(config->base, PRIME_CHAR); #endif return 0; } static int uart_cc32xx_poll_in(const struct device *dev, unsigned char *c) { - const struct uart_device_config *config = dev->config; + const struct uart_cc32xx_dev_config *config = dev->config; - if (MAP_UARTCharsAvail((unsigned long)config->base)) { - *c = MAP_UARTCharGetNonBlocking((unsigned long)config->base); + if (MAP_UARTCharsAvail(config->base)) { + *c = MAP_UARTCharGetNonBlocking(config->base); } else { return (-1); } @@ -90,18 +97,18 @@ static int uart_cc32xx_poll_in(const struct device *dev, unsigned char *c) static void uart_cc32xx_poll_out(const struct device *dev, unsigned char c) { - const struct uart_device_config *config = dev->config; + const struct uart_cc32xx_dev_config *config = dev->config; - MAP_UARTCharPut((unsigned long)config->base, c); + MAP_UARTCharPut(config->base, c); } static int uart_cc32xx_err_check(const struct device *dev) { - const struct uart_device_config *config = dev->config; + const struct uart_cc32xx_dev_config *config = dev->config; unsigned long cc32xx_errs = 0L; unsigned int z_err = 0U; - cc32xx_errs = MAP_UARTRxErrorGet((unsigned long)config->base); + cc32xx_errs = MAP_UARTRxErrorGet(config->base); /* Map cc32xx SDK uart.h defines to zephyr uart.h defines */ z_err = ((cc32xx_errs & UART_RXERROR_OVERRUN) ? @@ -110,7 +117,7 @@ static int uart_cc32xx_err_check(const struct device *dev) ((cc32xx_errs & UART_RXERROR_PARITY) ? UART_ERROR_PARITY : 0) | ((cc32xx_errs & UART_RXERROR_FRAMING) ? UART_ERROR_FRAMING : 0); - MAP_UARTRxErrorClear((unsigned long)config->base); + MAP_UARTRxErrorClear(config->base); return (int)z_err; } @@ -121,13 +128,12 @@ static int uart_cc32xx_fifo_fill(const struct device *dev, const uint8_t *tx_data, int size) { - const struct uart_device_config *config = dev->config; + const struct uart_cc32xx_dev_config *config = dev->config; unsigned int num_tx = 0U; while ((size - num_tx) > 0) { /* Send a character */ - if (MAP_UARTCharPutNonBlocking((unsigned long)config->base, - tx_data[num_tx])) { + if (MAP_UARTCharPutNonBlocking(config->base, tx_data[num_tx])) { num_tx++; } else { break; @@ -140,15 +146,15 @@ static int uart_cc32xx_fifo_fill(const struct device *dev, static int uart_cc32xx_fifo_read(const struct device *dev, uint8_t *rx_data, const int size) { - const struct uart_device_config *config = dev->config; + const struct uart_cc32xx_dev_config *config = dev->config; unsigned int num_rx = 0U; while (((size - num_rx) > 0) && - MAP_UARTCharsAvail((unsigned long)config->base)) { + MAP_UARTCharsAvail(config->base)) { /* Receive a character */ rx_data[num_rx++] = - MAP_UARTCharGetNonBlocking((unsigned long)config->base); + MAP_UARTCharGetNonBlocking(config->base); } return num_rx; @@ -156,56 +162,56 @@ static int uart_cc32xx_fifo_read(const struct device *dev, uint8_t *rx_data, static void uart_cc32xx_irq_tx_enable(const struct device *dev) { - const struct uart_device_config *config = dev->config; + const struct uart_cc32xx_dev_config *config = dev->config; - MAP_UARTIntEnable((unsigned long)config->base, UART_INT_TX); + MAP_UARTIntEnable(config->base, UART_INT_TX); } static void uart_cc32xx_irq_tx_disable(const struct device *dev) { - const struct uart_device_config *config = dev->config; + const struct uart_cc32xx_dev_config *config = dev->config; - MAP_UARTIntDisable((unsigned long)config->base, UART_INT_TX); + MAP_UARTIntDisable(config->base, UART_INT_TX); } static int uart_cc32xx_irq_tx_ready(const struct device *dev) { - const struct uart_device_config *config = dev->config; + const struct uart_cc32xx_dev_config *config = dev->config; unsigned int int_status; - int_status = MAP_UARTIntStatus((unsigned long)config->base, 1); + int_status = MAP_UARTIntStatus(config->base, 1); return (int_status & UART_INT_TX); } static void uart_cc32xx_irq_rx_enable(const struct device *dev) { - const struct uart_device_config *config = dev->config; + const struct uart_cc32xx_dev_config *config = dev->config; /* FIFOs are left disabled from reset, so UART_INT_RT flag not used. */ - MAP_UARTIntEnable((unsigned long)config->base, UART_INT_RX); + MAP_UARTIntEnable(config->base, UART_INT_RX); } static void uart_cc32xx_irq_rx_disable(const struct device *dev) { - const struct uart_device_config *config = dev->config; + const struct uart_cc32xx_dev_config *config = dev->config; - MAP_UARTIntDisable((unsigned long)config->base, UART_INT_RX); + MAP_UARTIntDisable(config->base, UART_INT_RX); } static int uart_cc32xx_irq_tx_complete(const struct device *dev) { - const struct uart_device_config *config = dev->config; + const struct uart_cc32xx_dev_config *config = dev->config; - return (!MAP_UARTBusy((unsigned long)config->base)); + return (!MAP_UARTBusy(config->base)); } static int uart_cc32xx_irq_rx_ready(const struct device *dev) { - const struct uart_device_config *config = dev->config; + const struct uart_cc32xx_dev_config *config = dev->config; unsigned int int_status; - int_status = MAP_UARTIntStatus((unsigned long)config->base, 1); + int_status = MAP_UARTIntStatus(config->base, 1); return (int_status & UART_INT_RX); } @@ -222,10 +228,10 @@ static void uart_cc32xx_irq_err_disable(const struct device *dev) static int uart_cc32xx_irq_is_pending(const struct device *dev) { - const struct uart_device_config *config = dev->config; + const struct uart_cc32xx_dev_config *config = dev->config; unsigned int int_status; - int_status = MAP_UARTIntStatus((unsigned long)config->base, 1); + int_status = MAP_UARTIntStatus(config->base, 1); return (int_status & (UART_INT_TX | UART_INT_RX)); } @@ -257,11 +263,10 @@ static void uart_cc32xx_irq_callback_set(const struct device *dev, */ static void uart_cc32xx_isr(const struct device *dev) { - const struct uart_device_config *config = dev->config; + const struct uart_cc32xx_dev_config *config = dev->config; struct uart_cc32xx_dev_data_t * const dev_data = dev->data; - unsigned long intStatus = MAP_UARTIntStatus((unsigned long)config->base, - 1); + unsigned long intStatus = MAP_UARTIntStatus(config->base, 1); if (dev_data->cb) { dev_data->cb(dev, dev_data->cb_data); @@ -271,7 +276,7 @@ static void uart_cc32xx_isr(const struct device *dev) * clients calling uart_fifo_read() or uart_fifo_write(). * Still, clear any error interrupts here, as they're not yet handled. */ - MAP_UARTIntClear((unsigned long)config->base, + MAP_UARTIntClear(config->base, intStatus & ~(UART_INT_RX | UART_INT_TX)); } #endif /* CONFIG_UART_INTERRUPT_DRIVEN */ @@ -310,8 +315,8 @@ IF_ENABLED(CONFIG_UART_INTERRUPT_DRIVEN, \ irq_enable(DT_INST_IRQN(idx))) \ ); \ })); \ -static const struct uart_device_config uart_cc32xx_dev_cfg_##idx = { \ - .base = (void *)DT_INST_REG_ADDR(idx), \ +static const struct uart_cc32xx_dev_config uart_cc32xx_dev_cfg_##idx = { \ + .base = DT_INST_REG_ADDR(idx), \ .sys_clk_freq = DT_INST_PROP_BY_PHANDLE(idx, clocks, clock_frequency),\ IF_ENABLED(CONFIG_UART_INTERRUPT_DRIVEN, \ (.irq_config_func = uart_cc32xx_cfg_func_##idx,)) \