startup.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. * 2006-02-26 Bernard first implementation
  13. * 2006-05-05 Bernard add two test thread
  14. * 2006-08-10 Bernard use rt_show_version to display version information
  15. * 2008-07-14 Bernard modify the heap memory init parameter
  16. */
  17. #include <rthw.h>
  18. #include <rtthread.h>
  19. #include <s3c24x0.h>
  20. #ifdef RT_USING_FINSH
  21. #include <finsh.h>
  22. #endif
  23. extern void rt_hw_interrupt_init(void);
  24. extern void rt_hw_board_init(void);
  25. extern void rt_hw_rtc_init(void);
  26. extern void rt_serial_init(void);
  27. extern void rt_system_timer_init(void);
  28. extern void rt_system_scheduler_init(void);
  29. extern void rt_thread_idle_init(void);
  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 mini2440
  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[1024] SECTION(".nobss");
  51. extern int __bss_end;
  52. #endif
  53. /**
  54. * Fix me
  55. */
  56. #if (defined (__GNUC__))
  57. void *_sbrk (int incr)
  58. {
  59. extern int __bss_end; /* Set by linker. */
  60. static char * heap_end;
  61. char * prev_heap_end;
  62. if (heap_end == 0)
  63. heap_end = & __bss_end;
  64. prev_heap_end = heap_end;
  65. heap_end += incr;
  66. return (void *) prev_heap_end;
  67. }
  68. #endif
  69. #ifdef RT_USING_FINSH
  70. extern void finsh_system_init(void);
  71. #endif
  72. /**
  73. * This function will startup RT-Thread RTOS.
  74. */
  75. void rtthread_startup(void)
  76. {
  77. /* enable cpu cache */
  78. rt_hw_cpu_icache_enable();
  79. rt_hw_cpu_dcache_enable();
  80. /* init hardware interrupt */
  81. rt_hw_interrupt_init();
  82. /* init board */
  83. rt_hw_board_init();
  84. /* show version */
  85. rt_show_version();
  86. /* init tick */
  87. rt_system_tick_init();
  88. /* init kernel object */
  89. rt_system_object_init();
  90. /* init timer system */
  91. rt_system_timer_init();
  92. /* init heap memory system */
  93. #ifdef __CC_ARM
  94. rt_system_heap_init((void*)&Image$$ER_ZI$$ZI$$Limit, (void*)0x07400000);
  95. #else
  96. rt_system_heap_init(&__bss_end, (void*)0x34000000);
  97. #endif
  98. /* init scheduler system */
  99. rt_system_scheduler_init();
  100. #ifdef RT_USING_DEVICE
  101. /* register uart1 */
  102. rt_hw_serial_register(&uart0_device, "uart0",
  103. RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_STREAM,
  104. &uart0);
  105. #ifdef RT_USING_DFS
  106. rt_hw_sdcard_init();
  107. #endif
  108. /* rtc init */
  109. rt_hw_rtc_init();
  110. /*init all registed devices */
  111. rt_device_init_all();
  112. #endif
  113. /* init application */
  114. rt_application_init();
  115. #ifdef RT_USING_FINSH
  116. /* init finsh */
  117. finsh_system_init();
  118. #ifdef RT_USING_DEVICE
  119. finsh_set_device("uart0");
  120. #endif
  121. #endif
  122. /* init idle thread */
  123. rt_thread_idle_init();
  124. /* start scheduler */
  125. rt_system_scheduler_start();
  126. /* never reach here */
  127. return ;
  128. }
  129. int main(void)
  130. {
  131. rt_uint32_t UNUSED level;
  132. /* disable interrupt first */
  133. level = rt_hw_interrupt_disable();
  134. /* startup RT-Thread RTOS */
  135. rtthread_startup();
  136. return 0;
  137. }
  138. /*@}*/