From 8fd31727bc7ff51c83a3c47840cff1bfb100c0ba Mon Sep 17 00:00:00 2001 From: Huaqi Fang <578567190@qq.com> Date: Wed, 15 Apr 2020 12:38:04 +0800 Subject: [PATCH] [BSP][NUCLEI] Format application and board source code Signed-off-by: Huaqi Fang <578567190@qq.com> --- bsp/nuclei/gd32vf103_rvstar/SConstruct | 7 +++-- .../gd32vf103_rvstar/applications/main.c | 30 +++++++++++-------- bsp/nuclei/gd32vf103_rvstar/board/board.c | 22 ++++++++++---- bsp/nuclei/gd32vf103_rvstar/board/board.h | 2 +- 4 files changed, 40 insertions(+), 21 deletions(-) diff --git a/bsp/nuclei/gd32vf103_rvstar/SConstruct b/bsp/nuclei/gd32vf103_rvstar/SConstruct index 08b8a240c7..7adcd69070 100644 --- a/bsp/nuclei/gd32vf103_rvstar/SConstruct +++ b/bsp/nuclei/gd32vf103_rvstar/SConstruct @@ -47,13 +47,16 @@ GDB = rtconfig.GDB # prepare building environment objs = PrepareBuilding(env, RTT_ROOT) -bsp_library_type = 'gd32vf103' +bsp_library_type = rtconfig.NUCLEI_SDK_SOC rtconfig.BSP_LIBRARY_TYPE = bsp_library_type openocd_cfg = rtconfig.NUCLEI_SDK_OPENOCD_CFG.replace('\\', '/') # include hal drivers -objs.extend(SConscript(os.path.join(libraries_path_prefix, bsp_library_type, 'HAL_Drivers', 'SConscript'))) +hal_sconscript = os.path.join(libraries_path_prefix, bsp_library_type, 'HAL_Drivers', 'SConscript') + +if os.path.isfile(hal_sconscript): + objs.extend(SConscript(hal_sconscript)) # make a building DoBuilding(TARGET, objs) diff --git a/bsp/nuclei/gd32vf103_rvstar/applications/main.c b/bsp/nuclei/gd32vf103_rvstar/applications/main.c index a013e6604d..ef6ba62014 100644 --- a/bsp/nuclei/gd32vf103_rvstar/applications/main.c +++ b/bsp/nuclei/gd32vf103_rvstar/applications/main.c @@ -1,11 +1,11 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2020, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes - * 2019-07-23 tyustli first version + * 2020-04-15 hqfang first version */ #include @@ -28,12 +28,14 @@ static void thread_entry(void *parameter) { rt_uint32_t count = 0; - while (1) { + while (1) + { #ifdef APP_DEBUG_PRINT rt_kprintf("thread %d count: %d\n", (rt_uint32_t)parameter, count++); #endif rt_thread_mdelay(500); - if ((rt_uint32_t)parameter < (LEDn-1)) { + if ((rt_uint32_t)parameter < (LEDn - 1)) + { gd_rvstar_led_toggle((rt_uint32_t)parameter); } } @@ -44,18 +46,20 @@ int create_thread_demo(void) { int i; static char tname[9] = "thread"; - - for (i = 0; i < THREAD_NUM; i ++) { + + for (i = 0; i < THREAD_NUM; i ++) + { /* Create static threads */ - tname[6] = i/10 + '0'; - tname[7] = i%10 + '0'; + tname[6] = i / 10 + '0'; + tname[7] = i % 10 + '0'; tname[8] = '\0'; rt_thread_init(&tid[i], tname, thread_entry, (void *)i, thread_stack[i], - THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE); + THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE); } /* Startup threads */ - for (i = 0; i < THREAD_NUM; i ++) { + for (i = 0; i < THREAD_NUM; i ++) + { rt_thread_startup(&tid[i]); } @@ -67,12 +71,14 @@ int main(void) rt_uint32_t count = 0; create_thread_demo(); - for (int i = 0; i < LEDn; i ++) { + for (int i = 0; i < LEDn; i ++) + { gd_rvstar_led_init(i); } - while (1) { + while (1) + { #ifdef APP_DEBUG_PRINT rt_kprintf("Main thread count: %d\n", count++); #endif diff --git a/bsp/nuclei/gd32vf103_rvstar/board/board.c b/bsp/nuclei/gd32vf103_rvstar/board/board.c index a1d2b16e91..7dad875006 100644 --- a/bsp/nuclei/gd32vf103_rvstar/board/board.c +++ b/bsp/nuclei/gd32vf103_rvstar/board/board.c @@ -5,37 +5,47 @@ * * Change Logs: * Date Author Notes - * 2020-04-02 Huaqi Fang first version + * 2020-04-02 hqfang first version * */ #include #include #include "board.h" +#include "cpuport.h" #ifdef RT_USING_SERIAL -#include + #include #endif - +/** _end symbol defined in linker script of Nuclei SDK */ extern void *_end; + +/** _heap_end symbol defined in linker script of Nuclei SDK */ extern void *_heap_end; #define HEAP_BEGIN &_end #define HEAP_END &_heap_end +/* + * - Implemented and defined in Nuclei SDK system_.c file + * - Required macro NUCLEI_BANNER set to 0 + */ extern void _init(void); -extern void vPortSetupTimerInterrupt(void); +/** + * @brief Setup hardware board for rt-thread + * + */ void rt_hw_board_init(void) { /* OS Tick Configuration */ - vPortSetupTimerInterrupt(); + rt_hw_ticksetup(); #ifdef RT_USING_HEAP rt_system_heap_init((void *) HEAP_BEGIN, (void *) HEAP_END); #endif - _init(); // __libc_init_array is not used + _init(); // __libc_init_array is not used in RT-Thread /* USART driver initialization is open by default */ #ifdef RT_USING_SERIAL diff --git a/bsp/nuclei/gd32vf103_rvstar/board/board.h b/bsp/nuclei/gd32vf103_rvstar/board/board.h index 62438d7f51..4e571e3ee2 100644 --- a/bsp/nuclei/gd32vf103_rvstar/board/board.h +++ b/bsp/nuclei/gd32vf103_rvstar/board/board.h @@ -5,7 +5,7 @@ * * Change Logs: * Date Author Notes - * 2020-04-02 Huaqi Fang first version + * 2020-04-02 hqfang first version * */