startup.c 2.5 KB

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