application.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 the first version
  9. * 2010-03-04 Magicoe for LPC1766 version
  10. * 2010-05-02 Aozima add led function
  11. * 2010-05-24 Bernard add filesystem initialization and move led function to led.c
  12. * 2012-04-15 Bernard enable components_init.
  13. */
  14. #include <rtthread.h>
  15. #include "platform.h"
  16. #ifdef RT_USING_LWIP
  17. #include <emac.h>
  18. #include <netif/ethernetif.h>
  19. extern int lwip_system_init(void);
  20. #endif
  21. #ifdef RT_USING_DFS
  22. #include <dfs_fs.h>
  23. #include <dfs.h>
  24. #include <sd.h>
  25. #ifdef RT_USING_DFS_ELMFAT
  26. #include <dfs_elm.h>
  27. #endif
  28. #endif
  29. #ifdef RT_USING_FINSH
  30. #include <shell.h>
  31. #include <finsh.h>
  32. #endif
  33. /* thread phase init */
  34. void rt_init_thread_entry(void *parameter)
  35. {
  36. /* initialize platform */
  37. platform_init();
  38. #ifdef RT_USING_LWIP
  39. /* register Ethernet interface device */
  40. lpc17xx_emac_hw_init();
  41. /* initialize lwip stack */
  42. /* register ethernetif device */
  43. eth_system_device_init();
  44. /* initialize lwip system */
  45. lwip_system_init();
  46. rt_kprintf("TCP/IP initialized!\n");
  47. #endif
  48. /* Filesystem Initialization */
  49. #ifdef RT_USING_DFS
  50. rt_hw_sdcard_init();
  51. /* initialize the device file system */
  52. dfs_init();
  53. #ifdef RT_USING_DFS_ELMFAT
  54. /* initialize the elm chan FatFS file system*/
  55. elm_init();
  56. #endif
  57. /* mount sd card fat partition 1 as root directory */
  58. if (dfs_mount("sd0", "/", "elm", 0, 0) == 0)
  59. rt_kprintf("File System initialized!\n");
  60. else
  61. rt_kprintf("File System init failed!\n");
  62. #endif
  63. #ifdef RT_USING_FINSH
  64. /* initialize finsh */
  65. finsh_system_init();
  66. #endif
  67. }
  68. int rt_application_init()
  69. {
  70. rt_thread_t tid;
  71. tid = rt_thread_create("init",
  72. rt_init_thread_entry, RT_NULL,
  73. 2048, RT_THREAD_PRIORITY_MAX/3, 20);
  74. if (tid != RT_NULL) rt_thread_startup(tid);
  75. return 0;
  76. }