2016-11-01 01:46:32 +01:00
|
|
|
/*
|
2017-03-30 03:10:42 +02:00
|
|
|
* Copyright (c) 2016-2017, Texas Instruments Incorporated
|
2016-11-01 01:46:32 +01:00
|
|
|
*
|
2017-01-19 02:01:01 +01:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2016-11-01 01:46:32 +01:00
|
|
|
*/
|
|
|
|
|
2020-04-23 02:53:46 +02:00
|
|
|
#define DT_DRV_COMPAT ti_cc32xx_uart
|
|
|
|
|
2022-05-06 10:25:46 +02:00
|
|
|
#include <zephyr/kernel.h>
|
|
|
|
#include <zephyr/arch/cpu.h>
|
|
|
|
#include <zephyr/drivers/uart.h>
|
2023-06-12 13:58:36 +02:00
|
|
|
#include <zephyr/drivers/pinctrl.h>
|
2016-11-01 01:46:32 +01:00
|
|
|
|
|
|
|
/* Driverlib includes */
|
|
|
|
#include <inc/hw_types.h>
|
|
|
|
#include <driverlib/rom.h>
|
|
|
|
#include <driverlib/rom_map.h>
|
|
|
|
#include <driverlib/prcm.h>
|
|
|
|
#include <driverlib/uart.h>
|
2022-10-17 10:24:11 +02:00
|
|
|
#include <zephyr/irq.h>
|
2016-11-01 01:46:32 +01:00
|
|
|
|
2022-01-25 19:19:43 +01:00
|
|
|
struct uart_cc32xx_dev_config {
|
|
|
|
unsigned long base;
|
|
|
|
uint32_t sys_clk_freq;
|
2023-06-12 13:58:36 +02:00
|
|
|
const struct pinctrl_dev_config *pcfg;
|
2022-01-25 19:19:43 +01:00
|
|
|
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
|
|
|
uart_irq_config_func_t irq_config_func;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2016-11-01 01:46:32 +01:00
|
|
|
struct uart_cc32xx_dev_data_t {
|
2021-02-01 18:59:34 +01:00
|
|
|
uint32_t prcm;
|
|
|
|
uint32_t baud_rate;
|
2016-11-01 01:46:32 +01:00
|
|
|
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
2018-07-16 20:12:26 +02:00
|
|
|
uart_irq_callback_user_data_t cb; /**< Callback function pointer */
|
|
|
|
void *cb_data; /**< Callback function arg */
|
2016-11-01 01:46:32 +01:00
|
|
|
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */
|
|
|
|
};
|
|
|
|
|
2018-11-14 03:04:24 +01:00
|
|
|
#define PRIME_CHAR '\r'
|
|
|
|
|
2016-11-01 01:46:32 +01:00
|
|
|
/* Forward decls: */
|
|
|
|
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
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 uart_cc32xx_isr(const struct device *dev);
|
2016-11-01 01:46:32 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* CC32XX UART has a configurable FIFO length, from 1 to 8 characters.
|
|
|
|
* However, the Zephyr console driver, and the Zephyr uart sample test, assume
|
|
|
|
* a RX FIFO depth of one: meaning, one interrupt == one character received.
|
|
|
|
* Keeping with this assumption, this driver leaves the FIFOs disabled,
|
|
|
|
* and at depth 1.
|
|
|
|
*/
|
2020-04-30 20:33:38 +02:00
|
|
|
static int uart_cc32xx_init(const struct device *dev)
|
2016-11-01 01:46:32 +01:00
|
|
|
{
|
2022-01-25 19:19:43 +01:00
|
|
|
const struct uart_cc32xx_dev_config *config = dev->config;
|
2022-01-18 16:58:32 +01:00
|
|
|
const struct uart_cc32xx_dev_data_t *data = dev->data;
|
2023-06-12 13:58:36 +02:00
|
|
|
int ret;
|
2021-02-01 18:59:34 +01:00
|
|
|
|
|
|
|
MAP_PRCMPeripheralClkEnable(data->prcm,
|
|
|
|
PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK);
|
2016-11-01 01:46:32 +01:00
|
|
|
|
2021-02-01 18:59:34 +01:00
|
|
|
MAP_PRCMPeripheralReset(data->prcm);
|
2016-11-01 01:46:32 +01:00
|
|
|
|
2023-06-12 13:58:36 +02:00
|
|
|
ret = pinctrl_apply_state(config->pcfg, PINCTRL_STATE_DEFAULT);
|
|
|
|
if (ret < 0) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-11-01 01:46:32 +01:00
|
|
|
/* This also calls MAP_UARTEnable() to enable the FIFOs: */
|
2022-01-25 19:19:43 +01:00
|
|
|
MAP_UARTConfigSetExpClk(config->base,
|
2021-02-01 18:59:34 +01:00
|
|
|
MAP_PRCMPeripheralClockGet(data->prcm),
|
|
|
|
data->baud_rate,
|
2016-11-01 01:46:32 +01:00
|
|
|
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE
|
|
|
|
| UART_CONFIG_PAR_NONE));
|
2022-01-25 19:19:43 +01:00
|
|
|
MAP_UARTFlowControlSet(config->base, UART_FLOWCONTROL_NONE);
|
2016-11-01 01:46:32 +01:00
|
|
|
/* Re-disable the FIFOs: */
|
2022-01-25 19:19:43 +01:00
|
|
|
MAP_UARTFIFODisable(config->base);
|
2016-11-01 01:46:32 +01:00
|
|
|
|
|
|
|
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
2018-11-14 03:04:24 +01:00
|
|
|
/* Clear any pending UART RX interrupts: */
|
2022-01-25 19:19:43 +01:00
|
|
|
MAP_UARTIntClear(config->base, UART_INT_RX);
|
2016-11-01 01:46:32 +01:00
|
|
|
|
2021-02-01 18:59:34 +01:00
|
|
|
config->irq_config_func(dev);
|
2018-11-14 03:04:24 +01:00
|
|
|
|
|
|
|
/* Fill the tx fifo, so Zephyr console & shell subsystems get "primed"
|
|
|
|
* with first tx fifo empty interrupt when they first call
|
|
|
|
* uart_irq_tx_enable().
|
|
|
|
*/
|
2022-01-25 19:19:43 +01:00
|
|
|
MAP_UARTCharPutNonBlocking(config->base, PRIME_CHAR);
|
2016-11-01 01:46:32 +01:00
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int uart_cc32xx_poll_in(const struct device *dev, unsigned char *c)
|
2016-11-01 01:46:32 +01:00
|
|
|
{
|
2022-01-25 19:19:43 +01:00
|
|
|
const struct uart_cc32xx_dev_config *config = dev->config;
|
2016-11-01 01:46:32 +01:00
|
|
|
|
2022-01-25 19:19:43 +01:00
|
|
|
if (MAP_UARTCharsAvail(config->base)) {
|
|
|
|
*c = MAP_UARTCharGetNonBlocking(config->base);
|
2016-11-01 01:46:32 +01:00
|
|
|
} else {
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static void uart_cc32xx_poll_out(const struct device *dev, unsigned char c)
|
2016-11-01 01:46:32 +01:00
|
|
|
{
|
2022-01-25 19:19:43 +01:00
|
|
|
const struct uart_cc32xx_dev_config *config = dev->config;
|
2016-11-01 01:46:32 +01:00
|
|
|
|
2022-01-25 19:19:43 +01:00
|
|
|
MAP_UARTCharPut(config->base, c);
|
2016-11-01 01:46:32 +01:00
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int uart_cc32xx_err_check(const struct device *dev)
|
2016-11-01 01:46:32 +01:00
|
|
|
{
|
2022-01-25 19:19:43 +01:00
|
|
|
const struct uart_cc32xx_dev_config *config = dev->config;
|
2016-11-01 01:46:32 +01:00
|
|
|
unsigned long cc32xx_errs = 0L;
|
2018-11-29 20:12:22 +01:00
|
|
|
unsigned int z_err = 0U;
|
2016-11-01 01:46:32 +01:00
|
|
|
|
2022-01-25 19:19:43 +01:00
|
|
|
cc32xx_errs = MAP_UARTRxErrorGet(config->base);
|
2016-11-01 01:46:32 +01:00
|
|
|
|
2017-08-15 03:26:39 +02:00
|
|
|
/* Map cc32xx SDK uart.h defines to zephyr uart.h defines */
|
2016-11-01 01:46:32 +01:00
|
|
|
z_err = ((cc32xx_errs & UART_RXERROR_OVERRUN) ?
|
|
|
|
UART_ERROR_OVERRUN : 0) |
|
2019-11-02 16:19:17 +01:00
|
|
|
((cc32xx_errs & UART_RXERROR_BREAK) ? UART_BREAK : 0) |
|
2016-11-01 01:46:32 +01:00
|
|
|
((cc32xx_errs & UART_RXERROR_PARITY) ? UART_ERROR_PARITY : 0) |
|
|
|
|
((cc32xx_errs & UART_RXERROR_FRAMING) ? UART_ERROR_FRAMING : 0);
|
|
|
|
|
2022-01-25 19:19:43 +01:00
|
|
|
MAP_UARTRxErrorClear(config->base);
|
2016-11-01 01:46:32 +01:00
|
|
|
|
|
|
|
return (int)z_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int uart_cc32xx_fifo_fill(const struct device *dev,
|
|
|
|
const uint8_t *tx_data,
|
2016-11-01 01:46:32 +01:00
|
|
|
int size)
|
|
|
|
{
|
2022-01-25 19:19:43 +01:00
|
|
|
const struct uart_cc32xx_dev_config *config = dev->config;
|
2018-11-29 20:12:22 +01:00
|
|
|
unsigned int num_tx = 0U;
|
2016-11-01 01:46:32 +01:00
|
|
|
|
|
|
|
while ((size - num_tx) > 0) {
|
|
|
|
/* Send a character */
|
2022-01-25 19:19:43 +01:00
|
|
|
if (MAP_UARTCharPutNonBlocking(config->base, tx_data[num_tx])) {
|
2016-11-01 01:46:32 +01:00
|
|
|
num_tx++;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (int)num_tx;
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int uart_cc32xx_fifo_read(const struct device *dev, uint8_t *rx_data,
|
2016-11-01 01:46:32 +01:00
|
|
|
const int size)
|
|
|
|
{
|
2022-01-25 19:19:43 +01:00
|
|
|
const struct uart_cc32xx_dev_config *config = dev->config;
|
2018-11-29 20:12:22 +01:00
|
|
|
unsigned int num_rx = 0U;
|
2016-11-01 01:46:32 +01:00
|
|
|
|
|
|
|
while (((size - num_rx) > 0) &&
|
2022-01-25 19:19:43 +01:00
|
|
|
MAP_UARTCharsAvail(config->base)) {
|
2016-11-01 01:46:32 +01:00
|
|
|
|
|
|
|
/* Receive a character */
|
|
|
|
rx_data[num_rx++] =
|
2022-01-25 19:19:43 +01:00
|
|
|
MAP_UARTCharGetNonBlocking(config->base);
|
2016-11-01 01:46:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return num_rx;
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static void uart_cc32xx_irq_tx_enable(const struct device *dev)
|
2016-11-01 01:46:32 +01:00
|
|
|
{
|
2022-01-25 19:19:43 +01:00
|
|
|
const struct uart_cc32xx_dev_config *config = dev->config;
|
2016-11-01 01:46:32 +01:00
|
|
|
|
2022-01-25 19:19:43 +01:00
|
|
|
MAP_UARTIntEnable(config->base, UART_INT_TX);
|
2016-11-01 01:46:32 +01:00
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static void uart_cc32xx_irq_tx_disable(const struct device *dev)
|
2016-11-01 01:46:32 +01:00
|
|
|
{
|
2022-01-25 19:19:43 +01:00
|
|
|
const struct uart_cc32xx_dev_config *config = dev->config;
|
2016-11-01 01:46:32 +01:00
|
|
|
|
2022-01-25 19:19:43 +01:00
|
|
|
MAP_UARTIntDisable(config->base, UART_INT_TX);
|
2016-11-01 01:46:32 +01:00
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int uart_cc32xx_irq_tx_ready(const struct device *dev)
|
2016-11-01 01:46:32 +01:00
|
|
|
{
|
2022-01-25 19:19:43 +01:00
|
|
|
const struct uart_cc32xx_dev_config *config = dev->config;
|
2016-11-01 01:46:32 +01:00
|
|
|
unsigned int int_status;
|
|
|
|
|
2022-01-25 19:19:43 +01:00
|
|
|
int_status = MAP_UARTIntStatus(config->base, 1);
|
2016-11-01 01:46:32 +01:00
|
|
|
|
|
|
|
return (int_status & UART_INT_TX);
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static void uart_cc32xx_irq_rx_enable(const struct device *dev)
|
2016-11-01 01:46:32 +01:00
|
|
|
{
|
2022-01-25 19:19:43 +01:00
|
|
|
const struct uart_cc32xx_dev_config *config = dev->config;
|
2016-11-01 01:46:32 +01:00
|
|
|
|
|
|
|
/* FIFOs are left disabled from reset, so UART_INT_RT flag not used. */
|
2022-01-25 19:19:43 +01:00
|
|
|
MAP_UARTIntEnable(config->base, UART_INT_RX);
|
2016-11-01 01:46:32 +01:00
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static void uart_cc32xx_irq_rx_disable(const struct device *dev)
|
2016-11-01 01:46:32 +01:00
|
|
|
{
|
2022-01-25 19:19:43 +01:00
|
|
|
const struct uart_cc32xx_dev_config *config = dev->config;
|
2016-11-01 01:46:32 +01:00
|
|
|
|
2022-01-25 19:19:43 +01:00
|
|
|
MAP_UARTIntDisable(config->base, UART_INT_RX);
|
2016-11-01 01:46:32 +01:00
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int uart_cc32xx_irq_tx_complete(const struct device *dev)
|
2016-11-01 01:46:32 +01:00
|
|
|
{
|
2022-01-25 19:19:43 +01:00
|
|
|
const struct uart_cc32xx_dev_config *config = dev->config;
|
2016-11-01 01:46:32 +01:00
|
|
|
|
2022-01-25 19:19:43 +01:00
|
|
|
return (!MAP_UARTBusy(config->base));
|
2016-11-01 01:46:32 +01:00
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int uart_cc32xx_irq_rx_ready(const struct device *dev)
|
2016-11-01 01:46:32 +01:00
|
|
|
{
|
2022-01-25 19:19:43 +01:00
|
|
|
const struct uart_cc32xx_dev_config *config = dev->config;
|
2016-11-01 01:46:32 +01:00
|
|
|
unsigned int int_status;
|
|
|
|
|
2022-01-25 19:19:43 +01:00
|
|
|
int_status = MAP_UARTIntStatus(config->base, 1);
|
2016-11-01 01:46:32 +01:00
|
|
|
|
|
|
|
return (int_status & UART_INT_RX);
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static void uart_cc32xx_irq_err_enable(const struct device *dev)
|
2016-11-01 01:46:32 +01:00
|
|
|
{
|
|
|
|
/* Not yet used in zephyr */
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static void uart_cc32xx_irq_err_disable(const struct device *dev)
|
2016-11-01 01:46:32 +01:00
|
|
|
{
|
|
|
|
/* Not yet used in zephyr */
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int uart_cc32xx_irq_is_pending(const struct device *dev)
|
2016-11-01 01:46:32 +01:00
|
|
|
{
|
2022-01-25 19:19:43 +01:00
|
|
|
const struct uart_cc32xx_dev_config *config = dev->config;
|
2016-11-01 01:46:32 +01:00
|
|
|
unsigned int int_status;
|
|
|
|
|
2022-01-25 19:19:43 +01:00
|
|
|
int_status = MAP_UARTIntStatus(config->base, 1);
|
2016-11-01 01:46:32 +01:00
|
|
|
|
|
|
|
return (int_status & (UART_INT_TX | UART_INT_RX));
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int uart_cc32xx_irq_update(const struct device *dev)
|
2016-11-01 01:46:32 +01:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static void uart_cc32xx_irq_callback_set(const struct device *dev,
|
2018-07-16 20:12:26 +02:00
|
|
|
uart_irq_callback_user_data_t cb,
|
|
|
|
void *cb_data)
|
2016-11-01 01:46:32 +01:00
|
|
|
{
|
2022-01-18 16:58:32 +01:00
|
|
|
struct uart_cc32xx_dev_data_t * const dev_data = dev->data;
|
2016-11-01 01:46:32 +01:00
|
|
|
|
|
|
|
dev_data->cb = cb;
|
2018-07-16 20:12:26 +02:00
|
|
|
dev_data->cb_data = cb_data;
|
2016-11-01 01:46:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Interrupt service routine.
|
|
|
|
*
|
|
|
|
* This simply calls the callback function, if one exists.
|
|
|
|
*
|
|
|
|
* Note: CC32XX UART Tx interrupts when ready to send; Rx interrupts when char
|
|
|
|
* received.
|
|
|
|
*
|
|
|
|
* @param arg Argument to ISR.
|
|
|
|
*/
|
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 uart_cc32xx_isr(const struct device *dev)
|
2016-11-01 01:46:32 +01:00
|
|
|
{
|
2022-01-25 19:19:43 +01:00
|
|
|
const struct uart_cc32xx_dev_config *config = dev->config;
|
2022-01-18 16:58:32 +01:00
|
|
|
struct uart_cc32xx_dev_data_t * const dev_data = dev->data;
|
2016-11-01 01:46:32 +01:00
|
|
|
|
2022-01-25 19:19:43 +01:00
|
|
|
unsigned long intStatus = MAP_UARTIntStatus(config->base, 1);
|
2016-11-01 01:46:32 +01:00
|
|
|
|
|
|
|
if (dev_data->cb) {
|
2020-06-24 15:47:15 +02:00
|
|
|
dev_data->cb(dev, dev_data->cb_data);
|
2016-11-01 01:46:32 +01:00
|
|
|
}
|
|
|
|
/*
|
2018-11-14 03:04:24 +01:00
|
|
|
* RX/TX interrupt should have been implicitly cleared by Zephyr UART
|
|
|
|
* clients calling uart_fifo_read() or uart_fifo_write().
|
|
|
|
* Still, clear any error interrupts here, as they're not yet handled.
|
2016-11-01 01:46:32 +01:00
|
|
|
*/
|
2022-01-25 19:19:43 +01:00
|
|
|
MAP_UARTIntClear(config->base,
|
2018-11-14 03:04:24 +01:00
|
|
|
intStatus & ~(UART_INT_RX | UART_INT_TX));
|
2016-11-01 01:46:32 +01:00
|
|
|
}
|
|
|
|
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */
|
|
|
|
|
|
|
|
static const struct uart_driver_api uart_cc32xx_driver_api = {
|
|
|
|
.poll_in = uart_cc32xx_poll_in,
|
|
|
|
.poll_out = uart_cc32xx_poll_out,
|
|
|
|
.err_check = uart_cc32xx_err_check,
|
|
|
|
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
|
|
|
.fifo_fill = uart_cc32xx_fifo_fill,
|
|
|
|
.fifo_read = uart_cc32xx_fifo_read,
|
|
|
|
.irq_tx_enable = uart_cc32xx_irq_tx_enable,
|
|
|
|
.irq_tx_disable = uart_cc32xx_irq_tx_disable,
|
|
|
|
.irq_tx_ready = uart_cc32xx_irq_tx_ready,
|
|
|
|
.irq_rx_enable = uart_cc32xx_irq_rx_enable,
|
|
|
|
.irq_rx_disable = uart_cc32xx_irq_rx_disable,
|
2017-05-11 16:57:29 +02:00
|
|
|
.irq_tx_complete = uart_cc32xx_irq_tx_complete,
|
2016-11-01 01:46:32 +01:00
|
|
|
.irq_rx_ready = uart_cc32xx_irq_rx_ready,
|
|
|
|
.irq_err_enable = uart_cc32xx_irq_err_enable,
|
|
|
|
.irq_err_disable = uart_cc32xx_irq_err_disable,
|
|
|
|
.irq_is_pending = uart_cc32xx_irq_is_pending,
|
|
|
|
.irq_update = uart_cc32xx_irq_update,
|
|
|
|
.irq_callback_set = uart_cc32xx_irq_callback_set,
|
|
|
|
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */
|
|
|
|
};
|
|
|
|
|
2021-02-01 18:59:34 +01:00
|
|
|
#define UART_32XX_DEVICE(idx) \
|
2023-06-12 13:58:36 +02:00
|
|
|
PINCTRL_DT_INST_DEFINE(idx); \
|
2021-02-01 18:59:34 +01:00
|
|
|
IF_ENABLED(CONFIG_UART_INTERRUPT_DRIVEN, \
|
|
|
|
(static void uart_cc32xx_cfg_func_##idx(const struct device *dev) \
|
|
|
|
{ \
|
|
|
|
IF_ENABLED(CONFIG_UART_INTERRUPT_DRIVEN, ( \
|
|
|
|
IRQ_CONNECT(DT_INST_IRQN(idx), \
|
|
|
|
DT_INST_IRQ(idx, priority), \
|
|
|
|
uart_cc32xx_isr, DEVICE_DT_INST_GET(idx), \
|
|
|
|
0); \
|
|
|
|
irq_enable(DT_INST_IRQN(idx))) \
|
|
|
|
); \
|
|
|
|
})); \
|
2022-01-25 19:19:43 +01:00
|
|
|
static const struct uart_cc32xx_dev_config uart_cc32xx_dev_cfg_##idx = { \
|
|
|
|
.base = DT_INST_REG_ADDR(idx), \
|
2021-02-01 18:59:34 +01:00
|
|
|
.sys_clk_freq = DT_INST_PROP_BY_PHANDLE(idx, clocks, clock_frequency),\
|
2023-06-12 13:58:36 +02:00
|
|
|
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(idx), \
|
2021-02-01 18:59:34 +01:00
|
|
|
IF_ENABLED(CONFIG_UART_INTERRUPT_DRIVEN, \
|
|
|
|
(.irq_config_func = uart_cc32xx_cfg_func_##idx,)) \
|
|
|
|
}; \
|
|
|
|
static struct uart_cc32xx_dev_data_t uart_cc32xx_dev_data_##idx = { \
|
|
|
|
.prcm = PRCM_UARTA##idx, \
|
|
|
|
.baud_rate = DT_INST_PROP(idx, current_speed), \
|
|
|
|
IF_ENABLED(CONFIG_UART_INTERRUPT_DRIVEN, (.cb = NULL,)) \
|
|
|
|
}; \
|
|
|
|
DEVICE_DT_INST_DEFINE(idx, uart_cc32xx_init, \
|
2021-04-28 12:01:21 +02:00
|
|
|
NULL, &uart_cc32xx_dev_data_##idx, \
|
2021-02-01 18:59:34 +01:00
|
|
|
&uart_cc32xx_dev_cfg_##idx, \
|
2021-10-14 16:38:10 +02:00
|
|
|
PRE_KERNEL_1, CONFIG_SERIAL_INIT_PRIORITY, \
|
2021-02-01 18:59:34 +01:00
|
|
|
(void *)&uart_cc32xx_driver_api); \
|
|
|
|
|
|
|
|
DT_INST_FOREACH_STATUS_OKAY(UART_32XX_DEVICE);
|