startup.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2009-01-05 Bernard first implementation
  9. * 2010-04-09 fify for M16C
  10. */
  11. #include <rthw.h>
  12. #include <rtthread.h>
  13. #include "iom16c62p.h"
  14. #include "board.h"
  15. #include "bsp.h"
  16. extern void rt_hw_interrupt_init(void);
  17. extern int rt_application_init(void);
  18. #ifdef RT_USING_FINSH
  19. extern int finsh_system_init(void);
  20. extern void finsh_set_device(const char* device);
  21. #endif
  22. #ifdef RT_USING_HEAP
  23. #if (defined (__ICCM16C__))
  24. #pragma section="DATA16_HEAP"
  25. #elif (defined (__GNUC__))
  26. extern unsigned char user_ram_end;
  27. #endif
  28. #endif
  29. /**
  30. * This function will startup RT-Thread RTOS.
  31. */
  32. void rtthread_startup(void)
  33. {
  34. /* init hardware interrupt */
  35. rt_hw_interrupt_init();
  36. /* init board */
  37. rt_hw_board_init();
  38. /* show version */
  39. rt_show_version();
  40. /* init timer system */
  41. rt_system_timer_init();
  42. #ifdef RT_USING_HEAP
  43. #ifdef __ICCM16C__
  44. rt_system_heap_init(__segment_begin("DATA16_HEAP"), __segment_end("DATA16_HEAP"));
  45. #elif (defined (__GNUC__))
  46. rt_system_heap_init((void*)&user_ram_end, (void*)M16C62P_SRAM_END);
  47. #endif
  48. #endif
  49. /* init scheduler system */
  50. rt_system_scheduler_init();
  51. /* init application */
  52. rt_application_init();
  53. #ifdef RT_USING_FINSH
  54. /* init finsh */
  55. finsh_system_init();
  56. #if !defined(RT_USING_POSIX_STDIO) && defined(RT_USING_DEVICE)
  57. finsh_set_device("uart0");
  58. #endif
  59. #endif
  60. /* init timer thread */
  61. rt_system_timer_thread_init();
  62. /* init idle thread */
  63. rt_thread_idle_init();
  64. /* start scheduler */
  65. rt_system_scheduler_start();
  66. /* never reach here */
  67. return ;
  68. }
  69. int main(void)
  70. {
  71. /* disable interrupt first */
  72. rt_hw_interrupt_disable();
  73. /* init system setting */
  74. system_init();
  75. /* startup RT-Thread RTOS */
  76. rtthread_startup();
  77. return 0;
  78. }