From 597d71cc032bf30098c2a5f890eec48ce5ff418d Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Sun, 23 Dec 2018 14:11:25 +0800 Subject: [PATCH] [bsp][k210] Add get_free_heap_size function. * Add get_free_heap_size function; * Increase shell stack for KPU module. --- bsp/k210/.config | 36 +++++++++++++++++++++++++++++++- bsp/k210/README.md | 4 ++++ bsp/k210/driver/SConscript | 1 + bsp/k210/driver/heap.c | 11 ++++++++++ bsp/k210/rtconfig.h | 2 +- bsp/k210/rtconfig.py | 2 +- libcpu/risc-v/k210/interrupt.c | 14 ++++++++++++- libcpu/risc-v/k210/startup_gcc.S | 5 +++++ 8 files changed, 71 insertions(+), 4 deletions(-) create mode 100644 bsp/k210/driver/heap.c diff --git a/bsp/k210/.config b/bsp/k210/.config index c696886459..a9737f1c80 100644 --- a/bsp/k210/.config +++ b/bsp/k210/.config @@ -93,7 +93,7 @@ CONFIG_FINSH_USING_SYMTAB=y CONFIG_FINSH_USING_DESCRIPTION=y # CONFIG_FINSH_ECHO_DISABLE_DEFAULT is not set CONFIG_FINSH_THREAD_PRIORITY=20 -CONFIG_FINSH_THREAD_STACK_SIZE=4096 +CONFIG_FINSH_THREAD_STACK_SIZE=16384 CONFIG_FINSH_CMD_SIZE=80 # CONFIG_FINSH_USING_AUTH is not set CONFIG_FINSH_USING_MSH=y @@ -325,6 +325,40 @@ CONFIG_PKG_KENDRYTE_SDK_VER="v0.5.2" # CONFIG_PKG_USING_ZLIB is not set # CONFIG_PKG_USING_DSTR is not set # CONFIG_PKG_USING_TINYFRAME is not set +# CONFIG_PKG_USING_KENDRYTE_DEMO is not set +# CONFIG_PKG_USING_KENDRYTE_DEMO_V001 is not set +# CONFIG_PKG_USING_KENDRYTE_DEMO_LATEST_VERSION is not set +# CONFIG_KENDRYTE_DEMO_NONE is not set +# CONFIG_KENDRYTE_DEMO_AES_128_TEST is not set +# CONFIG_KENDRYTE_DEMO_AES_192_TEST is not set +# CONFIG_KENDRYTE_DEMO_AES_256_TEST is not set +# CONFIG_KENDRYTE_DEMO_AI_DEMO_SIM is not set +# CONFIG_KENDRYTE_DEMO_DVP_OV is not set +# CONFIG_KENDRYTE_DEMO_FACE_DETECT is not set +# CONFIG_KENDRYTE_DEMO_FFT_TEST is not set +# CONFIG_KENDRYTE_DEMO_FLASH_W25QXX is not set +# CONFIG_KENDRYTE_DEMO_FLASH_W25QXX_DMA_TEST is not set +# CONFIG_KENDRYTE_DEMO_FLASH_W25QXX_TEST is not set +# CONFIG_KENDRYTE_DEMO_GPIOHS_LED is not set +# CONFIG_KENDRYTE_DEMO_GPIO_LED is not set +# CONFIG_KENDRYTE_DEMO_HELLO_WORLD is not set +# CONFIG_KENDRYTE_DEMO_I2C_SLAVE is not set +# CONFIG_KENDRYTE_DEMO_KPU is not set +# CONFIG_KENDRYTE_DEMO_LCD is not set +# CONFIG_KENDRYTE_DEMO_MIC_PLAY is not set +# CONFIG_KENDRYTE_DEMO_PLAY_PCM is not set +# CONFIG_KENDRYTE_DEMO_PWM is not set +# CONFIG_KENDRYTE_DEMO_RTC is not set +# CONFIG_KENDRYTE_DEMO_RTC_SD3068 is not set +# CONFIG_KENDRYTE_DEMO_SD_CARD is not set +# CONFIG_KENDRYTE_DEMO_SERVO is not set +# CONFIG_KENDRYTE_DEMO_SHA256_TEST is not set +# CONFIG_KENDRYTE_DEMO_TIMER is not set +# CONFIG_KENDRYTE_DEMO_UART is not set +# CONFIG_KENDRYTE_DEMO_UART_DMA is not set +# CONFIG_KENDRYTE_DEMO_UART_DMA_IRQ is not set +# CONFIG_KENDRYTE_DEMO_UART_INTERRUPT is not set +# CONFIG_KENDRYTE_DEMO_WATCHDOG is not set # # samples: kernel and components samples diff --git a/bsp/k210/README.md b/bsp/k210/README.md index 6de922d7a2..66bdf2287d 100644 --- a/bsp/k210/README.md +++ b/bsp/k210/README.md @@ -64,6 +64,10 @@ Kendryte中文含义为勘智,而勘智取自勘物探智。这颗芯片主要 ![terminal](images/k210.png) +如果是K210-test_v0.2开发板,可以用如下命令来打开串口: + + python -m serial.tools.miniterm --rts 0 --dtr 0 COM9 115200 + ## 4. 驱动支持情况及计划 | 驱动 | 支持情况 | 备注 | diff --git a/bsp/k210/driver/SConscript b/bsp/k210/driver/SConscript index 3ea01aa83f..7d5d6e54ce 100644 --- a/bsp/k210/driver/SConscript +++ b/bsp/k210/driver/SConscript @@ -5,6 +5,7 @@ from building import * cwd = GetCurrentDir() src = Split(''' board.c +heap.c drv_uart.c ''') CPPPATH = [cwd] diff --git a/bsp/k210/driver/heap.c b/bsp/k210/driver/heap.c new file mode 100644 index 0000000000..f1d6d2c27a --- /dev/null +++ b/bsp/k210/driver/heap.c @@ -0,0 +1,11 @@ +#include +#include + +size_t get_free_heap_size(void) +{ + rt_uint32_t total, used, max; + + rt_memory_info(&total, &used, &max); + + return total - used; +} diff --git a/bsp/k210/rtconfig.h b/bsp/k210/rtconfig.h index bb101c8c8d..b5fe0dfd48 100644 --- a/bsp/k210/rtconfig.h +++ b/bsp/k210/rtconfig.h @@ -64,7 +64,7 @@ #define FINSH_USING_SYMTAB #define FINSH_USING_DESCRIPTION #define FINSH_THREAD_PRIORITY 20 -#define FINSH_THREAD_STACK_SIZE 4096 +#define FINSH_THREAD_STACK_SIZE 16384 #define FINSH_CMD_SIZE 80 #define FINSH_USING_MSH #define FINSH_USING_MSH_DEFAULT diff --git a/bsp/k210/rtconfig.py b/bsp/k210/rtconfig.py index b159d6fb9e..418c1d7456 100644 --- a/bsp/k210/rtconfig.py +++ b/bsp/k210/rtconfig.py @@ -50,7 +50,7 @@ if PLATFORM == 'gcc': CFLAGS += ' -O0 -ggdb' AFLAGS += ' -ggdb' else: - CFLAGS += ' -O2' + CFLAGS += ' -O2 -Os' CXXFLAGS = CFLAGS diff --git a/libcpu/risc-v/k210/interrupt.c b/libcpu/risc-v/k210/interrupt.c index 6d8866c3f0..f9c3eb5a67 100644 --- a/libcpu/risc-v/k210/interrupt.c +++ b/libcpu/risc-v/k210/interrupt.c @@ -114,6 +114,13 @@ rt_isr_handler_t rt_hw_interrupt_install(int vector, rt_isr_handler_t handler, return old_handler; } +RT_WEAK +void plic_irq_handle(plic_irq_t irq) +{ + rt_kprintf("UN-handled interrupt %d occurred!!!\n", irq); + return ; +} + uintptr_t handle_irq_m_ext(uintptr_t cause, uintptr_t epc) { /* @@ -142,7 +149,12 @@ uintptr_t handle_irq_m_ext(uintptr_t cause, uintptr_t epc) /* Disable software interrupt and timer interrupt */ clear_csr(mie, MIP_MTIP | MIP_MSIP); - if (irq_desc[core_id][int_num].handler) + if (irq_desc[core_id][int_num].handler == (rt_isr_handler_t)rt_hw_interrupt_handle) + { + /* default handler, route to kendryte bsp plic driver */ + plic_irq_handle(int_num); + } + else if (irq_desc[core_id][int_num].handler) { irq_desc[core_id][int_num].handler(int_num, irq_desc[core_id][int_num].param); } diff --git a/libcpu/risc-v/k210/startup_gcc.S b/libcpu/risc-v/k210/startup_gcc.S index bc73f51e03..2e69c5021e 100644 --- a/libcpu/risc-v/k210/startup_gcc.S +++ b/libcpu/risc-v/k210/startup_gcc.S @@ -16,6 +16,11 @@ _start: j 1f .word 0xdeadbeef + .align 3 + .global g_wake_up + g_wake_up: + .dword 1 + .dword 0 1: csrw mideleg, 0 csrw medeleg, 0