]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A9_Zynq_ZC702/RTOSDemo/src/lwIP_Demo/lwIP_port/netif/xadapter.c
Remove obsolete MPU demos.
[freertos] / FreeRTOS / Demo / CORTEX_A9_Zynq_ZC702 / RTOSDemo / src / lwIP_Demo / lwIP_port / netif / xadapter.c
1 /*
2  * Copyright (c) 2007-2013 Xilinx, Inc.  All rights reserved.
3  *
4  * Xilinx, Inc.
5  * XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS" AS A
6  * COURTESY TO YOU.  BY PROVIDING THIS DESIGN, CODE, OR INFORMATION AS
7  * ONE POSSIBLE   IMPLEMENTATION OF THIS FEATURE, APPLICATION OR
8  * STANDARD, XILINX IS MAKING NO REPRESENTATION THAT THIS IMPLEMENTATION
9  * IS FREE FROM ANY CLAIMS OF INFRINGEMENT, AND YOU ARE RESPONSIBLE
10  * FOR OBTAINING ANY RIGHTS YOU MAY REQUIRE FOR YOUR IMPLEMENTATION.
11  * XILINX EXPRESSLY DISCLAIMS ANY WARRANTY WHATSOEVER WITH RESPECT TO
12  * THE ADEQUACY OF THE IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO
13  * ANY WARRANTIES OR REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE
14  * FROM CLAIMS OF INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY
15  * AND FITNESS FOR A PARTICULAR PURPOSE.
16  *
17  */
18
19 #include "lwipopts.h"
20 #include "xlwipconfig.h"
21
22 #if !NO_SYS
23 #ifdef OS_IS_XILKERNEL
24 #include "xmk.h"
25 #include "sys/process.h"
26 #endif
27 #endif
28
29 #include "lwip/mem.h"
30 #include "lwip/stats.h"
31 #include "lwip/sys.h"
32 #include "lwip/ip.h"
33 #include "lwip/tcp.h"
34 #include "lwip/udp.h"
35 #include "lwip/tcp_impl.h"
36
37 #include "netif/etharp.h"
38 #include "netif/xadapter.h"
39
40 #ifdef XLWIP_CONFIG_INCLUDE_EMACLITE
41 #include "netif/xemacliteif.h"
42 #endif
43
44 #ifdef XLWIP_CONFIG_INCLUDE_TEMAC
45 #include "netif/xlltemacif.h"
46 #endif
47
48 #ifdef XLWIP_CONFIG_INCLUDE_AXI_ETHERNET
49 #include "netif/xaxiemacif.h"
50 #endif
51
52 #ifdef XLWIP_CONFIG_INCLUDE_GEM
53 #include "netif/xemacpsif.h"
54 #endif
55
56 #if !NO_SYS
57 #include "lwip/tcpip.h"
58 #endif
59
60
61 /* global lwip debug variable used for debugging */
62 int lwip_runtime_debug = 0;
63
64 void
65 lwip_raw_init()
66 {
67         ip_init();      /* Doesn't do much, it should be called to handle future changes. */
68 #if LWIP_UDP
69         udp_init();     /* Clears the UDP PCB list. */
70 #endif
71 #if LWIP_TCP
72         tcp_init();     /* Clears the TCP PCB list and clears some internal TCP timers. */
73                         /* Note: you must call tcp_fasttmr() and tcp_slowtmr() at the */
74                         /* predefined regular intervals after this initialization. */
75 #endif
76 }
77
78 static enum xemac_types
79 find_mac_type(unsigned base)
80 {
81         int i;
82
83         for (i = 0; i < xtopology_n_emacs; i++) {
84                 if (xtopology[i].emac_baseaddr == base)
85                         return xtopology[i].emac_type;
86         }
87
88         return xemac_type_unknown;
89 }
90
91 int
92 xtopology_find_index(unsigned base)
93 {
94         int i;
95
96         for (i = 0; i < xtopology_n_emacs; i++) {
97                 if (xtopology[i].emac_baseaddr == base)
98                         return i;
99         }
100
101         return -1;
102 }
103
104 /*
105  * xemac_add: this is a wrapper around lwIP's netif_add function.
106  * The objective is to provide portability between the different Xilinx MAC's
107  * This function can be used to add both xps_ethernetlite and xps_ll_temac
108  * based interfaces
109  */
110 struct netif *
111 xemac_add(struct netif *netif,
112         struct ip_addr *ipaddr, struct ip_addr *netmask, struct ip_addr *gw,
113         unsigned char *mac_ethernet_address,
114         unsigned mac_baseaddr)
115 {
116         int i;
117
118         /* set mac address */
119         netif->hwaddr_len = 6;
120         for (i = 0; i < 6; i++)
121                 netif->hwaddr[i] = mac_ethernet_address[i];
122
123         /* initialize based on MAC type */
124                 switch (find_mac_type(mac_baseaddr)) {
125                         case xemac_type_xps_emaclite:
126 #ifdef XLWIP_CONFIG_INCLUDE_EMACLITE
127                                 return netif_add(netif, ipaddr, netmask, gw,
128                                         (void*)mac_baseaddr,
129                                         xemacliteif_init,
130 #if NO_SYS
131                                         ethernet_input
132 #else
133                                         tcpip_input
134 #endif
135                                         );
136 #else
137                                 return NULL;
138 #endif
139                         case xemac_type_xps_ll_temac:
140 #ifdef XLWIP_CONFIG_INCLUDE_TEMAC
141                                 return netif_add(netif, ipaddr, netmask, gw,
142                                         (void*)mac_baseaddr,
143                                         xlltemacif_init,
144 #if NO_SYS
145                                         ethernet_input
146 #else
147                                         tcpip_input
148 #endif
149                                         );
150 #else
151                                 return NULL;
152 #endif
153                         case xemac_type_axi_ethernet:
154 #ifdef XLWIP_CONFIG_INCLUDE_AXI_ETHERNET
155                                 return netif_add(netif, ipaddr, netmask, gw,
156                                         (void*)mac_baseaddr,
157                                         xaxiemacif_init,
158 #if NO_SYS
159                                         ethernet_input
160 #else
161                                         tcpip_input
162 #endif
163                                         );
164 #else
165                                 return NULL;
166 #endif
167 #ifdef __arm__
168                         case xemac_type_emacps:
169 #ifdef XLWIP_CONFIG_INCLUDE_GEM
170                                 return netif_add(netif, ipaddr, netmask, gw,
171                                                 (void*)mac_baseaddr,
172                                                 xemacpsif_init,
173 #if NO_SYS
174                                                 ethernet_input
175 #else
176                                                 tcpip_input
177 #endif
178
179                                                 );
180 #endif
181 #endif
182                         default:
183                                 printf("unable to determine type of EMAC with baseaddress 0x%08x\r\n",
184                                                 mac_baseaddr);
185                                 return NULL;
186         }
187 }
188
189 #if !NO_SYS
190 /*
191  * The input thread calls lwIP to process any received packets.
192  * This thread waits until a packet is received (sem_rx_data_available),
193  * and then calls xemacif_input which processes 1 packet at a time.
194  */
195 void
196 xemacif_input_thread(struct netif *netif)
197 {
198         struct xemac_s *emac = (struct xemac_s *)netif->state;
199         while (1) {
200                 /* sleep until there are packets to process
201                  * This semaphore is set by the packet receive interrupt
202                  * routine.
203                  */
204                 sys_arch_sem_wait( &emac->sem_rx_data_available, 250 / portTICK_PERIOD_MS );
205
206                 /* move all received packets to lwIP */
207                 xemacif_input(netif);
208         }
209 }
210 #endif
211
212 int
213 xemacif_input(struct netif *netif)
214 {
215         struct xemac_s *emac = (struct xemac_s *)netif->state;
216         SYS_ARCH_DECL_PROTECT(lev);
217
218         int n_packets = 0;
219
220         switch (emac->type) {
221                 case xemac_type_xps_emaclite:
222 #ifdef XLWIP_CONFIG_INCLUDE_EMACLITE
223                         SYS_ARCH_PROTECT(lev);
224                         n_packets = xemacliteif_input(netif);
225                         SYS_ARCH_UNPROTECT(lev);
226                         break;
227 #else
228                         print("incorrect configuration: xps_ethernetlite drivers not present?");
229                         while(1);
230                         return 0;
231 #endif
232                 case xemac_type_xps_ll_temac:
233 #ifdef XLWIP_CONFIG_INCLUDE_TEMAC
234                         SYS_ARCH_PROTECT(lev);
235                         n_packets = xlltemacif_input(netif);
236                         SYS_ARCH_UNPROTECT(lev);
237                         break;
238 #else
239                         print("incorrect configuration: xps_ll_temac drivers not present?");
240                         while(1);
241                         return 0;
242 #endif
243                 case xemac_type_axi_ethernet:
244 #ifdef XLWIP_CONFIG_INCLUDE_AXI_ETHERNET
245                         SYS_ARCH_PROTECT(lev);
246                         n_packets = xaxiemacif_input(netif);
247                         SYS_ARCH_UNPROTECT(lev);
248                         break;
249 #else
250                         print("incorrect configuration: axi_ethernet drivers not present?");
251                         while(1);
252                         return 0;
253 #endif
254 #ifdef __arm__
255                 case xemac_type_emacps:
256 #ifdef XLWIP_CONFIG_INCLUDE_GEM
257                         SYS_ARCH_PROTECT(lev);
258                         n_packets = xemacpsif_input(netif);
259                         SYS_ARCH_UNPROTECT(lev);
260                         break;
261 #else
262                         xil_printf("incorrect configuration: ps7_ethernet drivers not present?\r\n");
263                         while(1);
264                         return 0;
265 #endif
266 #endif
267                 default:
268                         print("incorrect configuration: unknown temac type");
269                         while(1);
270                         return 0;
271         }
272
273         return n_packets;
274 }