application.c 2.1 KB

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