ra8_eth_driver.c
Go to the documentation of this file.
1 /**
2  * @file ra8_eth_driver.c
3  * @brief Renesas RA8M1 / RA8D1 / RA8T1 Ethernet MAC driver
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2025 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneTCP Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.5.0
29  **/
30 
31 //Switch to the appropriate trace level
32 #define TRACE_LEVEL NIC_TRACE_LEVEL
33 
34 //Dependencies
35 #include "bsp_api.h"
36 #include "core/net.h"
38 #include "debug.h"
39 
40 //Underlying network interface
41 static NetInterface *nicDriverInterface;
42 
43 //IAR EWARM compiler?
44 #if defined(__ICCARM__)
45 
46 //Transmit buffer
47 #pragma data_alignment = 32
48 #pragma location = RA8_ETH_RAM_SECTION
50 //Receive buffer
51 #pragma data_alignment = 32
52 #pragma location = RA8_ETH_RAM_SECTION
54 //Transmit DMA descriptors
55 #pragma data_alignment = 16
56 #pragma location = RA8_ETH_RAM_SECTION
58 //Receive DMA descriptors
59 #pragma data_alignment = 16
60 #pragma location = RA8_ETH_RAM_SECTION
62 
63 //ARM or GCC compiler?
64 #else
65 
66 //Transmit buffer
68  __attribute__((aligned(32), __section__(RA8_ETH_RAM_SECTION)));
69 //Receive buffer
71  __attribute__((aligned(32), __section__(RA8_ETH_RAM_SECTION)));
72 //Transmit DMA descriptors
74  __attribute__((aligned(16), __section__(RA8_ETH_RAM_SECTION)));
75 //Receive DMA descriptors
77  __attribute__((aligned(16), __section__(RA8_ETH_RAM_SECTION)));
78 
79 #endif
80 
81 //Current transmit descriptor
82 static uint_t txIndex;
83 //Current receive descriptor
84 static uint_t rxIndex;
85 
86 
87 /**
88  * @brief RA8 Ethernet MAC driver
89  **/
90 
92 {
94  ETH_MTU,
95  ra8EthInit,
96  ra8EthTick,
105  TRUE,
106  TRUE,
107  TRUE,
108  TRUE
109 };
110 
111 
112 /**
113  * @brief RA8 Ethernet MAC initialization
114  * @param[in] interface Underlying network interface
115  * @return Error code
116  **/
117 
119 {
120  error_t error;
121 
122  //Debug message
123  TRACE_INFO("Initializing RA8 Ethernet MAC...\r\n");
124 
125  //Save underlying network interface
126  nicDriverInterface = interface;
127 
128  //Disable protection
129  R_SYSTEM->PRCR = 0xA50B;
130  //Cancel EDMAC0 module stop state
131  R_MSTP->MSTPCRB &= ~R_MSTP_MSTPCRB_MSTPB15_Msk;
132  //Enable protection
133  R_SYSTEM->PRCR = 0xA500;
134 
135  //GPIO configuration
136  ra8EthInitGpio(interface);
137 
138  //Reset EDMAC0 module
139  R_ETHERC_EDMAC->EDMR |= R_ETHERC_EDMAC_EDMR_SWR_Msk;
140  //Wait for the reset to complete
141  sleep(10);
142 
143  //Valid Ethernet PHY or switch driver?
144  if(interface->phyDriver != NULL)
145  {
146  //Ethernet PHY initialization
147  error = interface->phyDriver->init(interface);
148  }
149  else if(interface->switchDriver != NULL)
150  {
151  //Ethernet switch initialization
152  error = interface->switchDriver->init(interface);
153  }
154  else
155  {
156  //The interface is not properly configured
157  error = ERROR_FAILURE;
158  }
159 
160  //Any error to report?
161  if(error)
162  {
163  return error;
164  }
165 
166  //Initialize DMA descriptor lists
167  ra8EthInitDmaDesc(interface);
168 
169  //Maximum frame length that can be accepted
170  R_ETHERC0->RFLR = RA8_ETH_RX_BUFFER_SIZE;
171  //Set default inter packet gap (96-bit time)
172  R_ETHERC0->IPGR = 0x14;
173 
174  //Set the upper 32 bits of the MAC address
175  R_ETHERC0->MAHR = (interface->macAddr.b[0] << 24) | (interface->macAddr.b[1] << 16) |
176  (interface->macAddr.b[2] << 8) | interface->macAddr.b[3];
177 
178  //Set the lower 16 bits of the MAC address
179  R_ETHERC0->MALR = (interface->macAddr.b[4] << 8) | interface->macAddr.b[5];
180 
181  //Select little endian mode and set descriptor length (16 bytes)
182  R_ETHERC_EDMAC->EDMR = R_ETHERC_EDMAC_EDMR_DE_Msk |
183  (0 << R_ETHERC_EDMAC_EDMR_DL_Pos);
184 
185  //Use store and forward mode
186  R_ETHERC_EDMAC->TFTR = 0;
187 
188  //Set transmit FIFO size (2048 bytes) and receive FIFO size (4096 bytes)
189  R_ETHERC_EDMAC->FDR = (7 << R_ETHERC_EDMAC_FDR_TFD_Pos) |
190  (15 << R_ETHERC_EDMAC_FDR_RFD_Pos);
191 
192  //Enable continuous reception of multiple frames
193  R_ETHERC_EDMAC->RMCR = R_ETHERC_EDMAC_RMCR_RNR_Msk;
194 
195  //Select write-back complete interrupt mode and enable transmit interrupts
196  R_ETHERC_EDMAC->TRIMD = R_ETHERC_EDMAC_TRIMD_TIM_Msk |
197  R_ETHERC_EDMAC_TRIMD_TIS_Msk;
198 
199  //Disable all ETHERC interrupts
200  R_ETHERC0->ECSIPR = 0;
201 
202  //Enable the desired EDMAC interrupts
203  R_ETHERC_EDMAC->EESIPR = R_ETHERC_EDMAC_EESIPR_TWBIP_Msk |
204  R_ETHERC_EDMAC_EESIPR_FRIP_Msk;
205 
206  //Set priority grouping (4 bits for pre-emption priority, no bits for subpriority)
207  NVIC_SetPriorityGrouping(RA8_ETH_IRQ_PRIORITY_GROUPING);
208 
209  //Configure EDMAC interrupt priority
210  NVIC_SetPriority(EDMAC0_EINT_IRQn, NVIC_EncodePriority(RA8_ETH_IRQ_PRIORITY_GROUPING,
212 
213  //Enable transmission and reception
214  R_ETHERC0->ECMR |= R_ETHERC0_ECMR_TE_Msk | R_ETHERC0_ECMR_RE_Msk;
215 
216  //Instruct the DMA to poll the receive descriptor list
217  R_ETHERC_EDMAC->EDRRR = R_ETHERC_EDMAC_EDRRR_RR_Msk;
218 
219  //Accept any packets from the upper layer
220  osSetEvent(&interface->nicTxEvent);
221 
222  //Successful initialization
223  return NO_ERROR;
224 }
225 
226 
227 /**
228  * @brief GPIO configuration
229  * @param[in] interface Underlying network interface
230  **/
231 
232 __weak_func void ra8EthInitGpio(NetInterface *interface)
233 {
234 //EK-RA8M1 evaluation board?
235 #if defined(USE_EK_RA8M1)
236  //Disable protection
237  R_SYSTEM->PRCR = 0xA50B;
238  //Disable VBATT channel 0 input (P4_2)
239  R_SYSTEM->VBTICTLR &= ~R_SYSTEM_VBTICTLR_VCH0INEN_Msk;
240  //Enable protection
241  R_SYSTEM->PRCR = 0xA500;
242 
243  //Unlock PFS registers
244  R_PMISC->PWPRS &= ~R_PMISC_PWPR_B0WI_Msk;
245  R_PMISC->PWPRS |= R_PMISC_PWPR_PFSWE_Msk;
246 
247  //Select RMII interface mode
248  R_PMISC->PFENET &= ~R_PMISC_PFENET_PHYMODE0_Msk;
249 
250  //Configure ET0_MDC (P4_1)
251  R_PFS->PORT[4].PIN[1].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
252  R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (1 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
253 
254  //Configure ET0_MDIO (P4_2)
255  R_PFS->PORT[4].PIN[2].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
256  R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (1 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
257 
258  //Configure RMII0_TXD_EN_B (P4_5)
259  R_PFS->PORT[4].PIN[5].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
260  R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (3 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
261 
262  //Configure RMII0_TXD1_B (P4_6)
263  R_PFS->PORT[4].PIN[6].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
264  R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (3 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
265 
266  //Configure RMII0_TXD0_B (P7_0)
267  R_PFS->PORT[7].PIN[0].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
268  R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (3 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
269 
270  //Configure REF50CK0_B (P7_1)
271  R_PFS->PORT[7].PIN[1].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
272  R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (3 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
273 
274  //Configure RMII0_RXD0_B (P7_2)
275  R_PFS->PORT[7].PIN[2].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
276  R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (3 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
277 
278  //Configure RMII0_RXD1_B (P7_3)
279  R_PFS->PORT[7].PIN[3].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
280  R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (3 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
281 
282  //Configure RMII0_RX_ER_B (P7_4)
283  R_PFS->PORT[7].PIN[4].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
284  R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (3 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
285 
286  //Configure RMII0_CRS_DV_B (P7_5)
287  R_PFS->PORT[7].PIN[5].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
288  R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (3 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
289 
290  //Configure PHY reset pin (P4_4)
291  R_PFS->PORT[4].PIN[4].PmnPFS = R_PFS_PORT_PIN_PmnPFS_PDR_Msk;
292 
293  //Lock PFS registers
294  R_PMISC->PWPRS &= ~R_PMISC_PWPR_PFSWE_Msk;
295  R_PMISC->PWPRS |= R_PMISC_PWPR_B0WI_Msk;
296 
297  //Reset PHY transceiver
298  R_PORT4->PCNTR3 = (1 << 4) << R_PORT0_PCNTR3_PORR_Pos;
299  sleep(10);
300  R_PORT4->PCNTR3 = (1 << 4) << R_PORT0_PCNTR3_POSR_Pos;
301  sleep(10);
302 
303 //EK-RA8D1 evaluation board?
304 #elif defined(USE_EK_RA8D1)
305  //Disable protection
306  R_SYSTEM->PRCR = 0xA50B;
307  //Disable VBATT channel 0 input (P4_2)
308  R_SYSTEM->VBTICTLR &= ~R_SYSTEM_VBTICTLR_VCH0INEN_Msk;
309  //Enable protection
310  R_SYSTEM->PRCR = 0xA500;
311 
312  //Unlock PFS registers
313  R_PMISC->PWPRS &= ~R_PMISC_PWPR_B0WI_Msk;
314  R_PMISC->PWPRS |= R_PMISC_PWPR_PFSWE_Msk;
315 
316  //Select RMII interface mode
317  R_PMISC->PFENET &= ~R_PMISC_PFENET_PHYMODE0_Msk;
318 
319  //Configure ET0_MDC (P4_1)
320  R_PFS->PORT[4].PIN[1].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
321  R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (1 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
322 
323  //Configure ET0_MDIO (P4_2)
324  R_PFS->PORT[4].PIN[2].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
325  R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (1 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
326 
327  //Configure RMII0_TXD_EN_B (P4_5)
328  R_PFS->PORT[4].PIN[5].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
329  R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (3 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
330 
331  //Configure RMII0_TXD1_B (P4_6)
332  R_PFS->PORT[4].PIN[6].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
333  R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (3 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
334 
335  //Configure RMII0_TXD0_B (P7_0)
336  R_PFS->PORT[7].PIN[0].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
337  R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (3 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
338 
339  //Configure REF50CK0_B (P7_1)
340  R_PFS->PORT[7].PIN[1].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
341  R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (3 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
342 
343  //Configure RMII0_RXD0_B (P7_2)
344  R_PFS->PORT[7].PIN[2].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
345  R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (3 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
346 
347  //Configure RMII0_RXD1_B (P7_3)
348  R_PFS->PORT[7].PIN[3].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
349  R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (3 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
350 
351  //Configure RMII0_RX_ER_B (P7_4)
352  R_PFS->PORT[7].PIN[4].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
353  R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (3 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
354 
355  //Configure RMII0_CRS_DV_B (P7_5)
356  R_PFS->PORT[7].PIN[5].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
357  R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (3 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
358 
359  //Configure PHY reset pin (P7_6)
360  R_PFS->PORT[7].PIN[6].PmnPFS = R_PFS_PORT_PIN_PmnPFS_PDR_Msk;
361 
362  //Lock PFS registers
363  R_PMISC->PWPRS &= ~R_PMISC_PWPR_PFSWE_Msk;
364  R_PMISC->PWPRS |= R_PMISC_PWPR_B0WI_Msk;
365 
366  //Reset PHY transceiver
367  R_PORT7->PCNTR3 = (1 << 6) << R_PORT0_PCNTR3_PORR_Pos;
368  sleep(10);
369  R_PORT7->PCNTR3 = (1 << 6) << R_PORT0_PCNTR3_POSR_Pos;
370  sleep(10);
371 
372 //MCK-RA8T1 evaluation board?
373 #elif defined(USE_MCK_RA8T1)
374  //Disable protection
375  R_SYSTEM->PRCR = 0xA50B;
376  //Disable VBATT channel 0 input (P4_2)
377  R_SYSTEM->VBTICTLR &= ~R_SYSTEM_VBTICTLR_VCH0INEN_Msk;
378  //Enable protection
379  R_SYSTEM->PRCR = 0xA500;
380 
381  //Unlock PFS registers
382  R_PMISC->PWPRS &= ~R_PMISC_PWPR_B0WI_Msk;
383  R_PMISC->PWPRS |= R_PMISC_PWPR_PFSWE_Msk;
384 
385  //Select RMII interface mode
386  R_PMISC->PFENET &= ~R_PMISC_PFENET_PHYMODE0_Msk;
387 
388  //Configure ET0_MDC (P4_1)
389  R_PFS->PORT[4].PIN[1].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
390  R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (1 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
391 
392  //Configure ET0_MDIO (P4_2)
393  R_PFS->PORT[4].PIN[2].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
394  R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (1 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
395 
396  //Configure RMII0_TXD_EN_B (P4_5)
397  R_PFS->PORT[4].PIN[5].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
398  R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (3 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
399 
400  //Configure RMII0_TXD1_B (P4_6)
401  R_PFS->PORT[4].PIN[6].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
402  R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (3 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
403 
404  //Configure RMII0_TXD0_B (P7_0)
405  R_PFS->PORT[7].PIN[0].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
406  R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (3 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
407 
408  //Configure REF50CK0_B (P7_1)
409  R_PFS->PORT[7].PIN[1].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
410  R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (3 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
411 
412  //Configure RMII0_RXD0_B (P7_2)
413  R_PFS->PORT[7].PIN[2].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
414  R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (3 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
415 
416  //Configure RMII0_RXD1_B (P7_3)
417  R_PFS->PORT[7].PIN[3].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
418  R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (3 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
419 
420  //Configure RMII0_RX_ER_B (P7_4)
421  R_PFS->PORT[7].PIN[4].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
422  R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (3 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
423 
424  //Configure RMII0_CRS_DV_B (P7_5)
425  R_PFS->PORT[7].PIN[5].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
426  R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (3 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
427 
428  //Configure PHY reset pin (PB_1)
429  R_PFS->PORT[11].PIN[1].PmnPFS = R_PFS_PORT_PIN_PmnPFS_PDR_Msk;
430 
431  //Lock PFS registers
432  R_PMISC->PWPRS &= ~R_PMISC_PWPR_PFSWE_Msk;
433  R_PMISC->PWPRS |= R_PMISC_PWPR_B0WI_Msk;
434 
435  //Reset PHY transceiver
436  R_PORTB->PCNTR3 = (1 << 1) << R_PORTB_PCNTR3_PORR_Pos;
437  sleep(10);
438  R_PORTB->PCNTR3 = (1 << 1) << R_PORTB_PCNTR3_POSR_Pos;
439  sleep(10);
440 
441 //M13-RA8D1-EK evaluation board?
442 #elif defined(USE_M13_RA8D1_EK)
443  //Unlock PFS registers
444  R_PMISC->PWPRS &= ~R_PMISC_PWPR_B0WI_Msk;
445  R_PMISC->PWPRS |= R_PMISC_PWPR_PFSWE_Msk;
446 
447  //Select RMII interface mode
448  R_PMISC->PFENET &= ~R_PMISC_PFENET_PHYMODE0_Msk;
449 
450  //Configure RMII0_TXD_EN_B (P4_5)
451  R_PFS->PORT[4].PIN[5].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
452  R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (3 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
453 
454  //Configure RMII0_TXD1_B (P4_6)
455  R_PFS->PORT[4].PIN[6].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
456  R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (3 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
457 
458  //Configure RMII0_TXD0_B (P7_0)
459  R_PFS->PORT[7].PIN[0].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
460  R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (3 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
461 
462  //Configure REF50CK0_B (P7_1)
463  R_PFS->PORT[7].PIN[1].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
464  R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (3 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
465 
466  //Configure RMII0_RXD0_B (P7_2)
467  R_PFS->PORT[7].PIN[2].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
468  R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (3 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
469 
470  //Configure RMII0_RXD1_B (P7_3)
471  R_PFS->PORT[7].PIN[3].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
472  R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (3 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
473 
474  //Configure RMII0_RX_ER_B (P7_4)
475  R_PFS->PORT[7].PIN[4].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
476  R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (3 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
477 
478  //Configure RMII0_CRS_DV_B (P7_5)
479  R_PFS->PORT[7].PIN[5].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
480  R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (3 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
481 
482  //Configure PHY reset pin (P4_4)
483  R_PFS->PORT[4].PIN[4].PmnPFS = R_PFS_PORT_PIN_PmnPFS_PDR_Msk;
484 
485  //Lock PFS registers
486  R_PMISC->PWPRS &= ~R_PMISC_PWPR_PFSWE_Msk;
487  R_PMISC->PWPRS |= R_PMISC_PWPR_B0WI_Msk;
488 
489  //Reset PHY transceiver
490  R_PORT4->PCNTR3 = (1 << 4) << R_PORT0_PCNTR3_PORR_Pos;
491  sleep(10);
492  R_PORT4->PCNTR3 = (1 << 4) << R_PORT0_PCNTR3_POSR_Pos;
493  sleep(10);
494 #endif
495 }
496 
497 
498 /**
499  * @brief Initialize DMA descriptor lists
500  * @param[in] interface Underlying network interface
501  **/
502 
504 {
505  uint_t i;
506 
507  //Initialize TX descriptors
508  for(i = 0; i < RA8_ETH_TX_BUFFER_COUNT; i++)
509  {
510  //The descriptor is initially owned by the application
511  txDmaDesc[i].td0 = 0;
512  //Transmit buffer length
513  txDmaDesc[i].td1 = 0;
514  //Transmit buffer address
515  txDmaDesc[i].td2 = (uint32_t) txBuffer[i];
516  //Clear padding field
517  txDmaDesc[i].padding = 0;
518  }
519 
520  //Mark the last descriptor entry with the TDLE flag
521  txDmaDesc[i - 1].td0 |= EDMAC_TD0_TDLE;
522  //Initialize TX descriptor index
523  txIndex = 0;
524 
525  //Initialize RX descriptors
526  for(i = 0; i < RA8_ETH_RX_BUFFER_COUNT; i++)
527  {
528  //The descriptor is initially owned by the DMA
529  rxDmaDesc[i].rd0 = EDMAC_RD0_RACT;
530  //Receive buffer length
532  //Receive buffer address
533  rxDmaDesc[i].rd2 = (uint32_t) rxBuffer[i];
534  //Clear padding field
535  rxDmaDesc[i].padding = 0;
536  }
537 
538  //Mark the last descriptor entry with the RDLE flag
539  rxDmaDesc[i - 1].rd0 |= EDMAC_RD0_RDLE;
540  //Initialize RX descriptor index
541  rxIndex = 0;
542 
543  //Start address of the TX descriptor list
544  R_ETHERC_EDMAC->TDLAR = (uint32_t) txDmaDesc;
545  //Start address of the RX descriptor list
546  R_ETHERC_EDMAC->RDLAR = (uint32_t) rxDmaDesc;
547 }
548 
549 
550 /**
551  * @brief RA8 Ethernet MAC timer handler
552  *
553  * This routine is periodically called by the TCP/IP stack to handle periodic
554  * operations such as polling the link state
555  *
556  * @param[in] interface Underlying network interface
557  **/
558 
559 void ra8EthTick(NetInterface *interface)
560 {
561  //Valid Ethernet PHY or switch driver?
562  if(interface->phyDriver != NULL)
563  {
564  //Handle periodic operations
565  interface->phyDriver->tick(interface);
566  }
567  else if(interface->switchDriver != NULL)
568  {
569  //Handle periodic operations
570  interface->switchDriver->tick(interface);
571  }
572  else
573  {
574  //Just for sanity
575  }
576 }
577 
578 
579 /**
580  * @brief Enable interrupts
581  * @param[in] interface Underlying network interface
582  **/
583 
585 {
586  //Enable Ethernet MAC interrupts
587  NVIC_EnableIRQ(EDMAC0_EINT_IRQn);
588 
589  //Valid Ethernet PHY or switch driver?
590  if(interface->phyDriver != NULL)
591  {
592  //Enable Ethernet PHY interrupts
593  interface->phyDriver->enableIrq(interface);
594  }
595  else if(interface->switchDriver != NULL)
596  {
597  //Enable Ethernet switch interrupts
598  interface->switchDriver->enableIrq(interface);
599  }
600  else
601  {
602  //Just for sanity
603  }
604 }
605 
606 
607 /**
608  * @brief Disable interrupts
609  * @param[in] interface Underlying network interface
610  **/
611 
613 {
614  //Disable Ethernet MAC interrupts
615  NVIC_DisableIRQ(EDMAC0_EINT_IRQn);
616 
617  //Valid Ethernet PHY or switch driver?
618  if(interface->phyDriver != NULL)
619  {
620  //Disable Ethernet PHY interrupts
621  interface->phyDriver->disableIrq(interface);
622  }
623  else if(interface->switchDriver != NULL)
624  {
625  //Disable Ethernet switch interrupts
626  interface->switchDriver->disableIrq(interface);
627  }
628  else
629  {
630  //Just for sanity
631  }
632 }
633 
634 
635 /**
636  * @brief RA8 Ethernet MAC interrupt service routine
637  **/
638 
640 {
641  bool_t flag;
642  uint32_t status;
643 
644  //Interrupt service routine prologue
645  osEnterIsr();
646 
647  //This flag will be set if a higher priority task must be woken
648  flag = FALSE;
649 
650  //Read interrupt status register
651  status = R_ETHERC_EDMAC->EESR;
652 
653  //Packet transmitted?
654  if((status & R_ETHERC_EDMAC_EESR_TWB_Msk) != 0)
655  {
656  //Clear TWB interrupt flag
657  R_ETHERC_EDMAC->EESR = R_ETHERC_EDMAC_EESR_TWB_Msk;
658 
659  //Check whether the TX buffer is available for writing
660  if((txDmaDesc[txIndex].td0 & EDMAC_TD0_TACT) == 0)
661  {
662  //Notify the TCP/IP stack that the transmitter is ready to send
663  flag |= osSetEventFromIsr(&nicDriverInterface->nicTxEvent);
664  }
665  }
666 
667  //Packet received?
668  if((status & R_ETHERC_EDMAC_EESR_FR_Msk) != 0)
669  {
670  //Clear FR interrupt flag
671  R_ETHERC_EDMAC->EESR = R_ETHERC_EDMAC_EESR_FR_Msk;
672 
673  //Set event flag
674  nicDriverInterface->nicEvent = TRUE;
675  //Notify the TCP/IP stack of the event
676  flag |= osSetEventFromIsr(&netEvent);
677  }
678 
679  //Clear IR flag
680  R_ICU->IELSR[EDMAC0_EINT_IRQn] &= ~R_ICU_IELSR_IR_Msk;
681 
682  //Interrupt service routine epilogue
683  osExitIsr(flag);
684 }
685 
686 
687 /**
688  * @brief RA8 Ethernet MAC event handler
689  * @param[in] interface Underlying network interface
690  **/
691 
693 {
694  error_t error;
695 
696  //Process all pending packets
697  do
698  {
699  //Read incoming packet
700  error = ra8EthReceivePacket(interface);
701 
702  //No more data in the receive buffer?
703  } while(error != ERROR_BUFFER_EMPTY);
704 }
705 
706 
707 /**
708  * @brief Send a packet
709  * @param[in] interface Underlying network interface
710  * @param[in] buffer Multi-part buffer containing the data to send
711  * @param[in] offset Offset to the first data byte
712  * @param[in] ancillary Additional options passed to the stack along with
713  * the packet
714  * @return Error code
715  **/
716 
718  const NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary)
719 {
720  //Retrieve the length of the packet
721  size_t length = netBufferGetLength(buffer) - offset;
722 
723  //Check the frame length
725  {
726  //The transmitter can accept another packet
727  osSetEvent(&interface->nicTxEvent);
728  //Report an error
729  return ERROR_INVALID_LENGTH;
730  }
731 
732  //Make sure the current buffer is available for writing
733  if((txDmaDesc[txIndex].td0 & EDMAC_TD0_TACT) != 0)
734  {
735  return ERROR_FAILURE;
736  }
737 
738  //Copy user data to the transmit buffer
739  netBufferRead(txBuffer[txIndex], buffer, offset, length);
740 
741  //Write the number of bytes to send
742  txDmaDesc[txIndex].td1 = (length << 16) & EDMAC_TD1_TBL;
743 
744  //Check current index
745  if(txIndex < (RA8_ETH_TX_BUFFER_COUNT - 1))
746  {
747  //Give the ownership of the descriptor to the DMA engine
748  txDmaDesc[txIndex].td0 = EDMAC_TD0_TACT | EDMAC_TD0_TFP_SOF |
750 
751  //Point to the next descriptor
752  txIndex++;
753  }
754  else
755  {
756  //Give the ownership of the descriptor to the DMA engine
757  txDmaDesc[txIndex].td0 = EDMAC_TD0_TACT | EDMAC_TD0_TDLE |
759 
760  //Wrap around
761  txIndex = 0;
762  }
763 
764  //Instruct the DMA to poll the transmit descriptor list
765  R_ETHERC_EDMAC->EDTRR = R_ETHERC_EDMAC_EDTRR_TR_Msk;
766 
767  //Check whether the next buffer is available for writing
768  if((txDmaDesc[txIndex].td0 & EDMAC_TD0_TACT) == 0)
769  {
770  //The transmitter can accept another packet
771  osSetEvent(&interface->nicTxEvent);
772  }
773 
774  //Successful write operation
775  return NO_ERROR;
776 }
777 
778 
779 /**
780  * @brief Receive a packet
781  * @param[in] interface Underlying network interface
782  * @return Error code
783  **/
784 
786 {
787  error_t error;
788  size_t n;
789  NetRxAncillary ancillary;
790 
791  //Current buffer available for reading?
792  if((rxDmaDesc[rxIndex].rd0 & EDMAC_RD0_RACT) == 0)
793  {
794  //SOF and EOF flags should be set
795  if((rxDmaDesc[rxIndex].rd0 & EDMAC_RD0_RFP_SOF) != 0 &&
796  (rxDmaDesc[rxIndex].rd0 & EDMAC_RD0_RFP_EOF) != 0)
797  {
798  //Make sure no error occurred
799  if((rxDmaDesc[rxIndex].rd0 & (EDMAC_RD0_RFS_MASK & ~EDMAC_RD0_RFS_RMAF)) == 0)
800  {
801  //Retrieve the length of the frame
802  n = rxDmaDesc[rxIndex].rd1 & EDMAC_RD1_RFL;
803  //Limit the number of data to read
805 
806  //Additional options can be passed to the stack along with the packet
807  ancillary = NET_DEFAULT_RX_ANCILLARY;
808 
809  //Pass the packet to the upper layer
810  nicProcessPacket(interface, rxBuffer[rxIndex], n, &ancillary);
811 
812  //Valid packet received
813  error = NO_ERROR;
814  }
815  else
816  {
817  //The received packet contains an error
818  error = ERROR_INVALID_PACKET;
819  }
820  }
821  else
822  {
823  //The packet is not valid
824  error = ERROR_INVALID_PACKET;
825  }
826 
827  //Check current index
828  if(rxIndex < (RA8_ETH_RX_BUFFER_COUNT - 1))
829  {
830  //Give the ownership of the descriptor back to the DMA
831  rxDmaDesc[rxIndex].rd0 = EDMAC_RD0_RACT;
832  //Point to the next descriptor
833  rxIndex++;
834  }
835  else
836  {
837  //Give the ownership of the descriptor back to the DMA
838  rxDmaDesc[rxIndex].rd0 = EDMAC_RD0_RACT | EDMAC_RD0_RDLE;
839  //Wrap around
840  rxIndex = 0;
841  }
842 
843  //Instruct the DMA to poll the receive descriptor list
844  R_ETHERC_EDMAC->EDRRR = R_ETHERC_EDMAC_EDRRR_RR_Msk;
845  }
846  else
847  {
848  //No more data in the receive buffer
849  error = ERROR_BUFFER_EMPTY;
850  }
851 
852  //Return status code
853  return error;
854 }
855 
856 
857 /**
858  * @brief Configure MAC address filtering
859  * @param[in] interface Underlying network interface
860  * @return Error code
861  **/
862 
864 {
865  uint_t i;
866  bool_t acceptMulticast;
867 
868  //Debug message
869  TRACE_DEBUG("Updating MAC filter...\r\n");
870 
871  //Promiscuous mode?
872  if(interface->promiscuous)
873  {
874  //Accept all frames regardless of their destination address
875  R_ETHERC0->ECMR |= R_ETHERC0_ECMR_PRM_Msk;
876  }
877  else
878  {
879  //Disable promiscuous mode
880  R_ETHERC0->ECMR &= ~R_ETHERC0_ECMR_PRM_Msk;
881 
882  //Set the upper 32 bits of the MAC address
883  R_ETHERC0->MAHR = (interface->macAddr.b[0] << 24) | (interface->macAddr.b[1] << 16) |
884  (interface->macAddr.b[2] << 8) | interface->macAddr.b[3];
885 
886  //Set the lower 16 bits of the MAC address
887  R_ETHERC0->MALR = (interface->macAddr.b[4] << 8) | interface->macAddr.b[5];
888 
889  //This flag will be set if multicast addresses should be accepted
890  acceptMulticast = FALSE;
891 
892  //The MAC address filter contains the list of MAC addresses to accept
893  //when receiving an Ethernet frame
894  for(i = 0; i < MAC_ADDR_FILTER_SIZE; i++)
895  {
896  //Valid entry?
897  if(interface->macAddrFilter[i].refCount > 0)
898  {
899  //Accept multicast addresses
900  acceptMulticast = TRUE;
901  //We are done
902  break;
903  }
904  }
905 
906  //Enable or disable the reception of multicast frames
907  if(acceptMulticast || interface->acceptAllMulticast)
908  {
909  R_ETHERC_EDMAC->EESR |= R_ETHERC_EDMAC_EESR_RMAF_Msk;
910  }
911  else
912  {
913  R_ETHERC_EDMAC->EESR &= ~R_ETHERC_EDMAC_EESR_RMAF_Msk;
914  }
915  }
916 
917  //Successful processing
918  return NO_ERROR;
919 }
920 
921 
922 /**
923  * @brief Adjust MAC configuration parameters for proper operation
924  * @param[in] interface Underlying network interface
925  * @return Error code
926  **/
927 
929 {
930  uint32_t mode;
931 
932  //Read ETHERC mode register
933  mode = R_ETHERC0->ECMR;
934 
935  //10BASE-T or 100BASE-TX operation mode?
936  if(interface->linkSpeed == NIC_LINK_SPEED_100MBPS)
937  {
938  mode |= R_ETHERC0_ECMR_RTM_Msk;
939  }
940  else
941  {
942  mode &= ~R_ETHERC0_ECMR_RTM_Msk;
943  }
944 
945  //Half-duplex or full-duplex mode?
946  if(interface->duplexMode == NIC_FULL_DUPLEX_MODE)
947  {
948  mode |= R_ETHERC0_ECMR_DM_Msk;
949  }
950  else
951  {
952  mode &= ~R_ETHERC0_ECMR_DM_Msk;
953  }
954 
955  //Update ETHERC mode register
956  R_ETHERC0->ECMR = mode;
957 
958  //Successful processing
959  return NO_ERROR;
960 }
961 
962 
963 /**
964  * @brief Write PHY register
965  * @param[in] opcode Access type (2 bits)
966  * @param[in] phyAddr PHY address (5 bits)
967  * @param[in] regAddr Register address (5 bits)
968  * @param[in] data Register value
969  **/
970 
971 void ra8EthWritePhyReg(uint8_t opcode, uint8_t phyAddr,
972  uint8_t regAddr, uint16_t data)
973 {
974  //Synchronization pattern
976  //Start of frame
978  //Set up a write operation
980  //Write PHY address
981  ra8EthWriteSmi(phyAddr, 5);
982  //Write register address
984  //Turnaround
986  //Write register value
987  ra8EthWriteSmi(data, 16);
988  //Release MDIO
989  ra8EthReadSmi(1);
990 }
991 
992 
993 /**
994  * @brief Read PHY register
995  * @param[in] opcode Access type (2 bits)
996  * @param[in] phyAddr PHY address (5 bits)
997  * @param[in] regAddr Register address (5 bits)
998  * @return Register value
999  **/
1000 
1001 uint16_t ra8EthReadPhyReg(uint8_t opcode, uint8_t phyAddr,
1002  uint8_t regAddr)
1003 {
1004  uint16_t data;
1005 
1006  //Synchronization pattern
1007  ra8EthWriteSmi(SMI_SYNC, 32);
1008  //Start of frame
1010  //Set up a read operation
1011  ra8EthWriteSmi(opcode, 2);
1012  //Write PHY address
1013  ra8EthWriteSmi(phyAddr, 5);
1014  //Write register address
1015  ra8EthWriteSmi(regAddr, 5);
1016  //Turnaround to avoid contention
1017  ra8EthReadSmi(1);
1018  //Read register value
1019  data = ra8EthReadSmi(16);
1020  //Force the PHY to release the MDIO pin
1021  ra8EthReadSmi(1);
1022 
1023  //Return PHY register contents
1024  return data;
1025 }
1026 
1027 
1028 /**
1029  * @brief SMI write operation
1030  * @param[in] data Raw data to be written
1031  * @param[in] length Number of bits to be written
1032  **/
1033 
1035 {
1036  //Skip the most significant bits since they are meaningless
1037  data <<= 32 - length;
1038 
1039  //Configure MDIO as an output
1040  R_ETHERC0->PIR |= R_ETHERC0_PIR_MMD_Msk;
1041 
1042  //Write the specified number of bits
1043  while(length--)
1044  {
1045  //Write MDIO
1046  if((data & 0x80000000) != 0)
1047  {
1048  R_ETHERC0->PIR |= R_ETHERC0_PIR_MDO_Msk;
1049  }
1050  else
1051  {
1052  R_ETHERC0->PIR &= ~R_ETHERC0_PIR_MDO_Msk;
1053  }
1054 
1055  //Assert MDC
1056  usleep(1);
1057  R_ETHERC0->PIR |= R_ETHERC0_PIR_MDC_Msk;
1058  //Deassert MDC
1059  usleep(1);
1060  R_ETHERC0->PIR &= ~R_ETHERC0_PIR_MDC_Msk;
1061 
1062  //Rotate data
1063  data <<= 1;
1064  }
1065 }
1066 
1067 
1068 /**
1069  * @brief SMI read operation
1070  * @param[in] length Number of bits to be read
1071  * @return Data resulting from the MDIO read operation
1072  **/
1073 
1075 {
1076  uint32_t data = 0;
1077 
1078  //Configure MDIO as an input
1079  R_ETHERC0->PIR &= ~R_ETHERC0_PIR_MMD_Msk;
1080 
1081  //Read the specified number of bits
1082  while(length--)
1083  {
1084  //Rotate data
1085  data <<= 1;
1086 
1087  //Assert MDC
1088  R_ETHERC0->PIR |= R_ETHERC0_PIR_MDC_Msk;
1089  usleep(1);
1090  //Deassert MDC
1091  R_ETHERC0->PIR &= ~R_ETHERC0_PIR_MDC_Msk;
1092  usleep(1);
1093 
1094  //Check MDIO state
1095  if((R_ETHERC0->PIR & R_ETHERC0_PIR_MDI_Msk) != 0)
1096  {
1097  data |= 0x01;
1098  }
1099  }
1100 
1101  //Return the received data
1102  return data;
1103 }
bool_t osSetEventFromIsr(OsEvent *event)
Set an event object to the signaled state from an interrupt service routine.
#define EDMAC_RD0_RFP_EOF
#define usleep(delay)
Definition: os_port.h:306
uint8_t opcode
Definition: dns_common.h:188
int bool_t
Definition: compiler_port.h:61
#define netEvent
Definition: net_legacy.h:196
@ NIC_FULL_DUPLEX_MODE
Definition: nic.h:125
size_t netBufferRead(void *dest, const NetBuffer *src, size_t srcOffset, size_t length)
Read data from a multi-part buffer.
Definition: net_mem.c:690
#define RA8_ETH_IRQ_GROUP_PRIORITY
void ra8EthEnableIrq(NetInterface *interface)
Enable interrupts.
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:89
#define MAC_ADDR_FILTER_SIZE
Definition: ethernet.h:95
#define TRUE
Definition: os_port.h:50
uint8_t data[]
Definition: ethernet.h:222
#define sleep(delay)
Definition: os_port.h:310
void ra8EthWriteSmi(uint32_t data, uint_t length)
SMI write operation.
#define EDMAC_RD0_RACT
#define RA8_ETH_TX_BUFFER_SIZE
#define R_MSTP_MSTPCRB_MSTPB15_Msk
uint16_t ra8EthReadPhyReg(uint8_t opcode, uint8_t phyAddr, uint8_t regAddr)
Read PHY register.
#define SMI_TA
Definition: nic.h:68
Renesas RA8M1 / RA8D1 / RA8T1 Ethernet MAC driver.
#define SMI_START
Definition: nic.h:64
error_t ra8EthUpdateMacAddrFilter(NetInterface *interface)
Configure MAC address filtering.
void nicProcessPacket(NetInterface *interface, uint8_t *packet, size_t length, NetRxAncillary *ancillary)
Handle a packet received by the network controller.
Definition: nic.c:392
void ra8EthInitDmaDesc(NetInterface *interface)
Initialize DMA descriptor lists.
void EDMAC0_EINT_IRQHandler(void)
RA8 Ethernet MAC interrupt service routine.
#define osExitIsr(flag)
#define EDMAC_TD0_TWBI
error_t ra8EthUpdateMacConfig(NetInterface *interface)
Adjust MAC configuration parameters for proper operation.
#define EDMAC_RD1_RFL
#define EDMAC_RD0_RDLE
#define FALSE
Definition: os_port.h:46
#define EDMAC_RD0_RFP_SOF
void ra8EthDisableIrq(NetInterface *interface)
Disable interrupts.
error_t
Error codes.
Definition: error.h:43
__weak_func void ra8EthInitGpio(NetInterface *interface)
GPIO configuration.
#define EDMAC_RD1_RBL
#define R_ETHERC_EDMAC
#define RA8_ETH_RX_BUFFER_SIZE
#define RA8_ETH_IRQ_SUB_PRIORITY
const NetRxAncillary NET_DEFAULT_RX_ANCILLARY
Definition: net_misc.c:105
@ ERROR_FAILURE
Generic error code.
Definition: error.h:45
#define txBuffer
#define NetRxAncillary
Definition: net_misc.h:40
#define EDMAC_RD0_RFS_RMAF
@ ERROR_INVALID_PACKET
Definition: error.h:141
#define NetInterface
Definition: net.h:36
@ ERROR_INVALID_LENGTH
Definition: error.h:111
#define EDMAC_RD0_RFS_MASK
const NicDriver ra8EthDriver
RA8 Ethernet MAC driver.
@ ERROR_BUFFER_EMPTY
Definition: error.h:142
#define NetTxAncillary
Definition: net_misc.h:36
#define TRACE_INFO(...)
Definition: debug.h:105
uint8_t length
Definition: tcp.h:375
size_t netBufferGetLength(const NetBuffer *buffer)
Get the actual length of a multi-part buffer.
Definition: net_mem.c:297
#define MIN(a, b)
Definition: os_port.h:63
#define RA8_ETH_RAM_SECTION
#define RA8_ETH_RX_BUFFER_COUNT
#define rxBuffer
uint32_t ra8EthReadSmi(uint_t length)
SMI read operation.
error_t ra8EthReceivePacket(NetInterface *interface)
Receive a packet.
void ra8EthEventHandler(NetInterface *interface)
RA8 Ethernet MAC event handler.
#define EDMAC_TD1_TBL
#define TRACE_DEBUG(...)
Definition: debug.h:119
#define EDMAC_TD0_TFP_SOF
#define EDMAC_TD0_TDLE
error_t ra8EthInit(NetInterface *interface)
RA8 Ethernet MAC initialization.
uint16_t regAddr
#define ETH_MTU
Definition: ethernet.h:116
uint8_t n
#define osEnterIsr()
error_t ra8EthSendPacket(NetInterface *interface, const NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary)
Send a packet.
Transmit DMA descriptor.
void ra8EthTick(NetInterface *interface)
RA8 Ethernet MAC timer handler.
#define rxDmaDesc
void osSetEvent(OsEvent *event)
Set the specified event object to the signaled state.
#define txDmaDesc
#define RA8_ETH_IRQ_PRIORITY_GROUPING
@ NIC_LINK_SPEED_100MBPS
Definition: nic.h:112
#define EDMAC_TD0_TACT
#define SMI_SYNC
Definition: nic.h:63
unsigned int uint_t
Definition: compiler_port.h:57
TCP/IP stack core.
#define RA8_ETH_TX_BUFFER_COUNT
NIC driver.
Definition: nic.h:286
void ra8EthWritePhyReg(uint8_t opcode, uint8_t phyAddr, uint8_t regAddr, uint16_t data)
Write PHY register.
Receive DMA descriptor.
@ NO_ERROR
Success.
Definition: error.h:44
__attribute__((naked))
AVR32 Ethernet MAC interrupt wrapper.
Debugging facilities.
#define EDMAC_TD0_TFP_EOF
@ NIC_TYPE_ETHERNET
Ethernet interface.
Definition: nic.h:83