Skip to content
Merged
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 7 additions & 0 deletions .github/ALL_BSP_COMPILE.json
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,13 @@
"SUB_RTT_BSP": [
"qemu-vexpress-a9"
]
},
{
"RTT_BSP": "xuantie",
"RTT_TOOL_CHAIN": "sourcery-Xuantie-900-gcc-elf-newlib",
"SUB_RTT_BSP": [
"xuantie/smartl/e906"
]
}
]
}
8 changes: 8 additions & 0 deletions .github/workflows/bsp_buildings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,14 @@ jobs:
/opt/riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-linux-ubuntu14/bin/riscv64-unknown-elf-gcc --version
echo "RTT_EXEC_PATH=/opt/riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-linux-ubuntu14/bin" >> $GITHUB_ENV

- name: Install Xuantie-900-gcc-elf-newlib Tools
if: ${{ matrix.legs.RTT_TOOL_CHAIN == 'sourcery-Xuantie-900-gcc-elf-newlib' && success() }}
run: |
wget -q https://occ-oss-prod.oss-cn-hangzhou.aliyuncs.com/resource//1744884010580/Xuantie-900-gcc-elf-newlib-x86_64-V3.0.2-20250410.tar.gz
sudo tar -zxvf Xuantie-900-gcc-elf-newlib-x86_64-V3.0.2-20250410.tar.gz -C /opt
/opt/Xuantie-900-gcc-elf-newlib-x86_64-V3.0.2/bin/riscv64-unknown-elf-gcc --version
echo "RTT_EXEC_PATH=/opt/Xuantie-900-gcc-elf-newlib-x86_64-V3.0.2/bin" >> $GITHUB_ENV

- name: Install k230 MUSL ToolChains
if: ${{ matrix.legs.RTT_TOOL_CHAIN == 'riscv64-unknown-linux-musl-' && matrix.legs.RTT_BSP == 'K230' && success() }}
run: |
Expand Down
15 changes: 15 additions & 0 deletions bsp/xuantie/libraries/SConscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# for module compiling
import os
Import('RTT_ROOT')
from building import *

cwd = GetCurrentDir()
objs = []
list = os.listdir(cwd)

for d in list:
path = os.path.join(cwd, d)
if os.path.isfile(os.path.join(path, 'SConscript')):
objs = objs + SConscript(os.path.join(d, 'SConscript'))

Return('objs')
16 changes: 16 additions & 0 deletions bsp/xuantie/libraries/device_drivers/SConscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from building import *
import os

cwd = GetCurrentDir()
CPPPATH = [cwd]

src = Split("""
""")

if GetDepend('SOC_XUANTIE'):

if GetDepend('BSP_USING_UART'):
src += ['drv_usart.c']

group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH)
Return('group')
219 changes: 219 additions & 0 deletions bsp/xuantie/libraries/device_drivers/drv_usart.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
/*
* Copyright (c) 2006-2025, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2025-04-27 WangShun the first version
*/

#include "board.h"
#include "rtthread.h"
#include <rtdevice.h>
#include <string.h>
#include <drv_usart.h>

#ifdef RT_USING_SERIAL
#define DRV_DEBUG
#define LOG_TAG "drv.uart"

#ifdef DRV_DEBUG
#define DBG_LVL DBG_LOG
#else
#define DBG_LVL DBG_INFO
#endif /* DRV_DEBUG */

#include <rtdbg.h>

#if !defined(BSP_USING_UART0) && !defined(BSP_USING_UART1) && !defined(BSP_USING_UART2) && !defined(BSP_USING_UART3) \
&& !defined(BSP_USING_UART4) && !defined(BSP_USING_UART5) && !defined(BSP_USING_UART6) && !defined(BSP_USING_UART7)
#error "Please define at least one BSP_USING_UARTx"
/* this driver can be disabled at menuconfig -> RT-Thread Components -> Device Drivers */
#endif

static void xuantie_uart0_rx_isr(csi_uart_t *uart_handler, csi_uart_event_t event, void *arg);

enum
{
#ifdef BSP_USING_UART0
UART0_INDEX,
#endif
};

struct xuantie_uart_config uart_config[] =
{
#ifdef BSP_USING_UART0
{
"uart0",
0,
xuantie_uart0_rx_isr
}
#endif
};

struct xuantie_uart uart_obj[sizeof(uart_config) / sizeof(uart_config[0])] = {0};

static rt_err_t xuantie_configure(struct rt_serial_device *serial, struct serial_configure *cfg)
{
struct xuantie_uart *uart = (struct xuantie_uart *)serial->parent.user_data;
csi_error_t ret;

ret = csi_uart_baud(&uart->uart, cfg->baud_rate);
if (ret != CSI_OK)
{
return -RT_ERROR;
}

csi_uart_data_bits_t data_bits;
csi_uart_parity_t parity;
csi_uart_stop_bits_t stop_bits;

switch (cfg->data_bits)
{
case DATA_BITS_5:
data_bits = UART_DATA_BITS_5;
break;
case DATA_BITS_6:
data_bits = UART_DATA_BITS_6;
break;
case DATA_BITS_7:
data_bits = UART_DATA_BITS_7;
break;
case DATA_BITS_8:
data_bits = UART_DATA_BITS_8;
break;
case DATA_BITS_9:
data_bits = UART_DATA_BITS_9;
break;
default:
data_bits = UART_DATA_BITS_8;
break;
}

switch (cfg->parity)
{
case PARITY_NONE:
parity = UART_PARITY_NONE;
break;
case PARITY_ODD:
parity = UART_PARITY_ODD;
break;
case PARITY_EVEN:
parity = UART_PARITY_EVEN;
break;
default:
parity = UART_PARITY_NONE;
break;
}

switch (cfg->stop_bits)
{
case STOP_BITS_1:
stop_bits = UART_STOP_BITS_1;
break;
case STOP_BITS_2:
stop_bits = UART_STOP_BITS_2;
break;
default:
stop_bits = UART_STOP_BITS_1;
break;
}

ret = csi_uart_format(&uart->uart, data_bits, parity, stop_bits);
if (ret != CSI_OK)
{
return -RT_ERROR;
}

return RT_EOK;
}

