startup.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * File : startup.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2009, RT-Thread Development 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. * 2009-01-05 Bernard first implementation
  13. * 2010-04-09 fify for M16C
  14. */
  15. #include <rthw.h>
  16. #include <rtthread.h>
  17. #include "iom16c62p.h"
  18. #include "board.h"
  19. #include "bsp.h"
  20. extern void rt_hw_interrupt_init(void);
  21. extern int rt_application_init(void);
  22. #ifdef RT_USING_FINSH
  23. extern int finsh_system_init(void);
  24. extern void finsh_set_device(const char* device);
  25. #endif
  26. #ifdef RT_USING_HEAP
  27. #if (defined (__ICCM16C__))
  28. #pragma section="DATA16_HEAP"
  29. #elif (defined (__GNUC__))
  30. extern unsigned char user_ram_end;
  31. #endif
  32. #endif
  33. /**
  34. * This function will startup RT-Thread RTOS.
  35. */
  36. void rtthread_startup(void)
  37. {
  38. /* init hardware interrupt */
  39. rt_hw_interrupt_init();
  40. /* init board */
  41. rt_hw_board_init();
  42. /* show version */
  43. rt_show_version();
  44. /* init tick */
  45. rt_system_tick_init();
  46. /* init kernel object */
  47. rt_system_object_init();
  48. /* init timer system */
  49. rt_system_timer_init();
  50. #ifdef RT_USING_HEAP
  51. #ifdef __ICCM16C__
  52. rt_system_heap_init(__segment_begin("DATA16_HEAP"), __segment_end("DATA16_HEAP"));
  53. #elif (defined (__GNUC__))
  54. rt_system_heap_init((void*)&user_ram_end, (void*)M16C62P_SRAM_END);
  55. #endif
  56. #endif
  57. /* init scheduler system */
  58. rt_system_scheduler_init();
  59. /* init application */
  60. rt_application_init();
  61. #ifdef RT_USING_FINSH
  62. /* init finsh */
  63. finsh_system_init();
  64. finsh_set_device("uart0");
  65. #endif
  66. /* init timer thread */
  67. rt_system_timer_thread_init();
  68. /* init idle thread */
  69. rt_thread_idle_init();
  70. /* start scheduler */
  71. rt_system_scheduler_start();
  72. /* never reach here */
  73. return ;
  74. }
  75. int main(void)
  76. {
  77. /* disable interrupt first */
  78. rt_hw_interrupt_disable();
  79. /* init system setting */
  80. system_init();
  81. /* startup RT-Thread RTOS */
  82. rtthread_startup();
  83. return 0;
  84. }