1 /*
2  * Copyright (c) 2006-2022, 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  * 2010-12-29   onelife     Modify for EFM32
10  * 2011-12-20   onelife     Add RTGUI initialization routine
11  * 2012-02-21   onelife     Add energy management initialization routine
12  * 2012-05-15   onelife     Modified to compatible with CMSIS v3
13  */
14 
15 /***************************************************************************//**
16  * @addtogroup efm32
17  * @{
18  ******************************************************************************/
19 
20 /* Includes ------------------------------------------------------------------*/
21 #include "board.h"
22 
23 /* Private typedef -----------------------------------------------------------*/
24 /* Private define ------------------------------------------------------------*/
25 /* Private macro -------------------------------------------------------------*/
26 /* External variables --------------------------------------------------------*/
27 #ifdef __CC_ARM
28 extern int Image$$RW_IRAM1$$ZI$$Limit;
29 #elif __ICCARM__
30 #pragma section="HEAP"
31 #else
32 extern int __bss_end__;
33 #endif
34 
35 /* Private variables ---------------------------------------------------------*/
36 /* External function prototypes ----------------------------------------------*/
37 /* Private function prototypes -----------------------------------------------*/
38 /* Private functions ---------------------------------------------------------*/
39 #ifdef RT_USING_DEBUG
40 /***************************************************************************//**
41  * @brief
42  *  Reports the name of the source file and the source line number where the
43  *  assert error has occurred.
44  *
45  * @details
46  *
47  * @note
48  *
49  * @param[in] file
50  *  Pointer to the source file name
51  *
52  * @param[in] line
53  *  Assert error line source number
54  ******************************************************************************/
assert_failed(uint8_t * file,uint32_t line)55 void assert_failed(uint8_t * file, uint32_t line)
56 {
57     rt_kprintf("\n\r Wrong parameter value detected on\r\n");
58     rt_kprintf("       file  %s\r\n", file);
59     rt_kprintf("       line  %d\r\n", line);
60 
61     while (1) ;
62 }
63 #endif
64 
65 /***************************************************************************//**
66  * @brief
67  *  Startup RT-Thread
68  *
69  * @details
70  *
71  * @note
72  *
73  ******************************************************************************/
rtthread_startup(void)74 void rtthread_startup(void)
75 {
76     /* init board */
77     rt_hw_board_init();
78 
79 #ifdef RT_USING_HEAP
80     #ifdef __CC_ARM
81     rt_system_heap_init((void*)&Image$$RW_IRAM1$$ZI$$Limit, (void*)EFM32_SRAM_END);
82     #elif __ICCARM__
83     rt_system_heap_init(__segment_end("HEAP"), (void*)EFM32_SRAM_END);
84     #else
85     /* init memory system */
86     rt_system_heap_init((void*)&__bss_end__, (void*)EFM32_SRAM_END);
87     #endif
88 #endif
89 
90     /* enable interrupt */
91     rt_hw_interrupt_enable(0x0UL);
92 
93     /* init drivers */
94     rt_hw_driver_init();
95 
96     /* show version */
97     rt_show_version();
98 
99     /* init timer system */
100     rt_system_timer_init();
101 
102     /* init scheduler system */
103     rt_system_scheduler_init();
104 
105     /* init finsh */
106 #ifdef RT_USING_FINSH
107     finsh_system_init();
108 #if !defined(RT_USING_POSIX_STDIO) && defined(RT_USING_DEVICE)
109     finsh_set_device(CONSOLE_DEVICE);
110 #endif
111 #endif
112 
113     /* Initialize gui server */
114 #ifdef RT_USING_RTGUI
115     rtgui_system_server_init();
116 #endif
117 
118     /* init timer thread */
119     rt_system_timer_thread_init();
120 
121     /* init idle thread */
122     rt_thread_idle_init();
123 
124     /* init energy mode thread */
125     efm32_emu_init();
126 
127     /* init application */
128     rt_application_init();
129 
130     /* start scheduler */
131     rt_system_scheduler_start();
132 
133     /* never reach here */
134     return ;
135 }
136 
137 /***************************************************************************//**
138  * @brief
139  *  Program entry point
140  *
141  * @details
142  *
143  * @note
144  *
145  ******************************************************************************/
main(void)146 int main(void)
147 {
148     /* disable interrupt first */
149     rt_hw_interrupt_disable();
150 
151     /* init system setting */
152     SystemInit();
153 
154     /* startup RT-Thread RTOS */
155     rtthread_startup();
156 
157     return 0;
158 }
159 
160 /***************************************************************************//**
161  * @}
162  ******************************************************************************/
163