Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 56 additions & 11 deletions bsp/novosns/ns800/libraries/HAL_Drivers/drivers/drv_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,29 @@
#define NS800_UART_DEFAULT_TX_TIMEOUT BSP_NS800_UART_TX_TIMEOUT
#endif

/* Default UART configuration from Kconfig */
#ifndef BSP_UART_DEFAULT_BAUDRATE
#define BSP_UART_DEFAULT_BAUDRATE 115200
#endif

/* Data bits mapping */
#if defined(BSP_UART_DATABITS_7)
#define NS800_UART_DEFAULT_DATA_BITS DATA_BITS_7
#elif defined(BSP_UART_DATABITS_8)
#define NS800_UART_DEFAULT_DATA_BITS DATA_BITS_8
#elif defined(BSP_UART_DATABITS_9)
#define NS800_UART_DEFAULT_DATA_BITS DATA_BITS_9
#else
#define NS800_UART_DEFAULT_DATA_BITS DATA_BITS_8
#endif

/* Stop bits mapping */
#ifdef BSP_UART_STOPBITS_2
#define NS800_UART_DEFAULT_STOP_BITS STOP_BITS_2
#else
#define NS800_UART_DEFAULT_STOP_BITS STOP_BITS_1
#endif

enum
{
#ifdef BSP_USING_UART1
Expand Down Expand Up @@ -377,31 +400,48 @@ static rt_err_t ns800_control(struct rt_serial_device *serial, int cmd, void *ar
return RT_EOK;
}

static int ns800_putc(struct rt_serial_device *serial, char c)
static rt_err_t ns800_wait_tx_space(struct ns800_uart *uart, rt_uint32_t timeout_ms)
{
struct ns800_uart *uart;
rt_uint32_t block_timeout;
rt_tick_t start_tick;
rt_tick_t timeout_tick;

RT_ASSERT(serial != RT_NULL);
RT_ASSERT(uart != RT_NULL);

uart = rt_container_of(serial, struct ns800_uart, serial);
block_timeout = uart->tx_block_timeout;
if (UART_isSpaceAvailable(uart->handle.Instance))
{
return RT_EOK;
}

timeout_tick = rt_tick_from_millisecond(timeout_ms);
start_tick = rt_tick_get();
Comment on lines +415 to +416

while (!UART_isSpaceAvailable(uart->handle.Instance))
{
if (block_timeout-- == 0U)
if ((rt_tick_get() - start_tick) > timeout_tick)
{
return -1;
return -RT_ETIMEOUT;
}
}
Comment on lines 418 to 424

UART_writeChar(uart->handle.Instance, (rt_uint8_t)c);
return RT_EOK;
}

static int ns800_putc(struct rt_serial_device *serial, char c)
{
struct ns800_uart *uart;
rt_err_t result;

RT_ASSERT(serial != RT_NULL);

while ((uart->handle.Instance->STAT.BIT.TC == false) && (--block_timeout != 0U))
uart = rt_container_of(serial, struct ns800_uart, serial);
result = ns800_wait_tx_space(uart, uart->tx_block_timeout);
if (result != RT_EOK)
{
return -1;
}

return (block_timeout != 0U) ? 1 : -1;
UART_writeChar(uart->handle.Instance, (rt_uint8_t)c);
return 1;
Comment on lines +443 to +444
}

static int ns800_getc(struct rt_serial_device *serial)
Expand Down Expand Up @@ -489,6 +529,11 @@ static void ns800_uart_fill_default_config(struct serial_configure *config,

*config = (struct serial_configure)RT_SERIAL_CONFIG_DEFAULT;

/* Override with Kconfig settings */
config->baud_rate = BSP_UART_DEFAULT_BAUDRATE;
config->data_bits = NS800_UART_DEFAULT_DATA_BITS;
config->stop_bits = NS800_UART_DEFAULT_STOP_BITS;

#ifdef RT_USING_SERIAL_V2
config->rx_bufsz = hw->rx_bufsz;
config->tx_bufsz = hw->tx_bufsz;
Expand Down
26 changes: 26 additions & 0 deletions bsp/novosns/ns800/ns800rt7p65-nssinepad/board/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,32 @@ menu "On-chip Peripheral Drivers"
default 6000
depends on !RT_USING_SERIAL_V2

config BSP_UART_DEFAULT_BAUDRATE
int "UART default baudrate"
default 115200
help
Default baudrate for all UART ports.
Comment on lines +23 to +27

choice BSP_UART_DEFAULT_DATABITS
prompt "UART default data bits"
default BSP_UART_DATABITS_8
config BSP_UART_DATABITS_7
bool "7 bits"
config BSP_UART_DATABITS_8
bool "8 bits"
config BSP_UART_DATABITS_9
bool "9 bits"
endchoice

choice BSP_UART_DEFAULT_STOPBITS
prompt "UART default stop bits"
default BSP_UART_STOPBITS_1
config BSP_UART_STOPBITS_1
bool "1 bit"
config BSP_UART_STOPBITS_2
bool "2 bits"
endchoice

menuconfig BSP_USING_UART1
bool "Enable UART1"
default y
Expand Down
Loading