startup.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. #ifdef RT_USING_FINSH
  18. #include "shell.h"
  19. #endif
  20. /**
  21. * @addtogroup STM32
  22. */
  23. /*@{*/
  24. extern int rt_application_init(void);
  25. #ifdef __CC_ARM
  26. extern int Image$$RW_IRAM1$$ZI$$Limit;
  27. #elif __ICCARM__
  28. #pragma section="HEAP"
  29. #else
  30. extern int __bss_end;
  31. #endif
  32. /*******************************************************************************
  33. * Function Name : assert_failed
  34. * Description : Reports the name of the source file and the source line number
  35. * where the assert error has occurred.
  36. * Input : - file: pointer to the source file name
  37. * - line: assert error line source number
  38. * Output : None
  39. * Return : None
  40. *******************************************************************************/
  41. void assert_failed(rt_uint8_t * file, rt_uint32_t line)
  42. {
  43. rt_kprintf("\n\r Wrong parameter value detected on\r\n");
  44. rt_kprintf(" file %s\r\n", file);
  45. rt_kprintf(" line %d\r\n", line);
  46. while (1) ;
  47. }
  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. #ifdef RT_USING_HEAP
  58. #if STM32_EXT_SRAM
  59. rt_system_heap_init((void*)STM32_EXT_SRAM_BEGIN, (void*)STM32_EXT_SRAM_END);
  60. #else
  61. #ifdef __CC_ARM
  62. rt_system_heap_init((void*)&Image$$RW_IRAM1$$ZI$$Limit, (void*)STM32_SRAM_END);
  63. #elif __ICCARM__
  64. rt_system_heap_init(__segment_end("HEAP"), (void*)STM32_SRAM_END);
  65. #else
  66. /* init memory system */
  67. rt_system_heap_init((void*)&__bss_end, (void*)STM32_SRAM_END);
  68. #endif
  69. #endif /* STM32_EXT_SRAM */
  70. #endif /* RT_USING_HEAP */
  71. /* init scheduler system */
  72. rt_system_scheduler_init();
  73. /* initialize timer */
  74. rt_system_timer_init();
  75. /* init timer thread */
  76. rt_system_timer_thread_init();
  77. /* init application */
  78. rt_application_init();
  79. #ifdef RT_USING_FINSH
  80. finsh_system_init();
  81. finsh_set_device(RT_CONSOLE_DEVICE_NAME);
  82. #endif
  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. /*@}*/