startup.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. * 2010-01-25 Bernard first version
  13. */
  14. #include <rthw.h>
  15. #include <rtthread.h>
  16. #include "board.h"
  17. #ifdef RT_USING_UART
  18. #include "uart.h"
  19. #endif
  20. /**
  21. * @addtogroup sam7s
  22. */
  23. /*@{*/
  24. #ifdef __CC_ARM
  25. extern int Image$$RW_IRAM1$$ZI$$Limit;
  26. #endif
  27. #ifdef __GNUC__
  28. extern unsigned char __bss_start;
  29. extern unsigned char __bss_end;
  30. #endif
  31. extern void rt_hw_interrupt_init(void);
  32. extern int rt_application_init(void);
  33. #ifdef RT_USING_DEVICE
  34. extern rt_err_t rt_hw_serial_init(void);
  35. #endif
  36. /**
  37. * This function will startup RT-Thread RTOS.
  38. */
  39. void rtthread_startup(void)
  40. {
  41. /* init kernel object */
  42. rt_system_object_init();
  43. /* init board */
  44. rt_hw_board_init();
  45. rt_show_version();
  46. /* init tick */
  47. rt_system_tick_init();
  48. /* init timer system */
  49. rt_system_timer_init();
  50. #ifdef RT_USING_HEAP
  51. #ifdef __CC_ARM
  52. rt_system_heap_init((void*)&Image$$RW_IRAM1$$ZI$$Limit, (void*)0x204000);
  53. #elif __ICCARM__
  54. rt_system_heap_init(__segment_end("HEAP"), (void*)0x204000);
  55. #else
  56. rt_system_heap_init((void*)&__bss_end, (void*)0x204000);
  57. #endif
  58. #endif
  59. /* init scheduler system */
  60. rt_system_scheduler_init();
  61. #ifdef RT_USING_HOOK /* if the hook is used */
  62. /* set idle thread hook */
  63. rt_thread_idle_sethook(rt_hw_led_flash);
  64. #endif
  65. #ifdef RT_USING_DEVICE
  66. /* init all device */
  67. rt_device_init_all();
  68. #endif
  69. /* init application */
  70. rt_application_init();
  71. #ifdef RT_USING_FINSH
  72. /* init finsh */
  73. finsh_system_init();
  74. finsh_set_device("uart1");
  75. #endif
  76. /* init idle thread */
  77. rt_thread_idle_init();
  78. /* start scheduler */
  79. rt_system_scheduler_start();
  80. /* never reach here */
  81. return ;
  82. }
  83. int main (void)
  84. {
  85. rt_uint32_t UNUSED level;
  86. /* disable interrupt first */
  87. level = rt_hw_interrupt_disable();
  88. /* invoke rtthread_startup */
  89. rtthread_startup();
  90. return 0;
  91. }
  92. /*@}*/