startup.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. * File : startup.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006, RT-Thread Develop Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://openlab.rt-thread.com/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2006-08-31 Bernard first implementation
  13. */
  14. #include <rthw.h>
  15. #include <rtthread.h>
  16. #include "stm32f10x.h"
  17. #include "board.h"
  18. #include "rtc.h"
  19. /**
  20. * @addtogroup STM32
  21. */
  22. /*@{*/
  23. #ifdef RT_USING_LWIP
  24. #ifdef STM32F10X_CL
  25. void rt_hw_stm32_eth_init(void);
  26. #else
  27. #include "enc28j60.h"
  28. #endif
  29. #include <netif/ethernetif.h>
  30. #endif
  31. extern int rt_application_init(void);
  32. #ifdef RT_USING_FINSH
  33. extern void finsh_system_init(void);
  34. extern void finsh_set_device(const char* device);
  35. #endif
  36. #ifdef __CC_ARM
  37. extern int Image$$RW_IRAM1$$ZI$$Limit;
  38. #elif __ICCARM__
  39. #pragma section="HEAP"
  40. #else
  41. extern int __bss_end;
  42. #endif
  43. #ifdef DEBUG
  44. /*******************************************************************************
  45. * Function Name : assert_failed
  46. * Description : Reports the name of the source file and the source line number
  47. * where the assert error has occurred.
  48. * Input : - file: pointer to the source file name
  49. * - line: assert error line source number
  50. * Output : None
  51. * Return : None
  52. *******************************************************************************/
  53. void assert_failed(u8* file, u32 line)
  54. {
  55. rt_kprintf("\n\r Wrong parameter value detected on\r\n");
  56. rt_kprintf(" file %s\r\n", file);
  57. rt_kprintf(" line %d\r\n", line);
  58. while (1) ;
  59. }
  60. #endif
  61. /**
  62. * This function will startup RT-Thread RTOS.
  63. */
  64. void rtthread_startup(void)
  65. {
  66. /* init board */
  67. rt_hw_board_init();
  68. /* show version */
  69. rt_show_version();
  70. /* init tick */
  71. rt_system_tick_init();
  72. /* init kernel object */
  73. rt_system_object_init();
  74. /* init timer system */
  75. rt_system_timer_init();
  76. #ifdef RT_USING_HEAP
  77. #if STM32_EXT_SRAM
  78. rt_system_heap_init((void*)STM32_EXT_SRAM_BEGIN, (void*)STM32_EXT_SRAM_END);
  79. #else
  80. #ifdef __CC_ARM
  81. rt_system_heap_init((void*)&Image$$RW_IRAM1$$ZI$$Limit, (void*)STM32_SRAM_END);
  82. #elif __ICCARM__
  83. rt_system_heap_init(__segment_end("HEAP"), (void*)STM32_SRAM_END);
  84. #else
  85. /* init memory system */
  86. rt_system_heap_init((void*)&__bss_end, (void*)STM32_SRAM_END);
  87. #endif
  88. #endif
  89. #endif
  90. /* init scheduler system */
  91. rt_system_scheduler_init();
  92. /* init hardware serial device */
  93. rt_hw_usart_init();
  94. #ifdef RT_USINS_DFS
  95. /* init sdcard driver */
  96. #if STM32_USE_SDIO
  97. rt_hw_sdcard_init();
  98. #else
  99. rt_hw_msd_init();
  100. #endif
  101. #endif
  102. #ifdef RT_USING_LWIP
  103. eth_system_device_init();
  104. #ifdef STM32F10X_CL
  105. rt_hw_stm32_eth_init();
  106. #else
  107. /* register ethernetif device */
  108. rt_hw_enc28j60_init();
  109. #endif
  110. #endif // end of RT_USING_LWIP
  111. rt_hw_rtc_init();
  112. /* init all device */
  113. rt_device_init_all();
  114. /* init application */
  115. rt_application_init();
  116. #ifdef RT_USING_FINSH
  117. /* init finsh */
  118. finsh_system_init();
  119. finsh_set_device(FINSH_DEVICE_NAME);
  120. #endif
  121. /* init idle thread */
  122. rt_thread_idle_init();
  123. /* start scheduler */
  124. rt_system_scheduler_start();
  125. /* never reach here */
  126. return ;
  127. }
  128. int main(void)
  129. {
  130. rt_uint32_t UNUSED level;
  131. /* disable interrupt first */
  132. level = rt_hw_interrupt_disable();
  133. /* init system setting */
  134. SystemInit();
  135. /* startup RT-Thread RTOS */
  136. rtthread_startup();
  137. return 0;
  138. }
  139. /*@}*/