startup.c 2.9 KB

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