1
0

startup.c 2.7 KB

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