startup.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. * 2013-11-15 bright modify for stm32f0xx version and components initial
  14. */
  15. #include <rthw.h>
  16. #include <rtthread.h>
  17. #include "board.h"
  18. /**
  19. * @addtogroup STM32
  20. */
  21. /*@{*/
  22. extern int rt_application_init(void);
  23. #ifdef RT_USING_FINSH
  24. extern void finsh_system_init(void);
  25. extern void finsh_set_device(const char* device);
  26. #endif
  27. #ifdef __CC_ARM
  28. extern int Image$$RW_IRAM1$$ZI$$Limit;
  29. #define STM32_SRAM_BEGIN (&Image$$RW_IRAM1$$ZI$$Limit)
  30. #elif __ICCARM__
  31. #pragma section="HEAP"
  32. #define STM32_SRAM_BEGIN (__segment_end("HEAP"))
  33. #else
  34. extern int __bss_end;
  35. #define STM32_SRAM_BEGIN (&__bss_end)
  36. #endif
  37. /*******************************************************************************
  38. * Function Name : assert_failed
  39. * Description : Reports the name of the source file and the source line number
  40. * where the assert error has occurred.
  41. * Input : - file: pointer to the source file name
  42. * - line: assert error line source number
  43. * Output : None
  44. * Return : None
  45. *******************************************************************************/
  46. void assert_failed(uint8_t* file, uint32_t line)
  47. {
  48. rt_kprintf("\n\r Wrong parameter value detected on\r\n");
  49. rt_kprintf(" file %s\r\n", file);
  50. rt_kprintf(" line %d\r\n", line);
  51. while (1) ;
  52. }
  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. rt_system_heap_init((void*)STM32_SRAM_BEGIN, (void*)STM32_SRAM_END);
  70. #endif
  71. /* init scheduler system */
  72. rt_system_scheduler_init();
  73. /* init application */
  74. rt_application_init();
  75. /* init timer thread */
  76. rt_system_timer_thread_init();
  77. /* init idle thread */
  78. rt_thread_idle_init();
  79. /* start scheduler */
  80. rt_system_scheduler_start();
  81. /* never reach here */
  82. return ;
  83. }
  84. int main(void)
  85. {
  86. /* disable interrupt first */
  87. rt_hw_interrupt_disable();
  88. /* startup RT-Thread RTOS */
  89. rtthread_startup();
  90. return 0;
  91. }
  92. /*@}*/