source: azure_iot_hub_f767zi/trunk/asp_baseplatform/OBJ/STM32F767NUCLEO144_GCC/MAC/lwip_test.c@ 457

Last change on this file since 457 was 457, checked in by coas-nagasima, 4 years ago

ファイルを追加

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-csrc;charset=UTF-8
File size: 19.8 KB
Line 
1/*
2 * TOPPERS/ASP Kernel
3 * Toyohashi Open Platform for Embedded Real-Time Systems/
4 * Advanced Standard Profile Kernel
5 *
6 * Copyright (C) 2000-2003 by Embedded and Real-Time Systems Laboratory
7 * Toyohashi Univ. of Technology, JAPAN
8 * Copyright (C) 2004-2012 by Embedded and Real-Time Systems Laboratory
9 * Graduate School of Information Science, Nagoya Univ., JAPAN
10 * Copyright (C) 2015-2020 by TOPPERS PROJECT Educational Working Group.
11 *
12 * 上記著作権者は,以下の(1)~(4)の条件を満たす場合に限り,本ソフトウェ
13 * ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
14 * 変・再配布(以下,利用と呼ぶ)することを無償で許諾する.
15 * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
16 * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
17 * スコード中に含まれていること.
18 * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
19 * 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
20 * 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
21 * の無保証規定を掲載すること.
22 * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
23 * 用できない形で再配布する場合には,次のいずれかの条件を満たすこ
24 * と.
25 * (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
26 * 作権表示,この利用条件および下記の無保証規定を掲載すること.
27 * (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに
28 * 報告すること.
29 * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
30 * 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
31 * また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理
32 * 由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを
33 * 免責すること.
34 *
35 * 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
36 * よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
37 * に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ
38 * アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
39 * の責任を負わない.
40 *
41 * $Id$
42 */
43
44/*
45 * Copyright (c) 2001-2003 Swedish Institute of Computer Science.
46 * All rights reserved.
47 *
48 * Redistribution and use in source and binary forms, with or without modification,
49 * are permitted provided that the following conditions are met:
50 *
51 * 1. Redistributions of source code must retain the above copyright notice,
52 * this list of conditions and the following disclaimer.
53 * 2. Redistributions in binary form must reproduce the above copyright notice,
54 * this list of conditions and the following disclaimer in the documentation
55 * and/or other materials provided with the distribution.
56 * 3. The name of the author may not be used to endorse or promote products
57 * derived from this software without specific prior written permission.
58 *
59 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
60 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
61 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
62 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
63 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
64 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
65 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
66 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
67 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
68 * OF SUCH DAMAGE.
69 *
70 * This file is part of the lwIP TCP/IP stack.
71 *
72 * Author: Adam Dunkels <adam@sics.se>
73 *
74 */
75
76/*
77 * LWIPテストプログラムの本体
78 */
79
80#include <kernel.h>
81#include <t_syslog.h>
82#include <t_stdlib.h>
83#include <sil.h>
84#include "syssvc/serial.h"
85#include "syssvc/syslog.h"
86#ifdef USE_STORAGEDEVICE
87#include "storagedevice.h"
88#endif /* USE_STORAGEDEVICE */
89#include "device.h"
90#include "sdmmc.h"
91#include "kernel_cfg.h"
92#include "lwip_test.h"
93
94#include "lwip/opt.h"
95
96#include "lwip/init.h"
97
98#include "lwip/mem.h"
99#include "lwip/memp.h"
100#include "lwip/sys.h"
101#include "lwip/timeouts.h"
102
103#include "lwip/ip_addr.h"
104
105#include "lwip/dns.h"
106#include "lwip/dhcp.h"
107
108#include "lwip/stats.h"
109
110#include "lwip/tcp.h"
111#include "lwip/inet_chksum.h"
112
113#include "lwip/tcpip.h"
114#include "lwip/sockets.h"
115
116
117#if 0
118#include "netif/pcapif.h"
119#endif
120
121#ifndef LWIP_HAVE_SLIPIF
122#define LWIP_HAVE_SLIPIF 0
123#endif
124#if LWIP_HAVE_SLIPIF
125#include "netif/slipif.h"
126#define SLIP_PTY_TEST 1
127#endif
128
129#if PPP_SUPPORT
130#include "netif/ppp/pppos.h"
131#include "lwip/sio.h"
132#define PPP_PTY_TEST 1
133#include <termios.h>
134#endif
135
136#include "lwip/ip_addr.h"
137
138#include "lwip/apps/httpd.h"
139#include "apps/udpecho/udpecho.h"
140#include "apps/tcpecho/tcpecho.h"
141#include "apps/shell/shell.h"
142#include "apps/chargen/chargen.h"
143#include "apps/netio/netio.h"
144#include "apps/ping/ping.h"
145#include "lwip/apps/netbiosns.h"
146#include "lwip/apps/mdns.h"
147#include "lwip/apps/sntp.h"
148#include "lwip/apps/snmp.h"
149#include "lwip/apps/snmp_mib2.h"
150#include "examples/snmp/snmp_private_mib/private_mib.h"
151#include "lwip/apps/tftp_server.h"
152
153#if LWIP_RAW
154#include "lwip/icmp.h"
155#include "lwip/raw.h"
156#endif
157
158err_t ethernetif_init(struct netif *netif);
159
160/*
161 * サービスコールのエラーのログ出力
162 */
163Inline void
164svc_perror(const char *file, int_t line, const char *expr, ER ercd)
165{
166 if (ercd < 0) {
167 t_perror(LOG_ERROR, file, line, expr, ercd);
168 }
169}
170
171#define SVC_PERROR(expr) svc_perror(__FILE__, __LINE__, #expr, (expr))
172
173static uint32_t heap_area[HEAP_SIZE/sizeof(uint32_t)];
174
175uint32_t heap_param[2] = {
176 (uint32_t)heap_area,
177 HEAP_SIZE
178};
179
180
181#ifdef _STORAGEDEVICE_H_
182static void storagedev_notice(void *psdev, bool_t sw)
183{
184 syslog_2(LOG_NOTICE, "SD-CARD[%08x] on/off(%d) !", psdev, sw);
185}
186
187static uint32_t get_fat_time(void)
188{
189 int reqtime = 0;
190
191 reqtime = 0x00210000;
192 return reqtime;
193}
194#endif /* _STORAGEDEVICE_H_ */
195
196#if 1 /* ROI DEBUG */
197void sw_int(void)
198{
199 syslog_0(LOG_NOTICE, "## sw_int() ##");
200}
201#endif /* ROI DEBUG */
202
203uint32_t LWIP_RAND(void)
204{
205 return rand();
206}
207
208#if LWIP_SNMP
209static const struct snmp_mib *mibs[] = {
210 &mib2,
211 &mib_private
212};
213#endif /* LWIP_SNMP */
214
215#if LWIP_IPV4
216/* (manual) host IP configuration */
217static ip_addr_t ipaddr, netmask, gw;
218#endif /* LWIP_IPV4 */
219
220struct netif netif;
221
222/* ping out destination cmd option */
223static ip_addr_t ping_addr;
224
225static bool_t tcpip_init_flag = false;
226
227/* nonstatic debug cmd option, exported in lwipopts.h */
228unsigned char debug_flags;
229
230static void init_netifs(void);
231
232#if 0
233static void
234tcp_debug_timeout(void *data)
235{
236 LWIP_UNUSED_ARG(data);
237#if TCP_DEBUG
238 tcp_debug_print_pcbs();
239#endif /* TCP_DEBUG */
240 sys_timeout(5000, tcp_debug_timeout, NULL);
241}
242#endif
243
244/*
245 * gmtime_r関数
246 */
247struct tm *gmtime_r(const time_t *pt, struct tm *ptm);
248
249void
250sntp_set_system_time(u32_t sec)
251{
252 struct tm current_time_val;
253 time_t current_time = (time_t)sec;
254
255 gmtime_r(&current_time, &current_time_val);
256 printf("%04d/%02d/%02d %02d:%02d:%02d\n",
257 current_time_val.tm_year+1900, current_time_val.tm_mon, current_time_val.tm_mday,
258 current_time_val.tm_hour, current_time_val.tm_min, current_time_val.tm_sec);
259}
260
261#if LWIP_MDNS_RESPONDER
262static void
263srv_txt(struct mdns_service *service, void *txt_userdata)
264{
265 err_t res;
266 LWIP_UNUSED_ARG(txt_userdata);
267
268 res = mdns_resp_add_service_txtitem(service, "path=/", 6);
269 LWIP_ERROR("mdns add service txt failed\n", (res == ERR_OK), return);
270}
271#endif
272
273#if LWIP_UDP
274
275static void*
276tftp_open(const char* fname, const char* mode, u8_t is_write)
277{
278#ifdef _STORAGEDEVICE_H_
279 LWIP_UNUSED_ARG(mode);
280
281 if(is_write)
282 return (void*)fopen(fname, "wb");
283 else
284 return (void*)fopen(fname, "rb");
285#else /* _STORAGEDEVICE_H_ */
286 return NULL;
287#endif /* _STORAGEDEVICE_H_ */
288}
289
290static void
291tftp_close(void* handle)
292{
293#ifdef _STORAGEDEVICE_H_
294 fclose((FILE*)handle);
295#endif /* _STORAGEDEVICE_H_ */
296}
297
298static int
299tftp_read(void* handle, void* buf, int bytes)
300{
301#ifdef _STORAGEDEVICE_H_
302 int rlen = fread(buf, 1, bytes, (FILE*)handle);
303 if(rlen <= 0)
304 return -1;
305 else
306 return rlen;
307#else /* _STORAGEDEVICE_H_ */
308 return -1;
309#endif /* _STORAGEDEVICE_H_ */
310}
311
312static int
313tftp_write(void* handle, struct pbuf* p)
314{
315#ifdef _STORAGEDEVICE_H_
316 while(p != NULL){
317 if(fwrite(p->payload, 1, p->len, (FILE*)handle) != (size_t)p->len)
318 return -1;
319 p = p->next;
320 }
321 return 0;
322#else /* _STORAGEDEVICE_H_ */
323 return -1;
324#endif /* _STORAGEDEVICE_H_ */
325}
326
327static const struct tftp_context tftp = {
328 tftp_open,
329 tftp_close,
330 tftp_read,
331 tftp_write
332};
333
334#endif /* LWIP_UDP */
335
336static void
337tcpip_init_done(void *arg)
338{
339 sys_sem_t *sem;
340 sem = (sys_sem_t *)arg;
341
342 init_netifs();
343
344#if LWIP_IPV4
345 netbiosns_set_name("toppershost");
346 netbiosns_init();
347#endif /* LWIP_IPV4 */
348
349 sntp_setoperatingmode(SNTP_OPMODE_POLL);
350#if LWIP_DHCP
351 sntp_servermode_dhcp(1); /* get SNTP server via DHCP */
352#else /* LWIP_DHCP */
353#if LWIP_IPV4
354 sntp_setserver(0, netif_ip_gw4(&netif));
355#endif /* LWIP_IPV4 */
356#endif /* LWIP_DHCP */
357 sntp_init();
358
359#if LWIP_SNMP
360 lwip_privmib_init();
361#if SNMP_LWIP_MIB2
362#if SNMP_USE_NETCONN
363 snmp_threadsync_init(&snmp_mib2_lwip_locks, snmp_mib2_lwip_synchronizer);
364#endif /* SNMP_USE_NETCONN */
365 snmp_mib2_set_syscontact_readonly((const u8_t*)"root", NULL);
366 snmp_mib2_set_syslocation_readonly((const u8_t*)"lwIP development PC", NULL);
367 snmp_mib2_set_sysdescr((const u8_t*)"toppershost", NULL);
368#endif /* SNMP_LWIP_MIB2 */
369
370 snmp_set_mibs(mibs, LWIP_ARRAYSIZE(mibs));
371 snmp_init();
372#endif /* LWIP_SNMP */
373
374#if LWIP_MDNS_RESPONDER
375 mdns_resp_init();
376 mdns_resp_add_netif(&netif, "toppershost", 3600);
377 mdns_resp_add_service(&netif, "myweb", "_http", DNSSD_PROTO_TCP, 80, 3600, srv_txt, NULL);
378#endif
379
380#if LWIP_UDP
381 tftp_init(&tftp);
382#endif /* LWIP_UDP */
383
384 sys_sem_signal(sem);
385}
386
387/*-----------------------------------------------------------------------------------*/
388
389#if LWIP_HAVE_SLIPIF
390/* (manual) host IP configuration */
391#if LWIP_IPV4
392static ip_addr_t ipaddr_slip, netmask_slip, gw_slip;
393#endif /* LWIP_IPV4 */
394struct netif slipif;
395#endif /* LWIP_HAVE_SLIPIF */
396
397#if PPP_SUPPORT
398sio_fd_t ppp_sio;
399ppp_pcb *ppp;
400struct netif pppos_netif;
401
402static void
403pppos_rx_thread(void *arg)
404{
405 u32_t len;
406 u8_t buffer[128];
407 LWIP_UNUSED_ARG(arg);
408
409 /* Please read the "PPPoS input path" chapter in the PPP documentation. */
410 while(1){
411 len = sio_read(ppp_sio, buffer, sizeof(buffer));
412 if (len > 0) {
413 /* Pass received raw characters from PPPoS to be decoded through lwIP
414 * TCPIP thread using the TCPIP API. This is thread safe in all cases
415 * but you should avoid passing data byte after byte. */
416 pppos_input_tcpip(ppp, buffer, len);
417 }
418 }
419}
420
421static void
422ppp_link_status_cb(ppp_pcb *pcb, int err_code, void *ctx)
423{
424 struct netif *pppif = ppp_netif(pcb);
425 LWIP_UNUSED_ARG(ctx);
426
427 switch(err_code) {
428 case PPPERR_NONE: /* No error. */
429 {
430#if LWIP_DNS
431 const ip_addr_t *ns;
432#endif /* LWIP_DNS */
433 fprintf(stderr, "ppp_link_status_cb: PPPERR_NONE\n\r");
434#if LWIP_IPV4
435 fprintf(stderr, " our_ip4addr = %s\n\r", ip4addr_ntoa(netif_ip4_addr(pppif)));
436 fprintf(stderr, " his_ipaddr = %s\n\r", ip4addr_ntoa(netif_ip4_gw(pppif)));
437 fprintf(stderr, " netmask = %s\n\r", ip4addr_ntoa(netif_ip4_netmask(pppif)));
438#endif /* LWIP_IPV4 */
439#if LWIP_IPV6
440 fprintf(stderr, " our_ip6addr = %s\n\r", ip6addr_ntoa(netif_ip6_addr(pppif, 0)));
441#endif /* LWIP_IPV6 */
442
443#if LWIP_DNS
444 ns = dns_getserver(0);
445 fprintf(stderr, " dns1 = %s\n\r", ipaddr_ntoa(ns));
446 ns = dns_getserver(1);
447 fprintf(stderr, " dns2 = %s\n\r", ipaddr_ntoa(ns));
448#endif /* LWIP_DNS */
449#if PPP_IPV6_SUPPORT
450 fprintf(stderr, " our6_ipaddr = %s\n\r", ip6addr_ntoa(netif_ip6_addr(pppif, 0)));
451#endif /* PPP_IPV6_SUPPORT */
452 }
453 break;
454
455 case PPPERR_PARAM: /* Invalid parameter. */
456 printf("ppp_link_status_cb: PPPERR_PARAM\n");
457 break;
458
459 case PPPERR_OPEN: /* Unable to open PPP session. */
460 printf("ppp_link_status_cb: PPPERR_OPEN\n");
461 break;
462
463 case PPPERR_DEVICE: /* Invalid I/O device for PPP. */
464 printf("ppp_link_status_cb: PPPERR_DEVICE\n");
465 break;
466
467 case PPPERR_ALLOC: /* Unable to allocate resources. */
468 printf("ppp_link_status_cb: PPPERR_ALLOC\n");
469 break;
470
471 case PPPERR_USER: /* User interrupt. */
472 printf("ppp_link_status_cb: PPPERR_USER\n");
473 break;
474
475 case PPPERR_CONNECT: /* Connection lost. */
476 printf("ppp_link_status_cb: PPPERR_CONNECT\n");
477 break;
478
479 case PPPERR_AUTHFAIL: /* Failed authentication challenge. */
480 printf("ppp_link_status_cb: PPPERR_AUTHFAIL\n");
481 break;
482
483 case PPPERR_PROTOCOL: /* Failed to meet protocol. */
484 printf("ppp_link_status_cb: PPPERR_PROTOCOL\n");
485 break;
486
487 case PPPERR_PEERDEAD: /* Connection timeout. */
488 printf("ppp_link_status_cb: PPPERR_PEERDEAD\n");
489 break;
490
491 case PPPERR_IDLETIMEOUT: /* Idle Timeout. */
492 printf("ppp_link_status_cb: PPPERR_IDLETIMEOUT\n");
493 break;
494
495 case PPPERR_CONNECTTIME: /* PPPERR_CONNECTTIME. */
496 printf("ppp_link_status_cb: PPPERR_CONNECTTIME\n");
497 break;
498
499 case PPPERR_LOOPBACK: /* Connection timeout. */
500 printf("ppp_link_status_cb: PPPERR_LOOPBACK\n");
501 break;
502
503 default:
504 printf("ppp_link_status_cb: unknown errCode %d\n", err_code);
505 break;
506 }
507}
508
509static u32_t
510ppp_output_cb(ppp_pcb *pcb, u8_t *data, u32_t len, void *ctx)
511{
512 LWIP_UNUSED_ARG(pcb);
513 LWIP_UNUSED_ARG(ctx);
514 return sio_write(ppp_sio, data, len);
515}
516#endif
517
518#if LWIP_NETIF_STATUS_CALLBACK
519static void
520netif_status_callback(struct netif *nif)
521{
522 printf("NETIF: %c%c%d is %s\n", nif->name[0], nif->name[1], nif->num,
523 netif_is_up(nif) ? "UP" : "DOWN");
524#if LWIP_IPV4
525 printf("IPV4: Host at %s ", ip4addr_ntoa(netif_ip4_addr(nif)));
526 printf("mask %s ", ip4addr_ntoa(netif_ip4_netmask(nif)));
527 printf("gateway %s\n", ip4addr_ntoa(netif_ip4_gw(nif)));
528#endif /* LWIP_IPV4 */
529#if LWIP_IPV6
530 printf("IPV6: Host at %s\n", ip6addr_ntoa(netif_ip6_addr(nif, 0)));
531#endif /* LWIP_IPV6 */
532#if LWIP_NETIF_HOSTNAME
533 printf("FQDN: %s\n", netif_get_hostname(nif));
534#endif /* LWIP_NETIF_HOSTNAME */
535
536#if LWIP_MDNS_RESPONDER
537 if(tcpip_init_flag)
538 mdns_resp_netif_settings_changed(nif);
539#endif
540}
541#endif /* LWIP_NETIF_STATUS_CALLBACK */
542
543static void
544init_netifs(void)
545{
546#if LWIP_HAVE_SLIPIF
547#if SLIP_PTY_TEST
548 u8_t siodev_slip = 3;
549#else
550 u8_t siodev_slip = 0;
551#endif
552
553#if LWIP_IPV4
554 netif_add(&slipif, ip_2_ip4(&ipaddr_slip), ip_2_ip4(&netmask_slip), ip_2_ip4(&gw_slip),
555 (void*)&siodev_slip, slipif_init, tcpip_input);
556#else /* LWIP_IPV4 */
557 netif_add(&slipif, (void*)&siodev_slip, slipif_init, tcpip_input);
558#endif /* LWIP_IPV4 */
559#if LWIP_IPV6
560 netif_create_ip6_linklocal_address(&slipif, 1);
561#endif
562#if LWIP_NETIF_STATUS_CALLBACK
563 netif_set_status_callback(&slipif, netif_status_callback);
564#endif /* LWIP_NETIF_STATUS_CALLBACK */
565 netif_set_link_up(&slipif);
566 netif_set_up(&slipif);
567#endif /* LWIP_HAVE_SLIPIF */
568
569#if PPP_SUPPORT
570#if PPP_PTY_TEST
571 ppp_sio = sio_open(2);
572#else
573 ppp_sio = sio_open(0);
574#endif
575 if(!ppp_sio){
576 syslog_0(LOG_ERROR, "Error opening device: ");
577 slp_tsk();
578 }
579
580 ppp = pppos_create(&pppos_netif, ppp_output_cb, ppp_link_status_cb, NULL);
581 if(!ppp){
582 syslog_0(LOG_ERROR, "Could not create PPP control interface");
583 slp_tsk();
584 }
585
586#ifdef LWIP_PPP_CHAP_TEST
587 ppp_set_auth(ppp, PPPAUTHTYPE_CHAP, "lwip", "mysecret");
588#endif
589
590 ppp_connect(ppp, 0);
591
592#if LWIP_NETIF_STATUS_CALLBACK
593 netif_set_status_callback(&pppos_netif, netif_status_callback);
594#endif /* LWIP_NETIF_STATUS_CALLBACK */
595#endif /* PPP_SUPPORT */
596
597#if LWIP_IPV4
598#if LWIP_DHCP
599 IP_ADDR4(&gw, 0,0,0,0);
600 IP_ADDR4(&ipaddr, 0,0,0,0);
601 IP_ADDR4(&netmask, 0,0,0,0);
602#endif /* LWIP_DHCP */
603 netif_add(&netif, ip_2_ip4(&ipaddr), ip_2_ip4(&netmask), ip_2_ip4(&gw), NULL, ethernetif_init, tcpip_input);
604#else /* LWIP_IPV4 */
605 netif_add(&netif, NULL, ethernetif_init, tcpip_input);
606#endif /* LWIP_IPV4 */
607#if LWIP_IPV6
608 netif_create_ip6_linklocal_address(&netif, 1);
609 netif.ip6_autoconfig_enabled = 1;
610#endif
611#if LWIP_NETIF_STATUS_CALLBACK
612 netif_set_status_callback(&netif, netif_status_callback);
613#endif /* LWIP_NETIF_STATUS_CALLBACK */
614 netif_set_default(&netif);
615 netif_set_up(&netif);
616
617#if LWIP_DHCP
618 dhcp_start(&netif);
619#endif /* LWIP_DHCP */
620
621#if 0
622 /* Only used for testing purposes: */
623 netif_add(&ipaddr, &netmask, &gw, NULL, pcapif_init, tcpip_input);
624#endif
625
626#if LWIP_TCP
627 netio_init();
628#endif
629#if LWIP_TCP && LWIP_NETCONN
630 tcpecho_init();
631 shell_init();
632 httpd_init();
633#endif
634#if LWIP_UDP && LWIP_NETCONN
635 udpecho_init();
636#endif
637#if LWIP_SOCKET
638 chargen_init();
639#endif
640 /* sys_timeout(5000, tcp_debug_timeout, NULL);*/
641}
642
643/*-----------------------------------------------------------------------------------*/
644static void
645main_thread(void *arg)
646{
647 sys_sem_t sem;
648 LWIP_UNUSED_ARG(arg);
649
650 if(sys_sem_new(&sem, 0) != ERR_OK) {
651 LWIP_ASSERT("Failed to create semaphore", 0);
652 }
653 tcpip_init(tcpip_init_done, &sem);
654 sys_sem_wait(&sem);
655 syslog_0(LOG_NOTICE, "TCP/IP initialized.");
656
657#if LWIP_SOCKET && defined(USE_PINGSEND)
658 ping_init(&ping_addr);
659#endif
660
661 syslog_0(LOG_NOTICE, "Applications started.");
662
663#ifdef MEM_PERF
664 mem_perf_init("/tmp/memstats.client");
665#endif /* MEM_PERF */
666#if 0
667 stats_display();
668#endif
669#if PPP_SUPPORT
670 /* Block forever. */
671 sys_thread_new("pppos_rx_thread", pppos_rx_thread, NULL, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO);
672 sys_sem_wait(&sem);
673#endif
674 tcpip_init_flag = true;
675}
676
677/*
678 * メインタスク
679 */
680void
681main_task(intptr_t exinf)
682{
683#ifdef _STORAGEDEVICE_H_
684 StorageDevice_t *psdev;
685#endif /* _STORAGEDEVICE_H_ */
686 ER_UINT ercd;
687
688 SVC_PERROR(syslog_msk_log(LOG_UPTO(LOG_NOTICE), LOG_UPTO(LOG_EMERG)));
689 syslog(LOG_NOTICE, "Sample program starts (exinf = %d).", (int_t) exinf);
690
691 /*
692 * シリアルポートの初期化
693 *
694 * システムログタスクと同じシリアルポートを使う場合など,シリアル
695 * ポートがオープン済みの場合にはここでE_OBJエラーになるが,支障は
696 * ない.
697 */
698 ercd = serial_opn_por(TASK_PORTID);
699 if (ercd < 0 && MERCD(ercd) != E_OBJ) {
700 syslog(LOG_ERROR, "%s (%d) reported by `serial_opn_por'.",
701 itron_strerror(ercd), SERCD(ercd));
702 }
703 SVC_PERROR(serial_ctl_por(TASK_PORTID,
704 (IOCTL_CRLF | IOCTL_FCSND | IOCTL_FCRCV)));
705
706#ifdef _STORAGEDEVICE_H_
707 /*
708 * SD-CARDの設定
709 */
710 psdev = SDMGetStorageDevice(0);
711 psdev->_sdev_notice = storagedev_notice;
712 SDeviceHead._get_datetime = get_fat_time;
713#endif /* _STORAGEDEVICE_H_ */
714
715 /* startup defaults (may be overridden by one or more opts) */
716#if LWIP_IPV4
717 IP_ADDR4(&gw, 192,168, 0,1);
718 IP_ADDR4(&netmask, 255,255,255,0);
719 IP_ADDR4(&ipaddr, 192,168, 0,2);
720#if LWIP_HAVE_SLIPIF
721 IP_ADDR4(&gw_slip, 192,168, 2, 1);
722 IP_ADDR4(&netmask_slip, 255,255,255,255);
723 IP_ADDR4(&ipaddr_slip, 192,168, 2, 2);
724#endif
725#endif /* LWIP_IPV4 */
726
727 IP_SET_TYPE_VAL(ping_addr, IPADDR_TYPE_V4);
728 /* use debug flags defined by debug.h */
729 debug_flags = LWIP_DBG_OFF;
730
731 sys_init();
732 sys_thread_new("main_thread", main_thread, NULL, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO);
733
734 syslog(LOG_NOTICE, "Sample program ends.");
735 slp_tsk();
736 SVC_PERROR(ext_ker());
737 assert(0);
738}
Note: See TracBrowser for help on using the repository browser.