startup.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. * 2006-08-31 Bernard first implementation
  13. */
  14. #include <rthw.h>
  15. #include <rtthread.h>
  16. #include "board.h"
  17. #include "rtc.h"
  18. #ifdef RT_USING_LWIP
  19. #include <netif/ethernetif.h>
  20. #include "enc28j60.h"
  21. #endif
  22. /**
  23. * @addtogroup STM32
  24. */
  25. /*@{*/
  26. #ifdef RT_USING_FINSH
  27. extern void finsh_system_init(void);
  28. extern void finsh_set_device(char* device);
  29. #endif
  30. extern int rt_application_init(void);
  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*)0x20005000);
  74. #elif __ICCARM__
  75. rt_system_heap_init(__segment_end("HEAP"), (void*)0x20005000);
  76. #else
  77. /* init memory system */
  78. rt_system_heap_init((void*)&__bss_end, (void*)0x20005000);
  79. #endif
  80. #endif
  81. /* init scheduler system */
  82. rt_system_scheduler_init();
  83. #ifdef RT_USING_LWIP
  84. eth_system_device_init();
  85. /* register ethernetif device */
  86. rt_hw_enc28j60_init();
  87. #endif
  88. rt_hw_rtc_init();
  89. /* init hardware serial device */
  90. rt_hw_usart_init();
  91. #ifdef RT_USING_DFS
  92. rt_hw_sdcard_init();
  93. #endif
  94. /* init all device */
  95. rt_device_init_all();
  96. /* init application */
  97. rt_application_init();
  98. #ifdef RT_USING_FINSH
  99. /* init finsh */
  100. finsh_system_init();
  101. finsh_set_device("uart1");
  102. #endif
  103. /* init idle thread */
  104. rt_thread_idle_init();
  105. /* start scheduler */
  106. rt_system_scheduler_start();
  107. /* never reach here */
  108. return ;
  109. }
  110. int main(void)
  111. {
  112. rt_uint32_t UNUSED level;
  113. /* disable interrupt first */
  114. level = rt_hw_interrupt_disable();
  115. rtthread_startup();
  116. return 0;
  117. }
  118. /*@}*/