Refactors all of the serial drivers to use a shared driver class initialization priority configuration, CONFIG_SERIAL_INIT_PRIORITY, to allow configuring serial drivers separately from other devices. This is similar to other driver classes like I2C and SPI. The default is set to CONFIG_KERNEL_INIT_PRIORITY_DEVICE to preserve the existing default initialization priority for most drivers. The one exception is uart_lpc11u6x.c which previously used CONFIG_KERNEL_INIT_PRIORITY_OBJECTS. This change was motivated by an issue on the frdm_k64f board where the serial driver was incorrectly initialized before the clock control driver. Signed-off-by: Maureen Helm <maureen.helm@intel.com>
60 lines
1.4 KiB
C
60 lines
1.4 KiB
C
/*
|
|
* Copyright (c) 2021 Espressif Systems (Shanghai) Co., Ltd.
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
#define DT_DRV_COMPAT espressif_esp32c3_uart
|
|
|
|
/* Include esp-idf headers first to avoid redefining BIT() macro */
|
|
#include <device.h>
|
|
#include <soc.h>
|
|
#include <drivers/uart.h>
|
|
#include <drivers/clock_control.h>
|
|
#include <errno.h>
|
|
#include <sys/util.h>
|
|
#include <esp_attr.h>
|
|
|
|
static int uart_rom_esp32c3_poll_in(const struct device *dev, unsigned char *p_char)
|
|
{
|
|
ARG_UNUSED(dev);
|
|
return (int)esp_rom_uart_rx_one_char(p_char);
|
|
}
|
|
|
|
static IRAM_ATTR void uart_rom_esp32c3_poll_out(const struct device *dev,
|
|
unsigned char c)
|
|
{
|
|
ARG_UNUSED(dev);
|
|
esp_rom_uart_tx_one_char(c);
|
|
}
|
|
|
|
static int uart_rom_esp32c3_poll_err_check(const struct device *dev)
|
|
{
|
|
ARG_UNUSED(dev);
|
|
return 0;
|
|
}
|
|
|
|
static int uart_rom_esp32c3_init(const struct device *dev)
|
|
{
|
|
ARG_UNUSED(dev);
|
|
return 0;
|
|
}
|
|
|
|
static const DRAM_ATTR struct uart_driver_api uart_rom_esp32c3_api = {
|
|
.poll_in = uart_rom_esp32c3_poll_in,
|
|
.poll_out = uart_rom_esp32c3_poll_out,
|
|
.err_check = uart_rom_esp32c3_poll_err_check,
|
|
};
|
|
|
|
#define ESP32C3_ROM_UART_INIT(idx) \
|
|
DEVICE_DT_DEFINE(DT_NODELABEL(uart##idx), \
|
|
&uart_rom_esp32c3_init, \
|
|
NULL, \
|
|
NULL, \
|
|
NULL, \
|
|
PRE_KERNEL_1, \
|
|
CONFIG_SERIAL_INIT_PRIORITY, \
|
|
&uart_rom_esp32c3_api); \
|
|
|
|
DT_INST_FOREACH_STATUS_OKAY(ESP32C3_ROM_UART_INIT)
|