xref: /nrf52832-nimble/rt-thread/components/net/uip/rt-thread/uIPmain.c (revision 104654410c56c573564690304ae786df310c91fc)
1 /*
2  * Copyright (c) 2001, Adam Dunkels.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *      This product includes software developed by Adam Dunkels.
16  * 4. The name of the author may not be used to endorse or promote
17  *    products derived from this software without specific prior
18  *    written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
21  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
24  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
26  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * This file is part of the uIP TCP/IP stack.
33  *
34  * $Id: main.c,v 1.16 2006/06/11 21:55:03 adam Exp $
35  *
36  */
37 #include "uip.h"
38 #include "uip_arp.h"
39 #include "stm32_eth.h"
40 #include "rtconfig.h"
41 #include "rtdef.h"
42 #include "uip_timer.h"
43 #include "rtthread.h"
44 
45 
46 
47 
48 
49 #define BUF ((struct uip_eth_hdr *)&uip_buf[0])
50 // Define Prototypes
TransmitPacket(void)51 void TransmitPacket(void)
52 {
53     int i;
54     u8_t data[1500];
55     // Copy the header portion part
56     for(i=0; i < (UIP_LLH_LEN + 40); ++i)
57     {
58          data[i] =  uip_buf[i];
59     }
60     // Copy the data portion part
61     for(; i < uip_len; ++i)
62     {
63         data[i] =  uip_appdata[i - UIP_LLH_LEN - 40 ];
64     }
65     ETH_HandleTxPkt(data,uip_len);
66 }
uip_tcpip_thread(void * parameter)67 void uip_tcpip_thread(void *parameter)
68 {
69     int i;
70     static u8_t cnt;
71     while(1)
72     {
73         rt_thread_delay(CLOCK_SECOND*5);
74         for (i = 0; i < UIP_CONNS; i++)
75         {
76 	    uip_periodic(i);
77 	/* If the above function invocation resulted in data that
78 	   should be sent out on the network, the global variable
79 	   uip_len is set to a value > 0. */
80 	    if (uip_len > 0)
81             {
82 	        uip_arp_out();
83                 TransmitPacket();
84 	    }
85         }
86 #if UIP_UDP
87         for (i = 0; i < UIP_UDP_CONNS; i++)
88         {
89 	    uip_udp_periodic(i);
90 	/* If the above function invocation resulted in data that
91 	   should be sent out on the network, the global variable
92 	   uip_len is set to a value > 0. */
93 	   if (uip_len > 0)
94            {
95 	      uip_arp_out();
96               TransmitPacket();
97 	   }
98         }
99 #endif /* UIP_UDP */
100       /* Call the ARP timer function every 10 seconds. */
101 	 if (++cnt > 2) uip_arp_timer();
102     }
103 }
104 
sys_thread_new(char * name,void (* thread)(void * arg),void * arg,int stacksize,int prio)105 rt_thread_t sys_thread_new(char *name, void (* thread)(void *arg), void *arg, int stacksize, int prio)
106 {
107     rt_thread_t t;
108     t = rt_thread_create(name, thread, arg, stacksize, prio, 20);
109     RT_ASSERT(t != RT_NULL);
110     rt_thread_startup(t);
111     return t;
112 }
113 
114 
uip_sys_init(void)115 void uip_sys_init(void)
116 {
117 
118     uip_init();         //uip init
119     sys_thread_new("uip",uip_tcpip_thread, RT_NULL, RT_LWIP_TCPTHREAD_STACKSIZE, RT_LWIP_TCPTHREAD_PRIORITY);
120     hello_world_init(); //
121 }
122 
123 /*---------------------------------------------------------------------------*/
uip_log(char * m)124 void uip_log(char *m)
125 {
126     rt_kprintf("uIP log message: %s\n", m);
127 }
128