drivers: serial: drop get_dev_data/get_dev_config usage
Replace all get_dev_data()/get_dev_config() accessor utilities with dev->data and dev->config. Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
parent
2c103a25cc
commit
a6614968a8
4 changed files with 181 additions and 163 deletions
|
@ -38,24 +38,16 @@ struct uart_cc13xx_cc26xx_data {
|
|||
#endif
|
||||
};
|
||||
|
||||
static inline struct uart_cc13xx_cc26xx_data *get_dev_data(const struct device *dev)
|
||||
{
|
||||
return dev->data;
|
||||
}
|
||||
|
||||
static inline const struct uart_device_config *get_dev_conf(const struct device *dev)
|
||||
{
|
||||
return dev->config;
|
||||
}
|
||||
|
||||
static int uart_cc13xx_cc26xx_poll_in(const struct device *dev,
|
||||
unsigned char *c)
|
||||
{
|
||||
if (!UARTCharsAvail(get_dev_conf(dev)->regs)) {
|
||||
const struct uart_device_config *config = dev->config;
|
||||
|
||||
if (!UARTCharsAvail(config->regs)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
*c = UARTCharGetNonBlocking(get_dev_conf(dev)->regs);
|
||||
*c = UARTCharGetNonBlocking(config->regs);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -63,25 +55,29 @@ static int uart_cc13xx_cc26xx_poll_in(const struct device *dev,
|
|||
static void uart_cc13xx_cc26xx_poll_out(const struct device *dev,
|
||||
unsigned char c)
|
||||
{
|
||||
UARTCharPut(get_dev_conf(dev)->regs, c);
|
||||
const struct uart_device_config *config = dev->config;
|
||||
|
||||
UARTCharPut(config->regs, c);
|
||||
/*
|
||||
* Need to wait for character to be transmitted to ensure cpu does not
|
||||
* enter standby when uart is busy
|
||||
*/
|
||||
while (UARTBusy(get_dev_conf(dev)->regs) == true) {
|
||||
while (UARTBusy(config->regs) == true) {
|
||||
}
|
||||
}
|
||||
|
||||
static int uart_cc13xx_cc26xx_err_check(const struct device *dev)
|
||||
{
|
||||
uint32_t flags = UARTRxErrorGet(get_dev_conf(dev)->regs);
|
||||
const struct uart_device_config *config = dev->config;
|
||||
|
||||
uint32_t flags = UARTRxErrorGet(config->regs);
|
||||
|
||||
int error = (flags & UART_RXERROR_FRAMING ? UART_ERROR_FRAMING : 0) |
|
||||
(flags & UART_RXERROR_PARITY ? UART_ERROR_PARITY : 0) |
|
||||
(flags & UART_RXERROR_BREAK ? UART_BREAK : 0) |
|
||||
(flags & UART_RXERROR_OVERRUN ? UART_ERROR_OVERRUN : 0);
|
||||
|
||||
UARTRxErrorClear(get_dev_conf(dev)->regs);
|
||||
UARTRxErrorClear(config->regs);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
@ -89,6 +85,8 @@ static int uart_cc13xx_cc26xx_err_check(const struct device *dev)
|
|||
static int uart_cc13xx_cc26xx_configure(const struct device *dev,
|
||||
const struct uart_config *cfg)
|
||||
{
|
||||
const struct uart_device_config *config = dev->config;
|
||||
struct uart_cc13xx_cc26xx_data *data = dev->data;
|
||||
uint32_t line_ctrl = 0;
|
||||
bool flow_ctrl;
|
||||
|
||||
|
@ -157,29 +155,29 @@ static int uart_cc13xx_cc26xx_configure(const struct device *dev,
|
|||
}
|
||||
|
||||
/* Disables UART before setting control registers */
|
||||
UARTConfigSetExpClk(get_dev_conf(dev)->regs,
|
||||
get_dev_conf(dev)->sys_clk_freq, cfg->baudrate,
|
||||
UARTConfigSetExpClk(config->regs,
|
||||
config->sys_clk_freq, cfg->baudrate,
|
||||
line_ctrl);
|
||||
|
||||
/* Clear all UART interrupts */
|
||||
UARTIntClear(get_dev_conf(dev)->regs,
|
||||
UARTIntClear(config->regs,
|
||||
UART_INT_OE | UART_INT_BE | UART_INT_PE |
|
||||
UART_INT_FE | UART_INT_RT | UART_INT_TX |
|
||||
UART_INT_RX | UART_INT_CTS);
|
||||
|
||||
if (flow_ctrl) {
|
||||
UARTHwFlowControlEnable(get_dev_conf(dev)->regs);
|
||||
UARTHwFlowControlEnable(config->regs);
|
||||
} else {
|
||||
UARTHwFlowControlDisable(get_dev_conf(dev)->regs);
|
||||
UARTHwFlowControlDisable(config->regs);
|
||||
}
|
||||
|
||||
/* Re-enable UART */
|
||||
UARTEnable(get_dev_conf(dev)->regs);
|
||||
UARTEnable(config->regs);
|
||||
|
||||
/* Disabled FIFOs act as 1-byte-deep holding registers (character mode) */
|
||||
UARTFIFODisable(get_dev_conf(dev)->regs);
|
||||
UARTFIFODisable(config->regs);
|
||||
|
||||
get_dev_data(dev)->uart_config = *cfg;
|
||||
data->uart_config = *cfg;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -188,7 +186,9 @@ static int uart_cc13xx_cc26xx_configure(const struct device *dev,
|
|||
static int uart_cc13xx_cc26xx_config_get(const struct device *dev,
|
||||
struct uart_config *cfg)
|
||||
{
|
||||
*cfg = get_dev_data(dev)->uart_config;
|
||||
struct uart_cc13xx_cc26xx_data *data = dev->data;
|
||||
|
||||
*cfg = data->uart_config;
|
||||
return 0;
|
||||
}
|
||||
#endif /* CONFIG_UART_USE_RUNTIME_CONFIGURE */
|
||||
|
@ -199,10 +199,11 @@ static int uart_cc13xx_cc26xx_fifo_fill(const struct device *dev,
|
|||
const uint8_t *buf,
|
||||
int len)
|
||||
{
|
||||
const struct uart_device_config *config = dev->config;
|
||||
int n = 0;
|
||||
|
||||
while (n < len) {
|
||||
if (!UARTCharPutNonBlocking(get_dev_conf(dev)->regs, buf[n])) {
|
||||
if (!UARTCharPutNonBlocking(config->regs, buf[n])) {
|
||||
break;
|
||||
}
|
||||
n++;
|
||||
|
@ -215,11 +216,12 @@ static int uart_cc13xx_cc26xx_fifo_read(const struct device *dev,
|
|||
uint8_t *buf,
|
||||
const int len)
|
||||
{
|
||||
const struct uart_device_config *config = dev->config;
|
||||
int c, n;
|
||||
|
||||
n = 0;
|
||||
while (n < len) {
|
||||
c = UARTCharGetNonBlocking(get_dev_conf(dev)->regs);
|
||||
c = UARTCharGetNonBlocking(config->regs);
|
||||
if (c == -1) {
|
||||
break;
|
||||
}
|
||||
|
@ -231,8 +233,12 @@ static int uart_cc13xx_cc26xx_fifo_read(const struct device *dev,
|
|||
|
||||
static void uart_cc13xx_cc26xx_irq_tx_enable(const struct device *dev)
|
||||
{
|
||||
const struct uart_device_config *config = dev->config;
|
||||
|
||||
#ifdef CONFIG_PM
|
||||
if (!get_dev_data(dev)->tx_constrained) {
|
||||
struct uart_cc13xx_cc26xx_data *data = dev->data;
|
||||
|
||||
if (!data->tx_constrained) {
|
||||
/*
|
||||
* When tx irq is enabled, it is implicit that we are expecting
|
||||
* to transmit using the uart, hence we should no longer go
|
||||
|
@ -244,86 +250,109 @@ static void uart_cc13xx_cc26xx_irq_tx_enable(const struct device *dev)
|
|||
* would interfere with a transfer.
|
||||
*/
|
||||
pm_constraint_set(PM_STATE_STANDBY);
|
||||
get_dev_data(dev)->tx_constrained = true;
|
||||
data->tx_constrained = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
UARTIntEnable(get_dev_conf(dev)->regs, UART_INT_TX);
|
||||
UARTIntEnable(config->regs, UART_INT_TX);
|
||||
}
|
||||
|
||||
static void uart_cc13xx_cc26xx_irq_tx_disable(const struct device *dev)
|
||||
{
|
||||
UARTIntDisable(get_dev_conf(dev)->regs, UART_INT_TX);
|
||||
const struct uart_device_config *config = dev->config;
|
||||
|
||||
UARTIntDisable(config->regs, UART_INT_TX);
|
||||
|
||||
#ifdef CONFIG_PM
|
||||
if (get_dev_data(dev)->tx_constrained) {
|
||||
struct uart_cc13xx_cc26xx_data *data = dev->data;
|
||||
|
||||
if (data->tx_constrained) {
|
||||
pm_constraint_release(PM_STATE_STANDBY);
|
||||
get_dev_data(dev)->tx_constrained = false;
|
||||
data->tx_constrained = false;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static int uart_cc13xx_cc26xx_irq_tx_ready(const struct device *dev)
|
||||
{
|
||||
return UARTSpaceAvail(get_dev_conf(dev)->regs) ? 1 : 0;
|
||||
const struct uart_device_config *config = dev->config;
|
||||
|
||||
return UARTSpaceAvail(config->regs) ? 1 : 0;
|
||||
}
|
||||
|
||||
static void uart_cc13xx_cc26xx_irq_rx_enable(const struct device *dev)
|
||||
{
|
||||
const struct uart_device_config *config = dev->config;
|
||||
|
||||
#ifdef CONFIG_PM
|
||||
struct uart_cc13xx_cc26xx_data *data = dev->data;
|
||||
|
||||
/*
|
||||
* When rx is enabled, it is implicit that we are expecting
|
||||
* to receive from the uart, hence we can no longer go into
|
||||
* standby.
|
||||
*/
|
||||
if (!get_dev_data(dev)->rx_constrained) {
|
||||
if (!data->rx_constrained) {
|
||||
pm_constraint_set(PM_STATE_STANDBY);
|
||||
get_dev_data(dev)->rx_constrained = true;
|
||||
data->rx_constrained = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
UARTIntEnable(get_dev_conf(dev)->regs, UART_INT_RX);
|
||||
UARTIntEnable(config->regs, UART_INT_RX);
|
||||
}
|
||||
|
||||
static void uart_cc13xx_cc26xx_irq_rx_disable(const struct device *dev)
|
||||
{
|
||||
const struct uart_device_config *config = dev->config;
|
||||
|
||||
#ifdef CONFIG_PM
|
||||
if (get_dev_data(dev)->rx_constrained) {
|
||||
struct uart_cc13xx_cc26xx_data *data = dev->data;
|
||||
|
||||
if (data->rx_constrained) {
|
||||
pm_constraint_release(PM_STATE_STANDBY);
|
||||
get_dev_data(dev)->rx_constrained = false;
|
||||
data->rx_constrained = false;
|
||||
}
|
||||
#endif
|
||||
|
||||
UARTIntDisable(get_dev_conf(dev)->regs, UART_INT_RX);
|
||||
UARTIntDisable(config->regs, UART_INT_RX);
|
||||
}
|
||||
|
||||
static int uart_cc13xx_cc26xx_irq_tx_complete(const struct device *dev)
|
||||
{
|
||||
return UARTBusy(get_dev_conf(dev)->regs) ? 0 : 1;
|
||||
const struct uart_device_config *config = dev->config;
|
||||
|
||||
return UARTBusy(config->regs) ? 0 : 1;
|
||||
}
|
||||
|
||||
static int uart_cc13xx_cc26xx_irq_rx_ready(const struct device *dev)
|
||||
{
|
||||
return UARTCharsAvail(get_dev_conf(dev)->regs) ? 1 : 0;
|
||||
const struct uart_device_config *config = dev->config;
|
||||
|
||||
return UARTCharsAvail(config->regs) ? 1 : 0;
|
||||
}
|
||||
|
||||
static void uart_cc13xx_cc26xx_irq_err_enable(const struct device *dev)
|
||||
{
|
||||
return UARTIntEnable(get_dev_conf(dev)->regs,
|
||||
const struct uart_device_config *config = dev->config;
|
||||
|
||||
return UARTIntEnable(config->regs,
|
||||
UART_INT_OE | UART_INT_BE | UART_INT_PE |
|
||||
UART_INT_FE);
|
||||
}
|
||||
|
||||
static void uart_cc13xx_cc26xx_irq_err_disable(const struct device *dev)
|
||||
{
|
||||
return UARTIntDisable(get_dev_conf(dev)->regs,
|
||||
const struct uart_device_config *config = dev->config;
|
||||
|
||||
return UARTIntDisable(config->regs,
|
||||
UART_INT_OE | UART_INT_BE | UART_INT_PE |
|
||||
UART_INT_FE);
|
||||
}
|
||||
|
||||
static int uart_cc13xx_cc26xx_irq_is_pending(const struct device *dev)
|
||||
{
|
||||
uint32_t status = UARTIntStatus(get_dev_conf(dev)->regs, true);
|
||||
const struct uart_device_config *config = dev->config;
|
||||
uint32_t status = UARTIntStatus(config->regs, true);
|
||||
|
||||
return status & (UART_INT_TX | UART_INT_RX) ? 1 : 0;
|
||||
}
|
||||
|
@ -338,7 +367,7 @@ static void uart_cc13xx_cc26xx_irq_callback_set(const struct device *dev,
|
|||
uart_irq_callback_user_data_t cb,
|
||||
void *user_data)
|
||||
{
|
||||
struct uart_cc13xx_cc26xx_data *data = get_dev_data(dev);
|
||||
struct uart_cc13xx_cc26xx_data *data = dev->data;
|
||||
|
||||
data->callback = cb;
|
||||
data->user_data = user_data;
|
||||
|
@ -346,7 +375,7 @@ static void uart_cc13xx_cc26xx_irq_callback_set(const struct device *dev,
|
|||
|
||||
static void uart_cc13xx_cc26xx_isr(const struct device *dev)
|
||||
{
|
||||
struct uart_cc13xx_cc26xx_data *data = get_dev_data(dev);
|
||||
struct uart_cc13xx_cc26xx_data *data = dev->data;
|
||||
|
||||
if (data->callback) {
|
||||
data->callback(dev, data->user_data);
|
||||
|
@ -368,13 +397,14 @@ static int postNotifyFxn(unsigned int eventType, uintptr_t eventArg,
|
|||
uintptr_t clientArg)
|
||||
{
|
||||
const struct device *dev = (const struct device *)clientArg;
|
||||
const struct uart_device_config *config = dev->config;
|
||||
struct uart_cc13xx_cc26xx_data *data = dev->data;
|
||||
int ret = Power_NOTIFYDONE;
|
||||
int16_t res_id;
|
||||
|
||||
/* Reconfigure the hardware if returning from standby */
|
||||
if (eventType == PowerCC26XX_AWAKE_STANDBY) {
|
||||
if (get_dev_conf(dev)->regs ==
|
||||
DT_INST_REG_ADDR(0)) {
|
||||
if (config->regs == DT_INST_REG_ADDR(0)) {
|
||||
res_id = PowerCC26XX_PERIPH_UART0;
|
||||
} else { /* DT_INST_REG_ADDR(1) */
|
||||
res_id = PowerCC26X2_PERIPH_UART1;
|
||||
|
@ -386,7 +416,7 @@ static int postNotifyFxn(unsigned int eventType, uintptr_t eventArg,
|
|||
* actively powered down
|
||||
*/
|
||||
if (uart_cc13xx_cc26xx_configure(dev,
|
||||
&get_dev_data(dev)->uart_config) != 0) {
|
||||
&data->uart_config) != 0) {
|
||||
ret = Power_NOTIFYERROR;
|
||||
}
|
||||
}
|
||||
|
@ -400,27 +430,27 @@ static int postNotifyFxn(unsigned int eventType, uintptr_t eventArg,
|
|||
static int uart_cc13xx_cc26xx_pm_action(const struct device *dev,
|
||||
enum pm_device_action action)
|
||||
{
|
||||
const struct uart_device_config *config = dev->config;
|
||||
struct uart_cc13xx_cc26xx_data *data = dev->data;
|
||||
int ret = 0;
|
||||
|
||||
switch (action) {
|
||||
case PM_DEVICE_ACTION_RESUME:
|
||||
if (get_dev_conf(dev)->regs == DT_INST_REG_ADDR(0)) {
|
||||
if (config->regs == DT_INST_REG_ADDR(0)) {
|
||||
Power_setDependency(PowerCC26XX_PERIPH_UART0);
|
||||
} else {
|
||||
Power_setDependency(PowerCC26X2_PERIPH_UART1);
|
||||
}
|
||||
/* Configure and enable UART */
|
||||
ret = uart_cc13xx_cc26xx_configure(dev,
|
||||
&get_dev_data(dev)->uart_config);
|
||||
ret = uart_cc13xx_cc26xx_configure(dev, &data->uart_config);
|
||||
break;
|
||||
case PM_DEVICE_ACTION_SUSPEND:
|
||||
UARTDisable(get_dev_conf(dev)->regs);
|
||||
UARTDisable(config->regs);
|
||||
/*
|
||||
* Release power dependency - i.e. potentially power
|
||||
* down serial domain.
|
||||
*/
|
||||
if (get_dev_conf(dev)->regs ==
|
||||
DT_INST_REG_ADDR(0)) {
|
||||
if (config->regs == DT_INST_REG_ADDR(0)) {
|
||||
Power_releaseDependency(PowerCC26XX_PERIPH_UART0);
|
||||
} else {
|
||||
Power_releaseDependency(PowerCC26X2_PERIPH_UART1);
|
||||
|
@ -463,8 +493,10 @@ static const struct uart_driver_api uart_cc13xx_cc26xx_driver_api = {
|
|||
#ifdef CONFIG_PM
|
||||
#define UART_CC13XX_CC26XX_POWER_UART(n) \
|
||||
do { \
|
||||
get_dev_data(dev)->rx_constrained = false; \
|
||||
get_dev_data(dev)->tx_constrained = false; \
|
||||
struct uart_cc13xx_cc26xx_data *data = dev->data; \
|
||||
\
|
||||
data->rx_constrained = false; \
|
||||
data->tx_constrained = false; \
|
||||
\
|
||||
/* Set Power dependencies */ \
|
||||
if (DT_INST_REG_ADDR(n) == 0x40001000) { \
|
||||
|
@ -474,7 +506,7 @@ static const struct uart_driver_api uart_cc13xx_cc26xx_driver_api = {
|
|||
} \
|
||||
\
|
||||
/* Register notification function */ \
|
||||
Power_registerNotify(&get_dev_data(dev)->postNotify, \
|
||||
Power_registerNotify(&data->postNotify, \
|
||||
PowerCC26XX_AWAKE_STANDBY, \
|
||||
postNotifyFxn, (uintptr_t)dev); \
|
||||
} while (0)
|
||||
|
@ -514,7 +546,9 @@ static const struct uart_driver_api uart_cc13xx_cc26xx_driver_api = {
|
|||
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
||||
#define UART_CC13XX_CC26XX_IRQ_CFG(n) \
|
||||
do { \
|
||||
UARTIntClear(get_dev_conf(dev)->regs, UART_INT_RX); \
|
||||
const struct uart_device_config *config = dev->config; \
|
||||
\
|
||||
UARTIntClear(config->regs, UART_INT_RX); \
|
||||
\
|
||||
IRQ_CONNECT(DT_INST_IRQN(n), \
|
||||
DT_INST_IRQ(n, priority), \
|
||||
|
@ -523,7 +557,7 @@ static const struct uart_driver_api uart_cc13xx_cc26xx_driver_api = {
|
|||
0); \
|
||||
irq_enable(DT_INST_IRQN(n)); \
|
||||
/* Causes an initial TX ready INT when TX INT enabled */\
|
||||
UARTCharPutNonBlocking(get_dev_conf(dev)->regs, '\0'); \
|
||||
UARTCharPutNonBlocking(config->regs, '\0'); \
|
||||
} while (0)
|
||||
|
||||
#define UART_CC13XX_CC26XX_INT_FIELDS \
|
||||
|
@ -552,6 +586,7 @@ static const struct uart_driver_api uart_cc13xx_cc26xx_driver_api = {
|
|||
#define UART_CC13XX_CC26XX_INIT_FUNC(n) \
|
||||
static int uart_cc13xx_cc26xx_init_##n(const struct device *dev) \
|
||||
{ \
|
||||
struct uart_cc13xx_cc26xx_data *data = dev->data; \
|
||||
int ret; \
|
||||
\
|
||||
UART_CC13XX_CC26XX_POWER_UART(n); \
|
||||
|
@ -563,8 +598,7 @@ static const struct uart_driver_api uart_cc13xx_cc26xx_driver_api = {
|
|||
IOC_STD_INPUT); \
|
||||
\
|
||||
/* Configure and enable UART */ \
|
||||
ret = uart_cc13xx_cc26xx_configure(dev, \
|
||||
&get_dev_data(dev)->uart_config); \
|
||||
ret = uart_cc13xx_cc26xx_configure(dev, &data->uart_config);\
|
||||
\
|
||||
/* Enable interrupts */ \
|
||||
UART_CC13XX_CC26XX_IRQ_CFG(n); \
|
||||
|
|
|
@ -61,17 +61,6 @@ struct uart_nrfx_data {
|
|||
struct uart_config uart_config;
|
||||
};
|
||||
|
||||
static inline const struct uart_nrfx_config *get_dev_config(
|
||||
const struct device *dev)
|
||||
{
|
||||
return dev->config;
|
||||
}
|
||||
|
||||
static inline struct uart_nrfx_data *get_dev_data(const struct device *dev)
|
||||
{
|
||||
return dev->data;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_UART_0_ASYNC
|
||||
static struct {
|
||||
uart_callback_t callback;
|
||||
|
@ -117,7 +106,7 @@ static volatile bool disable_tx_irq;
|
|||
#ifndef CONFIG_PINCTRL
|
||||
static void uart_nrfx_pins_configure(const struct device *dev, bool sleep)
|
||||
{
|
||||
const struct uart_nrfx_config *cfg = get_dev_config(dev);
|
||||
const struct uart_nrfx_config *cfg = dev->config;
|
||||
|
||||
if (!sleep) {
|
||||
if (cfg->tx_pin != NRF_UART_PSEL_DISCONNECTED) {
|
||||
|
@ -383,6 +372,7 @@ static int uart_nrfx_err_check(const struct device *dev)
|
|||
static int uart_nrfx_configure(const struct device *dev,
|
||||
const struct uart_config *cfg)
|
||||
{
|
||||
struct uart_nrfx_data *data = dev->data;
|
||||
nrf_uart_config_t uart_cfg;
|
||||
|
||||
#if defined(UART_CONFIG_STOP_Msk)
|
||||
|
@ -447,7 +437,7 @@ static int uart_nrfx_configure(const struct device *dev,
|
|||
|
||||
nrf_uart_configure(uart0_addr, &uart_cfg);
|
||||
|
||||
get_dev_data(dev)->uart_config = *cfg;
|
||||
data->uart_config = *cfg;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -456,7 +446,9 @@ static int uart_nrfx_configure(const struct device *dev,
|
|||
static int uart_nrfx_config_get(const struct device *dev,
|
||||
struct uart_config *cfg)
|
||||
{
|
||||
*cfg = get_dev_data(dev)->uart_config;
|
||||
struct uart_nrfx_data *data = dev->data;
|
||||
|
||||
*cfg = data->uart_config;
|
||||
return 0;
|
||||
}
|
||||
#endif /* CONFIG_UART_USE_RUNTIME_CONFIGURE */
|
||||
|
@ -1046,9 +1038,10 @@ static void uart_nrfx_isr(const struct device *dev)
|
|||
*/
|
||||
static int uart_nrfx_init(const struct device *dev)
|
||||
{
|
||||
struct uart_nrfx_data *data = dev->data;
|
||||
int err;
|
||||
#ifdef CONFIG_PINCTRL
|
||||
const struct uart_nrfx_config *config = get_dev_config(dev);
|
||||
const struct uart_nrfx_config *config = dev->config;
|
||||
#endif /* CONFIG_PINCTRL */
|
||||
|
||||
nrf_uart_disable(uart0_addr);
|
||||
|
@ -1063,7 +1056,7 @@ static int uart_nrfx_init(const struct device *dev)
|
|||
#endif /* CONFIG_PINCTRL */
|
||||
|
||||
/* Set initial configuration */
|
||||
err = uart_nrfx_configure(dev, &get_dev_data(dev)->uart_config);
|
||||
err = uart_nrfx_configure(dev, &data->uart_config);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
@ -1148,7 +1141,7 @@ static int uart_nrfx_pm_action(const struct device *dev,
|
|||
enum pm_device_action action)
|
||||
{
|
||||
#ifdef CONFIG_PINCTRL
|
||||
const struct uart_nrfx_config *config = get_dev_config(dev);
|
||||
const struct uart_nrfx_config *config = dev->config;
|
||||
int ret;
|
||||
#endif
|
||||
|
||||
|
|
|
@ -171,19 +171,9 @@ struct uarte_nrfx_config {
|
|||
#endif
|
||||
};
|
||||
|
||||
static inline struct uarte_nrfx_data *get_dev_data(const struct device *dev)
|
||||
{
|
||||
return dev->data;
|
||||
}
|
||||
|
||||
static inline const struct uarte_nrfx_config *get_dev_config(const struct device *dev)
|
||||
{
|
||||
return dev->config;
|
||||
}
|
||||
|
||||
static inline NRF_UARTE_Type *get_uarte_instance(const struct device *dev)
|
||||
{
|
||||
const struct uarte_nrfx_config *config = get_dev_config(dev);
|
||||
const struct uarte_nrfx_config *config = dev->config;
|
||||
|
||||
return config->uarte_regs;
|
||||
}
|
||||
|
@ -191,7 +181,7 @@ static inline NRF_UARTE_Type *get_uarte_instance(const struct device *dev)
|
|||
#ifndef CONFIG_PINCTRL
|
||||
static void uarte_nrfx_pins_configure(const struct device *dev, bool sleep)
|
||||
{
|
||||
const struct uarte_nrfx_config *cfg = get_dev_config(dev);
|
||||
const struct uarte_nrfx_config *cfg = dev->config;
|
||||
|
||||
if (!sleep) {
|
||||
if (cfg->tx_pin != NRF_UARTE_PSEL_DISCONNECTED) {
|
||||
|
@ -266,6 +256,7 @@ static void endtx_isr(const struct device *dev)
|
|||
static void uarte_nrfx_isr_int(void *arg)
|
||||
{
|
||||
const struct device *dev = arg;
|
||||
const struct uarte_nrfx_config *config = dev->config;
|
||||
NRF_UARTE_Type *uarte = get_uarte_instance(dev);
|
||||
|
||||
/* If interrupt driven and asynchronous APIs are disabled then UART
|
||||
|
@ -276,7 +267,7 @@ static void uarte_nrfx_isr_int(void *arg)
|
|||
endtx_isr(dev);
|
||||
}
|
||||
|
||||
if (get_dev_config(dev)->flags & UARTE_CFG_FLAG_LOW_POWER) {
|
||||
if (config->flags & UARTE_CFG_FLAG_LOW_POWER) {
|
||||
int key = irq_lock();
|
||||
|
||||
if (nrf_uarte_event_check(uarte, NRF_UARTE_EVENT_TXSTOPPED)) {
|
||||
|
@ -284,7 +275,7 @@ static void uarte_nrfx_isr_int(void *arg)
|
|||
}
|
||||
|
||||
#ifdef UARTE_INTERRUPT_DRIVEN
|
||||
struct uarte_nrfx_data *data = get_dev_data(dev);
|
||||
struct uarte_nrfx_data *data = dev->data;
|
||||
|
||||
if (!data->int_driven || data->int_driven->fifo_fill_lock == 0)
|
||||
#endif
|
||||
|
@ -297,7 +288,7 @@ static void uarte_nrfx_isr_int(void *arg)
|
|||
}
|
||||
|
||||
#ifdef UARTE_INTERRUPT_DRIVEN
|
||||
struct uarte_nrfx_data *data = get_dev_data(dev);
|
||||
struct uarte_nrfx_data *data = dev->data;
|
||||
|
||||
if (!data->int_driven) {
|
||||
return;
|
||||
|
@ -416,6 +407,7 @@ static int baudrate_set(const struct device *dev, uint32_t baudrate)
|
|||
static int uarte_nrfx_configure(const struct device *dev,
|
||||
const struct uart_config *cfg)
|
||||
{
|
||||
struct uarte_nrfx_data *data = dev->data;
|
||||
nrf_uarte_config_t uarte_cfg;
|
||||
|
||||
#if defined(UARTE_CONFIG_STOP_Msk)
|
||||
|
@ -476,7 +468,7 @@ static int uarte_nrfx_configure(const struct device *dev,
|
|||
|
||||
nrf_uarte_configure(get_uarte_instance(dev), &uarte_cfg);
|
||||
|
||||
get_dev_data(dev)->uart_config = *cfg;
|
||||
data->uart_config = *cfg;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -485,7 +477,9 @@ static int uarte_nrfx_configure(const struct device *dev,
|
|||
static int uarte_nrfx_config_get(const struct device *dev,
|
||||
struct uart_config *cfg)
|
||||
{
|
||||
*cfg = get_dev_data(dev)->uart_config;
|
||||
struct uarte_nrfx_data *data = dev->data;
|
||||
|
||||
*cfg = data->uart_config;
|
||||
return 0;
|
||||
}
|
||||
#endif /* CONFIG_UART_USE_RUNTIME_CONFIGURE */
|
||||
|
@ -504,8 +498,9 @@ static int uarte_nrfx_err_check(const struct device *dev)
|
|||
*/
|
||||
static bool is_tx_ready(const struct device *dev)
|
||||
{
|
||||
const struct uarte_nrfx_config *config = dev->config;
|
||||
NRF_UARTE_Type *uarte = get_uarte_instance(dev);
|
||||
bool ppi_endtx = get_dev_config(dev)->flags & UARTE_CFG_FLAG_PPI_ENDTX;
|
||||
bool ppi_endtx = config->flags & UARTE_CFG_FLAG_PPI_ENDTX;
|
||||
|
||||
return nrf_uarte_event_check(uarte, NRF_UARTE_EVENT_TXSTOPPED) ||
|
||||
(!ppi_endtx ?
|
||||
|
@ -556,14 +551,15 @@ static inline bool hw_rx_counting_enabled(struct uarte_nrfx_data *data)
|
|||
static void uarte_enable(const struct device *dev, uint32_t mask)
|
||||
{
|
||||
#ifdef CONFIG_UART_ASYNC_API
|
||||
struct uarte_nrfx_data *data = get_dev_data(dev);
|
||||
const struct uarte_nrfx_config *config = dev->config;
|
||||
struct uarte_nrfx_data *data = dev->data;
|
||||
|
||||
if (data->async) {
|
||||
bool disabled = data->async->low_power_mask == 0;
|
||||
|
||||
data->async->low_power_mask |= mask;
|
||||
if (hw_rx_counting_enabled(data) && disabled) {
|
||||
const nrfx_timer_t *timer = &get_dev_config(dev)->timer;
|
||||
const nrfx_timer_t *timer = &config->timer;
|
||||
|
||||
nrfx_timer_enable(timer);
|
||||
|
||||
|
@ -581,6 +577,7 @@ static void uarte_enable(const struct device *dev, uint32_t mask)
|
|||
*/
|
||||
static void tx_start(const struct device *dev, const uint8_t *buf, size_t len)
|
||||
{
|
||||
const struct uarte_nrfx_config *config = dev->config;
|
||||
NRF_UARTE_Type *uarte = get_uarte_instance(dev);
|
||||
|
||||
#if CONFIG_PM_DEVICE
|
||||
|
@ -595,7 +592,7 @@ static void tx_start(const struct device *dev, const uint8_t *buf, size_t len)
|
|||
nrf_uarte_event_clear(uarte, NRF_UARTE_EVENT_ENDTX);
|
||||
nrf_uarte_event_clear(uarte, NRF_UARTE_EVENT_TXSTOPPED);
|
||||
|
||||
if (get_dev_config(dev)->flags & UARTE_CFG_FLAG_LOW_POWER) {
|
||||
if (config->flags & UARTE_CFG_FLAG_LOW_POWER) {
|
||||
uarte_enable(dev, UARTE_LOW_POWER_TX);
|
||||
nrf_uarte_int_enable(uarte, NRF_UARTE_INT_TXSTOPPED_MASK);
|
||||
}
|
||||
|
@ -607,10 +604,11 @@ static void tx_start(const struct device *dev, const uint8_t *buf, size_t len)
|
|||
static void uart_disable(const struct device *dev)
|
||||
{
|
||||
#ifdef CONFIG_UART_ASYNC_API
|
||||
struct uarte_nrfx_data *data = get_dev_data(dev);
|
||||
const struct uarte_nrfx_config *config = dev->config;
|
||||
struct uarte_nrfx_data *data = dev->data;
|
||||
|
||||
if (data->async && hw_rx_counting_enabled(data)) {
|
||||
nrfx_timer_disable(&get_dev_config(dev)->timer);
|
||||
nrfx_timer_disable(&config->timer);
|
||||
/* Timer/counter value is reset when disabled. */
|
||||
data->async->rx_total_byte_cnt = 0;
|
||||
data->async->rx_total_user_byte_cnt = 0;
|
||||
|
@ -629,8 +627,8 @@ static void tx_timeout(struct k_timer *timer);
|
|||
|
||||
static int uarte_nrfx_rx_counting_init(const struct device *dev)
|
||||
{
|
||||
struct uarte_nrfx_data *data = get_dev_data(dev);
|
||||
const struct uarte_nrfx_config *cfg = get_dev_config(dev);
|
||||
struct uarte_nrfx_data *data = dev->data;
|
||||
const struct uarte_nrfx_config *cfg = dev->config;
|
||||
NRF_UARTE_Type *uarte = get_uarte_instance(dev);
|
||||
int ret;
|
||||
|
||||
|
@ -696,7 +694,7 @@ static int uarte_nrfx_rx_counting_init(const struct device *dev)
|
|||
|
||||
static int uarte_nrfx_init(const struct device *dev)
|
||||
{
|
||||
struct uarte_nrfx_data *data = get_dev_data(dev);
|
||||
struct uarte_nrfx_data *data = dev->data;
|
||||
NRF_UARTE_Type *uarte = get_uarte_instance(dev);
|
||||
|
||||
int ret = uarte_nrfx_rx_counting_init(dev);
|
||||
|
@ -741,7 +739,7 @@ static int uarte_nrfx_tx(const struct device *dev, const uint8_t *buf,
|
|||
size_t len,
|
||||
int32_t timeout)
|
||||
{
|
||||
struct uarte_nrfx_data *data = get_dev_data(dev);
|
||||
struct uarte_nrfx_data *data = dev->data;
|
||||
NRF_UARTE_Type *uarte = get_uarte_instance(dev);
|
||||
|
||||
if (!nrfx_is_in_ram(buf)) {
|
||||
|
@ -779,7 +777,7 @@ static int uarte_nrfx_tx(const struct device *dev, const uint8_t *buf,
|
|||
|
||||
static int uarte_nrfx_tx_abort(const struct device *dev)
|
||||
{
|
||||
struct uarte_nrfx_data *data = get_dev_data(dev);
|
||||
struct uarte_nrfx_data *data = dev->data;
|
||||
NRF_UARTE_Type *uarte = get_uarte_instance(dev);
|
||||
|
||||
if (data->async->tx_buf == NULL) {
|
||||
|
@ -793,7 +791,7 @@ static int uarte_nrfx_tx_abort(const struct device *dev)
|
|||
|
||||
static void user_callback(const struct device *dev, struct uart_event *evt)
|
||||
{
|
||||
struct uarte_nrfx_data *data = get_dev_data(dev);
|
||||
struct uarte_nrfx_data *data = dev->data;
|
||||
|
||||
if (data->async->user_callback) {
|
||||
data->async->user_callback(dev, evt, data->async->user_data);
|
||||
|
@ -802,7 +800,7 @@ static void user_callback(const struct device *dev, struct uart_event *evt)
|
|||
|
||||
static void notify_uart_rx_rdy(const struct device *dev, size_t len)
|
||||
{
|
||||
struct uarte_nrfx_data *data = get_dev_data(dev);
|
||||
struct uarte_nrfx_data *data = dev->data;
|
||||
struct uart_event evt = {
|
||||
.type = UART_RX_RDY,
|
||||
.data.rx.buf = data->async->rx_buf,
|
||||
|
@ -842,8 +840,8 @@ static int uarte_nrfx_rx_enable(const struct device *dev, uint8_t *buf,
|
|||
size_t len,
|
||||
int32_t timeout)
|
||||
{
|
||||
struct uarte_nrfx_data *data = get_dev_data(dev);
|
||||
const struct uarte_nrfx_config *cfg = get_dev_config(dev);
|
||||
struct uarte_nrfx_data *data = dev->data;
|
||||
const struct uarte_nrfx_config *cfg = dev->config;
|
||||
NRF_UARTE_Type *uarte = get_uarte_instance(dev);
|
||||
|
||||
if (cfg->disable_rx) {
|
||||
|
@ -872,7 +870,7 @@ static int uarte_nrfx_rx_enable(const struct device *dev, uint8_t *buf,
|
|||
data->async->rx_next_buf = NULL;
|
||||
data->async->rx_next_buf_len = 0;
|
||||
|
||||
if (get_dev_config(dev)->flags & UARTE_CFG_FLAG_LOW_POWER) {
|
||||
if (cfg->flags & UARTE_CFG_FLAG_LOW_POWER) {
|
||||
if (data->async->rx_flush_cnt) {
|
||||
int cpy_len = MIN(len, data->async->rx_flush_cnt);
|
||||
|
||||
|
@ -900,7 +898,7 @@ static int uarte_nrfx_rx_enable(const struct device *dev, uint8_t *buf,
|
|||
nrf_uarte_event_clear(uarte, NRF_UARTE_EVENT_RXSTARTED);
|
||||
|
||||
data->async->rx_enabled = true;
|
||||
if (get_dev_config(dev)->flags & UARTE_CFG_FLAG_LOW_POWER) {
|
||||
if (cfg->flags & UARTE_CFG_FLAG_LOW_POWER) {
|
||||
int key = irq_lock();
|
||||
|
||||
uarte_enable(dev, UARTE_LOW_POWER_RX);
|
||||
|
@ -915,7 +913,7 @@ static int uarte_nrfx_rx_enable(const struct device *dev, uint8_t *buf,
|
|||
static int uarte_nrfx_rx_buf_rsp(const struct device *dev, uint8_t *buf,
|
||||
size_t len)
|
||||
{
|
||||
struct uarte_nrfx_data *data = get_dev_data(dev);
|
||||
struct uarte_nrfx_data *data = dev->data;
|
||||
int err;
|
||||
NRF_UARTE_Type *uarte = get_uarte_instance(dev);
|
||||
int key = irq_lock();
|
||||
|
@ -941,7 +939,7 @@ static int uarte_nrfx_callback_set(const struct device *dev,
|
|||
uart_callback_t callback,
|
||||
void *user_data)
|
||||
{
|
||||
struct uarte_nrfx_data *data = get_dev_data(dev);
|
||||
struct uarte_nrfx_data *data = dev->data;
|
||||
|
||||
if (!data->async) {
|
||||
return -ENOTSUP;
|
||||
|
@ -955,7 +953,7 @@ static int uarte_nrfx_callback_set(const struct device *dev,
|
|||
|
||||
static int uarte_nrfx_rx_disable(const struct device *dev)
|
||||
{
|
||||
struct uarte_nrfx_data *data = get_dev_data(dev);
|
||||
struct uarte_nrfx_data *data = dev->data;
|
||||
NRF_UARTE_Type *uarte = get_uarte_instance(dev);
|
||||
|
||||
if (data->async->rx_buf == NULL) {
|
||||
|
@ -992,7 +990,7 @@ static void rx_timeout(struct k_timer *timer)
|
|||
{
|
||||
struct uarte_nrfx_data *data = k_timer_user_data_get(timer);
|
||||
const struct device *dev = data->dev;
|
||||
const struct uarte_nrfx_config *cfg = get_dev_config(dev);
|
||||
const struct uarte_nrfx_config *cfg = dev->config;
|
||||
uint32_t read;
|
||||
|
||||
if (data->async->is_in_irq) {
|
||||
|
@ -1095,7 +1093,7 @@ static void error_isr(const struct device *dev)
|
|||
|
||||
static void rxstarted_isr(const struct device *dev)
|
||||
{
|
||||
struct uarte_nrfx_data *data = get_dev_data(dev);
|
||||
struct uarte_nrfx_data *data = dev->data;
|
||||
struct uart_event evt = {
|
||||
.type = UART_RX_BUF_REQUEST,
|
||||
};
|
||||
|
@ -1110,7 +1108,7 @@ static void rxstarted_isr(const struct device *dev)
|
|||
|
||||
static void endrx_isr(const struct device *dev)
|
||||
{
|
||||
struct uarte_nrfx_data *data = get_dev_data(dev);
|
||||
struct uarte_nrfx_data *data = dev->data;
|
||||
NRF_UARTE_Type *uarte = get_uarte_instance(dev);
|
||||
|
||||
data->async->is_in_irq = true;
|
||||
|
@ -1261,7 +1259,7 @@ static uint8_t rx_flush(const struct device *dev, uint8_t *buf, uint32_t len)
|
|||
|
||||
static void async_uart_release(const struct device *dev, uint32_t dir_mask)
|
||||
{
|
||||
struct uarte_nrfx_data *data = get_dev_data(dev);
|
||||
struct uarte_nrfx_data *data = dev->data;
|
||||
int key = irq_lock();
|
||||
|
||||
data->async->low_power_mask &= ~dir_mask;
|
||||
|
@ -1283,7 +1281,8 @@ static void async_uart_release(const struct device *dev, uint32_t dir_mask)
|
|||
*/
|
||||
static void rxto_isr(const struct device *dev)
|
||||
{
|
||||
struct uarte_nrfx_data *data = get_dev_data(dev);
|
||||
const struct uarte_nrfx_config *config = dev->config;
|
||||
struct uarte_nrfx_data *data = dev->data;
|
||||
|
||||
notify_rx_buf_release(dev, &data->async->rx_buf, true);
|
||||
notify_rx_buf_release(dev, &data->async->rx_next_buf, true);
|
||||
|
@ -1292,7 +1291,7 @@ static void rxto_isr(const struct device *dev)
|
|||
(void)rx_flush(dev, NULL, 0);
|
||||
}
|
||||
|
||||
if (get_dev_config(dev)->flags & UARTE_CFG_FLAG_LOW_POWER) {
|
||||
if (config->flags & UARTE_CFG_FLAG_LOW_POWER) {
|
||||
async_uart_release(dev, UARTE_LOW_POWER_RX);
|
||||
}
|
||||
|
||||
|
@ -1301,11 +1300,12 @@ static void rxto_isr(const struct device *dev)
|
|||
|
||||
static void txstopped_isr(const struct device *dev)
|
||||
{
|
||||
struct uarte_nrfx_data *data = get_dev_data(dev);
|
||||
const struct uarte_nrfx_config *config = dev->config;
|
||||
struct uarte_nrfx_data *data = dev->data;
|
||||
NRF_UARTE_Type *uarte = get_uarte_instance(dev);
|
||||
int key;
|
||||
|
||||
if (get_dev_config(dev)->flags & UARTE_CFG_FLAG_LOW_POWER) {
|
||||
if (config->flags & UARTE_CFG_FLAG_LOW_POWER) {
|
||||
nrf_uarte_int_disable(uarte, NRF_UARTE_INT_TXSTOPPED_MASK);
|
||||
async_uart_release(dev, UARTE_LOW_POWER_TX);
|
||||
|
||||
|
@ -1364,7 +1364,7 @@ static void txstopped_isr(const struct device *dev)
|
|||
static void uarte_nrfx_isr_async(const struct device *dev)
|
||||
{
|
||||
NRF_UARTE_Type *uarte = get_uarte_instance(dev);
|
||||
struct uarte_nrfx_data *data = get_dev_data(dev);
|
||||
struct uarte_nrfx_data *data = dev->data;
|
||||
|
||||
if (!hw_rx_counting_enabled(data)
|
||||
&& nrf_uarte_event_check(uarte, NRF_UARTE_EVENT_RXDRDY)) {
|
||||
|
@ -1434,7 +1434,7 @@ static void uarte_nrfx_isr_async(const struct device *dev)
|
|||
static int uarte_nrfx_poll_in(const struct device *dev, unsigned char *c)
|
||||
{
|
||||
|
||||
const struct uarte_nrfx_data *data = get_dev_data(dev);
|
||||
const struct uarte_nrfx_data *data = dev->data;
|
||||
NRF_UARTE_Type *uarte = get_uarte_instance(dev);
|
||||
|
||||
#ifdef CONFIG_UART_ASYNC_API
|
||||
|
@ -1464,7 +1464,7 @@ static int uarte_nrfx_poll_in(const struct device *dev, unsigned char *c)
|
|||
*/
|
||||
static void uarte_nrfx_poll_out(const struct device *dev, unsigned char c)
|
||||
{
|
||||
struct uarte_nrfx_data *data = get_dev_data(dev);
|
||||
struct uarte_nrfx_data *data = dev->data;
|
||||
bool isr_mode = k_is_in_isr() || k_is_pre_kernel();
|
||||
int key;
|
||||
|
||||
|
@ -1502,7 +1502,7 @@ static int uarte_nrfx_fifo_fill(const struct device *dev,
|
|||
const uint8_t *tx_data,
|
||||
int len)
|
||||
{
|
||||
struct uarte_nrfx_data *data = get_dev_data(dev);
|
||||
struct uarte_nrfx_data *data = dev->data;
|
||||
|
||||
len = MIN(len, data->int_driven->tx_buff_size);
|
||||
if (!atomic_cas(&data->int_driven->fifo_fill_lock, 0, 1)) {
|
||||
|
@ -1535,7 +1535,7 @@ static int uarte_nrfx_fifo_read(const struct device *dev,
|
|||
{
|
||||
int num_rx = 0;
|
||||
NRF_UARTE_Type *uarte = get_uarte_instance(dev);
|
||||
const struct uarte_nrfx_data *data = get_dev_data(dev);
|
||||
const struct uarte_nrfx_data *data = dev->data;
|
||||
|
||||
if (size > 0 && nrf_uarte_event_check(uarte, NRF_UARTE_EVENT_ENDRX)) {
|
||||
/* Clear the interrupt */
|
||||
|
@ -1554,7 +1554,7 @@ static int uarte_nrfx_fifo_read(const struct device *dev,
|
|||
static void uarte_nrfx_irq_tx_enable(const struct device *dev)
|
||||
{
|
||||
NRF_UARTE_Type *uarte = get_uarte_instance(dev);
|
||||
struct uarte_nrfx_data *data = get_dev_data(dev);
|
||||
struct uarte_nrfx_data *data = dev->data;
|
||||
int key = irq_lock();
|
||||
|
||||
data->int_driven->disable_tx_irq = false;
|
||||
|
@ -1566,7 +1566,7 @@ static void uarte_nrfx_irq_tx_enable(const struct device *dev)
|
|||
/** Interrupt driven transfer disabling function */
|
||||
static void uarte_nrfx_irq_tx_disable(const struct device *dev)
|
||||
{
|
||||
struct uarte_nrfx_data *data = get_dev_data(dev);
|
||||
struct uarte_nrfx_data *data = dev->data;
|
||||
/* TX IRQ will be disabled after current transmission is finished */
|
||||
data->int_driven->disable_tx_irq = true;
|
||||
}
|
||||
|
@ -1575,7 +1575,7 @@ static void uarte_nrfx_irq_tx_disable(const struct device *dev)
|
|||
static int uarte_nrfx_irq_tx_ready_complete(const struct device *dev)
|
||||
{
|
||||
NRF_UARTE_Type *uarte = get_uarte_instance(dev);
|
||||
struct uarte_nrfx_data *data = get_dev_data(dev);
|
||||
struct uarte_nrfx_data *data = dev->data;
|
||||
|
||||
/* ENDTX flag is always on so that ISR is called when we enable TX IRQ.
|
||||
* Because of that we have to explicitly check if ENDTX interrupt is
|
||||
|
@ -1658,7 +1658,7 @@ static void uarte_nrfx_irq_callback_set(const struct device *dev,
|
|||
uart_irq_callback_user_data_t cb,
|
||||
void *cb_data)
|
||||
{
|
||||
struct uarte_nrfx_data *data = get_dev_data(dev);
|
||||
struct uarte_nrfx_data *data = dev->data;
|
||||
|
||||
data->int_driven->cb = cb;
|
||||
data->int_driven->cb_data = cb_data;
|
||||
|
@ -1723,8 +1723,8 @@ static int uarte_instance_init(const struct device *dev,
|
|||
{
|
||||
int err;
|
||||
NRF_UARTE_Type *uarte = get_uarte_instance(dev);
|
||||
struct uarte_nrfx_data *data = get_dev_data(dev);
|
||||
const struct uarte_nrfx_config *cfg = get_dev_config(dev);
|
||||
struct uarte_nrfx_data *data = dev->data;
|
||||
const struct uarte_nrfx_config *cfg = dev->config;
|
||||
|
||||
nrf_uarte_disable(uarte);
|
||||
|
||||
|
@ -1739,7 +1739,7 @@ static int uarte_instance_init(const struct device *dev,
|
|||
uarte_nrfx_pins_configure(dev, false);
|
||||
#endif /* CONFIG_PINCTRL */
|
||||
|
||||
err = uarte_nrfx_configure(dev, &get_dev_data(dev)->uart_config);
|
||||
err = uarte_nrfx_configure(dev, &data->uart_config);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
@ -1803,7 +1803,8 @@ static int uarte_instance_init(const struct device *dev,
|
|||
*/
|
||||
static void wait_for_tx_stopped(const struct device *dev)
|
||||
{
|
||||
bool ppi_endtx = get_dev_config(dev)->flags & UARTE_CFG_FLAG_PPI_ENDTX;
|
||||
const struct uarte_nrfx_config *config = dev->config;
|
||||
bool ppi_endtx = config->flags & UARTE_CFG_FLAG_PPI_ENDTX;
|
||||
NRF_UARTE_Type *uarte = get_uarte_instance(dev);
|
||||
bool res;
|
||||
|
||||
|
@ -1835,9 +1836,9 @@ static int uarte_nrfx_pm_action(const struct device *dev,
|
|||
{
|
||||
NRF_UARTE_Type *uarte = get_uarte_instance(dev);
|
||||
#if defined(CONFIG_UART_ASYNC_API) || defined(UARTE_INTERRUPT_DRIVEN)
|
||||
struct uarte_nrfx_data *data = get_dev_data(dev);
|
||||
struct uarte_nrfx_data *data = dev->data;
|
||||
#endif
|
||||
const struct uarte_nrfx_config *cfg = get_dev_config(dev);
|
||||
const struct uarte_nrfx_config *cfg = dev->config;
|
||||
#ifdef CONFIG_PINCTRL
|
||||
int ret;
|
||||
#endif
|
||||
|
@ -1860,7 +1861,7 @@ static int uarte_nrfx_pm_action(const struct device *dev,
|
|||
|
||||
#ifdef CONFIG_UART_ASYNC_API
|
||||
if (hw_rx_counting_enabled(data)) {
|
||||
nrfx_timer_enable(&get_dev_config(dev)->timer);
|
||||
nrfx_timer_enable(&cfg->timer);
|
||||
}
|
||||
if (data->async) {
|
||||
return 0;
|
||||
|
|
|
@ -24,18 +24,6 @@ struct uart_rtt_data {
|
|||
#endif /* CONFIG_UART_ASYNC_API */
|
||||
};
|
||||
|
||||
static inline
|
||||
const struct uart_rtt_config *get_dev_config(const struct device *dev)
|
||||
{
|
||||
return dev->config;
|
||||
}
|
||||
|
||||
static inline
|
||||
struct uart_rtt_data *get_dev_data(const struct device *dev)
|
||||
{
|
||||
return dev->data;
|
||||
}
|
||||
|
||||
static int uart_rtt_init(const struct device *dev)
|
||||
{
|
||||
/*
|
||||
|
@ -43,8 +31,8 @@ static int uart_rtt_init(const struct device *dev)
|
|||
* it is configured in correct, non-blocking mode. Other channels
|
||||
* need to be configured at run-time.
|
||||
*/
|
||||
if (get_dev_config(dev)) {
|
||||
const struct uart_rtt_config *cfg = get_dev_config(dev);
|
||||
if (dev->config) {
|
||||
const struct uart_rtt_config *cfg = dev->config;
|
||||
|
||||
SEGGER_RTT_ConfigUpBuffer(cfg->channel, dev->name,
|
||||
cfg->up_buffer, cfg->up_size,
|
||||
|
@ -67,8 +55,8 @@ static int uart_rtt_init(const struct device *dev)
|
|||
|
||||
static int uart_rtt_poll_in(const struct device *dev, unsigned char *c)
|
||||
{
|
||||
unsigned int ch =
|
||||
get_dev_config(dev) ? get_dev_config(dev)->channel : 0;
|
||||
const struct uart_rtt_config *config = dev->config;
|
||||
unsigned int ch = config ? config->channel : 0;
|
||||
unsigned int ret = SEGGER_RTT_Read(ch, c, 1);
|
||||
|
||||
return ret ? 0 : -1;
|
||||
|
@ -82,8 +70,8 @@ static int uart_rtt_poll_in(const struct device *dev, unsigned char *c)
|
|||
*/
|
||||
static void uart_rtt_poll_out(const struct device *dev, unsigned char c)
|
||||
{
|
||||
unsigned int ch =
|
||||
get_dev_config(dev) ? get_dev_config(dev)->channel : 0;
|
||||
const struct uart_rtt_config *config = dev->config;
|
||||
unsigned int ch = config ? config->channel : 0;
|
||||
|
||||
SEGGER_RTT_Write(ch, &c, 1);
|
||||
}
|
||||
|
@ -93,16 +81,18 @@ static void uart_rtt_poll_out(const struct device *dev, unsigned char c)
|
|||
static int uart_rtt_callback_set(const struct device *dev,
|
||||
uart_callback_t callback, void *user_data)
|
||||
{
|
||||
get_dev_data(dev)->callback = callback;
|
||||
get_dev_data(dev)->user_data = user_data;
|
||||
struct uart_rtt_data *data = dev->data;
|
||||
|
||||
data->callback = callback;
|
||||
data->user_data = user_data;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int uart_rtt_tx(const struct device *dev,
|
||||
const uint8_t *buf, size_t len, int32_t timeout)
|
||||
{
|
||||
const struct uart_rtt_config *cfg = get_dev_config(dev);
|
||||
struct uart_rtt_data *data = get_dev_data(dev);
|
||||
const struct uart_rtt_config *cfg = dev->config;
|
||||
struct uart_rtt_data *data = dev->data;
|
||||
unsigned int ch = cfg ? cfg->channel : 0;
|
||||
|
||||
ARG_UNUSED(timeout);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue