startup.c 3.4 KB

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