startup.c 2.6 KB

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