startup.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2012-02-13 mojingxian first version
  9. */
  10. #include <rthw.h>
  11. #include <rtthread.h>
  12. #include "application.h"
  13. #include "board.h"
  14. #include "serial.h"
  15. #include "finsh.h"
  16. extern "asm" int rtt_heap_start;
  17. extern "asm" int rtt_heap_end;
  18. extern struct serial_device uart0;
  19. extern struct rt_device uart0_device;
  20. void rtthread_startup(void)
  21. {
  22. /* init hardware interrupt */
  23. rt_hw_interrupt_init();
  24. /* init board */
  25. rt_hw_board_init();
  26. /* show version */
  27. rt_show_version();
  28. /* init tick */
  29. rt_system_tick_init();
  30. /* init kernel object */
  31. rt_system_object_init();
  32. /* init timer system */
  33. rt_system_timer_init();
  34. #ifdef RT_USING_HEAP
  35. rt_system_heap_init((void*)&rtt_heap_start, (void*)&rtt_heap_end);
  36. #endif
  37. #ifdef RT_USING_MODULE
  38. /* init module system*/
  39. rt_system_module_init();
  40. #endif
  41. /* init scheduler system */
  42. rt_system_scheduler_init();
  43. #ifdef RT_USING_DEVICE
  44. /* register uart0 */
  45. rt_hw_serial_register(&uart0_device, "uart0",
  46. RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_STREAM,
  47. &uart0);
  48. rt_console_set_device("uart0");
  49. #endif
  50. /* init application */
  51. rt_application_init();
  52. #ifdef RT_USING_FINSH
  53. /* init finsh */
  54. extern int finsh_system_init(void);
  55. finsh_system_init();
  56. finsh_set_device("uart0");
  57. #endif
  58. rt_system_timer_thread_init();
  59. /* init idle thread */
  60. rt_thread_idle_init();
  61. /* start scheduler */
  62. rt_system_scheduler_start();
  63. /* never reach here */
  64. return ;
  65. }
  66. int main(void)
  67. {
  68. /* disable interrupt first */
  69. rt_hw_interrupt_disable();
  70. /* startup RT-Thread RTOS */
  71. rtthread_startup();
  72. return 0;
  73. }