diff --git a/arch/risc-v/common/tos_cpu.c b/arch/risc-v/common/tos_cpu.c index 8bf2d5ec..97972c8e 100644 --- a/arch/risc-v/common/tos_cpu.c +++ b/arch/risc-v/common/tos_cpu.c @@ -118,7 +118,7 @@ void cpu_trap_entry(cpu_data_t cause, cpu_context_t *regs) } void SysTick_IRQHandler() { - port_systick_config(k_cpu_cycle_per_tick); + port_systick_config((uint32_t)k_cpu_cycle_per_tick); if(tos_knl_is_running()) { tos_knl_irq_enter(); tos_tick_handler(); diff --git a/arch/risc-v/rv32i/gcc/port_c.c b/arch/risc-v/rv32i/gcc/port_c.c index d110ff29..f0cd4096 100644 --- a/arch/risc-v/rv32i/gcc/port_c.c +++ b/arch/risc-v/rv32i/gcc/port_c.c @@ -1,10 +1,18 @@ #include "riscv_encoding.h" #include +#if 0 #define CLINT_CTRL_ADDR 0x2000000 #define CLINT_MSIP 0x0000 #define CLINT_MTIMECMP 0x4000 #define CLINT_MTIME 0xBFF8 +#else +#include "gd32vf103.h" +#define CLINT_CTRL_ADDR 0xD1000000 +#define CLINT_MSIP 0x0FFC +#define CLINT_MTIMECMP 0x0008 +#define CLINT_MTIME 0x0000 +#endif __PORT__ void port_systick_config(uint32_t cycle_per_tick) { @@ -35,6 +43,8 @@ __PORT__ void port_systick_config(uint32_t cycle_per_tick) *(volatile uint32_t *)(CLINT_CTRL_ADDR + CLINT_MTIMECMP + 0) = 0xFFFFFFFF; *(volatile uint32_t *)(CLINT_CTRL_ADDR + CLINT_MTIMECMP + 4) = 0xFFFFFFFF & (mtimecmp >> 32); *(volatile uint32_t *)(CLINT_CTRL_ADDR + CLINT_MTIMECMP + 0) = 0xFFFFFFFF & (mtimecmp >> 0); + + } __PORT__ void port_systick_priority_set(uint32_t prio) diff --git a/arch/risc-v/rv32i/gcc/port_s.S b/arch/risc-v/rv32i/gcc/port_s.S index 9286e5c3..17ae1d3c 100644 --- a/arch/risc-v/rv32i/gcc/port_s.S +++ b/arch/risc-v/rv32i/gcc/port_s.S @@ -250,8 +250,8 @@ irq_entry: call cpu_trap_entry j restore irq: - slli a0, a0, 1 - srli a0, a0, 1 + slli a0, a0, 16 + srli a0, a0, 16 call cpu_irq_entry restore: RESTORE_CONTEXT diff --git a/board/GD32VF103C_START/TOS_CONFIG/tos_config.h b/board/GD32VF103C_START/TOS_CONFIG/tos_config.h index 99ddd475..5ff31cf2 100644 --- a/board/GD32VF103C_START/TOS_CONFIG/tos_config.h +++ b/board/GD32VF103C_START/TOS_CONFIG/tos_config.h @@ -3,25 +3,25 @@ #include "stddef.h" -#define TOS_CFG_TASK_PRIO_MAX 10u // 配置TencentOS tiny默认支持的最大优先级数量 +#define TOS_CFG_TASK_PRIO_MAX 10u // 閰嶇疆TencentOS tiny榛樿鏀寔鐨勬渶澶т紭鍏堢骇鏁伴噺 -#define TOS_CFG_ROUND_ROBIN_EN 0u // 配置TencentOS tiny的内核是否开启时间片轮转 +#define TOS_CFG_ROUND_ROBIN_EN 0u // 閰嶇疆TencentOS tiny鐨勫唴鏍告槸鍚﹀紑鍚椂闂寸墖杞浆 -#define TOS_CFG_OBJECT_VERIFY 0u // 配置TencentOS tiny是否校验指针合法 +#define TOS_CFG_OBJECT_VERIFY 0u // 閰嶇疆TencentOS tiny鏄惁鏍¢獙鎸囬拡鍚堟硶 -#define TOS_CFG_EVENT_EN 1u // TencentOS tiny 事件模块功能宏 +#define TOS_CFG_EVENT_EN 1u // TencentOS tiny 浜嬩欢妯″潡鍔熻兘瀹 -#define TOS_CFG_MMHEAP_EN 1u // 配置TencentOS tiny是否开启动态内存模块 +#define TOS_CFG_MMHEAP_EN 1u // 閰嶇疆TencentOS tiny鏄惁寮鍚姩鎬佸唴瀛樻ā鍧 -#define TOS_CFG_MMHEAP_POOL_SIZE 8192 // 配置TencentOS tiny动态内存池大小 +#define TOS_CFG_MMHEAP_POOL_SIZE 8192 // 閰嶇疆TencentOS tiny鍔ㄦ佸唴瀛樻睜澶у皬 -#define TOS_CFG_MUTEX_EN 1u // 配置TencentOS tiny是否开启互斥锁模块 +#define TOS_CFG_MUTEX_EN 1u // 閰嶇疆TencentOS tiny鏄惁寮鍚簰鏂ラ攣妯″潡 -#define TOS_CFG_QUEUE_EN 1u // 配置TencentOS tiny是否开启队列模块 +#define TOS_CFG_QUEUE_EN 1u // 閰嶇疆TencentOS tiny鏄惁寮鍚槦鍒楁ā鍧 -#define TOS_CFG_TIMER_EN 0u // 配置TencentOS tiny是否开启软件定时器模块 +#define TOS_CFG_TIMER_EN 0u // 閰嶇疆TencentOS tiny鏄惁寮鍚蒋浠跺畾鏃跺櫒妯″潡 -#define TOS_CFG_SEM_EN 1u // 配置TencentOS tiny是否开启信号量模块 +#define TOS_CFG_SEM_EN 1u // 閰嶇疆TencentOS tiny鏄惁寮鍚俊鍙烽噺妯″潡 #if (TOS_CFG_QUEUE_EN > 0u) #define TOS_CFG_MSG_EN 1u @@ -29,15 +29,15 @@ #define TOS_CFG_MSG_EN 0u #endif -#define TOS_CFG_MSG_POOL_SIZE 10u // 配置TencentOS tiny消息队列大小 +#define TOS_CFG_MSG_POOL_SIZE 10u // 閰嶇疆TencentOS tiny娑堟伅闃熷垪澶у皬 -#define TOS_CFG_IDLE_TASK_STK_SIZE 512u // 配置TencentOS tiny空闲任务栈大小 +#define TOS_CFG_IDLE_TASK_STK_SIZE 512u // 閰嶇疆TencentOS tiny绌洪棽浠诲姟鏍堝ぇ灏 -#define TOS_CFG_CPU_TICK_PER_SECOND 1000u // 配置TencentOS tiny的tick频率 +#define TOS_CFG_CPU_TICK_PER_SECOND 4000u // 閰嶇疆TencentOS tiny鐨則ick棰戠巼 -#define TOS_CFG_CPU_CLOCK 108000000 // 配置TencentOS tiny CPU频率 +#define TOS_CFG_CPU_CLOCK 108000000 // 閰嶇疆TencentOS tiny CPU棰戠巼 -#define TOS_CFG_TIMER_AS_PROC 1u // 配置是否将TIMER配置成函数模式 +#define TOS_CFG_TIMER_AS_PROC 1u // 閰嶇疆鏄惁灏員IMER閰嶇疆鎴愬嚱鏁版ā寮 #define TOS_CFG_VFS_EN 1u diff --git a/board/GD32VF103C_START/eclipse/hello_world/.cproject b/board/GD32VF103C_START/eclipse/hello_world/.cproject index 9324d982..10165b10 100644 --- a/board/GD32VF103C_START/eclipse/hello_world/.cproject +++ b/board/GD32VF103C_START/eclipse/hello_world/.cproject @@ -1,208 +1,430 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/board/GD32VF103C_START/eclipse/hello_world/.project b/board/GD32VF103C_START/eclipse/hello_world/.project index e791c989..345bb056 100644 --- a/board/GD32VF103C_START/eclipse/hello_world/.project +++ b/board/GD32VF103C_START/eclipse/hello_world/.project @@ -32,7 +32,7 @@ GD32VF103_Firmware_Library 2 - Z:/workspace/TencentOS-tiny/platform/vendor_bsp/gd/GD32VF103_Firmware_Library + $%7BPARENT-4-PROJECT_LOC%7D/platform/vendor_bsp/gd/GD32VF103_Firmware_Library TencentOS_tiny @@ -42,7 +42,7 @@ Application/tos_config.h 1 - Z:/workspace/TencentOS-tiny/board/GD32VF103C_START/TOS_CONFIG/tos_config.h + $%7BPARENT-2-PROJECT_LOC%7D/TOS_CONFIG/tos_config.h TencentOS_tiny/arch @@ -52,12 +52,12 @@ TencentOS_tiny/kernel 2 - Z:/workspace/TencentOS-tiny/kernel + $%7BPARENT-4-PROJECT_LOC%7D/kernel TencentOS_tiny/arch/risc-v 2 - Z:/workspace/TencentOS-tiny/arch/risc-v + $%7BPARENT-4-PROJECT_LOC%7D/arch/risc-v diff --git a/board/GD32VF103C_START/eclipse/hello_world/.settings/ilg.gnumcueclipse.debug.gdbjtag.openocd.prefs b/board/GD32VF103C_START/eclipse/hello_world/.settings/ilg.gnumcueclipse.debug.gdbjtag.openocd.prefs index 2fcf1572..5ce8285b 100644 --- a/board/GD32VF103C_START/eclipse/hello_world/.settings/ilg.gnumcueclipse.debug.gdbjtag.openocd.prefs +++ b/board/GD32VF103C_START/eclipse/hello_world/.settings/ilg.gnumcueclipse.debug.gdbjtag.openocd.prefs @@ -1,2 +1,3 @@ eclipse.preferences.version=1 -install.folder=C\:\\ToolChain\\OpenOCD\\0.10.0-12-20190722-0746\\bin +executable.name=openocd +install.folder=/Users/ace/sys/gnu-mcu-eclipse/openocd/self/bin diff --git a/board/GD32VF103C_START/eclipse/hello_world/.settings/ilg.gnumcueclipse.managedbuild.cross.prefs b/board/GD32VF103C_START/eclipse/hello_world/.settings/ilg.gnumcueclipse.managedbuild.cross.prefs deleted file mode 100644 index ab137a2c..00000000 --- a/board/GD32VF103C_START/eclipse/hello_world/.settings/ilg.gnumcueclipse.managedbuild.cross.prefs +++ /dev/null @@ -1,2 +0,0 @@ -buildTools.path=C\:\\ToolChain\\Build Tools\\2.10-20180103-1919\\bin -eclipse.preferences.version=1 diff --git a/board/GD32VF103C_START/eclipse/hello_world/.settings/ilg.gnumcueclipse.managedbuild.cross.riscv.prefs b/board/GD32VF103C_START/eclipse/hello_world/.settings/ilg.gnumcueclipse.managedbuild.cross.riscv.prefs index 4899e031..d5692f5e 100644 --- a/board/GD32VF103C_START/eclipse/hello_world/.settings/ilg.gnumcueclipse.managedbuild.cross.riscv.prefs +++ b/board/GD32VF103C_START/eclipse/hello_world/.settings/ilg.gnumcueclipse.managedbuild.cross.riscv.prefs @@ -1,2 +1,2 @@ eclipse.preferences.version=1 -toolchain.path.512258282=C\:\\ToolChain\\RISC-V Embedded GCC\\8.2.0-2.2-20190521-0004\\bin +toolchain.path.512258282=/Users/ace/sys/gnu-mcu-eclipse/riscv-none-gcc/8.2.0-2.2-20190521-0004/bin diff --git a/board/GD32VF103C_START/eclipse/hello_world/.settings/language.settings.xml b/board/GD32VF103C_START/eclipse/hello_world/.settings/language.settings.xml index 349c7da5..17a290e7 100644 --- a/board/GD32VF103C_START/eclipse/hello_world/.settings/language.settings.xml +++ b/board/GD32VF103C_START/eclipse/hello_world/.settings/language.settings.xml @@ -1,25 +1,48 @@ - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/board/GD32VF103C_START/eclipse/hello_world/.settings/org.eclipse.ltk.core.refactoring.prefs b/board/GD32VF103C_START/eclipse/hello_world/.settings/org.eclipse.ltk.core.refactoring.prefs new file mode 100644 index 00000000..b196c64a --- /dev/null +++ b/board/GD32VF103C_START/eclipse/hello_world/.settings/org.eclipse.ltk.core.refactoring.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false diff --git a/board/GD32VF103C_START/eclipse/hello_world/link.lds b/board/GD32VF103C_START/eclipse/hello_world/link.lds new file mode 100644 index 00000000..1c32e640 --- /dev/null +++ b/board/GD32VF103C_START/eclipse/hello_world/link.lds @@ -0,0 +1,175 @@ +OUTPUT_ARCH( "riscv" ) + +ENTRY( _start ) + +MEMORY +{ + /* Run in FLASH */ + flash (rxai!w) : ORIGIN = 0x08000000, LENGTH = 128k + ram (wxa!ri) : ORIGIN = 0x20000000, LENGTH = 32K + + /* Run in RAM */ +/* flash (rxai!w) : ORIGIN = 0x20000000, LENGTH = 24k + ram (wxa!ri) : ORIGIN = 0x20006000, LENGTH = 8K +*/ +} + + +SECTIONS +{ + __stack_size = DEFINED(__stack_size) ? __stack_size : 2K; + + + .init : + { + KEEP (*(SORT_NONE(.init))) + } >flash AT>flash + + .ilalign : + { + . = ALIGN(4); + PROVIDE( _ilm_lma = . ); + } >flash AT>flash + + .ialign : + { + PROVIDE( _ilm = . ); + } >flash AT>flash + + .text : + { + *(.rodata .rodata.*) + *(.text.unlikely .text.unlikely.*) + *(.text.startup .text.startup.*) + *(.text .text.*) + *(.gnu.linkonce.t.*) + } >flash AT>flash + + .fini : + { + KEEP (*(SORT_NONE(.fini))) + } >flash AT>flash + + . = ALIGN(4); + + PROVIDE (__etext = .); + PROVIDE (_etext = .);/*0x80022c8*/ + PROVIDE (etext = .);/*0x80022c8*/ + PROVIDE( _eilm = . ); + + .preinit_array : + { + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP (*(.preinit_array)) + PROVIDE_HIDDEN (__preinit_array_end = .); + } >flash AT>flash + + .init_array : + { + PROVIDE_HIDDEN (__init_array_start = .); + KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*))) + KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors)) + PROVIDE_HIDDEN (__init_array_end = .); + } >flash AT>flash + + .fini_array : + { + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*))) + KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors)) + PROVIDE_HIDDEN (__fini_array_end = .); + } >flash AT>flash + + .ctors : + { + /* gcc uses crtbegin.o to find the start of + the constructors, so we make sure it is + first. Because this is a wildcard, it + doesn't matter if the user does not + actually link against crtbegin.o; the + linker won't look for a file to match a + wildcard. The wildcard also means that it + doesn't matter which directory crtbegin.o + is in. */ + KEEP (*crtbegin.o(.ctors)) + KEEP (*crtbegin?.o(.ctors)) + /* We don't want to include the .ctor section from + the crtend.o file until after the sorted ctors. + The .ctor section from the crtend file contains the + end of ctors marker and it must be last */ + KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors)) + KEEP (*(SORT(.ctors.*))) + KEEP (*(.ctors)) + } >flash AT>flash + + .dtors : + { + KEEP (*crtbegin.o(.dtors)) + KEEP (*crtbegin?.o(.dtors)) + KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors)) + KEEP (*(SORT(.dtors.*))) + KEEP (*(.dtors)) + } >flash AT>flash + + . = ALIGN(4); + PROVIDE( _eilm = . ); + + .lalign : + { + . = ALIGN(4); + PROVIDE( _data_lma = . ); + } >flash AT>flash + + .dalign : + { + . = ALIGN(4); + PROVIDE( _data = . ); + } >ram AT>flash + + + .data : + { + *(.rdata) + + *(.gnu.linkonce.r.*) + *(.data .data.*) + *(.gnu.linkonce.d.*) + . = ALIGN(8); + PROVIDE( __global_pointer$ = . + 0x800); + *(.sdata .sdata.*) + *(.gnu.linkonce.s.*) + . = ALIGN(8); + *(.srodata.cst16) + *(.srodata.cst8) + *(.srodata.cst4) + *(.srodata.cst2) + *(.srodata .srodata.*) + } >ram AT>flash + + . = ALIGN(4); + PROVIDE( _edata = . ); + PROVIDE( edata = . ); + + PROVIDE( _fbss = . ); /*0X200052A0 0X200002A0*/ + PROVIDE( __bss_start = . ); + .bss : + { + *(.sbss*) + *(.gnu.linkonce.sb.*) + *(.bss .bss.*) + *(.gnu.linkonce.b.*) + *(COMMON) + . = ALIGN(4); + } >ram AT>ram + + . = ALIGN(8); + PROVIDE( _end = . ); /*0X2000,0340*/ + PROVIDE( end = . ); + + .stack ORIGIN(ram) + LENGTH(ram) - __stack_size : + { + PROVIDE( _heap_end = . ); + . = __stack_size; + PROVIDE( _sp = . ); + } >ram AT>ram +} diff --git a/board/GD32VF103C_START/eclipse/hello_world/main.c b/board/GD32VF103C_START/eclipse/hello_world/main.c index 29d3aa94..afba9061 100644 --- a/board/GD32VF103C_START/eclipse/hello_world/main.c +++ b/board/GD32VF103C_START/eclipse/hello_world/main.c @@ -16,7 +16,7 @@ void delay_1ms(uint32_t count) }while(delta_mtime <(SystemCoreClock/4000.0 *count)); } -#define TASK_SIZE 512 +#define TASK_SIZE 1024 k_task_t k_task_task1; k_task_t k_task_task2; uint8_t k_task1_stk[TASK_SIZE]; @@ -59,12 +59,14 @@ void main(void) { gpio_init(GPIOA, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_7); gpio_bit_reset(GPIOA, GPIO_PIN_7); - tos_knl_init(); - tos_task_create(&k_task_task1, "task1", task1, NULL, 3, k_task1_stk, TASK_SIZE, 0); - tos_task_create(&k_task_task2, "task2", task2, NULL, 3, k_task2_stk, TASK_SIZE, 0); + eclic_irq_enable(CLIC_INT_TMR, 0, 0); + tos_task_create(&k_task_task1, "task1", task1, NULL, 3, k_task1_stk, TASK_SIZE, 0); + //tos_task_create(&k_task_task2, "task2", task2, NULL, 3, k_task2_stk, TASK_SIZE, 0); + + //eclic_irq_enable(CLIC_INT_TMR, 0, 0); tos_knl_start(); diff --git a/board/GD32VF103C_START/eclipse/hello_world/openocd_gdlink.cfg b/board/GD32VF103C_START/eclipse/hello_world/openocd_gdlink.cfg index 8e845bca..aaba1624 100644 --- a/board/GD32VF103C_START/eclipse/hello_world/openocd_gdlink.cfg +++ b/board/GD32VF103C_START/eclipse/hello_world/openocd_gdlink.cfg @@ -8,7 +8,7 @@ interface cmsis-dap transport select jtag -autoexit true +#autoexit true set _CHIPNAME riscv jtag newtap $_CHIPNAME cpu -irlen 5 -expected-id 0x1000563d @@ -37,8 +37,7 @@ if { [info exists FLASH_SIZE] } { set _FLASHNAME $_CHIPNAME.flash flash bank $_FLASHNAME gd32vf103 0x08000000 0 0 0 $_TARGETNAME -#flash bank $_FLASHNAME stm32f103 0x08000000 0 0 0 $_TARGETNAME -riscv set_reset_timeout_sec 10 +riscv set_reset_timeout_sec 1 init halt diff --git a/board/QEMU_Spike/GCC/demo/start.S b/board/QEMU_Spike/GCC/demo/start.S index 727ce1d1..229f15bb 100644 --- a/board/QEMU_Spike/GCC/demo/start.S +++ b/board/QEMU_Spike/GCC/demo/start.S @@ -6,6 +6,9 @@ .globl _start .type _start,@function _start: + lui s0, 0x20000 + lw a0, 148(s0) + csrc mstatus, MSTATUS_MIE csrw mie, 0 diff --git a/board/QEMU_Spike/eclipse/demo/.settings/language.settings.xml b/board/QEMU_Spike/eclipse/demo/.settings/language.settings.xml index 988663db..9201e03a 100644 --- a/board/QEMU_Spike/eclipse/demo/.settings/language.settings.xml +++ b/board/QEMU_Spike/eclipse/demo/.settings/language.settings.xml @@ -11,7 +11,7 @@ - + diff --git a/kernel/core/tos_sched.c b/kernel/core/tos_sched.c index 9ab93b2b..0c57c697 100644 --- a/kernel/core/tos_sched.c +++ b/kernel/core/tos_sched.c @@ -61,7 +61,8 @@ __KERNEL__ k_task_t *readyqueue_highest_ready_task_get(void) k_list_t *task_list; task_list = &k_rdyq.task_list_head[k_rdyq.highest_prio]; - return TOS_LIST_FIRST_ENTRY(task_list, k_task_t, pend_list); + k_task_t *fuck = TOS_LIST_FIRST_ENTRY(task_list, k_task_t, pend_list); + return fuck; } __KERNEL__ void readyqueue_init(void)