2018-10-30 18:26:25 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018, Christian Taedcke, Diego Sueiro
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
2020-03-24 14:49:56 -05:00
|
|
|
#define DT_DRV_COMPAT silabs_gecko_leuart
|
|
|
|
|
2018-10-30 18:26:25 +00:00
|
|
|
#include <errno.h>
|
2022-05-06 10:25:46 +02:00
|
|
|
#include <zephyr/drivers/uart.h>
|
2022-10-11 20:30:15 -04:00
|
|
|
#include <zephyr/irq.h>
|
2018-10-30 18:26:25 +00:00
|
|
|
#include <em_leuart.h>
|
|
|
|
#include <em_gpio.h>
|
|
|
|
#include <em_cmu.h>
|
2018-10-31 12:44:45 -05:00
|
|
|
#include <soc.h>
|
2018-10-30 18:26:25 +00:00
|
|
|
|
2019-09-20 08:34:57 +02:00
|
|
|
#define LEUART_PREFIX cmuClock_LEUART
|
|
|
|
#define CLOCK_ID_PRFX2(prefix, suffix) prefix##suffix
|
|
|
|
#define CLOCK_ID_PRFX(prefix, suffix) CLOCK_ID_PRFX2(prefix, suffix)
|
|
|
|
#define CLOCK_LEUART(id) CLOCK_ID_PRFX(LEUART_PREFIX, id)
|
|
|
|
|
2018-10-30 18:26:25 +00:00
|
|
|
#define DEV_BASE(dev) \
|
2022-01-18 16:58:32 +01:00
|
|
|
((LEUART_TypeDef *) \
|
|
|
|
((const struct leuart_gecko_config * const)(dev)->config)->base)
|
2018-10-30 18:26:25 +00:00
|
|
|
|
|
|
|
struct leuart_gecko_config {
|
|
|
|
LEUART_TypeDef *base;
|
|
|
|
CMU_Clock_TypeDef clock;
|
2020-05-27 11:26:57 -05:00
|
|
|
uint32_t baud_rate;
|
2018-10-30 18:26:25 +00:00
|
|
|
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
2020-04-30 20:33:38 +02:00
|
|
|
void (*irq_config_func)(const struct device *dev);
|
2019-01-31 15:27:21 +01:00
|
|
|
#endif
|
|
|
|
struct soc_gpio_pin pin_rx;
|
|
|
|
struct soc_gpio_pin pin_tx;
|
|
|
|
#ifdef CONFIG_SOC_GECKO_HAS_INDIVIDUAL_PIN_LOCATION
|
2020-05-27 11:26:57 -05:00
|
|
|
uint8_t loc_rx;
|
|
|
|
uint8_t loc_tx;
|
2019-01-31 15:27:21 +01:00
|
|
|
#else
|
2020-05-27 11:26:57 -05:00
|
|
|
uint8_t loc;
|
2018-10-30 18:26:25 +00:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
struct leuart_gecko_data {
|
|
|
|
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
|
|
|
uart_irq_callback_user_data_t callback;
|
|
|
|
void *cb_data;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int leuart_gecko_poll_in(const struct device *dev, unsigned char *c)
|
2018-10-30 18:26:25 +00:00
|
|
|
{
|
|
|
|
LEUART_TypeDef *base = DEV_BASE(dev);
|
2020-05-27 11:26:57 -05:00
|
|
|
uint32_t flags = LEUART_StatusGet(base);
|
2018-10-30 18:26:25 +00:00
|
|
|
|
|
|
|
if (flags & LEUART_STATUS_RXDATAV) {
|
|
|
|
*c = LEUART_Rx(base);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static void leuart_gecko_poll_out(const struct device *dev, unsigned char c)
|
2018-10-30 18:26:25 +00:00
|
|
|
{
|
|
|
|
LEUART_TypeDef *base = DEV_BASE(dev);
|
|
|
|
|
|
|
|
/* LEUART_Tx function already waits for the transmit buffer being empty
|
everywhere: replace double words
import os
import re
common_words = set([
'about', 'after', 'all', 'also', 'an', 'and',
'any', 'are', 'as', 'at',
'be', 'because', 'but', 'by', 'can', 'come',
'could', 'day', 'do', 'even',
'first', 'for', 'get', 'give', 'go', 'has',
'have', 'he', 'her',
'him', 'his', 'how', 'I', 'in', 'into', 'it',
'its', 'just',
'know', 'like', 'look', 'make', 'man', 'many',
'me', 'more', 'my', 'new',
'no', 'not', 'now', 'of', 'one', 'only', 'or',
'other', 'our', 'out',
'over', 'people', 'say', 'see', 'she', 'so',
'some', 'take', 'tell', 'than',
'their', 'them', 'then', 'there', 'these',
'they', 'think',
'this', 'time', 'two', 'up', 'use', 'very',
'want', 'was', 'way',
'we', 'well', 'what', 'when', 'which', 'who',
'will', 'with', 'would',
'year', 'you', 'your'
])
valid_extensions = set([
'c', 'h', 'yaml', 'cmake', 'conf', 'txt', 'overlay',
'rst', 'dtsi',
'Kconfig', 'dts', 'defconfig', 'yml', 'ld', 'sh', 'py',
'soc', 'cfg'
])
def filter_repeated_words(text):
# Split the text into lines
lines = text.split('\n')
# Combine lines into a single string with unique separator
combined_text = '/*sep*/'.join(lines)
# Replace repeated words within a line
def replace_within_line(match):
return match.group(1)
# Regex for matching repeated words within a line
within_line_pattern =
re.compile(r'\b(' +
'|'.join(map(re.escape, common_words)) +
r')\b\s+\b\1\b')
combined_text = within_line_pattern.
sub(replace_within_line, combined_text)
# Replace repeated words across line boundaries
def replace_across_lines(match):
return match.group(1) + match.group(2)
# Regex for matching repeated words across line boundaries
across_lines_pattern = re.
compile(r'\b(' + '|'.join(
map(re.escape, common_words)) +
r')\b(\s*[*\/\n\s]*)\b\1\b')
combined_text = across_lines_pattern.
sub(replace_across_lines, combined_text)
# Split the text back into lines
filtered_text = combined_text.split('/*sep*/')
return '\n'.join(filtered_text)
def process_file(file_path):
with open(file_path, 'r', encoding='utf-8') as file:
text = file.read()
new_text = filter_repeated_words(text)
with open(file_path, 'w', encoding='utf-8') as file:
file.write(new_text)
def process_directory(directory_path):
for root, dirs, files in os.walk(directory_path):
dirs[:] = [d for d in dirs if not d.startswith('.')]
for file in files:
# Filter out hidden files
if file.startswith('.'):
continue
file_extension = file.split('.')[-1]
if
file_extension in valid_extensions: # 只处理指定后缀的文件
file_path = os.path.join(root, file)
print(f"Processed file: {file_path}")
process_file(file_path)
directory_to_process = "/home/mi/works/github/zephyrproject/zephyr"
process_directory(directory_to_process)
Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2024-06-22 14:28:05 +08:00
|
|
|
* and waits for the bus to be free to transmit.
|
2018-10-30 18:26:25 +00:00
|
|
|
*/
|
|
|
|
LEUART_Tx(base, c);
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int leuart_gecko_err_check(const struct device *dev)
|
2018-10-30 18:26:25 +00:00
|
|
|
{
|
|
|
|
LEUART_TypeDef *base = DEV_BASE(dev);
|
2020-05-27 11:26:57 -05:00
|
|
|
uint32_t flags = LEUART_IntGet(base);
|
2018-10-30 18:26:25 +00:00
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
if (flags & LEUART_IF_RXOF) {
|
|
|
|
err |= UART_ERROR_OVERRUN;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & LEUART_IF_PERR) {
|
|
|
|
err |= UART_ERROR_PARITY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & LEUART_IF_FERR) {
|
|
|
|
err |= UART_ERROR_FRAMING;
|
|
|
|
}
|
|
|
|
|
|
|
|
LEUART_IntClear(base, LEUART_IF_RXOF |
|
|
|
|
LEUART_IF_PERR |
|
|
|
|
LEUART_IF_FERR);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
2020-04-30 20:33:38 +02:00
|
|
|
static int leuart_gecko_fifo_fill(const struct device *dev,
|
|
|
|
const uint8_t *tx_data,
|
|
|
|
int len)
|
2018-10-30 18:26:25 +00:00
|
|
|
{
|
|
|
|
LEUART_TypeDef *base = DEV_BASE(dev);
|
2024-10-30 19:34:45 +08:00
|
|
|
int num_tx = 0U;
|
2018-10-30 18:26:25 +00:00
|
|
|
|
|
|
|
while ((len - num_tx > 0) &&
|
|
|
|
(base->STATUS & LEUART_STATUS_TXBL)) {
|
|
|
|
|
2020-05-27 11:26:57 -05:00
|
|
|
base->TXDATA = (uint32_t)tx_data[num_tx++];
|
2018-10-30 18:26:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return num_tx;
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int leuart_gecko_fifo_read(const struct device *dev, uint8_t *rx_data,
|
|
|
|
const int len)
|
2018-10-30 18:26:25 +00:00
|
|
|
{
|
|
|
|
LEUART_TypeDef *base = DEV_BASE(dev);
|
2024-10-30 19:34:45 +08:00
|
|
|
int num_rx = 0U;
|
2018-10-30 18:26:25 +00:00
|
|
|
|
|
|
|
while ((len - num_rx > 0) &&
|
|
|
|
(base->STATUS & LEUART_STATUS_RXDATAV)) {
|
|
|
|
|
2020-05-27 11:26:57 -05:00
|
|
|
rx_data[num_rx++] = (uint8_t)base->RXDATA;
|
2018-10-30 18:26:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return num_rx;
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static void leuart_gecko_irq_tx_enable(const struct device *dev)
|
2018-10-30 18:26:25 +00:00
|
|
|
{
|
|
|
|
LEUART_TypeDef *base = DEV_BASE(dev);
|
2020-05-27 11:26:57 -05:00
|
|
|
uint32_t mask = LEUART_IEN_TXBL | LEUART_IEN_TXC;
|
2018-10-30 18:26:25 +00:00
|
|
|
|
|
|
|
LEUART_IntEnable(base, mask);
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static void leuart_gecko_irq_tx_disable(const struct device *dev)
|
2018-10-30 18:26:25 +00:00
|
|
|
{
|
|
|
|
LEUART_TypeDef *base = DEV_BASE(dev);
|
2020-05-27 11:26:57 -05:00
|
|
|
uint32_t mask = LEUART_IEN_TXBL | LEUART_IEN_TXC;
|
2018-10-30 18:26:25 +00:00
|
|
|
|
|
|
|
LEUART_IntDisable(base, mask);
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int leuart_gecko_irq_tx_complete(const struct device *dev)
|
2018-10-30 18:26:25 +00:00
|
|
|
{
|
|
|
|
LEUART_TypeDef *base = DEV_BASE(dev);
|
2020-05-27 11:26:57 -05:00
|
|
|
uint32_t flags = LEUART_IntGet(base);
|
2018-10-30 18:26:25 +00:00
|
|
|
|
2019-03-26 19:57:45 -06:00
|
|
|
return (flags & LEUART_IF_TXC) != 0U;
|
2018-10-30 18:26:25 +00:00
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int leuart_gecko_irq_tx_ready(const struct device *dev)
|
2018-10-30 18:26:25 +00:00
|
|
|
{
|
|
|
|
LEUART_TypeDef *base = DEV_BASE(dev);
|
2020-05-27 11:26:57 -05:00
|
|
|
uint32_t flags = LEUART_IntGet(base);
|
2018-10-30 18:26:25 +00:00
|
|
|
|
2019-03-26 19:57:45 -06:00
|
|
|
return (flags & LEUART_IF_TXBL) != 0U;
|
2018-10-30 18:26:25 +00:00
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static void leuart_gecko_irq_rx_enable(const struct device *dev)
|
2018-10-30 18:26:25 +00:00
|
|
|
{
|
|
|
|
LEUART_TypeDef *base = DEV_BASE(dev);
|
2020-05-27 11:26:57 -05:00
|
|
|
uint32_t mask = LEUART_IEN_RXDATAV;
|
2018-10-30 18:26:25 +00:00
|
|
|
|
|
|
|
LEUART_IntEnable(base, mask);
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static void leuart_gecko_irq_rx_disable(const struct device *dev)
|
2018-10-30 18:26:25 +00:00
|
|
|
{
|
|
|
|
LEUART_TypeDef *base = DEV_BASE(dev);
|
2020-05-27 11:26:57 -05:00
|
|
|
uint32_t mask = LEUART_IEN_RXDATAV;
|
2018-10-30 18:26:25 +00:00
|
|
|
|
|
|
|
LEUART_IntDisable(base, mask);
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int leuart_gecko_irq_rx_full(const struct device *dev)
|
2018-10-30 18:26:25 +00:00
|
|
|
{
|
|
|
|
LEUART_TypeDef *base = DEV_BASE(dev);
|
2020-05-27 11:26:57 -05:00
|
|
|
uint32_t flags = LEUART_IntGet(base);
|
2018-10-30 18:26:25 +00:00
|
|
|
|
2019-03-26 19:57:45 -06:00
|
|
|
return (flags & LEUART_IF_RXDATAV) != 0U;
|
2018-10-30 18:26:25 +00:00
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int leuart_gecko_irq_rx_ready(const struct device *dev)
|
2018-10-30 18:26:25 +00:00
|
|
|
{
|
|
|
|
LEUART_TypeDef *base = DEV_BASE(dev);
|
2020-05-27 11:26:57 -05:00
|
|
|
uint32_t mask = LEUART_IEN_RXDATAV;
|
2018-10-30 18:26:25 +00:00
|
|
|
|
|
|
|
return (base->IEN & mask)
|
|
|
|
&& leuart_gecko_irq_rx_full(dev);
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static void leuart_gecko_irq_err_enable(const struct device *dev)
|
2018-10-30 18:26:25 +00:00
|
|
|
{
|
|
|
|
LEUART_TypeDef *base = DEV_BASE(dev);
|
|
|
|
|
|
|
|
LEUART_IntEnable(base, LEUART_IF_RXOF |
|
|
|
|
LEUART_IF_PERR |
|
|
|
|
LEUART_IF_FERR);
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static void leuart_gecko_irq_err_disable(const struct device *dev)
|
2018-10-30 18:26:25 +00:00
|
|
|
{
|
|
|
|
LEUART_TypeDef *base = DEV_BASE(dev);
|
|
|
|
|
|
|
|
LEUART_IntDisable(base, LEUART_IF_RXOF |
|
|
|
|
LEUART_IF_PERR |
|
|
|
|
LEUART_IF_FERR);
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int leuart_gecko_irq_is_pending(const struct device *dev)
|
2018-10-30 18:26:25 +00:00
|
|
|
{
|
|
|
|
return leuart_gecko_irq_tx_ready(dev) || leuart_gecko_irq_rx_ready(dev);
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int leuart_gecko_irq_update(const struct device *dev)
|
2018-10-30 18:26:25 +00:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static void leuart_gecko_irq_callback_set(const struct device *dev,
|
2018-10-30 18:26:25 +00:00
|
|
|
uart_irq_callback_user_data_t cb,
|
|
|
|
void *cb_data)
|
|
|
|
{
|
2020-05-28 21:23:02 +02:00
|
|
|
struct leuart_gecko_data *data = dev->data;
|
2018-10-30 18:26:25 +00:00
|
|
|
|
|
|
|
data->callback = cb;
|
|
|
|
data->cb_data = cb_data;
|
|
|
|
}
|
|
|
|
|
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 leuart_gecko_isr(const struct device *dev)
|
2018-10-30 18:26:25 +00:00
|
|
|
{
|
2020-05-28 21:23:02 +02:00
|
|
|
struct leuart_gecko_data *data = dev->data;
|
2018-10-30 18:26:25 +00:00
|
|
|
|
|
|
|
if (data->callback) {
|
2020-06-24 15:47:15 +02:00
|
|
|
data->callback(dev, data->cb_data);
|
2018-10-30 18:26:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static void leuart_gecko_init_pins(const struct device *dev)
|
2018-10-30 18:26:25 +00:00
|
|
|
{
|
2022-01-18 16:58:32 +01:00
|
|
|
const struct leuart_gecko_config *config = dev->config;
|
2018-10-30 18:26:25 +00:00
|
|
|
LEUART_TypeDef *base = DEV_BASE(dev);
|
|
|
|
|
2022-10-24 10:20:45 +02:00
|
|
|
GPIO_PinModeSet(config->pin_rx.port, config->pin_rx.pin,
|
|
|
|
config->pin_rx.mode, config->pin_rx.out);
|
|
|
|
GPIO_PinModeSet(config->pin_tx.port, config->pin_tx.pin,
|
|
|
|
config->pin_tx.mode, config->pin_tx.out);
|
2018-10-30 18:26:25 +00:00
|
|
|
|
2019-01-31 15:27:21 +01:00
|
|
|
#ifdef CONFIG_SOC_GECKO_HAS_INDIVIDUAL_PIN_LOCATION
|
2018-10-30 18:26:25 +00:00
|
|
|
base->ROUTEPEN = LEUART_ROUTEPEN_RXPEN | LEUART_ROUTEPEN_TXPEN;
|
2019-01-31 15:27:21 +01:00
|
|
|
base->ROUTELOC0 =
|
|
|
|
(config->loc_tx << _LEUART_ROUTELOC0_TXLOC_SHIFT) |
|
|
|
|
(config->loc_rx << _LEUART_ROUTELOC0_RXLOC_SHIFT);
|
2018-10-30 18:26:25 +00:00
|
|
|
#else
|
|
|
|
base->ROUTE = LEUART_ROUTE_RXPEN | LEUART_ROUTE_TXPEN
|
2019-01-31 15:27:21 +01:00
|
|
|
| (config->loc << 8);
|
2018-10-30 18:26:25 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int leuart_gecko_init(const struct device *dev)
|
2018-10-30 18:26:25 +00:00
|
|
|
{
|
2022-01-18 16:58:32 +01:00
|
|
|
const struct leuart_gecko_config *config = dev->config;
|
2018-10-30 18:26:25 +00:00
|
|
|
LEUART_TypeDef *base = DEV_BASE(dev);
|
|
|
|
LEUART_Init_TypeDef leuartInit = LEUART_INIT_DEFAULT;
|
|
|
|
|
|
|
|
/* The peripheral and gpio clock are already enabled from soc and gpio
|
|
|
|
* driver
|
|
|
|
*/
|
|
|
|
|
|
|
|
leuartInit.baudrate = config->baud_rate;
|
|
|
|
|
|
|
|
/* Enable CORE LE clock in order to access LE modules */
|
|
|
|
CMU_ClockEnable(cmuClock_CORELE, true);
|
|
|
|
|
|
|
|
/* Select LFXO for LEUARTs (and wait for it to stabilize) */
|
|
|
|
CMU_ClockSelectSet(cmuClock_LFB, cmuSelect_LFXO);
|
|
|
|
|
2019-01-31 15:27:21 +01:00
|
|
|
/* Enable LEUART clock */
|
|
|
|
CMU_ClockEnable(config->clock, true);
|
|
|
|
|
2018-10-30 18:26:25 +00:00
|
|
|
/* Init LEUART */
|
|
|
|
LEUART_Init(base, &leuartInit);
|
|
|
|
|
|
|
|
/* Initialize LEUART pins */
|
|
|
|
leuart_gecko_init_pins(dev);
|
|
|
|
|
|
|
|
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
|
|
|
config->irq_config_func(dev);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-11-28 21:21:48 +01:00
|
|
|
static DEVICE_API(uart, leuart_gecko_driver_api) = {
|
2018-10-30 18:26:25 +00:00
|
|
|
.poll_in = leuart_gecko_poll_in,
|
|
|
|
.poll_out = leuart_gecko_poll_out,
|
|
|
|
.err_check = leuart_gecko_err_check,
|
|
|
|
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
|
|
|
.fifo_fill = leuart_gecko_fifo_fill,
|
|
|
|
.fifo_read = leuart_gecko_fifo_read,
|
|
|
|
.irq_tx_enable = leuart_gecko_irq_tx_enable,
|
|
|
|
.irq_tx_disable = leuart_gecko_irq_tx_disable,
|
|
|
|
.irq_tx_complete = leuart_gecko_irq_tx_complete,
|
|
|
|
.irq_tx_ready = leuart_gecko_irq_tx_ready,
|
|
|
|
.irq_rx_enable = leuart_gecko_irq_rx_enable,
|
|
|
|
.irq_rx_disable = leuart_gecko_irq_rx_disable,
|
|
|
|
.irq_rx_ready = leuart_gecko_irq_rx_ready,
|
|
|
|
.irq_err_enable = leuart_gecko_irq_err_enable,
|
|
|
|
.irq_err_disable = leuart_gecko_irq_err_disable,
|
|
|
|
.irq_is_pending = leuart_gecko_irq_is_pending,
|
|
|
|
.irq_update = leuart_gecko_irq_update,
|
|
|
|
.irq_callback_set = leuart_gecko_irq_callback_set,
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2024-09-20 12:47:40 +08:00
|
|
|
#if DT_NODE_HAS_STATUS_OKAY(DT_DRV_INST(0))
|
2019-01-31 15:27:21 +01:00
|
|
|
|
2020-03-24 14:49:56 -05:00
|
|
|
#define PIN_LEUART_0_RXD {DT_INST_PROP_BY_IDX(0, location_rx, 1), \
|
|
|
|
DT_INST_PROP_BY_IDX(0, location_rx, 2), gpioModeInput, 1}
|
|
|
|
#define PIN_LEUART_0_TXD {DT_INST_PROP_BY_IDX(0, location_tx, 1), \
|
|
|
|
DT_INST_PROP_BY_IDX(0, location_tx, 2), gpioModePushPull, 1}
|
2018-10-30 18:26:25 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
2020-04-30 20:33:38 +02:00
|
|
|
static void leuart_gecko_config_func_0(const struct device *dev);
|
2018-10-30 18:26:25 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static const struct leuart_gecko_config leuart_gecko_0_config = {
|
2020-03-24 14:49:56 -05:00
|
|
|
.base = (LEUART_TypeDef *)DT_INST_REG_ADDR(0),
|
|
|
|
.clock = CLOCK_LEUART(DT_INST_PROP(0, peripheral_id)),
|
|
|
|
.baud_rate = DT_INST_PROP(0, current_speed),
|
2019-01-31 15:27:21 +01:00
|
|
|
.pin_rx = PIN_LEUART_0_RXD,
|
|
|
|
.pin_tx = PIN_LEUART_0_TXD,
|
|
|
|
#ifdef CONFIG_SOC_GECKO_HAS_INDIVIDUAL_PIN_LOCATION
|
2020-03-24 14:49:56 -05:00
|
|
|
.loc_rx = DT_INST_PROP_BY_IDX(0, location_rx, 0),
|
|
|
|
.loc_tx = DT_INST_PROP_BY_IDX(0, location_tx, 0),
|
2019-01-31 15:27:21 +01:00
|
|
|
#else
|
2020-03-24 14:49:56 -05:00
|
|
|
#if DT_INST_PROP_BY_IDX(0, location_rx, 0) \
|
|
|
|
!= DT_INST_PROP_BY_IDX(0, location_tx, 0)
|
2019-01-31 15:27:21 +01:00
|
|
|
#error LEUART_0 DTS location-* properties must have identical value
|
|
|
|
#endif
|
2020-03-24 14:49:56 -05:00
|
|
|
.loc = DT_INST_PROP_BY_IDX(0, location_rx, 0),
|
2019-01-31 15:27:21 +01:00
|
|
|
#endif
|
2018-10-30 18:26:25 +00:00
|
|
|
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
|
|
|
.irq_config_func = leuart_gecko_config_func_0,
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct leuart_gecko_data leuart_gecko_0_data;
|
|
|
|
|
2020-12-11 10:12:30 -06:00
|
|
|
DEVICE_DT_INST_DEFINE(0, &leuart_gecko_init,
|
2021-04-28 12:01:21 +02:00
|
|
|
NULL, &leuart_gecko_0_data,
|
2018-11-28 13:07:44 +01:00
|
|
|
&leuart_gecko_0_config, PRE_KERNEL_1,
|
2021-10-14 09:38:10 -05:00
|
|
|
CONFIG_SERIAL_INIT_PRIORITY,
|
2018-10-30 18:26:25 +00:00
|
|
|
&leuart_gecko_driver_api);
|
|
|
|
|
|
|
|
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
2020-04-30 20:33:38 +02:00
|
|
|
static void leuart_gecko_config_func_0(const struct device *dev)
|
2018-10-30 18:26:25 +00:00
|
|
|
{
|
2020-03-24 14:49:56 -05:00
|
|
|
IRQ_CONNECT(DT_INST_IRQN(0),
|
|
|
|
DT_INST_IRQ(0, priority),
|
2020-12-11 10:12:30 -06:00
|
|
|
leuart_gecko_isr, DEVICE_DT_INST_GET(0), 0);
|
2018-10-30 18:26:25 +00:00
|
|
|
|
2020-03-24 14:49:56 -05:00
|
|
|
irq_enable(DT_INST_IRQN(0));
|
2018-10-30 18:26:25 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2024-09-20 12:47:40 +08:00
|
|
|
#endif /* DT_NODE_HAS_STATUS_OKAY(DT_DRV_INST(0)) */
|
2019-01-31 15:27:21 +01:00
|
|
|
|
2024-09-20 12:47:40 +08:00
|
|
|
#if DT_NODE_HAS_STATUS_OKAY(DT_DRV_INST(1))
|
2018-10-30 18:26:25 +00:00
|
|
|
|
2020-03-24 14:49:56 -05:00
|
|
|
#define PIN_LEUART_1_RXD {DT_INST_PROP_BY_IDX(1, location_rx, 1), \
|
|
|
|
DT_INST_PROP_BY_IDX(1, location_rx, 2), gpioModeInput, 1}
|
|
|
|
#define PIN_LEUART_1_TXD {DT_INST_PROP_BY_IDX(1, location_tx, 1), \
|
|
|
|
DT_INST_PROP_BY_IDX(1, location_tx, 2), gpioModePushPull, 1}
|
2018-10-30 18:26:25 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
2020-04-30 20:33:38 +02:00
|
|
|
static void leuart_gecko_config_func_1(const struct device *dev);
|
2018-10-30 18:26:25 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static const struct leuart_gecko_config leuart_gecko_1_config = {
|
2020-03-24 14:49:56 -05:00
|
|
|
.base = (LEUART_TypeDef *)DT_INST_REG_ADDR(1),
|
|
|
|
.clock = CLOCK_LEUART(DT_INST_PROP(1, peripheral_id)),
|
|
|
|
.baud_rate = DT_INST_PROP(1, current_speed),
|
2019-01-31 15:27:21 +01:00
|
|
|
.pin_rx = PIN_LEUART_1_RXD,
|
|
|
|
.pin_tx = PIN_LEUART_1_TXD,
|
|
|
|
#ifdef CONFIG_SOC_GECKO_HAS_INDIVIDUAL_PIN_LOCATION
|
2020-03-24 14:49:56 -05:00
|
|
|
.loc_rx = DT_INST_PROP_BY_IDX(1, location_rx, 0),
|
|
|
|
.loc_tx = DT_INST_PROP_BY_IDX(1, location_tx, 0),
|
2019-01-31 15:27:21 +01:00
|
|
|
#else
|
2020-03-24 14:49:56 -05:00
|
|
|
#if DT_INST_PROP_BY_IDX(1, location_rx, 0) \
|
|
|
|
!= DT_INST_PROP_BY_IDX(1, location_tx, 0)
|
2019-01-31 15:27:21 +01:00
|
|
|
#error LEUART_1 DTS location-* properties must have identical value
|
|
|
|
#endif
|
2020-03-24 14:49:56 -05:00
|
|
|
.loc = DT_INST_PROP_BY_IDX(1, location_rx, 0),
|
2019-01-31 15:27:21 +01:00
|
|
|
#endif
|
2018-10-30 18:26:25 +00:00
|
|
|
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
|
|
|
.irq_config_func = leuart_gecko_config_func_1,
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct leuart_gecko_data leuart_gecko_1_data;
|
|
|
|
|
2020-12-11 10:12:30 -06:00
|
|
|
DEVICE_DT_INST_DEFINE(1, &leuart_gecko_init,
|
2021-04-28 12:01:21 +02:00
|
|
|
NULL, &leuart_gecko_1_data,
|
2018-11-28 13:07:44 +01:00
|
|
|
&leuart_gecko_1_config, PRE_KERNEL_1,
|
2021-10-14 09:38:10 -05:00
|
|
|
CONFIG_SERIAL_INIT_PRIORITY,
|
2018-10-30 18:26:25 +00:00
|
|
|
&leuart_gecko_driver_api);
|
|
|
|
|
|
|
|
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
2020-04-30 20:33:38 +02:00
|
|
|
static void leuart_gecko_config_func_1(const struct device *dev)
|
2018-10-30 18:26:25 +00:00
|
|
|
{
|
2020-03-24 14:49:56 -05:00
|
|
|
IRQ_CONNECT(DT_INST_IRQN(1),
|
|
|
|
DT_INST_IRQ(1, priority),
|
2020-12-11 10:12:30 -06:00
|
|
|
leuart_gecko_isr, DEVICE_DT_INST_GET(1), 0);
|
2018-10-30 18:26:25 +00:00
|
|
|
|
2020-03-24 14:49:56 -05:00
|
|
|
irq_enable(DT_INST_IRQN(1));
|
2018-10-30 18:26:25 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2024-09-20 12:47:40 +08:00
|
|
|
#endif /* DT_NODE_HAS_STATUS_OKAY(DT_DRV_INST(1)) */
|