startup.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 int finsh_system_init(void);
  26. extern void finsh_set_device(const char* device);
  27. #endif
  28. /*******************************************************************************
  29. * Function Name : assert_failed
  30. * Description : Reports the name of the source file and the source line number
  31. * where the assert error has occurred.
  32. * Input : - file: pointer to the source file name
  33. * - line: assert error line source number
  34. * Output : None
  35. * Return : None
  36. *******************************************************************************/
  37. void assert_failed(uint8_t* file, uint32_t line)
  38. {
  39. rt_kprintf("\n\r Wrong parameter value detected on\r\n");
  40. rt_kprintf(" file %s\r\n", file);
  41. rt_kprintf(" line %d\r\n", line);
  42. while (1) ;
  43. }
  44. /**
  45. * This function will startup RT-Thread RTOS.
  46. */
  47. void rtthread_startup(void)
  48. {
  49. /* init board */
  50. rt_hw_board_init();
  51. /* show version */
  52. rt_show_version();
  53. /* init tick */
  54. rt_system_tick_init();
  55. /* init kernel object */
  56. rt_system_object_init();
  57. /* init timer system */
  58. rt_system_timer_init();
  59. #ifdef RT_USING_HEAP
  60. #ifdef RT_USING_EXT_SDRAM
  61. rt_system_heap_init((void*)EXT_SDRAM_BEGIN, (void*)EXT_SDRAM_END);
  62. #endif
  63. {
  64. static struct rt_memheap _heap;
  65. /* initialize a default heap in the system */
  66. rt_memheap_init(&_heap,
  67. "in-heap",
  68. HEAP_BEGIN,
  69. (rt_uint32_t)HEAP_END - (rt_uint32_t)HEAP_BEGIN);
  70. }
  71. #endif
  72. //rt_system_heap_init((void*)HEAP_BEGIN, (void*)HEAP_END);
  73. /* init scheduler system */
  74. rt_system_scheduler_init();
  75. /* init application */
  76. rt_application_init();
  77. /* init timer thread */
  78. rt_system_timer_thread_init();
  79. /* init idle thread */
  80. rt_thread_idle_init();
  81. /* start scheduler */
  82. rt_system_scheduler_start();
  83. /* never reach here */
  84. return ;
  85. }
  86. int main(void)
  87. {
  88. /* disable interrupt first */
  89. rt_hw_interrupt_disable();
  90. /* startup RT-Thread RTOS */
  91. rtthread_startup();
  92. return 0;
  93. }
  94. /*@}*/