source: UsbWattMeter/trunk/lwip-1.4.1/ports/grsakura/if_rx62n.c

Last change on this file was 329, checked in by coas-nagasima, 5 years ago

syslogの文が間違っているのを修正

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-csrc; charset=SHIFT_JIS
File size: 19.5 KB
Line 
1/**
2 * @file
3 * Ethernet Interface Skeleton
4 *
5 */
6
7 /*
8 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without modification,
12 * are permitted provided that the following conditions are met:
13 *
14 * 1. Redistributions of source code must retain the above copyright notice,
15 * this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright notice,
17 * this list of conditions and the following disclaimer in the documentation
18 * and/or other materials provided with the distribution.
19 * 3. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
23 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
25 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
27 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
30 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
31 * OF SUCH DAMAGE.
32 *
33 * This file is part of the lwIP TCP/IP stack.
34 *
35 * Author: Adam Dunkels <adam@sics.se>
36 *
37 */
38
39 /*
40 * This file is a skeleton for developing Ethernet network interface
41 * drivers for lwIP. Add code to the low_level functions and do a
42 * search-and-replace for the word "ethernetif" to replace it with
43 * something that better describes your network interface.
44 */
45#ifdef _MSC_VER
46#pragma warning(disable : 4005)
47#endif
48#include "lwip/opt.h"
49#include "lwip/def.h"
50#include "lwip/mem.h"
51#include "lwip/pbuf.h"
52#include <lwip/stats.h>
53#include <lwip/snmp.h>
54#include "netif/etharp.h"
55#include "netif/ppp_oe.h"
56#ifdef _MSC_VER
57#pragma warning(default : 4005)
58#endif
59#include <t_stddef.h>
60#include <sil.h>
61#include <kernel.h>
62#include <t_syslog.h>
63#ifdef __RX
64#include <rx630_ccrx/prc_rename.h>
65#else
66#include <rx630_msvc/prc_rename.h>
67#endif
68#include "if_rx62n.h"
69#include "if_rx62nreg.h"
70#include <string.h>
71#include "ether_phy.h"
72
73 /* Define those to better describe your network interface. */
74#define IFNAME0 'e'
75#define IFNAME1 'n'
76
77extern uint8_t mac_addr[ETHARP_HWADDR_LEN];
78
79typedef struct t_rx62n_buf
80{
81 uint8_t rx_buff[NUM_IF_RX62N_RXBUF][32 * ((IF_RX62N_BUF_PAGE_SIZE + 31) / 32)];
82 uint8_t tx_buff[NUM_IF_RX62N_TXBUF][32 * ((IF_RX62N_BUF_PAGE_SIZE + 31) / 32)];
83 T_RX62N_RX_DESC rx_desc[NUM_IF_RX62N_RXBUF];
84 T_RX62N_TX_DESC tx_desc[NUM_IF_RX62N_TXBUF];
85} T_RX62N_BUF;
86
87#if defined(__RX)
88#pragma section ETH_MEMORY
89#endif
90T_RX62N_BUF rx62n_buf;
91#if defined(__RX)
92#pragma section
93#endif
94
95/**
96 * Helper struct to hold private data used to operate your ethernet interface.
97 * Keeping the ethernet address of the MAC in this struct is not necessary
98 * as it is already kept in the struct netif.
99 * But this is only an example, anyway...
100 */
101struct ethernetif
102{
103 ID sem_rev;
104 struct eth_addr *ethaddr;
105 /* Add whatever per-interface state that is needed here. */
106 T_RX62N_TX_DESC *tx_write;
107 T_RX62N_RX_DESC *rx_read;
108 PHY_STATE_T state;
109 bool_t link_pre;
110 bool_t link_now;
111 bool_t over_flow;
112};
113
114/* Forward declarations. */
115void ethernetif_input(struct netif *netif);
116
117static void rx62n_set_ecmr(struct netif *netif, PHY_MODE_T mode);
118
119/*
120 * rx62n_bus_init -- ターゲット依存部のバスの初期化
121 */
122
123void
124rx62n_bus_init (void)
125{
126 /* イーサネット・コントローラの動作を許可 */
127 sil_wrh_mem((uint16_t *)SYSTEM_PRCR_ADDR, (uint16_t)0xA502); /* 書込み許可 */
128 sil_wrw_mem((uint32_t *)SYSTEM_MSTPCRB_ADDR,
129 sil_rew_mem((uint32_t *)SYSTEM_MSTPCRB_ADDR) & ~SYSTEM_MSTPCRB_MSTPB15_BIT);
130 sil_wrh_mem((uint16_t *)SYSTEM_PRCR_ADDR, (uint16_t)0xA500); /* 書込み禁止 */
131
132 /* EtherNET有効 */
133 /* PA3〜5 RMII_MDIO, RMII_MDC, RMII_LINKSTA */
134 sil_wrb_mem((uint8_t *)PORTA_PMR_ADDR,
135 sil_reb_mem((uint8_t *)PORTA_PMR_ADDR) | (1 << 3) | (1 << 4) | (1 << 5));
136 /* PB0〜7 RXD1, RXD0, REF50CK, RX-ER, TXD-EN, TXD0, TXD1, CRS */
137 sil_wrb_mem((uint8_t *)PORTB_PMR_ADDR,
138 sil_reb_mem((uint8_t *)PORTB_PMR_ADDR) | 0xFF);
139
140 /* 書き込みプロテクトレジスタの設定 PFSWEビットへの書き込みを許可 */
141 sil_wrb_mem((uint8_t *)(MPC_PWPR_ADDR) , 0x00);
142 /* 書き込みプロテクトレジスタの設定 PxxFSレジスタへの書き込みを許可 */
143 sil_wrb_mem((uint8_t *)(MPC_PWPR_ADDR) , 0x40);
144
145 /* PA3をET_MDIOとする */
146 sil_wrb_mem((uint8_t *)MPC_PA3PFS_ADDR, 0x11);
147 /* PA4をET_MDCとする */
148 sil_wrb_mem((uint8_t *)MPC_PA4PFS_ADDR, 0x11);
149 /* PA5をET_LINKSTAとする */
150 sil_wrb_mem((uint8_t *)MPC_PA5PFS_ADDR, 0x11);
151
152 /* PB0をRXD1とする */
153 sil_wrb_mem((uint8_t *)MPC_PB0PFS_ADDR, 0x12);
154 /* PB1をRXD0とする */
155 sil_wrb_mem((uint8_t *)MPC_PB1PFS_ADDR, 0x12);
156 /* PB2をREF50CKとする */
157 sil_wrb_mem((uint8_t *)MPC_PB2PFS_ADDR, 0x12);
158 /* PB3をRX-ERとする */
159 sil_wrb_mem((uint8_t *)MPC_PB3PFS_ADDR, 0x12);
160 /* PB4をTXD-ENとする */
161 sil_wrb_mem((uint8_t *)MPC_PB4PFS_ADDR, 0x12);
162 /* PB5をTXD0とする */
163 sil_wrb_mem((uint8_t *)MPC_PB5PFS_ADDR, 0x12);
164 /* PB6をTXD1とする */
165 sil_wrb_mem((uint8_t *)MPC_PB6PFS_ADDR, 0x12);
166 /* PB7をCRSとする */
167 sil_wrb_mem((uint8_t *)MPC_PB7PFS_ADDR, 0x12);
168
169 /* 書き込みプロテクトレジスタの設定 書き込みを禁止 */
170 sil_wrb_mem((uint8_t *)(MPC_PWPR_ADDR) , 0x80);
171}
172
173/*
174 * rx62n_init_sub -- ネットワークインタフェースの初期化
175 *
176 * 注意: NIC 割り込み禁止状態で呼び出すこと。
177 */
178
179static void
180rx62n_init_sub(struct netif *netif)
181{
182 struct ethernetif *ethernetif = netif->state;
183 PHY_STATE_T state = PHY_STATE_UNINIT;
184
185 /* MAC部ソフトウエア・リセット */
186 sil_wrw_mem(EDMAC_EDMR, sil_rew_mem(EDMAC_EDMR) | EDMAC_EDMR_SWR_BIT);
187
188 dly_tsk(1);
189
190 sil_wrw_mem(ETHERC_MAHR, ((uint32_t)mac_addr[0] << 24)
191 | ((uint32_t)mac_addr[1] << 16) | ((uint32_t)mac_addr[2] << 8)
192 | (uint32_t)mac_addr[3]);
193 sil_wrw_mem(ETHERC_MALR, ((uint32_t)mac_addr[4] << 8)
194 | (uint32_t)mac_addr[5]);
195
196 /* PHYリセット */
197 while ((state = phy_reset(state, 0)) != PHY_STATE_RESET);
198 ethernetif->state = state;
199
200 /* Clear all ETHERC status BFR, PSRTO, LCHNG, MPD, ICD */
201 sil_wrw_mem(ETHERC_ECSR, 0x00000037);
202
203 /* リンク変化割り込み有効 */
204 sil_wrw_mem(ETHERC_ECSIPR, sil_rew_mem(ETHERC_ECSIPR) | ETHERC_ECSIPR_LCHNGIP);
205
206 /* Clear all ETHERC and EDMAC status bits */
207 sil_wrw_mem(EDMAC_EESR, 0x47FF0F9F);
208
209 /* 送受信割り込み有効 */
210 sil_wrw_mem(EDMAC_EESIPR, (EDMAC_EESIPR_TCIP | EDMAC_EESIPR_FRIP | EDMAC_EESIPR_RDEIP | EDMAC_EESIPR_FROFIP));
211
212 /* 受信フレーム長上限(バッファサイズ) */
213 sil_wrw_mem(ETHERC_RFLR, IF_RX62N_BUF_PAGE_SIZE);
214
215 /* 96ビット時間(初期値) */
216 sil_wrw_mem(ETHERC_IPGR, 0x00000014);
217
218 /* Set little endian mode */
219 sil_wrw_mem(EDMAC_EDMR, sil_rew_mem(EDMAC_EDMR) | EDMAC_EDMR_DE_BIT);
220
221 /* Initialize Rx descriptor list address */
222 sil_wrw_mem(EDMAC_RDLAR, (uint32_t)rx62n_buf.rx_desc);
223 /* Initialize Tx descriptor list address */
224 sil_wrw_mem(EDMAC_TDLAR, (uint32_t)rx62n_buf.tx_desc);
225 /* Copy-back status is RFE & TFE only */
226 sil_wrw_mem(EDMAC_TRSCER, 0x00000000);
227 /* Threshold of Tx_FIFO */
228 sil_wrw_mem(EDMAC_TFTR, 0x00000000);
229 /* Transmit fifo & receive fifo is 2048 bytes */
230 sil_wrw_mem(EDMAC_FDR, 0x00000707);
231 /* RR in EDRRR is under driver control */
232 sil_wrw_mem(EDMAC_RMCR, 0x00000001);
233
234 /* PHYの初期化を促す */
235 ethernetif->link_pre = false;
236 ethernetif->link_now = true;
237}
238
239/**
240 * In this function, the hardware should be initialized.
241 * Called from ethernetif_init().
242 *
243 * @param netif the already initialized lwip network interface structure
244 * for this ethernetif
245 */
246static void
247low_level_init(struct netif *netif)
248{
249 struct ethernetif *ethernetif = netif->state;
250
251 rx62n_bus_init();
252
253 /* set MAC hardware address length */
254 netif->hwaddr_len = ETHARP_HWADDR_LEN;
255
256 /* set MAC hardware address */
257 memcpy(netif->hwaddr, mac_addr, sizeof(netif->hwaddr));
258
259 /* maximum transfer unit */
260 netif->mtu = 1500;
261
262 /* device capabilities */
263 /* don't set NETIF_FLAG_ETHARP if this device is not an ethernet one */
264 netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_IGMP;
265
266 /* Do whatever else is needed to initialize interface. */
267 T_RX62N_TX_DESC *tdsc;
268 T_RX62N_RX_DESC *rdsc;
269 int i;
270 ER ret;
271
272 /* NIC からの割り込みを禁止する。*/
273 ret = dis_int(INTNO_IF_RX62N_TRX);
274 if (ret != E_OK)
275 syslog(LOG_DEBUG, "dis_int");
276
277 tdsc = (T_RX62N_TX_DESC *)rx62n_buf.tx_desc;
278 ethernetif->tx_write = tdsc;
279 for (i = 0; i < NUM_IF_RX62N_TXBUF; i++) {
280 memset(tdsc, 0, sizeof(*tdsc));
281 tdsc->tbl = 0;
282 tdsc->tba = (uint32_t)&rx62n_buf.tx_buff[i];
283 tdsc++;
284 }
285 tdsc--;
286 tdsc->tdle = 1;
287
288 rdsc = (T_RX62N_RX_DESC *)rx62n_buf.rx_desc;
289 ethernetif->rx_read = rdsc;
290 for (i = 0; i < NUM_IF_RX62N_RXBUF; i++) {
291 memset(rdsc, 0, sizeof(*rdsc));
292 rdsc->rbl = IF_RX62N_BUF_PAGE_SIZE;
293 rdsc->rba = (uint32_t)&rx62n_buf.rx_buff[i];
294 rdsc->rfl = 0;
295 rdsc->ract = 1;
296 rdsc++;
297 }
298 rdsc--;
299 rdsc->rdle = 1;
300
301 /* rx62n_init 本体を呼び出す。*/
302 rx62n_init_sub(netif);
303
304 if (sil_rew_mem(EDMAC_EDRRR) == 0) {
305 sil_wrw_mem(EDMAC_EDRRR, EDMAC_EDRRR_RR);
306 }
307
308 /* 送受信を有効 */
309 rx62n_set_ecmr(netif, 1);
310
311 /* NIC からの割り込みを許可する。*/
312 ret = ena_int(INTNO_IF_RX62N_TRX);
313 if (ret != E_OK)
314 syslog(LOG_DEBUG, "ena_int");
315}
316
317/*
318* rx62n_set_ecmr -- ECMRレジスタの設定
319*/
320
321static void
322rx62n_set_ecmr(struct netif *netif, PHY_MODE_T mode)
323{
324 uint32_t ecmr;
325
326 ecmr = ETHERC_ECMR_RE | ETHERC_ECMR_TE/* | ETHERC_ECMR_PRM*/;
327
328 if ((mode & 0x01) != 0)
329 ecmr |= ETHERC_ECMR_DM;
330 if ((mode & 0x02) != 0)
331 ecmr |= ETHERC_ECMR_RTM;
332
333 /* 動作モード設定 */
334 sil_wrw_mem(ETHERC_ECMR, ecmr);
335}
336
337/**
338 * This function should do the actual transmission of the packet. The packet is
339 * contained in the pbuf that is passed to the function. This pbuf
340 * might be chained.
341 *
342 * @param netif the lwip network interface structure for this ethernetif
343 * @param p the MAC packet to send (e.g. IP packet including MAC addresses and type)
344 * @return ERR_OK if the packet could be sent
345 * an err_t value if the packet couldn't be sent
346 *
347 * @note Returning ERR_MEM here if a DMA queue of your MAC is full can lead to
348 * strange results. You might consider waiting for space in the DMA queue
349 * to become availale since the stack doesn't retry to send a packet
350 * dropped because of memory failure (except for the TCP timers).
351 */
352
353static err_t
354low_level_output(struct netif *netif, struct pbuf *p)
355{
356 struct ethernetif *ethernetif = netif->state;
357 struct pbuf *q;
358
359 T_RX62N_TX_DESC *desc, *next;
360 uint8_t *buf = NULL, *end;
361 int32_t len, res, pos;
362 uint32_t tfp;
363
364 for (res = p->tot_len, pos = 0; res > 0; res -= len, pos += len) {
365 desc = ethernetif->tx_write;
366
367 while (desc->tact != 0) {
368 tslp_tsk(1);
369 }
370
371 buf = (uint8_t *)desc->tba;
372
373 next = desc + 1;
374 if (next == &rx62n_buf.tx_desc[NUM_IF_RX62N_TXBUF]) {
375 next = rx62n_buf.tx_desc;
376 }
377 ethernetif->tx_write = next;
378
379 len = res;
380 if (len > IF_RX62N_BUF_PAGE_SIZE) {
381 len = IF_RX62N_BUF_PAGE_SIZE;
382 tfp = 0x0;
383 }
384 else
385 tfp = 0x1;
386
387 if (pos == 0)
388 tfp |= 0x2;
389
390#if ETH_PAD_SIZE
391 pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */
392#endif
393
394 end = &buf[len];
395 for (q = p; (q != NULL) && (buf < end); buf += q->len, q = q->next) {
396 /* Send the data from the pbuf to the interface, one pbuf at a
397 time. The size of the data in each pbuf is kept in the ->len
398 variable. */
399 memcpy(buf, (uint8_t *)q->payload, q->len);
400 }
401
402 desc->tbl = len;
403 desc->tfp = tfp;
404 desc->tact = 1;
405
406#if ETH_PAD_SIZE
407 pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */
408#endif
409
410 LINK_STATS_INC(link.xmit);
411 }
412
413 if (sil_rew_mem(EDMAC_EDTRR) == 0) {
414 sil_wrw_mem(EDMAC_EDTRR, EDMAC_EDTRR_TR);
415 }
416
417 return ERR_OK;
418}
419
420/**
421 * Should allocate a pbuf and transfer the bytes of the incoming
422 * packet from the interface into the pbuf.
423 *
424 * @param netif the lwip network interface structure for this ethernetif
425 * @return a pbuf filled with the received packet (including MAC header)
426 * NULL on memory error
427 */
428static struct pbuf *
429low_level_input(struct netif *netif)
430{
431 struct ethernetif *ethernetif = netif->state;
432 struct pbuf *p, *q;
433 u16_t pos, len;
434 T_RX62N_RX_DESC *desc;
435
436 desc = ethernetif->rx_read;
437
438 if (desc->ract != 0) {
439 return NULL;
440 }
441
442 /* Obtain the size of the packet and put it into the "len"
443 variable. */
444 len = desc->rfl;
445 if (len == 0) {
446 return NULL;
447 }
448
449#if ETH_PAD_SIZE
450 len += ETH_PAD_SIZE; /* allow room for Ethernet padding */
451#endif
452
453 /* We allocate a pbuf chain of pbufs from the pool. */
454 p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL);
455
456 if (p != NULL) {
457
458#if ETH_PAD_SIZE
459 pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */
460#endif
461
462 /* We iterate over the pbuf chain until we have read the entire
463 * packet into the pbuf. */
464 for (q = p, pos = 0; q != NULL; pos += q->len, q = q->next) {
465 /* Read enough bytes to fill this pbuf in the chain. The
466 * available data in the pbuf is given by the q->len
467 * variable.
468 * This does not necessarily have to be a memcpy, you can also preallocate
469 * pbufs for a DMA-enabled MAC and after receiving truncate it to the
470 * actually received size. In this case, ensure the tot_len member of the
471 * pbuf is the sum of the chained pbuf len members.
472 */
473 memcpy(q->payload, (uint8_t *)desc->rba + pos, q->len);
474 }
475
476 desc->rfp = 0;
477 desc->ract = 1;
478
479 desc++;
480 if (desc == &rx62n_buf.rx_desc[NUM_IF_RX62N_RXBUF]) {
481 desc = rx62n_buf.rx_desc;
482 }
483 ethernetif->rx_read = desc;
484
485 if (sil_rew_mem(EDMAC_EDRRR) == 0) {
486 sil_wrw_mem(EDMAC_EDRRR, EDMAC_EDRRR_RR);
487 }
488
489#if ETH_PAD_SIZE
490 pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */
491#endif
492
493 LINK_STATS_INC(link.recv);
494 }
495 else {
496 //drop packet();
497 LINK_STATS_INC(link.memerr);
498 LINK_STATS_INC(link.drop);
499 }
500
501 return p;
502}
503
504/*
505 * rx62n_link -- リンク状態の変化に対する処理
506 */
507bool_t
508rx62n_link(struct netif *netif)
509{
510 struct ethernetif *ethernetif;
511 PHY_MODE_T mode;
512 uint8_t phy_addr = 0;
513
514 ethernetif = netif->state;
515
516 if(ethernetif->state == PHY_STATE_NEGOTIATED){
517 ethernetif->link_now = phy_is_link(phy_addr);
518 if(!ethernetif->link_now)
519 ethernetif->state = PHY_STATE_RESET;
520 return true;
521 }
522
523 /* PHYの初期化 */
524 ethernetif->state = phy_initialize(ethernetif->state, phy_addr, &mode);
525 if(ethernetif->state != PHY_STATE_NEGOTIATED){
526 return false;
527 }
528
529 /* ECMRレジスタの設定 */
530 rx62n_set_ecmr(netif, mode);
531 return true;
532}
533
534/**
535 * This function should be called when a packet is ready to be read
536 * from the interface. It uses the function low_level_input() that
537 * should handle the actual reception of bytes from the network
538 * interface. Then the type of the received packet is determined and
539 * the appropriate input function is called.
540 *
541 * @param netif the lwip network interface structure for this ethernetif
542 */
543void
544ethernetif_input(struct netif *netif)
545{
546 struct ethernetif *ethernetif;
547 struct eth_hdr *ethhdr;
548 struct pbuf *p;
549
550 ethernetif = netif->state;
551
552 if(ethernetif->link_pre != ethernetif->link_now){
553 ethernetif->link_pre = ethernetif->link_now;
554 /* リンク状態に変化あり */
555 if (rx62n_link(netif)) {
556 netif_set_link_up(netif);
557 }
558 else {
559 netif_set_link_down(netif);
560 }
561
562 if (ethernetif->state != PHY_STATE_NEGOTIATED) {
563 ethernetif->link_pre = !ethernetif->link_now;
564 sig_sem(ethernetif->sem_rev);
565 }
566
567 return;
568 }
569
570 for (;;) {
571 /* move received packet into a new pbuf */
572 p = low_level_input(netif);
573 /* no packet could be read, silently ignore this */
574 if (p == NULL) return;
575 /* points to packet payload, which starts with an Ethernet header */
576 ethhdr = p->payload;
577
578 switch (htons(ethhdr->type)) {
579 /* IP or ARP packet? */
580 case ETHTYPE_IP:
581 case ETHTYPE_ARP:
582#if PPPOE_SUPPORT
583 /* PPPoE packet? */
584 case ETHTYPE_PPPOEDISC:
585 case ETHTYPE_PPPOE:
586#endif /* PPPOE_SUPPORT */
587 /* full packet send to tcpip_thread to process */
588 if (netif->input(p, netif) != ERR_OK) {
589 LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n"));
590 pbuf_free(p);
591 p = NULL;
592 }
593 break;
594
595 default:
596 pbuf_free(p);
597 p = NULL;
598 break;
599 }
600 }
601}
602
603struct netif *if_rx62n;
604
605/**
606 * Should be called at the beginning of the program to set up the
607 * network interface. It calls the function low_level_init() to do the
608 * actual setup of the hardware.
609 *
610 * This function should be passed as a parameter to netif_add().
611 *
612 * @param netif the lwip network interface structure for this ethernetif
613 * @return ERR_OK if the loopif is initialized
614 * ERR_MEM if private data couldn't be allocated
615 * any other err_t on error
616 */
617err_t
618ethernetif_init(struct netif *netif)
619{
620 struct ethernetif *ethernetif;
621
622 LWIP_ASSERT("netif != NULL", (netif != NULL));
623
624 if_rx62n = netif;
625 ethernetif = (struct ethernetif *)(((intptr_t)netif) + sizeof(struct netif));
626 if (ethernetif == NULL) {
627 LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_init: out of memory\n"));
628 return ERR_MEM;
629 }
630
631#if LWIP_NETIF_HOSTNAME
632 /* Initialize interface hostname */
633 netif->hostname = "lwip";
634#endif /* LWIP_NETIF_HOSTNAME */
635
636 /*
637 * Initialize the snmp variables and counters inside the struct netif.
638 * The last argument should be replaced with your link speed, in units
639 * of bits per second.
640 */
641 NETIF_INIT_SNMP(netif, snmp_ifType_ethernet_csmacd, LINK_SPEED_OF_YOUR_NETIF_IN_BPS);
642
643 netif->state = ethernetif;
644 netif->name[0] = IFNAME0;
645 netif->name[1] = IFNAME1;
646 /* We directly use etharp_output() here to save a function call.
647 * You can instead declare your own function an call etharp_output()
648 * from it if you have to do some checks before sending (e.g. if link
649 * is available...) */
650 netif->output = etharp_output;
651 netif->linkoutput = low_level_output;
652
653 ethernetif->ethaddr = (struct eth_addr *)&(netif->hwaddr[0]);
654
655 /* initialize the hardware */
656 low_level_init(netif);
657
658 return ERR_OK;
659}
660
661/*
662* RX62N Ethernet Controler 送受信割り込みハンドラ
663*/
664
665void
666if_rx62n_trx_handler(void)
667{
668 struct netif *netif;
669 struct ethernetif *ethernetif;
670 uint32_t ecsr, eesr, psr;
671
672 i_begin_int(INTNO_IF_RX62N_TRX);
673
674 netif = if_rx62n;
675 ethernetif = netif->state;
676
677 ecsr = sil_rew_mem(ETHERC_ECSR);
678
679 if (ecsr & ETHERC_ECSR_LCHNG) {
680 /* ETHERC部割り込み要因クリア */
681 sil_wrw_mem(ETHERC_ECSR, ETHERC_ECSR_LCHNG);
682
683 psr = sil_rew_mem(ETHERC_PSR);
684 ethernetif->link_now = (psr & ETHERC_PSR_LMON) != 0;
685
686 /* リンク状態に変化あり */
687 if (ethernetif->link_pre != ethernetif->link_now) {
688 /* 受信割り込み処理 */
689 isig_sem(ethernetif->sem_rev);
690 }
691 }
692
693 eesr = sil_rew_mem(EDMAC_EESR);
694
695 if (eesr & EDMAC_EESR_FR) {
696 /* DMA部割り込み要因クリア */
697 sil_wrw_mem(EDMAC_EESR, EDMAC_EESR_FR);
698
699 /* 受信割り込み処理 */
700 isig_sem(ethernetif->sem_rev);
701 }
702 if (eesr & EDMAC_EESR_TC) {
703 /* DMA部割り込み要因クリア */
704 sil_wrw_mem(EDMAC_EESR, EDMAC_EESR_TC);
705
706 /* 送信割り込み処理 */
707 isig_sem(ethernetif->sem_rev);
708 }
709 if (eesr & (EDMAC_EESR_FROF | EDMAC_EESR_RDE)) {
710 /* DMA部割り込み要因クリア */
711 sil_wrw_mem(EDMAC_EESR, EDMAC_EESR_FROF | EDMAC_EESR_RDE);
712
713 ethernetif->over_flow = true;
714
715 /* 受信割り込み処理 */
716 isig_sem(ethernetif->sem_rev);
717 }
718
719 i_end_int(INTNO_IF_RX62N_TRX);
720}
Note: See TracBrowser for help on using the repository browser.