From 6085f6826d9c19a9d0c7f3feafbd0a5996d7ec2e Mon Sep 17 00:00:00 2001 From: weety Date: Thu, 19 Oct 2017 23:46:17 +0800 Subject: [PATCH] [bsp][at91sam9260] Fix the problem of the finsh function failure by using component initialization. --- bsp/at91sam9260/applications/application.c | 83 +------------- bsp/at91sam9260/applications/startup.c | 106 ------------------ bsp/at91sam9260/drivers/at91_i2c_gpio.c | 6 +- bsp/at91sam9260/drivers/board.c | 28 ++++- bsp/at91sam9260/drivers/macb.c | 8 +- bsp/at91sam9260/drivers/macb.h | 2 +- bsp/at91sam9260/drivers/usart.c | 6 +- .../link_scripts/at91sam9260_ram.ld | 10 +- bsp/at91sam9260/platform/interrupt.c | 31 +++-- bsp/at91sam9260/platform/reset.c | 24 ++++ bsp/at91sam9260/rtconfig.h | 4 + bsp/at91sam9260/rtconfig.py | 4 +- libcpu/arm/arm926/start_gcc.S | 6 +- 13 files changed, 105 insertions(+), 213 deletions(-) delete mode 100644 bsp/at91sam9260/applications/startup.c diff --git a/bsp/at91sam9260/applications/application.c b/bsp/at91sam9260/applications/application.c index 53d08e5ef..50373d89f 100644 --- a/bsp/at91sam9260/applications/application.c +++ b/bsp/at91sam9260/applications/application.c @@ -31,18 +31,8 @@ #include #ifdef RT_USING_DFS -/* dfs filesystem:ELM FatFs filesystem init */ -#include /* dfs Filesystem APIs */ #include -#ifdef RT_USING_DFS_UFFS -/* dfs filesystem:UFFS filesystem init */ -#include -#endif -#endif - -#if defined(RT_USING_DFS_DEVFS) -#include #endif #ifdef RT_USING_SDIO @@ -50,37 +40,18 @@ #include "at91_mci.h" #endif -#ifdef RT_USING_LWIP -#include -//#include -#include "macb.h" -#endif - #ifdef RT_USING_LED #include "led.h" #endif -#define RT_INIT_THREAD_STACK_SIZE (2*1024) +static int rt_led_app_init(void); -#ifdef RT_USING_DFS_ROMFS -#include -#endif - -void rt_init_thread_entry(void* parameter) +int main(void) { /* Filesystem Initialization */ #ifdef RT_USING_DFS { - /* init the device filesystem */ - dfs_init(); - -#if defined(RT_USING_DFS_ELMFAT) - /* init the elm chan FatFs filesystam*/ - elm_init(); -#endif - #if defined(RT_USING_DFS_ROMFS) - dfs_romfs_init(); if (dfs_mount(RT_NULL, "/rom", "rom", 0, &romfs_root) == 0) { rt_kprintf("ROM File System initialized!\n"); @@ -89,24 +60,8 @@ void rt_init_thread_entry(void* parameter) rt_kprintf("ROM File System initialzation failed!\n"); #endif -#if defined(RT_USING_DFS_DEVFS) - devfs_init(); - if (dfs_mount(RT_NULL, "/dev", "devfs", 0, 0) == 0) - rt_kprintf("Device File System initialized!\n"); - else - rt_kprintf("Device File System initialzation failed!\n"); - - #ifdef RT_USING_NEWLIB - /* init libc */ - libc_system_init("uart0"); - #endif -#endif - #if defined(RT_USING_DFS_UFFS) { - /* init the uffs filesystem */ - dfs_uffs_init(); - /* mount flash device as flash directory */ if(dfs_mount("nand0", "/nand0", "uffs", 0, 0) == 0) rt_kprintf("UFFS File System initialized!\n"); @@ -131,20 +86,9 @@ void rt_init_thread_entry(void* parameter) } #endif -#ifdef RT_USING_LWIP - { - /* register ethernetif device */ - eth_system_device_init(); - rt_hw_macb_init(); - /* init lwip system */ - lwip_sys_init(); - } -#endif - #ifdef RT_USING_I2C { rt_i2c_core_init(); - at91_i2c_init(); } #endif @@ -177,38 +121,21 @@ void rt_led_thread_entry(void* parameter) } #endif -int rt_application_init() +static int rt_led_app_init(void) { - rt_thread_t init_thread; #ifdef RT_USING_LED rt_thread_t led_thread; -#endif #if (RT_THREAD_PRIORITY_MAX == 32) - init_thread = rt_thread_create("init", - rt_init_thread_entry, RT_NULL, - RT_INIT_THREAD_STACK_SIZE, 8, 20); -#ifdef RT_USING_LED led_thread = rt_thread_create("led", rt_led_thread_entry, RT_NULL, - 512, 20, 20); -#endif - + 512, 20, 20); #else - init_thread = rt_thread_create("init", - rt_init_thread_entry, RT_NULL, - RT_INIT_THREAD_STACK_SIZE, 80, 20); -#ifdef RT_USING_LED led_thread = rt_thread_create("led", rt_led_thread_entry, RT_NULL, - 512, 200, 20); -#endif - + 512, 200, 20); #endif - if (init_thread != RT_NULL) - rt_thread_startup(init_thread); -#ifdef RT_USING_LED if(led_thread != RT_NULL) rt_thread_startup(led_thread); #endif diff --git a/bsp/at91sam9260/applications/startup.c b/bsp/at91sam9260/applications/startup.c deleted file mode 100644 index 5d374d351..000000000 --- a/bsp/at91sam9260/applications/startup.c +++ /dev/null @@ -1,106 +0,0 @@ -/* - * File : startup.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006, RT-Thread Develop Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Change Logs: - * Date Author Notes - * 2011-01-13 weety first version - */ - -#include -#include - -#include -#ifdef RT_USING_FINSH -#include -#endif -extern void rt_application_init(void); - -/** - * @addtogroup at91sam9260 - */ - -/*@{*/ -#if defined(__CC_ARM) -extern int Image$$ER_ZI$$ZI$$Limit; -#define HEAP_BEGIN (&Image$$ER_ZI$$ZI$$Limit) -#elif (defined (__GNUC__)) -extern unsigned char __bss_end__; -#define HEAP_BEGIN (&__bss_end__) -#elif (defined (__ICCARM__)) -#pragma section=".noinit" -#define HEAP_BEGIN (__section_end(".noinit")) -#endif - -#define HEAP_END (0x24000000) - -/** - * This function will startup RT-Thread RTOS. - */ -static void rtthread_startup(void) -{ - /* initialize board */ - rt_hw_board_init(); - - /* show version */ - rt_show_version(); - -#ifdef RT_USING_HEAP - rt_system_heap_init((void *)HEAP_BEGIN, (void *)HEAP_END); -#endif - - /* initialize scheduler system */ - rt_system_scheduler_init(); - /* initialize system timer*/ - rt_system_timer_init(); - /* initialize application */ - rt_application_init(); - -#ifdef RT_USING_FINSH - /* initialize finsh */ - finsh_system_init(); -#ifdef RT_USING_DEVICE - finsh_set_device(RT_CONSOLE_DEVICE_NAME); -#endif -#endif - - /* initialize timer thread */ - rt_system_timer_thread_init(); - - /* initialize idle thread */ - rt_thread_idle_init(); - - /* start scheduler */ - rt_system_scheduler_start(); - - /* never reach here */ - return ; -} - -int main(void) -{ - /* disable interrupt first */ - rt_hw_interrupt_disable(); - - /* startup RT-Thread RTOS */ - rtthread_startup(); - - return 0; -} - -/*@}*/ diff --git a/bsp/at91sam9260/drivers/at91_i2c_gpio.c b/bsp/at91sam9260/drivers/at91_i2c_gpio.c index c83c36218..1c11f4ad7 100644 --- a/bsp/at91sam9260/drivers/at91_i2c_gpio.c +++ b/bsp/at91sam9260/drivers/at91_i2c_gpio.c @@ -104,7 +104,7 @@ static const struct rt_i2c_bit_ops bit_ops = { 100 }; -rt_err_t at91_i2c_init(void) +int at91_i2c_init(void) { struct rt_i2c_bus_device *bus; @@ -123,8 +123,8 @@ rt_err_t at91_i2c_init(void) rt_i2c_bit_add_bus(bus, "i2c0"); - return RT_EOK; + return 0; } - +INIT_DEVICE_EXPORT(at91_i2c_init); diff --git a/bsp/at91sam9260/drivers/board.c b/bsp/at91sam9260/drivers/board.c index 4b2e0caa2..c45a2e6b2 100644 --- a/bsp/at91sam9260/drivers/board.c +++ b/bsp/at91sam9260/drivers/board.c @@ -32,6 +32,18 @@ * @addtogroup at91sam9260 */ /*@{*/ +#if defined(__CC_ARM) +extern int Image$$ER_ZI$$ZI$$Limit; +#define HEAP_BEGIN (&Image$$ER_ZI$$ZI$$Limit) +#elif (defined (__GNUC__)) +extern unsigned char __bss_end__; +#define HEAP_BEGIN (&__bss_end__) +#elif (defined (__ICCARM__)) +#pragma section=".noinit" +#define HEAP_BEGIN (__section_end(".noinit")) +#endif + +#define HEAP_END (0x24000000) extern void rt_hw_interrupt_init(void); extern void rt_hw_clock_init(void); @@ -150,15 +162,21 @@ void rt_hw_board_init() /* initialize the system clock */ rt_hw_clock_init(); - /* initialize uart */ - rt_hw_uart_init(); + /* initialize early device */ +#ifdef RT_USING_COMPONENTS_INIT + rt_components_board_init(); +#endif +#ifdef RT_USING_CONSOLE rt_console_set_device(RT_CONSOLE_DEVICE_NAME); - - - +#endif /* initialize timer0 */ rt_hw_timer_init(); +/* initialize board */ +#ifdef RT_USING_HEAP + rt_system_heap_init((void *)HEAP_BEGIN, (void *)HEAP_END); +#endif + } /*@}*/ diff --git a/bsp/at91sam9260/drivers/macb.c b/bsp/at91sam9260/drivers/macb.c index be665e09c..fd1f508d3 100644 --- a/bsp/at91sam9260/drivers/macb.c +++ b/bsp/at91sam9260/drivers/macb.c @@ -866,7 +866,7 @@ err1: return -RT_ENOMEM; } -void rt_hw_macb_init() +int rt_hw_macb_init(void) { rt_err_t ret; at91_sys_write(AT91_PMC + AT91_PMC_PCER, 1 << AT91SAM9260_ID_EMAC); //enable macb clock @@ -903,5 +903,9 @@ void rt_hw_macb_init() rt_sem_init(&macb_device.mdio_bus_lock, "mdio_bus_lock", 1, RT_IPC_FLAG_FIFO); eth_device_init(&(macb_device.parent), "e0"); - + + return 0; } + +INIT_DEVICE_EXPORT(rt_hw_macb_init); + diff --git a/bsp/at91sam9260/drivers/macb.h b/bsp/at91sam9260/drivers/macb.h index 4e579e427..9df288353 100644 --- a/bsp/at91sam9260/drivers/macb.h +++ b/bsp/at91sam9260/drivers/macb.h @@ -340,7 +340,7 @@ struct dma_desc { #define MACB_TX_USED_OFFSET 31 #define MACB_TX_USED_SIZE 1 -extern void rt_hw_macb_init(); +extern int rt_hw_macb_init(); #endif /* _MACB_H */ diff --git a/bsp/at91sam9260/drivers/usart.c b/bsp/at91sam9260/drivers/usart.c index c47d378cb..fb91393b3 100644 --- a/bsp/at91sam9260/drivers/usart.c +++ b/bsp/at91sam9260/drivers/usart.c @@ -326,7 +326,7 @@ void at91_usart_gpio_init(void) /** * This function will handle init uart */ -void rt_hw_uart_init(void) +int rt_hw_uart_init(void) { at91_usart_gpio_init(); @@ -422,8 +422,12 @@ void rt_hw_uart_init(void) (void *)&(serial3.parent), "UART3"); rt_hw_interrupt_umask(uart3.irq); #endif + + return 0; } +INIT_BOARD_EXPORT(rt_hw_uart_init); + #ifdef RT_USING_DBGU void rt_dbgu_isr(void) { diff --git a/bsp/at91sam9260/link_scripts/at91sam9260_ram.ld b/bsp/at91sam9260/link_scripts/at91sam9260_ram.ld index 258881b08..9e4397a69 100644 --- a/bsp/at91sam9260/link_scripts/at91sam9260_ram.ld +++ b/bsp/at91sam9260/link_scripts/at91sam9260_ram.ld @@ -1,6 +1,6 @@ OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm") OUTPUT_ARCH(arm) -ENTRY(entry) +ENTRY(start) SECTIONS { . = 0x20000000; @@ -34,6 +34,14 @@ SECTIONS __rtmsymtab_start = .; KEEP(*(RTMSymTab)) __rtmsymtab_end = .; + . = ALIGN(4); + + /* section information for initial. */ + . = ALIGN(4); + __rt_init_start = .; + KEEP(*(SORT(.rti_fn*))) + __rt_init_end = .; + . = ALIGN(4); } . = ALIGN(4); diff --git a/bsp/at91sam9260/platform/interrupt.c b/bsp/at91sam9260/platform/interrupt.c index 014290c61..b6231e3f0 100644 --- a/bsp/at91sam9260/platform/interrupt.c +++ b/bsp/at91sam9260/platform/interrupt.c @@ -405,23 +405,34 @@ void rt_hw_interrupt_ack(rt_uint32_t fiq_irq, rt_uint32_t id) } #ifdef RT_USING_FINSH +#ifdef RT_USING_INTERRUPT_INFO void list_irq(void) { - int irq; - - rt_kprintf("number\tcount\tname\n"); - for (irq = 0; irq < MAX_HANDLERS; irq++) - { - if (rt_strncmp(irq_desc[irq].name, "default", sizeof("default"))) - { - rt_kprintf("%02ld: %10ld %s\n", irq, irq_desc[irq].counter, irq_desc[irq].name); - } - } + int irq; + + rt_kprintf("number\tcount\tname\n"); + for (irq = 0; irq < MAX_HANDLERS; irq++) + { + if (rt_strncmp(irq_desc[irq].name, "default", sizeof("default"))) + { + rt_kprintf("%02ld: %10ld %s\n", irq, irq_desc[irq].counter, irq_desc[irq].name); + } + } } #include FINSH_FUNCTION_EXPORT(list_irq, list system irq); +#ifdef FINSH_USING_MSH +int cmd_list_irq(int argc, char** argv) +{ + list_irq(); + return 0; +} +FINSH_FUNCTION_EXPORT_ALIAS(cmd_list_irq, __cmd_list_irq, list system irq.); + +#endif +#endif #endif diff --git a/bsp/at91sam9260/platform/reset.c b/bsp/at91sam9260/platform/reset.c index 4be76e69a..699e29efd 100644 --- a/bsp/at91sam9260/platform/reset.c +++ b/bsp/at91sam9260/platform/reset.c @@ -41,4 +41,28 @@ void machine_shutdown(void) at91_sys_write(AT91_SHDW_CR, AT91_SHDW_KEY | AT91_SHDW_SHDW); } +#ifdef RT_USING_FINSH + +#include +FINSH_FUNCTION_EXPORT_ALIAS(rt_hw_cpu_reset, reset, restart the system); + +#ifdef FINSH_USING_MSH +int cmd_reset(int argc, char** argv) +{ + rt_hw_cpu_reset(); + return 0; +} + +int cmd_shutdown(int argc, char** argv) +{ + rt_hw_cpu_shutdown(); + return 0; +} + +FINSH_FUNCTION_EXPORT_ALIAS(cmd_reset, __cmd_reset, restart the system.); +FINSH_FUNCTION_EXPORT_ALIAS(cmd_shutdown, __cmd_shutdown, shutdown the system.); + +#endif +#endif + /*@}*/ diff --git a/bsp/at91sam9260/rtconfig.h b/bsp/at91sam9260/rtconfig.h index 4a4b08d0a..07f39ca13 100755 --- a/bsp/at91sam9260/rtconfig.h +++ b/bsp/at91sam9260/rtconfig.h @@ -91,6 +91,7 @@ #define FINSH_USING_SYMTAB #define FINSH_USING_DESCRIPTION #define FINSH_THREAD_STACK_SIZE 4096 +#define FINSH_USING_MSH /* SECTION: C++ support */ /* Using C++ support */ @@ -256,4 +257,7 @@ * #define RT_DFS_ELM_MAX_LFN 128 */ +#define RT_USING_COMPONENTS_INIT +#define RT_USING_USER_MAIN + #endif diff --git a/bsp/at91sam9260/rtconfig.py b/bsp/at91sam9260/rtconfig.py index ce2704871..264e60539 100755 --- a/bsp/at91sam9260/rtconfig.py +++ b/bsp/at91sam9260/rtconfig.py @@ -10,8 +10,7 @@ if os.getenv('RTT_CC'): if CROSS_TOOL == 'gcc': PLATFORM = 'gcc' - EXEC_PATH = 'D:/ArdaArmTools/Sourcery_Lite/bin' - #EXEC_PATH = 'D:/ArdaArmTools/GNUARM_4.9_2015q1/bin' + EXEC_PATH = r'D:\arm-2013.11\bin' elif CROSS_TOOL == 'keil': PLATFORM = 'armcc' EXEC_PATH = 'C:/Keil_v5' @@ -34,7 +33,6 @@ TARGET_NAME = 'rtthread.bin' if PLATFORM == 'gcc': # toolchains PREFIX = 'arm-none-eabi-' - #PREFIX = 'arm-none-linux-gnueabi-' CC = PREFIX + 'gcc' AS = PREFIX + 'gcc' AR = PREFIX + 'ar' diff --git a/libcpu/arm/arm926/start_gcc.S b/libcpu/arm/arm926/start_gcc.S index 4924583cb..1ccff156b 100644 --- a/libcpu/arm/arm926/start_gcc.S +++ b/libcpu/arm/arm926/start_gcc.S @@ -95,8 +95,8 @@ SVC_STACK_START: .section .init, "ax" .arm - .global entry -entry: + .global start +start: LDR PC, vector_reset LDR PC, vector_undef LDR PC, vector_swi @@ -204,7 +204,7 @@ ctor_loop: ctor_end: @; Enter the C code - LDR R0, =main + LDR R0, =rtthread_startup BLX R0 @;----------------- Exception Handler -----------------------------------------