application.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * File : application.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006, 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. * 2007-11-20 Yi.Qiu add rtgui application
  13. * 2008-6-28 Bernard no rtgui init
  14. */
  15. /**
  16. * @addtogroup mini2440
  17. */
  18. /*@{*/
  19. #include <board.h>
  20. #include <rtthread.h>
  21. #include "led.h"
  22. #ifdef RT_USING_DFS
  23. /* dfs init */
  24. #include <dfs_init.h>
  25. /* dfs filesystem:EFS filesystem init */
  26. #include <dfs_efs.h>
  27. /* dfs Filesystem APIs */
  28. #include <dfs_fs.h>
  29. #endif
  30. #ifdef RT_USING_LWIP
  31. #include <netif/ethernetif.h>
  32. #endif
  33. #ifdef RT_USING_RTGUI
  34. extern void rt_hw_lcd_init(void);
  35. extern void rt_hw_key_init(void);
  36. #endif
  37. void rt_init_thread_entry(void* parameter)
  38. {
  39. /* Filesystem Initialization */
  40. #ifdef RT_USING_DFS
  41. {
  42. /* init the device filesystem */
  43. dfs_init();
  44. #ifdef RT_USING_DFS_EFSL
  45. /* init the efsl filesystam*/
  46. efsl_init();
  47. /* mount sd card fat partition 1 as root directory */
  48. if (dfs_mount("sd0", "/", "efs", 0, 0) == 0)
  49. {
  50. rt_kprintf("File System initialized!\n");
  51. }
  52. else
  53. rt_kprintf("File System initialzation failed!\n");
  54. #elif defined(RT_USING_DFS_ELMFAT)
  55. /* init the elm chan FatFs filesystam*/
  56. elm_init();
  57. /* mount sd card fat partition 1 as root directory */
  58. if (dfs_mount("sd0", "/", "elm", 0, 0) == 0)
  59. {
  60. rt_kprintf("File System initialized!\n");
  61. }
  62. else
  63. rt_kprintf("File System initialzation failed!\n");
  64. #endif
  65. }
  66. #endif
  67. #ifdef RT_USING_RTGUI
  68. {
  69. rt_hw_key_init();
  70. }
  71. #endif
  72. /* LwIP Initialization */
  73. #ifdef RT_USING_LWIP
  74. {
  75. extern void lwip_sys_init(void);
  76. eth_system_device_init();
  77. /* register ethernetif device */
  78. rt_hw_dm9000_init();
  79. /* re-init device driver */
  80. rt_device_init_all();
  81. /* init lwip system */
  82. lwip_sys_init();
  83. rt_kprintf("TCP/IP initialized!\n");
  84. }
  85. #endif
  86. }
  87. void rt_led_thread_entry(void* parameter)
  88. {
  89. while(1)
  90. {
  91. /* light on leds for one second */
  92. rt_hw_led_on(LED2|LED3);
  93. rt_hw_led_off(LED1|LED4);
  94. rt_thread_delay(100);
  95. /* light off leds for one second */
  96. rt_hw_led_off(LED2|LED3);
  97. rt_hw_led_on(LED1|LED4);
  98. rt_thread_delay(100);
  99. }
  100. }
  101. int rt_application_init()
  102. {
  103. rt_thread_t init_thread;
  104. rt_thread_t led_thread;
  105. #ifdef RT_USING_RTGUI
  106. rt_hw_lcd_init();
  107. #endif
  108. #if (RT_THREAD_PRIORITY_MAX == 32)
  109. init_thread = rt_thread_create("init",
  110. rt_init_thread_entry, RT_NULL,
  111. 2048, 8, 20);
  112. led_thread = rt_thread_create("led",
  113. rt_led_thread_entry, RT_NULL,
  114. 512, 20, 20);
  115. #else
  116. init_thread = rt_thread_create("init",
  117. rt_init_thread_entry, RT_NULL,
  118. 2048, 80, 20);
  119. led_thread = rt_thread_create("led",
  120. rt_led_thread_entry, RT_NULL,
  121. 512, 200, 20);
  122. #endif
  123. if (init_thread != RT_NULL)
  124. rt_thread_startup(init_thread);
  125. if(led_thread != RT_NULL)
  126. rt_thread_startup(led_thread);
  127. return 0;
  128. }
  129. /*@}*/