startup.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /***************************************************************************//**
  2. * @file interrupt.c
  3. * @brief This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2011, RT-Thread Development Team
  5. * @author Bernard, onelife
  6. * @version 0.4 beta
  7. *******************************************************************************
  8. * @section License
  9. * The license and distribution terms for this file may be found in the file
  10. * LICENSE in this distribution or at http://www.rt-thread.org/license/LICENSE
  11. *******************************************************************************
  12. * @section Change Logs
  13. * Date Author Notes
  14. * 2006-08-31 Bernard first implementation
  15. * 2010-12-29 onelife Modify for EFM32
  16. * 2011-12-20 onelife Add RTGUI initialization routine
  17. ******************************************************************************/
  18. /***************************************************************************//**
  19. * @addtogroup efm32
  20. * @{
  21. ******************************************************************************/
  22. /* Includes ------------------------------------------------------------------*/
  23. #include "board.h"
  24. #include <rtthread.h>
  25. /* Private typedef -----------------------------------------------------------*/
  26. /* Private define ------------------------------------------------------------*/
  27. /* Private macro -------------------------------------------------------------*/
  28. /* External variables --------------------------------------------------------*/
  29. #ifdef __CC_ARM
  30. extern int Image$$RW_IRAM1$$ZI$$Limit;
  31. #elif __ICCARM__
  32. #pragma section="HEAP"
  33. #else
  34. extern int __bss_end;
  35. #endif
  36. /* Private variables ---------------------------------------------------------*/
  37. /* External function prototypes ----------------------------------------------*/
  38. extern int rt_application_init(void);
  39. #ifdef RT_USING_FINSH
  40. extern void finsh_system_init(void);
  41. extern void finsh_set_device(const char* device);
  42. #endif
  43. /* Private function prototypes -----------------------------------------------*/
  44. /* Private functions ---------------------------------------------------------*/
  45. #ifdef DEBUG
  46. /***************************************************************************//**
  47. * @brief
  48. * Reports the name of the source file and the source line number where the
  49. * assert error has occurred.
  50. *
  51. * @details
  52. *
  53. * @note
  54. *
  55. * @param[in] file
  56. * Pointer to the source file name
  57. *
  58. * @param[in] line
  59. * Assert error line source number
  60. ******************************************************************************/
  61. void assert_failed(u8* file, u32 line)
  62. {
  63. rt_kprintf("\n\r Wrong parameter value detected on\r\n");
  64. rt_kprintf(" file %s\r\n", file);
  65. rt_kprintf(" line %d\r\n", line);
  66. while (1) ;
  67. }
  68. #endif
  69. /***************************************************************************//**
  70. * @brief
  71. * Startup RT-Thread
  72. *
  73. * @details
  74. *
  75. * @note
  76. *
  77. ******************************************************************************/
  78. void rtthread_startup(void)
  79. {
  80. /* init board */
  81. rt_hw_board_init();
  82. #ifdef RT_USING_HEAP
  83. #ifdef __CC_ARM
  84. rt_system_heap_init((void*)&Image$$RW_IRAM1$$ZI$$Limit, (void*)EFM32_SRAM_END);
  85. #elif __ICCARM__
  86. rt_system_heap_init(__segment_end("HEAP"), (void*)EFM32_SRAM_END);
  87. #else
  88. /* init memory system */
  89. rt_system_heap_init((void*)&__bss_end, (void*)EFM32_SRAM_END);
  90. #endif
  91. #endif
  92. /* enable interrupt */
  93. rt_hw_interrupt_enable(0x0UL);
  94. /* init drivers */
  95. rt_hw_driver_init();
  96. /* show version */
  97. rt_show_version();
  98. /* init tick */
  99. rt_system_tick_init();
  100. /* init kernel object */
  101. rt_system_object_init();
  102. /* init timer system */
  103. rt_system_timer_init();
  104. /* init scheduler system */
  105. rt_system_scheduler_init();
  106. /* init all devices */
  107. rt_device_init_all();
  108. /* init finsh */
  109. #ifdef RT_USING_FINSH
  110. finsh_system_init();
  111. finsh_set_device(CONSOLE_DEVICE);
  112. #endif
  113. /* Initialize gui server */
  114. #ifdef RT_USING_RTGUI
  115. rtgui_system_server_init();
  116. #endif
  117. /* init timer thread */
  118. rt_system_timer_thread_init();
  119. /* init idle thread */
  120. rt_thread_idle_init();
  121. /* init application */
  122. rt_application_init();
  123. /* start scheduler */
  124. rt_system_scheduler_start();
  125. /* never reach here */
  126. return ;
  127. }
  128. /***************************************************************************//**
  129. * @brief
  130. * Program entry point
  131. *
  132. * @details
  133. *
  134. * @note
  135. *
  136. ******************************************************************************/
  137. int main(void)
  138. {
  139. /* disable interrupt first */
  140. rt_hw_interrupt_disable();
  141. /* init system setting */
  142. SystemInit();
  143. /* startup RT-Thread RTOS */
  144. rtthread_startup();
  145. return 0;
  146. }
  147. /***************************************************************************//**
  148. * @}
  149. ******************************************************************************/