startup.c 2.7 KB

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