startup.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. * File : startup.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006, RT-Thread Develop Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2011-01-13 weety first version
  23. */
  24. #include <rthw.h>
  25. #include <rtthread.h>
  26. #include <at91sam926x.h>
  27. #ifdef RT_USING_FINSH
  28. #include <finsh.h>
  29. #endif
  30. extern void rt_hw_interrupt_init(void);
  31. extern void rt_hw_board_init(void);
  32. extern void rt_system_timer_init(void);
  33. extern void rt_system_scheduler_init(void);
  34. extern void rt_thread_idle_init(void);
  35. extern void mmu_invalidate_icache();
  36. extern void rt_hw_cpu_icache_enable(void);
  37. extern void rt_show_version(void);
  38. extern void rt_system_heap_init(void*, void*);
  39. extern void rt_hw_finsh_init(void);
  40. extern void rt_application_init(void);
  41. /**
  42. * @addtogroup at91sam9260
  43. */
  44. /*@{*/
  45. #if defined(__CC_ARM)
  46. extern int Image$$ER_ZI$$ZI$$Base;
  47. extern int Image$$ER_ZI$$ZI$$Length;
  48. extern int Image$$ER_ZI$$ZI$$Limit;
  49. #elif (defined (__GNUC__))
  50. rt_uint8_t _irq_stack_start[1024];
  51. rt_uint8_t _fiq_stack_start[1024];
  52. rt_uint8_t _undefined_stack_start[512];
  53. rt_uint8_t _abort_stack_start[512];
  54. rt_uint8_t _svc_stack_start[4096] SECTION(".nobss");
  55. extern unsigned char __bss_start;
  56. extern unsigned char __bss_end;
  57. #endif
  58. #ifdef RT_USING_FINSH
  59. extern void finsh_system_init(void);
  60. #endif
  61. /**
  62. * This function will startup RT-Thread RTOS.
  63. */
  64. void rtthread_startup(void)
  65. {
  66. /* disable interrupt first */
  67. rt_hw_interrupt_disable();
  68. /* enable cpu cache */
  69. rt_hw_cpu_icache_disable();
  70. mmu_invalidate_icache();
  71. rt_hw_cpu_icache_enable();
  72. /* initialize hardware interrupt */
  73. rt_hw_interrupt_init();
  74. /* initialize board */
  75. rt_hw_board_init();
  76. /* show version */
  77. rt_show_version();
  78. /* initialize tick */
  79. rt_system_tick_init();
  80. /* initialize kernel object */
  81. rt_system_object_init();
  82. /* initialize timer system */
  83. rt_system_timer_init();
  84. /* initialize heap memory system */
  85. #ifdef __CC_ARM
  86. rt_system_heap_init((void*)&Image$$ER_ZI$$ZI$$Limit, (void*)0x24000000);
  87. #else
  88. rt_system_heap_init((void*)&__bss_end, (void*)0x23f00000);
  89. #endif
  90. #ifdef RT_USING_MODULE
  91. /* initialize module system*/
  92. rt_system_module_init();
  93. #endif
  94. /* initialize scheduler system */
  95. rt_system_scheduler_init();
  96. /* initialize application */
  97. rt_application_init();
  98. #ifdef RT_USING_FINSH
  99. /* initialize finsh */
  100. finsh_system_init();
  101. #ifdef RT_USING_DEVICE
  102. finsh_set_device(RT_CONSOLE_DEVICE_NAME);
  103. #endif
  104. #endif
  105. /* initialize system timer thread */
  106. rt_system_timer_thread_init();
  107. /* initialize idle thread */
  108. rt_thread_idle_init();
  109. /* start scheduler */
  110. rt_system_scheduler_start();
  111. /* never reach here */
  112. return ;
  113. }
  114. int main(void)
  115. {
  116. /* startup RT-Thread RTOS */
  117. rtthread_startup();
  118. return 0;
  119. }
  120. /*@}*/