startup.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /***************************************************************************//**
  2. * @file startup.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. /* Private typedef -----------------------------------------------------------*/
  25. /* Private define ------------------------------------------------------------*/
  26. /* Private macro -------------------------------------------------------------*/
  27. /* External variables --------------------------------------------------------*/
  28. #ifdef __CC_ARM
  29. extern int Image$$RW_IRAM1$$ZI$$Limit;
  30. #elif __ICCARM__
  31. #pragma section="HEAP"
  32. #else
  33. extern int __bss_end;
  34. #endif
  35. /* Private variables ---------------------------------------------------------*/
  36. /* External function prototypes ----------------------------------------------*/
  37. /* Private function prototypes -----------------------------------------------*/
  38. /* Private functions ---------------------------------------------------------*/
  39. #ifdef RT_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. ******************************************************************************/
  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. while (1) ;
  61. }
  62. #endif
  63. /***************************************************************************//**
  64. * @brief
  65. * Startup RT-Thread
  66. *
  67. * @details
  68. *
  69. * @note
  70. *
  71. ******************************************************************************/
  72. void rtthread_startup(void)
  73. {
  74. /* init board */
  75. rt_hw_board_init();
  76. #ifdef RT_USING_HEAP
  77. #ifdef __CC_ARM
  78. rt_system_heap_init((void*)&Image$$RW_IRAM1$$ZI$$Limit, (void*)EFM32_SRAM_END);
  79. #elif __ICCARM__
  80. rt_system_heap_init(__segment_end("HEAP"), (void*)EFM32_SRAM_END);
  81. #else
  82. /* init memory system */
  83. rt_system_heap_init((void*)&__bss_end, (void*)EFM32_SRAM_END);
  84. #endif
  85. #endif
  86. /* enable interrupt */
  87. rt_hw_interrupt_enable(0x0UL);
  88. /* init drivers */
  89. rt_hw_driver_init();
  90. /* show version */
  91. rt_show_version();
  92. /* init tick */
  93. rt_system_tick_init();
  94. /* init kernel object */
  95. rt_system_object_init();
  96. /* init timer system */
  97. rt_system_timer_init();
  98. /* init scheduler system */
  99. rt_system_scheduler_init();
  100. /* init all devices */
  101. rt_device_init_all();
  102. /* init finsh */
  103. #ifdef RT_USING_FINSH
  104. finsh_system_init();
  105. finsh_set_device(CONSOLE_DEVICE);
  106. #endif
  107. /* Initialize gui server */
  108. #ifdef RT_USING_RTGUI
  109. rtgui_system_server_init();
  110. #endif
  111. /* init timer thread */
  112. rt_system_timer_thread_init();
  113. /* init idle thread */
  114. rt_thread_idle_init();
  115. /* init application */
  116. rt_application_init();
  117. /* start scheduler */
  118. rt_system_scheduler_start();
  119. /* never reach here */
  120. return ;
  121. }
  122. /***************************************************************************//**
  123. * @brief
  124. * Program entry point
  125. *
  126. * @details
  127. *
  128. * @note
  129. *
  130. ******************************************************************************/
  131. int main(void)
  132. {
  133. /* disable interrupt first */
  134. rt_hw_interrupt_disable();
  135. /* init system setting */
  136. SystemInit();
  137. /* startup RT-Thread RTOS */
  138. rtthread_startup();
  139. return 0;
  140. }
  141. /***************************************************************************//**
  142. * @}
  143. ******************************************************************************/