startup.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. extern rt_err_t wm8978_hw_init(void);
  41. #ifdef DEBUG
  42. /*******************************************************************************
  43. * Function Name : assert_failed
  44. * Description : Reports the name of the source file and the source line number
  45. * where the assert error has occurred.
  46. * Input : - file: pointer to the source file name
  47. * - line: assert error line source number
  48. * Output : None
  49. * Return : None
  50. *******************************************************************************/
  51. void assert_failed(u8* file, u32 line)
  52. {
  53. rt_kprintf("\n\r Wrong parameter value detected on\r\n");
  54. rt_kprintf(" file %s\r\n", file);
  55. rt_kprintf(" line %d\r\n", line);
  56. while (1) ;
  57. }
  58. #endif
  59. /**
  60. * This function will startup RT-Thread RTOS.
  61. */
  62. void rtthread_startup(void)
  63. {
  64. /* init board */
  65. rt_hw_board_init();
  66. /* show version */
  67. rt_show_version();
  68. /* init tick */
  69. rt_system_tick_init();
  70. /* init kernel object */
  71. rt_system_object_init();
  72. /* init timer system */
  73. rt_system_timer_init();
  74. #ifdef RT_USING_HEAP
  75. #if STM32_EXT_SRAM
  76. rt_system_heap_init((void*)STM32_EXT_SRAM_BEGIN, (void*)STM32_EXT_SRAM_END);
  77. #else
  78. #ifdef __CC_ARM
  79. rt_system_heap_init((void*)&Image$$RW_IRAM1$$ZI$$Limit, (void*)STM32_SRAM_END);
  80. #elif __ICCARM__
  81. rt_system_heap_init(__segment_end("HEAP"), (void*)STM32_SRAM_END);
  82. #else
  83. /* init memory system */
  84. rt_system_heap_init((void*)&__bss_end, (void*)STM32_SRAM_END);
  85. #endif
  86. #endif
  87. #endif
  88. /* init scheduler system */
  89. rt_system_scheduler_init();
  90. #if CODEC_VERSION == 1
  91. wm8753_hw_init();
  92. #elif CODEC_VERSION == 2
  93. wm8978_hw_init();
  94. #endif
  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. /*@}*/