startup.c 2.6 KB

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