startup.c 4.0 KB

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