2015-04-11 01:44:37 +02:00
|
|
|
/* stellarisUartDrv.c - Stellaris UART driver */
|
|
|
|
|
2020-03-24 22:18:30 +01:00
|
|
|
#define DT_DRV_COMPAT ti_stellaris_uart
|
|
|
|
|
2015-04-11 01:44:37 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2013-2015 Wind River Systems, Inc.
|
|
|
|
*
|
2017-01-19 02:01:01 +01:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2015-04-11 01:44:37 +02:00
|
|
|
*/
|
|
|
|
|
2015-08-21 01:08:06 +02:00
|
|
|
/**
|
|
|
|
* @brief Driver for Stellaris UART
|
|
|
|
*
|
|
|
|
* Driver for Stellaris UART found namely on TI LM3S6965 board. It is similar to
|
|
|
|
* an 16550 in functionality, but is not register-compatible.
|
2017-06-15 14:06:05 +02:00
|
|
|
* It is also register-compatible with the UART found on TI CC2650 SoC,
|
|
|
|
* so it can be used for boards using it, like the TI SensorTag.
|
2015-08-21 01:08:06 +02:00
|
|
|
*
|
|
|
|
* There is only support for poll-mode, so it can only be used with the printk
|
|
|
|
* and STDOUT_CONSOLE APIs.
|
2015-07-01 23:22:39 +02:00
|
|
|
*/
|
2015-04-11 01:44:37 +02:00
|
|
|
|
2016-12-04 21:59:37 +01:00
|
|
|
#include <kernel.h>
|
2015-05-28 19:56:47 +02:00
|
|
|
#include <arch/cpu.h>
|
2019-06-26 16:33:39 +02:00
|
|
|
#include <sys/__assert.h>
|
2018-10-31 18:44:45 +01:00
|
|
|
#include <soc.h>
|
2015-12-01 17:42:19 +01:00
|
|
|
#include <init.h>
|
2019-06-25 21:54:01 +02:00
|
|
|
#include <drivers/uart.h>
|
2017-06-17 17:30:47 +02:00
|
|
|
#include <linker/sections.h>
|
2015-04-11 01:44:37 +02:00
|
|
|
|
|
|
|
/* definitions */
|
|
|
|
|
|
|
|
/* Stellaris UART module */
|
2015-08-21 01:03:44 +02:00
|
|
|
struct _uart {
|
2020-05-27 18:26:57 +02:00
|
|
|
uint32_t dr;
|
2015-04-11 01:44:37 +02:00
|
|
|
union {
|
2020-05-27 18:26:57 +02:00
|
|
|
uint32_t _sr;
|
|
|
|
uint32_t _cr;
|
2015-04-11 01:44:37 +02:00
|
|
|
} u1;
|
2020-05-27 18:26:57 +02:00
|
|
|
uint8_t _res1[0x010];
|
|
|
|
uint32_t fr;
|
|
|
|
uint8_t _res2[0x04];
|
|
|
|
uint32_t ilpr;
|
|
|
|
uint32_t ibrd;
|
|
|
|
uint32_t fbrd;
|
|
|
|
uint32_t lcrh;
|
|
|
|
uint32_t ctl;
|
|
|
|
uint32_t ifls;
|
|
|
|
uint32_t im;
|
|
|
|
uint32_t ris;
|
|
|
|
uint32_t mis;
|
|
|
|
uint32_t icr;
|
|
|
|
uint8_t _res3[0xf8c];
|
|
|
|
|
|
|
|
uint32_t peripd_id4;
|
|
|
|
uint32_t peripd_id5;
|
|
|
|
uint32_t peripd_id6;
|
|
|
|
uint32_t peripd_id7;
|
|
|
|
uint32_t peripd_id0;
|
|
|
|
uint32_t peripd_id1;
|
|
|
|
uint32_t peripd_id2;
|
|
|
|
uint32_t peripd_id3;
|
|
|
|
|
|
|
|
uint32_t p_cell_id0;
|
|
|
|
uint32_t p_cell_id1;
|
|
|
|
uint32_t p_cell_id2;
|
|
|
|
uint32_t p_cell_id3;
|
2015-04-11 01:44:37 +02:00
|
|
|
};
|
|
|
|
|
2016-01-06 18:17:03 +01:00
|
|
|
/* Device data structure */
|
|
|
|
struct uart_stellaris_dev_data_t {
|
2020-05-27 18:26:57 +02:00
|
|
|
uint32_t baud_rate; /* Baud rate */
|
2016-03-03 19:14:50 +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-03-03 19:14:50 +01:00
|
|
|
#endif
|
2016-01-06 18:17:03 +01:00
|
|
|
};
|
|
|
|
|
2015-08-05 21:13:36 +02:00
|
|
|
/* convenience defines */
|
|
|
|
|
|
|
|
#define DEV_CFG(dev) \
|
2020-05-28 20:44:16 +02:00
|
|
|
((const struct uart_device_config * const)(dev)->config)
|
2016-01-06 18:17:03 +01:00
|
|
|
#define DEV_DATA(dev) \
|
2020-05-28 21:23:02 +02:00
|
|
|
((struct uart_stellaris_dev_data_t * const)(dev)->data)
|
2015-08-05 21:13:36 +02:00
|
|
|
#define UART_STRUCT(dev) \
|
2015-08-21 01:03:44 +02:00
|
|
|
((volatile struct _uart *)(DEV_CFG(dev))->base)
|
2015-08-05 21:13:36 +02:00
|
|
|
|
2015-04-11 01:44:37 +02:00
|
|
|
/* registers */
|
2020-05-27 18:26:57 +02:00
|
|
|
#define UARTDR(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0x000)))
|
|
|
|
#define UARTSR(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0x004)))
|
|
|
|
#define UARTCR(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0x004)))
|
|
|
|
#define UARTFR(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0x018)))
|
|
|
|
#define UARTILPR(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0x020)))
|
|
|
|
#define UARTIBRD(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0x024)))
|
|
|
|
#define UARTFBRD(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0x028)))
|
|
|
|
#define UARTLCRH(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0x02C)))
|
|
|
|
#define UARTCTL(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0x030)))
|
|
|
|
#define UARTIFLS(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0x034)))
|
|
|
|
#define UARTIM(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0x038)))
|
|
|
|
#define UARTRIS(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0x03C)))
|
|
|
|
#define UARTMIS(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0x040)))
|
|
|
|
#define UARTICR(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0x044)))
|
2015-04-11 01:44:37 +02:00
|
|
|
|
|
|
|
/* ID registers: UARTPID = UARTPeriphID, UARTPCID = UARTPCellId */
|
2020-05-27 18:26:57 +02:00
|
|
|
#define UARTPID4(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0xFD0)))
|
|
|
|
#define UARTPID5(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0xFD4)))
|
|
|
|
#define UARTPID6(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0xFD8)))
|
|
|
|
#define UARTPID7(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0xFDC)))
|
|
|
|
#define UARTPID0(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0xFE0)))
|
|
|
|
#define UARTPID1(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0xFE4)))
|
|
|
|
#define UARTPID2(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0xFE8)))
|
|
|
|
#define UARTPID3(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0xFEC)))
|
|
|
|
#define UARTPCID0(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0xFF0)))
|
|
|
|
#define UARTPCID1(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0xFF4)))
|
|
|
|
#define UARTPCID2(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0xFF8)))
|
|
|
|
#define UARTPCID3(dev) (*((volatile uint32_t *)(DEV_CFG(dev)->base + 0xFFC)))
|
2015-04-11 01:44:37 +02:00
|
|
|
|
|
|
|
/* muxed UART registers */
|
|
|
|
#define sr u1._sr /* Read: receive status */
|
|
|
|
#define cr u1._cr /* Write: receive error clear */
|
|
|
|
|
|
|
|
/* bits */
|
|
|
|
#define UARTFR_BUSY 0x00000008
|
|
|
|
#define UARTFR_RXFE 0x00000010
|
|
|
|
#define UARTFR_TXFF 0x00000020
|
|
|
|
#define UARTFR_RXFF 0x00000040
|
|
|
|
#define UARTFR_TXFE 0x00000080
|
|
|
|
|
|
|
|
#define UARTLCRH_FEN 0x00000010
|
|
|
|
#define UARTLCRH_WLEN 0x00000060
|
|
|
|
|
|
|
|
#define UARTCTL_UARTEN 0x00000001
|
|
|
|
#define UARTCTL_LBE 0x00000800
|
|
|
|
#define UARTCTL_TXEN 0x00000100
|
|
|
|
#define UARTCTL_RXEN 0x00000200
|
|
|
|
|
|
|
|
#define UARTTIM_RXIM 0x00000010
|
|
|
|
#define UARTTIM_TXIM 0x00000020
|
|
|
|
#define UARTTIM_RTIM 0x00000040
|
|
|
|
#define UARTTIM_FEIM 0x00000080
|
|
|
|
#define UARTTIM_PEIM 0x00000100
|
|
|
|
#define UARTTIM_BEIM 0x00000200
|
|
|
|
#define UARTTIM_OEIM 0x00000400
|
|
|
|
|
|
|
|
#define UARTMIS_RXMIS 0x00000010
|
|
|
|
#define UARTMIS_TXMIS 0x00000020
|
|
|
|
|
2016-10-24 09:38:39 +02:00
|
|
|
static const struct uart_driver_api uart_stellaris_driver_api;
|
2015-08-13 18:51:10 +02:00
|
|
|
|
2015-07-01 23:22:39 +02:00
|
|
|
/**
|
2015-07-01 23:51:40 +02:00
|
|
|
* @brief Set the baud rate
|
2015-07-01 23:22:39 +02:00
|
|
|
*
|
|
|
|
* This routine set the given baud rate for the UART.
|
|
|
|
*
|
2016-01-26 21:32:06 +01:00
|
|
|
* @param dev UART device struct
|
2015-08-05 21:13:36 +02:00
|
|
|
* @param baudrate Baud rate
|
2015-08-21 01:03:44 +02:00
|
|
|
* @param sys_clk_freq_hz System clock frequency in Hz
|
2015-08-05 21:13:36 +02:00
|
|
|
*
|
2015-07-01 23:29:04 +02:00
|
|
|
* @return N/A
|
2015-07-01 23:22:39 +02:00
|
|
|
*/
|
2020-04-30 20:33:38 +02:00
|
|
|
static void baudrate_set(const struct device *dev,
|
2020-05-27 18:26:57 +02:00
|
|
|
uint32_t baudrate, uint32_t sys_clk_freq_hz)
|
2015-04-11 01:44:37 +02:00
|
|
|
{
|
2015-08-21 01:03:44 +02:00
|
|
|
volatile struct _uart *uart = UART_STRUCT(dev);
|
2020-05-27 18:26:57 +02:00
|
|
|
uint32_t brdi, brdf, div, rem;
|
2015-08-05 21:13:36 +02:00
|
|
|
|
2015-04-11 01:44:37 +02:00
|
|
|
/* upon reset, the system clock uses the intenal OSC @ 12MHz */
|
|
|
|
|
2019-03-28 21:57:54 +01:00
|
|
|
div = (baudrate * 16U);
|
2015-08-21 01:03:44 +02:00
|
|
|
rem = sys_clk_freq_hz % div;
|
2015-04-11 01:44:37 +02:00
|
|
|
|
2015-10-20 18:42:33 +02:00
|
|
|
/*
|
|
|
|
* floating part of baud rate (LM3S6965 p.433), equivalent to
|
|
|
|
* [float part of (SYSCLK / div)] * 64 + 0.5
|
|
|
|
*/
|
2019-03-27 02:57:45 +01:00
|
|
|
brdf = ((((rem * 64U) << 1) / div) + 1) >> 1;
|
2015-04-11 01:44:37 +02:00
|
|
|
|
|
|
|
/* integer part of baud rate (LM3S6965 p.433) */
|
2015-08-21 01:03:44 +02:00
|
|
|
brdi = sys_clk_freq_hz / div;
|
2015-04-11 01:44:37 +02:00
|
|
|
|
2015-10-20 18:42:33 +02:00
|
|
|
/*
|
|
|
|
* those registers are 32-bit, but the reserved bits should be
|
|
|
|
* preserved
|
|
|
|
*/
|
2020-05-27 18:26:57 +02:00
|
|
|
uart->ibrd = (uint16_t)(brdi & 0xffff); /* 16 bits */
|
|
|
|
uart->fbrd = (uint8_t)(brdf & 0x3f); /* 6 bits */
|
2015-04-11 01:44:37 +02:00
|
|
|
}
|
|
|
|
|
2015-07-01 23:22:39 +02:00
|
|
|
/**
|
2015-07-01 23:51:40 +02:00
|
|
|
* @brief Enable the UART
|
2015-07-01 23:22:39 +02:00
|
|
|
*
|
|
|
|
* This routine enables the given UART.
|
|
|
|
*
|
2016-01-26 21:32:06 +01:00
|
|
|
* @param dev UART device struct
|
2015-08-05 21:13:36 +02:00
|
|
|
*
|
2015-07-01 23:29:04 +02:00
|
|
|
* @return N/A
|
2015-07-01 23:22:39 +02:00
|
|
|
*/
|
2020-04-30 20:33:38 +02:00
|
|
|
static inline void enable(const struct device *dev)
|
2015-04-11 01:44:37 +02:00
|
|
|
{
|
2015-08-21 01:03:44 +02:00
|
|
|
volatile struct _uart *uart = UART_STRUCT(dev);
|
2015-04-15 00:15:52 +02:00
|
|
|
|
2015-08-21 01:03:44 +02:00
|
|
|
uart->ctl |= UARTCTL_UARTEN;
|
2015-04-11 01:44:37 +02:00
|
|
|
}
|
|
|
|
|
2015-07-01 23:22:39 +02:00
|
|
|
/**
|
2015-07-01 23:51:40 +02:00
|
|
|
* @brief Disable the UART
|
2015-07-01 23:22:39 +02:00
|
|
|
*
|
|
|
|
* This routine disables the given UART.
|
|
|
|
*
|
2016-01-26 21:32:06 +01:00
|
|
|
* @param dev UART device struct
|
2015-08-05 21:13:36 +02:00
|
|
|
*
|
2015-07-01 23:29:04 +02:00
|
|
|
* @return N/A
|
2015-07-01 23:22:39 +02:00
|
|
|
*/
|
2020-04-30 20:33:38 +02:00
|
|
|
static inline void disable(const struct device *dev)
|
2015-04-11 01:44:37 +02:00
|
|
|
{
|
2015-08-21 01:03:44 +02:00
|
|
|
volatile struct _uart *uart = UART_STRUCT(dev);
|
2015-04-11 01:44:37 +02:00
|
|
|
|
2015-08-21 01:03:44 +02:00
|
|
|
uart->ctl &= ~UARTCTL_UARTEN;
|
2015-04-11 01:44:37 +02:00
|
|
|
|
|
|
|
/* ensure transmissions are complete */
|
2019-06-04 16:52:23 +02:00
|
|
|
while (uart->fr & UARTFR_BUSY) {
|
|
|
|
}
|
2015-04-11 01:44:37 +02:00
|
|
|
|
|
|
|
/* flush the FIFOs by disabling them */
|
2015-08-21 01:03:44 +02:00
|
|
|
uart->lcrh &= ~UARTLCRH_FEN;
|
2015-04-11 01:44:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* no stick parity
|
|
|
|
* 8-bit frame
|
|
|
|
* FIFOs disabled
|
|
|
|
* one stop bit
|
|
|
|
* parity disabled
|
|
|
|
* send break off
|
|
|
|
*/
|
|
|
|
#define LINE_CONTROL_DEFAULTS UARTLCRH_WLEN
|
|
|
|
|
2015-07-01 23:22:39 +02:00
|
|
|
/**
|
2015-07-01 23:51:40 +02:00
|
|
|
* @brief Set the default UART line controls
|
2015-07-01 23:22:39 +02:00
|
|
|
*
|
|
|
|
* This routine sets the given UART's line controls to their default settings.
|
|
|
|
*
|
2016-01-26 21:32:06 +01:00
|
|
|
* @param dev UART device struct
|
2015-08-05 21:13:36 +02:00
|
|
|
*
|
2015-07-01 23:29:04 +02:00
|
|
|
* @return N/A
|
2015-07-01 23:22:39 +02:00
|
|
|
*/
|
2020-04-30 20:33:38 +02:00
|
|
|
static inline void line_control_defaults_set(const struct device *dev)
|
2015-04-11 01:44:37 +02:00
|
|
|
{
|
2015-08-21 01:03:44 +02:00
|
|
|
volatile struct _uart *uart = UART_STRUCT(dev);
|
2015-04-15 00:15:52 +02:00
|
|
|
|
2015-08-21 01:03:44 +02:00
|
|
|
uart->lcrh = LINE_CONTROL_DEFAULTS;
|
2015-04-11 01:44:37 +02:00
|
|
|
}
|
|
|
|
|
2015-07-01 23:22:39 +02:00
|
|
|
/**
|
2015-07-01 23:51:40 +02:00
|
|
|
* @brief Initialize UART channel
|
2015-07-01 23:22:39 +02:00
|
|
|
*
|
|
|
|
* This routine is called to reset the chip in a quiescent state.
|
|
|
|
* It is assumed that this function is called only once per UART.
|
|
|
|
*
|
2016-01-26 21:32:06 +01:00
|
|
|
* @param dev UART device struct
|
2015-08-05 21:13:36 +02:00
|
|
|
*
|
2016-03-09 18:01:20 +01:00
|
|
|
* @return 0
|
2015-07-01 23:22:39 +02:00
|
|
|
*/
|
2020-04-30 20:33:38 +02:00
|
|
|
static int uart_stellaris_init(const struct device *dev)
|
2015-04-11 01:44:37 +02:00
|
|
|
{
|
2015-08-05 21:13:36 +02:00
|
|
|
disable(dev);
|
2016-01-06 18:17:03 +01:00
|
|
|
baudrate_set(dev, DEV_DATA(dev)->baud_rate,
|
|
|
|
DEV_CFG(dev)->sys_clk_freq);
|
2015-08-21 01:03:44 +02:00
|
|
|
line_control_defaults_set(dev);
|
2015-08-05 21:13:36 +02:00
|
|
|
enable(dev);
|
2015-08-13 18:51:10 +02:00
|
|
|
|
2016-03-03 19:14:50 +01:00
|
|
|
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
|
|
|
DEV_CFG(dev)->irq_config_func(dev);
|
|
|
|
#endif
|
|
|
|
|
2016-03-09 18:01:20 +01:00
|
|
|
return 0;
|
2015-04-11 01:44:37 +02:00
|
|
|
}
|
|
|
|
|
2015-07-01 23:22:39 +02:00
|
|
|
/**
|
2015-07-01 23:51:40 +02:00
|
|
|
* @brief Get the UART transmit ready status
|
2015-07-01 23:22:39 +02:00
|
|
|
*
|
|
|
|
* This routine returns the given UART's transmit ready status.
|
|
|
|
*
|
2016-01-26 21:32:06 +01:00
|
|
|
* @param dev UART device struct
|
2015-08-05 21:13:36 +02:00
|
|
|
*
|
2015-07-01 23:29:04 +02:00
|
|
|
* @return 0 if ready to transmit, 1 otherwise
|
2015-07-01 23:22:39 +02:00
|
|
|
*/
|
2020-04-30 20:33:38 +02:00
|
|
|
static int poll_tx_ready(const struct device *dev)
|
2015-04-11 01:44:37 +02:00
|
|
|
{
|
2015-08-21 01:03:44 +02:00
|
|
|
volatile struct _uart *uart = UART_STRUCT(dev);
|
2015-04-15 00:15:52 +02:00
|
|
|
|
2015-08-21 01:03:44 +02:00
|
|
|
return (uart->fr & UARTFR_TXFE);
|
2015-04-11 01:44:37 +02:00
|
|
|
}
|
|
|
|
|
2015-07-01 23:22:39 +02:00
|
|
|
/**
|
2015-07-01 23:51:40 +02:00
|
|
|
* @brief Poll the device for input.
|
2015-07-01 23:22:39 +02:00
|
|
|
*
|
2016-01-26 21:32:06 +01:00
|
|
|
* @param dev UART device struct
|
2015-08-21 01:03:44 +02:00
|
|
|
* @param c Pointer to character
|
2015-08-05 21:13:36 +02:00
|
|
|
*
|
2015-07-01 23:29:04 +02:00
|
|
|
* @return 0 if a character arrived, -1 if the input buffer if empty.
|
2015-07-01 23:22:39 +02:00
|
|
|
*/
|
2015-04-11 01:44:37 +02:00
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int uart_stellaris_poll_in(const struct device *dev, unsigned char *c)
|
2015-04-11 01:44:37 +02:00
|
|
|
{
|
2015-08-21 01:03:44 +02:00
|
|
|
volatile struct _uart *uart = UART_STRUCT(dev);
|
2015-04-11 01:44:37 +02:00
|
|
|
|
2019-06-04 16:52:23 +02:00
|
|
|
if (uart->fr & UARTFR_RXFE) {
|
2015-04-11 01:44:37 +02:00
|
|
|
return (-1);
|
2019-06-04 16:52:23 +02:00
|
|
|
}
|
2015-04-11 01:44:37 +02:00
|
|
|
|
|
|
|
/* got a character */
|
2015-08-21 01:03:44 +02:00
|
|
|
*c = (unsigned char)uart->dr;
|
2015-04-11 01:44:37 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-07-01 23:22:39 +02:00
|
|
|
/**
|
2015-07-01 23:51:40 +02:00
|
|
|
* @brief Output a character in polled mode.
|
2015-07-01 23:22:39 +02:00
|
|
|
*
|
|
|
|
* Checks if the transmitter is empty. If empty, a character is written to
|
|
|
|
* the data register.
|
|
|
|
*
|
2016-01-26 21:32:06 +01:00
|
|
|
* @param dev UART device struct
|
2015-08-05 21:13:36 +02:00
|
|
|
* @param c Character to send
|
2015-07-01 23:22:39 +02:00
|
|
|
*/
|
2020-04-30 20:33:38 +02:00
|
|
|
static void uart_stellaris_poll_out(const struct device *dev,
|
2015-08-13 18:51:10 +02:00
|
|
|
unsigned char c)
|
2015-04-11 01:44:37 +02:00
|
|
|
{
|
2015-08-21 01:03:44 +02:00
|
|
|
volatile struct _uart *uart = UART_STRUCT(dev);
|
2015-04-11 01:44:37 +02:00
|
|
|
|
2019-06-04 16:52:23 +02:00
|
|
|
while (!poll_tx_ready(dev)) {
|
|
|
|
}
|
2015-04-11 01:44:37 +02:00
|
|
|
|
|
|
|
/* send a character */
|
2020-05-27 18:26:57 +02:00
|
|
|
uart->dr = (uint32_t)c;
|
2015-04-11 01:44:37 +02:00
|
|
|
}
|
|
|
|
|
2015-04-21 19:09:15 +02:00
|
|
|
#if CONFIG_UART_INTERRUPT_DRIVEN
|
2015-04-11 01:44:37 +02:00
|
|
|
|
2015-07-01 23:22:39 +02:00
|
|
|
/**
|
2015-07-01 23:51:40 +02:00
|
|
|
* @brief Fill FIFO with data
|
2015-07-01 23:22:39 +02:00
|
|
|
*
|
2016-01-26 21:32:06 +01:00
|
|
|
* @param dev UART device struct
|
2015-08-21 01:03:44 +02:00
|
|
|
* @param tx_data Data to transmit
|
2015-08-05 21:13:36 +02:00
|
|
|
* @param len Number of bytes to send
|
|
|
|
*
|
2015-08-21 01:08:06 +02:00
|
|
|
* @return Number of bytes sent
|
2015-07-01 23:22:39 +02:00
|
|
|
*/
|
2020-04-30 20:33:38 +02:00
|
|
|
static int uart_stellaris_fifo_fill(const struct device *dev,
|
|
|
|
const uint8_t *tx_data,
|
2015-08-21 01:03:44 +02:00
|
|
|
int len)
|
2015-04-11 01:44:37 +02:00
|
|
|
{
|
2015-08-21 01:03:44 +02:00
|
|
|
volatile struct _uart *uart = UART_STRUCT(dev);
|
2020-05-27 18:26:57 +02:00
|
|
|
uint8_t num_tx = 0U;
|
2015-04-11 01:44:37 +02:00
|
|
|
|
2019-03-27 02:57:45 +01:00
|
|
|
while ((len - num_tx > 0) && ((uart->fr & UARTFR_TXFF) == 0U)) {
|
2020-05-27 18:26:57 +02:00
|
|
|
uart->dr = (uint32_t)tx_data[num_tx++];
|
2015-04-11 01:44:37 +02:00
|
|
|
}
|
|
|
|
|
2015-08-21 01:03:44 +02:00
|
|
|
return (int)num_tx;
|
2015-04-11 01:44:37 +02:00
|
|
|
}
|
|
|
|
|
2015-07-01 23:22:39 +02:00
|
|
|
/**
|
2015-07-01 23:51:40 +02:00
|
|
|
* @brief Read data from FIFO
|
2015-07-01 23:22:39 +02:00
|
|
|
*
|
2016-01-26 21:32:06 +01:00
|
|
|
* @param dev UART device struct
|
2015-08-21 01:03:44 +02:00
|
|
|
* @param rx_data Pointer to data container
|
2015-08-05 21:13:36 +02:00
|
|
|
* @param size Container size
|
|
|
|
*
|
2015-08-21 01:08:06 +02:00
|
|
|
* @return Number of bytes read
|
2015-07-01 23:22:39 +02:00
|
|
|
*/
|
2020-04-30 20:33:38 +02:00
|
|
|
static int uart_stellaris_fifo_read(const struct device *dev,
|
|
|
|
uint8_t *rx_data,
|
2015-08-21 01:03:44 +02:00
|
|
|
const int size)
|
2015-04-11 01:44:37 +02:00
|
|
|
{
|
2015-08-21 01:03:44 +02:00
|
|
|
volatile struct _uart *uart = UART_STRUCT(dev);
|
2020-05-27 18:26:57 +02:00
|
|
|
uint8_t num_rx = 0U;
|
2015-04-11 01:44:37 +02:00
|
|
|
|
2019-03-27 02:57:45 +01:00
|
|
|
while ((size - num_rx > 0) && ((uart->fr & UARTFR_RXFE) == 0U)) {
|
2020-05-27 18:26:57 +02:00
|
|
|
rx_data[num_rx++] = (uint8_t)uart->dr;
|
2015-04-11 01:44:37 +02:00
|
|
|
}
|
|
|
|
|
2015-08-21 01:03:44 +02:00
|
|
|
return num_rx;
|
2015-04-11 01:44:37 +02:00
|
|
|
}
|
|
|
|
|
2015-07-01 23:22:39 +02:00
|
|
|
/**
|
2015-07-01 23:51:40 +02:00
|
|
|
* @brief Enable TX interrupt
|
2015-07-01 23:22:39 +02:00
|
|
|
*
|
2016-01-26 21:32:06 +01:00
|
|
|
* @param dev UART device struct
|
2015-08-05 21:13:36 +02:00
|
|
|
*
|
2015-07-01 23:29:04 +02:00
|
|
|
* @return N/A
|
2015-07-01 23:22:39 +02:00
|
|
|
*/
|
2020-04-30 20:33:38 +02:00
|
|
|
static void uart_stellaris_irq_tx_enable(const struct device *dev)
|
2015-04-11 01:44:37 +02:00
|
|
|
{
|
2020-05-27 18:26:57 +02:00
|
|
|
static uint8_t first_time =
|
2018-11-29 20:12:22 +01:00
|
|
|
1U; /* used to allow the first transmission */
|
2020-05-27 18:26:57 +02:00
|
|
|
uint32_t saved_ctl; /* saved UARTCTL (control) register */
|
|
|
|
uint32_t saved_ibrd; /* saved UARTIBRD (integer baud rate) register */
|
|
|
|
uint32_t saved_fbrd; /* saved UARTFBRD (fractional baud rate) register
|
2015-04-11 01:44:37 +02:00
|
|
|
*/
|
2015-08-21 01:03:44 +02:00
|
|
|
volatile struct _uart *uart = UART_STRUCT(dev);
|
2015-04-11 01:44:37 +02:00
|
|
|
|
|
|
|
if (first_time) {
|
|
|
|
/*
|
|
|
|
* The Tx interrupt will not be set when transmission is first
|
|
|
|
* enabled.
|
|
|
|
* A character has to be transmitted before Tx interrupts will
|
|
|
|
* work,
|
|
|
|
* so send one via loopback mode.
|
|
|
|
*/
|
2018-11-29 20:12:22 +01:00
|
|
|
first_time = 0U;
|
2015-04-11 01:44:37 +02:00
|
|
|
|
|
|
|
/* save current control and baud rate settings */
|
2015-08-21 01:03:44 +02:00
|
|
|
saved_ctl = uart->ctl;
|
|
|
|
saved_ibrd = uart->ibrd;
|
|
|
|
saved_fbrd = uart->fbrd;
|
2015-04-11 01:44:37 +02:00
|
|
|
|
|
|
|
/* send a character with default settings via loopback */
|
2015-08-05 21:13:36 +02:00
|
|
|
disable(dev);
|
2018-11-29 20:12:22 +01:00
|
|
|
uart->fbrd = 0U;
|
|
|
|
uart->ibrd = 1U;
|
|
|
|
uart->lcrh = 0U;
|
2015-08-21 01:03:44 +02:00
|
|
|
uart->ctl = (UARTCTL_UARTEN | UARTCTL_TXEN | UARTCTL_LBE);
|
2018-11-29 20:12:22 +01:00
|
|
|
uart->dr = 0U;
|
2015-04-11 01:44:37 +02:00
|
|
|
|
2019-06-04 16:52:23 +02:00
|
|
|
while (uart->fr & UARTFR_BUSY) {
|
|
|
|
}
|
2015-04-11 01:44:37 +02:00
|
|
|
|
|
|
|
/* restore control and baud rate settings */
|
2015-08-05 21:13:36 +02:00
|
|
|
disable(dev);
|
2015-08-21 01:03:44 +02:00
|
|
|
uart->ibrd = saved_ibrd;
|
|
|
|
uart->fbrd = saved_fbrd;
|
|
|
|
line_control_defaults_set(dev);
|
|
|
|
uart->ctl = saved_ctl;
|
2015-04-11 01:44:37 +02:00
|
|
|
}
|
|
|
|
|
2015-08-21 01:03:44 +02:00
|
|
|
uart->im |= UARTTIM_TXIM;
|
2015-04-11 01:44:37 +02:00
|
|
|
}
|
|
|
|
|
2015-07-01 23:22:39 +02:00
|
|
|
/**
|
2015-07-01 23:51:40 +02:00
|
|
|
* @brief Disable TX interrupt in IER
|
2015-07-01 23:22:39 +02:00
|
|
|
*
|
2016-01-26 21:32:06 +01:00
|
|
|
* @param dev UART device struct
|
2015-08-05 21:13:36 +02:00
|
|
|
*
|
2015-07-01 23:29:04 +02:00
|
|
|
* @return N/A
|
2015-07-01 23:22:39 +02:00
|
|
|
*/
|
2020-04-30 20:33:38 +02:00
|
|
|
static void uart_stellaris_irq_tx_disable(const struct device *dev)
|
2015-04-11 01:44:37 +02:00
|
|
|
{
|
2015-08-21 01:03:44 +02:00
|
|
|
volatile struct _uart *uart = UART_STRUCT(dev);
|
2015-04-11 01:44:37 +02:00
|
|
|
|
2015-08-21 01:03:44 +02:00
|
|
|
uart->im &= ~UARTTIM_TXIM;
|
2015-04-11 01:44:37 +02:00
|
|
|
}
|
|
|
|
|
2015-07-01 23:22:39 +02:00
|
|
|
/**
|
2015-07-01 23:51:40 +02:00
|
|
|
* @brief Check if Tx IRQ has been raised
|
2015-07-01 23:22:39 +02:00
|
|
|
*
|
2016-01-26 21:32:06 +01:00
|
|
|
* @param dev UART device struct
|
2015-08-05 21:13:36 +02:00
|
|
|
*
|
2015-07-01 23:29:04 +02:00
|
|
|
* @return 1 if a Tx IRQ is pending, 0 otherwise
|
2015-07-01 23:22:39 +02:00
|
|
|
*/
|
2020-04-30 20:33:38 +02:00
|
|
|
static int uart_stellaris_irq_tx_ready(const struct device *dev)
|
2015-04-11 01:44:37 +02:00
|
|
|
{
|
2015-08-21 01:03:44 +02:00
|
|
|
volatile struct _uart *uart = UART_STRUCT(dev);
|
2015-04-11 01:44:37 +02:00
|
|
|
|
2015-08-21 01:03:44 +02:00
|
|
|
return ((uart->mis & UARTMIS_TXMIS) == UARTMIS_TXMIS);
|
2015-04-11 01:44:37 +02:00
|
|
|
}
|
|
|
|
|
2015-07-01 23:22:39 +02:00
|
|
|
/**
|
2015-07-01 23:51:40 +02:00
|
|
|
* @brief Enable RX interrupt in IER
|
2015-07-01 23:22:39 +02:00
|
|
|
*
|
2016-01-26 21:32:06 +01:00
|
|
|
* @param dev UART device struct
|
2015-08-05 21:13:36 +02:00
|
|
|
*
|
2015-07-01 23:29:04 +02:00
|
|
|
* @return N/A
|
2015-07-01 23:22:39 +02:00
|
|
|
*/
|
2020-04-30 20:33:38 +02:00
|
|
|
static void uart_stellaris_irq_rx_enable(const struct device *dev)
|
2015-04-11 01:44:37 +02:00
|
|
|
{
|
2015-08-21 01:03:44 +02:00
|
|
|
volatile struct _uart *uart = UART_STRUCT(dev);
|
2015-04-11 01:44:37 +02:00
|
|
|
|
2015-08-21 01:03:44 +02:00
|
|
|
uart->im |= UARTTIM_RXIM;
|
2015-04-11 01:44:37 +02:00
|
|
|
}
|
|
|
|
|
2015-07-01 23:22:39 +02:00
|
|
|
/**
|
2015-07-01 23:51:40 +02:00
|
|
|
* @brief Disable RX interrupt in IER
|
2015-07-01 23:22:39 +02:00
|
|
|
*
|
2016-01-26 21:32:06 +01:00
|
|
|
* @param dev UART device struct
|
2015-08-05 21:13:36 +02:00
|
|
|
*
|
2015-07-01 23:29:04 +02:00
|
|
|
* @return N/A
|
2015-07-01 23:22:39 +02:00
|
|
|
*/
|
2020-04-30 20:33:38 +02:00
|
|
|
static void uart_stellaris_irq_rx_disable(const struct device *dev)
|
2015-04-11 01:44:37 +02:00
|
|
|
{
|
2015-08-21 01:03:44 +02:00
|
|
|
volatile struct _uart *uart = UART_STRUCT(dev);
|
2015-04-11 01:44:37 +02:00
|
|
|
|
2015-08-21 01:03:44 +02:00
|
|
|
uart->im &= ~UARTTIM_RXIM;
|
2015-04-11 01:44:37 +02:00
|
|
|
}
|
|
|
|
|
2015-07-01 23:22:39 +02:00
|
|
|
/**
|
2015-07-01 23:51:40 +02:00
|
|
|
* @brief Check if Rx IRQ has been raised
|
2015-07-01 23:22:39 +02:00
|
|
|
*
|
2016-01-26 21:32:06 +01:00
|
|
|
* @param dev UART device struct
|
2015-08-05 21:13:36 +02:00
|
|
|
*
|
2015-07-01 23:29:04 +02:00
|
|
|
* @return 1 if an IRQ is ready, 0 otherwise
|
2015-07-01 23:22:39 +02:00
|
|
|
*/
|
2020-04-30 20:33:38 +02:00
|
|
|
static int uart_stellaris_irq_rx_ready(const struct device *dev)
|
2015-04-11 01:44:37 +02:00
|
|
|
{
|
2015-08-21 01:03:44 +02:00
|
|
|
volatile struct _uart *uart = UART_STRUCT(dev);
|
2015-04-11 01:44:37 +02:00
|
|
|
|
2015-08-21 01:03:44 +02:00
|
|
|
return ((uart->mis & UARTMIS_RXMIS) == UARTMIS_RXMIS);
|
2015-04-11 01:44:37 +02:00
|
|
|
}
|
|
|
|
|
2015-07-01 23:22:39 +02:00
|
|
|
/**
|
2015-07-01 23:51:40 +02:00
|
|
|
* @brief Enable error interrupts
|
2015-07-01 23:22:39 +02:00
|
|
|
*
|
2016-01-26 21:32:06 +01:00
|
|
|
* @param dev UART device struct
|
2015-08-05 21:13:36 +02:00
|
|
|
*
|
2015-07-01 23:29:04 +02:00
|
|
|
* @return N/A
|
2015-07-01 23:22:39 +02:00
|
|
|
*/
|
2020-04-30 20:33:38 +02:00
|
|
|
static void uart_stellaris_irq_err_enable(const struct device *dev)
|
2015-04-11 01:44:37 +02:00
|
|
|
{
|
2015-08-21 01:03:44 +02:00
|
|
|
volatile struct _uart *uart = UART_STRUCT(dev);
|
2015-04-11 01:44:37 +02:00
|
|
|
|
2015-08-21 01:03:44 +02:00
|
|
|
uart->im |= (UARTTIM_RTIM | UARTTIM_FEIM | UARTTIM_PEIM |
|
2015-04-11 01:44:37 +02:00
|
|
|
UARTTIM_BEIM | UARTTIM_OEIM);
|
|
|
|
}
|
|
|
|
|
2015-07-01 23:22:39 +02:00
|
|
|
/**
|
2015-07-01 23:51:40 +02:00
|
|
|
* @brief Disable error interrupts
|
2015-07-01 23:22:39 +02:00
|
|
|
*
|
2016-01-26 21:32:06 +01:00
|
|
|
* @param dev UART device struct
|
2015-08-05 21:13:36 +02:00
|
|
|
*
|
2015-07-01 23:29:04 +02:00
|
|
|
* @return N/A
|
2015-07-01 23:22:39 +02:00
|
|
|
*/
|
2020-04-30 20:33:38 +02:00
|
|
|
static void uart_stellaris_irq_err_disable(const struct device *dev)
|
2015-04-11 01:44:37 +02:00
|
|
|
{
|
2015-08-21 01:03:44 +02:00
|
|
|
volatile struct _uart *uart = UART_STRUCT(dev);
|
2015-04-11 01:44:37 +02:00
|
|
|
|
2015-08-21 01:03:44 +02:00
|
|
|
uart->im &= ~(UARTTIM_RTIM | UARTTIM_FEIM | UARTTIM_PEIM |
|
2015-04-11 01:44:37 +02:00
|
|
|
UARTTIM_BEIM | UARTTIM_OEIM);
|
|
|
|
}
|
|
|
|
|
2015-07-01 23:22:39 +02:00
|
|
|
/**
|
2015-07-01 23:51:40 +02:00
|
|
|
* @brief Check if Tx or Rx IRQ is pending
|
2015-07-01 23:22:39 +02:00
|
|
|
*
|
2016-01-26 21:32:06 +01:00
|
|
|
* @param dev UART device struct
|
2015-08-05 21:13:36 +02:00
|
|
|
*
|
2015-07-01 23:29:04 +02:00
|
|
|
* @return 1 if a Tx or Rx IRQ is pending, 0 otherwise
|
2015-07-01 23:22:39 +02:00
|
|
|
*/
|
2020-04-30 20:33:38 +02:00
|
|
|
static int uart_stellaris_irq_is_pending(const struct device *dev)
|
2015-04-11 01:44:37 +02:00
|
|
|
{
|
2015-08-21 01:03:44 +02:00
|
|
|
volatile struct _uart *uart = UART_STRUCT(dev);
|
2015-04-11 01:44:37 +02:00
|
|
|
|
|
|
|
/* Look only at Tx and Rx data interrupt flags */
|
2015-08-21 01:03:44 +02:00
|
|
|
return ((uart->mis & (UARTMIS_RXMIS | UARTMIS_TXMIS)) ? 1 : 0);
|
2015-04-11 01:44:37 +02:00
|
|
|
}
|
|
|
|
|
2015-07-01 23:22:39 +02:00
|
|
|
/**
|
2015-07-01 23:51:40 +02:00
|
|
|
* @brief Update IRQ status
|
2015-07-01 23:22:39 +02:00
|
|
|
*
|
2016-01-26 21:32:06 +01:00
|
|
|
* @param dev UART device struct
|
2015-08-05 21:13:36 +02:00
|
|
|
*
|
2015-08-21 01:08:06 +02:00
|
|
|
* @return Always 1
|
2015-07-01 23:22:39 +02:00
|
|
|
*/
|
2020-04-30 20:33:38 +02:00
|
|
|
static int uart_stellaris_irq_update(const struct device *dev)
|
2015-04-11 01:44:37 +02:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-03-03 19:14:50 +01:00
|
|
|
/**
|
|
|
|
* @brief Set the callback function pointer for IRQ.
|
|
|
|
*
|
|
|
|
* @param dev UART device struct
|
|
|
|
* @param cb Callback function pointer.
|
|
|
|
*
|
|
|
|
* @return N/A
|
|
|
|
*/
|
2020-04-30 20:33:38 +02:00
|
|
|
static void uart_stellaris_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-03-03 19:14:50 +01:00
|
|
|
{
|
|
|
|
struct uart_stellaris_dev_data_t * const dev_data = DEV_DATA(dev);
|
|
|
|
|
|
|
|
dev_data->cb = cb;
|
2018-07-16 20:12:26 +02:00
|
|
|
dev_data->cb_data = cb_data;
|
2016-03-03 19:14:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Interrupt service routine.
|
|
|
|
*
|
|
|
|
* This simply calls the callback function, if one exists.
|
|
|
|
*
|
|
|
|
* @param arg Argument to ISR.
|
|
|
|
*
|
|
|
|
* @return N/A
|
|
|
|
*/
|
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_stellaris_isr(const struct device *dev)
|
2016-03-03 19:14:50 +01:00
|
|
|
{
|
|
|
|
struct uart_stellaris_dev_data_t * const dev_data = DEV_DATA(dev);
|
|
|
|
|
|
|
|
if (dev_data->cb) {
|
2020-06-24 15:47:15 +02:00
|
|
|
dev_data->cb(dev, dev_data->cb_data);
|
2016-03-03 19:14:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-21 19:09:15 +02:00
|
|
|
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */
|
2015-08-13 18:51:10 +02:00
|
|
|
|
|
|
|
|
2016-10-24 09:38:39 +02:00
|
|
|
static const struct uart_driver_api uart_stellaris_driver_api = {
|
2015-12-01 17:42:19 +01:00
|
|
|
.poll_in = uart_stellaris_poll_in,
|
|
|
|
.poll_out = uart_stellaris_poll_out,
|
2015-08-13 18:51:10 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
|
|
|
|
2015-12-01 17:42:19 +01:00
|
|
|
.fifo_fill = uart_stellaris_fifo_fill,
|
|
|
|
.fifo_read = uart_stellaris_fifo_read,
|
|
|
|
.irq_tx_enable = uart_stellaris_irq_tx_enable,
|
|
|
|
.irq_tx_disable = uart_stellaris_irq_tx_disable,
|
|
|
|
.irq_tx_ready = uart_stellaris_irq_tx_ready,
|
|
|
|
.irq_rx_enable = uart_stellaris_irq_rx_enable,
|
|
|
|
.irq_rx_disable = uart_stellaris_irq_rx_disable,
|
|
|
|
.irq_rx_ready = uart_stellaris_irq_rx_ready,
|
|
|
|
.irq_err_enable = uart_stellaris_irq_err_enable,
|
|
|
|
.irq_err_disable = uart_stellaris_irq_err_disable,
|
|
|
|
.irq_is_pending = uart_stellaris_irq_is_pending,
|
|
|
|
.irq_update = uart_stellaris_irq_update,
|
2016-03-03 19:14:50 +01:00
|
|
|
.irq_callback_set = uart_stellaris_irq_callback_set,
|
2015-12-01 17:42:19 +01:00
|
|
|
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef CONFIG_UART_STELLARIS_PORT_0
|
|
|
|
|
2016-03-03 19:14:50 +01:00
|
|
|
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
2020-04-30 20:33:38 +02:00
|
|
|
static void irq_config_func_0(const struct device *port);
|
2016-03-03 19:14:50 +01:00
|
|
|
#endif
|
|
|
|
|
2016-10-19 23:17:58 +02:00
|
|
|
static const struct uart_device_config uart_stellaris_dev_cfg_0 = {
|
2020-05-27 18:26:57 +02:00
|
|
|
.base = (uint8_t *)DT_INST_REG_ADDR(0),
|
2020-03-24 22:18:30 +01:00
|
|
|
.sys_clk_freq = DT_INST_PROP_BY_PHANDLE(0, clocks, clock_frequency),
|
2016-03-03 19:14:50 +01:00
|
|
|
|
|
|
|
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
|
|
|
.irq_config_func = irq_config_func_0,
|
|
|
|
#endif
|
2016-01-06 18:17:03 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct uart_stellaris_dev_data_t uart_stellaris_dev_data_0 = {
|
2020-03-24 22:18:30 +01:00
|
|
|
.baud_rate = DT_INST_PROP(0, current_speed),
|
2015-12-01 17:42:19 +01:00
|
|
|
};
|
|
|
|
|
2020-12-11 17:12:30 +01:00
|
|
|
DEVICE_DT_INST_DEFINE(0,
|
2017-06-16 17:42:01 +02:00
|
|
|
&uart_stellaris_init,
|
2021-04-28 12:01:21 +02:00
|
|
|
NULL,
|
2016-04-14 18:28:35 +02:00
|
|
|
&uart_stellaris_dev_data_0, &uart_stellaris_dev_cfg_0,
|
2021-10-14 16:38:10 +02:00
|
|
|
PRE_KERNEL_1, CONFIG_SERIAL_INIT_PRIORITY,
|
2016-04-14 18:28:35 +02:00
|
|
|
&uart_stellaris_driver_api);
|
2015-12-01 17:42:19 +01:00
|
|
|
|
2016-03-03 19:14:50 +01:00
|
|
|
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
2020-04-30 20:33:38 +02:00
|
|
|
static void irq_config_func_0(const struct device *dev)
|
2016-03-03 19:14:50 +01:00
|
|
|
{
|
2020-03-24 22:18:30 +01:00
|
|
|
IRQ_CONNECT(DT_INST_IRQN(0),
|
|
|
|
DT_INST_IRQ(0, priority),
|
2020-12-11 17:12:30 +01:00
|
|
|
uart_stellaris_isr, DEVICE_DT_INST_GET(0),
|
2017-06-15 14:06:05 +02:00
|
|
|
0);
|
2020-03-24 22:18:30 +01:00
|
|
|
irq_enable(DT_INST_IRQN(0));
|
2016-03-03 19:14:50 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-12-01 17:42:19 +01:00
|
|
|
#endif /* CONFIG_UART_STELLARIS_PORT_0 */
|
|
|
|
|
|
|
|
#ifdef CONFIG_UART_STELLARIS_PORT_1
|
|
|
|
|
2016-03-03 19:14:50 +01:00
|
|
|
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
2020-04-30 20:33:38 +02:00
|
|
|
static void irq_config_func_1(const struct device *port);
|
2016-03-03 19:14:50 +01:00
|
|
|
#endif
|
|
|
|
|
2015-12-01 17:42:19 +01:00
|
|
|
static struct uart_device_config uart_stellaris_dev_cfg_1 = {
|
2020-05-27 18:26:57 +02:00
|
|
|
.base = (uint8_t *)DT_INST_REG_ADDR(1),
|
2020-03-24 22:18:30 +01:00
|
|
|
.sys_clk_freq = DT_INST_PROP_BY_PHANDLE(1, clocks, clock_frequency),
|
2016-03-03 19:14:50 +01:00
|
|
|
|
|
|
|
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
|
|
|
.irq_config_func = irq_config_func_1,
|
|
|
|
#endif
|
2016-01-06 18:17:03 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct uart_stellaris_dev_data_t uart_stellaris_dev_data_1 = {
|
2020-03-24 22:18:30 +01:00
|
|
|
.baud_rate = DT_INST_PROP(1, current_speed),
|
2015-12-01 17:42:19 +01:00
|
|
|
};
|
|
|
|
|
2020-12-11 17:12:30 +01:00
|
|
|
DEVICE_DT_INST_DEFINE(1,
|
2017-06-16 17:42:01 +02:00
|
|
|
&uart_stellaris_init,
|
2021-04-28 12:01:21 +02:00
|
|
|
NULL,
|
2016-04-14 18:28:35 +02:00
|
|
|
&uart_stellaris_dev_data_1, &uart_stellaris_dev_cfg_1,
|
2021-10-14 16:38:10 +02:00
|
|
|
PRE_KERNEL_1, CONFIG_SERIAL_INIT_PRIORITY,
|
2016-04-14 18:28:35 +02:00
|
|
|
&uart_stellaris_driver_api);
|
2015-12-01 17:42:19 +01:00
|
|
|
|
2016-03-03 19:14:50 +01:00
|
|
|
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
2020-04-30 20:33:38 +02:00
|
|
|
static void irq_config_func_1(const struct device *dev)
|
2016-03-03 19:14:50 +01:00
|
|
|
{
|
2020-03-24 22:18:30 +01:00
|
|
|
IRQ_CONNECT(DT_INST_IRQN(1),
|
|
|
|
DT_INST_IRQ(1, priority),
|
2020-12-11 17:12:30 +01:00
|
|
|
uart_stellaris_isr, DEVICE_DT_INST_GET(1),
|
2017-06-15 14:06:05 +02:00
|
|
|
0);
|
2020-03-24 22:18:30 +01:00
|
|
|
irq_enable(DT_INST_IRQN(1));
|
2016-03-03 19:14:50 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-12-01 17:42:19 +01:00
|
|
|
#endif /* CONFIG_UART_STELLARIS_PORT_1 */
|
|
|
|
|
|
|
|
#ifdef CONFIG_UART_STELLARIS_PORT_2
|
|
|
|
|
2016-03-03 19:14:50 +01:00
|
|
|
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
2020-04-30 20:33:38 +02:00
|
|
|
static void irq_config_func_2(const struct device *port);
|
2016-03-03 19:14:50 +01:00
|
|
|
#endif
|
|
|
|
|
2016-10-19 23:17:58 +02:00
|
|
|
static const struct uart_device_config uart_stellaris_dev_cfg_2 = {
|
2020-05-27 18:26:57 +02:00
|
|
|
.base = (uint8_t *)DT_INST_REG_ADDR(2),
|
2020-03-24 22:18:30 +01:00
|
|
|
.sys_clk_freq = DT_INST_PROP_BY_PHANDLE(2, clocks, clock_frequency),
|
2016-03-03 19:14:50 +01:00
|
|
|
|
|
|
|
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
|
|
|
.irq_config_func = irq_config_func_2,
|
|
|
|
#endif
|
2016-01-06 18:17:03 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct uart_stellaris_dev_data_t uart_stellaris_dev_data_2 = {
|
2020-03-24 22:18:30 +01:00
|
|
|
.baud_rate = DT_INST_PROP(2, current_speed),
|
2015-12-01 17:42:19 +01:00
|
|
|
};
|
|
|
|
|
2020-12-11 17:12:30 +01:00
|
|
|
DEVICE_DT_INST_DEFINE(2,
|
2017-06-16 17:42:01 +02:00
|
|
|
&uart_stellaris_init,
|
2021-04-28 12:01:21 +02:00
|
|
|
NULL,
|
2016-04-14 18:28:35 +02:00
|
|
|
&uart_stellaris_dev_data_2, &uart_stellaris_dev_cfg_2,
|
2021-10-14 16:38:10 +02:00
|
|
|
PRE_KERNEL_1, CONFIG_SERIAL_INIT_PRIORITY,
|
2016-04-14 18:28:35 +02:00
|
|
|
&uart_stellaris_driver_api);
|
2015-12-01 17:42:19 +01:00
|
|
|
|
2016-03-03 19:14:50 +01:00
|
|
|
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
2020-04-30 20:33:38 +02:00
|
|
|
static void irq_config_func_2(const struct device *dev)
|
2016-03-03 19:14:50 +01:00
|
|
|
{
|
2020-03-24 22:18:30 +01:00
|
|
|
IRQ_CONNECT(DT_INST_IRQN(2),
|
|
|
|
DT_INST_IRQ(2, priority),
|
2020-12-11 17:12:30 +01:00
|
|
|
uart_stellaris_isr, DEVICE_DT_INST_GET(2),
|
2017-06-15 14:06:05 +02:00
|
|
|
0);
|
2020-03-24 22:18:30 +01:00
|
|
|
irq_enable(DT_INST_IRQN(2));
|
2016-03-03 19:14:50 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-12-01 17:42:19 +01:00
|
|
|
#endif /* CONFIG_UART_STELLARIS_PORT_2 */
|