32 #define TRACE_LEVEL NIC_TRACE_LEVEL
44 #if defined(__ICCARM__)
47 #pragma data_alignment = 4
50 #pragma data_alignment = 4
53 #pragma data_alignment = 4
56 #pragma data_alignment = 4
119 TRACE_INFO(
"Initializing FM4 Ethernet MAC...\r\n");
122 nicDriverInterface = interface;
128 FM4_ETHERNET_CONTROL->ETH_CLKG_f.MACEN = 1;
131 FM4_ETHERNET_CONTROL->ETH_MODE_f.RST0 = 1;
132 FM4_ETHERNET_CONTROL->ETH_MODE_f.RST0 = 0;
135 FM4_ETHERNET_MAC0->BMR_f.SWR = 1;
137 while(FM4_ETHERNET_MAC0->BMR_f.SWR)
142 while(FM4_ETHERNET_MAC0->AHBSR_f.AHBS)
147 FM4_ETHERNET_MAC0->GAR_f.CR = 5;
150 if(interface->phyDriver != NULL)
153 error = interface->phyDriver->init(interface);
155 else if(interface->switchDriver != NULL)
158 error = interface->switchDriver->init(interface);
173 FM4_ETHERNET_MAC0->MCR = 0;
174 FM4_ETHERNET_MAC0->MCR_f.PS = 1;
175 FM4_ETHERNET_MAC0->MCR_f.DO = 1;
178 FM4_ETHERNET_MAC0->MAR0L = interface->macAddr.w[0] | (interface->macAddr.w[1] << 16);
179 FM4_ETHERNET_MAC0->MAR0H = interface->macAddr.w[2];
182 FM4_ETHERNET_MAC0->MHTRL = 0;
183 FM4_ETHERNET_MAC0->MHTRH = 0;
186 FM4_ETHERNET_MAC0->MFFR = 0;
187 FM4_ETHERNET_MAC0->MFFR_f.HPF = 1;
188 FM4_ETHERNET_MAC0->MFFR_f.HMC = 1;
191 FM4_ETHERNET_MAC0->FCR = 0;
194 FM4_ETHERNET_MAC0->OMR = 0;
195 FM4_ETHERNET_MAC0->OMR_f.RSF = 1;
196 FM4_ETHERNET_MAC0->OMR_f.TSF = 1;
199 FM4_ETHERNET_MAC0->BMR = 0;
200 FM4_ETHERNET_MAC0->BMR_f.TXPR = 0;
201 FM4_ETHERNET_MAC0->BMR_f.MB = 1;
202 FM4_ETHERNET_MAC0->BMR_f.AAL = 0;
203 FM4_ETHERNET_MAC0->BMR_f._8XPBL = 0;
204 FM4_ETHERNET_MAC0->BMR_f.USP = 1;
205 FM4_ETHERNET_MAC0->BMR_f.RPBL = 32;
206 FM4_ETHERNET_MAC0->BMR_f.FB = 0;
207 FM4_ETHERNET_MAC0->BMR_f.PR = 0;
208 FM4_ETHERNET_MAC0->BMR_f.PBL = 32;
209 FM4_ETHERNET_MAC0->BMR_f.ATDS = 1;
210 FM4_ETHERNET_MAC0->BMR_f.DSL = 0;
211 FM4_ETHERNET_MAC0->BMR_f.DA = 0;
218 FM4_ETHERNET_MAC0->MMC_INTR_MASK_TX = 0xFFFFFFFF;
219 FM4_ETHERNET_MAC0->MMC_INTR_MASK_RX = 0xFFFFFFFF;
220 FM4_ETHERNET_MAC0->MMC_IPC_INTR_MASK_RX = 0xFFFFFFFF;
223 bFM4_ETHERNET_MAC0_IMR_LPIIM = 1;
224 bFM4_ETHERNET_MAC0_IMR_TSIM = 1;
225 bFM4_ETHERNET_MAC0_IMR_PIM = 1;
226 bFM4_ETHERNET_MAC0_IMR_RGIM = 1;
229 bFM4_ETHERNET_MAC0_IER_TIE = 1;
230 bFM4_ETHERNET_MAC0_IER_RIE = 1;
231 bFM4_ETHERNET_MAC0_IER_NIE = 1;
241 bFM4_ETHERNET_MAC0_MCR_TE = 1;
242 bFM4_ETHERNET_MAC0_MCR_RE = 1;
245 bFM4_ETHERNET_MAC0_OMR_ST = 1;
246 bFM4_ETHERNET_MAC0_OMR_SR = 1;
264 #if defined(USE_SK_FM4_176L_S6E2CC_ETH) || defined(USE_SK_FM4_176L_S6E2GM)
266 FM4_ETHERNET_CONTROL->ETH_MODE_f.IFMODE = 0;
269 FM4_GPIO->PFRC_f.P0 = 1;
271 FM4_GPIO->PFRC_f.P1 = 1;
273 FM4_GPIO->PFRC_f.P2 = 1;
275 FM4_GPIO->PFRC_f.P3 = 1;
277 FM4_GPIO->PFRC_f.P4 = 1;
279 FM4_GPIO->PFRC_f.P5 = 1;
281 FM4_GPIO->PFRC_f.P6 = 1;
283 FM4_GPIO->PFRC_f.P7 = 1;
285 FM4_GPIO->PFRC_f.P8 = 1;
287 FM4_GPIO->PFRC_f.P9 = 1;
289 FM4_GPIO->PFRC_f.PA = 1;
291 FM4_GPIO->PFRC_f.PC = 1;
293 FM4_GPIO->PFRC_f.PD = 1;
295 FM4_GPIO->PFRC_f.PE = 1;
297 FM4_GPIO->PFRC_f.PF = 1;
299 FM4_GPIO->PFRD_f.P0 = 1;
301 FM4_GPIO->PFRD_f.P1 = 1;
303 FM4_GPIO->PFRD_f.P2 = 1;
306 FM4_GPIO->EPFR14_f.E_TD0E = 1;
307 FM4_GPIO->EPFR14_f.E_TD1E = 1;
308 FM4_GPIO->EPFR14_f.E_TE0E = 1;
309 FM4_GPIO->EPFR14_f.E_TE1E = 1;
310 FM4_GPIO->EPFR14_f.E_MC0E = 1;
311 FM4_GPIO->EPFR14_f.E_MC1B = 1;
312 FM4_GPIO->EPFR14_f.E_MD0B = 1;
313 FM4_GPIO->EPFR14_f.E_MD1B = 1;
314 FM4_GPIO->EPFR14_f.E_SPLC = 1;
317 FM4_GPIO->PFR6_f.P5 = 0;
318 FM4_GPIO->DDR6_f.P5 = 1;
321 FM4_GPIO->PDOR6_f.P5 = 0;
323 FM4_GPIO->PDOR6_f.P5 = 1;
388 FM4_ETHERNET_MAC0->TDLAR = (uint32_t)
txDmaDesc;
390 FM4_ETHERNET_MAC0->RDLAR = (uint32_t)
rxDmaDesc;
406 if(interface->phyDriver != NULL)
409 interface->phyDriver->tick(interface);
411 else if(interface->switchDriver != NULL)
414 interface->switchDriver->tick(interface);
431 NVIC_EnableIRQ(ETHER0_IRQn);
434 if(interface->phyDriver != NULL)
437 interface->phyDriver->enableIrq(interface);
439 else if(interface->switchDriver != NULL)
442 interface->switchDriver->enableIrq(interface);
459 NVIC_DisableIRQ(ETHER0_IRQn);
462 if(interface->phyDriver != NULL)
465 interface->phyDriver->disableIrq(interface);
467 else if(interface->switchDriver != NULL)
470 interface->switchDriver->disableIrq(interface);
495 status = FM4_ETHERNET_MAC0->SR;
518 nicDriverInterface->nicEvent =
TRUE;
597 FM4_ETHERNET_MAC0->TPDR = 0;
677 FM4_ETHERNET_MAC0->RPDR = 0;
695 uint32_t hashTable[2];
702 FM4_ETHERNET_MAC0->MAR0L = interface->macAddr.w[0] | (interface->macAddr.w[1] << 16);
703 FM4_ETHERNET_MAC0->MAR0H = interface->macAddr.w[2];
714 entry = &interface->macAddrFilter[i];
724 k = (crc >> 26) & 0x3F;
727 hashTable[k / 32] |= (1 << (k % 32));
732 FM4_ETHERNET_MAC0->MHTRL = hashTable[0];
733 FM4_ETHERNET_MAC0->MHTRH = hashTable[1];
736 TRACE_DEBUG(
" MACHTLR = %08" PRIX32
"\r\n", FM4_ETHERNET_MAC0->MHTRL);
737 TRACE_DEBUG(
" MACHTHR = %08" PRIX32
"\r\n", FM4_ETHERNET_MAC0->MHTRH);
752 stc_ethernet_mac_mcr_field_t config;
755 config = FM4_ETHERNET_MAC0->MCR_f;
778 FM4_ETHERNET_MAC0->MCR_f = config;
800 FM4_ETHERNET_MAC0->GAR_f.GW = 1;
802 FM4_ETHERNET_MAC0->GAR_f.PA = phyAddr;
804 FM4_ETHERNET_MAC0->GAR_f.GR =
regAddr;
807 FM4_ETHERNET_MAC0->GDR_f.GD =
data;
810 FM4_ETHERNET_MAC0->GAR_f.GB = 1;
812 while(FM4_ETHERNET_MAC0->GAR_f.GB)
840 FM4_ETHERNET_MAC0->GAR_f.GW = 0;
842 FM4_ETHERNET_MAC0->GAR_f.PA = phyAddr;
844 FM4_ETHERNET_MAC0->GAR_f.GR =
regAddr;
847 FM4_ETHERNET_MAC0->GAR_f.GB = 1;
849 while(FM4_ETHERNET_MAC0->GAR_f.GB)
854 data = FM4_ETHERNET_MAC0->GDR_f.GD;
882 p = (uint8_t *)
data;
887 for(i = 0; i <
length; i++)
890 for(j = 0; j < 8; j++)
893 if((((crc >> 31) ^ (
p[i] >> j)) & 0x01) != 0)
895 crc = (crc << 1) ^ 0x04C11DB7;