startup.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * File : startup.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2009 - 2011, 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. * 2011-02-24 Bernard first implementation
  13. */
  14. #include <rthw.h>
  15. #include <rtthread.h>
  16. #include "board.h"
  17. #include "mb9bf506r.h"
  18. #ifdef RT_USING_FINSH
  19. #include <finsh.h>
  20. #endif
  21. /**
  22. * @addtogroup FM3
  23. */
  24. extern struct serial_device uart0;
  25. extern struct rt_device uart0_device;
  26. extern struct serial_device uart2;
  27. extern struct rt_device uart2_device;
  28. /*@{*/
  29. extern int rt_application_init(void);
  30. #ifdef RT_USING_FINSH
  31. extern void finsh_system_init(void);
  32. #endif
  33. #ifdef __CC_ARM
  34. extern int Image$$RW_IRAM1$$ZI$$Limit;
  35. #elif __ICCARM__
  36. #pragma section="HEAP"
  37. #else
  38. extern int __bss_end;
  39. #endif
  40. /**
  41. * This function will startup RT-Thread RTOS.
  42. */
  43. void rtthread_startup(void)
  44. {
  45. /* init board */
  46. rt_hw_board_init();
  47. /* show version */
  48. rt_show_version();
  49. /* init tick */
  50. rt_system_tick_init();
  51. /* init kernel object */
  52. rt_system_object_init();
  53. /* init timer system */
  54. rt_system_timer_init();
  55. #ifdef RT_USING_HEAP
  56. #ifdef __CC_ARM
  57. rt_system_heap_init((void*)&Image$$RW_IRAM1$$ZI$$Limit, (void*)FM3_SRAM_END);
  58. #elif __ICCARM__
  59. rt_system_heap_init(__segment_end("HEAP"), (void*)FM3_SRAM_END);
  60. #else
  61. /* init memory system */
  62. rt_system_heap_init((void*)&__bss_end, (void*)FM3_SRAM_END);
  63. #endif
  64. #endif
  65. /* init scheduler system */
  66. rt_system_scheduler_init();
  67. #ifdef RT_USING_DEVICE
  68. /* register uart0 */
  69. rt_hw_serial_register(&uart0_device, "uart0",
  70. RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_STREAM,
  71. &uart0);
  72. /* register uart2, used for RTI debug */
  73. rt_hw_serial_register(&uart2_device, "uart2",
  74. RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_STREAM,
  75. &uart2);
  76. #ifdef RT_USING_DFS
  77. #ifdef RT_USING_DFS_UFFS
  78. rt_hw_nand_init();
  79. #endif
  80. #endif
  81. /*init all registed devices */
  82. rt_device_init_all();
  83. #endif
  84. /* init application */
  85. rt_application_init();
  86. #ifdef RT_USING_FINSH
  87. /* init finsh */
  88. finsh_system_init();
  89. #ifdef RT_USING_DEVICE
  90. finsh_set_device("uart2");
  91. #endif
  92. #endif
  93. /* init timer thread */
  94. rt_system_timer_thread_init();
  95. /* init idle thread */
  96. rt_thread_idle_init();
  97. /* start scheduler */
  98. rt_system_scheduler_start();
  99. /* never reach here */
  100. return ;
  101. }
  102. int main(void)
  103. {
  104. rt_uint32_t UNUSED level;
  105. /* disable interrupt first */
  106. level = rt_hw_interrupt_disable();
  107. /* init system setting */
  108. SystemInit();
  109. /* startup RT-Thread RTOS */
  110. rtthread_startup();
  111. return 0;
  112. }
  113. /*@}*/