application.c 3.2 KB

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