startup.c 2.1 KB

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