startup.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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-03-04 Magicoe for LPC17xx
  14. */
  15. #include <rthw.h>
  16. #include <rtthread.h>
  17. #include "lpc17xx.h"
  18. #include "board.h"
  19. #ifdef RT_USING_DFS
  20. #include "sd.h"
  21. #endif
  22. /**
  23. * @addtogroup LPC17
  24. */
  25. /*@{*/
  26. extern int rt_application_init(void);
  27. #ifdef RT_USING_FINSH
  28. extern void finsh_system_init(void);
  29. extern void finsh_set_device(const char* device);
  30. #endif
  31. #ifdef __CC_ARM
  32. extern int Image$$RW_IRAM1$$ZI$$Limit;
  33. #elif __ICCARM__
  34. #pragma section="HEAP"
  35. #else
  36. extern int __bss_end;
  37. #endif
  38. #ifdef DEBUG
  39. /*******************************************************************************
  40. * Function Name : assert_failed
  41. * Description : Reports the name of the source file and the source line number
  42. * where the assert error has occurred.
  43. * Input : - file: pointer to the source file name
  44. * - line: assert error line source number
  45. * Output : None
  46. * Return : None
  47. *******************************************************************************/
  48. void assert_failed(u8* file, u32 line)
  49. {
  50. rt_kprintf("\n\r Wrong parameter value detected on\r\n");
  51. rt_kprintf(" file %s\r\n", file);
  52. rt_kprintf(" line %d\r\n", line);
  53. while (1) ;
  54. }
  55. #endif
  56. /**
  57. * This function will startup RT-Thread RTOS.
  58. */
  59. void rtthread_startup(void)
  60. {
  61. /* init board */
  62. rt_hw_board_init();
  63. /* show version */
  64. rt_show_version();
  65. /* init tick */
  66. rt_system_tick_init();
  67. /* init kernel object */
  68. rt_system_object_init();
  69. /* init timer system */
  70. rt_system_timer_init();
  71. #ifdef RT_USING_HEAP
  72. #ifdef __CC_ARM
  73. rt_system_heap_init((void*)&Image$$RW_IRAM1$$ZI$$Limit, (void*)0x10008000);
  74. #elif __ICCARM__
  75. rt_system_heap_init(__segment_end("HEAP"), (void*)0x10008000);
  76. #else
  77. /* init memory system */
  78. rt_system_heap_init((void*)&__bss_end, (void*)0x10008000);
  79. #endif
  80. #endif
  81. /* init scheduler system */
  82. rt_system_scheduler_init();
  83. #ifdef RT_USING_DEVICE
  84. #ifdef RT_USING_DFS
  85. rt_hw_sdcard_init();
  86. #endif
  87. /* init all device */
  88. rt_device_init_all();
  89. #endif
  90. /* init application */
  91. rt_application_init();
  92. #ifdef RT_USING_FINSH
  93. /* init finsh */
  94. finsh_system_init();
  95. finsh_set_device("uart0");
  96. #endif
  97. /* init timer thread */
  98. rt_system_timer_thread_init();
  99. /* init idle thread */
  100. rt_thread_idle_init();
  101. /* start scheduler */
  102. rt_system_scheduler_start();
  103. /* never reach here */
  104. return ;
  105. }
  106. int main(void)
  107. {
  108. rt_uint32_t UNUSED level;
  109. /* disable interrupt first */
  110. level = rt_hw_interrupt_disable();
  111. /* init system setting */
  112. SystemInit();
  113. /* startup RT-Thread RTOS */
  114. rtthread_startup();
  115. return 0;
  116. }
  117. /*@}*/