startup.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 LICENSE in this
  10. * 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. *********************************************************************/
  17. /******************************************************************//**
  18. * @addtogroup efm32
  19. * @{
  20. *********************************************************************/
  21. /* Includes -------------------------------------------------------------------*/
  22. #include "board.h"
  23. #include <rtthread.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. extern int rt_application_init(void);
  38. #ifdef RT_USING_FINSH
  39. extern void finsh_system_init(void);
  40. extern void finsh_set_device(const char* device);
  41. #endif
  42. /* Private function prototypes ---------------------------------------------------*/
  43. /* Private functions ------------------------------------------------------------*/
  44. #ifdef DEBUG
  45. /******************************************************************//**
  46. * @brief
  47. * Reports the name of the source file and the source line number where the assert error
  48. * has occurred.
  49. *
  50. * @details
  51. *
  52. * @note
  53. *
  54. * @param[in] file
  55. * Pointer to the source file name
  56. *
  57. * @param[in] line
  58. * Assert error line source number
  59. *********************************************************************/
  60. void assert_failed(u8* file, u32 line)
  61. {
  62. rt_kprintf("\n\r Wrong parameter value detected on\r\n");
  63. rt_kprintf(" file %s\r\n", file);
  64. rt_kprintf(" line %d\r\n", line);
  65. while (1) ;
  66. }
  67. #endif
  68. /******************************************************************//**
  69. * @brief
  70. * Startup RT-Thread
  71. *
  72. * @details
  73. *
  74. * @note
  75. *
  76. *********************************************************************/
  77. void rtthread_startup(void)
  78. {
  79. /* init board */
  80. rt_hw_board_init();
  81. #ifdef RT_USING_HEAP
  82. #ifdef __CC_ARM
  83. rt_system_heap_init((void*)&Image$$RW_IRAM1$$ZI$$Limit, (void*)EFM32_SRAM_END);
  84. #elif __ICCARM__
  85. rt_system_heap_init(__segment_end("HEAP"), (void*)EFM32_SRAM_END);
  86. #else
  87. /* init memory system */
  88. rt_system_heap_init((void*)&__bss_end, (void*)EFM32_SRAM_END);
  89. #endif
  90. #endif
  91. /* enable interrupt */
  92. rt_hw_interrupt_enable(0x0UL);
  93. /* init drivers */
  94. rt_hw_driver_init();
  95. /* show version */
  96. rt_show_version();
  97. /* init tick */
  98. rt_system_tick_init();
  99. /* init kernel object */
  100. rt_system_object_init();
  101. /* init timer system */
  102. rt_system_timer_init();
  103. /* init scheduler system */
  104. rt_system_scheduler_init();
  105. /* init all devices */
  106. rt_device_init_all();
  107. #ifdef RT_USING_FINSH
  108. /* init finsh */
  109. finsh_system_init();
  110. finsh_set_device(CONSOLE_DEVICE);
  111. #endif
  112. /* init timer thread */
  113. rt_system_timer_thread_init();
  114. /* init idle thread */
  115. rt_thread_idle_init();
  116. /* init application */
  117. rt_application_init();
  118. /* start scheduler */
  119. rt_system_scheduler_start();
  120. /* never reach here */
  121. return ;
  122. }
  123. /******************************************************************//**
  124. * @brief
  125. * Program entry point
  126. *
  127. * @details
  128. *
  129. * @note
  130. *
  131. *********************************************************************/
  132. int main(void)
  133. {
  134. /* disable interrupt first */
  135. rt_hw_interrupt_disable();
  136. /* init system setting */
  137. SystemInit();
  138. /* startup RT-Thread RTOS */
  139. rtthread_startup();
  140. return 0;
  141. }
  142. /******************************************************************//**
  143. * @}
  144. *********************************************************************/