startup.c 2.6 KB

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