32 #define TRACE_LEVEL NIC_TRACE_LEVEL
44 #if defined(__ICCARM__)
47 #pragma data_alignment = 32
48 #pragma location = RA6_ETH_RAM_SECTION
51 #pragma data_alignment = 32
52 #pragma location = RA6_ETH_RAM_SECTION
55 #pragma data_alignment = 16
56 #pragma location = RA6_ETH_RAM_SECTION
59 #pragma data_alignment = 16
60 #pragma location = RA6_ETH_RAM_SECTION
123 TRACE_INFO(
"Initializing RA6 Ethernet MAC...\r\n");
126 nicDriverInterface = interface;
129 R_SYSTEM->PRCR = 0xA50B;
133 R_SYSTEM->PRCR = 0xA500;
144 if(interface->phyDriver != NULL)
147 error = interface->phyDriver->init(interface);
149 else if(interface->switchDriver != NULL)
152 error = interface->switchDriver->init(interface);
172 R_ETHERC0->IPGR = 0x14;
175 R_ETHERC0->MAHR = (interface->macAddr.b[0] << 24) | (interface->macAddr.b[1] << 16) |
176 (interface->macAddr.b[2] << 8) | interface->macAddr.b[3];
179 R_ETHERC0->MALR = (interface->macAddr.b[4] << 8) | interface->macAddr.b[5];
183 (0 << R_ETHERC_EDMAC_EDMR_DL_Pos);
190 (15 << R_ETHERC_EDMAC_FDR_RFD_Pos);
197 R_ETHERC_EDMAC_TRIMD_TIS_Msk;
200 R_ETHERC0->ECSIPR = 0;
204 R_ETHERC_EDMAC_EESIPR_FRIP_Msk;
214 R_ETHERC0->ECMR |= R_ETHERC0_ECMR_TE_Msk | R_ETHERC0_ECMR_RE_Msk;
235 #if defined(USE_EK_RA6M3) || defined(USE_EK_RA6M4) || defined(USE_EK_RA6M5)
237 R_SYSTEM->PRCR = 0xA50B;
239 R_SYSTEM->VBTICTLR &= ~R_SYSTEM_VBTICTLR_VCH0INEN_Msk;
241 R_SYSTEM->PRCR = 0xA500;
244 R_PMISC->PWPR &= ~R_PMISC_PWPR_B0WI_Msk;
245 R_PMISC->PWPR |= R_PMISC_PWPR_PFSWE_Msk;
248 R_PMISC->PFENET &= ~R_PMISC_PFENET_PHYMODE0_Msk;
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
291 R_PMISC->PWPR &= ~R_PMISC_PWPR_PFSWE_Msk;
292 R_PMISC->PWPR |= R_PMISC_PWPR_B0WI_Msk;
295 #elif defined(USE_AIK_RA6M3)
297 R_PMISC->PWPR &= ~R_PMISC_PWPR_B0WI_Msk;
298 R_PMISC->PWPR |= R_PMISC_PWPR_PFSWE_Msk;
301 R_PMISC->PFENET &= ~R_PMISC_PFENET_PHYMODE0_Msk;
304 R_PFS->PORT[2].PIN[14].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
305 R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (1 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
308 R_PFS->PORT[2].PIN[11].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
309 R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (1 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
312 R_PFS->PORT[4].PIN[5].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
313 R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (3 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
316 R_PFS->PORT[4].PIN[6].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
317 R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (3 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
320 R_PFS->PORT[7].PIN[0].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
321 R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (3 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
324 R_PFS->PORT[7].PIN[1].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
325 R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (3 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
328 R_PFS->PORT[7].PIN[2].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);
332 R_PFS->PORT[7].PIN[3].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);
336 R_PFS->PORT[7].PIN[4].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);
340 R_PFS->PORT[7].PIN[5].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);
344 R_PFS->PORT[0].PIN[10].PmnPFS = R_PFS_PORT_PIN_PmnPFS_PDR_Msk;
347 R_PMISC->PWPRS &= ~R_PMISC_PWPR_PFSWE_Msk;
348 R_PMISC->PWPRS |= R_PMISC_PWPR_B0WI_Msk;
351 R_PORT0->PCNTR3 = (1 << 10) << R_PORTB_PCNTR3_PORR_Pos;
353 R_PORT0->PCNTR3 = (1 << 10) << R_PORTB_PCNTR3_POSR_Pos;
357 #elif defined(USE_M13_RA6M2_EK) || defined(USE_M13_RA6M4_EK) || \
358 defined(USE_M13_RA6M5_EK)
360 R_PMISC->PWPR &= ~R_PMISC_PWPR_B0WI_Msk;
361 R_PMISC->PWPR |= R_PMISC_PWPR_PFSWE_Msk;
364 R_PMISC->PFENET &= ~R_PMISC_PFENET_PHYMODE0_Msk;
367 R_PFS->PORT[4].PIN[5].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
368 R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (3 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
371 R_PFS->PORT[4].PIN[6].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
372 R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (3 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
375 R_PFS->PORT[7].PIN[0].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
376 R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (3 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
379 R_PFS->PORT[7].PIN[1].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
380 R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (3 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
383 R_PFS->PORT[7].PIN[2].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
384 R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (3 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
387 R_PFS->PORT[7].PIN[3].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
388 R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (3 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
391 R_PFS->PORT[7].PIN[4].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
392 R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (3 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
395 R_PFS->PORT[7].PIN[5].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
396 R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (3 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
399 R_PFS->PORT[6].PIN[5].PmnPFS = R_PFS_PORT_PIN_PmnPFS_PDR_Msk;
402 R_PMISC->PWPR &= ~R_PMISC_PWPR_PFSWE_Msk;
403 R_PMISC->PWPR |= R_PMISC_PWPR_B0WI_Msk;
406 R_PORT6->PCNTR3 = (1 << 5) << R_PORT0_PCNTR3_PORR_Pos;
408 R_PORT6->PCNTR3 = (1 << 5) << R_PORT0_PCNTR3_POSR_Pos;
412 #elif defined(USE_M13_RA6M3_EK)
414 R_SYSTEM->PRCR = 0xA50B;
416 R_SYSTEM->VBTICTLR &= ~R_SYSTEM_VBTICTLR_VCH0INEN_Msk;
418 R_SYSTEM->PRCR = 0xA500;
421 R_PMISC->PWPR &= ~R_PMISC_PWPR_B0WI_Msk;
422 R_PMISC->PWPR |= R_PMISC_PWPR_PFSWE_Msk;
425 R_PMISC->PFENET &= ~R_PMISC_PFENET_PHYMODE0_Msk;
428 R_PFS->PORT[4].PIN[1].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
429 R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (1 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
432 R_PFS->PORT[4].PIN[2].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
433 R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (1 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
436 R_PFS->PORT[4].PIN[8].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
437 R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (3 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
440 R_PFS->PORT[4].PIN[10].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
441 R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (3 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
444 R_PFS->PORT[4].PIN[11].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
445 R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (3 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
448 R_PFS->PORT[4].PIN[12].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
449 R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (3 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
452 R_PFS->PORT[4].PIN[13].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
453 R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (3 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
456 R_PFS->PORT[4].PIN[14].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
457 R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (3 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
460 R_PFS->PORT[4].PIN[15].PmnPFS = (23 << R_PFS_PORT_PIN_PmnPFS_PSEL_Pos) |
461 R_PFS_PORT_PIN_PmnPFS_PMR_Msk | (3 << R_PFS_PORT_PIN_PmnPFS_DSCR_Pos);
464 R_PMISC->PWPR &= ~R_PMISC_PWPR_PFSWE_Msk;
465 R_PMISC->PWPR |= R_PMISC_PWPR_B0WI_Msk;
534 if(interface->phyDriver != NULL)
537 interface->phyDriver->tick(interface);
539 else if(interface->switchDriver != NULL)
542 interface->switchDriver->tick(interface);
559 NVIC_EnableIRQ(EDMAC0_EINT_IRQn);
562 if(interface->phyDriver != NULL)
565 interface->phyDriver->enableIrq(interface);
567 else if(interface->switchDriver != NULL)
570 interface->switchDriver->enableIrq(interface);
587 NVIC_DisableIRQ(EDMAC0_EINT_IRQn);
590 if(interface->phyDriver != NULL)
593 interface->phyDriver->disableIrq(interface);
595 else if(interface->switchDriver != NULL)
598 interface->switchDriver->disableIrq(interface);
626 if((status & R_ETHERC_EDMAC_EESR_TWB_Msk) != 0)
640 if((status & R_ETHERC_EDMAC_EESR_FR_Msk) != 0)
646 nicDriverInterface->nicEvent =
TRUE;
652 R_ICU->IELSR[EDMAC0_EINT_IRQn] &= ~R_ICU_IELSR_IR_Msk;
844 if(interface->promiscuous)
847 R_ETHERC0->ECMR |= R_ETHERC0_ECMR_PRM_Msk;
852 R_ETHERC0->ECMR &= ~R_ETHERC0_ECMR_PRM_Msk;
855 R_ETHERC0->MAHR = (interface->macAddr.b[0] << 24) | (interface->macAddr.b[1] << 16) |
856 (interface->macAddr.b[2] << 8) | interface->macAddr.b[3];
859 R_ETHERC0->MALR = (interface->macAddr.b[4] << 8) | interface->macAddr.b[5];
862 acceptMulticast =
FALSE;
869 if(interface->macAddrFilter[i].refCount > 0)
872 acceptMulticast =
TRUE;
879 if(acceptMulticast || interface->acceptAllMulticast)
905 mode = R_ETHERC0->ECMR;
910 mode |= R_ETHERC0_ECMR_RTM_Msk;
914 mode &= ~R_ETHERC0_ECMR_RTM_Msk;
920 mode |= R_ETHERC0_ECMR_DM_Msk;
924 mode &= ~R_ETHERC0_ECMR_DM_Msk;
928 R_ETHERC0->ECMR = mode;
1012 R_ETHERC0->PIR |= R_ETHERC0_PIR_MMD_Msk;
1018 if((
data & 0x80000000) != 0)
1020 R_ETHERC0->PIR |= R_ETHERC0_PIR_MDO_Msk;
1024 R_ETHERC0->PIR &= ~R_ETHERC0_PIR_MDO_Msk;
1029 R_ETHERC0->PIR |= R_ETHERC0_PIR_MDC_Msk;
1032 R_ETHERC0->PIR &= ~R_ETHERC0_PIR_MDC_Msk;
1051 R_ETHERC0->PIR &= ~R_ETHERC0_PIR_MMD_Msk;
1060 R_ETHERC0->PIR |= R_ETHERC0_PIR_MDC_Msk;
1063 R_ETHERC0->PIR &= ~R_ETHERC0_PIR_MDC_Msk;
1067 if((R_ETHERC0->PIR & R_ETHERC0_PIR_MDI_Msk) != 0)