startup.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*
  2. * File : startup.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006, RT-Thread Develop 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-01-13 weety first version
  13. */
  14. #include <rthw.h>
  15. #include <rtthread.h>
  16. #include <at91sam926x.h>
  17. #ifdef RT_USING_FINSH
  18. #include <finsh.h>
  19. #endif
  20. extern void rt_hw_interrupt_init(void);
  21. extern void rt_hw_board_init(void);
  22. extern void rt_serial_init(void);
  23. extern void rt_system_timer_init(void);
  24. extern void rt_system_scheduler_init(void);
  25. extern void rt_thread_idle_init(void);
  26. extern void rt_hw_cpu_icache_enable(void);
  27. extern void rt_show_version(void);
  28. extern void rt_system_heap_init(void*, void*);
  29. extern void rt_hw_finsh_init(void);
  30. extern void rt_application_init(void);
  31. extern struct serial_device uart0;
  32. extern struct rt_device uart0_device;
  33. /**
  34. * @addtogroup at91sam9260
  35. */
  36. /*@{*/
  37. #if defined(__CC_ARM)
  38. extern int Image$$ER_ZI$$ZI$$Base;
  39. extern int Image$$ER_ZI$$ZI$$Length;
  40. extern int Image$$ER_ZI$$ZI$$Limit;
  41. #elif (defined (__GNUC__))
  42. rt_uint8_t _irq_stack_start[1024];
  43. rt_uint8_t _fiq_stack_start[1024];
  44. rt_uint8_t _undefined_stack_start[512];
  45. rt_uint8_t _abort_stack_start[512];
  46. rt_uint8_t _svc_stack_start[4096] SECTION(".nobss");
  47. extern unsigned char __bss_start;
  48. extern unsigned char __bss_end;
  49. #endif
  50. #ifdef RT_USING_FINSH
  51. extern void finsh_system_init(void);
  52. #endif
  53. /**
  54. * This function will startup RT-Thread RTOS.
  55. */
  56. void rtthread_startup(void)
  57. {
  58. /* disable interrupt first */
  59. rt_hw_interrupt_disable();
  60. /* enable cpu cache */
  61. rt_hw_cpu_icache_disable();
  62. mmu_invalidate_icache();
  63. rt_hw_cpu_icache_enable();
  64. /* initialize hardware interrupt */
  65. rt_hw_interrupt_init();
  66. /* initialize board */
  67. rt_hw_board_init();
  68. /* show version */
  69. rt_show_version();
  70. /* initialize tick */
  71. rt_system_tick_init();
  72. /* initialize kernel object */
  73. rt_system_object_init();
  74. /* initialize timer system */
  75. rt_system_timer_init();
  76. /* initialize heap memory system */
  77. #ifdef __CC_ARM
  78. rt_system_heap_init((void*)&Image$$ER_ZI$$ZI$$Limit, (void*)0x24000000);
  79. #else
  80. rt_system_heap_init((void*)&__bss_end, (void*)0x23f00000);
  81. #endif
  82. #ifdef RT_USING_MODULE
  83. /* initialize module system*/
  84. rt_system_module_init();
  85. #endif
  86. /* initialize scheduler system */
  87. rt_system_scheduler_init();
  88. #ifdef RT_USING_DEVICE
  89. #ifdef RT_USING_DBGU
  90. /* register dbgu */
  91. rt_hw_serial_register(&uart0_device, "uart0",
  92. RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_STREAM | RT_DEVICE_FLAG_INT_RX,
  93. &uart0);
  94. #endif
  95. #ifdef RT_USING_UART0
  96. /* register uart0 */
  97. rt_hw_serial_register(&uart1_device, "uart1",
  98. RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_STREAM | RT_DEVICE_FLAG_INT_RX,
  99. &uart1);
  100. #endif
  101. #ifdef RT_USING_UART1
  102. /* register uart1 */
  103. rt_hw_serial_register(&uart2_device, "uart2",
  104. RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_STREAM | RT_DEVICE_FLAG_INT_RX,
  105. &uart2);
  106. #endif
  107. #ifdef RT_USING_UART2
  108. /* register uart2 */
  109. rt_hw_serial_register(&uart3_device, "uart3",
  110. RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_STREAM | RT_DEVICE_FLAG_INT_RX,
  111. &uart3);
  112. #endif
  113. #ifdef RT_USING_UART3
  114. /* register uart3 */
  115. rt_hw_serial_register(&uart4_device, "uart4",
  116. RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_STREAM | RT_DEVICE_FLAG_INT_RX,
  117. &uart4);
  118. #endif
  119. #ifdef RT_USING_DFS
  120. //rt_hw_sdcard_init();
  121. #endif
  122. #ifdef RT_USING_LWIP
  123. /* register ethernetif device */
  124. eth_system_device_init();
  125. rt_hw_macb_init();
  126. /* init lwip system */
  127. lwip_sys_init();
  128. rt_kprintf("TCP/IP initialized!\n");
  129. #endif
  130. /*init all registed devices */
  131. rt_device_init_all();
  132. #endif
  133. /* initialize application */
  134. rt_application_init();
  135. #ifdef RT_USING_FINSH
  136. /* initialize finsh */
  137. finsh_system_init();
  138. #ifdef RT_USING_DEVICE
  139. #ifdef RT_USING_DBGU
  140. finsh_set_device("uart0");
  141. #endif
  142. #endif
  143. #endif
  144. /* initialize system timer thread */
  145. rt_system_timer_thread_init();
  146. /* initialize idle thread */
  147. rt_thread_idle_init();
  148. /* start scheduler */
  149. rt_system_scheduler_start();
  150. /* never reach here */
  151. return ;
  152. }
  153. /*@}*/