startup.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. extern 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. /* bss end definitions for heap init */
  37. #ifdef __CC_ARM
  38. extern int Image$$RW_IRAM1$$ZI$$Limit;
  39. #elif __ICCARM__
  40. #pragma section="HEAP"
  41. #else
  42. extern int __bss_end;
  43. #endif
  44. #ifdef DEBUG
  45. /*******************************************************************************
  46. * Function Name : assert_failed
  47. * Description : Reports the name of the source file and the source line number
  48. * where the assert error has occurred.
  49. * Input : - file: pointer to the source file name
  50. * - line: assert error line source number
  51. * Output : None
  52. * Return : None
  53. *******************************************************************************/
  54. void assert_failed(u8* file, u32 line)
  55. {
  56. rt_kprintf("\n\r Wrong parameter value detected on\r\n");
  57. rt_kprintf(" file %s\r\n", file);
  58. rt_kprintf(" line %d\r\n", line);
  59. while (1) ;
  60. }
  61. #endif
  62. /**
  63. * This function will startup RT-Thread RTOS.
  64. */
  65. void rtthread_startup(void)
  66. {
  67. /* init board */
  68. rt_hw_board_init();
  69. /* show version */
  70. rt_show_version();
  71. /* init tick */
  72. rt_system_tick_init();
  73. /* init kernel object */
  74. rt_system_object_init();
  75. /* init timer system */
  76. rt_system_timer_init();
  77. #ifdef RT_USING_HEAP
  78. #if STM32_EXT_SRAM
  79. rt_system_heap_init((void*)STM32_EXT_SRAM_BEGIN, (void*)STM32_EXT_SRAM_END);
  80. #else
  81. #ifdef __CC_ARM
  82. rt_system_heap_init((void*)&Image$$RW_IRAM1$$ZI$$Limit, (void*)STM32_SRAM_END);
  83. #elif __ICCARM__
  84. rt_system_heap_init(__segment_end("HEAP"), (void*)STM32_SRAM_END);
  85. #else
  86. /* init memory system */
  87. rt_system_heap_init((void*)&__bss_end, (void*)STM32_SRAM_END);
  88. #endif
  89. #endif
  90. #endif
  91. /* init scheduler system */
  92. rt_system_scheduler_init();
  93. /* init hardware serial device */
  94. rt_hw_usart_init();
  95. #ifdef RT_USING_DFS
  96. /* init sdcard driver */
  97. #if STM32_USE_SDIO
  98. rt_hw_sdcard_init();
  99. #else
  100. rt_hw_msd_init();
  101. #endif
  102. #endif
  103. #ifdef RT_USING_LWIP
  104. eth_system_device_init();
  105. /* register ethernetif device */
  106. #ifdef STM32F10X_CL
  107. rt_hw_stm32_eth_init();
  108. #else
  109. rt_hw_enc28j60_init();
  110. #endif
  111. #endif
  112. rt_hw_rtc_init();
  113. /* init all device */
  114. rt_device_init_all();
  115. /* init application */
  116. rt_application_init();
  117. #ifdef RT_USING_FINSH
  118. /* init finsh */
  119. finsh_system_init();
  120. finsh_set_device(FINSH_DEVICE_NAME);
  121. #endif
  122. /* init idle thread */
  123. rt_thread_idle_init();
  124. /* start scheduler */
  125. rt_system_scheduler_start();
  126. /* never reach here */
  127. return ;
  128. }
  129. int main(void)
  130. {
  131. rt_uint32_t UNUSED level;
  132. /* disable interrupt first */
  133. level = rt_hw_interrupt_disable();
  134. /* init system setting */
  135. SystemInit();
  136. /* startup RT-Thread RTOS */
  137. rtthread_startup();
  138. return 0;
  139. }
  140. /*@}*/