32 #define TRACE_LEVEL NIC_TRACE_LEVEL
44 #if defined(__ICCARM__)
47 #pragma data_alignment = 32
48 #pragma location = RA8_ETH_RAM_SECTION
51 #pragma data_alignment = 32
52 #pragma location = RA8_ETH_RAM_SECTION
55 #pragma data_alignment = 16
56 #pragma location = RA8_ETH_RAM_SECTION
59 #pragma data_alignment = 16
60 #pragma location = RA8_ETH_RAM_SECTION
123 TRACE_INFO(
"Initializing RA8 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_RA8M1)
237 R_SYSTEM->PRCR = 0xA50B;
239 R_SYSTEM->VBTICTLR &= ~R_SYSTEM_VBTICTLR_VCH0INEN_Msk;
241 R_SYSTEM->PRCR = 0xA500;
244 R_PMISC->PWPRS &= ~R_PMISC_PWPR_B0WI_Msk;
245 R_PMISC->PWPRS |= 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_PFS->PORT[4].PIN[4].PmnPFS = R_PFS_PORT_PIN_PmnPFS_PDR_Msk;
294 R_PMISC->PWPRS &= ~R_PMISC_PWPR_PFSWE_Msk;
295 R_PMISC->PWPRS |= R_PMISC_PWPR_B0WI_Msk;
298 R_PORT4->PCNTR3 = (1 << 4) << R_PORT0_PCNTR3_PORR_Pos;
300 R_PORT4->PCNTR3 = (1 << 4) << R_PORT0_PCNTR3_POSR_Pos;
304 #elif defined(USE_EK_RA8D1)
306 R_SYSTEM->PRCR = 0xA50B;
308 R_SYSTEM->VBTICTLR &= ~R_SYSTEM_VBTICTLR_VCH0INEN_Msk;
310 R_SYSTEM->PRCR = 0xA500;
313 R_PMISC->PWPRS &= ~R_PMISC_PWPR_B0WI_Msk;
314 R_PMISC->PWPRS |= R_PMISC_PWPR_PFSWE_Msk;
317 R_PMISC->PFENET &= ~R_PMISC_PFENET_PHYMODE0_Msk;
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
360 R_PFS->PORT[7].PIN[6].PmnPFS = R_PFS_PORT_PIN_PmnPFS_PDR_Msk;
363 R_PMISC->PWPRS &= ~R_PMISC_PWPR_PFSWE_Msk;
364 R_PMISC->PWPRS |= R_PMISC_PWPR_B0WI_Msk;
367 R_PORT7->PCNTR3 = (1 << 6) << R_PORT0_PCNTR3_PORR_Pos;
369 R_PORT7->PCNTR3 = (1 << 6) << R_PORT0_PCNTR3_POSR_Pos;
373 #elif defined(USE_MCK_RA8T1)
375 R_SYSTEM->PRCR = 0xA50B;
377 R_SYSTEM->VBTICTLR &= ~R_SYSTEM_VBTICTLR_VCH0INEN_Msk;
379 R_SYSTEM->PRCR = 0xA500;
382 R_PMISC->PWPRS &= ~R_PMISC_PWPR_B0WI_Msk;
383 R_PMISC->PWPRS |= R_PMISC_PWPR_PFSWE_Msk;
386 R_PMISC->PFENET &= ~R_PMISC_PFENET_PHYMODE0_Msk;
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
429 R_PFS->PORT[11].PIN[1].PmnPFS = R_PFS_PORT_PIN_PmnPFS_PDR_Msk;
432 R_PMISC->PWPRS &= ~R_PMISC_PWPR_PFSWE_Msk;
433 R_PMISC->PWPRS |= R_PMISC_PWPR_B0WI_Msk;
436 R_PORTB->PCNTR3 = (1 << 1) << R_PORTB_PCNTR3_PORR_Pos;
438 R_PORTB->PCNTR3 = (1 << 1) << R_PORTB_PCNTR3_POSR_Pos;
508 if(interface->phyDriver != NULL)
511 interface->phyDriver->tick(interface);
513 else if(interface->switchDriver != NULL)
516 interface->switchDriver->tick(interface);
533 NVIC_EnableIRQ(EDMAC0_EINT_IRQn);
536 if(interface->phyDriver != NULL)
539 interface->phyDriver->enableIrq(interface);
541 else if(interface->switchDriver != NULL)
544 interface->switchDriver->enableIrq(interface);
561 NVIC_DisableIRQ(EDMAC0_EINT_IRQn);
564 if(interface->phyDriver != NULL)
567 interface->phyDriver->disableIrq(interface);
569 else if(interface->switchDriver != NULL)
572 interface->switchDriver->disableIrq(interface);
600 if((status & R_ETHERC_EDMAC_EESR_TWB_Msk) != 0)
614 if((status & R_ETHERC_EDMAC_EESR_FR_Msk) != 0)
620 nicDriverInterface->nicEvent =
TRUE;
626 R_ICU->IELSR[EDMAC0_EINT_IRQn] &= ~R_ICU_IELSR_IR_Msk;
818 if(interface->promiscuous)
821 R_ETHERC0->ECMR |= R_ETHERC0_ECMR_PRM_Msk;
826 R_ETHERC0->ECMR &= ~R_ETHERC0_ECMR_PRM_Msk;
829 R_ETHERC0->MAHR = (interface->macAddr.b[0] << 24) | (interface->macAddr.b[1] << 16) |
830 (interface->macAddr.b[2] << 8) | interface->macAddr.b[3];
833 R_ETHERC0->MALR = (interface->macAddr.b[4] << 8) | interface->macAddr.b[5];
836 acceptMulticast =
FALSE;
843 if(interface->macAddrFilter[i].refCount > 0)
846 acceptMulticast =
TRUE;
853 if(acceptMulticast || interface->acceptAllMulticast)
879 mode = R_ETHERC0->ECMR;
884 mode |= R_ETHERC0_ECMR_RTM_Msk;
888 mode &= ~R_ETHERC0_ECMR_RTM_Msk;
894 mode |= R_ETHERC0_ECMR_DM_Msk;
898 mode &= ~R_ETHERC0_ECMR_DM_Msk;
902 R_ETHERC0->ECMR = mode;
986 R_ETHERC0->PIR |= R_ETHERC0_PIR_MMD_Msk;
992 if((
data & 0x80000000) != 0)
994 R_ETHERC0->PIR |= R_ETHERC0_PIR_MDO_Msk;
998 R_ETHERC0->PIR &= ~R_ETHERC0_PIR_MDO_Msk;
1003 R_ETHERC0->PIR |= R_ETHERC0_PIR_MDC_Msk;
1006 R_ETHERC0->PIR &= ~R_ETHERC0_PIR_MDC_Msk;
1025 R_ETHERC0->PIR &= ~R_ETHERC0_PIR_MMD_Msk;
1034 R_ETHERC0->PIR |= R_ETHERC0_PIR_MDC_Msk;
1037 R_ETHERC0->PIR &= ~R_ETHERC0_PIR_MDC_Msk;
1041 if((R_ETHERC0->PIR & R_ETHERC0_PIR_MDI_Msk) != 0)