startup.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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-08-31 Bernard first implementation
  13. */
  14. #include <rthw.h>
  15. #include <rtthread.h>
  16. #include "board.h"
  17. #ifdef RT_USING_DFS
  18. #include "sd.h"
  19. #endif
  20. #ifdef RT_USING_LWIP
  21. #include "sam7x_emac.h"
  22. #endif
  23. #ifdef RT_USING_FINSH
  24. #include <finsh.h>
  25. extern void finsh_system_init(void);
  26. #endif
  27. /**
  28. * @addtogroup sam7x256
  29. */
  30. /*@{*/
  31. #ifdef __CC_ARM
  32. extern int Image$$RW_IRAM1$$ZI$$Limit;
  33. #endif
  34. #ifdef __GNUCC__
  35. extern unsigned char __bss_start;
  36. extern unsigned char __bss_end;
  37. #endif
  38. extern void rt_hw_interrupt_init(void);
  39. extern int rt_application_init(void);
  40. #ifdef RT_USING_DEVICE
  41. extern rt_err_t rt_hw_serial_init(void);
  42. #endif
  43. #ifdef RT_USING_FINSH
  44. extern void finsh_system_init(void);
  45. #endif
  46. void led_flash()
  47. {
  48. int i;
  49. static int j = 0;
  50. rt_hw_board_led_off(j);
  51. for (i = 0; i < 2000000; i ++);
  52. j ++;
  53. if (j >= 4) j = 0;
  54. rt_hw_board_led_on(j);
  55. for (i = 0; i < 2000000; i ++);
  56. }
  57. /**
  58. * This function will startup RT-Thread RTOS.
  59. */
  60. void rtthread_startup(void)
  61. {
  62. /* init hardware interrupt */
  63. rt_hw_interrupt_init();
  64. /* init board */
  65. rt_hw_board_init();
  66. rt_show_version();
  67. /* init tick */
  68. rt_system_tick_init();
  69. /* init kernel object */
  70. rt_system_object_init();
  71. /* init timer system */
  72. rt_system_timer_init();
  73. #ifdef RT_USING_HEAP
  74. #ifdef __CC_ARM
  75. rt_system_heap_init((void*)&Image$$RW_IRAM1$$ZI$$Limit, (void*)0x00210000);
  76. #elif __ICCARM__
  77. rt_system_heap_init(__segment_end("HEAP"), (void*)0x00210000);
  78. #else
  79. rt_system_heap_init(&__bss_end, 0x00210000);
  80. #endif
  81. #endif
  82. /* init scheduler system */
  83. rt_system_scheduler_init();
  84. #ifdef RT_USING_HOOK /* if the hook is used */
  85. /* set idle thread hook */
  86. rt_thread_idle_sethook(led_flash);
  87. #endif
  88. #ifdef RT_USING_DEVICE
  89. /* init hardware serial device */
  90. rt_hw_serial_init();
  91. #ifdef RT_USING_LWIP
  92. eth_system_device_init();
  93. /* register AT91 EMAC device */
  94. sam7xether_register("E0");
  95. #endif
  96. #ifdef RT_USING_DFS
  97. rt_hw_sdcard_init();
  98. #endif
  99. /*init all registed devices*/
  100. rt_device_init_all();
  101. #endif
  102. /* init application */
  103. rt_application_init();
  104. #ifdef RT_USING_FINSH
  105. /* init finsh */
  106. finsh_system_init();
  107. finsh_set_device("uart1");
  108. #endif
  109. /* init idle thread */
  110. rt_thread_idle_init();
  111. /* start scheduler */
  112. rt_system_scheduler_start();
  113. /* never reach here */
  114. return ;
  115. }
  116. int main (void)
  117. {
  118. /* invoke rtthread_startup */
  119. rtthread_startup();
  120. return 0;
  121. }
  122. /*@}*/