static rt_err_t xuantie_control(struct rt_serial_device *serial, int cmd, void *arg)
{
switch (cmd)
{
case RT_DEVICE_CTRL_CONFIG:
return xuantie_configure(serial, (struct serial_configure *)arg);
default:
return -RT_ERROR;
}
}

static int xuantie_putc(struct rt_serial_device *serial, char c)
{
struct xuantie_uart *uart = (struct xuantie_uart *)serial->parent.user_data;
int32_t ret;

ret = csi_uart_send(&uart->uart, &c, 1, 50);
if (ret == 1)
return RT_EOK;

return -RT_ERROR;
}

static int xuantie_getc(struct rt_serial_device *serial)
{
int c = -1;
struct xuantie_uart *uart = (struct xuantie_uart *)serial->parent.user_data;
dw_uart_regs_t *uart_base = (dw_uart_regs_t *)HANDLE_REG_BASE((&uart->uart));

csi_uart_receive(&uart->uart, &c, 1, 0x5);
dw_uart_enable_recv_irq(uart_base);
return c;
}

static const struct rt_uart_ops xuantie_uart_ops =
{
xuantie_configure,
xuantie_control,
xuantie_putc,
xuantie_getc,
RT_NULL,
};

static void xuantie_uart0_rx_isr(csi_uart_t *uart_handler, csi_uart_event_t event, void *arg)
{
rt_interrupt_enter();
rt_hw_serial_isr(&uart_obj[UART0_INDEX].serial, RT_SERIAL_EVENT_RX_IND);
rt_interrupt_leave();
}

int rt_hw_usart_init(void)
{
rt_size_t obj_num = sizeof(uart_obj) / sizeof(struct xuantie_uart);
struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT;
rt_err_t result = 0;

for (int i = 0; i < obj_num; i++)
{
/* Initialize YOC UART */
result = csi_uart_init(&uart_obj[i].uart, 0);
if (result != CSI_OK)
{
LOG_E("Failed to initialize UART %d", uart_obj[i].config->idx);
return -RT_ERROR;
}

/* Init UART object */
uart_obj[i].config = &uart_config[i];
uart_obj[i].serial.ops = &xuantie_uart_ops;
uart_obj[i].serial.config = config;

csi_uart_attach_callback(&uart_obj[i].uart, uart_obj[i].config->xuantie_uart_rx_isr, NULL);

/* Register UART device */
result = rt_hw_serial_register(&uart_obj[i].serial, uart_obj[i].config->name,
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX,
&uart_obj[i]);
if (result != RT_EOK)
{
LOG_E("Failed to register UART device %s", uart_obj[i].config->name);
csi_uart_uninit(&uart_obj[i].uart);
return -RT_ERROR;
}
}
return result;
}

#endif /* RT_USING_SERIAL */
38 changes: 38 additions & 0 deletions bsp/xuantie/libraries/device_drivers/drv_usart.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2006-2025, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2022-12-08 WangShun the first version
*/
#ifndef __DRV_USART_H__
#define __DRV_USART_H__
#include <rtthread.h>
#include "rtdevice.h"
#include <rthw.h>

#include <soc.h>
#include <dw_uart_ll.h>
#include <drv/uart.h>

/* xuantie config class */
struct xuantie_uart_config
{
const char *name;
uint32_t idx;
void (*xuantie_uart_rx_isr)(csi_uart_t *uart_handler, csi_uart_event_t event, void *arg);
};

/* xuantie uart dirver class */
struct xuantie_uart
{
struct xuantie_uart_config *config;
struct rt_serial_device serial;
csi_uart_t uart;
};

extern void uart_rx_isr (void *id);
int rt_hw_usart_init(void);
#endif /* __DRV_USART_H__ */
15 changes: 15 additions & 0 deletions bsp/xuantie/libraries/xuantie_libraries/SConscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# for module compiling
import os
Import('RTT_ROOT')
from building import *

cwd = GetCurrentDir()
objs = []
list = os.listdir(cwd)

for d in list:
path = os.path.join(cwd, d)
if os.path.isfile(os.path.join(path, 'SConscript')):
objs = objs + SConscript(os.path.join(d, 'SConscript'))

Return('objs')
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# for module compiling
import os
Import('RTT_ROOT')
from building import *

cwd = GetCurrentDir()
objs = []
list = os.listdir(cwd)

for d in list:
path = os.path.join(cwd, d)
if os.path.isfile(os.path.join(path, 'SConscript')):
objs = objs + SConscript(os.path.join(d, 'SConscript'))

Return('objs')
Loading