application.c 2.8 KB

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