From ec060312b7fe73859227eb17b01eb6362cdfb136 Mon Sep 17 00:00:00 2001 From: greedyhao Date: Fri, 11 Dec 2020 18:33:09 +0800 Subject: [bluetrum] add --dist --- bsp/bluetrum/ab32vg1-ab-prougen/.gitignore | 1 + bsp/bluetrum/ab32vg1-ab-prougen/README.md | 2 +- bsp/bluetrum/ab32vg1-ab-prougen/SConstruct | 2 +- bsp/bluetrum/ab32vg1-ab-prougen/cconfig.h | 11 +- bsp/bluetrum/ab32vg1-ab-prougen/rtconfig.py | 9 +- bsp/bluetrum/libcpu/SConscript | 23 --- bsp/bluetrum/libcpu/context_gcc.S | 222 ---------------------------- bsp/bluetrum/libcpu/cpu/SConscript | 23 +++ bsp/bluetrum/libcpu/cpu/context_gcc.S | 222 ++++++++++++++++++++++++++++ bsp/bluetrum/libcpu/cpu/cpuport.c | 66 +++++++++ bsp/bluetrum/libcpu/cpu/interrupt.c | 71 +++++++++ bsp/bluetrum/libcpu/cpuport.c | 66 --------- bsp/bluetrum/libcpu/interrupt.c | 71 --------- bsp/bluetrum/tools/sdk_dist.py | 24 +++ 14 files changed, 427 insertions(+), 386 deletions(-) delete mode 100644 bsp/bluetrum/libcpu/SConscript delete mode 100644 bsp/bluetrum/libcpu/context_gcc.S create mode 100644 bsp/bluetrum/libcpu/cpu/SConscript create mode 100644 bsp/bluetrum/libcpu/cpu/context_gcc.S create mode 100644 bsp/bluetrum/libcpu/cpu/cpuport.c create mode 100644 bsp/bluetrum/libcpu/cpu/interrupt.c delete mode 100644 bsp/bluetrum/libcpu/cpuport.c delete mode 100644 bsp/bluetrum/libcpu/interrupt.c create mode 100644 bsp/bluetrum/tools/sdk_dist.py diff --git a/bsp/bluetrum/ab32vg1-ab-prougen/.gitignore b/bsp/bluetrum/ab32vg1-ab-prougen/.gitignore index 00b6f02b70..37749b0928 100644 --- a/bsp/bluetrum/ab32vg1-ab-prougen/.gitignore +++ b/bsp/bluetrum/ab32vg1-ab-prougen/.gitignore @@ -7,3 +7,4 @@ *.old build +dist diff --git a/bsp/bluetrum/ab32vg1-ab-prougen/README.md b/bsp/bluetrum/ab32vg1-ab-prougen/README.md index 35f08e20bb..d761cfce45 100644 --- a/bsp/bluetrum/ab32vg1-ab-prougen/README.md +++ b/bsp/bluetrum/ab32vg1-ab-prougen/README.md @@ -102,7 +102,7 @@ msh > ## 注意事项 -目前的 `cconfig.h` 的生成脚本对 riscv 的工具链识别有问题,可能需要在 `cconfig.h` 中手动添加以下配置 +编译报错的时候,如果出现重复定义的报错,可能需要在 `cconfig.h` 中手动添加以下配置 ``` #define HAVE_SIGEVENT 1 diff --git a/bsp/bluetrum/ab32vg1-ab-prougen/SConstruct b/bsp/bluetrum/ab32vg1-ab-prougen/SConstruct index 8afae966f8..697488940c 100644 --- a/bsp/bluetrum/ab32vg1-ab-prougen/SConstruct +++ b/bsp/bluetrum/ab32vg1-ab-prougen/SConstruct @@ -55,7 +55,7 @@ objs.extend(SConscript(os.path.join(libraries_path_prefix, bsp_library_type, 'SC objs.extend(SConscript(os.path.join(libraries_path_prefix, 'hal_drivers', 'SConscript'))) # include drivers -objs.extend(SConscript(os.path.join(libcpu_path_prefix, 'SConscript'))) +objs.extend(SConscript(os.path.join(libcpu_path_prefix, 'cpu', 'SConscript'))) # make a building DoBuilding(TARGET, objs) diff --git a/bsp/bluetrum/ab32vg1-ab-prougen/cconfig.h b/bsp/bluetrum/ab32vg1-ab-prougen/cconfig.h index 9c81dd397d..074cbd3397 100644 --- a/bsp/bluetrum/ab32vg1-ab-prougen/cconfig.h +++ b/bsp/bluetrum/ab32vg1-ab-prougen/cconfig.h @@ -3,10 +3,19 @@ /* Automatically generated file; DO NOT EDIT. */ /* compiler configure file for RT-Thread in GCC*/ +#define HAVE_NEWLIB_H 1 +#define LIBC_VERSION "newlib 3.2.0" -#define STDC "1989" +#define HAVE_SYS_SIGNAL_H 1 +#define HAVE_SYS_SELECT_H 1 +#define HAVE_PTHREAD_H 1 + +#define HAVE_FDSET 1 +#define HAVE_SIGACTION 1 #define HAVE_SIGEVENT 1 #define HAVE_SIGINFO 1 #define HAVE_SIGVAL 1 +#define GCC_VERSION_STR "10.1.0" +#define STDC "2011" #endif diff --git a/bsp/bluetrum/ab32vg1-ab-prougen/rtconfig.py b/bsp/bluetrum/ab32vg1-ab-prougen/rtconfig.py index b782e0d2c2..300d845047 100644 --- a/bsp/bluetrum/ab32vg1-ab-prougen/rtconfig.py +++ b/bsp/bluetrum/ab32vg1-ab-prougen/rtconfig.py @@ -57,4 +57,11 @@ if PLATFORM == 'gcc': DUMP_ACTION = OBJDUMP + ' -D -S $TARGET > rtt.asm\n' POST_ACTION = OBJCPY + ' -O binary $TARGET rtthread.bin\n' + SIZE + ' $TARGET \n' -POST_ACTION += './riscv32-elf-xmaker -b rtthread.xm\n' \ No newline at end of file +POST_ACTION += './riscv32-elf-xmaker -b rtthread.xm\n' + +def dist_handle(BSP_ROOT, dist_dir): + import sys + cwd_path = os.getcwd() + sys.path.append(os.path.join(os.path.dirname(BSP_ROOT), 'tools')) + from sdk_dist import dist_do_building + dist_do_building(BSP_ROOT, dist_dir) diff --git a/bsp/bluetrum/libcpu/SConscript b/bsp/bluetrum/libcpu/SConscript deleted file mode 100644 index 9ff30a796b..0000000000 --- a/bsp/bluetrum/libcpu/SConscript +++ /dev/null @@ -1,23 +0,0 @@ -# RT-Thread building script for component - -from building import * - -Import('rtconfig') - -cwd = GetCurrentDir() -src = Glob('*.c') + Glob('*.cpp') -CPPPATH = [cwd] - -if rtconfig.PLATFORM == 'armcc': - src += Glob('*_rvds.S') - -if rtconfig.PLATFORM == 'gcc': - src += Glob('*_init.S') - src += Glob('*_gcc.S') - -if rtconfig.PLATFORM == 'iar': - src += Glob('*_iar.S') - -group = DefineGroup('cpu', src, depend = [''], CPPPATH = CPPPATH) - -Return('group') diff --git a/bsp/bluetrum/libcpu/context_gcc.S b/bsp/bluetrum/libcpu/context_gcc.S deleted file mode 100644 index 9139657eaa..0000000000 --- a/bsp/bluetrum/libcpu/context_gcc.S +++ /dev/null @@ -1,222 +0,0 @@ -/* - * Copyright (c) 2020-2020, Bluetrum Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2020/11/18 greedyhao The first version. - */ - -#include "ab32vg1.h" - -.global rt_interrupt_from_thread -.global rt_interrupt_to_thread -.global rt_cur_thread_sp -.global rt_switch_flag -.global rt_interrupt_nest - -/* - * rt_base_t rt_hw_interrupt_disable(); - * a0 -> return - */ - .global rt_hw_interrupt_disable -rt_hw_interrupt_disable: - lw a5, PICCON(zero) - mv a0, a5 - andi a5, a5, -2 - sw a5, PICCON(zero) - ret - -/* - * void rt_hw_interrupt_enable(rt_base_t level); - * a0 -> level - */ - .global rt_hw_interrupt_enable -rt_hw_interrupt_enable: - andi a0, a0, 1 - beqz a0,enable_int_ret - lw a5, PICCON(zero) - ori a5, a5, 1 - sw a5,PICCON(zero) -enable_int_ret: - ret - -/* Macro for saving task context */ -.macro save_context - addi sp, sp, -120 - - /* Save Context */ - sw x1, 0(sp) - sw x4, 4(sp) - sw x5, 8(sp) - sw x6, 12(sp) - sw x7, 16(sp) - sw x8, 20(sp) - sw x9, 24(sp) - sw x10, 28(sp) - sw x11, 32(sp) - sw x12, 36(sp) - sw x13, 40(sp) - sw x14, 44(sp) - sw x15, 48(sp) - sw x16, 52(sp) - sw x17, 56(sp) - sw x18, 60(sp) - sw x19, 64(sp) - sw x20, 68(sp) - sw x21, 72(sp) - sw x22, 76(sp) - sw x23, 80(sp) - sw x24, 84(sp) - sw x25, 88(sp) - sw x26, 92(sp) - sw x27, 96(sp) - sw x28, 100(sp) - sw x29, 104(sp) - sw x30, 108(sp) - sw x31, 112(sp) - - lw a5, EPC(zero) //Saves current program counter (EPC) as task program counter - sw a5, 116(sp) - - sw sp, rt_cur_thread_sp, a4 //store sp in preempted tasks tcb - .endm - - -/* Macro for restoring task context */ -.macro restore_context - - la a5, rt_cur_thread_sp - lw sp, 0(a5) //get new task stack pointer - - /* Load task program counter EPC*/ - lw a5, 116(sp) - sw a5, EPC(zero) - - /* Restore registers, - Skip global pointer because that does not change */ - lw x1, 0(sp) - lw x4, 4(sp) - lw x5, 8(sp) - lw x6, 12(sp) - lw x7, 16(sp) - lw x8, 20(sp) - lw x9, 24(sp) - lw x10, 28(sp) - lw x11, 32(sp) - lw x12, 36(sp) - lw x13, 40(sp) - lw x14, 44(sp) - lw x15, 48(sp) - lw x16, 52(sp) - lw x17, 56(sp) - lw x18, 60(sp) - lw x19, 64(sp) - lw x20, 68(sp) - lw x21, 72(sp) - lw x22, 76(sp) - lw x23, 80(sp) - lw x24, 84(sp) - lw x25, 88(sp) - lw x26, 92(sp) - lw x27, 96(sp) - lw x28, 100(sp) - lw x29, 104(sp) - lw x30, 108(sp) - lw x31, 112(sp) - - addi sp, sp, 120 - mret - .endm - -/* - * void rt_hw_context_switch_to(rt_uint32 to); - * r0 --> to - */ - .globl rt_hw_context_switch_to -rt_hw_context_switch_to: - sw zero, rt_interrupt_from_thread, a4 /*set from thread to 0*/ - sw a0, rt_interrupt_to_thread, a4 /*set rt_interrupt_to_thread*/ - - sb zero, rt_interrupt_nest, a4 /*rt_interrupt_nest = 0*/ - - li a5, 1 - sw a5, rt_switch_flag, a4 // rt_switch_flag = 1; - - SWINT /*kick soft interrupt*/ - lw a5, PICCON(zero) /*enable interrupt*/ - ori a5, a5, 1 - sw a5, PICCON(zero) - ret - -/* - * void rt_hw_context_switch(rt_uint32 from, rt_uint32 to); - * a0 --> from - * a1 --> to - */ - .globl rt_hw_context_switch -rt_hw_context_switch: - sw a0, rt_interrupt_from_thread, a4 /*set rt_interrupt_from_thread*/ - sw a1, rt_interrupt_to_thread, a4 /*set rt_interrupt_to_thread*/ - li a5, 1 - sw a5, rt_switch_flag, a4 // rt_switch_flag = 1; - SWINT /*kick soft interrupt*/ - ret - - /* - * void rt_switch_to_thread(void); - * r0 --> to - */ - .globl rt_switch_to_thread -rt_switch_to_thread: - lw a0, rt_interrupt_from_thread - lw a5, rt_cur_thread_sp - sw a5, 0(a0) - - lw a0, rt_interrupt_to_thread - lw a5, 0(a0) - sw a5, rt_cur_thread_sp, a4 - ret - -/* - * void rt_hw_context_switch_interrupt(rt_uint32 from, rt_uint32 to); - * a0 --> from - * a1 --> to - */ - .global rt_hw_context_switch_interrupt -rt_hw_context_switch_interrupt: - lw a5, rt_switch_flag - bnez a5, _reswitch - li a5, 0x01 - sw a5, rt_switch_flag, a4 - sw a0, rt_interrupt_from_thread, a4 /*set rt_interrupt_from_thread*/ -_reswitch: - sw a1, rt_interrupt_to_thread, a4 /*set rt_interrupt_to_thread*/ - ret - - //软中断服务 - .global rt_soft_isr -rt_soft_isr: - li a5, 0x4 // PICPND = BIT(IRQ_SW_VECTOR); 清软中断Pending - sw a5, PICPND(zero) - ret - - .globl low_prio_irq -low_prio_irq: - save_context - li a5, 1 - sb a5, rt_interrupt_nest, a4 // rt_interrupt_nest = 1; - - lw a5, cpu_irq_comm_hook - jalr a5 - - lw a5, rt_switch_flag - beqz a5, _low_prio_irq_exit // if (rt_switch_flag) - jal rt_switch_to_thread - sw zero, rt_switch_flag, a4 // rt_switch_flag = 0; - - _low_prio_irq_exit: - sb zero, rt_interrupt_nest, a4 // rt_interrupt_nest = 0; - restore_context - diff --git a/bsp/bluetrum/libcpu/cpu/SConscript b/bsp/bluetrum/libcpu/cpu/SConscript new file mode 100644 index 0000000000..9ff30a796b --- /dev/null +++ b/bsp/bluetrum/libcpu/cpu/SConscript @@ -0,0 +1,23 @@ +# RT-Thread building script for component + +from building import * + +Import('rtconfig') + +cwd = GetCurrentDir() +src = Glob('*.c') + Glob('*.cpp') +CPPPATH = [cwd] + +if rtconfig.PLATFORM == 'armcc': + src += Glob('*_rvds.S') + +if rtconfig.PLATFORM == 'gcc': + src += Glob('*_init.S') + src += Glob('*_gcc.S') + +if rtconfig.PLATFORM == 'iar': + src += Glob('*_iar.S') + +group = DefineGroup('cpu', src, depend = [''], CPPPATH = CPPPATH) + +Return('group') diff --git a/bsp/bluetrum/libcpu/cpu/context_gcc.S b/bsp/bluetrum/libcpu/cpu/context_gcc.S new file mode 100644 index 0000000000..9139657eaa --- /dev/null +++ b/bsp/bluetrum/libcpu/cpu/context_gcc.S @@ -0,0 +1,222 @@ +/* + * Copyright (c) 2020-2020, Bluetrum Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2020/11/18 greedyhao The first version. + */ + +#include "ab32vg1.h" + +.global rt_interrupt_from_thread +.global rt_interrupt_to_thread +.global rt_cur_thread_sp +.global rt_switch_flag +.global rt_interrupt_nest + +/* + * rt_base_t rt_hw_interrupt_disable(); + * a0 -> return + */ + .global rt_hw_interrupt_disable +rt_hw_interrupt_disable: + lw a5, PICCON(zero) + mv a0, a5 + andi a5, a5, -2 + sw a5, PICCON(zero) + ret + +/* + * void rt_hw_interrupt_enable(rt_base_t level); + * a0 -> level + */ + .global rt_hw_interrupt_enable +rt_hw_interrupt_enable: + andi a0, a0, 1 + beqz a0,enable_int_ret + lw a5, PICCON(zero) + ori a5, a5, 1 + sw a5,PICCON(zero) +enable_int_ret: + ret + +/* Macro for saving task context */ +.macro save_context + addi sp, sp, -120 + + /* Save Context */ + sw x1, 0(sp) + sw x4, 4(sp) + sw x5, 8(sp) + sw x6, 12(sp) + sw x7, 16(sp) + sw x8, 20(sp) + sw x9, 24(sp) + sw x10, 28(sp) + sw x11, 32(sp) + sw x12, 36(sp) + sw x13, 40(sp) + sw x14, 44(sp) + sw x15, 48(sp) + sw x16, 52(sp) + sw x17, 56(sp) + sw x18, 60(sp) + sw x19, 64(sp) + sw x20, 68(sp) + sw x21, 72(sp) + sw x22, 76(sp) + sw x23, 80(sp) + sw x24, 84(sp) + sw x25, 88(sp) + sw x26, 92(sp) + sw x27, 96(sp) + sw x28, 100(sp) + sw x29, 104(sp) + sw x30, 108(sp) + sw x31, 112(sp) + + lw a5, EPC(zero) //Saves current program counter (EPC) as task program counter + sw a5, 116(sp) + + sw sp, rt_cur_thread_sp, a4 //store sp in preempted tasks tcb + .endm + + +/* Macro for restoring task context */ +.macro restore_context + + la a5, rt_cur_thread_sp + lw sp, 0(a5) //get new task stack pointer + + /* Load task program counter EPC*/ + lw a5, 116(sp) + sw a5, EPC(zero) + + /* Restore registers, + Skip global pointer because that does not change */ + lw x1, 0(sp) + lw x4, 4(sp) + lw x5, 8(sp) + lw x6, 12(sp) + lw x7, 16(sp) + lw x8, 20(sp) + lw x9, 24(sp) + lw x10, 28(sp) + lw x11, 32(sp) + lw x12, 36(sp) + lw x13, 40(sp) + lw x14, 44(sp) + lw x15, 48(sp) + lw x16, 52(sp) + lw x17, 56(sp) + lw x18, 60(sp) + lw x19, 64(sp) + lw x20, 68(sp) + lw x21, 72(sp) + lw x22, 76(sp) + lw x23, 80(sp) + lw x24, 84(sp) + lw x25, 88(sp) + lw x26, 92(sp) + lw x27, 96(sp) + lw x28, 100(sp) + lw x29, 104(sp) + lw x30, 108(sp) + lw x31, 112(sp) + + addi sp, sp, 120 + mret + .endm + +/* + * void rt_hw_context_switch_to(rt_uint32 to); + * r0 --> to + */ + .globl rt_hw_context_switch_to +rt_hw_context_switch_to: + sw zero, rt_interrupt_from_thread, a4 /*set from thread to 0*/ + sw a0, rt_interrupt_to_thread, a4 /*set rt_interrupt_to_thread*/ + + sb zero, rt_interrupt_nest, a4 /*rt_interrupt_nest = 0*/ + + li a5, 1 + sw a5, rt_switch_flag, a4 // rt_switch_flag = 1; + + SWINT /*kick soft interrupt*/ + lw a5, PICCON(zero) /*enable interrupt*/ + ori a5, a5, 1 + sw a5, PICCON(zero) + ret + +/* + * void rt_hw_context_switch(rt_uint32 from, rt_uint32 to); + * a0 --> from + * a1 --> to + */ + .globl rt_hw_context_switch +rt_hw_context_switch: + sw a0, rt_interrupt_from_thread, a4 /*set rt_interrupt_from_thread*/ + sw a1, rt_interrupt_to_thread, a4 /*set rt_interrupt_to_thread*/ + li a5, 1 + sw a5, rt_switch_flag, a4 // rt_switch_flag = 1; + SWINT /*kick soft interrupt*/ + ret + + /* + * void rt_switch_to_thread(void); + * r0 --> to + */ + .globl rt_switch_to_thread +rt_switch_to_thread: + lw a0, rt_interrupt_from_thread + lw a5, rt_cur_thread_sp + sw a5, 0(a0) + + lw a0, rt_interrupt_to_thread + lw a5, 0(a0) + sw a5, rt_cur_thread_sp, a4 + ret + +/* + * void rt_hw_context_switch_interrupt(rt_uint32 from, rt_uint32 to); + * a0 --> from + * a1 --> to + */ + .global rt_hw_context_switch_interrupt +rt_hw_context_switch_interrupt: + lw a5, rt_switch_flag + bnez a5, _reswitch + li a5, 0x01 + sw a5, rt_switch_flag, a4 + sw a0, rt_interrupt_from_thread, a4 /*set rt_interrupt_from_thread*/ +_reswitch: + sw a1, rt_interrupt_to_thread, a4 /*set rt_interrupt_to_thread*/ + ret + + //软中断服务 + .global rt_soft_isr +rt_soft_isr: + li a5, 0x4 // PICPND = BIT(IRQ_SW_VECTOR); 清软中断Pending + sw a5, PICPND(zero) + ret + + .globl low_prio_irq +low_prio_irq: + save_context + li a5, 1 + sb a5, rt_interrupt_nest, a4 // rt_interrupt_nest = 1; + + lw a5, cpu_irq_comm_hook + jalr a5 + + lw a5, rt_switch_flag + beqz a5, _low_prio_irq_exit // if (rt_switch_flag) + jal rt_switch_to_thread + sw zero, rt_switch_flag, a4 // rt_switch_flag = 0; + + _low_prio_irq_exit: + sb zero, rt_interrupt_nest, a4 // rt_interrupt_nest = 0; + restore_context + diff --git a/bsp/bluetrum/libcpu/cpu/cpuport.c b/bsp/bluetrum/libcpu/cpu/cpuport.c new file mode 100644 index 0000000000..576401421a --- /dev/null +++ b/bsp/bluetrum/libcpu/cpu/cpuport.c @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2020-2020, Bluetrum Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2020/11/18 greedyhao Bluetrum RISC-V porting code. + */ + +#include +#include + +volatile rt_ubase_t rt_interrupt_from_thread = 0; +volatile rt_ubase_t rt_interrupt_to_thread = 0; +volatile rt_uint32_t rt_thread_switch_interrupt_flag = 0; +volatile rt_uint32_t rt_switch_flag = 0; +rt_uint32_t rt_cur_thread_sp = 0; + +/** + * This function will initialize thread stack + * + * @param tentry the entry of thread + * @param parameter the parameter of entry + * @param stack_addr the beginning stack address + * @param texit the function will be called when thread exit + * + * @return stack address + */ +rt_uint8_t *rt_hw_stack_init(void *tentry, + void *parameter, + rt_uint8_t *stack_addr, + void *texit) +{ + rt_uint32_t *stk; + register int *tp asm("x3"); + + stack_addr += sizeof(rt_uint32_t); + stack_addr = (rt_uint8_t *)RT_ALIGN_DOWN((rt_uint32_t)stack_addr, 8); + stk = (rt_uint32_t *)stack_addr; + + stk--; + *stk = (rt_uint32_t)tentry; /* Start address */ + stk -= 22; + *stk = (rt_uint32_t)parameter; /* Register a0 parameter*/ + stk -= 6; + *stk = (rt_uint32_t)tp; /* Register thread pointer */ + stk --; + *stk = (rt_uint32_t)texit; /* Register ra texit*/ + + /* return task's current stack address */ + return (rt_uint8_t *)stk; +} + +/** shutdown CPU */ +void rt_hw_cpu_shutdown(void) +{ + rt_uint32_t level; + rt_kprintf("shutdown...\n"); + + level = rt_hw_interrupt_disable(); + while (level) + { + RT_ASSERT(0); + } +} diff --git a/bsp/bluetrum/libcpu/cpu/interrupt.c b/bsp/bluetrum/libcpu/cpu/interrupt.c new file mode 100644 index 0000000000..1903ec25ce --- /dev/null +++ b/bsp/bluetrum/libcpu/cpu/interrupt.c @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2020-2020, Bluetrum Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2020/11/18 greedyhao Bluetrum RISC-V porting code. + */ + +#include +#include +#include +#include "ab32vgx.h" + +uint32_t irq_mask AT(.bss.irq_tbl); +void *tbl_irq_vector[IRQ_TOTAL_NUM] AT(.bss.irq_tbl); +void (*cpu_irq_comm_hook)(void); + +void set_cpu_irq_comm(void (*irq_hook)(void)) +{ + cpu_irq_comm_hook = irq_hook; +} + +AT(.com_text.irq) +void cpu_irq_comm_do(void) +{ + void (*pfnct)(void); + uint32_t irq_pend = PICPND & irq_mask; + for (int i = 0; i < IRQ_TOTAL_NUM; i++) { + if (irq_pend & BIT(i)) { + pfnct = tbl_irq_vector[i]; + if (pfnct) { + pfnct(); /* call ISR */ + } + } + } +} + +void rt_hw_interrupt_init(void) +{ +} + +/** + * @brief This function will install a interrupt service routine to a interrupt. + * + * @param vector + * @param handler + * @param param + * @param name + * @return rt_isr_handler_t + */ +rt_isr_handler_t rt_hw_interrupt_install(int vector, + rt_isr_handler_t handler, + void *param, + const char *name) +{ + rt_isr_handler_t old_handler = RT_NULL; + + if (vector < IRQ_TOTAL_NUM) { + uint32_t cpu_ie = PICCON&BIT(0); + PICCON &= ~BIT(0); + old_handler = tbl_irq_vector[vector]; + tbl_irq_vector[vector] = handler; + irq_mask |= BIT(vector); + PICCON |= cpu_ie; + PICPR &= ~BIT(vector); + PICEN |= BIT(vector); + } + return old_handler; +} diff --git a/bsp/bluetrum/libcpu/cpuport.c b/bsp/bluetrum/libcpu/cpuport.c deleted file mode 100644 index 576401421a..0000000000 --- a/bsp/bluetrum/libcpu/cpuport.c +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2020-2020, Bluetrum Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2020/11/18 greedyhao Bluetrum RISC-V porting code. - */ - -#include -#include - -volatile rt_ubase_t rt_interrupt_from_thread = 0; -volatile rt_ubase_t rt_interrupt_to_thread = 0; -volatile rt_uint32_t rt_thread_switch_interrupt_flag = 0; -volatile rt_uint32_t rt_switch_flag = 0; -rt_uint32_t rt_cur_thread_sp = 0; - -/** - * This function will initialize thread stack - * - * @param tentry the entry of thread - * @param parameter the parameter of entry - * @param stack_addr the beginning stack address - * @param texit the function will be called when thread exit - * - * @return stack address - */ -rt_uint8_t *rt_hw_stack_init(void *tentry, - void *parameter, - rt_uint8_t *stack_addr, - void *texit) -{ - rt_uint32_t *stk; - register int *tp asm("x3"); - - stack_addr += sizeof(rt_uint32_t); - stack_addr = (rt_uint8_t *)RT_ALIGN_DOWN((rt_uint32_t)stack_addr, 8); - stk = (rt_uint32_t *)stack_addr; - - stk--; - *stk = (rt_uint32_t)tentry; /* Start address */ - stk -= 22; - *stk = (rt_uint32_t)parameter; /* Register a0 parameter*/ - stk -= 6; - *stk = (rt_uint32_t)tp; /* Register thread pointer */ - stk --; - *stk = (rt_uint32_t)texit; /* Register ra texit*/ - - /* return task's current stack address */ - return (rt_uint8_t *)stk; -} - -/** shutdown CPU */ -void rt_hw_cpu_shutdown(void) -{ - rt_uint32_t level; - rt_kprintf("shutdown...\n"); - - level = rt_hw_interrupt_disable(); - while (level) - { - RT_ASSERT(0); - } -} diff --git a/bsp/bluetrum/libcpu/interrupt.c b/bsp/bluetrum/libcpu/interrupt.c deleted file mode 100644 index 1903ec25ce..0000000000 --- a/bsp/bluetrum/libcpu/interrupt.c +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2020-2020, Bluetrum Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2020/11/18 greedyhao Bluetrum RISC-V porting code. - */ - -#include -#include -#include -#include "ab32vgx.h" - -uint32_t irq_mask AT(.bss.irq_tbl); -void *tbl_irq_vector[IRQ_TOTAL_NUM] AT(.bss.irq_tbl); -void (*cpu_irq_comm_hook)(void); - -void set_cpu_irq_comm(void (*irq_hook)(void)) -{ - cpu_irq_comm_hook = irq_hook; -} - -AT(.com_text.irq) -void cpu_irq_comm_do(void) -{ - void (*pfnct)(void); - uint32_t irq_pend = PICPND & irq_mask; - for (int i = 0; i < IRQ_TOTAL_NUM; i++) { - if (irq_pend & BIT(i)) { - pfnct = tbl_irq_vector[i]; - if (pfnct) { - pfnct(); /* call ISR */ - } - } - } -} - -void rt_hw_interrupt_init(void) -{ -} - -/** - * @brief This function will install a interrupt service routine to a interrupt. - * - * @param vector - * @param handler - * @param param - * @param name - * @return rt_isr_handler_t - */ -rt_isr_handler_t rt_hw_interrupt_install(int vector, - rt_isr_handler_t handler, - void *param, - const char *name) -{ - rt_isr_handler_t old_handler = RT_NULL; - - if (vector < IRQ_TOTAL_NUM) { - uint32_t cpu_ie = PICCON&BIT(0); - PICCON &= ~BIT(0); - old_handler = tbl_irq_vector[vector]; - tbl_irq_vector[vector] = handler; - irq_mask |= BIT(vector); - PICCON |= cpu_ie; - PICPR &= ~BIT(vector); - PICEN |= BIT(vector); - } - return old_handler; -} diff --git a/bsp/bluetrum/tools/sdk_dist.py b/bsp/bluetrum/tools/sdk_dist.py new file mode 100644 index 0000000000..e40064fb84 --- /dev/null +++ b/bsp/bluetrum/tools/sdk_dist.py @@ -0,0 +1,24 @@ +import os +import sys +import shutil +cwd_path = os.getcwd() +sys.path.append(os.path.join(os.path.dirname(cwd_path), 'rt-thread', 'tools')) + +# BSP dist function +def dist_do_building(BSP_ROOT, dist_dir): + from mkdist import bsp_copy_files + import rtconfig + + library_dir = os.path.join(dist_dir, 'libraries') + + print("=> copy bluetrum bsp library") + library_path = os.path.join(os.path.dirname(BSP_ROOT), 'libraries') + library_dir = os.path.join(dist_dir, 'libraries') + bsp_copy_files(os.path.join(library_path, rtconfig.BSP_LIBRARY_TYPE), os.path.join(library_dir, rtconfig.BSP_LIBRARY_TYPE)) + + print("=> copy bsp drivers") + bsp_copy_files(os.path.join(library_path, 'hal_drivers'), os.path.join(library_dir, 'hal_drivers')) + # shutil.copyfile(os.path.join(library_path, 'Kconfig'), os.path.join(library_dir, 'Kconfig')) + + print("=> copy libcpu") + bsp_copy_files(os.path.join(os.path.dirname(BSP_ROOT), 'libcpu'), os.path.join(dist_dir, 'libcpu')) -- cgit v1.3.1