startup.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * Copyright (c) 2006-2018, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. *
  9. */
  10. #include <rthw.h>
  11. #include <rtthread.h>
  12. #include <board.h>
  13. /**
  14. * @addtogroup k64
  15. */
  16. /*@{*/
  17. extern int rt_application_init(void);
  18. #ifdef RT_USING_FINSH
  19. extern int finsh_system_init(void);
  20. extern void finsh_set_device(const char* device);
  21. #endif
  22. #ifdef __CC_ARM
  23. extern int Image$$RW_IRAM2$$ZI$$Limit;
  24. #define K64_SRAM_BEGIN (&Image$$RW_IRAM2$$ZI$$Limit)
  25. #elif __ICCARM__
  26. #pragma section="HEAP"
  27. #define K64_SRAM_BEGIN (__segment_end("HEAP"))
  28. #else
  29. extern int __bss_end;
  30. #define K64_SRAM_BEGIN (&__bss_end)
  31. #endif
  32. /*******************************************************************************
  33. * Function Name : assert_failed
  34. * Description : Reports the name of the source file and the source line number
  35. * where the assert error has occurred.
  36. * Input : - file: pointer to the source file name
  37. * - line: assert error line source number
  38. * Output : None
  39. * Return : None
  40. *******************************************************************************/
  41. void assert_failed(rt_uint8_t* file, rt_uint32_t line)
  42. {
  43. rt_kprintf("\n\r Wrong parameter value detected on\r\n");
  44. rt_kprintf(" file %s\r\n", file);
  45. rt_kprintf(" line %d\r\n", line);
  46. while (1) ;
  47. }
  48. /**
  49. * This function will startup RT-Thread RTOS.
  50. */
  51. void rtthread_startup(void)
  52. {
  53. /* init board */
  54. rt_hw_board_init();
  55. /* show version */
  56. rt_show_version();
  57. /* init tick */
  58. rt_system_tick_init();
  59. /* init kernel object */
  60. rt_system_object_init();
  61. /* init timer system */
  62. rt_system_timer_init();
  63. rt_system_heap_init((void*)K64_SRAM_BEGIN, (void*)K64_SRAM_END);
  64. /* init scheduler system */
  65. rt_system_scheduler_init();
  66. /* init all device */
  67. rt_device_init_all();
  68. /* init application */
  69. rt_application_init();
  70. #ifdef RT_USING_FINSH
  71. /* init finsh */
  72. finsh_system_init();
  73. finsh_set_device( FINSH_DEVICE_NAME );
  74. #endif
  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. /*@}*/