startup.c 3.4 KB

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