startup.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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://openlab.rt-thread.com/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2012-09-03 prife first implementation
  13. */
  14. #include <rthw.h>
  15. #include <rtthread.h>
  16. #include "board.h"
  17. /**
  18. * @addtogroup win32
  19. */
  20. #define HEAP_SIZE (1024*1024*10)
  21. static rt_uint8_t * heap;
  22. void vs_heap_init(void)
  23. {
  24. heap = malloc(HEAP_SIZE);
  25. if (heap == RT_NULL)
  26. rt_kprintf("there is no memory in pc.");
  27. }
  28. /*@{*/
  29. extern int rt_application_init(void);
  30. #ifdef RT_USING_FINSH
  31. extern void finsh_system_init(void);
  32. extern void finsh_set_device(const char* device);
  33. #endif
  34. /**
  35. * This function will startup RT-Thread RTOS.
  36. */
  37. void rtthread_startup(void)
  38. {
  39. /* init board */
  40. rt_hw_board_init();
  41. /* show version */
  42. rt_show_version();
  43. /* init tick */
  44. rt_system_tick_init();
  45. /* init kernel object */
  46. rt_system_object_init();
  47. /* init timer system */
  48. rt_system_timer_init();
  49. #ifdef RT_USING_HEAP
  50. /* init memory system */
  51. #if (MSVC)
  52. vs_heap_init();
  53. #endif
  54. rt_system_heap_init((void*)heap, (void*)&heap[HEAP_SIZE-1]);
  55. #endif
  56. /* init scheduler system */
  57. rt_system_scheduler_init();
  58. /* init all device */
  59. #ifdef RT_USING_DEVICE
  60. rt_device_init_all();
  61. #endif
  62. /* init application */
  63. rt_application_init();
  64. /* init timer thread */
  65. rt_system_timer_thread_init();
  66. /* init idle thread */
  67. rt_thread_idle_init();
  68. /* start scheduler */
  69. rt_system_scheduler_start();
  70. /* never reach here */
  71. return ;
  72. }
  73. int main(void)
  74. {
  75. /* disable interrupt first */
  76. rt_hw_interrupt_disable();
  77. /* startup RT-Thread RTOS */
  78. rtthread_startup();
  79. return 0;
  80. }
  81. /*@}*/