startup.c 4.7 KB

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