startup.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 timer system */
  29. rt_system_timer_init();
  30. #ifdef RT_USING_HEAP
  31. rt_system_heap_init((void*)&rtt_heap_start, (void*)&rtt_heap_end);
  32. #endif
  33. #ifdef RT_USING_MODULE
  34. /* init module system*/
  35. rt_system_module_init();
  36. #endif
  37. /* init scheduler system */
  38. rt_system_scheduler_init();
  39. #ifdef RT_USING_DEVICE
  40. /* register uart0 */
  41. rt_hw_serial_register(&uart0_device, "uart0",
  42. RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_STREAM,
  43. &uart0);
  44. rt_console_set_device("uart0");
  45. #endif
  46. /* init application */
  47. rt_application_init();
  48. #ifdef RT_USING_FINSH
  49. /* init finsh */
  50. extern int finsh_system_init(void);
  51. finsh_system_init();
  52. #if !defined(RT_USING_POSIX_DEVIO) && defined(RT_USING_DEVICE)
  53. finsh_set_device("uart0");
  54. #endif
  55. #endif
  56. rt_system_timer_thread_init();
  57. /* init idle thread */
  58. rt_thread_idle_init();
  59. /* start scheduler */
  60. rt_system_scheduler_start();
  61. /* never reach here */
  62. return ;
  63. }
  64. int main(void)
  65. {
  66. /* disable interrupt first */
  67. rt_hw_interrupt_disable();
  68. /* startup RT-Thread RTOS */
  69. rtthread_startup();
  70. return 0;
  71. }