1 /* 2 * Copyright (c) 2006-2021, RT-Thread Development Team 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 * 6 * Change Logs: 7 * Date Author Notes 8 * 2006-08-31 Bernard first implementation 9 */ 10 11 #include <rthw.h> 12 #include <rtthread.h> 13 14 #include "board.h" 15 16 #ifdef RT_USING_DFS 17 #include "sd.h" 18 #endif 19 20 #ifdef RT_USING_LWIP 21 #include "sam7x_emac.h" 22 extern rt_err_t eth_system_device_init(void); 23 #endif 24 25 #ifdef RT_USING_FINSH 26 #include <finsh.h> 27 extern int finsh_system_init(void); 28 #endif 29 30 /** 31 * @addtogroup sam7x256 32 */ 33 34 /*@{*/ 35 #ifdef __CC_ARM 36 extern int Image$$RW_IRAM1$$ZI$$Limit; 37 #endif 38 39 #ifdef __GNUC__ 40 extern unsigned char __bss_start; 41 extern unsigned char __bss_end; 42 #endif 43 44 extern void rt_hw_interrupt_init(void); 45 extern int rt_application_init(void); 46 #ifdef RT_USING_DEVICE 47 extern rt_err_t rt_hw_serial_init(void); 48 #endif 49 #ifdef RT_USING_FINSH 50 extern int finsh_system_init(void); 51 #endif 52 led_flash()53void led_flash() 54 { 55 int i; 56 static int j = 0; 57 58 rt_hw_board_led_off(j); 59 for (i = 0; i < 2000000; i ++); 60 61 j ++; 62 if (j >= 4) j = 0; 63 64 rt_hw_board_led_on(j); 65 for (i = 0; i < 2000000; i ++); 66 } 67 68 /** 69 * This function will startup RT-Thread RTOS. 70 */ rtthread_startup(void)71void rtthread_startup(void) 72 { 73 /* init hardware interrupt */ 74 rt_hw_interrupt_init(); 75 76 /* init board */ 77 rt_hw_board_init(); 78 79 rt_show_version(); 80 81 /* init timer system */ 82 rt_system_timer_init(); 83 84 #ifdef RT_USING_HEAP 85 #ifdef __CC_ARM 86 rt_system_heap_init((void*)&Image$$RW_IRAM1$$ZI$$Limit, (void*)0x00210000); 87 #elif __ICCARM__ 88 rt_system_heap_init(__segment_end("HEAP"), (void*)0x00210000); 89 #else 90 rt_system_heap_init(&__bss_end, (void*)0x00210000); 91 #endif 92 #endif 93 94 /* init scheduler system */ 95 rt_system_scheduler_init(); 96 97 #ifdef RT_USING_HOOK /* if the hook is used */ 98 /* set idle thread hook */ 99 rt_thread_idle_sethook(led_flash); 100 #endif 101 102 #ifdef RT_USING_DEVICE 103 /* init hardware serial device */ 104 rt_hw_serial_init(); 105 106 #ifdef RT_USING_DFS 107 rt_hw_sdcard_init(); 108 #endif 109 #endif 110 111 /* init application */ 112 rt_application_init(); 113 114 #ifdef RT_USING_FINSH 115 /* init finsh */ 116 finsh_system_init(); 117 #if !defined(RT_USING_POSIX_STDIO) && defined(RT_USING_DEVICE) 118 finsh_set_device("uart1"); 119 #endif 120 #endif 121 122 /* init idle thread */ 123 rt_thread_idle_init(); 124 125 /* start scheduler */ 126 rt_system_scheduler_start(); 127 128 /* never reach here */ 129 return ; 130 } 131 132 #ifdef __CC_ARM main(void)133int main (void) 134 { 135 /* invoke rtthread_startup */ 136 rtthread_startup(); 137 138 return 0; 139 } 140 #endif 141 142 /*@}*/ 143