application.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. */
  17. /**
  18. * @addtogroup LPC17
  19. */
  20. /*@{*/
  21. #include <rtthread.h>
  22. #ifdef RT_USING_DFS
  23. /* dfs init */
  24. #include <dfs_init.h>
  25. /* dfs filesystem:ELM FatFs filesystem init */
  26. #include <dfs_elm.h>
  27. /* dfs Filesystem APIs */
  28. #include <dfs_fs.h>
  29. #endif
  30. #ifdef RT_USING_LWIP
  31. #include <lwip/sys.h>
  32. #include <lwip/api.h>
  33. #include <netif/ethernetif.h>
  34. #endif
  35. /* thread phase init */
  36. void rt_init_thread_entry(void *parameter)
  37. {
  38. // unsigned int count=0;
  39. //
  40. // while (1)
  41. // {
  42. // /* led1 on */
  43. // rt_kprintf("on count : %d\r\n",count);
  44. // count++;
  45. // rt_thread_delay( RT_TICK_PER_SECOND/2 ); /* sleep 0.5 second and switch to other thread */
  46. //
  47. // /* led1 off */
  48. // rt_kprintf("led off\r\n");
  49. // rt_thread_delay( RT_TICK_PER_SECOND/2 );
  50. // }
  51. /* Filesystem Initialization */
  52. #ifdef RT_USING_DFS
  53. {
  54. /* init the device filesystem */
  55. dfs_init();
  56. /* init the elm FAT filesystam*/
  57. elm_init();
  58. /* mount sd card fat partition 1 as root directory */
  59. if (dfs_mount("sd0", "/", "elm", 0, 0) == 0)
  60. rt_kprintf("File System initialized!\n");
  61. else
  62. rt_kprintf("File System init failed!\n");
  63. }
  64. #endif
  65. /* LwIP Initialization */
  66. #ifdef RT_USING_LWIP
  67. {
  68. extern void lwip_sys_init(void);
  69. extern void lpc17xx_emac_hw_init(void);
  70. eth_system_device_init();
  71. /* register ethernetif device */
  72. lpc17xx_emac_hw_init();
  73. /* init all device */
  74. rt_device_init_all();
  75. /* init lwip system */
  76. lwip_sys_init();
  77. rt_kprintf("TCP/IP initialized!\n");
  78. }
  79. #endif
  80. }
  81. int rt_application_init()
  82. {
  83. rt_thread_t init_thread;
  84. #if (RT_THREAD_PRIORITY_MAX == 32)
  85. init_thread = rt_thread_create("init",
  86. rt_init_thread_entry, RT_NULL,
  87. 2048, 8, 20);
  88. #else
  89. init_thread = rt_thread_create("init",
  90. rt_init_thread_entry, RT_NULL,
  91. 2048, 80, 20);
  92. #endif
  93. if (init_thread != RT_NULL) rt_thread_startup(init_thread);
  94. return 0;
  95. }
  96. /*@}*/