diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..f9ab7df4 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "files.associations": { + "arc_exception.h": "c", + "arc_timer.h": "c" + } +} \ No newline at end of file diff --git a/arch/arc/nsim/common/include/tos_cpu.h b/arch/arc/nsim/common/include/tos_cpu.h index 1dc9dc2f..d1385b6a 100644 --- a/arch/arc/nsim/common/include/tos_cpu.h +++ b/arch/arc/nsim/common/include/tos_cpu.h @@ -43,25 +43,33 @@ __API__ cpu_hrtimer_t tos_cpu_hrtimer_read(void); #endif -__KERNEL__ void cpu_init(void); -__KERNEL__ void cpu_reset(void); +__KNL__ void cpu_init(void); -__KERNEL__ void cpu_systick_init(k_cycle_t cycle_per_tick); -__KERNEL__ void cpu_sched_start(void); +__KNL__ void cpu_reset(void); -__KERNEL__ void cpu_context_switch(void); -__KERNEL__ void cpu_irq_context_switch(void); +__KNL__ void cpu_systick_init(k_cycle_t cycle_per_tick); + + +__KNL__ void cpu_sched_start(void); + + +__KNL__ void cpu_context_switch(void); + + +__KNL__ void cpu_irq_context_switch(void); #if TOS_CFG_TASK_STACK_DRAUGHT_DEPTH_DETACT_EN > 0u -__KERNEL__ k_err_t cpu_task_stack_draught_depth(k_stack_t *stk_base, size_t stk_size, int *depth); + +__KNL__ k_err_t cpu_task_stack_draught_depth(k_stack_t *stk_base, size_t stk_size, int *depth); #endif -__KERNEL__ k_stack_t *cpu_task_stk_init(void *entry, + +__KNL__ k_stack_t *cpu_task_stk_init(void *entry, void *arg, void *exit, k_stack_t *stk_base, @@ -69,29 +77,39 @@ __KERNEL__ k_stack_t *cpu_task_stk_init(void *entry, #if TOS_CFG_TICKLESS_EN > 0u -__KERNEL__ void cpu_systick_resume(void); -__KERNEL__ void cpu_systick_suspend(void); +__KNL__ void cpu_systick_resume(void); -__KERNEL__ void cpu_systick_reload_reset(void); -__KERNEL__ void cpu_systick_pending_reset(void); +__KNL__ void cpu_systick_suspend(void); -__KERNEL__ k_time_t cpu_systick_max_delay_millisecond(void); -__KERNEL__ void cpu_systick_expires_set(k_time_t millisecond); +__KNL__ void cpu_systick_reload_reset(void); -__KERNEL__ void cpu_systick_reset(void); + +__KNL__ void cpu_systick_pending_reset(void); + + +__KNL__ k_time_t cpu_systick_max_delay_millisecond(void); + + +__KNL__ void cpu_systick_expires_set(k_time_t millisecond); + + +__KNL__ void cpu_systick_reset(void); #endif #if TOS_CFG_PWR_MGR_EN > 0u -__KERNEL__ void cpu_sleep_mode_enter(void); -__KERNEL__ void cpu_stop_mode_enter(void); +__KNL__ void cpu_sleep_mode_enter(void); -__KERNEL__ void cpu_standby_mode_enter(void); + +__KNL__ void cpu_stop_mode_enter(void); + + +__KNL__ void cpu_standby_mode_enter(void); #endif @@ -99,11 +117,13 @@ __KERNEL__ void cpu_standby_mode_enter(void); #if defined (TOS_CFG_CPU_ARM_FPU_EN) && (TOS_CFG_CPU_ARM_FPU_EN == 1U) -__KERNEL__ void cpu_flush_fpu(void); + +__KNL__ void cpu_flush_fpu(void); #endif /* TOS_CFG_CPU_ARM_FPU_EN */ -__KERNEL__ void cpu_fault_diagnosis(void); + +__KNL__ void cpu_fault_diagnosis(void); #endif diff --git a/arch/arc/nsim/common/tos_cpu.c b/arch/arc/nsim/common/tos_cpu.c index 6f135027..7274d0ba 100644 --- a/arch/arc/nsim/common/tos_cpu.c +++ b/arch/arc/nsim/common/tos_cpu.c @@ -73,7 +73,7 @@ __API__ void tos_cpu_cpsr_restore(cpu_cpsr_t cpsr) port_cpsr_restore(cpsr); } -__KERNEL__ void cpu_init(void) +__KNL__ void cpu_init(void) { k_cpu_cycle_per_tick = TOS_CFG_CPU_CLOCK / k_cpu_tick_per_second; cpu_systick_init(k_cpu_cycle_per_tick); @@ -83,28 +83,28 @@ __KERNEL__ void cpu_init(void) #endif } -__KERNEL__ void cpu_reset(void) +__KNL__ void cpu_reset(void) { port_cpu_reset(); } -__KERNEL__ void cpu_sched_start(void) // 启动任务调度器 +__KNL__ void cpu_sched_start(void) // 启动任务调度器 { port_sched_start(); } -__KERNEL__ void cpu_context_switch(void) +__KNL__ void cpu_context_switch(void) { port_context_switch(); } -__KERNEL__ void cpu_irq_context_switch(void) +__KNL__ void cpu_irq_context_switch(void) { // port_irq_context_switch(); // DO NOTHING } -__KERNEL__ void cpu_systick_init(k_cycle_t cycle_per_tick) +__KNL__ void cpu_systick_init(k_cycle_t cycle_per_tick) { port_systick_priority_set(TOS_CFG_CPU_SYSTICK_PRIO); port_systick_config(cycle_per_tick); @@ -129,7 +129,7 @@ __STATIC_INLINE__ void cpu_systick_reload(k_cycle_t cycle_per_tick) * * @return None */ -__KERNEL__ void cpu_systick_resume(void) +__KNL__ void cpu_systick_resume(void) { port_systick_resume(); } @@ -139,17 +139,17 @@ __KERNEL__ void cpu_systick_resume(void) * * @return None */ -__KERNEL__ void cpu_systick_suspend(void) +__KNL__ void cpu_systick_suspend(void) { port_systick_suspend(); } -__KERNEL__ k_time_t cpu_systick_max_delay_millisecond(void) +__KNL__ k_time_t cpu_systick_max_delay_millisecond(void) { return port_systick_max_delay_millisecond(); } -__KERNEL__ void cpu_systick_expires_set(k_time_t millisecond) +__KNL__ void cpu_systick_expires_set(k_time_t millisecond) { k_cycle_t cycles; @@ -158,12 +158,12 @@ __KERNEL__ void cpu_systick_expires_set(k_time_t millisecond) cpu_systick_reload(cycles - 12); /* interrupt delay */ } -__KERNEL__ void cpu_systick_pending_reset(void) +__KNL__ void cpu_systick_pending_reset(void) { port_systick_pending_reset(); } -__KERNEL__ void cpu_systick_reset(void) +__KNL__ void cpu_systick_reset(void) { cpu_systick_reload(k_cpu_cycle_per_tick); } @@ -172,24 +172,24 @@ __KERNEL__ void cpu_systick_reset(void) #if TOS_CFG_PWR_MGR_EN > 0u -__KERNEL__ void cpu_sleep_mode_enter(void) +__KNL__ void cpu_sleep_mode_enter(void) { port_sleep_mode_enter(); } -__KERNEL__ void cpu_stop_mode_enter(void) +__KNL__ void cpu_stop_mode_enter(void) { port_stop_mode_enter(); } -__KERNEL__ void cpu_standby_mode_enter(void) +__KNL__ void cpu_standby_mode_enter(void) { port_standby_mode_enter(); } #endif /* TOS_CFG_PWR_MGR_EN */ -__KERNEL__ k_stack_t *cpu_task_stk_init(void *entry, +__KNL__ k_stack_t *cpu_task_stk_init(void *entry, void *arg, void *exit, k_stack_t *stk_base, @@ -214,7 +214,7 @@ __KERNEL__ k_stack_t *cpu_task_stk_init(void *entry, #if TOS_CFG_TASK_STACK_DRAUGHT_DEPTH_DETACT_EN > 0u -__KERNEL__ k_err_t cpu_task_stack_draught_depth(k_stack_t *stk_base, size_t stk_size, int *depth) +__KNL__ k_err_t cpu_task_stack_draught_depth(k_stack_t *stk_base, size_t stk_size, int *depth) { uint8_t *slot; uint8_t *sp, *bp; @@ -244,7 +244,7 @@ __KERNEL__ k_err_t cpu_task_stack_draught_depth(k_stack_t *stk_base, size_t stk_ #if TOS_CFG_FAULT_BACKTRACE_EN > 0u -__KERNEL__ void cpu_fault_diagnosis(void) +__KNL__ void cpu_fault_diagnosis(void) { port_fault_diagnosis(); } diff --git a/arch/arc/nsim/em/gcc/port_c.c b/arch/arc/nsim/em/gcc/port_c.c index 0f98658b..cca0812e 100644 --- a/arch/arc/nsim/em/gcc/port_c.c +++ b/arch/arc/nsim/em/gcc/port_c.c @@ -45,6 +45,11 @@ #include "board.h" #include "arc/arc_exception.h" +__PORT__ void port_cpu_reset(void) +{ + exc_entry_reset(); +} + __PORT__ void port_systick_config(uint32_t cycle_per_tick) // Configure SysTick to generate an interrupt every cycle_per_tick { timer_int_clear(0); // nsim #define BOARD_SYS_TIMER_ID TIMER_0 diff --git a/board/ARC_NSIM_EM/BSP/Inc/nsim.h b/board/ARC_NSIM_EM/BSP/Inc/nsim.h index c0342e22..4562f87a 100644 --- a/board/ARC_NSIM_EM/BSP/Inc/nsim.h +++ b/board/ARC_NSIM_EM/BSP/Inc/nsim.h @@ -32,7 +32,7 @@ #include "arc/arc_feature_config.h" #include "arc/arc_em.h" - +#include "arc/arc_timer.h" #include "nsim_uart_obj.h" /** CPU Clock Frequency definition */ diff --git a/board/ARC_NSIM_EM/BSP/Src/main.c b/board/ARC_NSIM_EM/BSP/Src/main.c new file mode 100644 index 00000000..bf5da6c8 --- /dev/null +++ b/board/ARC_NSIM_EM/BSP/Src/main.c @@ -0,0 +1,50 @@ +#include "cmsis_os.h" +#include "arc/arc_exception.h" +#include "arc/arc_cache.h" +#include "nsim.h" +#include "board.h" + +static uint32_t cyc_hz_count = (BOARD_CPU_CLOCK / BOARD_SYS_TIMER_HZ); + +static void board_timer_isr(void *ptr) +{ + timer_int_clear(BOARD_SYS_TIMER_ID); + + board_timer_update(BOARD_SYS_TIMER_HZ); +} + +static void board_timer_init(void) +{ + if (timer_present(BOARD_SYS_TIMER_ID)) { + int_disable(BOARD_SYS_TIMER_INTNO); /* disable first then enable */ + int_handler_install(BOARD_SYS_TIMER_INTNO, board_timer_isr); + timer_start(BOARD_SYS_TIMER_ID, TIMER_CTRL_IE | TIMER_CTRL_NH, cyc_hz_count); /* start 1ms timer interrupt */ + + int_enable(BOARD_SYS_TIMER_INTNO); + } +} + +#define APPLICATION_TASK_STK_SIZE 4096 +extern void application_entry(void *arg); +osThreadDef(application_entry, osPriorityNormal, 1, APPLICATION_TASK_STK_SIZE); + +EMBARC_WEAK void application_entry(void *arg) +{ + while (1) { + printf("This is a demo task,please use your task entry!\r\n"); + tos_task_delay(1000); + } +} + +int main(void) +{ + exc_int_init(); + arc_cache_init(); + board_init(); + board_timer_init(); + printf("Welcome to TencentOS tiny\r\n"); + osKernelInitialize(); // TOS Tiny kernel initialize + osThreadCreate(osThread(application_entry), NULL); // Create TOS Tiny task + osKernelStart(); // Start TOS Tiny +} + diff --git a/board/ARC_NSIM_EM/GCC/hello_world/Makefile b/board/ARC_NSIM_EM/GCC/hello_world/Makefile index 603d97d3..80b4b523 100644 --- a/board/ARC_NSIM_EM/GCC/hello_world/Makefile +++ b/board/ARC_NSIM_EM/GCC/hello_world/Makefile @@ -49,6 +49,7 @@ CMSIS_SRC = \ C_SOURCES += $(CMSIS_SRC) HAL_DRIVER_SRC = \ + $(TOP_DIR)/board/ARC_NSIM_EM/BSP/Src/main.c \ $(TOP_DIR)/board/ARC_NSIM_EM/BSP/Src/nsim_init.c \ $(TOP_DIR)/board/ARC_NSIM_EM/BSP/Src/nsim_uart_obj.c \ $(TOP_DIR)/examples/hello_world/hello_world.c \ diff --git a/platform/vendor_bsp/embarc_bsp/arc/startup/arc_startup.s b/platform/vendor_bsp/embarc_bsp/arc/startup/arc_startup.s index 7cbe6ce3..946669b1 100644 --- a/platform/vendor_bsp/embarc_bsp/arc/startup/arc_startup.s +++ b/platform/vendor_bsp/embarc_bsp/arc/startup/arc_startup.s @@ -49,7 +49,7 @@ .weak _f_sdata /* start of small data, defined in link script */ .weak init_hardware_hook /* app hardware init hook */ -.extern board_main +.extern main .extern exc_entry_table /* initial vector table */ @@ -188,7 +188,7 @@ _s3_clear_bss_loop: /* STAGE 3: go to next level initialization */ _arc_reset_call_main: - jl board_main /* board-level main */ + jl main /* board-level main */ b _exit_loop .global _exit_loop diff --git a/platform/vendor_bsp/embarc_bsp/board/board.c b/platform/vendor_bsp/embarc_bsp/board/board.c index 79ae149a..7e1b4dd0 100644 --- a/platform/vendor_bsp/embarc_bsp/board/board.c +++ b/platform/vendor_bsp/embarc_bsp/board/board.c @@ -84,80 +84,6 @@ static volatile uint32_t gl_ms_cnt = 0; #define HZ_COUNT_CONV(precision, base) ((precision) / (base)) -/** - * @brief Board bare-metal timer interrupt. - * Interrupt frequency is based on the defined @ref BOARD_SYS_TIMER_HZ - */ -static void board_timer_isr(void *ptr) -{ - timer_int_clear(BOARD_SYS_TIMER_ID); - - board_timer_update(BOARD_SYS_TIMER_HZ); -} - -/** - * @brief Initialise bare-metal board timer and interrupt - * @details - * This function is called in @ref board_init, and - * it initializes the 1-MS timer interrupt for bare-metal mode - */ -static void board_timer_init(void) -{ - if (timer_present(BOARD_SYS_TIMER_ID)) { - int_disable(BOARD_SYS_TIMER_INTNO); /* disable first then enable */ - int_handler_install(BOARD_SYS_TIMER_INTNO, board_timer_isr); - timer_start(BOARD_SYS_TIMER_ID, TIMER_CTRL_IE | TIMER_CTRL_NH, cyc_hz_count); /* start 1ms timer interrupt */ - - int_enable(BOARD_SYS_TIMER_INTNO); - } -} - -static void platform_print_banner(void) -{ - EMBARC_PRINTF("%s\r\n", embarc_banner); - EMBARC_PRINTF("embARC Build Time: %s, %s\r\n", __DATE__, __TIME__); -#if defined(__GNU__) - EMBARC_PRINTF("Compiler Version: ARC GNU, %s\r\n", __VERSION__); -#else - EMBARC_PRINTF("Compiler Version: Metaware, %s\r\n\r\n", __VERSION__); -#endif -} - -EMBARC_WEAK void platform_main(void) -{ -#ifdef LIB_CONSOLE - xprintf_setup(); -#endif - platform_print_banner(); - arc_goto_main(0, NULL); -} - -EMBARC_WEAK void board_main(void) -{ -#if defined(__MW__) -/* Metaware toolchain C++ init */ - arc_mwdt_init(); -#elif defined(__GNU__) -/* ARC GNU toolchain C++ init */ - arc_gnu_do_global_ctors_aux(); - arc_gnu_do_init_array_aux(); -#endif - /* init core level interrupt & exception management */ - exc_int_init(); - /* init cache */ - arc_cache_init(); - /* necessary board level init */ - board_init(); - /* Initialise bare-metal board timer and interrupt */ - board_timer_init(); - /* platform (e.g RTOS, baremetal)level init */ - platform_main(); -#if defined(__MW__) - arc_mwdt_fini(); -#elif defined(__GNU__) - arc_gnu_do_global_dtors_aux(); -#endif -} /** * @brief Update timer counter and other MS period operation