boarc: nsim: add source code to initialize board and start os

Signed-off-by: Jingru <jingru@synopsys.com>
This commit is contained in:
Jingru
2020-03-17 18:17:10 +08:00
parent 65f55e73e5
commit ddd2d53f06
9 changed files with 123 additions and 115 deletions

6
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,6 @@
{
"files.associations": {
"arc_exception.h": "c",
"arc_timer.h": "c"
}
}

View File

@@ -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

View File

@@ -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();
}

View File

@@ -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

View File

@@ -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 */

View File

@@ -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
}

View File

@@ -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 \

View File

@@ -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

View File

@@ -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