drivers: serial: drop DEV_DATA/DEV_CFG usage

Stop using redundant DEV_DATA/DEV_CFG macros and use dev->data and
dev->config instead.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
Gerard Marull-Paretas 2022-01-18 16:58:32 +01:00 committed by Carles Cufí
parent e8c15f68b2
commit 1674fec5b6
26 changed files with 700 additions and 623 deletions

View file

@ -18,12 +18,9 @@
#define CLOCK_ID_PRFX(prefix, suffix) CLOCK_ID_PRFX2(prefix, suffix)
#define CLOCK_LEUART(id) CLOCK_ID_PRFX(LEUART_PREFIX, id)
#define DEV_CFG(dev) \
((const struct leuart_gecko_config * const)(dev)->config)
#define DEV_DATA(dev) \
((struct leuart_gecko_data * const)(dev)->data)
#define DEV_BASE(dev) \
((LEUART_TypeDef *)(DEV_CFG(dev))->base)
((LEUART_TypeDef *) \
((const struct leuart_gecko_config * const)(dev)->config)->base)
struct leuart_gecko_config {
LEUART_TypeDef *base;
@ -244,7 +241,7 @@ static void leuart_gecko_isr(const struct device *dev)
static void leuart_gecko_init_pins(const struct device *dev)
{
const struct leuart_gecko_config *config = DEV_CFG(dev);
const struct leuart_gecko_config *config = dev->config;
LEUART_TypeDef *base = DEV_BASE(dev);
soc_gpio_configure(&config->pin_rx);
@ -263,7 +260,7 @@ static void leuart_gecko_init_pins(const struct device *dev)
static int leuart_gecko_init(const struct device *dev)
{
const struct leuart_gecko_config *config = DEV_CFG(dev);
const struct leuart_gecko_config *config = dev->config;
LEUART_TypeDef *base = DEV_BASE(dev);
LEUART_Init_TypeDef leuartInit = LEUART_INIT_DEFAULT;

View file

@ -18,9 +18,6 @@
#define UART_ALTERA_JTAG_DATA_REG 0
#define UART_ALTERA_JTAG_CONTROL_REG 1
#define DEV_CFG(dev) \
((const struct uart_device_config * const)(dev)->config)
extern int altera_avalon_jtag_uart_read(altera_avalon_jtag_uart_state *sp,
char *buffer, int space, int flags);
extern int altera_avalon_jtag_uart_write(altera_avalon_jtag_uart_state *sp,
@ -32,7 +29,7 @@ static void uart_altera_jtag_poll_out(const struct device *dev,
const struct uart_device_config *config;
altera_avalon_jtag_uart_state ustate;
config = DEV_CFG(dev);
config = dev->config;
ustate.base = JTAG_UART_0_BASE;
altera_avalon_jtag_uart_write(&ustate, &c, 1, 0);

View file

@ -134,20 +134,17 @@ struct apbuart_dev_data {
#endif
};
#define DEV_CFG(dev) \
((const struct apbuart_dev_cfg *const)(dev)->config)
#define DEV_DATA(dev) \
((struct apbuart_dev_data *const)(dev)->data)
/*
* This routine waits for the TX holding register or TX FIFO to be ready and
* then it writes a character to the data register.
*/
static void apbuart_poll_out(const struct device *dev, unsigned char x)
{
volatile struct apbuart_regs *regs = (void *) DEV_CFG(dev)->regs;
const struct apbuart_dev_cfg *config = dev->config;
struct apbuart_dev_data *data = dev->data;
volatile struct apbuart_regs *regs = (void *) config->regs;
if (DEV_DATA(dev)->usefifo) {
if (data->usefifo) {
/* Transmitter FIFO full flag is available. */
while (regs->status & APBUART_STATUS_TF) {
;
@ -167,7 +164,8 @@ static void apbuart_poll_out(const struct device *dev, unsigned char x)
static int apbuart_poll_in(const struct device *dev, unsigned char *c)
{
volatile struct apbuart_regs *regs = (void *) DEV_CFG(dev)->regs;
const struct apbuart_dev_cfg *config = dev->config;
volatile struct apbuart_regs *regs = (void *) config->regs;
if ((regs->status & APBUART_STATUS_DR) == 0) {
return -1;
@ -179,7 +177,8 @@ static int apbuart_poll_in(const struct device *dev, unsigned char *c)
static int apbuart_err_check(const struct device *dev)
{
volatile struct apbuart_regs *regs = (void *) DEV_CFG(dev)->regs;
const struct apbuart_dev_cfg *config = dev->config;
volatile struct apbuart_regs *regs = (void *) config->regs;
const uint32_t status = regs->status;
int err = 0;
@ -233,7 +232,8 @@ static void set_baud(volatile struct apbuart_regs *const regs, uint32_t baud)
static int apbuart_configure(const struct device *dev,
const struct uart_config *cfg)
{
volatile struct apbuart_regs *regs = (void *) DEV_CFG(dev)->regs;
const struct apbuart_dev_cfg *config = dev->config;
volatile struct apbuart_regs *regs = (void *) config->regs;
uint32_t ctrl = 0;
uint32_t newctrl = 0;
@ -279,7 +279,8 @@ static int apbuart_configure(const struct device *dev,
static int apbuart_config_get(const struct device *dev, struct uart_config *cfg)
{
volatile struct apbuart_regs *regs = (void *) DEV_CFG(dev)->regs;
const struct apbuart_dev_cfg *config = dev->config;
volatile struct apbuart_regs *regs = (void *) config->regs;
const uint32_t ctrl = regs->ctrl;
cfg->parity = UART_CFG_PARITY_NONE;
@ -311,10 +312,12 @@ static void apbuart_isr(const struct device *dev);
static int apbuart_fifo_fill(const struct device *dev, const uint8_t *tx_data,
int size)
{
volatile struct apbuart_regs *regs = (void *) DEV_CFG(dev)->regs;
const struct apbuart_dev_cfg *config = dev->config;
struct apbuart_dev_data *data = dev->data;
volatile struct apbuart_regs *regs = (void *) config->regs;
int i;
if (DEV_DATA(dev)->usefifo) {
if (data->usefifo) {
/* Transmitter FIFO full flag is available. */
for (
i = 0;
@ -335,7 +338,8 @@ static int apbuart_fifo_fill(const struct device *dev, const uint8_t *tx_data,
static int apbuart_fifo_read(const struct device *dev, uint8_t *rx_data,
const int size)
{
volatile struct apbuart_regs *regs = (void *) DEV_CFG(dev)->regs;
const struct apbuart_dev_cfg *config = dev->config;
volatile struct apbuart_regs *regs = (void *) config->regs;
int i;
for (i = 0; (i < size) && (regs->status & APBUART_STATUS_DR); i++) {
@ -347,10 +351,12 @@ static int apbuart_fifo_read(const struct device *dev, uint8_t *rx_data,
static void apbuart_irq_tx_enable(const struct device *dev)
{
volatile struct apbuart_regs *regs = (void *) DEV_CFG(dev)->regs;
const struct apbuart_dev_cfg *config = dev->config;
struct apbuart_dev_data *data = dev->data;
volatile struct apbuart_regs *regs = (void *) config->regs;
unsigned int key;
if (DEV_DATA(dev)->usefifo) {
if (data->usefifo) {
/* Enable the FIFO level interrupt */
regs->ctrl |= APBUART_CTRL_TF;
return;
@ -375,16 +381,19 @@ static void apbuart_irq_tx_enable(const struct device *dev)
static void apbuart_irq_tx_disable(const struct device *dev)
{
volatile struct apbuart_regs *regs = (void *) DEV_CFG(dev)->regs;
const struct apbuart_dev_cfg *config = dev->config;
volatile struct apbuart_regs *regs = (void *) config->regs;
regs->ctrl &= ~(APBUART_CTRL_TF | APBUART_CTRL_TI);
}
static int apbuart_irq_tx_ready(const struct device *dev)
{
volatile struct apbuart_regs *regs = (void *) DEV_CFG(dev)->regs;
const struct apbuart_dev_cfg *config = dev->config;
struct apbuart_dev_data *data = dev->data;
volatile struct apbuart_regs *regs = (void *) config->regs;
if (DEV_DATA(dev)->usefifo) {
if (data->usefifo) {
return !(regs->status & APBUART_STATUS_TF);
}
return !!(regs->status & APBUART_STATUS_TE);
@ -392,35 +401,41 @@ static int apbuart_irq_tx_ready(const struct device *dev)
static int apbuart_irq_tx_complete(const struct device *dev)
{
volatile struct apbuart_regs *regs = (void *) DEV_CFG(dev)->regs;
const struct apbuart_dev_cfg *config = dev->config;
volatile struct apbuart_regs *regs = (void *) config->regs;
return !!(regs->status & APBUART_STATUS_TS);
}
static void apbuart_irq_rx_enable(const struct device *dev)
{
volatile struct apbuart_regs *regs = (void *) DEV_CFG(dev)->regs;
const struct apbuart_dev_cfg *config = dev->config;
volatile struct apbuart_regs *regs = (void *) config->regs;
regs->ctrl |= APBUART_CTRL_RI;
}
static void apbuart_irq_rx_disable(const struct device *dev)
{
volatile struct apbuart_regs *regs = (void *) DEV_CFG(dev)->regs;
const struct apbuart_dev_cfg *config = dev->config;
volatile struct apbuart_regs *regs = (void *) config->regs;
regs->ctrl &= ~APBUART_CTRL_RI;
}
static int apbuart_irq_rx_ready(const struct device *dev)
{
volatile struct apbuart_regs *regs = (void *) DEV_CFG(dev)->regs;
const struct apbuart_dev_cfg *config = dev->config;
volatile struct apbuart_regs *regs = (void *) config->regs;
return !!(regs->status & APBUART_STATUS_DR);
}
static int apbuart_irq_is_pending(const struct device *dev)
{
volatile struct apbuart_regs *regs = (void *) DEV_CFG(dev)->regs;
const struct apbuart_dev_cfg *config = dev->config;
struct apbuart_dev_data *data = dev->data;
volatile struct apbuart_regs *regs = (void *) config->regs;
uint32_t status = regs->status;
uint32_t ctrl = regs->ctrl;
@ -428,7 +443,7 @@ static int apbuart_irq_is_pending(const struct device *dev)
return 1;
}
if (DEV_DATA(dev)->usefifo) {
if (data->usefifo) {
/* TH is the TX FIFO half-empty flag */
if (status & APBUART_STATUS_TH) {
return 1;
@ -451,7 +466,7 @@ static void apbuart_irq_callback_set(const struct device *dev,
uart_irq_callback_user_data_t cb,
void *cb_data)
{
struct apbuart_dev_data *const dev_data = DEV_DATA(dev);
struct apbuart_dev_data *const dev_data = dev->data;
dev_data->cb = cb;
dev_data->cb_data = cb_data;
@ -459,7 +474,7 @@ static void apbuart_irq_callback_set(const struct device *dev,
static void apbuart_isr(const struct device *dev)
{
struct apbuart_dev_data *const dev_data = DEV_DATA(dev);
struct apbuart_dev_data *const dev_data = dev->data;
if (dev_data->cb) {
dev_data->cb(dev, dev_data->cb_data);
@ -469,13 +484,15 @@ static void apbuart_isr(const struct device *dev)
static int apbuart_init(const struct device *dev)
{
volatile struct apbuart_regs *regs = (void *) DEV_CFG(dev)->regs;
const struct apbuart_dev_cfg *config = dev->config;
struct apbuart_dev_data *data = dev->data;
volatile struct apbuart_regs *regs = (void *) config->regs;
const uint32_t APBUART_DEBUG_MASK = APBUART_CTRL_DB | APBUART_CTRL_FL;
uint32_t dm;
uint32_t ctrl;
ctrl = regs->ctrl;
DEV_DATA(dev)->usefifo = !!(ctrl & APBUART_CTRL_FA);
data->usefifo = !!(ctrl & APBUART_CTRL_FA);
/* NOTE: CTRL_FL has reset value 0. CTRL_DB has no reset value. */
dm = ctrl & APBUART_DEBUG_MASK;
if (dm == APBUART_DEBUG_MASK) {
@ -488,9 +505,9 @@ static int apbuart_init(const struct device *dev)
regs->status = 0;
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
irq_connect_dynamic(DEV_CFG(dev)->interrupt,
irq_connect_dynamic(config->interrupt,
0, (void (*)(const void *))apbuart_isr, dev, 0);
irq_enable(DEV_CFG(dev)->interrupt);
irq_enable(config->interrupt);
#endif
return 0;

View file

@ -20,12 +20,6 @@
#define GET_UART(dev) ((volatile struct uart_b91_t *) \
((const struct uart_b91_config *)dev->config)->uart_addr)
/* Get UART configuration */
#define GET_CFG(dev) ((const struct uart_b91_config *)dev->config)
/* Get instance data */
#define DEV_DATA(dev) ((struct uart_b91_data *const)dev->data)
/* UART TX buffer count max value */
#define UART_TX_BUF_CNT ((uint8_t)8u)
@ -236,7 +230,7 @@ static void uart_b91_irq_handler(const struct device *dev)
#ifndef CONFIG_UART_INTERRUPT_DRIVEN
ARG_UNUSED(dev);
#else
struct uart_b91_data *data = DEV_DATA(dev);
struct uart_b91_data *data = dev->data;
if (data->callback != NULL) {
data->callback(dev, data->cb_data);
@ -248,6 +242,7 @@ static void uart_b91_irq_handler(const struct device *dev)
static int uart_b91_configure(const struct device *dev,
const struct uart_config *cfg)
{
struct uart_b91_data *data = dev->data;
uint16_t divider;
uint8_t bwpc;
uint8_t parity;
@ -287,7 +282,7 @@ static int uart_b91_configure(const struct device *dev,
uart_b91_init(uart, divider, bwpc, parity, stop_bits);
/* save configuration */
DEV_DATA(dev)->cfg = *cfg;
data->cfg = *cfg;
return 0;
}
@ -296,7 +291,8 @@ static int uart_b91_configure(const struct device *dev,
static int uart_b91_config_get(const struct device *dev,
struct uart_config *cfg)
{
*cfg = DEV_DATA(dev)->cfg;
struct uart_b91_data *data = dev->data;
*cfg = data->cfg;
return 0;
}
@ -308,7 +304,7 @@ static int uart_b91_driver_init(const struct device *dev)
uint8_t bwpc = 0u;
const struct device *pinmux;
volatile struct uart_b91_t *uart = GET_UART(dev);
const struct uart_b91_config *cfg = GET_CFG(dev);
const struct uart_b91_config *cfg = dev->config;
pinmux = DEVICE_DT_GET(DT_NODELABEL(pinmux));
if (!device_is_ready(pinmux)) {
@ -334,7 +330,7 @@ static int uart_b91_driver_init(const struct device *dev)
static void uart_b91_poll_out(const struct device *dev, uint8_t c)
{
volatile struct uart_b91_t *uart = GET_UART(dev);
struct uart_b91_data *data = DEV_DATA(dev);
struct uart_b91_data *data = dev->data;
while (uart_b91_get_tx_bufcnt(uart) >= UART_TX_BUF_CNT) {
};
@ -347,7 +343,7 @@ static void uart_b91_poll_out(const struct device *dev, uint8_t c)
static int uart_b91_poll_in(const struct device *dev, unsigned char *c)
{
volatile struct uart_b91_t *uart = GET_UART(dev);
struct uart_b91_data *data = DEV_DATA(dev);
struct uart_b91_data *data = dev->data;
if (uart_b91_get_rx_bufcnt(uart) == 0) {
return -1;
@ -510,7 +506,7 @@ static void uart_b91_irq_callback_set(const struct device *dev,
uart_irq_callback_user_data_t cb,
void *cb_data)
{
struct uart_b91_data *data = DEV_DATA(dev);
struct uart_b91_data *data = dev->data;
data->callback = cb;
data->cb_data = cb_data;

View file

@ -26,11 +26,6 @@ struct uart_cc32xx_dev_data_t {
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */
};
#define DEV_CFG(dev) \
((const struct uart_device_config * const)(dev)->config)
#define DEV_DATA(dev) \
((struct uart_cc32xx_dev_data_t * const)(dev)->data)
#define PRIME_CHAR '\r'
/* Forward decls: */
@ -47,8 +42,8 @@ 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_CFG(dev);
const struct uart_cc32xx_dev_data_t *data = DEV_DATA(dev);
const struct uart_device_config *config = dev->config;
const struct uart_cc32xx_dev_data_t *data = dev->data;
MAP_PRCMPeripheralClkEnable(data->prcm,
PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK);
@ -83,7 +78,7 @@ static int uart_cc32xx_init(const struct device *dev)
static int uart_cc32xx_poll_in(const struct device *dev, unsigned char *c)
{
const struct uart_device_config *config = DEV_CFG(dev);
const struct uart_device_config *config = dev->config;
if (MAP_UARTCharsAvail((unsigned long)config->base)) {
*c = MAP_UARTCharGetNonBlocking((unsigned long)config->base);
@ -95,14 +90,14 @@ 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_CFG(dev);
const struct uart_device_config *config = dev->config;
MAP_UARTCharPut((unsigned long)config->base, c);
}
static int uart_cc32xx_err_check(const struct device *dev)
{
const struct uart_device_config *config = DEV_CFG(dev);
const struct uart_device_config *config = dev->config;
unsigned long cc32xx_errs = 0L;
unsigned int z_err = 0U;
@ -126,7 +121,7 @@ static int uart_cc32xx_fifo_fill(const struct device *dev,
const uint8_t *tx_data,
int size)
{
const struct uart_device_config *config = DEV_CFG(dev);
const struct uart_device_config *config = dev->config;
unsigned int num_tx = 0U;
while ((size - num_tx) > 0) {
@ -145,7 +140,7 @@ 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_CFG(dev);
const struct uart_device_config *config = dev->config;
unsigned int num_rx = 0U;
while (((size - num_rx) > 0) &&
@ -161,21 +156,21 @@ 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_CFG(dev);
const struct uart_device_config *config = dev->config;
MAP_UARTIntEnable((unsigned long)config->base, UART_INT_TX);
}
static void uart_cc32xx_irq_tx_disable(const struct device *dev)
{
const struct uart_device_config *config = DEV_CFG(dev);
const struct uart_device_config *config = dev->config;
MAP_UARTIntDisable((unsigned long)config->base, UART_INT_TX);
}
static int uart_cc32xx_irq_tx_ready(const struct device *dev)
{
const struct uart_device_config *config = DEV_CFG(dev);
const struct uart_device_config *config = dev->config;
unsigned int int_status;
int_status = MAP_UARTIntStatus((unsigned long)config->base, 1);
@ -185,7 +180,7 @@ static int uart_cc32xx_irq_tx_ready(const struct device *dev)
static void uart_cc32xx_irq_rx_enable(const struct device *dev)
{
const struct uart_device_config *config = DEV_CFG(dev);
const struct uart_device_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);
@ -193,21 +188,21 @@ static void uart_cc32xx_irq_rx_enable(const struct device *dev)
static void uart_cc32xx_irq_rx_disable(const struct device *dev)
{
const struct uart_device_config *config = DEV_CFG(dev);
const struct uart_device_config *config = dev->config;
MAP_UARTIntDisable((unsigned long)config->base, UART_INT_RX);
}
static int uart_cc32xx_irq_tx_complete(const struct device *dev)
{
const struct uart_device_config *config = DEV_CFG(dev);
const struct uart_device_config *config = dev->config;
return (!MAP_UARTBusy((unsigned long)config->base));
}
static int uart_cc32xx_irq_rx_ready(const struct device *dev)
{
const struct uart_device_config *config = DEV_CFG(dev);
const struct uart_device_config *config = dev->config;
unsigned int int_status;
int_status = MAP_UARTIntStatus((unsigned long)config->base, 1);
@ -227,7 +222,7 @@ 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_CFG(dev);
const struct uart_device_config *config = dev->config;
unsigned int int_status;
int_status = MAP_UARTIntStatus((unsigned long)config->base, 1);
@ -244,7 +239,7 @@ static void uart_cc32xx_irq_callback_set(const struct device *dev,
uart_irq_callback_user_data_t cb,
void *cb_data)
{
struct uart_cc32xx_dev_data_t * const dev_data = DEV_DATA(dev);
struct uart_cc32xx_dev_data_t * const dev_data = dev->data;
dev_data->cb = cb;
dev_data->cb_data = cb_data;
@ -262,8 +257,8 @@ 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_CFG(dev);
struct uart_cc32xx_dev_data_t * const dev_data = DEV_DATA(dev);
const struct uart_device_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);

View file

@ -75,13 +75,9 @@ struct uart_cmsdk_apb_dev_data {
const struct arm_clock_control_t uart_cc_dss;
};
/* convenience defines */
#define DEV_CFG(dev) \
((const struct uart_device_config * const)(dev)->config)
#define DEV_DATA(dev) \
((struct uart_cmsdk_apb_dev_data * const)(dev)->data)
#define UART_STRUCT(dev) \
((volatile struct uart_cmsdk_apb *)(DEV_CFG(dev))->base)
((volatile struct uart_cmsdk_apb *) \
((const struct uart_device_config * const)(dev)->config)->base)
static const struct uart_driver_api uart_cmsdk_apb_driver_api;
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
@ -98,8 +94,8 @@ static void uart_cmsdk_apb_isr(const struct device *dev);
static void baudrate_set(const struct device *dev)
{
volatile struct uart_cmsdk_apb *uart = UART_STRUCT(dev);
const struct uart_device_config * const dev_cfg = DEV_CFG(dev);
struct uart_cmsdk_apb_dev_data *const dev_data = DEV_DATA(dev);
const struct uart_device_config * const dev_cfg = dev->config;
struct uart_cmsdk_apb_dev_data *const dev_data = dev->data;
/*
* If baudrate and/or sys_clk_freq are 0 the configuration remains
* unchanged. It can be useful in case that Zephyr it is run via
@ -125,7 +121,7 @@ static int uart_cmsdk_apb_init(const struct device *dev)
{
volatile struct uart_cmsdk_apb *uart = UART_STRUCT(dev);
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
const struct uart_device_config * const dev_cfg = DEV_CFG(dev);
const struct uart_device_config * const dev_cfg = dev->config;
#endif
#ifdef CONFIG_CLOCK_CONTROL
@ -133,7 +129,7 @@ static int uart_cmsdk_apb_init(const struct device *dev)
const struct device *clk =
device_get_binding(CONFIG_ARM_CLOCK_CONTROL_DEV_NAME);
struct uart_cmsdk_apb_dev_data * const data = DEV_DATA(dev);
struct uart_cmsdk_apb_dev_data * const data = dev->data;
#ifdef CONFIG_SOC_SERIES_BEETLE
clock_control_on(clk, (clock_control_subsys_t *) &data->uart_cc_as);
@ -416,8 +412,10 @@ static void uart_cmsdk_apb_irq_callback_set(const struct device *dev,
uart_irq_callback_user_data_t cb,
void *cb_data)
{
DEV_DATA(dev)->irq_cb = cb;
DEV_DATA(dev)->irq_cb_data = cb_data;
struct uart_cmsdk_apb_dev_data *data = dev->data;
data->irq_cb = cb;
data->irq_cb_data = cb_data;
}
/**
@ -429,7 +427,7 @@ static void uart_cmsdk_apb_irq_callback_set(const struct device *dev,
*/
void uart_cmsdk_apb_isr(const struct device *dev)
{
struct uart_cmsdk_apb_dev_data *data = DEV_DATA(dev);
struct uart_cmsdk_apb_dev_data *data = dev->data;
/* Verify if the callback has been registered */
if (data->irq_cb) {

View file

@ -80,11 +80,6 @@ struct uart_esp32_data {
int irq_line;
};
#define DEV_CFG(dev) \
((struct uart_esp32_config *const)(dev)->config)
#define DEV_DATA(dev) \
((struct uart_esp32_data *)(dev)->data)
#define UART_FIFO_LIMIT (UART_LL_FIFO_DEF_LEN)
#define UART_TX_FIFO_THRESH 0x1
#define UART_RX_FIFO_THRESH 0x16
@ -96,33 +91,36 @@ static void uart_esp32_isr(void *arg);
static int uart_esp32_poll_in(const struct device *dev, unsigned char *p_char)
{
const struct uart_esp32_config *config = dev->config;
int inout_rd_len = 1;
if (uart_hal_get_rxfifo_len(&DEV_CFG(dev)->hal) == 0) {
if (uart_hal_get_rxfifo_len(&config->hal) == 0) {
return -1;
}
uart_hal_read_rxfifo(&DEV_CFG(dev)->hal, p_char, &inout_rd_len);
uart_hal_read_rxfifo(&config->hal, p_char, &inout_rd_len);
return 0;
}
static void uart_esp32_poll_out(const struct device *dev, unsigned char c)
{
const struct uart_esp32_config *config = dev->config;
uint32_t written;
/* Wait for space in FIFO */
while (uart_hal_get_txfifo_len(&DEV_CFG(dev)->hal) == 0) {
while (uart_hal_get_txfifo_len(&config->hal) == 0) {
; /* Wait */
}
/* Send a character */
uart_hal_write_txfifo(&DEV_CFG(dev)->hal, &c, 1, &written);
uart_hal_write_txfifo(&config->hal, &c, 1, &written);
}
static int uart_esp32_err_check(const struct device *dev)
{
uint32_t mask = uart_hal_get_intsts_mask(&DEV_CFG(dev)->hal);
const struct uart_esp32_config *config = dev->config;
uint32_t mask = uart_hal_get_intsts_mask(&config->hal);
uint32_t err = mask & (UART_INTR_PARITY_ERR | UART_INTR_FRAM_ERR);
return err;
@ -132,14 +130,15 @@ static int uart_esp32_err_check(const struct device *dev)
static int uart_esp32_config_get(const struct device *dev,
struct uart_config *cfg)
{
const struct uart_esp32_config *config = dev->config;
uart_parity_t parity;
uart_stop_bits_t stop_bit;
uart_word_length_t data_bit;
uart_hw_flowcontrol_t hw_flow;
uart_hal_get_baudrate(&DEV_CFG(dev)->hal, &cfg->baudrate);
uart_hal_get_baudrate(&config->hal, &cfg->baudrate);
uart_hal_get_parity(&DEV_CFG(dev)->hal, &parity);
uart_hal_get_parity(&config->hal, &parity);
switch (parity) {
case UART_PARITY_DISABLE:
cfg->parity = UART_CFG_PARITY_NONE;
@ -154,7 +153,7 @@ static int uart_esp32_config_get(const struct device *dev,
return -ENOTSUP;
}
uart_hal_get_stop_bits(&DEV_CFG(dev)->hal, &stop_bit);
uart_hal_get_stop_bits(&config->hal, &stop_bit);
switch (stop_bit) {
case UART_STOP_BITS_1:
cfg->stop_bits = UART_CFG_STOP_BITS_1;
@ -169,7 +168,7 @@ static int uart_esp32_config_get(const struct device *dev,
return -ENOTSUP;
}
uart_hal_get_data_bit_num(&DEV_CFG(dev)->hal, &data_bit);
uart_hal_get_data_bit_num(&config->hal, &data_bit);
switch (data_bit) {
case UART_DATA_5_BITS:
cfg->data_bits = UART_CFG_DATA_BITS_5;
@ -187,7 +186,7 @@ static int uart_esp32_config_get(const struct device *dev,
return -ENOTSUP;
}
uart_hal_get_hw_flow_ctrl(&DEV_CFG(dev)->hal, &hw_flow);
uart_hal_get_hw_flow_ctrl(&config->hal, &hw_flow);
switch (hw_flow) {
case UART_HW_FLOWCTRL_DISABLE:
cfg->flow_ctrl = UART_CFG_FLOW_CTRL_NONE;
@ -205,7 +204,7 @@ static int uart_esp32_config_get(const struct device *dev,
static int uart_esp32_configure_pins(const struct device *dev, const struct uart_config *uart)
{
const struct uart_esp32_config *const cfg = DEV_CFG(dev);
const struct uart_esp32_config *const cfg = dev->config;
do {
if (cfg->tx.gpio_name == NULL || cfg->rx.gpio_name == NULL)
@ -257,28 +256,29 @@ static int uart_esp32_configure_pins(const struct device *dev, const struct uart
static int uart_esp32_configure(const struct device *dev, const struct uart_config *cfg)
{
const struct uart_esp32_config *config = dev->config;
int ret = uart_esp32_configure_pins(dev, cfg);
if (ret < 0) {
return ret;
}
clock_control_on(DEV_CFG(dev)->clock_dev, DEV_CFG(dev)->clock_subsys);
clock_control_on(config->clock_dev, config->clock_subsys);
uart_hal_set_sclk(&DEV_CFG(dev)->hal, UART_SCLK_APB);
uart_hal_set_rxfifo_full_thr(&DEV_CFG(dev)->hal, UART_RX_FIFO_THRESH);
uart_hal_set_txfifo_empty_thr(&DEV_CFG(dev)->hal, UART_TX_FIFO_THRESH);
uart_hal_rxfifo_rst(&DEV_CFG(dev)->hal);
uart_hal_set_sclk(&config->hal, UART_SCLK_APB);
uart_hal_set_rxfifo_full_thr(&config->hal, UART_RX_FIFO_THRESH);
uart_hal_set_txfifo_empty_thr(&config->hal, UART_TX_FIFO_THRESH);
uart_hal_rxfifo_rst(&config->hal);
switch (cfg->parity) {
case UART_CFG_PARITY_NONE:
uart_hal_set_parity(&DEV_CFG(dev)->hal, UART_PARITY_DISABLE);
uart_hal_set_parity(&config->hal, UART_PARITY_DISABLE);
break;
case UART_CFG_PARITY_EVEN:
uart_hal_set_parity(&DEV_CFG(dev)->hal, UART_PARITY_EVEN);
uart_hal_set_parity(&config->hal, UART_PARITY_EVEN);
break;
case UART_CFG_PARITY_ODD:
uart_hal_set_parity(&DEV_CFG(dev)->hal, UART_PARITY_ODD);
uart_hal_set_parity(&config->hal, UART_PARITY_ODD);
break;
default:
return -ENOTSUP;
@ -286,13 +286,13 @@ static int uart_esp32_configure(const struct device *dev, const struct uart_conf
switch (cfg->stop_bits) {
case UART_CFG_STOP_BITS_1:
uart_hal_set_stop_bits(&DEV_CFG(dev)->hal, UART_STOP_BITS_1);
uart_hal_set_stop_bits(&config->hal, UART_STOP_BITS_1);
break;
case UART_CFG_STOP_BITS_1_5:
uart_hal_set_stop_bits(&DEV_CFG(dev)->hal, UART_STOP_BITS_1_5);
uart_hal_set_stop_bits(&config->hal, UART_STOP_BITS_1_5);
break;
case UART_CFG_STOP_BITS_2:
uart_hal_set_stop_bits(&DEV_CFG(dev)->hal, UART_STOP_BITS_2);
uart_hal_set_stop_bits(&config->hal, UART_STOP_BITS_2);
break;
default:
return -ENOTSUP;
@ -300,16 +300,16 @@ static int uart_esp32_configure(const struct device *dev, const struct uart_conf
switch (cfg->data_bits) {
case UART_CFG_DATA_BITS_5:
uart_hal_set_data_bit_num(&DEV_CFG(dev)->hal, UART_DATA_5_BITS);
uart_hal_set_data_bit_num(&config->hal, UART_DATA_5_BITS);
break;
case UART_CFG_DATA_BITS_6:
uart_hal_set_data_bit_num(&DEV_CFG(dev)->hal, UART_DATA_6_BITS);
uart_hal_set_data_bit_num(&config->hal, UART_DATA_6_BITS);
break;
case UART_CFG_DATA_BITS_7:
uart_hal_set_data_bit_num(&DEV_CFG(dev)->hal, UART_DATA_7_BITS);
uart_hal_set_data_bit_num(&config->hal, UART_DATA_7_BITS);
break;
case UART_CFG_DATA_BITS_8:
uart_hal_set_data_bit_num(&DEV_CFG(dev)->hal, UART_DATA_8_BITS);
uart_hal_set_data_bit_num(&config->hal, UART_DATA_8_BITS);
break;
default:
return -ENOTSUP;
@ -317,29 +317,32 @@ static int uart_esp32_configure(const struct device *dev, const struct uart_conf
switch (cfg->flow_ctrl) {
case UART_CFG_FLOW_CTRL_NONE:
uart_hal_set_hw_flow_ctrl(&DEV_CFG(dev)->hal, UART_HW_FLOWCTRL_DISABLE, 0);
uart_hal_set_hw_flow_ctrl(&config->hal, UART_HW_FLOWCTRL_DISABLE, 0);
break;
case UART_CFG_FLOW_CTRL_RTS_CTS:
uart_hal_set_hw_flow_ctrl(&DEV_CFG(dev)->hal, UART_HW_FLOWCTRL_CTS_RTS, 10);
uart_hal_set_hw_flow_ctrl(&config->hal, UART_HW_FLOWCTRL_CTS_RTS, 10);
break;
default:
return -ENOTSUP;
}
uart_hal_set_baudrate(&DEV_CFG(dev)->hal, cfg->baudrate);
uart_hal_set_baudrate(&config->hal, cfg->baudrate);
uart_hal_set_rx_timeout(&DEV_CFG(dev)->hal, 0x16);
uart_hal_set_rx_timeout(&config->hal, 0x16);
return 0;
}
static int uart_esp32_init(const struct device *dev)
{
int ret = uart_esp32_configure(dev, &DEV_DATA(dev)->uart_config);
struct uart_esp32_data *data = dev->data;
int ret = uart_esp32_configure(dev, &data->uart_config);
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
DEV_DATA(dev)->irq_line =
esp_intr_alloc(DEV_CFG(dev)->irq_source,
const struct uart_esp32_config *config = dev->config;
data->irq_line =
esp_intr_alloc(config->irq_source,
0,
(ISR_HANDLER)uart_esp32_isr,
(void *)dev,
@ -354,82 +357,102 @@ static int uart_esp32_init(const struct device *dev)
static int uart_esp32_fifo_fill(const struct device *dev,
const uint8_t *tx_data, int len)
{
const struct uart_esp32_config *config = dev->config;
uint32_t written = 0;
if (len < 0) {
return 0;
}
uart_hal_write_txfifo(&DEV_CFG(dev)->hal, tx_data, len, &written);
uart_hal_write_txfifo(&config->hal, tx_data, len, &written);
return written;
}
static int uart_esp32_fifo_read(const struct device *dev,
uint8_t *rx_data, const int len)
{
const int num_rx = uart_hal_get_rxfifo_len(&DEV_CFG(dev)->hal);
const struct uart_esp32_config *config = dev->config;
const int num_rx = uart_hal_get_rxfifo_len(&config->hal);
int read = MIN(len, num_rx);
if (!read) {
return 0;
}
uart_hal_read_rxfifo(&DEV_CFG(dev)->hal, rx_data, &read);
uart_hal_read_rxfifo(&config->hal, rx_data, &read);
return read;
}
static void uart_esp32_irq_tx_enable(const struct device *dev)
{
uart_hal_clr_intsts_mask(&DEV_CFG(dev)->hal, UART_INTR_TXFIFO_EMPTY);
uart_hal_ena_intr_mask(&DEV_CFG(dev)->hal, UART_INTR_TXFIFO_EMPTY);
const struct uart_esp32_config *config = dev->config;
uart_hal_clr_intsts_mask(&config->hal, UART_INTR_TXFIFO_EMPTY);
uart_hal_ena_intr_mask(&config->hal, UART_INTR_TXFIFO_EMPTY);
}
static void uart_esp32_irq_tx_disable(const struct device *dev)
{
uart_hal_disable_intr_mask(&DEV_CFG(dev)->hal, UART_INTR_TXFIFO_EMPTY);
const struct uart_esp32_config *config = dev->config;
uart_hal_disable_intr_mask(&config->hal, UART_INTR_TXFIFO_EMPTY);
}
static int uart_esp32_irq_tx_ready(const struct device *dev)
{
return (uart_hal_get_txfifo_len(&DEV_CFG(dev)->hal) > 0 &&
uart_hal_get_intr_ena_status(&DEV_CFG(dev)->hal) & UART_INTR_TXFIFO_EMPTY);
const struct uart_esp32_config *config = dev->config;
return (uart_hal_get_txfifo_len(&config->hal) > 0 &&
uart_hal_get_intr_ena_status(&config->hal) & UART_INTR_TXFIFO_EMPTY);
}
static void uart_esp32_irq_rx_enable(const struct device *dev)
{
uart_hal_clr_intsts_mask(&DEV_CFG(dev)->hal, UART_INTR_RXFIFO_FULL);
uart_hal_clr_intsts_mask(&DEV_CFG(dev)->hal, UART_INTR_RXFIFO_TOUT);
uart_hal_ena_intr_mask(&DEV_CFG(dev)->hal, UART_INTR_RXFIFO_FULL);
uart_hal_ena_intr_mask(&DEV_CFG(dev)->hal, UART_INTR_RXFIFO_TOUT);
const struct uart_esp32_config *config = dev->config;
uart_hal_clr_intsts_mask(&config->hal, UART_INTR_RXFIFO_FULL);
uart_hal_clr_intsts_mask(&config->hal, UART_INTR_RXFIFO_TOUT);
uart_hal_ena_intr_mask(&config->hal, UART_INTR_RXFIFO_FULL);
uart_hal_ena_intr_mask(&config->hal, UART_INTR_RXFIFO_TOUT);
}
static void uart_esp32_irq_rx_disable(const struct device *dev)
{
uart_hal_disable_intr_mask(&DEV_CFG(dev)->hal, UART_INTR_RXFIFO_FULL);
uart_hal_disable_intr_mask(&DEV_CFG(dev)->hal, UART_INTR_RXFIFO_TOUT);
const struct uart_esp32_config *config = dev->config;
uart_hal_disable_intr_mask(&config->hal, UART_INTR_RXFIFO_FULL);
uart_hal_disable_intr_mask(&config->hal, UART_INTR_RXFIFO_TOUT);
}
static int uart_esp32_irq_tx_complete(const struct device *dev)
{
return uart_hal_is_tx_idle(&DEV_CFG(dev)->hal);
const struct uart_esp32_config *config = dev->config;
return uart_hal_is_tx_idle(&config->hal);
}
static int uart_esp32_irq_rx_ready(const struct device *dev)
{
return (uart_hal_get_rxfifo_len(&DEV_CFG(dev)->hal) > 0);
const struct uart_esp32_config *config = dev->config;
return (uart_hal_get_rxfifo_len(&config->hal) > 0);
}
static void uart_esp32_irq_err_enable(const struct device *dev)
{
const struct uart_esp32_config *config = dev->config;
/* enable framing, parity */
uart_hal_ena_intr_mask(&DEV_CFG(dev)->hal, UART_INTR_FRAM_ERR);
uart_hal_ena_intr_mask(&DEV_CFG(dev)->hal, UART_INTR_PARITY_ERR);
uart_hal_ena_intr_mask(&config->hal, UART_INTR_FRAM_ERR);
uart_hal_ena_intr_mask(&config->hal, UART_INTR_PARITY_ERR);
}
static void uart_esp32_irq_err_disable(const struct device *dev)
{
uart_hal_disable_intr_mask(&DEV_CFG(dev)->hal, UART_INTR_FRAM_ERR);
uart_hal_disable_intr_mask(&DEV_CFG(dev)->hal, UART_INTR_PARITY_ERR);
const struct uart_esp32_config *config = dev->config;
uart_hal_disable_intr_mask(&config->hal, UART_INTR_FRAM_ERR);
uart_hal_disable_intr_mask(&config->hal, UART_INTR_PARITY_ERR);
}
static int uart_esp32_irq_is_pending(const struct device *dev)
@ -439,9 +462,11 @@ static int uart_esp32_irq_is_pending(const struct device *dev)
static int uart_esp32_irq_update(const struct device *dev)
{
uart_hal_clr_intsts_mask(&DEV_CFG(dev)->hal, UART_INTR_RXFIFO_FULL);
uart_hal_clr_intsts_mask(&DEV_CFG(dev)->hal, UART_INTR_RXFIFO_TOUT);
uart_hal_clr_intsts_mask(&DEV_CFG(dev)->hal, UART_INTR_TXFIFO_EMPTY);
const struct uart_esp32_config *config = dev->config;
uart_hal_clr_intsts_mask(&config->hal, UART_INTR_RXFIFO_FULL);
uart_hal_clr_intsts_mask(&config->hal, UART_INTR_RXFIFO_TOUT);
uart_hal_clr_intsts_mask(&config->hal, UART_INTR_TXFIFO_EMPTY);
return 1;
}
@ -450,20 +475,23 @@ static void uart_esp32_irq_callback_set(const struct device *dev,
uart_irq_callback_user_data_t cb,
void *cb_data)
{
DEV_DATA(dev)->irq_cb = cb;
DEV_DATA(dev)->irq_cb_data = cb_data;
struct uart_esp32_data *data = dev->data;
data->irq_cb = cb;
data->irq_cb_data = cb_data;
}
static void uart_esp32_isr(void *arg)
{
const struct uart_esp32_config *config = dev->config;
const struct device *dev = (const struct device *)arg;
struct uart_esp32_data *data = DEV_DATA(dev);
uint32_t uart_intr_status = uart_hal_get_intsts_mask(&DEV_CFG(dev)->hal);
struct uart_esp32_data *data = dev->data;
uint32_t uart_intr_status = uart_hal_get_intsts_mask(&config->hal);
if (uart_intr_status == 0) {
return;
}
uart_hal_clr_intsts_mask(&DEV_CFG(dev)->hal, uart_intr_status);
uart_hal_clr_intsts_mask(&config->hal, uart_intr_status);
/* Verify if the callback has been registered */
if (data->irq_cb) {

View file

@ -21,10 +21,8 @@
#include <drivers/uart.h>
#include <uart_imx.h>
#define DEV_CFG(dev) \
((const struct imx_uart_config *const)(dev)->config)
#define UART_STRUCT(dev) \
((UART_Type *)(DEV_CFG(dev))->base)
((UART_Type *)((const struct imx_uart_config *const)(dev)->config)->base)
struct imx_uart_config {
UART_Type *base;

View file

@ -264,7 +264,7 @@ static void uart_liteuart_irq_callback_set(const struct device *dev,
static void liteuart_uart_irq_handler(const struct device *dev)
{
struct uart_liteuart_data *data = DEV_DATA(dev);
struct uart_liteuart_data *data = dev->data;
int key = irq_lock();
if (data->callback) {

View file

@ -13,13 +13,10 @@
#include "uart_lpc11u6x.h"
#define DEV_CFG(dev) ((dev)->config)
#define DEV_DATA(dev) ((dev)->data)
#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart0), okay)
static int lpc11u6x_uart0_poll_in(const struct device *dev, unsigned char *c)
{
const struct lpc11u6x_uart0_config *cfg = DEV_CFG(dev);
const struct lpc11u6x_uart0_config *cfg = dev->config;
if (!(cfg->uart0->lsr & LPC11U6X_UART0_LSR_RDR)) {
return -1;
@ -31,7 +28,7 @@ static int lpc11u6x_uart0_poll_in(const struct device *dev, unsigned char *c)
static void lpc11u6x_uart0_poll_out(const struct device *dev, unsigned char c)
{
const struct lpc11u6x_uart0_config *cfg = DEV_CFG(dev);
const struct lpc11u6x_uart0_config *cfg = dev->config;
while (!(cfg->uart0->lsr & LPC11U6X_UART0_LSR_THRE)) {
}
@ -40,7 +37,7 @@ static void lpc11u6x_uart0_poll_out(const struct device *dev, unsigned char c)
static int lpc11u6x_uart0_err_check(const struct device *dev)
{
const struct lpc11u6x_uart0_config *cfg = DEV_CFG(dev);
const struct lpc11u6x_uart0_config *cfg = dev->config;
uint32_t lsr;
int ret = 0;
@ -104,8 +101,8 @@ static void lpc11u6x_uart0_config_baudrate(const struct device *clk_drv,
static int lpc11u6x_uart0_configure(const struct device *dev,
const struct uart_config *cfg)
{
const struct lpc11u6x_uart0_config *dev_cfg = DEV_CFG(dev);
struct lpc11u6x_uart0_data *data = DEV_DATA(dev);
const struct lpc11u6x_uart0_config *dev_cfg = dev->config;
struct lpc11u6x_uart0_data *data = dev->data;
const struct device *clk_dev;
uint32_t flags = 0;
@ -190,7 +187,7 @@ static int lpc11u6x_uart0_configure(const struct device *dev,
static int lpc11u6x_uart0_config_get(const struct device *dev,
struct uart_config *cfg)
{
struct lpc11u6x_uart0_data *data = DEV_DATA(dev);
struct lpc11u6x_uart0_data *data = dev->data;
cfg->baudrate = data->baudrate;
cfg->parity = data->parity;
@ -207,7 +204,7 @@ static int lpc11u6x_uart0_fifo_fill(const struct device *dev,
const uint8_t *data,
const int size)
{
const struct lpc11u6x_uart0_config *cfg = DEV_CFG(dev);
const struct lpc11u6x_uart0_config *cfg = dev->config;
int nr_sent = 0;
while (nr_sent < size && (cfg->uart0->lsr & LPC11U6X_UART0_LSR_THRE)) {
@ -220,7 +217,7 @@ static int lpc11u6x_uart0_fifo_fill(const struct device *dev,
static int lpc11u6x_uart0_fifo_read(const struct device *dev, uint8_t *data,
const int size)
{
const struct lpc11u6x_uart0_config *cfg = DEV_CFG(dev);
const struct lpc11u6x_uart0_config *cfg = dev->config;
int nr_rx = 0;
while (nr_rx < size && (cfg->uart0->lsr & LPC11U6X_UART0_LSR_RDR)) {
@ -232,7 +229,7 @@ static int lpc11u6x_uart0_fifo_read(const struct device *dev, uint8_t *data,
static void lpc11u6x_uart0_irq_tx_enable(const struct device *dev)
{
const struct lpc11u6x_uart0_config *cfg = DEV_CFG(dev);
const struct lpc11u6x_uart0_config *cfg = dev->config;
cfg->uart0->ier = (cfg->uart0->ier & LPC11U6X_UART0_IER_MASK) |
LPC11U6X_UART0_IER_THREINTEN;
@ -245,7 +242,7 @@ static void lpc11u6x_uart0_irq_tx_enable(const struct device *dev)
static void lpc11u6x_uart0_irq_tx_disable(const struct device *dev)
{
const struct lpc11u6x_uart0_config *cfg = DEV_CFG(dev);
const struct lpc11u6x_uart0_config *cfg = dev->config;
cfg->uart0->ier = (cfg->uart0->ier & LPC11U6X_UART0_IER_MASK) &
~LPC11U6X_UART0_IER_THREINTEN;
@ -253,14 +250,14 @@ static void lpc11u6x_uart0_irq_tx_disable(const struct device *dev)
static int lpc11u6x_uart0_irq_tx_complete(const struct device *dev)
{
const struct lpc11u6x_uart0_config *cfg = DEV_CFG(dev);
const struct lpc11u6x_uart0_config *cfg = dev->config;
return (cfg->uart0->lsr & LPC11U6X_UART0_LSR_TEMT) != 0;
}
static int lpc11u6x_uart0_irq_tx_ready(const struct device *dev)
{
const struct lpc11u6x_uart0_config *cfg = DEV_CFG(dev);
const struct lpc11u6x_uart0_config *cfg = dev->config;
return (cfg->uart0->lsr & LPC11U6X_UART0_LSR_THRE) &&
(cfg->uart0->ier & LPC11U6X_UART0_IER_THREINTEN);
@ -268,7 +265,7 @@ static int lpc11u6x_uart0_irq_tx_ready(const struct device *dev)
static void lpc11u6x_uart0_irq_rx_enable(const struct device *dev)
{
const struct lpc11u6x_uart0_config *cfg = DEV_CFG(dev);
const struct lpc11u6x_uart0_config *cfg = dev->config;
cfg->uart0->ier = (cfg->uart0->ier & LPC11U6X_UART0_IER_MASK) |
LPC11U6X_UART0_IER_RBRINTEN;
@ -276,7 +273,7 @@ static void lpc11u6x_uart0_irq_rx_enable(const struct device *dev)
static void lpc11u6x_uart0_irq_rx_disable(const struct device *dev)
{
const struct lpc11u6x_uart0_config *cfg = DEV_CFG(dev);
const struct lpc11u6x_uart0_config *cfg = dev->config;
cfg->uart0->ier = (cfg->uart0->ier & LPC11U6X_UART0_IER_MASK) &
~LPC11U6X_UART0_IER_RBRINTEN;
@ -284,7 +281,7 @@ static void lpc11u6x_uart0_irq_rx_disable(const struct device *dev)
static int lpc11u6x_uart0_irq_rx_ready(const struct device *dev)
{
struct lpc11u6x_uart0_data *data = DEV_DATA(dev);
struct lpc11u6x_uart0_data *data = dev->data;
return (LPC11U6X_UART0_IIR_INTID(data->cached_iir) ==
LPC11U6X_UART0_IIR_INTID_RDA) ||
@ -294,7 +291,7 @@ static int lpc11u6x_uart0_irq_rx_ready(const struct device *dev)
static void lpc11u6x_uart0_irq_err_enable(const struct device *dev)
{
const struct lpc11u6x_uart0_config *cfg = DEV_CFG(dev);
const struct lpc11u6x_uart0_config *cfg = dev->config;
cfg->uart0->ier = (cfg->uart0->ier & LPC11U6X_UART0_IER_MASK) |
LPC11U6X_UART0_IER_RLSINTEN;
@ -302,7 +299,7 @@ static void lpc11u6x_uart0_irq_err_enable(const struct device *dev)
static void lpc11u6x_uart0_irq_err_disable(const struct device *dev)
{
const struct lpc11u6x_uart0_config *cfg = DEV_CFG(dev);
const struct lpc11u6x_uart0_config *cfg = dev->config;
cfg->uart0->ier = (cfg->uart0->ier & LPC11U6X_UART0_IER_MASK) &
~LPC11U6X_UART0_IER_RLSINTEN;
@ -310,15 +307,15 @@ static void lpc11u6x_uart0_irq_err_disable(const struct device *dev)
static int lpc11u6x_uart0_irq_is_pending(const struct device *dev)
{
struct lpc11u6x_uart0_data *data = DEV_DATA(dev);
struct lpc11u6x_uart0_data *data = dev->data;
return !(data->cached_iir & LPC11U6X_UART0_IIR_STATUS);
}
static int lpc11u6x_uart0_irq_update(const struct device *dev)
{
const struct lpc11u6x_uart0_config *cfg = DEV_CFG(dev);
struct lpc11u6x_uart0_data *data = DEV_DATA(dev);
const struct lpc11u6x_uart0_config *cfg = dev->config;
struct lpc11u6x_uart0_data *data = dev->data;
data->cached_iir = cfg->uart0->iir;
return 1;
@ -328,7 +325,7 @@ static void lpc11u6x_uart0_irq_callback_set(const struct device *dev,
uart_irq_callback_user_data_t cb,
void *user_data)
{
struct lpc11u6x_uart0_data *data = DEV_DATA(dev);
struct lpc11u6x_uart0_data *data = dev->data;
data->cb = cb;
data->cb_data = user_data;
@ -336,7 +333,7 @@ static void lpc11u6x_uart0_irq_callback_set(const struct device *dev,
static void lpc11u6x_uart0_isr(const struct device *dev)
{
struct lpc11u6x_uart0_data *data = DEV_DATA(dev);
struct lpc11u6x_uart0_data *data = dev->data;
if (data->cb) {
data->cb(dev, data->cb_data);
@ -346,8 +343,8 @@ static void lpc11u6x_uart0_isr(const struct device *dev)
static int lpc11u6x_uart0_init(const struct device *dev)
{
const struct lpc11u6x_uart0_config *cfg = DEV_CFG(dev);
struct lpc11u6x_uart0_data *data = DEV_DATA(dev);
const struct lpc11u6x_uart0_config *cfg = dev->config;
struct lpc11u6x_uart0_data *data = dev->data;
const struct device *clk_drv, *rx_pinmux_drv, *tx_pinmux_drv;
/* Configure RX and TX pin via the pinmux driver */
@ -469,7 +466,7 @@ static void lpc11u6x_uart0_isr_config(const struct device *dev)
static int lpc11u6x_uartx_poll_in(const struct device *dev, unsigned char *c)
{
const struct lpc11u6x_uartx_config *cfg = DEV_CFG(dev);
const struct lpc11u6x_uartx_config *cfg = dev->config;
if (!(cfg->base->stat & LPC11U6X_UARTX_STAT_RXRDY)) {
return -1;
@ -480,7 +477,7 @@ static int lpc11u6x_uartx_poll_in(const struct device *dev, unsigned char *c)
static void lpc11u6x_uartx_poll_out(const struct device *dev, unsigned char c)
{
const struct lpc11u6x_uartx_config *cfg = DEV_CFG(dev);
const struct lpc11u6x_uartx_config *cfg = dev->config;
while (!(cfg->base->stat & LPC11U6X_UARTX_STAT_TXRDY)) {
}
@ -489,7 +486,7 @@ static void lpc11u6x_uartx_poll_out(const struct device *dev, unsigned char c)
static int lpc11u6x_uartx_err_check(const struct device *dev)
{
const struct lpc11u6x_uartx_config *cfg = DEV_CFG(dev);
const struct lpc11u6x_uartx_config *cfg = dev->config;
int ret = 0;
if (cfg->base->stat & LPC11U6X_UARTX_STAT_OVERRUNINT) {
@ -526,8 +523,8 @@ static void lpc11u6x_uartx_config_baud(const struct lpc11u6x_uartx_config *cfg,
static int lpc11u6x_uartx_configure(const struct device *dev,
const struct uart_config *cfg)
{
const struct lpc11u6x_uartx_config *dev_cfg = DEV_CFG(dev);
struct lpc11u6x_uartx_data *data = DEV_DATA(dev);
const struct lpc11u6x_uartx_config *dev_cfg = dev->config;
struct lpc11u6x_uartx_data *data = dev->data;
const struct device *clk_dev;
uint32_t flags = 0;
@ -617,7 +614,7 @@ static int lpc11u6x_uartx_configure(const struct device *dev,
static int lpc11u6x_uartx_config_get(const struct device *dev,
struct uart_config *cfg)
{
const struct lpc11u6x_uartx_data *data = DEV_DATA(dev);
const struct lpc11u6x_uartx_data *data = dev->data;
cfg->baudrate = data->baudrate;
cfg->parity = data->parity;
@ -634,7 +631,7 @@ static int lpc11u6x_uartx_fifo_fill(const struct device *dev,
const uint8_t *data,
int size)
{
const struct lpc11u6x_uartx_config *cfg = DEV_CFG(dev);
const struct lpc11u6x_uartx_config *cfg = dev->config;
int tx_size = 0;
while (tx_size < size &&
@ -647,7 +644,7 @@ static int lpc11u6x_uartx_fifo_fill(const struct device *dev,
static int lpc11u6x_uartx_fifo_read(const struct device *dev, uint8_t *data,
int size)
{
const struct lpc11u6x_uartx_config *cfg = DEV_CFG(dev);
const struct lpc11u6x_uartx_config *cfg = dev->config;
int rx_size = 0;
while (rx_size < size &&
@ -659,7 +656,7 @@ static int lpc11u6x_uartx_fifo_read(const struct device *dev, uint8_t *data,
static void lpc11u6x_uartx_irq_tx_enable(const struct device *dev)
{
const struct lpc11u6x_uartx_config *cfg = DEV_CFG(dev);
const struct lpc11u6x_uartx_config *cfg = dev->config;
cfg->base->int_en_set = (cfg->base->int_en_set &
LPC11U6X_UARTX_INT_EN_SET_MASK) |
@ -668,14 +665,14 @@ static void lpc11u6x_uartx_irq_tx_enable(const struct device *dev)
static void lpc11u6x_uartx_irq_tx_disable(const struct device *dev)
{
const struct lpc11u6x_uartx_config *cfg = DEV_CFG(dev);
const struct lpc11u6x_uartx_config *cfg = dev->config;
cfg->base->int_en_clr = LPC11U6X_UARTX_INT_EN_CLR_TXRDYCLR;
}
static int lpc11u6x_uartx_irq_tx_ready(const struct device *dev)
{
const struct lpc11u6x_uartx_config *cfg = DEV_CFG(dev);
const struct lpc11u6x_uartx_config *cfg = dev->config;
return (cfg->base->stat & LPC11U6X_UARTX_STAT_TXRDY) &&
(cfg->base->int_en_set & LPC11U6X_UARTX_INT_EN_SET_TXRDYEN);
@ -683,14 +680,14 @@ static int lpc11u6x_uartx_irq_tx_ready(const struct device *dev)
static int lpc11u6x_uartx_irq_tx_complete(const struct device *dev)
{
const struct lpc11u6x_uartx_config *cfg = DEV_CFG(dev);
const struct lpc11u6x_uartx_config *cfg = dev->config;
return (cfg->base->stat & LPC11U6X_UARTX_STAT_TXIDLE) != 0;
}
static void lpc11u6x_uartx_irq_rx_enable(const struct device *dev)
{
const struct lpc11u6x_uartx_config *cfg = DEV_CFG(dev);
const struct lpc11u6x_uartx_config *cfg = dev->config;
cfg->base->int_en_set = (cfg->base->int_en_set &
LPC11U6X_UARTX_INT_EN_SET_MASK) |
@ -699,14 +696,14 @@ static void lpc11u6x_uartx_irq_rx_enable(const struct device *dev)
static void lpc11u6x_uartx_irq_rx_disable(const struct device *dev)
{
const struct lpc11u6x_uartx_config *cfg = DEV_CFG(dev);
const struct lpc11u6x_uartx_config *cfg = dev->config;
cfg->base->int_en_clr = LPC11U6X_UARTX_INT_EN_CLR_RXRDYCLR;
}
static int lpc11u6x_uartx_irq_rx_ready(const struct device *dev)
{
const struct lpc11u6x_uartx_config *cfg = DEV_CFG(dev);
const struct lpc11u6x_uartx_config *cfg = dev->config;
return (cfg->base->stat & LPC11U6X_UARTX_STAT_RXRDY) &&
(cfg->base->int_en_set & LPC11U6X_UARTX_INT_EN_SET_RXRDYEN);
@ -714,7 +711,7 @@ static int lpc11u6x_uartx_irq_rx_ready(const struct device *dev)
static void lpc11u6x_uartx_irq_err_enable(const struct device *dev)
{
const struct lpc11u6x_uartx_config *cfg = DEV_CFG(dev);
const struct lpc11u6x_uartx_config *cfg = dev->config;
cfg->base->int_en_set = (cfg->base->int_en_set &
LPC11U6X_UARTX_INT_EN_SET_MASK) |
@ -725,7 +722,7 @@ static void lpc11u6x_uartx_irq_err_enable(const struct device *dev)
static void lpc11u6x_uartx_irq_err_disable(const struct device *dev)
{
const struct lpc11u6x_uartx_config *cfg = DEV_CFG(dev);
const struct lpc11u6x_uartx_config *cfg = dev->config;
cfg->base->int_en_clr = LPC11U6X_UARTX_INT_EN_CLR_OVERRUNCLR |
LPC11U6X_UARTX_INT_EN_CLR_FRAMERRCLR |
@ -734,7 +731,7 @@ static void lpc11u6x_uartx_irq_err_disable(const struct device *dev)
static int lpc11u6x_uartx_irq_is_pending(const struct device *dev)
{
const struct lpc11u6x_uartx_config *cfg = DEV_CFG(dev);
const struct lpc11u6x_uartx_config *cfg = dev->config;
if ((cfg->base->stat & LPC11U6X_UARTX_STAT_RXRDY) &&
(cfg->base->int_stat & LPC11U6X_UARTX_INT_STAT_RXRDY)) {
@ -761,7 +758,7 @@ static void lpc11u6x_uartx_irq_callback_set(const struct device *dev,
uart_irq_callback_user_data_t cb,
void *user_data)
{
struct lpc11u6x_uartx_data *data = DEV_DATA(dev);
struct lpc11u6x_uartx_data *data = dev->data;
data->cb = cb;
data->cb_data = user_data;
@ -769,7 +766,7 @@ static void lpc11u6x_uartx_irq_callback_set(const struct device *dev,
static void lpc11u6x_uartx_isr(const struct device *dev)
{
struct lpc11u6x_uartx_data *data = DEV_DATA(dev);
struct lpc11u6x_uartx_data *data = dev->data;
if (data->cb) {
data->cb(dev, data->cb_data);
@ -792,8 +789,8 @@ static void lpc11u6x_uartx_shared_isr(const void *arg)
static int lpc11u6x_uartx_init(const struct device *dev)
{
const struct lpc11u6x_uartx_config *cfg = DEV_CFG(dev);
struct lpc11u6x_uartx_data *data = DEV_DATA(dev);
const struct lpc11u6x_uartx_config *cfg = dev->config;
struct lpc11u6x_uartx_data *data = dev->data;
const struct device *clk_drv, *rx_pinmux_drv, *tx_pinmux_drv;
/* Configure RX and TX pin via the pinmux driver */

View file

@ -163,14 +163,7 @@ BUILD_ASSERT(IS_ENABLED(CONFIG_SOC_SERIES_MEC172X),
#define MSR_RI 0x40 /* complement of ring signal */
#define MSR_DCD 0x80 /* complement of dcd */
/* convenience defines */
#define DEV_CFG(dev) \
((const struct uart_xec_device_config * const)(dev)->config)
#define DEV_DATA(dev) \
((struct uart_xec_dev_data *)(dev)->data)
#define IIRC(dev) (DEV_DATA(dev)->iir_cache)
#define IIRC(dev) (((struct uart_xec_dev_data *)(dev)->data)->iir_cache)
/* device config */
struct uart_xec_device_config {
@ -202,8 +195,8 @@ static const struct uart_driver_api uart_xec_driver_api;
static void set_baud_rate(const struct device *dev, uint32_t baud_rate)
{
const struct uart_xec_device_config * const dev_cfg = DEV_CFG(dev);
struct uart_xec_dev_data * const dev_data = DEV_DATA(dev);
const struct uart_xec_device_config * const dev_cfg = dev->config;
struct uart_xec_dev_data * const dev_data = dev->data;
struct uart_regs *regs = dev_cfg->regs;
uint32_t divisor; /* baud rate divisor */
uint8_t lcr_cache;
@ -239,8 +232,8 @@ static void set_baud_rate(const struct device *dev, uint32_t baud_rate)
static int uart_xec_configure(const struct device *dev,
const struct uart_config *cfg)
{
struct uart_xec_dev_data * const dev_data = DEV_DATA(dev);
const struct uart_xec_device_config * const dev_cfg = DEV_CFG(dev);
struct uart_xec_dev_data * const dev_data = dev->data;
const struct uart_xec_device_config * const dev_cfg = dev->config;
struct uart_regs *regs = dev_cfg->regs;
uint8_t lcr_cache;
@ -341,7 +334,7 @@ out:
static int uart_xec_config_get(const struct device *dev,
struct uart_config *cfg)
{
struct uart_xec_dev_data *data = DEV_DATA(dev);
struct uart_xec_dev_data *data = dev->data;
cfg->baudrate = data->uart_config.baudrate;
cfg->parity = data->uart_config.parity;
@ -364,7 +357,8 @@ static int uart_xec_config_get(const struct device *dev,
*/
static int uart_xec_init(const struct device *dev)
{
const struct uart_xec_device_config * const dev_cfg = DEV_CFG(dev);
const struct uart_xec_device_config * const dev_cfg = dev->config;
struct uart_xec_dev_data *dev_data = dev->data;
int ret;
ret = z_mchp_xec_pcr_periph_sleep(dev_cfg->pcr_idx,
@ -373,7 +367,7 @@ static int uart_xec_init(const struct device *dev)
return ret;
}
ret = uart_xec_configure(dev, &DEV_DATA(dev)->uart_config);
ret = uart_xec_configure(dev, &dev_data->uart_config);
if (ret != 0) {
return ret;
}
@ -395,10 +389,11 @@ static int uart_xec_init(const struct device *dev)
*/
static int uart_xec_poll_in(const struct device *dev, unsigned char *c)
{
const struct uart_xec_device_config * const dev_cfg = DEV_CFG(dev);
const struct uart_xec_device_config * const dev_cfg = dev->config;
struct uart_xec_dev_data *dev_data = dev->data;
struct uart_regs *regs = dev_cfg->regs;
int ret = -1;
k_spinlock_key_t key = k_spin_lock(&DEV_DATA(dev)->lock);
k_spinlock_key_t key = k_spin_lock(&dev_data->lock);
if ((regs->LSR & LSR_RXRDY) != 0) {
/* got a character */
@ -406,7 +401,7 @@ static int uart_xec_poll_in(const struct device *dev, unsigned char *c)
ret = 0;
}
k_spin_unlock(&DEV_DATA(dev)->lock, key);
k_spin_unlock(&dev_data->lock, key);
return ret;
}
@ -425,9 +420,10 @@ static int uart_xec_poll_in(const struct device *dev, unsigned char *c)
*/
static void uart_xec_poll_out(const struct device *dev, unsigned char c)
{
const struct uart_xec_device_config * const dev_cfg = DEV_CFG(dev);
const struct uart_xec_device_config * const dev_cfg = dev->config;
struct uart_xec_dev_data *dev_data = dev->data;
struct uart_regs *regs = dev_cfg->regs;
k_spinlock_key_t key = k_spin_lock(&DEV_DATA(dev)->lock);
k_spinlock_key_t key = k_spin_lock(&dev_data->lock);
while ((regs->LSR & LSR_THRE) == 0) {
;
@ -435,7 +431,7 @@ static void uart_xec_poll_out(const struct device *dev, unsigned char c)
regs->RTXB = c;
k_spin_unlock(&DEV_DATA(dev)->lock, key);
k_spin_unlock(&dev_data->lock, key);
}
/**
@ -448,12 +444,13 @@ static void uart_xec_poll_out(const struct device *dev, unsigned char c)
*/
static int uart_xec_err_check(const struct device *dev)
{
const struct uart_xec_device_config * const dev_cfg = DEV_CFG(dev);
const struct uart_xec_device_config * const dev_cfg = dev->config;
struct uart_xec_dev_data *dev_data = dev->data;
struct uart_regs *regs = dev_cfg->regs;
k_spinlock_key_t key = k_spin_lock(&DEV_DATA(dev)->lock);
k_spinlock_key_t key = k_spin_lock(&dev_data->lock);
int check = regs->LSR & LSR_EOB_MASK;
k_spin_unlock(&DEV_DATA(dev)->lock, key);
k_spin_unlock(&dev_data->lock, key);
return check >> 1;
}
@ -472,16 +469,17 @@ static int uart_xec_err_check(const struct device *dev)
static int uart_xec_fifo_fill(const struct device *dev, const uint8_t *tx_data,
int size)
{
const struct uart_xec_device_config * const dev_cfg = DEV_CFG(dev);
const struct uart_xec_device_config * const dev_cfg = dev->config;
struct uart_xec_dev_data *dev_data = dev->data;
struct uart_regs *regs = dev_cfg->regs;
int i;
k_spinlock_key_t key = k_spin_lock(&DEV_DATA(dev)->lock);
k_spinlock_key_t key = k_spin_lock(&dev_data->lock);
for (i = 0; (i < size) && (regs->LSR & LSR_THRE) != 0; i++) {
regs->RTXB = tx_data[i];
}
k_spin_unlock(&DEV_DATA(dev)->lock, key);
k_spin_unlock(&dev_data->lock, key);
return i;
}
@ -498,16 +496,17 @@ static int uart_xec_fifo_fill(const struct device *dev, const uint8_t *tx_data,
static int uart_xec_fifo_read(const struct device *dev, uint8_t *rx_data,
const int size)
{
const struct uart_xec_device_config * const dev_cfg = DEV_CFG(dev);
const struct uart_xec_device_config * const dev_cfg = dev->config;
struct uart_xec_dev_data *dev_data = dev->data;
struct uart_regs *regs = dev_cfg->regs;
int i;
k_spinlock_key_t key = k_spin_lock(&DEV_DATA(dev)->lock);
k_spinlock_key_t key = k_spin_lock(&dev_data->lock);
for (i = 0; (i < size) && (regs->LSR & LSR_RXRDY) != 0; i++) {
rx_data[i] = regs->RTXB;
}
k_spin_unlock(&DEV_DATA(dev)->lock, key);
k_spin_unlock(&dev_data->lock, key);
return i;
}
@ -519,13 +518,14 @@ static int uart_xec_fifo_read(const struct device *dev, uint8_t *rx_data,
*/
static void uart_xec_irq_tx_enable(const struct device *dev)
{
const struct uart_xec_device_config * const dev_cfg = DEV_CFG(dev);
const struct uart_xec_device_config * const dev_cfg = dev->config;
struct uart_xec_dev_data *dev_data = dev->data;
struct uart_regs *regs = dev_cfg->regs;
k_spinlock_key_t key = k_spin_lock(&DEV_DATA(dev)->lock);
k_spinlock_key_t key = k_spin_lock(&dev_data->lock);
regs->IER |= IER_TBE;
k_spin_unlock(&DEV_DATA(dev)->lock, key);
k_spin_unlock(&dev_data->lock, key);
}
/**
@ -535,13 +535,14 @@ static void uart_xec_irq_tx_enable(const struct device *dev)
*/
static void uart_xec_irq_tx_disable(const struct device *dev)
{
const struct uart_xec_device_config * const dev_cfg = DEV_CFG(dev);
const struct uart_xec_device_config * const dev_cfg = dev->config;
struct uart_xec_dev_data *dev_data = dev->data;
struct uart_regs *regs = dev_cfg->regs;
k_spinlock_key_t key = k_spin_lock(&DEV_DATA(dev)->lock);
k_spinlock_key_t key = k_spin_lock(&dev_data->lock);
regs->IER &= ~(IER_TBE);
k_spin_unlock(&DEV_DATA(dev)->lock, key);
k_spin_unlock(&dev_data->lock, key);
}
/**
@ -553,11 +554,12 @@ static void uart_xec_irq_tx_disable(const struct device *dev)
*/
static int uart_xec_irq_tx_ready(const struct device *dev)
{
k_spinlock_key_t key = k_spin_lock(&DEV_DATA(dev)->lock);
struct uart_xec_dev_data *dev_data = dev->data;
k_spinlock_key_t key = k_spin_lock(&dev_data->lock);
int ret = ((IIRC(dev) & IIR_ID) == IIR_THRE) ? 1 : 0;
k_spin_unlock(&DEV_DATA(dev)->lock, key);
k_spin_unlock(&dev_data->lock, key);
return ret;
}
@ -571,14 +573,15 @@ static int uart_xec_irq_tx_ready(const struct device *dev)
*/
static int uart_xec_irq_tx_complete(const struct device *dev)
{
const struct uart_xec_device_config * const dev_cfg = DEV_CFG(dev);
const struct uart_xec_device_config * const dev_cfg = dev->config;
struct uart_xec_dev_data *dev_data = dev->data;
struct uart_regs *regs = dev_cfg->regs;
k_spinlock_key_t key = k_spin_lock(&DEV_DATA(dev)->lock);
k_spinlock_key_t key = k_spin_lock(&dev_data->lock);
int ret = ((regs->LSR & (LSR_TEMT | LSR_THRE))
== (LSR_TEMT | LSR_THRE)) ? 1 : 0;
k_spin_unlock(&DEV_DATA(dev)->lock, key);
k_spin_unlock(&dev_data->lock, key);
return ret;
}
@ -590,13 +593,14 @@ static int uart_xec_irq_tx_complete(const struct device *dev)
*/
static void uart_xec_irq_rx_enable(const struct device *dev)
{
const struct uart_xec_device_config * const dev_cfg = DEV_CFG(dev);
const struct uart_xec_device_config * const dev_cfg = dev->config;
struct uart_xec_dev_data *dev_data = dev->data;
struct uart_regs *regs = dev_cfg->regs;
k_spinlock_key_t key = k_spin_lock(&DEV_DATA(dev)->lock);
k_spinlock_key_t key = k_spin_lock(&dev_data->lock);
regs->IER |= IER_RXRDY;
k_spin_unlock(&DEV_DATA(dev)->lock, key);
k_spin_unlock(&dev_data->lock, key);
}
/**
@ -606,13 +610,14 @@ static void uart_xec_irq_rx_enable(const struct device *dev)
*/
static void uart_xec_irq_rx_disable(const struct device *dev)
{
const struct uart_xec_device_config * const dev_cfg = DEV_CFG(dev);
const struct uart_xec_device_config * const dev_cfg = dev->config;
struct uart_xec_dev_data *dev_data = dev->data;
struct uart_regs *regs = dev_cfg->regs;
k_spinlock_key_t key = k_spin_lock(&DEV_DATA(dev)->lock);
k_spinlock_key_t key = k_spin_lock(&dev_data->lock);
regs->IER &= ~(IER_RXRDY);
k_spin_unlock(&DEV_DATA(dev)->lock, key);
k_spin_unlock(&dev_data->lock, key);
}
/**
@ -624,11 +629,12 @@ static void uart_xec_irq_rx_disable(const struct device *dev)
*/
static int uart_xec_irq_rx_ready(const struct device *dev)
{
k_spinlock_key_t key = k_spin_lock(&DEV_DATA(dev)->lock);
struct uart_xec_dev_data *dev_data = dev->data;
k_spinlock_key_t key = k_spin_lock(&dev_data->lock);
int ret = ((IIRC(dev) & IIR_ID) == IIR_RBRF) ? 1 : 0;
k_spin_unlock(&DEV_DATA(dev)->lock, key);
k_spin_unlock(&dev_data->lock, key);
return ret;
}
@ -640,13 +646,14 @@ static int uart_xec_irq_rx_ready(const struct device *dev)
*/
static void uart_xec_irq_err_enable(const struct device *dev)
{
const struct uart_xec_device_config * const dev_cfg = DEV_CFG(dev);
const struct uart_xec_device_config * const dev_cfg = dev->config;
struct uart_xec_dev_data *dev_data = dev->data;
struct uart_regs *regs = dev_cfg->regs;
k_spinlock_key_t key = k_spin_lock(&DEV_DATA(dev)->lock);
k_spinlock_key_t key = k_spin_lock(&dev_data->lock);
regs->IER |= IER_LSR;
k_spin_unlock(&DEV_DATA(dev)->lock, key);
k_spin_unlock(&dev_data->lock, key);
}
/**
@ -658,13 +665,14 @@ static void uart_xec_irq_err_enable(const struct device *dev)
*/
static void uart_xec_irq_err_disable(const struct device *dev)
{
const struct uart_xec_device_config * const dev_cfg = DEV_CFG(dev);
const struct uart_xec_device_config * const dev_cfg = dev->config;
struct uart_xec_dev_data *dev_data = dev->data;
struct uart_regs *regs = dev_cfg->regs;
k_spinlock_key_t key = k_spin_lock(&DEV_DATA(dev)->lock);
k_spinlock_key_t key = k_spin_lock(&dev_data->lock);
regs->IER &= ~(IER_LSR);
k_spin_unlock(&DEV_DATA(dev)->lock, key);
k_spin_unlock(&dev_data->lock, key);
}
/**
@ -676,11 +684,12 @@ static void uart_xec_irq_err_disable(const struct device *dev)
*/
static int uart_xec_irq_is_pending(const struct device *dev)
{
k_spinlock_key_t key = k_spin_lock(&DEV_DATA(dev)->lock);
struct uart_xec_dev_data *dev_data = dev->data;
k_spinlock_key_t key = k_spin_lock(&dev_data->lock);
int ret = (!(IIRC(dev) & IIR_NIP)) ? 1 : 0;
k_spin_unlock(&DEV_DATA(dev)->lock, key);
k_spin_unlock(&dev_data->lock, key);
return ret;
}
@ -694,13 +703,14 @@ static int uart_xec_irq_is_pending(const struct device *dev)
*/
static int uart_xec_irq_update(const struct device *dev)
{
const struct uart_xec_device_config * const dev_cfg = DEV_CFG(dev);
const struct uart_xec_device_config * const dev_cfg = dev->config;
struct uart_xec_dev_data *dev_data = dev->data;
struct uart_regs *regs = dev_cfg->regs;
k_spinlock_key_t key = k_spin_lock(&DEV_DATA(dev)->lock);
k_spinlock_key_t key = k_spin_lock(&dev_data->lock);
IIRC(dev) = regs->IIR_FCR;
k_spin_unlock(&DEV_DATA(dev)->lock, key);
k_spin_unlock(&dev_data->lock, key);
return 1;
}
@ -715,7 +725,7 @@ static void uart_xec_irq_callback_set(const struct device *dev,
uart_irq_callback_user_data_t cb,
void *cb_data)
{
struct uart_xec_dev_data * const dev_data = DEV_DATA(dev);
struct uart_xec_dev_data * const dev_data = dev->data;
k_spinlock_key_t key = k_spin_lock(&dev_data->lock);
dev_data->cb = cb;
@ -733,8 +743,8 @@ static void uart_xec_irq_callback_set(const struct device *dev,
*/
static void uart_xec_isr(const struct device *dev)
{
const struct uart_xec_device_config * const dev_cfg = DEV_CFG(dev);
struct uart_xec_dev_data * const dev_data = DEV_DATA(dev);
const struct uart_xec_device_config * const dev_cfg = dev->config;
struct uart_xec_dev_data * const dev_data = dev->data;
if (dev_data->cb) {
dev_data->cb(dev, dev_data->cb_data);
@ -760,7 +770,8 @@ static void uart_xec_isr(const struct device *dev)
static int uart_xec_line_ctrl_set(const struct device *dev,
uint32_t ctrl, uint32_t val)
{
const struct uart_xec_device_config * const dev_cfg = DEV_CFG(dev);
const struct uart_xec_device_config * const dev_cfg = dev->config;
struct uart_xec_dev_data *dev_data = dev->data;
struct uart_regs *regs = dev_cfg->regs;
uint32_t mdc, chg;
k_spinlock_key_t key;
@ -772,7 +783,7 @@ static int uart_xec_line_ctrl_set(const struct device *dev,
case UART_LINE_CTRL_RTS:
case UART_LINE_CTRL_DTR:
key = k_spin_lock(&DEV_DATA(dev)->lock);
key = k_spin_lock(&dev_data->lock);
mdc = regs->MCR;
if (ctrl == UART_LINE_CTRL_RTS) {
@ -787,7 +798,7 @@ static int uart_xec_line_ctrl_set(const struct device *dev,
mdc &= ~(chg);
}
regs->MCR = mdc;
k_spin_unlock(&DEV_DATA(dev)->lock, key);
k_spin_unlock(&dev_data->lock, key);
return 0;
}

View file

@ -30,12 +30,9 @@ struct mcux_iuart_data {
#endif
};
#define DEV_CFG(dev) \
((const struct mcux_iuart_config * const)(dev)->config)
static int mcux_iuart_poll_in(const struct device *dev, unsigned char *c)
{
const struct mcux_iuart_config *config = DEV_CFG(dev);
const struct mcux_iuart_config *config = dev->config;
int ret = -1;
if (UART_GetStatusFlag(config->base, kUART_RxDataReadyFlag)) {
@ -48,7 +45,7 @@ static int mcux_iuart_poll_in(const struct device *dev, unsigned char *c)
static void mcux_iuart_poll_out(const struct device *dev, unsigned char c)
{
const struct mcux_iuart_config *config = DEV_CFG(dev);
const struct mcux_iuart_config *config = dev->config;
while (!(UART_GetStatusFlag(config->base, kUART_TxReadyFlag))) {
}
@ -58,7 +55,7 @@ static void mcux_iuart_poll_out(const struct device *dev, unsigned char c)
static int mcux_iuart_err_check(const struct device *dev)
{
const struct mcux_iuart_config *config = DEV_CFG(dev);
const struct mcux_iuart_config *config = dev->config;
int err = 0;
if (UART_GetStatusFlag(config->base, kUART_RxOverrunFlag)) {
@ -84,7 +81,7 @@ static int mcux_iuart_fifo_fill(const struct device *dev,
const uint8_t *tx_data,
int len)
{
const struct mcux_iuart_config *config = DEV_CFG(dev);
const struct mcux_iuart_config *config = dev->config;
uint8_t num_tx = 0U;
while ((len - num_tx > 0) &&
@ -99,7 +96,7 @@ static int mcux_iuart_fifo_fill(const struct device *dev,
static int mcux_iuart_fifo_read(const struct device *dev, uint8_t *rx_data,
const int len)
{
const struct mcux_iuart_config *config = DEV_CFG(dev);
const struct mcux_iuart_config *config = dev->config;
uint8_t num_rx = 0U;
while ((len - num_rx > 0) &&
@ -113,28 +110,28 @@ static int mcux_iuart_fifo_read(const struct device *dev, uint8_t *rx_data,
static void mcux_iuart_irq_tx_enable(const struct device *dev)
{
const struct mcux_iuart_config *config = DEV_CFG(dev);
const struct mcux_iuart_config *config = dev->config;
UART_EnableInterrupts(config->base, kUART_TxEmptyEnable);
}
static void mcux_iuart_irq_tx_disable(const struct device *dev)
{
const struct mcux_iuart_config *config = DEV_CFG(dev);
const struct mcux_iuart_config *config = dev->config;
UART_DisableInterrupts(config->base, kUART_TxEmptyEnable);
}
static int mcux_iuart_irq_tx_complete(const struct device *dev)
{
const struct mcux_iuart_config *config = DEV_CFG(dev);
const struct mcux_iuart_config *config = dev->config;
return (UART_GetStatusFlag(config->base, kUART_TxEmptyFlag)) != 0U;
}
static int mcux_iuart_irq_tx_ready(const struct device *dev)
{
const struct mcux_iuart_config *config = DEV_CFG(dev);
const struct mcux_iuart_config *config = dev->config;
uint32_t mask = kUART_TxEmptyEnable;
return (UART_GetEnabledInterrupts(config->base) & mask)
@ -143,7 +140,7 @@ static int mcux_iuart_irq_tx_ready(const struct device *dev)
static void mcux_iuart_irq_rx_enable(const struct device *dev)
{
const struct mcux_iuart_config *config = DEV_CFG(dev);
const struct mcux_iuart_config *config = dev->config;
uint32_t mask = kUART_RxDataReadyEnable;
UART_EnableInterrupts(config->base, mask);
@ -151,7 +148,7 @@ static void mcux_iuart_irq_rx_enable(const struct device *dev)
static void mcux_iuart_irq_rx_disable(const struct device *dev)
{
const struct mcux_iuart_config *config = DEV_CFG(dev);
const struct mcux_iuart_config *config = dev->config;
uint32_t mask = kUART_RxDataReadyEnable;
UART_DisableInterrupts(config->base, mask);
@ -159,14 +156,14 @@ static void mcux_iuart_irq_rx_disable(const struct device *dev)
static int mcux_iuart_irq_rx_full(const struct device *dev)
{
const struct mcux_iuart_config *config = DEV_CFG(dev);
const struct mcux_iuart_config *config = dev->config;
return (UART_GetStatusFlag(config->base, kUART_RxDataReadyFlag)) != 0U;
}
static int mcux_iuart_irq_rx_pending(const struct device *dev)
{
const struct mcux_iuart_config *config = DEV_CFG(dev);
const struct mcux_iuart_config *config = dev->config;
uint32_t mask = kUART_RxDataReadyEnable;
return (UART_GetEnabledInterrupts(config->base) & mask)
@ -175,7 +172,7 @@ static int mcux_iuart_irq_rx_pending(const struct device *dev)
static void mcux_iuart_irq_err_enable(const struct device *dev)
{
const struct mcux_iuart_config *config = DEV_CFG(dev);
const struct mcux_iuart_config *config = dev->config;
uint32_t mask = kUART_RxOverrunEnable | kUART_ParityErrorEnable |
kUART_FrameErrorEnable;
@ -184,7 +181,7 @@ static void mcux_iuart_irq_err_enable(const struct device *dev)
static void mcux_iuart_irq_err_disable(const struct device *dev)
{
const struct mcux_iuart_config *config = DEV_CFG(dev);
const struct mcux_iuart_config *config = dev->config;
uint32_t mask = kUART_RxOverrunEnable | kUART_ParityErrorEnable |
kUART_FrameErrorEnable;
@ -223,7 +220,7 @@ static void mcux_iuart_isr(const struct device *dev)
static int mcux_iuart_init(const struct device *dev)
{
const struct mcux_iuart_config *config = DEV_CFG(dev);
const struct mcux_iuart_config *config = dev->config;
uart_config_t uart_config;
uint32_t clock_freq;

View file

@ -145,13 +145,9 @@ struct uart_miv_data {
#endif
};
#define DEV_CFG(dev) \
((const struct uart_miv_device_config * const) \
(dev)->config)
#define DEV_UART(dev) \
((struct uart_miv_regs_t *)(DEV_CFG(dev))->uart_addr)
#define DEV_DATA(dev) \
((struct uart_miv_data * const)(dev)->data)
((struct uart_miv_regs_t *) \
((const struct uart_miv_device_config * const)(dev)->config)->uart_addr)
static void uart_miv_poll_out(const struct device *dev,
unsigned char c)
@ -297,7 +293,7 @@ static int uart_miv_irq_update(const struct device *dev)
static void uart_miv_irq_handler(const struct device *dev)
{
struct uart_miv_data *data = DEV_DATA(dev);
struct uart_miv_data *data = dev->data;
if (data->callback) {
data->callback(dev, data->cb_data);
@ -315,7 +311,7 @@ void uart_miv_rx_thread(void *arg1, void *arg2, void *arg3)
struct uart_miv_data *data = (struct uart_miv_data *)arg1;
const struct device *dev = data->dev;
volatile struct uart_miv_regs_t *uart = DEV_UART(dev);
const struct uart_miv_device_config *const cfg = DEV_CFG(dev);
const struct uart_miv_device_config *const cfg = dev->config;
/* Make it go to sleep for a period no longer than
* time to receive next character.
*/
@ -336,7 +332,7 @@ static void uart_miv_irq_callback_set(const struct device *dev,
uart_irq_callback_user_data_t cb,
void *cb_data)
{
struct uart_miv_data *data = DEV_DATA(dev);
struct uart_miv_data *data = dev->data;
data->callback = cb;
data->cb_data = cb_data;
@ -346,7 +342,7 @@ static void uart_miv_irq_callback_set(const struct device *dev,
static int uart_miv_init(const struct device *dev)
{
const struct uart_miv_device_config *const cfg = DEV_CFG(dev);
const struct uart_miv_device_config *const cfg = dev->config;
volatile struct uart_miv_regs_t *uart = DEV_UART(dev);
/* Calculate divider value to set baudrate */
uint16_t baud_value = (cfg->sys_clk_freq / (cfg->baud_rate * 16U)) - 1;
@ -415,7 +411,7 @@ DEVICE_DT_INST_DEFINE(0, uart_miv_init, NULL,
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
static void uart_miv_irq_cfg_func_0(const struct device *dev)
{
struct uart_miv_data *data = DEV_DATA(dev);
struct uart_miv_data *data = dev->data;
data->dev = dev;

View file

@ -28,11 +28,6 @@ struct uart_msp432p4xx_dev_data_t {
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */
};
#define DEV_CFG(dev) \
((const struct uart_device_config * const)(dev)->config)
#define DEV_DATA(dev) \
((struct uart_msp432p4xx_dev_data_t * const)(dev)->data)
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
static void uart_msp432p4xx_isr(const struct device *dev);
#endif
@ -118,7 +113,7 @@ static int baudrate_set(eUSCI_UART_Config *config, uint32_t baudrate)
static int uart_msp432p4xx_init(const struct device *dev)
{
int err;
const struct uart_device_config *config = DEV_CFG(dev);
const struct uart_device_config *config = dev->config;
eUSCI_UART_Config UartConfig;
/* Select P1.2 and P1.3 in UART mode */
@ -156,7 +151,7 @@ static int uart_msp432p4xx_init(const struct device *dev)
static int uart_msp432p4xx_poll_in(const struct device *dev, unsigned char *c)
{
const struct uart_device_config *config = DEV_CFG(dev);
const struct uart_device_config *config = dev->config;
*c = MAP_UART_receiveData((unsigned long)config->base);
@ -166,7 +161,7 @@ static int uart_msp432p4xx_poll_in(const struct device *dev, unsigned char *c)
static void uart_msp432p4xx_poll_out(const struct device *dev,
unsigned char c)
{
const struct uart_device_config *config = DEV_CFG(dev);
const struct uart_device_config *config = dev->config;
MAP_UART_transmitData((unsigned long)config->base, c);
}
@ -175,7 +170,7 @@ static void uart_msp432p4xx_poll_out(const struct device *dev,
static int uart_msp432p4xx_fifo_fill(const struct device *dev,
const uint8_t *tx_data, int size)
{
const struct uart_device_config *config = DEV_CFG(dev);
const struct uart_device_config *config = dev->config;
unsigned int num_tx = 0U;
while ((size - num_tx) > 0) {
@ -196,7 +191,7 @@ static int uart_msp432p4xx_fifo_read(const struct device *dev,
uint8_t *rx_data,
const int size)
{
const struct uart_device_config *config = DEV_CFG(dev);
const struct uart_device_config *config = dev->config;
unsigned int num_rx = 0U;
while (((size - num_rx) > 0) &&
@ -212,7 +207,7 @@ static int uart_msp432p4xx_fifo_read(const struct device *dev,
static void uart_msp432p4xx_irq_tx_enable(const struct device *dev)
{
const struct uart_device_config *config = DEV_CFG(dev);
const struct uart_device_config *config = dev->config;
MAP_UART_enableInterrupt((unsigned long)config->base,
EUSCI_A_UART_TRANSMIT_INTERRUPT);
@ -220,7 +215,7 @@ static void uart_msp432p4xx_irq_tx_enable(const struct device *dev)
static void uart_msp432p4xx_irq_tx_disable(const struct device *dev)
{
const struct uart_device_config *config = DEV_CFG(dev);
const struct uart_device_config *config = dev->config;
MAP_UART_disableInterrupt((unsigned long)config->base,
EUSCI_A_UART_TRANSMIT_INTERRUPT);
@ -228,7 +223,7 @@ static void uart_msp432p4xx_irq_tx_disable(const struct device *dev)
static int uart_msp432p4xx_irq_tx_ready(const struct device *dev)
{
const struct uart_device_config *config = DEV_CFG(dev);
const struct uart_device_config *config = dev->config;
unsigned int int_status;
int_status = MAP_UART_getInterruptStatus((unsigned long)config->base,
@ -239,7 +234,7 @@ static int uart_msp432p4xx_irq_tx_ready(const struct device *dev)
static void uart_msp432p4xx_irq_rx_enable(const struct device *dev)
{
const struct uart_device_config *config = DEV_CFG(dev);
const struct uart_device_config *config = dev->config;
MAP_UART_enableInterrupt((unsigned long)config->base,
EUSCI_A_UART_RECEIVE_INTERRUPT);
@ -247,7 +242,7 @@ static void uart_msp432p4xx_irq_rx_enable(const struct device *dev)
static void uart_msp432p4xx_irq_rx_disable(const struct device *dev)
{
const struct uart_device_config *config = DEV_CFG(dev);
const struct uart_device_config *config = dev->config;
MAP_UART_disableInterrupt((unsigned long)config->base,
EUSCI_A_UART_RECEIVE_INTERRUPT);
@ -255,7 +250,7 @@ static void uart_msp432p4xx_irq_rx_disable(const struct device *dev)
static int uart_msp432p4xx_irq_tx_complete(const struct device *dev)
{
const struct uart_device_config *config = DEV_CFG(dev);
const struct uart_device_config *config = dev->config;
return MAP_UART_getInterruptStatus((unsigned long)config->base,
EUSCI_A_UART_TRANSMIT_COMPLETE_INTERRUPT_FLAG);
@ -263,7 +258,7 @@ static int uart_msp432p4xx_irq_tx_complete(const struct device *dev)
static int uart_msp432p4xx_irq_rx_ready(const struct device *dev)
{
const struct uart_device_config *config = DEV_CFG(dev);
const struct uart_device_config *config = dev->config;
unsigned int int_status;
int_status = MAP_UART_getInterruptStatus((unsigned long)config->base,
@ -284,7 +279,7 @@ static void uart_msp432p4xx_irq_err_disable(const struct device *dev)
static int uart_msp432p4xx_irq_is_pending(const struct device *dev)
{
const struct uart_device_config *config = DEV_CFG(dev);
const struct uart_device_config *config = dev->config;
unsigned int int_status;
int_status = MAP_UART_getEnabledInterruptStatus(
@ -302,7 +297,7 @@ static void uart_msp432p4xx_irq_callback_set(const struct device *dev,
uart_irq_callback_user_data_t cb,
void *cb_data)
{
struct uart_msp432p4xx_dev_data_t * const dev_data = DEV_DATA(dev);
struct uart_msp432p4xx_dev_data_t * const dev_data = dev->data;
dev_data->cb = cb;
dev_data->cb_data = cb_data;
@ -317,8 +312,8 @@ static void uart_msp432p4xx_irq_callback_set(const struct device *dev,
*/
static void uart_msp432p4xx_isr(const struct device *dev)
{
const struct uart_device_config *config = DEV_CFG(dev);
struct uart_msp432p4xx_dev_data_t * const dev_data = DEV_DATA(dev);
const struct uart_device_config *config = dev->config;
struct uart_msp432p4xx_dev_data_t * const dev_data = dev->data;
unsigned int int_status;
int_status = MAP_UART_getEnabledInterruptStatus(

View file

@ -190,14 +190,6 @@ BUILD_ASSERT(IS_ENABLED(CONFIG_PCIE), "NS16550(s) in DT need CONFIG_PCIE");
#define MSR_RI 0x40 /* complement of ring signal */
#define MSR_DCD 0x80 /* complement of dcd */
/* convenience defines */
#define DEV_CFG(dev) \
((const struct uart_ns16550_device_config * const) \
(dev)->config)
#define DEV_DATA(dev) \
((struct uart_ns16550_dev_data *)(dev)->data)
#define THR(dev) (get_port(dev) + REG_THR * reg_interval(dev))
#define RDR(dev) (get_port(dev) + REG_RDR * reg_interval(dev))
#define BRDL(dev) (get_port(dev) + REG_BRDL * reg_interval(dev))
@ -212,7 +204,7 @@ BUILD_ASSERT(IS_ENABLED(CONFIG_PCIE), "NS16550(s) in DT need CONFIG_PCIE");
#define DLF(dev) (get_port(dev) + REG_DLF)
#define PCP(dev) (get_port(dev) + REG_PCP)
#define IIRC(dev) (DEV_DATA(dev)->iir_cache)
#define IIRC(dev) (((struct uart_ns16550_dev_data *)(dev)->data)->iir_cache)
#ifdef UART_NS16550_ACCESS_IOPORT
#define INBYTE(x) sys_in8(x)
@ -292,8 +284,10 @@ struct uart_ns16550_dev_data {
#if UART_NS16550_REG_INTERVAL_ENABLED
static inline uint8_t reg_interval(const struct device *dev)
{
if (DEV_CFG(dev)->reg_interval) {
return DEV_CFG(dev)->reg_interval;
const struct uart_ns16550_device_config *config = dev->config;
if (config->reg_interval) {
return config->reg_interval;
}
return DEFAULT_REG_INTERVAL;
@ -309,14 +303,16 @@ static inline uintptr_t get_port(const struct device *dev)
#ifndef UART_NS16550_ACCESS_IOPORT
return DEVICE_MMIO_GET(dev);
#else
return DEV_CFG(dev)->port;
const struct uart_ns16550_device_config *config = dev->config;
return config->port;
#endif
}
static void set_baud_rate(const struct device *dev, uint32_t baud_rate)
{
const struct uart_ns16550_device_config * const dev_cfg = DEV_CFG(dev);
struct uart_ns16550_dev_data * const dev_data = DEV_DATA(dev);
const struct uart_ns16550_device_config * const dev_cfg = dev->config;
struct uart_ns16550_dev_data * const dev_data = dev->data;
uint32_t divisor; /* baud rate divisor */
uint8_t lcr_cache;
@ -344,8 +340,8 @@ static void set_baud_rate(const struct device *dev, uint32_t baud_rate)
static int uart_ns16550_configure(const struct device *dev,
const struct uart_config *cfg)
{
struct uart_ns16550_dev_data * const dev_data = DEV_DATA(dev);
const struct uart_ns16550_device_config * const dev_cfg = DEV_CFG(dev);
struct uart_ns16550_dev_data * const dev_data = dev->data;
const struct uart_ns16550_device_config * const dev_cfg = dev->config;
uint8_t mdc = 0U;
/* temp for return value if error occurs in this locked region */
@ -496,7 +492,7 @@ out:
static int uart_ns16550_config_get(const struct device *dev,
struct uart_config *cfg)
{
struct uart_ns16550_dev_data *data = DEV_DATA(dev);
struct uart_ns16550_dev_data *data = dev->data;
cfg->baudrate = data->uart_config.baudrate;
cfg->parity = data->uart_config.parity;
@ -519,15 +515,18 @@ static int uart_ns16550_config_get(const struct device *dev,
*/
static int uart_ns16550_init(const struct device *dev)
{
struct uart_ns16550_dev_data *data = dev->data;
int ret;
ret = uart_ns16550_configure(dev, &DEV_DATA(dev)->uart_config);
ret = uart_ns16550_configure(dev, &data->uart_config);
if (ret != 0) {
return ret;
}
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
DEV_CFG(dev)->irq_config_func(dev);
const struct uart_ns16550_device_config *config = dev->config;
config->irq_config_func(dev);
#endif
return 0;
@ -543,8 +542,9 @@ static int uart_ns16550_init(const struct device *dev)
*/
static int uart_ns16550_poll_in(const struct device *dev, unsigned char *c)
{
struct uart_ns16550_dev_data *data = dev->data;
int ret = -1;
k_spinlock_key_t key = k_spin_lock(&DEV_DATA(dev)->lock);
k_spinlock_key_t key = k_spin_lock(&data->lock);
if ((INBYTE(LSR(dev)) & LSR_RXRDY) != 0) {
/* got a character */
@ -552,7 +552,7 @@ static int uart_ns16550_poll_in(const struct device *dev, unsigned char *c)
ret = 0;
}
k_spin_unlock(&DEV_DATA(dev)->lock, key);
k_spin_unlock(&data->lock, key);
return ret;
}
@ -572,14 +572,15 @@ static int uart_ns16550_poll_in(const struct device *dev, unsigned char *c)
static void uart_ns16550_poll_out(const struct device *dev,
unsigned char c)
{
k_spinlock_key_t key = k_spin_lock(&DEV_DATA(dev)->lock);
struct uart_ns16550_dev_data *data = dev->data;
k_spinlock_key_t key = k_spin_lock(&data->lock);
while ((INBYTE(LSR(dev)) & LSR_THRE) == 0) {
}
OUTBYTE(THR(dev), c);
k_spin_unlock(&DEV_DATA(dev)->lock, key);
k_spin_unlock(&data->lock, key);
}
/**
@ -592,10 +593,11 @@ static void uart_ns16550_poll_out(const struct device *dev,
*/
static int uart_ns16550_err_check(const struct device *dev)
{
k_spinlock_key_t key = k_spin_lock(&DEV_DATA(dev)->lock);
struct uart_ns16550_dev_data *data = dev->data;
k_spinlock_key_t key = k_spin_lock(&data->lock);
int check = (INBYTE(LSR(dev)) & LSR_EOB_MASK);
k_spin_unlock(&DEV_DATA(dev)->lock, key);
k_spin_unlock(&data->lock, key);
return check >> 1;
}
@ -615,14 +617,15 @@ static int uart_ns16550_fifo_fill(const struct device *dev,
const uint8_t *tx_data,
int size)
{
struct uart_ns16550_dev_data *data = dev->data;
int i;
k_spinlock_key_t key = k_spin_lock(&DEV_DATA(dev)->lock);
k_spinlock_key_t key = k_spin_lock(&data->lock);
for (i = 0; (i < size) && (i < DEV_DATA(dev)->fifo_size); i++) {
for (i = 0; (i < size) && (i < data->fifo_size); i++) {
OUTBYTE(THR(dev), tx_data[i]);
}
k_spin_unlock(&DEV_DATA(dev)->lock, key);
k_spin_unlock(&data->lock, key);
return i;
}
@ -639,14 +642,15 @@ static int uart_ns16550_fifo_fill(const struct device *dev,
static int uart_ns16550_fifo_read(const struct device *dev, uint8_t *rx_data,
const int size)
{
struct uart_ns16550_dev_data *data = dev->data;
int i;
k_spinlock_key_t key = k_spin_lock(&DEV_DATA(dev)->lock);
k_spinlock_key_t key = k_spin_lock(&data->lock);
for (i = 0; (i < size) && (INBYTE(LSR(dev)) & LSR_RXRDY) != 0; i++) {
rx_data[i] = INBYTE(RDR(dev));
}
k_spin_unlock(&DEV_DATA(dev)->lock, key);
k_spin_unlock(&data->lock, key);
return i;
}
@ -658,7 +662,8 @@ static int uart_ns16550_fifo_read(const struct device *dev, uint8_t *rx_data,
*/
static void uart_ns16550_irq_tx_enable(const struct device *dev)
{
k_spinlock_key_t key = k_spin_lock(&DEV_DATA(dev)->lock);
struct uart_ns16550_dev_data *data = dev->data;
k_spinlock_key_t key = k_spin_lock(&data->lock);
#if defined(CONFIG_UART_INTERRUPT_DRIVEN) && defined(CONFIG_PM)
struct uart_ns16550_dev_data *const dev_data = dev->data;
@ -682,7 +687,7 @@ static void uart_ns16550_irq_tx_enable(const struct device *dev)
#endif
OUTBYTE(IER(dev), INBYTE(IER(dev)) | IER_TBE);
k_spin_unlock(&DEV_DATA(dev)->lock, key);
k_spin_unlock(&data->lock, key);
}
/**
@ -692,7 +697,8 @@ static void uart_ns16550_irq_tx_enable(const struct device *dev)
*/
static void uart_ns16550_irq_tx_disable(const struct device *dev)
{
k_spinlock_key_t key = k_spin_lock(&DEV_DATA(dev)->lock);
struct uart_ns16550_dev_data *data = dev->data;
k_spinlock_key_t key = k_spin_lock(&data->lock);
OUTBYTE(IER(dev), INBYTE(IER(dev)) & (~IER_TBE));
@ -716,7 +722,7 @@ static void uart_ns16550_irq_tx_disable(const struct device *dev)
}
}
#endif
k_spin_unlock(&DEV_DATA(dev)->lock, key);
k_spin_unlock(&data->lock, key);
}
/**
@ -728,11 +734,12 @@ static void uart_ns16550_irq_tx_disable(const struct device *dev)
*/
static int uart_ns16550_irq_tx_ready(const struct device *dev)
{
k_spinlock_key_t key = k_spin_lock(&DEV_DATA(dev)->lock);
struct uart_ns16550_dev_data *data = dev->data;
k_spinlock_key_t key = k_spin_lock(&data->lock);
int ret = ((IIRC(dev) & IIR_ID) == IIR_THRE) ? 1 : 0;
k_spin_unlock(&DEV_DATA(dev)->lock, key);
k_spin_unlock(&data->lock, key);
return ret;
}
@ -746,12 +753,13 @@ static int uart_ns16550_irq_tx_ready(const struct device *dev)
*/
static int uart_ns16550_irq_tx_complete(const struct device *dev)
{
k_spinlock_key_t key = k_spin_lock(&DEV_DATA(dev)->lock);
struct uart_ns16550_dev_data *data = dev->data;
k_spinlock_key_t key = k_spin_lock(&data->lock);
int ret = ((INBYTE(LSR(dev)) & (LSR_TEMT | LSR_THRE))
== (LSR_TEMT | LSR_THRE)) ? 1 : 0;
k_spin_unlock(&DEV_DATA(dev)->lock, key);
k_spin_unlock(&data->lock, key);
return ret;
}
@ -763,11 +771,12 @@ static int uart_ns16550_irq_tx_complete(const struct device *dev)
*/
static void uart_ns16550_irq_rx_enable(const struct device *dev)
{
k_spinlock_key_t key = k_spin_lock(&DEV_DATA(dev)->lock);
struct uart_ns16550_dev_data *data = dev->data;
k_spinlock_key_t key = k_spin_lock(&data->lock);
OUTBYTE(IER(dev), INBYTE(IER(dev)) | IER_RXRDY);
k_spin_unlock(&DEV_DATA(dev)->lock, key);
k_spin_unlock(&data->lock, key);
}
/**
@ -777,11 +786,12 @@ static void uart_ns16550_irq_rx_enable(const struct device *dev)
*/
static void uart_ns16550_irq_rx_disable(const struct device *dev)
{
k_spinlock_key_t key = k_spin_lock(&DEV_DATA(dev)->lock);
struct uart_ns16550_dev_data *data = dev->data;
k_spinlock_key_t key = k_spin_lock(&data->lock);
OUTBYTE(IER(dev), INBYTE(IER(dev)) & (~IER_RXRDY));
k_spin_unlock(&DEV_DATA(dev)->lock, key);
k_spin_unlock(&data->lock, key);
}
/**
@ -793,11 +803,12 @@ static void uart_ns16550_irq_rx_disable(const struct device *dev)
*/
static int uart_ns16550_irq_rx_ready(const struct device *dev)
{
k_spinlock_key_t key = k_spin_lock(&DEV_DATA(dev)->lock);
struct uart_ns16550_dev_data *data = dev->data;
k_spinlock_key_t key = k_spin_lock(&data->lock);
int ret = ((IIRC(dev) & IIR_ID) == IIR_RBRF) ? 1 : 0;
k_spin_unlock(&DEV_DATA(dev)->lock, key);
k_spin_unlock(&data->lock, key);
return ret;
}
@ -809,11 +820,12 @@ static int uart_ns16550_irq_rx_ready(const struct device *dev)
*/
static void uart_ns16550_irq_err_enable(const struct device *dev)
{
k_spinlock_key_t key = k_spin_lock(&DEV_DATA(dev)->lock);
struct uart_ns16550_dev_data *data = dev->data;
k_spinlock_key_t key = k_spin_lock(&data->lock);
OUTBYTE(IER(dev), INBYTE(IER(dev)) | IER_LSR);
k_spin_unlock(&DEV_DATA(dev)->lock, key);
k_spin_unlock(&data->lock, key);
}
/**
@ -825,11 +837,12 @@ static void uart_ns16550_irq_err_enable(const struct device *dev)
*/
static void uart_ns16550_irq_err_disable(const struct device *dev)
{
k_spinlock_key_t key = k_spin_lock(&DEV_DATA(dev)->lock);
struct uart_ns16550_dev_data *data = dev->data;
k_spinlock_key_t key = k_spin_lock(&data->lock);
OUTBYTE(IER(dev), INBYTE(IER(dev)) & (~IER_LSR));
k_spin_unlock(&DEV_DATA(dev)->lock, key);
k_spin_unlock(&data->lock, key);
}
/**
@ -841,11 +854,12 @@ static void uart_ns16550_irq_err_disable(const struct device *dev)
*/
static int uart_ns16550_irq_is_pending(const struct device *dev)
{
k_spinlock_key_t key = k_spin_lock(&DEV_DATA(dev)->lock);
struct uart_ns16550_dev_data *data = dev->data;
k_spinlock_key_t key = k_spin_lock(&data->lock);
int ret = (!(IIRC(dev) & IIR_NIP)) ? 1 : 0;
k_spin_unlock(&DEV_DATA(dev)->lock, key);
k_spin_unlock(&data->lock, key);
return ret;
}
@ -859,11 +873,12 @@ static int uart_ns16550_irq_is_pending(const struct device *dev)
*/
static int uart_ns16550_irq_update(const struct device *dev)
{
k_spinlock_key_t key = k_spin_lock(&DEV_DATA(dev)->lock);
struct uart_ns16550_dev_data *data = dev->data;
k_spinlock_key_t key = k_spin_lock(&data->lock);
IIRC(dev) = INBYTE(IIR(dev));
k_spin_unlock(&DEV_DATA(dev)->lock, key);
k_spin_unlock(&data->lock, key);
return 1;
}
@ -878,7 +893,7 @@ static void uart_ns16550_irq_callback_set(const struct device *dev,
uart_irq_callback_user_data_t cb,
void *cb_data)
{
struct uart_ns16550_dev_data * const dev_data = DEV_DATA(dev);
struct uart_ns16550_dev_data * const dev_data = dev->data;
k_spinlock_key_t key = k_spin_lock(&dev_data->lock);
dev_data->cb = cb;
@ -896,7 +911,7 @@ static void uart_ns16550_irq_callback_set(const struct device *dev,
*/
static void uart_ns16550_isr(const struct device *dev)
{
struct uart_ns16550_dev_data * const dev_data = DEV_DATA(dev);
struct uart_ns16550_dev_data * const dev_data = dev->data;
if (dev_data->cb) {
dev_data->cb(dev, dev_data->cb_data);
@ -926,6 +941,7 @@ static void uart_ns16550_isr(const struct device *dev)
static int uart_ns16550_line_ctrl_set(const struct device *dev,
uint32_t ctrl, uint32_t val)
{
struct uart_ns16550_dev_data *data = dev->data;
uint32_t mdc, chg;
k_spinlock_key_t key;
@ -936,7 +952,7 @@ static int uart_ns16550_line_ctrl_set(const struct device *dev,
case UART_LINE_CTRL_RTS:
case UART_LINE_CTRL_DTR:
key = k_spin_lock(&DEV_DATA(dev)->lock);
key = k_spin_lock(&data->lock);
mdc = INBYTE(MDC(dev));
if (ctrl == UART_LINE_CTRL_RTS) {
@ -951,7 +967,7 @@ static int uart_ns16550_line_ctrl_set(const struct device *dev,
mdc &= ~(chg);
}
OUTBYTE(MDC(dev), mdc);
k_spin_unlock(&DEV_DATA(dev)->lock, key);
k_spin_unlock(&data->lock, key);
return 0;
}
@ -976,7 +992,7 @@ static int uart_ns16550_drv_cmd(const struct device *dev, uint32_t cmd,
{
#if UART_NS16550_DLF_ENABLED
if (cmd == CMD_SET_DLF) {
struct uart_ns16550_dev_data * const dev_data = DEV_DATA(dev);
struct uart_ns16550_dev_data * const dev_data = dev->data;
k_spinlock_key_t key = k_spin_lock(&dev_data->lock);
dev_data->dlf = p;

View file

@ -11,15 +11,9 @@
#define DT_DRV_COMPAT nuvoton_numicro_uart
/* Device data structure */
#define DEV_CFG(dev) \
((const struct uart_numicro_config * const)(dev)->config)
#define DRV_DATA(dev) \
((struct uart_numicro_data * const)(dev)->data)
#define UART_STRUCT(dev) \
((UART_T *)(DEV_CFG(dev))->devcfg.base)
((UART_T *) \
((const struct uart_numicro_config * const)(dev)->config)->devcfg.base)
struct uart_numicro_config {
struct uart_device_config devcfg;
@ -105,7 +99,7 @@ static inline uint32_t uart_numicro_convert_parity(enum uart_config_parity parit
static int uart_numicro_configure(const struct device *dev,
const struct uart_config *cfg)
{
struct uart_numicro_data *ddata = DRV_DATA(dev);
struct uart_numicro_data *ddata = dev->data;
int32_t databits, stopbits;
uint32_t parity;
@ -140,7 +134,7 @@ static int uart_numicro_configure(const struct device *dev,
static int uart_numicro_config_get(const struct device *dev,
struct uart_config *cfg)
{
struct uart_numicro_data *ddata = DRV_DATA(dev);
struct uart_numicro_data *ddata = dev->data;
memcpy(cfg, &ddata->ucfg, sizeof(*cfg));
@ -150,8 +144,8 @@ static int uart_numicro_config_get(const struct device *dev,
static int uart_numicro_init(const struct device *dev)
{
const struct uart_numicro_config *config = DEV_CFG(dev);
struct uart_numicro_data *ddata = DRV_DATA(dev);
const struct uart_numicro_config *config = dev->config;
struct uart_numicro_data *ddata = dev->data;
SYS_ResetModule(config->id_rst);

View file

@ -142,12 +142,9 @@ struct pl011_data {
PL011_IMSC_RXIM | PL011_IMSC_TXIM | \
PL011_IMSC_RTIM)
#define DEV_CFG(dev) \
((const struct uart_device_config * const)(dev)->config)
#define DEV_DATA(dev) \
((struct pl011_data *)(dev)->data)
#define PL011_REGS(dev) \
((volatile struct pl011_regs *)(DEV_CFG(dev))->base)
((volatile struct pl011_regs *) \
((const struct uart_device_config * const)(dev)->config)->base)
static void pl011_enable(const struct device *dev)
{
@ -201,7 +198,9 @@ static int pl011_set_baudrate(const struct device *dev,
static bool pl011_is_readable(const struct device *dev)
{
if (!DEV_DATA(dev)->sbsa &&
struct pl011_data *data = dev->data;
if (!data->sbsa &&
(!(PL011_REGS(dev)->cr & PL011_CR_UARTEN) ||
!(PL011_REGS(dev)->cr & PL011_CR_RXE)))
return false;
@ -277,7 +276,9 @@ static int pl011_irq_tx_complete(const struct device *dev)
static int pl011_irq_tx_ready(const struct device *dev)
{
if (!DEV_DATA(dev)->sbsa && !(PL011_REGS(dev)->cr & PL011_CR_TXE))
struct pl011_data *data = dev->data;
if (!data->sbsa && !(PL011_REGS(dev)->cr & PL011_CR_TXE))
return false;
return ((PL011_REGS(dev)->imsc & PL011_IMSC_TXIM) &&
@ -298,7 +299,9 @@ static void pl011_irq_rx_disable(const struct device *dev)
static int pl011_irq_rx_ready(const struct device *dev)
{
if (!DEV_DATA(dev)->sbsa && !(PL011_REGS(dev)->cr & PL011_CR_RXE))
struct pl011_data *data = dev->data;
if (!data->sbsa && !(PL011_REGS(dev)->cr & PL011_CR_RXE))
return false;
return ((PL011_REGS(dev)->imsc & PL011_IMSC_RXIM) &&
@ -330,8 +333,10 @@ static void pl011_irq_callback_set(const struct device *dev,
uart_irq_callback_user_data_t cb,
void *cb_data)
{
DEV_DATA(dev)->irq_cb = cb;
DEV_DATA(dev)->irq_cb_data = cb_data;
struct pl011_data *data = dev->data;
data->irq_cb = cb;
data->irq_cb_data = cb_data;
}
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */
@ -358,6 +363,8 @@ static const struct uart_driver_api pl011_driver_api = {
static int pl011_init(const struct device *dev)
{
const struct uart_device_config *config = dev->config;
struct pl011_data *data = dev->data;
int ret;
uint32_t lcrh;
@ -366,14 +373,14 @@ static int pl011_init(const struct device *dev)
* or does not require configuration at all (if UART is emulated by
* virtualization software).
*/
if (!DEV_DATA(dev)->sbsa) {
if (!data->sbsa) {
/* disable the uart */
pl011_disable(dev);
pl011_disable_fifo(dev);
/* Set baud rate */
ret = pl011_set_baudrate(dev, DEV_CFG(dev)->sys_clk_freq,
DEV_DATA(dev)->baud_rate);
ret = pl011_set_baudrate(dev, config->sys_clk_freq,
data->baud_rate);
if (ret != 0) {
return ret;
}
@ -391,7 +398,7 @@ static int pl011_init(const struct device *dev)
PL011_REGS(dev)->imsc = 0U;
PL011_REGS(dev)->icr = PL011_IMSC_MASK_ALL;
if (!DEV_DATA(dev)->sbsa) {
if (!data->sbsa) {
PL011_REGS(dev)->dmacr = 0U;
__ISB();
PL011_REGS(dev)->cr &= ~(BIT(14) | BIT(15) | BIT(1));
@ -399,9 +406,9 @@ static int pl011_init(const struct device *dev)
__ISB();
}
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
DEV_CFG(dev)->irq_config_func(dev);
config->irq_config_func(dev);
#endif
if (!DEV_DATA(dev)->sbsa)
if (!data->sbsa)
pl011_enable(dev);
return 0;
@ -410,7 +417,7 @@ static int pl011_init(const struct device *dev)
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
void pl011_isr(const struct device *dev)
{
struct pl011_data *data = DEV_DATA(dev);
struct pl011_data *data = dev->data;
/* Verify if the callback has been registered */
if (data->irq_cb) {

View file

@ -60,9 +60,6 @@ struct cypress_psoc6_data {
void *irq_cb_data; /* Interrupt Callback Arg */
};
#define DEV_DATA(dev) \
((struct cypress_psoc6_data *const)(dev)->data)
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */
/* Populate configuration structure */
@ -288,7 +285,7 @@ static void uart_psoc6_irq_callback_set(const struct device *dev,
uart_irq_callback_user_data_t cb,
void *cb_data)
{
struct cypress_psoc6_data *const dev_data = DEV_DATA(dev);
struct cypress_psoc6_data *const dev_data = dev->data;
dev_data->irq_cb = cb;
dev_data->irq_cb_data = cb_data;
@ -296,7 +293,7 @@ static void uart_psoc6_irq_callback_set(const struct device *dev,
static void uart_psoc6_isr(const struct device *dev)
{
struct cypress_psoc6_data *const dev_data = DEV_DATA(dev);
struct cypress_psoc6_data *const dev_data = dev->data;
if (dev_data->irq_cb) {
dev_data->irq_cb(dev, dev_data->irq_cb_data);

View file

@ -43,12 +43,6 @@ struct uart_sam_dev_data {
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */
};
#define DEV_CFG(dev) \
((const struct uart_sam_dev_cfg *const)(dev)->config)
#define DEV_DATA(dev) \
((struct uart_sam_dev_data *const)(dev)->data)
static int baudrate_set(Uart *const uart, uint32_t baudrate,
uint32_t mck_freq_hz);
@ -56,8 +50,8 @@ static int baudrate_set(Uart *const uart, uint32_t baudrate,
static int uart_sam_init(const struct device *dev)
{
int retval;
const struct uart_sam_dev_cfg *const cfg = DEV_CFG(dev);
struct uart_sam_dev_data *const dev_data = DEV_DATA(dev);
const struct uart_sam_dev_cfg *const cfg = dev->config;
struct uart_sam_dev_data *const dev_data = dev->data;
Uart *const uart = cfg->regs;
/* Enable UART clock in PMC */
@ -99,7 +93,9 @@ static int uart_sam_init(const struct device *dev)
static int uart_sam_poll_in(const struct device *dev, unsigned char *c)
{
Uart *const uart = DEV_CFG(dev)->regs;
const struct uart_sam_dev_cfg *const cfg = dev->config;
Uart *const uart = cfg->regs;
if (!(uart->UART_SR & UART_SR_RXRDY)) {
return -EBUSY;
@ -113,7 +109,9 @@ static int uart_sam_poll_in(const struct device *dev, unsigned char *c)
static void uart_sam_poll_out(const struct device *dev, unsigned char c)
{
Uart *const uart = DEV_CFG(dev)->regs;
const struct uart_sam_dev_cfg *const cfg = dev->config;
Uart *const uart = cfg->regs;
/* Wait for transmitter to be ready */
while (!(uart->UART_SR & UART_SR_TXRDY)) {
@ -125,7 +123,9 @@ static void uart_sam_poll_out(const struct device *dev, unsigned char c)
static int uart_sam_err_check(const struct device *dev)
{
volatile Uart * const uart = DEV_CFG(dev)->regs;
const struct uart_sam_dev_cfg *const cfg = dev->config;
volatile Uart * const uart = cfg->regs;
int errors = 0;
if (uart->UART_SR & UART_SR_OVRE) {
@ -170,7 +170,9 @@ static int uart_sam_fifo_fill(const struct device *dev,
const uint8_t *tx_data,
int size)
{
volatile Uart * const uart = DEV_CFG(dev)->regs;
const struct uart_sam_dev_cfg *const cfg = dev->config;
volatile Uart * const uart = cfg->regs;
/* Wait for transmitter to be ready. */
while ((uart->UART_SR & UART_SR_TXRDY) == 0) {
@ -184,7 +186,9 @@ static int uart_sam_fifo_fill(const struct device *dev,
static int uart_sam_fifo_read(const struct device *dev, uint8_t *rx_data,
const int size)
{
volatile Uart * const uart = DEV_CFG(dev)->regs;
const struct uart_sam_dev_cfg *const cfg = dev->config;
volatile Uart * const uart = cfg->regs;
int bytes_read;
bytes_read = 0;
@ -203,70 +207,90 @@ static int uart_sam_fifo_read(const struct device *dev, uint8_t *rx_data,
static void uart_sam_irq_tx_enable(const struct device *dev)
{
volatile Uart * const uart = DEV_CFG(dev)->regs;
const struct uart_sam_dev_cfg *const cfg = dev->config;
volatile Uart * const uart = cfg->regs;
uart->UART_IER = UART_IER_TXRDY;
}
static void uart_sam_irq_tx_disable(const struct device *dev)
{
volatile Uart * const uart = DEV_CFG(dev)->regs;
const struct uart_sam_dev_cfg *const cfg = dev->config;
volatile Uart * const uart = cfg->regs;
uart->UART_IDR = UART_IDR_TXRDY;
}
static int uart_sam_irq_tx_ready(const struct device *dev)
{
volatile Uart * const uart = DEV_CFG(dev)->regs;
const struct uart_sam_dev_cfg *const cfg = dev->config;
volatile Uart * const uart = cfg->regs;
return (uart->UART_SR & UART_SR_TXRDY);
}
static void uart_sam_irq_rx_enable(const struct device *dev)
{
volatile Uart * const uart = DEV_CFG(dev)->regs;
const struct uart_sam_dev_cfg *const cfg = dev->config;
volatile Uart * const uart = cfg->regs;
uart->UART_IER = UART_IER_RXRDY;
}
static void uart_sam_irq_rx_disable(const struct device *dev)
{
volatile Uart * const uart = DEV_CFG(dev)->regs;
const struct uart_sam_dev_cfg *const cfg = dev->config;
volatile Uart * const uart = cfg->regs;
uart->UART_IDR = UART_IDR_RXRDY;
}
static int uart_sam_irq_tx_complete(const struct device *dev)
{
volatile Uart * const uart = DEV_CFG(dev)->regs;
const struct uart_sam_dev_cfg *const cfg = dev->config;
volatile Uart * const uart = cfg->regs;
return !(uart->UART_SR & UART_SR_TXRDY);
}
static int uart_sam_irq_rx_ready(const struct device *dev)
{
volatile Uart * const uart = DEV_CFG(dev)->regs;
const struct uart_sam_dev_cfg *const cfg = dev->config;
volatile Uart * const uart = cfg->regs;
return (uart->UART_SR & UART_SR_RXRDY);
}
static void uart_sam_irq_err_enable(const struct device *dev)
{
volatile Uart * const uart = DEV_CFG(dev)->regs;
const struct uart_sam_dev_cfg *const cfg = dev->config;
volatile Uart * const uart = cfg->regs;
uart->UART_IER = UART_IER_OVRE | UART_IER_FRAME | UART_IER_PARE;
}
static void uart_sam_irq_err_disable(const struct device *dev)
{
volatile Uart * const uart = DEV_CFG(dev)->regs;
const struct uart_sam_dev_cfg *const cfg = dev->config;
volatile Uart * const uart = cfg->regs;
uart->UART_IDR = UART_IDR_OVRE | UART_IDR_FRAME | UART_IDR_PARE;
}
static int uart_sam_irq_is_pending(const struct device *dev)
{
volatile Uart * const uart = DEV_CFG(dev)->regs;
const struct uart_sam_dev_cfg *const cfg = dev->config;
volatile Uart * const uart = cfg->regs;
return (uart->UART_IMR & (UART_IMR_TXRDY | UART_IMR_RXRDY)) &
(uart->UART_SR & (UART_SR_TXRDY | UART_SR_RXRDY));
@ -283,7 +307,7 @@ static void uart_sam_irq_callback_set(const struct device *dev,
uart_irq_callback_user_data_t cb,
void *cb_data)
{
struct uart_sam_dev_data *const dev_data = DEV_DATA(dev);
struct uart_sam_dev_data *const dev_data = dev->data;
dev_data->irq_cb = cb;
dev_data->irq_cb_data = cb_data;
@ -291,7 +315,7 @@ static void uart_sam_irq_callback_set(const struct device *dev,
static void uart_sam_isr(const struct device *dev)
{
struct uart_sam_dev_data *const dev_data = DEV_DATA(dev);
struct uart_sam_dev_data *const dev_data = dev->data;
if (dev_data->irq_cb) {
dev_data->irq_cb(dev, dev_data->irq_cb_data);

View file

@ -87,10 +87,6 @@ struct uart_sam0_dev_data {
#endif
};
#define DEV_CFG(dev) \
((const struct uart_sam0_dev_cfg *const)(dev)->config)
#define DEV_DATA(dev) ((struct uart_sam0_dev_data * const)(dev)->data)
static void wait_synchronization(SercomUsart *const usart)
{
#if defined(SERCOM_USART_SYNCBUSY_MASK)
@ -392,8 +388,8 @@ static int uart_sam0_configure(const struct device *dev,
{
int retval;
const struct uart_sam0_dev_cfg *const cfg = DEV_CFG(dev);
struct uart_sam0_dev_data *const dev_data = DEV_DATA(dev);
const struct uart_sam0_dev_cfg *const cfg = dev->config;
struct uart_sam0_dev_data *const dev_data = dev->data;
SercomUsart * const usart = cfg->regs;
wait_synchronization(usart);
@ -493,7 +489,8 @@ static int uart_sam0_configure(const struct device *dev,
static int uart_sam0_config_get(const struct device *dev,
struct uart_config *out_cfg)
{
struct uart_sam0_dev_data *const dev_data = DEV_DATA(dev);
struct uart_sam0_dev_data *const dev_data = dev->data;
memcpy(out_cfg, &(dev_data->config_cache),
sizeof(dev_data->config_cache));
@ -504,8 +501,8 @@ static int uart_sam0_config_get(const struct device *dev,
static int uart_sam0_init(const struct device *dev)
{
int retval;
const struct uart_sam0_dev_cfg *const cfg = DEV_CFG(dev);
struct uart_sam0_dev_data *const dev_data = DEV_DATA(dev);
const struct uart_sam0_dev_cfg *const cfg = dev->config;
struct uart_sam0_dev_data *const dev_data = dev->data;
SercomUsart *const usart = cfg->regs;
@ -634,7 +631,9 @@ static int uart_sam0_init(const struct device *dev)
static int uart_sam0_poll_in(const struct device *dev, unsigned char *c)
{
SercomUsart *const usart = DEV_CFG(dev)->regs;
const struct uart_sam0_dev_cfg *config = dev->config;
SercomUsart *const usart = config->regs;
if (!usart->INTFLAG.bit.RXC) {
return -EBUSY;
@ -646,7 +645,9 @@ static int uart_sam0_poll_in(const struct device *dev, unsigned char *c)
static void uart_sam0_poll_out(const struct device *dev, unsigned char c)
{
SercomUsart *const usart = DEV_CFG(dev)->regs;
const struct uart_sam0_dev_cfg *config = dev->config;
SercomUsart *const usart = config->regs;
while (!usart->INTFLAG.bit.DRE) {
}
@ -657,7 +658,9 @@ static void uart_sam0_poll_out(const struct device *dev, unsigned char c)
static int uart_sam0_err_check(const struct device *dev)
{
SercomUsart * const regs = DEV_CFG(dev)->regs;
const struct uart_sam0_dev_cfg *config = dev->config;
SercomUsart * const regs = config->regs;
uint32_t err = 0U;
if (regs->STATUS.reg & SERCOM_USART_STATUS_BUFOVF) {
@ -700,7 +703,7 @@ static int uart_sam0_err_check(const struct device *dev)
static void uart_sam0_isr(const struct device *dev)
{
struct uart_sam0_dev_data *const dev_data = DEV_DATA(dev);
struct uart_sam0_dev_data *const dev_data = dev->data;
#if CONFIG_UART_INTERRUPT_DRIVEN
if (dev_data->cb) {
@ -709,7 +712,7 @@ static void uart_sam0_isr(const struct device *dev)
#endif
#if CONFIG_UART_ASYNC_API
const struct uart_sam0_dev_cfg *const cfg = DEV_CFG(dev);
const struct uart_sam0_dev_cfg *const cfg = dev->config;
SercomUsart * const regs = cfg->regs;
if (dev_data->tx_len && regs->INTFLAG.bit.TXC) {
@ -775,7 +778,8 @@ static void uart_sam0_isr(const struct device *dev)
static int uart_sam0_fifo_fill(const struct device *dev,
const uint8_t *tx_data, int len)
{
SercomUsart *regs = DEV_CFG(dev)->regs;
const struct uart_sam0_dev_cfg *config = dev->config;
SercomUsart *regs = config->regs;
if (regs->INTFLAG.bit.DRE && len >= 1) {
regs->DATA.reg = tx_data[0];
@ -787,7 +791,8 @@ static int uart_sam0_fifo_fill(const struct device *dev,
static void uart_sam0_irq_tx_enable(const struct device *dev)
{
SercomUsart * const regs = DEV_CFG(dev)->regs;
const struct uart_sam0_dev_cfg *config = dev->config;
SercomUsart * const regs = config->regs;
regs->INTENSET.reg = SERCOM_USART_INTENSET_DRE
| SERCOM_USART_INTENSET_TXC;
@ -795,7 +800,8 @@ static void uart_sam0_irq_tx_enable(const struct device *dev)
static void uart_sam0_irq_tx_disable(const struct device *dev)
{
SercomUsart * const regs = DEV_CFG(dev)->regs;
const struct uart_sam0_dev_cfg *config = dev->config;
SercomUsart * const regs = config->regs;
regs->INTENCLR.reg = SERCOM_USART_INTENCLR_DRE
| SERCOM_USART_INTENCLR_TXC;
@ -803,35 +809,40 @@ static void uart_sam0_irq_tx_disable(const struct device *dev)
static int uart_sam0_irq_tx_ready(const struct device *dev)
{
SercomUsart * const regs = DEV_CFG(dev)->regs;
const struct uart_sam0_dev_cfg *config = dev->config;
SercomUsart * const regs = config->regs;
return (regs->INTFLAG.bit.DRE != 0) && (regs->INTENSET.bit.DRE != 0);
}
static int uart_sam0_irq_tx_complete(const struct device *dev)
{
SercomUsart * const regs = DEV_CFG(dev)->regs;
const struct uart_sam0_dev_cfg *config = dev->config;
SercomUsart * const regs = config->regs;
return (regs->INTFLAG.bit.TXC != 0) && (regs->INTENSET.bit.TXC != 0);
}
static void uart_sam0_irq_rx_enable(const struct device *dev)
{
SercomUsart * const regs = DEV_CFG(dev)->regs;
const struct uart_sam0_dev_cfg *config = dev->config;
SercomUsart * const regs = config->regs;
regs->INTENSET.reg = SERCOM_USART_INTENSET_RXC;
}
static void uart_sam0_irq_rx_disable(const struct device *dev)
{
SercomUsart * const regs = DEV_CFG(dev)->regs;
const struct uart_sam0_dev_cfg *config = dev->config;
SercomUsart * const regs = config->regs;
regs->INTENCLR.reg = SERCOM_USART_INTENCLR_RXC;
}
static int uart_sam0_irq_rx_ready(const struct device *dev)
{
SercomUsart * const regs = DEV_CFG(dev)->regs;
const struct uart_sam0_dev_cfg *config = dev->config;
SercomUsart * const regs = config->regs;
return regs->INTFLAG.bit.RXC != 0;
}
@ -839,7 +850,8 @@ static int uart_sam0_irq_rx_ready(const struct device *dev)
static int uart_sam0_fifo_read(const struct device *dev, uint8_t *rx_data,
const int size)
{
SercomUsart * const regs = DEV_CFG(dev)->regs;
const struct uart_sam0_dev_cfg *config = dev->config;
SercomUsart * const regs = config->regs;
if (regs->INTFLAG.bit.RXC) {
uint8_t ch = regs->DATA.reg;
@ -856,7 +868,8 @@ static int uart_sam0_fifo_read(const struct device *dev, uint8_t *rx_data,
static int uart_sam0_irq_is_pending(const struct device *dev)
{
SercomUsart * const regs = DEV_CFG(dev)->regs;
const struct uart_sam0_dev_cfg *config = dev->config;
SercomUsart * const regs = config->regs;
return (regs->INTENSET.reg & regs->INTFLAG.reg) != 0;
}
@ -864,7 +877,8 @@ static int uart_sam0_irq_is_pending(const struct device *dev)
#if defined(SERCOM_REV500)
static void uart_sam0_irq_err_enable(const struct device *dev)
{
SercomUsart * const regs = DEV_CFG(dev)->regs;
const struct uart_sam0_dev_cfg *config = dev->config;
SercomUsart * const regs = config->regs;
regs->INTENSET.reg |= SERCOM_USART_INTENCLR_ERROR;
wait_synchronization(regs);
@ -872,7 +886,8 @@ static void uart_sam0_irq_err_enable(const struct device *dev)
static void uart_sam0_irq_err_disable(const struct device *dev)
{
SercomUsart * const regs = DEV_CFG(dev)->regs;
const struct uart_sam0_dev_cfg *config = dev->config;
SercomUsart * const regs = config->regs;
regs->INTENCLR.reg |= SERCOM_USART_INTENSET_ERROR;
wait_synchronization(regs);
@ -882,7 +897,8 @@ static void uart_sam0_irq_err_disable(const struct device *dev)
static int uart_sam0_irq_update(const struct device *dev)
{
/* Clear sticky interrupts */
SercomUsart * const regs = DEV_CFG(dev)->regs;
const struct uart_sam0_dev_cfg *config = dev->config;
SercomUsart * const regs = config->regs;
#if defined(SERCOM_REV500)
regs->INTFLAG.reg |= SERCOM_USART_INTENCLR_ERROR
| SERCOM_USART_INTENCLR_RXBRK
@ -898,7 +914,7 @@ static void uart_sam0_irq_callback_set(const struct device *dev,
uart_irq_callback_user_data_t cb,
void *cb_data)
{
struct uart_sam0_dev_data *const dev_data = DEV_DATA(dev);
struct uart_sam0_dev_data *const dev_data = dev->data;
dev_data->cb = cb;
dev_data->cb_data = cb_data;
@ -911,7 +927,7 @@ static int uart_sam0_callback_set(const struct device *dev,
uart_callback_t callback,
void *user_data)
{
struct uart_sam0_dev_data *const dev_data = DEV_DATA(dev);
struct uart_sam0_dev_data *const dev_data = dev->data;
dev_data->async_cb = callback;
dev_data->async_cb_data = user_data;
@ -923,9 +939,9 @@ static int uart_sam0_tx(const struct device *dev, const uint8_t *buf,
size_t len,
int32_t timeout)
{
struct uart_sam0_dev_data *const dev_data = DEV_DATA(dev);
const struct uart_sam0_dev_cfg *const cfg = DEV_CFG(dev);
SercomUsart *regs = DEV_CFG(dev)->regs;
struct uart_sam0_dev_data *const dev_data = dev->data;
const struct uart_sam0_dev_cfg *const cfg = dev->config;
SercomUsart *regs = cfg->regs;
int retval;
if (cfg->tx_dma_channel == 0xFFU) {
@ -967,8 +983,8 @@ err:
static int uart_sam0_tx_abort(const struct device *dev)
{
struct uart_sam0_dev_data *const dev_data = DEV_DATA(dev);
const struct uart_sam0_dev_cfg *const cfg = DEV_CFG(dev);
struct uart_sam0_dev_data *const dev_data = dev->data;
const struct uart_sam0_dev_cfg *const cfg = dev->config;
if (cfg->tx_dma_channel == 0xFFU) {
return -ENOTSUP;
@ -983,9 +999,9 @@ static int uart_sam0_rx_enable(const struct device *dev, uint8_t *buf,
size_t len,
int32_t timeout)
{
struct uart_sam0_dev_data *const dev_data = DEV_DATA(dev);
const struct uart_sam0_dev_cfg *const cfg = DEV_CFG(dev);
SercomUsart *regs = DEV_CFG(dev)->regs;
struct uart_sam0_dev_data *const dev_data = dev->data;
const struct uart_sam0_dev_cfg *const cfg = dev->config;
SercomUsart *regs = cfg->regs;
int retval;
if (cfg->rx_dma_channel == 0xFFU) {
@ -1042,7 +1058,7 @@ static int uart_sam0_rx_buf_rsp(const struct device *dev, uint8_t *buf,
return -EINVAL;
}
struct uart_sam0_dev_data *const dev_data = DEV_DATA(dev);
struct uart_sam0_dev_data *const dev_data = dev->data;
int key = irq_lock();
int retval = 0;
@ -1069,8 +1085,8 @@ err:
static int uart_sam0_rx_disable(const struct device *dev)
{
struct uart_sam0_dev_data *const dev_data = DEV_DATA(dev);
const struct uart_sam0_dev_cfg *const cfg = DEV_CFG(dev);
struct uart_sam0_dev_data *const dev_data = dev->data;
const struct uart_sam0_dev_cfg *const cfg = dev->config;
SercomUsart * const regs = cfg->regs;
struct dma_status st;

View file

@ -64,13 +64,9 @@ struct uart_sifive_data {
#endif
};
#define DEV_CFG(dev) \
((const struct uart_sifive_device_config * const) \
(dev)->config)
#define DEV_UART(dev) \
((struct uart_sifive_regs_t *)(DEV_CFG(dev))->port)
#define DEV_DATA(dev) \
((struct uart_sifive_data * const)(dev)->data)
((struct uart_sifive_regs_t *) \
((const struct uart_sifive_device_config * const)(dev)->config)->port)
/**
* @brief Output a character in polled mode.
@ -301,7 +297,7 @@ static void uart_sifive_irq_callback_set(const struct device *dev,
uart_irq_callback_user_data_t cb,
void *cb_data)
{
struct uart_sifive_data *data = DEV_DATA(dev);
struct uart_sifive_data *data = dev->data;
data->callback = cb;
data->cb_data = cb_data;
@ -309,7 +305,7 @@ static void uart_sifive_irq_callback_set(const struct device *dev,
static void uart_sifive_irq_handler(const struct device *dev)
{
struct uart_sifive_data *data = DEV_DATA(dev);
struct uart_sifive_data *data = dev->data;
if (data->callback)
data->callback(dev, data->cb_data);
@ -320,7 +316,7 @@ static void uart_sifive_irq_handler(const struct device *dev)
static int uart_sifive_init(const struct device *dev)
{
const struct uart_sifive_device_config * const cfg = DEV_CFG(dev);
const struct uart_sifive_device_config * const cfg = dev->config;
volatile struct uart_sifive_regs_t *uart = DEV_UART(dev);
/* Enable TX and RX channels */

View file

@ -77,44 +77,39 @@ struct uart_stellaris_dev_data_t {
#endif
};
/* convenience defines */
#define DEV_CFG(dev) \
((const struct uart_device_config * const)(dev)->config)
#define DEV_DATA(dev) \
((struct uart_stellaris_dev_data_t * const)(dev)->data)
#define UART_STRUCT(dev) \
((volatile struct _uart *)(DEV_CFG(dev))->base)
((volatile struct _uart *) \
((const struct uart_device_config * const)(dev)->config)->base)
/* registers */
#define UARTDR(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0x000)))
#define UARTSR(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0x004)))
#define UARTCR(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0x004)))
#define UARTFR(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0x018)))
#define UARTILPR(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0x020)))
#define UARTIBRD(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0x024)))
#define UARTFBRD(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0x028)))
#define UARTLCRH(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0x02C)))
#define UARTCTL(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0x030)))
#define UARTIFLS(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0x034)))
#define UARTIM(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0x038)))
#define UARTRIS(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0x03C)))
#define UARTMIS(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0x040)))
#define UARTICR(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0x044)))
#define UARTDR(dev) (*((volatile uint32_t *)(UART_STRUCT(dev) + 0x000)))
#define UARTSR(dev) (*((volatile uint32_t *)(UART_STRUCT(dev) + 0x004)))
#define UARTCR(dev) (*((volatile uint32_t *)(UART_STRUCT(dev) + 0x004)))
#define UARTFR(dev) (*((volatile uint32_t *)(UART_STRUCT(dev) + 0x018)))
#define UARTILPR(dev) (*((volatile uint32_t *)(UART_STRUCT(dev) + 0x020)))
#define UARTIBRD(dev) (*((volatile uint32_t *)(UART_STRUCT(dev) + 0x024)))
#define UARTFBRD(dev) (*((volatile uint32_t *)(UART_STRUCT(dev) + 0x028)))
#define UARTLCRH(dev) (*((volatile uint32_t *)(UART_STRUCT(dev) + 0x02C)))
#define UARTCTL(dev) (*((volatile uint32_t *)(UART_STRUCT(dev) + 0x030)))
#define UARTIFLS(dev) (*((volatile uint32_t *)(UART_STRUCT(dev) + 0x034)))
#define UARTIM(dev) (*((volatile uint32_t *)(UART_STRUCT(dev) + 0x038)))
#define UARTRIS(dev) (*((volatile uint32_t *)(UART_STRUCT(dev) + 0x03C)))
#define UARTMIS(dev) (*((volatile uint32_t *)(UART_STRUCT(dev) + 0x040)))
#define UARTICR(dev) (*((volatile uint32_t *)(UART_STRUCT(dev) + 0x044)))
/* ID registers: UARTPID = UARTPeriphID, UARTPCID = UARTPCellId */
#define UARTPID4(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0xFD0)))
#define UARTPID5(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0xFD4)))
#define UARTPID6(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0xFD8)))
#define UARTPID7(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0xFDC)))
#define UARTPID0(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0xFE0)))
#define UARTPID1(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0xFE4)))
#define UARTPID2(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0xFE8)))
#define UARTPID3(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0xFEC)))
#define UARTPCID0(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0xFF0)))
#define UARTPCID1(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0xFF4)))
#define UARTPCID2(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0xFF8)))
#define UARTPCID3(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0xFFC)))
#define UARTPID4(dev) (*((volatile uint32_t *)(UART_STRUCT(dev) + 0xFD0)))
#define UARTPID5(dev) (*((volatile uint32_t *)(UART_STRUCT(dev) + 0xFD4)))
#define UARTPID6(dev) (*((volatile uint32_t *)(UART_STRUCT(dev) + 0xFD8)))
#define UARTPID7(dev) (*((volatile uint32_t *)(UART_STRUCT(dev) + 0xFDC)))
#define UARTPID0(dev) (*((volatile uint32_t *)(UART_STRUCT(dev) + 0xFE0)))
#define UARTPID1(dev) (*((volatile uint32_t *)(UART_STRUCT(dev) + 0xFE4)))
#define UARTPID2(dev) (*((volatile uint32_t *)(UART_STRUCT(dev) + 0xFE8)))
#define UARTPID3(dev) (*((volatile uint32_t *)(UART_STRUCT(dev) + 0xFEC)))
#define UARTPCID0(dev) (*((volatile uint32_t *)(UART_STRUCT(dev) + 0xFF0)))
#define UARTPCID1(dev) (*((volatile uint32_t *)(UART_STRUCT(dev) + 0xFF4)))
#define UARTPCID2(dev) (*((volatile uint32_t *)(UART_STRUCT(dev) + 0xFF8)))
#define UARTPCID3(dev) (*((volatile uint32_t *)(UART_STRUCT(dev) + 0xFFC)))
/* muxed UART registers */
#define sr u1._sr /* Read: receive status */
@ -256,14 +251,16 @@ static inline void line_control_defaults_set(const struct device *dev)
*/
static int uart_stellaris_init(const struct device *dev)
{
struct uart_stellaris_dev_data_t *data = dev->data;
const struct uart_device_config *config = dev->config;
disable(dev);
baudrate_set(dev, DEV_DATA(dev)->baud_rate,
DEV_CFG(dev)->sys_clk_freq);
baudrate_set(dev, data->baud_rate,
config->sys_clk_freq);
line_control_defaults_set(dev);
enable(dev);
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
DEV_CFG(dev)->irq_config_func(dev);
config->irq_config_func(dev);
#endif
return 0;
@ -556,7 +553,7 @@ static void uart_stellaris_irq_callback_set(const struct device *dev,
uart_irq_callback_user_data_t cb,
void *cb_data)
{
struct uart_stellaris_dev_data_t * const dev_data = DEV_DATA(dev);
struct uart_stellaris_dev_data_t * const dev_data = dev->data;
dev_data->cb = cb;
dev_data->cb_data = cb_data;
@ -571,7 +568,7 @@ static void uart_stellaris_irq_callback_set(const struct device *dev,
*/
static void uart_stellaris_isr(const struct device *dev)
{
struct uart_stellaris_dev_data_t * const dev_data = DEV_DATA(dev);
struct uart_stellaris_dev_data_t * const dev_data = dev->data;
if (dev_data->cb) {
dev_data->cb(dev, dev_data->cb_data);

View file

@ -41,13 +41,9 @@ LOG_MODULE_REGISTER(uart_stm32);
#define HAS_LPUART_1 (DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(lpuart1), \
st_stm32_lpuart, okay))
/* convenience defines */
#define DEV_CFG(dev) \
((const struct uart_stm32_config *const)(dev)->config)
#define DEV_DATA(dev) \
((struct uart_stm32_data *const)(dev)->data)
#define UART_STRUCT(dev) \
((USART_TypeDef *)(DEV_CFG(dev))->uconf.base)
((USART_TypeDef *) \
((const struct uart_stm32_config *const)(dev)->config)->uconf.base)
#if HAS_LPUART_1
#ifdef USART_PRESC_PRESCALER
@ -82,7 +78,7 @@ uint32_t lpuartdiv_calc(const uint64_t clock_rate, const uint32_t baud_rate)
#ifdef CONFIG_PM
static void uart_stm32_pm_constraint_set(const struct device *dev)
{
struct uart_stm32_data *data = DEV_DATA(dev);
struct uart_stm32_data *data = dev->data;
if (!data->pm_constraint_on) {
data->pm_constraint_on = true;
@ -92,7 +88,7 @@ static void uart_stm32_pm_constraint_set(const struct device *dev)
static void uart_stm32_pm_constraint_release(const struct device *dev)
{
struct uart_stm32_data *data = DEV_DATA(dev);
struct uart_stm32_data *data = dev->data;
if (data->pm_constraint_on) {
data->pm_constraint_on = false;
@ -104,8 +100,8 @@ static void uart_stm32_pm_constraint_release(const struct device *dev)
static inline void uart_stm32_set_baudrate(const struct device *dev,
uint32_t baud_rate)
{
const struct uart_stm32_config *config = DEV_CFG(dev);
struct uart_stm32_data *data = DEV_DATA(dev);
const struct uart_stm32_config *config = dev->config;
struct uart_stm32_data *data = dev->data;
USART_TypeDef *UartInstance = UART_STRUCT(dev);
uint32_t clock_rate;
@ -399,7 +395,7 @@ static inline enum uart_config_flow_control uart_stm32_ll2cfg_hwctrl(uint32_t fc
static int uart_stm32_configure(const struct device *dev,
const struct uart_config *cfg)
{
struct uart_stm32_data *data = DEV_DATA(dev);
struct uart_stm32_data *data = dev->data;
USART_TypeDef *UartInstance = UART_STRUCT(dev);
const uint32_t parity = uart_stm32_cfg2ll_parity(cfg->parity);
const uint32_t stopbits = uart_stm32_cfg2ll_stopbits(cfg->stop_bits);
@ -489,7 +485,7 @@ static int uart_stm32_configure(const struct device *dev,
static int uart_stm32_config_get(const struct device *dev,
struct uart_config *cfg)
{
struct uart_stm32_data *data = DEV_DATA(dev);
struct uart_stm32_data *data = dev->data;
cfg->baudrate = data->baud_rate;
cfg->parity = uart_stm32_ll2cfg_parity(uart_stm32_get_parity(dev));
@ -526,7 +522,7 @@ static void uart_stm32_poll_out(const struct device *dev,
{
USART_TypeDef *UartInstance = UART_STRUCT(dev);
#ifdef CONFIG_PM
struct uart_stm32_data *data = DEV_DATA(dev);
struct uart_stm32_data *data = dev->data;
#endif
int key;
@ -612,7 +608,7 @@ static int uart_stm32_err_check(const struct device *dev)
static inline void __uart_stm32_get_clock(const struct device *dev)
{
struct uart_stm32_data *data = DEV_DATA(dev);
struct uart_stm32_data *data = dev->data;
const struct device *clk = DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE);
data->clock = clk;
@ -674,7 +670,7 @@ static void uart_stm32_irq_tx_enable(const struct device *dev)
{
USART_TypeDef *UartInstance = UART_STRUCT(dev);
#ifdef CONFIG_PM
struct uart_stm32_data *data = DEV_DATA(dev);
struct uart_stm32_data *data = dev->data;
int key;
#endif
@ -695,7 +691,7 @@ static void uart_stm32_irq_tx_disable(const struct device *dev)
{
USART_TypeDef *UartInstance = UART_STRUCT(dev);
#ifdef CONFIG_PM
struct uart_stm32_data *data = DEV_DATA(dev);
struct uart_stm32_data *data = dev->data;
int key;
key = irq_lock();
@ -800,7 +796,7 @@ static void uart_stm32_irq_callback_set(const struct device *dev,
uart_irq_callback_user_data_t cb,
void *cb_data)
{
struct uart_stm32_data *data = DEV_DATA(dev);
struct uart_stm32_data *data = dev->data;
data->user_cb = cb;
data->user_data = cb_data;
@ -919,7 +915,7 @@ static inline void async_timer_start(struct k_work_delayable *work,
static void uart_stm32_dma_rx_flush(const struct device *dev)
{
struct dma_status stat;
struct uart_stm32_data *data = DEV_DATA(dev);
struct uart_stm32_data *data = dev->data;
if (dma_get_status(data->dma_rx.dma_dev,
data->dma_rx.dma_channel, &stat) == 0) {
@ -941,7 +937,7 @@ static void uart_stm32_dma_rx_flush(const struct device *dev)
static void uart_stm32_isr(const struct device *dev)
{
struct uart_stm32_data *data = DEV_DATA(dev);
struct uart_stm32_data *data = dev->data;
#if defined(CONFIG_PM) || defined(CONFIG_UART_ASYNC_API)
USART_TypeDef *UartInstance = UART_STRUCT(dev);
#endif
@ -1020,7 +1016,7 @@ static int uart_stm32_async_callback_set(const struct device *dev,
uart_callback_t callback,
void *user_data)
{
struct uart_stm32_data *data = DEV_DATA(dev);
struct uart_stm32_data *data = dev->data;
data->async_cb = callback;
data->async_user_data = user_data;
@ -1045,7 +1041,7 @@ static inline void uart_stm32_dma_tx_disable(const struct device *dev)
static inline void uart_stm32_dma_rx_enable(const struct device *dev)
{
USART_TypeDef *UartInstance = UART_STRUCT(dev);
struct uart_stm32_data *data = DEV_DATA(dev);
struct uart_stm32_data *data = dev->data;
LL_USART_EnableDMAReq_RX(UartInstance);
@ -1054,14 +1050,14 @@ static inline void uart_stm32_dma_rx_enable(const struct device *dev)
static inline void uart_stm32_dma_rx_disable(const struct device *dev)
{
struct uart_stm32_data *data = DEV_DATA(dev);
struct uart_stm32_data *data = dev->data;
data->dma_rx.enabled = false;
}
static int uart_stm32_async_rx_disable(const struct device *dev)
{
struct uart_stm32_data *data = DEV_DATA(dev);
struct uart_stm32_data *data = dev->data;
USART_TypeDef *UartInstance = UART_STRUCT(dev);
struct uart_event disabled_event = {
.type = UART_RX_DISABLED
@ -1101,7 +1097,7 @@ void uart_stm32_dma_tx_cb(const struct device *dma_dev, void *user_data,
uint32_t channel, int status)
{
const struct device *uart_dev = user_data;
struct uart_stm32_data *data = DEV_DATA(uart_dev);
struct uart_stm32_data *data = uart_dev->data;
struct dma_status stat;
unsigned int key = irq_lock();
@ -1123,7 +1119,7 @@ void uart_stm32_dma_tx_cb(const struct device *dma_dev, void *user_data,
static void uart_stm32_dma_replace_buffer(const struct device *dev)
{
struct uart_stm32_data *data = DEV_DATA(dev);
struct uart_stm32_data *data = dev->data;
/* Replace the buffer and relod the DMA */
LOG_DBG("Replacing RX buffer: %d", data->rx_next_buffer_len);
@ -1157,7 +1153,7 @@ void uart_stm32_dma_rx_cb(const struct device *dma_dev, void *user_data,
uint32_t channel, int status)
{
const struct device *uart_dev = user_data;
struct uart_stm32_data *data = DEV_DATA(uart_dev);
struct uart_stm32_data *data = uart_dev->data;
if (status != 0) {
async_evt_rx_err(data, status);
@ -1193,7 +1189,7 @@ void uart_stm32_dma_rx_cb(const struct device *dma_dev, void *user_data,
static int uart_stm32_async_tx(const struct device *dev,
const uint8_t *tx_data, size_t buf_size, int32_t timeout)
{
struct uart_stm32_data *data = DEV_DATA(dev);
struct uart_stm32_data *data = dev->data;
USART_TypeDef *UartInstance = UART_STRUCT(dev);
int ret;
@ -1252,7 +1248,7 @@ static int uart_stm32_async_tx(const struct device *dev,
static int uart_stm32_async_rx_enable(const struct device *dev,
uint8_t *rx_buf, size_t buf_size, int32_t timeout)
{
struct uart_stm32_data *data = DEV_DATA(dev);
struct uart_stm32_data *data = dev->data;
USART_TypeDef *UartInstance = UART_STRUCT(dev);
int ret;
@ -1311,7 +1307,7 @@ static int uart_stm32_async_rx_enable(const struct device *dev,
static int uart_stm32_async_tx_abort(const struct device *dev)
{
struct uart_stm32_data *data = DEV_DATA(dev);
struct uart_stm32_data *data = dev->data;
size_t tx_buffer_length = data->dma_tx.buffer_length;
struct dma_status stat;
@ -1364,7 +1360,7 @@ static void uart_stm32_async_tx_timeout(struct k_work *work)
static int uart_stm32_async_rx_buf_rsp(const struct device *dev, uint8_t *buf,
size_t len)
{
struct uart_stm32_data *data = DEV_DATA(dev);
struct uart_stm32_data *data = dev->data;
LOG_DBG("replace buffer (%d)", len);
data->rx_next_buffer = buf;
@ -1375,7 +1371,7 @@ static int uart_stm32_async_rx_buf_rsp(const struct device *dev, uint8_t *buf,
static int uart_stm32_async_init(const struct device *dev)
{
struct uart_stm32_data *data = DEV_DATA(dev);
struct uart_stm32_data *data = dev->data;
USART_TypeDef *UartInstance = UART_STRUCT(dev);
data->uart_dev = dev;
@ -1525,8 +1521,8 @@ static const struct uart_driver_api uart_stm32_driver_api = {
*/
static int uart_stm32_init(const struct device *dev)
{
const struct uart_stm32_config *config = DEV_CFG(dev);
struct uart_stm32_data *data = DEV_DATA(dev);
const struct uart_stm32_config *config = dev->config;
struct uart_stm32_data *data = dev->data;
USART_TypeDef *UartInstance = UART_STRUCT(dev);
uint32_t ll_parity;
uint32_t ll_datawidth;

View file

@ -150,12 +150,6 @@ struct uart_xlnx_ps_dev_data_t {
#endif
};
#define DEV_CFG(dev) \
((const struct uart_xlnx_ps_dev_config * const) \
(dev)->config)
#define DEV_DATA(dev) \
((struct uart_xlnx_ps_dev_data_t *)(dev)->data)
static const struct uart_driver_api uart_xlnx_ps_driver_api;
/**
@ -224,7 +218,7 @@ static void xlnx_ps_enable_uart(uint32_t reg_base)
*/
static void set_baudrate(const struct device *dev, uint32_t baud_rate)
{
const struct uart_xlnx_ps_dev_config *dev_cfg = DEV_CFG(dev);
const struct uart_xlnx_ps_dev_config *dev_cfg = dev->config;
uint32_t divisor, generator;
uint32_t baud;
uint32_t clk_freq;
@ -283,7 +277,7 @@ static void set_baudrate(const struct device *dev, uint32_t baud_rate)
*/
static int uart_xlnx_ps_init(const struct device *dev)
{
const struct uart_xlnx_ps_dev_config *dev_cfg = DEV_CFG(dev);
const struct uart_xlnx_ps_dev_config *dev_cfg = dev->config;
uint32_t reg_val;
uint32_t reg_base;
@ -334,7 +328,7 @@ static int uart_xlnx_ps_init(const struct device *dev)
*/
static int uart_xlnx_ps_poll_in(const struct device *dev, unsigned char *c)
{
const struct uart_xlnx_ps_dev_config *dev_cfg = DEV_CFG(dev);
const struct uart_xlnx_ps_dev_config *dev_cfg = dev->config;
uint32_t reg_val;
uint32_t reg_base;
@ -365,7 +359,7 @@ static int uart_xlnx_ps_poll_in(const struct device *dev, unsigned char *c)
*/
static void uart_xlnx_ps_poll_out(const struct device *dev, unsigned char c)
{
const struct uart_xlnx_ps_dev_config *dev_cfg = DEV_CFG(dev);
const struct uart_xlnx_ps_dev_config *dev_cfg = dev->config;
uint32_t reg_val;
uint32_t reg_base;
@ -597,7 +591,7 @@ static int uart_xlnx_ps_configure(const struct device *dev,
const struct uart_config *cfg)
{
struct uart_xlnx_ps_dev_config *dev_cfg =
(struct uart_xlnx_ps_dev_config *)DEV_CFG(dev);
(struct uart_xlnx_ps_dev_config *)dev->config;
uint32_t reg_base = dev_cfg->uconf.regs;
uint32_t mode_reg = 0;
@ -803,7 +797,7 @@ static inline enum uart_config_flow_control uart_xlnx_ps_ll2cfg_hwctrl(
static int uart_xlnx_ps_config_get(const struct device *dev,
struct uart_config *cfg)
{
const struct uart_xlnx_ps_dev_config *dev_cfg = DEV_CFG(dev);
const struct uart_xlnx_ps_dev_config *dev_cfg = dev->config;
/*
* Read the Mode & Modem control registers - they contain
@ -841,7 +835,7 @@ static int uart_xlnx_ps_fifo_fill(const struct device *dev,
const uint8_t *tx_data,
int size)
{
const struct uart_xlnx_ps_dev_config *dev_cfg = DEV_CFG(dev);
const struct uart_xlnx_ps_dev_config *dev_cfg = dev->config;
uint32_t reg_base = dev_cfg->uconf.regs;
uint32_t data_iter = 0;
@ -868,7 +862,7 @@ static int uart_xlnx_ps_fifo_fill(const struct device *dev,
static int uart_xlnx_ps_fifo_read(const struct device *dev, uint8_t *rx_data,
const int size)
{
const struct uart_xlnx_ps_dev_config *dev_cfg = DEV_CFG(dev);
const struct uart_xlnx_ps_dev_config *dev_cfg = dev->config;
uint32_t reg_val;
uint32_t reg_base;
int inum = 0;
@ -893,7 +887,7 @@ static int uart_xlnx_ps_fifo_read(const struct device *dev, uint8_t *rx_data,
*/
static void uart_xlnx_ps_irq_tx_enable(const struct device *dev)
{
const struct uart_xlnx_ps_dev_config *dev_cfg = DEV_CFG(dev);
const struct uart_xlnx_ps_dev_config *dev_cfg = dev->config;
uint32_t reg_base;
reg_base = dev_cfg->uconf.regs;
@ -909,7 +903,7 @@ static void uart_xlnx_ps_irq_tx_enable(const struct device *dev)
*/
static void uart_xlnx_ps_irq_tx_disable(const struct device *dev)
{
const struct uart_xlnx_ps_dev_config *dev_cfg = DEV_CFG(dev);
const struct uart_xlnx_ps_dev_config *dev_cfg = dev->config;
uint32_t reg_base;
reg_base = dev_cfg->uconf.regs;
@ -927,7 +921,7 @@ static void uart_xlnx_ps_irq_tx_disable(const struct device *dev)
*/
static int uart_xlnx_ps_irq_tx_ready(const struct device *dev)
{
const struct uart_xlnx_ps_dev_config *dev_cfg = DEV_CFG(dev);
const struct uart_xlnx_ps_dev_config *dev_cfg = dev->config;
uint32_t reg_base = dev_cfg->uconf.regs;
uint32_t reg_val = sys_read32(reg_base + XUARTPS_SR_OFFSET);
@ -947,7 +941,7 @@ static int uart_xlnx_ps_irq_tx_ready(const struct device *dev)
*/
static int uart_xlnx_ps_irq_tx_complete(const struct device *dev)
{
const struct uart_xlnx_ps_dev_config *dev_cfg = DEV_CFG(dev);
const struct uart_xlnx_ps_dev_config *dev_cfg = dev->config;
uint32_t reg_base;
uint32_t reg_val;
@ -967,7 +961,7 @@ static int uart_xlnx_ps_irq_tx_complete(const struct device *dev)
*/
static void uart_xlnx_ps_irq_rx_enable(const struct device *dev)
{
const struct uart_xlnx_ps_dev_config *dev_cfg = DEV_CFG(dev);
const struct uart_xlnx_ps_dev_config *dev_cfg = dev->config;
uint32_t reg_base;
reg_base = dev_cfg->uconf.regs;
@ -981,7 +975,7 @@ static void uart_xlnx_ps_irq_rx_enable(const struct device *dev)
*/
static void uart_xlnx_ps_irq_rx_disable(const struct device *dev)
{
const struct uart_xlnx_ps_dev_config *dev_cfg = DEV_CFG(dev);
const struct uart_xlnx_ps_dev_config *dev_cfg = dev->config;
uint32_t reg_base;
reg_base = dev_cfg->uconf.regs;
@ -997,7 +991,7 @@ static void uart_xlnx_ps_irq_rx_disable(const struct device *dev)
*/
static int uart_xlnx_ps_irq_rx_ready(const struct device *dev)
{
const struct uart_xlnx_ps_dev_config *dev_cfg = DEV_CFG(dev);
const struct uart_xlnx_ps_dev_config *dev_cfg = dev->config;
uint32_t reg_base = dev_cfg->uconf.regs;
uint32_t reg_val = sys_read32(reg_base + XUARTPS_ISR_OFFSET);
@ -1016,7 +1010,7 @@ static int uart_xlnx_ps_irq_rx_ready(const struct device *dev)
*/
static void uart_xlnx_ps_irq_err_enable(const struct device *dev)
{
const struct uart_xlnx_ps_dev_config *dev_cfg = DEV_CFG(dev);
const struct uart_xlnx_ps_dev_config *dev_cfg = dev->config;
uint32_t reg_base;
reg_base = dev_cfg->uconf.regs;
@ -1038,7 +1032,7 @@ static void uart_xlnx_ps_irq_err_enable(const struct device *dev)
*/
static void uart_xlnx_ps_irq_err_disable(const struct device *dev)
{
const struct uart_xlnx_ps_dev_config *dev_cfg = DEV_CFG(dev);
const struct uart_xlnx_ps_dev_config *dev_cfg = dev->config;
uint32_t reg_base;
reg_base = dev_cfg->uconf.regs;
@ -1060,7 +1054,7 @@ static void uart_xlnx_ps_irq_err_disable(const struct device *dev)
*/
static int uart_xlnx_ps_irq_is_pending(const struct device *dev)
{
const struct uart_xlnx_ps_dev_config *dev_cfg = DEV_CFG(dev);
const struct uart_xlnx_ps_dev_config *dev_cfg = dev->config;
uint32_t reg_base;
uint32_t reg_imr;
uint32_t reg_isr;
@ -1099,7 +1093,7 @@ static void uart_xlnx_ps_irq_callback_set(const struct device *dev,
uart_irq_callback_user_data_t cb,
void *cb_data)
{
struct uart_xlnx_ps_dev_data_t *dev_data = DEV_DATA(dev);
struct uart_xlnx_ps_dev_data_t *dev_data = dev->data;
dev_data->user_cb = cb;
dev_data->user_data = cb_data;
@ -1114,7 +1108,7 @@ static void uart_xlnx_ps_irq_callback_set(const struct device *dev,
*/
static void uart_xlnx_ps_isr(const struct device *dev)
{
const struct uart_xlnx_ps_dev_data_t *data = DEV_DATA(dev);
const struct uart_xlnx_ps_dev_data_t *data = dev->data;
if (data->user_cb) {
data->user_cb(dev, data->user_data);

View file

@ -15,14 +15,9 @@ struct uart_xmc4xxx_data {
XMC_UART_CH_CONFIG_t config;
};
#define DEV_CFG(dev) \
((const struct uart_device_config * const)(dev)->config)
#define DEV_DATA(dev) \
((struct uart_xmc4xxx_data * const)(dev)->data)
static int uart_xmc4xxx_poll_in(const struct device *dev, unsigned char *c)
{
const struct uart_device_config *config = DEV_CFG(dev);
const struct uart_device_config *config = dev->config;
*(uint16_t *)c =
XMC_UART_CH_GetReceivedData((XMC_USIC_CH_t *)config->base);
@ -32,15 +27,15 @@ static int uart_xmc4xxx_poll_in(const struct device *dev, unsigned char *c)
static void uart_xmc4xxx_poll_out(const struct device *dev, unsigned char c)
{
const struct uart_device_config *config = DEV_CFG(dev);
const struct uart_device_config *config = dev->config;
XMC_UART_CH_Transmit((XMC_USIC_CH_t *)config->base, (uint16_t)c);
}
static int uart_xmc4xxx_init(const struct device *dev)
{
const struct uart_device_config *config = DEV_CFG(dev);
struct uart_xmc4xxx_data *data = DEV_DATA(dev);
const struct uart_device_config *config = dev->config;
struct uart_xmc4xxx_data *data = dev->data;
XMC_USIC_CH_t *uart = (XMC_USIC_CH_t *)config->base;
data->config.data_bits = 8U;

View file

@ -43,12 +43,6 @@ struct usart_sam_dev_data {
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */
};
#define DEV_CFG(dev) \
((const struct usart_sam_dev_cfg *const)(dev)->config)
#define DEV_DATA(dev) \
((struct usart_sam_dev_data *const)(dev)->data)
static int baudrate_set(Usart *const usart, uint32_t baudrate,
uint32_t mck_freq_hz);
@ -56,8 +50,8 @@ static int baudrate_set(Usart *const usart, uint32_t baudrate,
static int usart_sam_init(const struct device *dev)
{
int retval;
const struct usart_sam_dev_cfg *const cfg = DEV_CFG(dev);
struct usart_sam_dev_data *const dev_data = DEV_DATA(dev);
const struct usart_sam_dev_cfg *const cfg = dev->config;
struct usart_sam_dev_data *const dev_data = dev->data;
Usart *const usart = cfg->regs;
/* Enable USART clock in PMC */
@ -100,7 +94,8 @@ static int usart_sam_init(const struct device *dev)
static int usart_sam_poll_in(const struct device *dev, unsigned char *c)
{
Usart *const usart = DEV_CFG(dev)->regs;
const struct usart_sam_dev_cfg *config = dev->config;
Usart *const usart = config->regs;
if (!(usart->US_CSR & US_CSR_RXRDY)) {
return -EBUSY;
@ -114,7 +109,9 @@ static int usart_sam_poll_in(const struct device *dev, unsigned char *c)
static void usart_sam_poll_out(const struct device *dev, unsigned char c)
{
Usart *const usart = DEV_CFG(dev)->regs;
const struct usart_sam_dev_cfg *config = dev->config;
Usart *const usart = config->regs;
/* Wait for transmitter to be ready */
while (!(usart->US_CSR & US_CSR_TXRDY)) {
@ -126,7 +123,9 @@ static void usart_sam_poll_out(const struct device *dev, unsigned char c)
static int usart_sam_err_check(const struct device *dev)
{
volatile Usart * const usart = DEV_CFG(dev)->regs;
const struct usart_sam_dev_cfg *config = dev->config;
volatile Usart * const usart = config->regs;
int errors = 0;
if (usart->US_CSR & US_CSR_OVRE) {
@ -171,7 +170,9 @@ static int usart_sam_fifo_fill(const struct device *dev,
const uint8_t *tx_data,
int size)
{
volatile Usart * const usart = DEV_CFG(dev)->regs;
const struct usart_sam_dev_cfg *config = dev->config;
volatile Usart * const usart = config->regs;
/* Wait for transmitter to be ready. */
while ((usart->US_CSR & US_CSR_TXRDY) == 0) {
@ -185,7 +186,9 @@ static int usart_sam_fifo_fill(const struct device *dev,
static int usart_sam_fifo_read(const struct device *dev, uint8_t *rx_data,
const int size)
{
volatile Usart * const usart = DEV_CFG(dev)->regs;
const struct usart_sam_dev_cfg *config = dev->config;
volatile Usart * const usart = config->regs;
int bytes_read;
bytes_read = 0;
@ -204,70 +207,90 @@ static int usart_sam_fifo_read(const struct device *dev, uint8_t *rx_data,
static void usart_sam_irq_tx_enable(const struct device *dev)
{
volatile Usart * const usart = DEV_CFG(dev)->regs;
const struct usart_sam_dev_cfg *config = dev->config;
volatile Usart * const usart = config->regs;
usart->US_IER = US_IER_TXRDY;
}
static void usart_sam_irq_tx_disable(const struct device *dev)
{
volatile Usart * const usart = DEV_CFG(dev)->regs;
const struct usart_sam_dev_cfg *config = dev->config;
volatile Usart * const usart = config->regs;
usart->US_IDR = US_IDR_TXRDY;
}
static int usart_sam_irq_tx_ready(const struct device *dev)
{
volatile Usart * const usart = DEV_CFG(dev)->regs;
const struct usart_sam_dev_cfg *config = dev->config;
volatile Usart * const usart = config->regs;
return (usart->US_CSR & US_CSR_TXRDY);
}
static void usart_sam_irq_rx_enable(const struct device *dev)
{
volatile Usart * const usart = DEV_CFG(dev)->regs;
const struct usart_sam_dev_cfg *config = dev->config;
volatile Usart * const usart = config->regs;
usart->US_IER = US_IER_RXRDY;
}
static void usart_sam_irq_rx_disable(const struct device *dev)
{
volatile Usart * const usart = DEV_CFG(dev)->regs;
const struct usart_sam_dev_cfg *config = dev->config;
volatile Usart * const usart = config->regs;
usart->US_IDR = US_IDR_RXRDY;
}
static int usart_sam_irq_tx_complete(const struct device *dev)
{
volatile Usart * const usart = DEV_CFG(dev)->regs;
const struct usart_sam_dev_cfg *config = dev->config;
volatile Usart * const usart = config->regs;
return !(usart->US_CSR & US_CSR_TXRDY);
}
static int usart_sam_irq_rx_ready(const struct device *dev)
{
volatile Usart * const usart = DEV_CFG(dev)->regs;
const struct usart_sam_dev_cfg *config = dev->config;
volatile Usart * const usart = config->regs;
return (usart->US_CSR & US_CSR_RXRDY);
}
static void usart_sam_irq_err_enable(const struct device *dev)
{
volatile Usart * const usart = DEV_CFG(dev)->regs;
const struct usart_sam_dev_cfg *config = dev->config;
volatile Usart * const usart = config->regs;
usart->US_IER = US_IER_OVRE | US_IER_FRAME | US_IER_PARE;
}
static void usart_sam_irq_err_disable(const struct device *dev)
{
volatile Usart * const usart = DEV_CFG(dev)->regs;
const struct usart_sam_dev_cfg *config = dev->config;
volatile Usart * const usart = config->regs;
usart->US_IDR = US_IDR_OVRE | US_IDR_FRAME | US_IDR_PARE;
}
static int usart_sam_irq_is_pending(const struct device *dev)
{
volatile Usart * const usart = DEV_CFG(dev)->regs;
const struct usart_sam_dev_cfg *config = dev->config;
volatile Usart * const usart = config->regs;
return (usart->US_IMR & (US_IMR_TXRDY | US_IMR_RXRDY)) &
(usart->US_CSR & (US_CSR_TXRDY | US_CSR_RXRDY));
@ -284,7 +307,7 @@ static void usart_sam_irq_callback_set(const struct device *dev,
uart_irq_callback_user_data_t cb,
void *cb_data)
{
struct usart_sam_dev_data *const dev_data = DEV_DATA(dev);
struct usart_sam_dev_data *const dev_data = dev->data;
dev_data->irq_cb = cb;
dev_data->cb_data = cb_data;
@ -292,7 +315,7 @@ static void usart_sam_irq_callback_set(const struct device *dev,
static void usart_sam_isr(const struct device *dev)
{
struct usart_sam_dev_data *const dev_data = DEV_DATA(dev);
struct usart_sam_dev_data *const dev_data = dev->data;
if (dev_data->irq_cb) {
dev_data->irq_cb(dev, dev_data->cb_data);