drivers: serial: cc32xx: drop usage of uart_device_config
Create a driver specific configuration structure, containing the required fields only. Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
parent
1e6b251913
commit
c5ef13266a
1 changed files with 48 additions and 43 deletions
|
@ -17,6 +17,14 @@
|
||||||
#include <driverlib/prcm.h>
|
#include <driverlib/prcm.h>
|
||||||
#include <driverlib/uart.h>
|
#include <driverlib/uart.h>
|
||||||
|
|
||||||
|
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 {
|
struct uart_cc32xx_dev_data_t {
|
||||||
uint32_t prcm;
|
uint32_t prcm;
|
||||||
uint32_t baud_rate;
|
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)
|
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;
|
const struct uart_cc32xx_dev_data_t *data = dev->data;
|
||||||
|
|
||||||
MAP_PRCMPeripheralClkEnable(data->prcm,
|
MAP_PRCMPeripheralClkEnable(data->prcm,
|
||||||
|
@ -51,19 +59,18 @@ static int uart_cc32xx_init(const struct device *dev)
|
||||||
MAP_PRCMPeripheralReset(data->prcm);
|
MAP_PRCMPeripheralReset(data->prcm);
|
||||||
|
|
||||||
/* This also calls MAP_UARTEnable() to enable the FIFOs: */
|
/* This also calls MAP_UARTEnable() to enable the FIFOs: */
|
||||||
MAP_UARTConfigSetExpClk((unsigned long)config->base,
|
MAP_UARTConfigSetExpClk(config->base,
|
||||||
MAP_PRCMPeripheralClockGet(data->prcm),
|
MAP_PRCMPeripheralClockGet(data->prcm),
|
||||||
data->baud_rate,
|
data->baud_rate,
|
||||||
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE
|
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE
|
||||||
| UART_CONFIG_PAR_NONE));
|
| UART_CONFIG_PAR_NONE));
|
||||||
MAP_UARTFlowControlSet((unsigned long)config->base,
|
MAP_UARTFlowControlSet(config->base, UART_FLOWCONTROL_NONE);
|
||||||
UART_FLOWCONTROL_NONE);
|
|
||||||
/* Re-disable the FIFOs: */
|
/* Re-disable the FIFOs: */
|
||||||
MAP_UARTFIFODisable((unsigned long)config->base);
|
MAP_UARTFIFODisable(config->base);
|
||||||
|
|
||||||
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
||||||
/* Clear any pending UART RX interrupts: */
|
/* 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);
|
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
|
* with first tx fifo empty interrupt when they first call
|
||||||
* uart_irq_tx_enable().
|
* uart_irq_tx_enable().
|
||||||
*/
|
*/
|
||||||
MAP_UARTCharPutNonBlocking((unsigned long)config->base, PRIME_CHAR);
|
MAP_UARTCharPutNonBlocking(config->base, PRIME_CHAR);
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int uart_cc32xx_poll_in(const struct device *dev, unsigned char *c)
|
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)) {
|
if (MAP_UARTCharsAvail(config->base)) {
|
||||||
*c = MAP_UARTCharGetNonBlocking((unsigned long)config->base);
|
*c = MAP_UARTCharGetNonBlocking(config->base);
|
||||||
} else {
|
} else {
|
||||||
return (-1);
|
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)
|
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)
|
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 long cc32xx_errs = 0L;
|
||||||
unsigned int z_err = 0U;
|
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 */
|
/* Map cc32xx SDK uart.h defines to zephyr uart.h defines */
|
||||||
z_err = ((cc32xx_errs & UART_RXERROR_OVERRUN) ?
|
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_PARITY) ? UART_ERROR_PARITY : 0) |
|
||||||
((cc32xx_errs & UART_RXERROR_FRAMING) ? UART_ERROR_FRAMING : 0);
|
((cc32xx_errs & UART_RXERROR_FRAMING) ? UART_ERROR_FRAMING : 0);
|
||||||
|
|
||||||
MAP_UARTRxErrorClear((unsigned long)config->base);
|
MAP_UARTRxErrorClear(config->base);
|
||||||
|
|
||||||
return (int)z_err;
|
return (int)z_err;
|
||||||
}
|
}
|
||||||
|
@ -121,13 +128,12 @@ static int uart_cc32xx_fifo_fill(const struct device *dev,
|
||||||
const uint8_t *tx_data,
|
const uint8_t *tx_data,
|
||||||
int size)
|
int size)
|
||||||
{
|
{
|
||||||
const struct uart_device_config *config = dev->config;
|
const struct uart_cc32xx_dev_config *config = dev->config;
|
||||||
unsigned int num_tx = 0U;
|
unsigned int num_tx = 0U;
|
||||||
|
|
||||||
while ((size - num_tx) > 0) {
|
while ((size - num_tx) > 0) {
|
||||||
/* Send a character */
|
/* Send a character */
|
||||||
if (MAP_UARTCharPutNonBlocking((unsigned long)config->base,
|
if (MAP_UARTCharPutNonBlocking(config->base, tx_data[num_tx])) {
|
||||||
tx_data[num_tx])) {
|
|
||||||
num_tx++;
|
num_tx++;
|
||||||
} else {
|
} else {
|
||||||
break;
|
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,
|
static int uart_cc32xx_fifo_read(const struct device *dev, uint8_t *rx_data,
|
||||||
const int size)
|
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;
|
unsigned int num_rx = 0U;
|
||||||
|
|
||||||
while (((size - num_rx) > 0) &&
|
while (((size - num_rx) > 0) &&
|
||||||
MAP_UARTCharsAvail((unsigned long)config->base)) {
|
MAP_UARTCharsAvail(config->base)) {
|
||||||
|
|
||||||
/* Receive a character */
|
/* Receive a character */
|
||||||
rx_data[num_rx++] =
|
rx_data[num_rx++] =
|
||||||
MAP_UARTCharGetNonBlocking((unsigned long)config->base);
|
MAP_UARTCharGetNonBlocking(config->base);
|
||||||
}
|
}
|
||||||
|
|
||||||
return num_rx;
|
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)
|
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)
|
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)
|
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;
|
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);
|
return (int_status & UART_INT_TX);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void uart_cc32xx_irq_rx_enable(const struct device *dev)
|
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. */
|
/* 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)
|
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)
|
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)
|
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;
|
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);
|
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)
|
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;
|
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));
|
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)
|
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;
|
struct uart_cc32xx_dev_data_t * const dev_data = dev->data;
|
||||||
|
|
||||||
unsigned long intStatus = MAP_UARTIntStatus((unsigned long)config->base,
|
unsigned long intStatus = MAP_UARTIntStatus(config->base, 1);
|
||||||
1);
|
|
||||||
|
|
||||||
if (dev_data->cb) {
|
if (dev_data->cb) {
|
||||||
dev_data->cb(dev, dev_data->cb_data);
|
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().
|
* clients calling uart_fifo_read() or uart_fifo_write().
|
||||||
* Still, clear any error interrupts here, as they're not yet handled.
|
* 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));
|
intStatus & ~(UART_INT_RX | UART_INT_TX));
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */
|
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */
|
||||||
|
@ -310,8 +315,8 @@ IF_ENABLED(CONFIG_UART_INTERRUPT_DRIVEN, \
|
||||||
irq_enable(DT_INST_IRQN(idx))) \
|
irq_enable(DT_INST_IRQN(idx))) \
|
||||||
); \
|
); \
|
||||||
})); \
|
})); \
|
||||||
static const struct uart_device_config uart_cc32xx_dev_cfg_##idx = { \
|
static const struct uart_cc32xx_dev_config uart_cc32xx_dev_cfg_##idx = { \
|
||||||
.base = (void *)DT_INST_REG_ADDR(idx), \
|
.base = DT_INST_REG_ADDR(idx), \
|
||||||
.sys_clk_freq = DT_INST_PROP_BY_PHANDLE(idx, clocks, clock_frequency),\
|
.sys_clk_freq = DT_INST_PROP_BY_PHANDLE(idx, clocks, clock_frequency),\
|
||||||
IF_ENABLED(CONFIG_UART_INTERRUPT_DRIVEN, \
|
IF_ENABLED(CONFIG_UART_INTERRUPT_DRIVEN, \
|
||||||
(.irq_config_func = uart_cc32xx_cfg_func_##idx,)) \
|
(.irq_config_func = uart_cc32xx_cfg_func_##idx,)) \
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue