1 | /*
|
---|
2 | * TINET (TCP/IP Protocol Stack)
|
---|
3 | *
|
---|
4 | * Copyright (C) 2001-2009 by Dep. of Computer Science and Engineering
|
---|
5 | * Tomakomai National College of Technology, JAPAN
|
---|
6 | * Copyright (C) 2014 Cores Co., Ltd. Japan
|
---|
7 | *
|
---|
8 | * ä¸è¨èä½æ¨©è
|
---|
9 | ã¯ï¼ä»¥ä¸ã®(1)ï½(4)ã®æ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§
|
---|
10 | * ã¢ï¼æ¬ã½ããã¦ã§ã¢ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ã使ç¨ã»è¤è£½ã»æ¹
|
---|
11 | * å¤ã»åé
|
---|
12 | å¸ï¼ä»¥ä¸ï¼å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼
|
---|
13 | * (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½
|
---|
14 | * 権表示ï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼
|
---|
15 | * ã¹ã³ã¼ãä¸ã«å«ã¾ãã¦ãããã¨ï¼
|
---|
16 | * (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
17 | * ç¨ã§ããå½¢ã§åé
|
---|
18 | å¸ããå ´åã«ã¯ï¼åé
|
---|
19 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨
|
---|
20 | * è
|
---|
21 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®èä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨
|
---|
22 | * ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
23 | * (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
24 | * ç¨ã§ããªãå½¢ã§åé
|
---|
25 | å¸ããå ´åã«ã¯ï¼æ¬¡ã®ããããã®æ¡ä»¶ãæºããã
|
---|
26 | * ã¨ï¼
|
---|
27 | * (a) åé
|
---|
28 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨è
|
---|
29 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è
|
---|
30 | * ä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
31 | * (b) åé
|
---|
32 | å¸ã®å½¢æ
|
---|
33 | ãï¼å¥ã«å®ããæ¹æ³ã«ãã£ã¦ï¼TOPPERSããã¸ã§ã¯ãã«
|
---|
34 | * å ±åãããã¨ï¼
|
---|
35 | * (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ
|
---|
36 | * 害ãããï¼ä¸è¨èä½æ¨©è
|
---|
37 | ããã³TOPPERSããã¸ã§ã¯ããå
|
---|
38 | 責ãããã¨ï¼
|
---|
39 | * ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®ã¦ã¼ã¶ã¾ãã¯ã¨ã³ãã¦ã¼ã¶ããã®ãããªãç
|
---|
40 | * ç±ã«åºã¥ãè«æ±ãããï¼ä¸è¨èä½æ¨©è
|
---|
41 | ããã³TOPPERSããã¸ã§ã¯ãã
|
---|
42 | * å
|
---|
43 | 責ãããã¨ï¼
|
---|
44 | *
|
---|
45 | * æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨èä½æ¨©è
|
---|
46 | ã
|
---|
47 | * ãã³TOPPERSããã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ç¹å®ã®ä½¿ç¨ç®ç
|
---|
48 | * ã«å¯¾ããé©åæ§ãå«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§
|
---|
49 | * ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ害ã«é¢ãã¦ãï¼ã
|
---|
50 | * ã®è²¬ä»»ãè² ããªãï¼
|
---|
51 | *
|
---|
52 | * @(#) $Id: if_mbed.c 270 2017-02-09 04:03:47Z coas-nagasima $
|
---|
53 | */
|
---|
54 |
|
---|
55 | /*
|
---|
56 | * Copyright (c) 1995, David Greenman
|
---|
57 | * All rights reserved.
|
---|
58 | *
|
---|
59 | * Redistribution and use in source and binary forms, with or without
|
---|
60 | * modification, are permitted provided that the following conditions
|
---|
61 | * are met:
|
---|
62 | * 1. Redistributions of source code must retain the above copyright
|
---|
63 | * notice unmodified, this list of conditions, and the following
|
---|
64 | * disclaimer.
|
---|
65 | * 2. Redistributions in binary form must reproduce the above copyright
|
---|
66 | * notice, this list of conditions and the following disclaimer in the
|
---|
67 | * documentation and/or other materials provided with the distribution.
|
---|
68 | *
|
---|
69 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
---|
70 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
---|
71 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
---|
72 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
---|
73 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
---|
74 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
---|
75 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
---|
76 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
---|
77 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
---|
78 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
---|
79 | * SUCH DAMAGE.
|
---|
80 | *
|
---|
81 | * $FreeBSD: src/sys/i386/isa/if_mbed.c,v 1.148.2.4 1999/09/25 13:08:18 nyan Exp $
|
---|
82 | */
|
---|
83 |
|
---|
84 | #define CAST(type, val) ((type)(val))
|
---|
85 |
|
---|
86 | #include <kernel.h>
|
---|
87 | #include <sil.h>
|
---|
88 | #include <t_syslog.h>
|
---|
89 | #include "kernel_cfg.h"
|
---|
90 | #include "kernel/kernel_impl.h"
|
---|
91 |
|
---|
92 | #include <tinet_defs.h>
|
---|
93 | #include <tinet_config.h>
|
---|
94 |
|
---|
95 | #include <net/if.h>
|
---|
96 | #include <net/ethernet.h>
|
---|
97 | #include <net/if_arp.h>
|
---|
98 | #include <net/net.h>
|
---|
99 | #include <net/net_timer.h>
|
---|
100 | #include <net/net_count.h>
|
---|
101 | #include <net/net_buf.h>
|
---|
102 | #include <net/ethernet.h>
|
---|
103 |
|
---|
104 | #include "mbed_interface.h"
|
---|
105 | #include "ethernet_api.h"
|
---|
106 | #include "ethernetext_api.h"
|
---|
107 | #include <string.h>
|
---|
108 | #include "if_mbed.h"
|
---|
109 | #include "iodefine.h"
|
---|
110 |
|
---|
111 | #ifdef _MSC_VER
|
---|
112 | #include <stdlib.h>
|
---|
113 | #endif
|
---|
114 |
|
---|
115 | extern uint8_t mac_addr[ETHER_ADDR_LEN];
|
---|
116 |
|
---|
117 | /*
|
---|
118 | * ãããã¯ã¼ã¯ã¤ã³ã¿ãã§ã¼ã¹ã«ä¾åããã½ããã¦ã§ã¢æ
|
---|
119 | å ±
|
---|
120 | */
|
---|
121 |
|
---|
122 | typedef struct t_mbed_softc {
|
---|
123 | bool_t link_pre;
|
---|
124 | bool_t link_now;
|
---|
125 | bool_t over_flow;
|
---|
126 | } T_MBED_SOFTC;
|
---|
127 |
|
---|
128 | /*
|
---|
129 | * ãããã¯ã¼ã¯ã¤ã³ã¿ãã§ã¼ã¹ã®ã½ããã¦ã§ã¢æ
|
---|
130 | å ±
|
---|
131 | */
|
---|
132 |
|
---|
133 | /* ãããã¯ã¼ã¯ã¤ã³ã¿ãã§ã¼ã¹ã«ä¾åããã½ããã¦ã§ã¢æ
|
---|
134 | å ± */
|
---|
135 |
|
---|
136 | static T_MBED_SOFTC mbed_softc;
|
---|
137 |
|
---|
138 | /* ãããã¯ã¼ã¯ã¤ã³ã¿ãã§ã¼ã¹ã«ä¾åããªãã½ããã¦ã§ã¢æ
|
---|
139 | å ± */
|
---|
140 |
|
---|
141 | T_IF_SOFTC if_softc = {
|
---|
142 | {0,}, /* ãããã¯ã¼ã¯ã¤ã³ã¿ãã§ã¼ã¹ã®ã¢ãã¬ã¹ */
|
---|
143 | 0, /* éä¿¡ã¿ã¤ã ã¢ã¦ã */
|
---|
144 | &mbed_softc, /* ãã£ãã¤ã¹ä¾åã®ã½ããã¦ã§ã¢æ
|
---|
145 | å ± */
|
---|
146 | SEM_IF_MBED_SBUF_READY, /* éä¿¡ã»ããã© */
|
---|
147 | SEM_IF_MBED_RBUF_READY, /* åä¿¡ã»ããã© */
|
---|
148 |
|
---|
149 | #ifdef SUPPORT_INET6
|
---|
150 |
|
---|
151 | IF_MADDR_INIT, /* ãã«ããã£ã¹ãã¢ãã¬ã¹ãªã¹ã */
|
---|
152 |
|
---|
153 | #endif /* of #ifdef SUPPORT_INET6 */
|
---|
154 | };
|
---|
155 |
|
---|
156 | /*
|
---|
157 | * å±æå¤æ°
|
---|
158 | */
|
---|
159 |
|
---|
160 | static void if_mbed_stop(T_MBED_SOFTC *sc);
|
---|
161 | static void if_mbed_init_sub(T_IF_SOFTC *ic);
|
---|
162 |
|
---|
163 | #ifdef SUPPORT_INET6
|
---|
164 |
|
---|
165 | static uint32_t ds_crc(uint8_t *addr);
|
---|
166 | static void ds_getmcaf(T_IF_SOFTC *ic, uint32_t *mcaf);
|
---|
167 |
|
---|
168 | /*
|
---|
169 | * ds_crc -- ã¤ã¼ãµãããã¢ãã¬ã¹ã® CRC ãè¨ç®ããã
|
---|
170 | */
|
---|
171 |
|
---|
172 | #define POLYNOMIAL 0x04c11db6
|
---|
173 |
|
---|
174 | static uint32_t
|
---|
175 | ds_crc(uint8_t *addr)
|
---|
176 | {
|
---|
177 | uint32_t crc = ULONG_C(0xffffffff);
|
---|
178 | int_t carry, len, bit;
|
---|
179 | uint8_t byte;
|
---|
180 |
|
---|
181 | for (len = ETHER_ADDR_LEN; len-- > 0; ) {
|
---|
182 | byte = *addr++;
|
---|
183 | for (bit = 8; bit-- > 0; ) {
|
---|
184 | carry = ((crc & ULONG_C(0x80000000)) ? 1 : 0) ^ (byte & UINT_C(0x01));
|
---|
185 | crc <<= 1;
|
---|
186 | byte >>= 1;
|
---|
187 | if (carry)
|
---|
188 | crc = (crc ^ POLYNOMIAL) | carry;
|
---|
189 | }
|
---|
190 | }
|
---|
191 | return crc;
|
---|
192 | }
|
---|
193 |
|
---|
194 | #undef POLYNOMIAL
|
---|
195 |
|
---|
196 | /*
|
---|
197 | * ds_getmcaf -- ãã«ããã£ã¹ãã¢ãã¬ã¹ã®ãªã¹ããããã«ããã£ã¹ãã¢ãã¬ã¹
|
---|
198 | * ãã£ã«ã¿ãè¨ç®ããã
|
---|
199 | */
|
---|
200 |
|
---|
201 | static void
|
---|
202 | ds_getmcaf(T_IF_SOFTC *ic, uint32_t *mcaf)
|
---|
203 | {
|
---|
204 | uint32_t count, index;
|
---|
205 | uint8_t *af = (uint8_t*)mcaf;
|
---|
206 |
|
---|
207 | mcaf[0] = mcaf[1] = 0;
|
---|
208 |
|
---|
209 | for (count = MAX_IF_MADDR_CNT; count-- > 0; ) {
|
---|
210 | index = ds_crc(ic->maddrs[count].lladdr) >> 26;
|
---|
211 | af[index >> 3] |= 1 << (index & 7);
|
---|
212 | }
|
---|
213 | }
|
---|
214 |
|
---|
215 | /*
|
---|
216 | * mbed_setrcr -- åä¿¡æ§æã¬ã¸ã¹ã¿ (RCR) ãè¨å®ããã
|
---|
217 | */
|
---|
218 |
|
---|
219 | static void
|
---|
220 | if_mbed_setrcr(T_IF_SOFTC *ic)
|
---|
221 | {
|
---|
222 | T_MBED_SOFTC *sc = ic->sc;
|
---|
223 | }
|
---|
224 |
|
---|
225 | /*
|
---|
226 | * mbed_addmulti -- ãã«ããã£ã¹ãã¢ãã¬ã¹ã追å ããã
|
---|
227 | */
|
---|
228 |
|
---|
229 | ER
|
---|
230 | if_mbed_addmulti(T_IF_SOFTC *ic)
|
---|
231 | {
|
---|
232 | mbed_setrcr(ic);
|
---|
233 | return E_OK;
|
---|
234 | }
|
---|
235 |
|
---|
236 | #endif /* of #ifdef SUPPORT_INET6 */
|
---|
237 |
|
---|
238 | /*
|
---|
239 | * mbed_stop -- ãããã¯ã¼ã¯ã¤ã³ã¿ãã§ã¼ã¹ãåæ¢ããã
|
---|
240 | *
|
---|
241 | * 注æ: NIC å²ãè¾¼ã¿ç¦æ¢ç¶æ
|
---|
242 | ã§å¼ã³åºããã¨ã
|
---|
243 | */
|
---|
244 |
|
---|
245 | static void
|
---|
246 | if_mbed_stop(T_MBED_SOFTC *sc)
|
---|
247 | {
|
---|
248 | ethernetext_start_stop(0);
|
---|
249 | }
|
---|
250 |
|
---|
251 | static void rza1_recv_callback(void)
|
---|
252 | {
|
---|
253 | sig_sem(if_softc.semid_rxb_ready);
|
---|
254 | }
|
---|
255 |
|
---|
256 | #define EDMAC_EESIPR_INI_TRANS (0xF4380000)
|
---|
257 | #define EDMAC_EESIPR_INI_RECV (0x0205001F) /* 0x02000000 : Detect reception suspended */
|
---|
258 | /* 0x00040000 : Detect frame reception */
|
---|
259 | /* 0x00010000 : Receive FIFO overflow */
|
---|
260 | /* 0x00000010 : Residual bit frame reception */
|
---|
261 | /* 0x00000008 : Long frame reception */
|
---|
262 | /* 0x00000004 : Short frame reception */
|
---|
263 | /* 0x00000002 : PHY-LSI reception error */
|
---|
264 | /* 0x00000001 : Receive frame CRC error */
|
---|
265 | #define EDMAC_EESIPR_INI_EtherC (0x00400000) /* 0x00400000 : E-MAC status register */
|
---|
266 |
|
---|
267 | static void
|
---|
268 | if_mbed_init_sub(T_IF_SOFTC *ic)
|
---|
269 | {
|
---|
270 | ethernet_cfg_t ethcfg;
|
---|
271 |
|
---|
272 | /* Initialize the hardware */
|
---|
273 | ethcfg.int_priority = 6;
|
---|
274 | ethcfg.recv_cb = &rza1_recv_callback;
|
---|
275 | ethcfg.ether_mac = (char *)ic->ifaddr.lladdr;
|
---|
276 | ethernetext_init(ðcfg);
|
---|
277 | }
|
---|
278 |
|
---|
279 | /*
|
---|
280 | * mbed_reset -- ãããã¯ã¼ã¯ã¤ã³ã¿ãã§ã¼ã¹ããªã»ããããã
|
---|
281 | */
|
---|
282 |
|
---|
283 | void
|
---|
284 | if_mbed_reset(T_IF_SOFTC *ic)
|
---|
285 | {
|
---|
286 | ethernetext_start_stop(0);
|
---|
287 |
|
---|
288 | NET_COUNT_ETHER_NIC(net_count_ether_nic[NC_ETHER_NIC_RESETS], 1);
|
---|
289 | if_mbed_stop(ic->sc);
|
---|
290 | if_mbed_init_sub(ic);
|
---|
291 |
|
---|
292 | ethernetext_start_stop(1);
|
---|
293 | }
|
---|
294 |
|
---|
295 | /*
|
---|
296 | * get_mbed_softc -- ãããã¯ã¼ã¯ã¤ã³ã¿ãã§ã¼ã¹ã®ã½ããã¦ã§ã¢æ
|
---|
297 | å ±ãè¿ãã
|
---|
298 | */
|
---|
299 |
|
---|
300 | T_IF_SOFTC *
|
---|
301 | if_mbed_get_softc(void)
|
---|
302 | {
|
---|
303 | return &if_softc;
|
---|
304 | }
|
---|
305 |
|
---|
306 | /*
|
---|
307 | * mbed_watchdog -- ãããã¯ã¼ã¯ã¤ã³ã¿ãã§ã¼ã¹ã®ã¯ããããã°ã¿ã¤ã ã¢ã¦ã
|
---|
308 | */
|
---|
309 |
|
---|
310 | void
|
---|
311 | if_mbed_watchdog(T_IF_SOFTC *ic)
|
---|
312 | {
|
---|
313 | if_mbed_reset(ic);
|
---|
314 | }
|
---|
315 |
|
---|
316 | /*
|
---|
317 | * mbed_probe -- ãããã¯ã¼ã¯ã¤ã³ã¿ãã§ã¼ã¹ã®æ¤åº
|
---|
318 | */
|
---|
319 |
|
---|
320 | void
|
---|
321 | if_mbed_probe(T_IF_SOFTC *ic)
|
---|
322 | {
|
---|
323 | #if (MBED_MAC_ADDRESS_SUM != MBED_MAC_ADDR_INTERFACE)
|
---|
324 | netif->hwaddr[0] = MBED_MAC_ADDR_0;
|
---|
325 | netif->hwaddr[1] = MBED_MAC_ADDR_1;
|
---|
326 | netif->hwaddr[2] = MBED_MAC_ADDR_2;
|
---|
327 | netif->hwaddr[3] = MBED_MAC_ADDR_3;
|
---|
328 | netif->hwaddr[4] = MBED_MAC_ADDR_4;
|
---|
329 | netif->hwaddr[5] = MBED_MAC_ADDR_5;
|
---|
330 | #else
|
---|
331 | mbed_mac_address((char *)ic->ifaddr.lladdr);
|
---|
332 | #endif
|
---|
333 | }
|
---|
334 |
|
---|
335 | /*
|
---|
336 | * mbed_init -- ãããã¯ã¼ã¯ã¤ã³ã¿ãã§ã¼ã¹ã®åæå
|
---|
337 | */
|
---|
338 |
|
---|
339 | void
|
---|
340 | if_mbed_init(T_IF_SOFTC *ic)
|
---|
341 | {
|
---|
342 | T_MBED_SOFTC *sc = ic->sc;
|
---|
343 |
|
---|
344 | /* mbed_init æ¬ä½ãå¼ã³åºãã*/
|
---|
345 | if_mbed_init_sub(ic);
|
---|
346 |
|
---|
347 | act_tsk(IF_MBED_PHY_TASK);
|
---|
348 |
|
---|
349 | ethernet_set_link(-1, 0);
|
---|
350 |
|
---|
351 | ETHER.EESIPR0 |= EDMAC_EESIPR_INI_TRANS;
|
---|
352 | }
|
---|
353 |
|
---|
354 | void if_mbed_phy_task(intptr_t arg)
|
---|
355 | {
|
---|
356 | T_IFNET *ether = ether_get_ifnet();
|
---|
357 | int32_t connect_sts = 0; /* 0: disconnect, 1:connect */
|
---|
358 | int32_t link_sts;
|
---|
359 | int32_t link_mode_new = NEGO_FAIL;
|
---|
360 | int32_t link_mode_old = NEGO_FAIL;
|
---|
361 |
|
---|
362 | while (1) {
|
---|
363 | link_sts = ethernet_link();
|
---|
364 | if (link_sts == 1) {
|
---|
365 | link_mode_new = ethernetext_chk_link_mode();
|
---|
366 | if (link_mode_new != link_mode_old) {
|
---|
367 | if (connect_sts == 1) {
|
---|
368 | ether_set_link_down(ether);
|
---|
369 | }
|
---|
370 | if (link_mode_new != NEGO_FAIL) {
|
---|
371 | ethernetext_set_link_mode(link_mode_new);
|
---|
372 | ETHER.EESIPR0 |= EDMAC_EESIPR_INI_TRANS;
|
---|
373 | ether_set_link_up(ether);
|
---|
374 | connect_sts = 1;
|
---|
375 | }
|
---|
376 | }
|
---|
377 | }
|
---|
378 | else {
|
---|
379 | if (connect_sts != 0) {
|
---|
380 | ether_set_link_down(ether);
|
---|
381 | link_mode_new = NEGO_FAIL;
|
---|
382 | connect_sts = 0;
|
---|
383 | }
|
---|
384 | }
|
---|
385 | link_mode_old = link_mode_new;
|
---|
386 | dly_tsk(PHY_TASK_WAIT);
|
---|
387 | }
|
---|
388 | }
|
---|
389 |
|
---|
390 | /*
|
---|
391 | * mbed_read -- ãã¬ã¼ã ã®èªã¿è¾¼ã¿
|
---|
392 | */
|
---|
393 |
|
---|
394 | T_NET_BUF *
|
---|
395 | if_mbed_read(T_IF_SOFTC *ic)
|
---|
396 | {
|
---|
397 | T_MBED_SOFTC *sc = ic->sc;
|
---|
398 | T_NET_BUF *input = NULL;
|
---|
399 | uint_t align;
|
---|
400 | int len;
|
---|
401 | uint8_t *dst;
|
---|
402 | ER error;
|
---|
403 |
|
---|
404 | len = ethernet_receive();
|
---|
405 | if (len <= 0)
|
---|
406 | return NULL;
|
---|
407 |
|
---|
408 | align = ((((len - sizeof(T_IF_HDR)) + 3) >> 2) << 2) + sizeof(T_IF_HDR);
|
---|
409 | if ((error = tget_net_buf(&input, align, TMO_IF_MBED_GET_NET_BUF)) == E_OK && input != NULL) {
|
---|
410 | dst = input->buf + IF_ETHER_NIC_HDR_ALIGN;
|
---|
411 | input->len = ethernet_read((char *)dst, len);
|
---|
412 | }
|
---|
413 | else {
|
---|
414 | NET_COUNT_ETHER_NIC(net_count_ether_nic[NC_ETHER_NIC_IN_ERR_PACKETS], 1);
|
---|
415 | NET_COUNT_ETHER_NIC(net_count_ether_nic[NC_ETHER_NIC_NO_BUFS], 1);
|
---|
416 | }
|
---|
417 |
|
---|
418 | sig_sem(ic->semid_rxb_ready);
|
---|
419 |
|
---|
420 | return input;
|
---|
421 | }
|
---|
422 |
|
---|
423 | /*
|
---|
424 | * mbed_start -- éä¿¡ãã¬ã¼ã ããããã¡ãªã³ã°ããã
|
---|
425 | */
|
---|
426 |
|
---|
427 | void
|
---|
428 | if_mbed_start(T_IF_SOFTC *ic, T_NET_BUF *output)
|
---|
429 | {
|
---|
430 | T_MBED_SOFTC *sc = ic->sc;
|
---|
431 | int32_t len, res, pos;
|
---|
432 |
|
---|
433 | for (res = output->len, pos = 0; res > 0; res -= len, pos += len) {
|
---|
434 | len = ethernet_write((char *)output->buf + IF_ETHER_NIC_HDR_ALIGN + pos, res);
|
---|
435 | if (len == 0) {
|
---|
436 | syslog(LOG_WARNING, "ethernet_write => 0");
|
---|
437 | break;
|
---|
438 | }
|
---|
439 | }
|
---|
440 |
|
---|
441 | if (ethernet_send() == 0) {
|
---|
442 | syslog(LOG_WARNING, "ethernet_send => 0");
|
---|
443 | }
|
---|
444 | }
|
---|
445 |
|
---|
446 | /*
|
---|
447 | * MBED Ethernet Controler éåä¿¡å²ãè¾¼ã¿ãã³ãã©
|
---|
448 | */
|
---|
449 |
|
---|
450 | void
|
---|
451 | if_mbed_eth_handler(void)
|
---|
452 | {
|
---|
453 | uint32_t stat_edmac;
|
---|
454 | uint32_t stat_etherc;
|
---|
455 |
|
---|
456 | /* Clear the interrupt request flag */
|
---|
457 | stat_edmac = (ETHER.EESR0 & ETHER.EESIPR0); /* Targets are restricted to allowed interrupts */
|
---|
458 | ETHER.EESR0 = stat_edmac;
|
---|
459 | /* Reception-related */
|
---|
460 | if (stat_edmac & EDMAC_EESIPR_INI_RECV) {
|
---|
461 | isig_sem(if_softc.semid_rxb_ready);
|
---|
462 | }
|
---|
463 | if (stat_edmac & EDMAC_EESIPR_INI_TRANS) {
|
---|
464 | isig_sem(if_softc.semid_txb_ready);
|
---|
465 | }
|
---|
466 | /* E-MAC-related */
|
---|
467 | if (stat_edmac & EDMAC_EESIPR_INI_EtherC) {
|
---|
468 | /* Clear the interrupt request flag */
|
---|
469 | stat_etherc = (ETHER.ECSR0 & ETHER.ECSIPR0); /* Targets are restricted to allowed interrupts */
|
---|
470 | ETHER.ECSR0 = stat_etherc;
|
---|
471 | }
|
---|
472 | }
|
---|