2016-10-13 17:55:02 +02:00
|
|
|
/*
|
2018-03-04 18:46:01 -08:00
|
|
|
* Copyright (c) 2018 Justin Watson
|
2016-10-13 17:55:02 +02:00
|
|
|
* Copyright (c) 2016 Piotr Mienkowski
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
2020-04-09 16:53:17 -05:00
|
|
|
#define DT_DRV_COMPAT atmel_sam_usart
|
|
|
|
|
2016-10-13 17:55:02 +02:00
|
|
|
/** @file
|
|
|
|
* @brief USART driver for Atmel SAM MCU family.
|
|
|
|
*
|
|
|
|
* Note:
|
|
|
|
* - Only basic USART features sufficient to support printf functionality
|
|
|
|
* are currently implemented.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <errno.h>
|
2019-06-26 10:33:39 -04:00
|
|
|
#include <sys/__assert.h>
|
2016-10-13 17:55:02 +02:00
|
|
|
#include <device.h>
|
|
|
|
#include <init.h>
|
|
|
|
#include <soc.h>
|
2019-06-25 15:54:01 -04:00
|
|
|
#include <drivers/uart.h>
|
2016-10-13 17:55:02 +02:00
|
|
|
|
|
|
|
/* Device constant configuration parameters */
|
|
|
|
struct usart_sam_dev_cfg {
|
|
|
|
Usart *regs;
|
2020-05-27 11:26:57 -05:00
|
|
|
uint32_t periph_id;
|
2016-10-13 17:55:02 +02:00
|
|
|
struct soc_gpio_pin pin_rx;
|
|
|
|
struct soc_gpio_pin pin_tx;
|
2018-03-04 18:46:01 -08:00
|
|
|
|
|
|
|
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
|
|
|
uart_irq_config_func_t irq_config_func;
|
|
|
|
#endif
|
2016-10-13 17:55:02 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Device run time data */
|
|
|
|
struct usart_sam_dev_data {
|
2020-05-27 11:26:57 -05:00
|
|
|
uint32_t baud_rate;
|
2018-03-04 18:46:01 -08:00
|
|
|
|
|
|
|
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
2018-07-16 21:12:26 +03:00
|
|
|
uart_irq_callback_user_data_t irq_cb; /* Interrupt Callback */
|
|
|
|
void *cb_data; /* Interrupt Callback Arg */
|
2018-03-04 18:46:01 -08:00
|
|
|
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */
|
2016-10-13 17:55:02 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#define DEV_CFG(dev) \
|
2020-05-28 20:44:16 +02:00
|
|
|
((const struct usart_sam_dev_cfg *const)(dev)->config)
|
2016-10-13 17:55:02 +02:00
|
|
|
#define DEV_DATA(dev) \
|
2020-05-28 21:23:02 +02:00
|
|
|
((struct usart_sam_dev_data *const)(dev)->data)
|
2016-10-13 17:55:02 +02:00
|
|
|
|
|
|
|
|
2020-05-27 11:26:57 -05:00
|
|
|
static int baudrate_set(Usart *const usart, uint32_t baudrate,
|
|
|
|
uint32_t mck_freq_hz);
|
2016-10-13 17:55:02 +02:00
|
|
|
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int usart_sam_init(const struct device *dev)
|
2016-10-13 17:55:02 +02:00
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
const struct usart_sam_dev_cfg *const cfg = DEV_CFG(dev);
|
|
|
|
struct usart_sam_dev_data *const dev_data = DEV_DATA(dev);
|
|
|
|
Usart *const usart = cfg->regs;
|
|
|
|
|
|
|
|
/* Enable USART clock in PMC */
|
|
|
|
soc_pmc_peripheral_enable(cfg->periph_id);
|
|
|
|
|
|
|
|
/* Connect pins to the peripheral */
|
|
|
|
soc_gpio_configure(&cfg->pin_rx);
|
|
|
|
soc_gpio_configure(&cfg->pin_tx);
|
|
|
|
|
|
|
|
/* Reset and disable USART */
|
|
|
|
usart->US_CR = US_CR_RSTRX | US_CR_RSTTX
|
|
|
|
| US_CR_RXDIS | US_CR_TXDIS | US_CR_RSTSTA;
|
|
|
|
|
|
|
|
/* Disable Interrupts */
|
|
|
|
usart->US_IDR = 0xFFFFFFFF;
|
|
|
|
|
|
|
|
/* 8 bits of data, no parity, 1 stop bit in normal mode */
|
|
|
|
usart->US_MR = US_MR_NBSTOP_1_BIT
|
|
|
|
| US_MR_PAR_NO
|
|
|
|
| US_MR_CHRL_8_BIT
|
|
|
|
| US_MR_USCLKS_MCK
|
|
|
|
| US_MR_CHMODE_NORMAL;
|
|
|
|
|
|
|
|
/* Set baud rate */
|
|
|
|
retval = baudrate_set(usart, dev_data->baud_rate,
|
|
|
|
SOC_ATMEL_SAM_MCK_FREQ_HZ);
|
|
|
|
if (retval != 0) {
|
|
|
|
return retval;
|
2018-10-23 11:04:33 +05:30
|
|
|
}
|
2016-10-13 17:55:02 +02:00
|
|
|
|
|
|
|
/* Enable receiver and transmitter */
|
|
|
|
usart->US_CR = US_CR_RXEN | US_CR_TXEN;
|
|
|
|
|
2018-03-04 18:46:01 -08:00
|
|
|
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
|
|
|
cfg->irq_config_func(dev);
|
|
|
|
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */
|
|
|
|
|
2016-10-13 17:55:02 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int usart_sam_poll_in(const struct device *dev, unsigned char *c)
|
2016-10-13 17:55:02 +02:00
|
|
|
{
|
|
|
|
Usart *const usart = DEV_CFG(dev)->regs;
|
|
|
|
|
|
|
|
if (!(usart->US_CSR & US_CSR_RXRDY)) {
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* got a character */
|
|
|
|
*c = (unsigned char)usart->US_RHR;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static void usart_sam_poll_out(const struct device *dev, unsigned char c)
|
2016-10-13 17:55:02 +02:00
|
|
|
{
|
|
|
|
Usart *const usart = DEV_CFG(dev)->regs;
|
|
|
|
|
|
|
|
/* Wait for transmitter to be ready */
|
2018-03-04 18:46:01 -08:00
|
|
|
while (!(usart->US_CSR & US_CSR_TXRDY)) {
|
|
|
|
}
|
2016-10-13 17:55:02 +02:00
|
|
|
|
|
|
|
/* send a character */
|
2020-05-27 11:26:57 -05:00
|
|
|
usart->US_THR = (uint32_t)c;
|
2016-10-13 17:55:02 +02:00
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int usart_sam_err_check(const struct device *dev)
|
2018-03-04 18:46:01 -08:00
|
|
|
{
|
|
|
|
volatile Usart * const usart = DEV_CFG(dev)->regs;
|
|
|
|
int errors = 0;
|
|
|
|
|
|
|
|
if (usart->US_CSR & US_CSR_OVRE) {
|
|
|
|
errors |= UART_ERROR_OVERRUN;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (usart->US_CSR & US_CSR_PARE) {
|
|
|
|
errors |= UART_ERROR_PARITY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (usart->US_CSR & US_CSR_FRAME) {
|
|
|
|
errors |= UART_ERROR_FRAMING;
|
|
|
|
}
|
|
|
|
|
|
|
|
return errors;
|
|
|
|
}
|
|
|
|
|
2020-05-27 11:26:57 -05:00
|
|
|
static int baudrate_set(Usart *const usart, uint32_t baudrate,
|
|
|
|
uint32_t mck_freq_hz)
|
2016-10-13 17:55:02 +02:00
|
|
|
{
|
2020-05-27 11:26:57 -05:00
|
|
|
uint32_t divisor;
|
2016-10-13 17:55:02 +02:00
|
|
|
|
|
|
|
__ASSERT(baudrate,
|
|
|
|
"baud rate has to be bigger than 0");
|
2019-03-26 19:57:45 -06:00
|
|
|
__ASSERT(mck_freq_hz/16U >= baudrate,
|
2016-10-13 17:55:02 +02:00
|
|
|
"MCK frequency is too small to set required baud rate");
|
|
|
|
|
2019-03-26 19:57:45 -06:00
|
|
|
divisor = mck_freq_hz / 16U / baudrate;
|
2016-10-13 17:55:02 +02:00
|
|
|
|
|
|
|
if (divisor > 0xFFFF) {
|
|
|
|
return -EINVAL;
|
2018-10-23 11:04:33 +05:30
|
|
|
}
|
2016-10-13 17:55:02 +02:00
|
|
|
|
|
|
|
usart->US_BRGR = US_BRGR_CD(divisor);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-04 18:46:01 -08:00
|
|
|
#if CONFIG_UART_INTERRUPT_DRIVEN
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int usart_sam_fifo_fill(const struct device *dev,
|
|
|
|
const uint8_t *tx_data,
|
2018-03-04 18:46:01 -08:00
|
|
|
int size)
|
|
|
|
{
|
|
|
|
volatile Usart * const usart = DEV_CFG(dev)->regs;
|
|
|
|
|
|
|
|
/* Wait for transmitter to be ready. */
|
|
|
|
while ((usart->US_CSR & US_CSR_TXRDY) == 0) {
|
|
|
|
}
|
|
|
|
|
|
|
|
usart->US_THR = *tx_data;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int usart_sam_fifo_read(const struct device *dev, uint8_t *rx_data,
|
2018-03-04 18:46:01 -08:00
|
|
|
const int size)
|
|
|
|
{
|
|
|
|
volatile Usart * const usart = DEV_CFG(dev)->regs;
|
|
|
|
int bytes_read;
|
|
|
|
|
|
|
|
bytes_read = 0;
|
|
|
|
|
|
|
|
while (bytes_read < size) {
|
|
|
|
if (usart->US_CSR & US_CSR_RXRDY) {
|
|
|
|
rx_data[bytes_read] = usart->US_RHR;
|
|
|
|
bytes_read++;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return bytes_read;
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static void usart_sam_irq_tx_enable(const struct device *dev)
|
2018-03-04 18:46:01 -08:00
|
|
|
{
|
|
|
|
volatile Usart * const usart = DEV_CFG(dev)->regs;
|
|
|
|
|
|
|
|
usart->US_IER = US_IER_TXRDY;
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static void usart_sam_irq_tx_disable(const struct device *dev)
|
2018-03-04 18:46:01 -08:00
|
|
|
{
|
|
|
|
volatile Usart * const usart = DEV_CFG(dev)->regs;
|
|
|
|
|
|
|
|
usart->US_IDR = US_IDR_TXRDY;
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int usart_sam_irq_tx_ready(const struct device *dev)
|
2018-03-04 18:46:01 -08:00
|
|
|
{
|
|
|
|
volatile Usart * const usart = DEV_CFG(dev)->regs;
|
|
|
|
|
|
|
|
return (usart->US_CSR & US_CSR_TXRDY);
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static void usart_sam_irq_rx_enable(const struct device *dev)
|
2018-03-04 18:46:01 -08:00
|
|
|
{
|
|
|
|
volatile Usart * const usart = DEV_CFG(dev)->regs;
|
|
|
|
|
|
|
|
usart->US_IER = US_IER_RXRDY;
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static void usart_sam_irq_rx_disable(const struct device *dev)
|
2018-03-04 18:46:01 -08:00
|
|
|
{
|
|
|
|
volatile Usart * const usart = DEV_CFG(dev)->regs;
|
|
|
|
|
|
|
|
usart->US_IDR = US_IDR_RXRDY;
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int usart_sam_irq_tx_complete(const struct device *dev)
|
2018-03-04 18:46:01 -08:00
|
|
|
{
|
|
|
|
volatile Usart * const usart = DEV_CFG(dev)->regs;
|
|
|
|
|
|
|
|
return !(usart->US_CSR & US_CSR_TXRDY);
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int usart_sam_irq_rx_ready(const struct device *dev)
|
2018-03-04 18:46:01 -08:00
|
|
|
{
|
|
|
|
volatile Usart * const usart = DEV_CFG(dev)->regs;
|
|
|
|
|
|
|
|
return (usart->US_CSR & US_CSR_RXRDY);
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static void usart_sam_irq_err_enable(const struct device *dev)
|
2018-03-04 18:46:01 -08:00
|
|
|
{
|
|
|
|
volatile Usart * const usart = DEV_CFG(dev)->regs;
|
|
|
|
|
|
|
|
usart->US_IER = US_IER_OVRE | US_IER_FRAME | US_IER_PARE;
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static void usart_sam_irq_err_disable(const struct device *dev)
|
2018-03-04 18:46:01 -08:00
|
|
|
{
|
|
|
|
volatile Usart * const usart = DEV_CFG(dev)->regs;
|
|
|
|
|
|
|
|
usart->US_IDR = US_IDR_OVRE | US_IDR_FRAME | US_IDR_PARE;
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int usart_sam_irq_is_pending(const struct device *dev)
|
2018-03-04 18:46:01 -08:00
|
|
|
{
|
|
|
|
volatile Usart * const usart = DEV_CFG(dev)->regs;
|
|
|
|
|
2019-02-21 17:41:42 +01:00
|
|
|
return (usart->US_IMR & (US_IMR_TXRDY | US_IMR_RXRDY)) &
|
|
|
|
(usart->US_CSR & (US_CSR_TXRDY | US_CSR_RXRDY));
|
2018-03-04 18:46:01 -08:00
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int usart_sam_irq_update(const struct device *dev)
|
2018-03-04 18:46:01 -08:00
|
|
|
{
|
2020-03-05 16:15:16 +09:00
|
|
|
ARG_UNUSED(dev);
|
2018-03-04 18:46:01 -08:00
|
|
|
|
2020-03-05 16:15:16 +09:00
|
|
|
return 1;
|
2018-03-04 18:46:01 -08:00
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static void usart_sam_irq_callback_set(const struct device *dev,
|
2018-07-16 21:12:26 +03:00
|
|
|
uart_irq_callback_user_data_t cb,
|
|
|
|
void *cb_data)
|
2018-03-04 18:46:01 -08:00
|
|
|
{
|
|
|
|
struct usart_sam_dev_data *const dev_data = DEV_DATA(dev);
|
|
|
|
|
|
|
|
dev_data->irq_cb = cb;
|
2018-07-16 21:12:26 +03:00
|
|
|
dev_data->cb_data = cb_data;
|
2018-03-04 18:46:01 -08:00
|
|
|
}
|
|
|
|
|
isr: Normalize usage of device instance through ISR
The goal of this patch is to replace the 'void *' parameter by 'struct
device *' if they use such variable or just 'const void *' on all
relevant ISRs
This will avoid not-so-nice const qualifier tweaks when device instances
will be constant.
Note that only the ISR passed to IRQ_CONNECT are of interest here.
In order to do so, the script fix_isr.py below is necessary:
from pathlib import Path
import subprocess
import pickle
import mmap
import sys
import re
import os
cocci_template = """
@r_fix_isr_0
@
type ret_type;
identifier P;
identifier D;
@@
-ret_type <!fn!>(void *P)
+ret_type <!fn!>(const struct device *P)
{
...
(
const struct device *D = (const struct device *)P;
|
const struct device *D = P;
)
...
}
@r_fix_isr_1
@
type ret_type;
identifier P;
identifier D;
@@
-ret_type <!fn!>(void *P)
+ret_type <!fn!>(const struct device *P)
{
...
const struct device *D;
...
(
D = (const struct device *)P;
|
D = P;
)
...
}
@r_fix_isr_2
@
type ret_type;
identifier A;
@@
-ret_type <!fn!>(void *A)
+ret_type <!fn!>(const void *A)
{
...
}
@r_fix_isr_3
@
const struct device *D;
@@
-<!fn!>((void *)D);
+<!fn!>(D);
@r_fix_isr_4
@
type ret_type;
identifier D;
identifier P;
@@
-ret_type <!fn!>(const struct device *P)
+ret_type <!fn!>(const struct device *D)
{
...
(
-const struct device *D = (const struct device *)P;
|
-const struct device *D = P;
)
...
}
@r_fix_isr_5
@
type ret_type;
identifier D;
identifier P;
@@
-ret_type <!fn!>(const struct device *P)
+ret_type <!fn!>(const struct device *D)
{
...
-const struct device *D;
...
(
-D = (const struct device *)P;
|
-D = P;
)
...
}
"""
def find_isr(fn):
db = []
data = None
start = 0
try:
with open(fn, 'r+') as f:
data = str(mmap.mmap(f.fileno(), 0).read())
except Exception as e:
return db
while True:
isr = ""
irq = data.find('IRQ_CONNECT', start)
while irq > -1:
p = 1
arg = 1
p_o = data.find('(', irq)
if p_o < 0:
irq = -1
break;
pos = p_o + 1
while p > 0:
if data[pos] == ')':
p -= 1
elif data[pos] == '(':
p += 1
elif data[pos] == ',' and p == 1:
arg += 1
if arg == 3:
isr += data[pos]
pos += 1
isr = isr.strip(',\\n\\t ')
if isr not in db and len(isr) > 0:
db.append(isr)
start = pos
break
if irq < 0:
break
return db
def patch_isr(fn, isr_list):
if len(isr_list) <= 0:
return
for isr in isr_list:
tmplt = cocci_template.replace('<!fn!>', isr)
with open('/tmp/isr_fix.cocci', 'w') as f:
f.write(tmplt)
cmd = ['spatch', '--sp-file', '/tmp/isr_fix.cocci', '--in-place', fn]
subprocess.run(cmd)
def process_files(path):
if path.is_file() and path.suffix in ['.h', '.c']:
p = str(path.parent) + '/' + path.name
isr_list = find_isr(p)
patch_isr(p, isr_list)
elif path.is_dir():
for p in path.iterdir():
process_files(p)
if len(sys.argv) < 2:
print("You need to provide a dir/file path")
sys.exit(1)
process_files(Path(sys.argv[1]))
And is run: ./fix_isr.py <zephyr root directory>
Finally, some files needed manual fixes such.
Fixes #27399
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-06-17 14:58:56 +02:00
|
|
|
static void usart_sam_isr(const struct device *dev)
|
2018-03-04 18:46:01 -08:00
|
|
|
{
|
|
|
|
struct usart_sam_dev_data *const dev_data = DEV_DATA(dev);
|
|
|
|
|
|
|
|
if (dev_data->irq_cb) {
|
2020-06-24 15:47:15 +02:00
|
|
|
dev_data->irq_cb(dev, dev_data->cb_data);
|
2018-03-04 18:46:01 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */
|
|
|
|
|
2016-10-13 17:55:02 +02:00
|
|
|
static const struct uart_driver_api usart_sam_driver_api = {
|
|
|
|
.poll_in = usart_sam_poll_in,
|
|
|
|
.poll_out = usart_sam_poll_out,
|
2018-03-04 18:46:01 -08:00
|
|
|
.err_check = usart_sam_err_check,
|
|
|
|
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
|
|
|
.fifo_fill = usart_sam_fifo_fill,
|
|
|
|
.fifo_read = usart_sam_fifo_read,
|
|
|
|
.irq_tx_enable = usart_sam_irq_tx_enable,
|
|
|
|
.irq_tx_disable = usart_sam_irq_tx_disable,
|
|
|
|
.irq_tx_ready = usart_sam_irq_tx_ready,
|
|
|
|
.irq_rx_enable = usart_sam_irq_rx_enable,
|
|
|
|
.irq_rx_disable = usart_sam_irq_rx_disable,
|
|
|
|
.irq_tx_complete = usart_sam_irq_tx_complete,
|
|
|
|
.irq_rx_ready = usart_sam_irq_rx_ready,
|
|
|
|
.irq_err_enable = usart_sam_irq_err_enable,
|
|
|
|
.irq_err_disable = usart_sam_irq_err_disable,
|
|
|
|
.irq_is_pending = usart_sam_irq_is_pending,
|
|
|
|
.irq_update = usart_sam_irq_update,
|
|
|
|
.irq_callback_set = usart_sam_irq_callback_set,
|
|
|
|
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */
|
2016-10-13 17:55:02 +02:00
|
|
|
};
|
|
|
|
|
2020-04-09 16:53:17 -05:00
|
|
|
#define USART_SAM_DECLARE_CFG(n, IRQ_FUNC_INIT) \
|
|
|
|
static const struct usart_sam_dev_cfg usart##n##_sam_config = { \
|
|
|
|
.regs = (Usart *)DT_INST_REG_ADDR(n), \
|
|
|
|
.periph_id = DT_INST_PROP(n, peripheral_id), \
|
|
|
|
\
|
|
|
|
.pin_rx = ATMEL_SAM_DT_PIN(n, 0), \
|
|
|
|
.pin_tx = ATMEL_SAM_DT_PIN(n, 1), \
|
|
|
|
\
|
|
|
|
IRQ_FUNC_INIT \
|
|
|
|
}
|
2018-10-12 11:52:21 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
2020-04-09 16:53:17 -05:00
|
|
|
#define USART_SAM_CONFIG_FUNC(n) \
|
2020-04-30 20:33:38 +02:00
|
|
|
static void usart##n##_sam_irq_config_func(const struct device *port) \
|
2020-04-09 16:53:17 -05:00
|
|
|
{ \
|
|
|
|
IRQ_CONNECT(DT_INST_IRQN(n), \
|
|
|
|
DT_INST_IRQ(n, priority), \
|
|
|
|
usart_sam_isr, \
|
2020-12-11 10:12:30 -06:00
|
|
|
DEVICE_DT_INST_GET(n), 0); \
|
2020-04-09 16:53:17 -05:00
|
|
|
irq_enable(DT_INST_IRQN(n)); \
|
|
|
|
}
|
|
|
|
#define USART_SAM_IRQ_CFG_FUNC_INIT(n) \
|
|
|
|
.irq_config_func = usart##n##_sam_irq_config_func
|
|
|
|
#define USART_SAM_INIT_CFG(n) \
|
|
|
|
USART_SAM_DECLARE_CFG(n, USART_SAM_IRQ_CFG_FUNC_INIT(n))
|
|
|
|
#else
|
|
|
|
#define USART_SAM_CONFIG_FUNC(n)
|
|
|
|
#define USART_SAM_IRQ_CFG_FUNC_INIT
|
|
|
|
#define USART_SAM_INIT_CFG(n) \
|
|
|
|
USART_SAM_DECLARE_CFG(n, USART_SAM_IRQ_CFG_FUNC_INIT)
|
2018-10-12 11:52:21 +08:00
|
|
|
#endif
|
2016-10-13 17:55:02 +02:00
|
|
|
|
2020-04-09 16:53:17 -05:00
|
|
|
#define USART_SAM_INIT(n) \
|
|
|
|
static struct usart_sam_dev_data usart##n##_sam_data = { \
|
|
|
|
.baud_rate = DT_INST_PROP(n, current_speed), \
|
|
|
|
}; \
|
|
|
|
\
|
|
|
|
static const struct usart_sam_dev_cfg usart##n##_sam_config; \
|
|
|
|
\
|
2020-12-11 10:12:30 -06:00
|
|
|
DEVICE_DT_INST_DEFINE(n, \
|
2021-04-28 12:01:21 +02:00
|
|
|
&usart_sam_init, NULL, \
|
2020-12-11 10:12:30 -06:00
|
|
|
&usart##n##_sam_data, \
|
2020-04-09 16:53:17 -05:00
|
|
|
&usart##n##_sam_config, PRE_KERNEL_1, \
|
|
|
|
CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \
|
|
|
|
&usart_sam_driver_api); \
|
|
|
|
\
|
|
|
|
USART_SAM_CONFIG_FUNC(n) \
|
|
|
|
\
|
2020-05-07 14:09:05 -05:00
|
|
|
USART_SAM_INIT_CFG(n);
|
2020-04-09 16:53:17 -05:00
|
|
|
|
2020-05-06 11:23:07 -07:00
|
|
|
DT_INST_FOREACH_STATUS_OKAY(USART_SAM_INIT)
|