application.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*
  2. * File : app.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://openlab.rt-thread.com/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 s3ceb2410
  17. */
  18. /*@{*/
  19. #include <rtthread.h>
  20. #ifdef RT_USING_RTGUI
  21. #include <rtgui/rtgui.h>
  22. #endif
  23. #ifdef RT_USING_DFS
  24. /* dfs init */
  25. #include <dfs_init.h>
  26. /* dfs filesystem:FAT filesystem init */
  27. #include <dfs_fat.h>
  28. /* dfs filesystem:EFS filesystem init */
  29. #include <dfs_efs.h>
  30. /* dfs Filesystem APIs */
  31. #include <dfs_fs.h>
  32. void dfs_init_entry(void* parameter)
  33. {
  34. /* init the device filesystem */
  35. dfs_init();
  36. /* init the fat filesystem */
  37. fatfs_init();
  38. /* init the efsl filesystam*/
  39. efsl_init();
  40. /* mount sd card fat partition 1 as root directory */
  41. dfs_mount("sd1", "/", "efs", 0, 0);
  42. /* mount sd card fat partition 0 */
  43. //dfs_mount("sd0", "/DEV", "efs", 0, 0);
  44. rt_kprintf("File System initialized!\n");
  45. }
  46. #endif
  47. #ifdef RT_USING_LWIP
  48. #include "lwip/sys.h"
  49. #include "lwip/api.h"
  50. #ifdef RT_USING_WEBSERVER
  51. extern void thread_webserver(void *parameter);
  52. #endif
  53. #ifdef RT_USING_FTPSERVER
  54. extern void thread_ftpserver(void *parameter);
  55. #endif
  56. void thread_tcpecho(void *parameter)
  57. {
  58. struct netconn *conn, *newconn;
  59. err_t err;
  60. /* Create a new connection identifier. */
  61. conn = netconn_new(NETCONN_TCP);
  62. /* Bind connection to well known port number 7. */
  63. netconn_bind(conn, NULL, 7);
  64. /* Tell connection to go into listening mode. */
  65. netconn_listen(conn);
  66. while(1)
  67. {
  68. /* Grab new connection. */
  69. newconn = netconn_accept(conn);
  70. /* Process the new connection. */
  71. if(newconn != NULL)
  72. {
  73. struct netbuf *buf;
  74. void *data;
  75. u16_t len;
  76. while((buf = netconn_recv(newconn)) != NULL)
  77. {
  78. do
  79. {
  80. netbuf_data(buf, &data, &len);
  81. err = netconn_write(newconn, data, len, NETCONN_COPY);
  82. if(err != ERR_OK){}
  83. }
  84. while(netbuf_next(buf) >= 0);
  85. netbuf_delete(buf);
  86. }
  87. /* Close connection and discard connection identifier. */
  88. netconn_delete(newconn);
  89. }
  90. }
  91. }
  92. void lwip_init_entry(void* parameter)
  93. {
  94. /* init lwip system */
  95. lwip_sys_init();
  96. rt_kprintf("TCP/IP initialized!\n");
  97. }
  98. #endif
  99. /* application start function */
  100. void rt_application_init()
  101. {
  102. #ifdef RT_USING_DFS
  103. rt_thread_t dfs_init;
  104. dfs_init = rt_thread_create("tdfs",
  105. dfs_init_entry, RT_NULL,
  106. 2048, 150, 20);
  107. rt_thread_startup(dfs_init);
  108. #endif
  109. #ifdef RT_USING_LWIP
  110. rt_thread_t lwip_init;
  111. rt_thread_t echo;
  112. lwip_init = rt_thread_create("tlwip",
  113. lwip_init_entry, RT_NULL,
  114. 1024, 100,20);
  115. rt_thread_startup(lwip_init);
  116. echo = rt_thread_create("echo",
  117. thread_tcpecho, RT_NULL,
  118. 1024, 200,20);
  119. rt_thread_startup(echo);
  120. #ifdef RT_USING_WEBSERVER
  121. rt_thread_t webserver;
  122. webserver = rt_thread_create("twebserv",
  123. thread_webserver, RT_NULL,
  124. 4096, 140, 20);
  125. rt_thread_startup(webserver);
  126. #endif
  127. #ifdef RT_USING_FTPSERVER
  128. rt_thread_t ftpserver;
  129. ftpserver = rt_thread_create("tftpserv",
  130. thread_ftpserver, RT_NULL,
  131. 1024, 200, 20);
  132. rt_thread_startup(ftpserver);
  133. #endif
  134. #endif
  135. #ifdef RT_USING_RTGUI
  136. {
  137. rtgui_rect_t rect;
  138. /* init rtgui system */
  139. rtgui_system_server_init();
  140. /* init graphic driver */
  141. rt_hw_lcd_init();
  142. /* register dock panel */
  143. rect.x1 = 0;
  144. rect.y1 = 0;
  145. rect.x2 = 240;
  146. rect.y2 = 25;
  147. rtgui_panel_register("dock", &rect);
  148. /* register main panel */
  149. rect.x1 = 0;
  150. rect.y1 = 25;
  151. rect.x2 = 240;
  152. rect.y2 = 320;
  153. rtgui_panel_register("main", &rect);
  154. rtgui_system_app_init();
  155. }
  156. #endif
  157. }
  158. /*@}*/