startup.c 4.2 KB

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