startup.c 3.2 KB

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