32 #define TRACE_LEVEL NIC_TRACE_LEVEL
35 #include <machine/intrinsics.h>
36 #include <machine/wdtcon.h>
37 #include "tc_inc_path.h"
38 #include TC_INCLUDE(TCPATH/Ifx_reg.h)
39 #include TC_INCLUDE(TCPATH/IfxCpu_bf.h)
40 #include "interrupts.h"
49 #if defined(__TASKING__)
125 TRACE_INFO(
"Initializing TC2xx Ethernet MAC...\r\n");
128 nicDriverInterface = interface;
133 MODULE_ETH.CLC.U = 0;
143 MODULE_ETH.KRST0.B.RST = 1;
144 MODULE_ETH.KRST1.B.RST = 1;
149 while(MODULE_ETH.KRST0.B.RSTSTAT == 0)
156 MODULE_ETH.KRSTCLR.B.CLR = 1;
161 MODULE_ETH.BUS_MODE.B.SWR = 1;
163 while(MODULE_ETH.BUS_MODE.B.SWR)
168 MODULE_ETH.GMII_ADDRESS.B.CR = 4;
171 if(interface->phyDriver != NULL)
174 error = interface->phyDriver->init(interface);
176 else if(interface->switchDriver != NULL)
179 error = interface->switchDriver->init(interface);
194 MODULE_ETH.MAC_CONFIGURATION.U = 0;
195 MODULE_ETH.MAC_CONFIGURATION.B.PS = 1;
196 MODULE_ETH.MAC_CONFIGURATION.B.DO = 1;
199 MODULE_ETH.MAC_ADDRESS_G0[0].LOW.U = interface->macAddr.w[0] | (interface->macAddr.w[1] << 16);
200 MODULE_ETH.MAC_ADDRESS_G0[0].HIGH.U = interface->macAddr.w[2];
203 for(i = 1; i < 16; i++)
205 MODULE_ETH.MAC_ADDRESS_G0[i].LOW.U = 0;
206 MODULE_ETH.MAC_ADDRESS_G0[i].HIGH.U = 0;
210 MODULE_ETH.HASH_TABLE_LOW.U = 0;
211 MODULE_ETH.HASH_TABLE_HIGH.U = 0;
214 MODULE_ETH.MAC_FRAME_FILTER.U = 0;
215 MODULE_ETH.MAC_FRAME_FILTER.B.HPF = 1;
216 MODULE_ETH.MAC_FRAME_FILTER.B.HMC = 1;
219 MODULE_ETH.FLOW_CONTROL.U = 0;
222 MODULE_ETH.OPERATION_MODE.U = 0;
223 MODULE_ETH.OPERATION_MODE.B.RSF = 1;
224 MODULE_ETH.OPERATION_MODE.B.TSF = 1;
227 MODULE_ETH.BUS_MODE.U = 0;
228 MODULE_ETH.BUS_MODE.B.PRWG = 0;
229 MODULE_ETH.BUS_MODE.B.TXPR = 0;
230 MODULE_ETH.BUS_MODE.B.MB = 0;
231 MODULE_ETH.BUS_MODE.B.AAL = 1;
232 MODULE_ETH.BUS_MODE.B.PBLx8 = 0;
233 MODULE_ETH.BUS_MODE.B.USP = 1;
234 MODULE_ETH.BUS_MODE.B.RPBL = 1;
235 MODULE_ETH.BUS_MODE.B.FB = 0;
236 MODULE_ETH.BUS_MODE.B.PR = 0;
237 MODULE_ETH.BUS_MODE.B.PBL = 1;
238 MODULE_ETH.BUS_MODE.B.ATDS = 1;
239 MODULE_ETH.BUS_MODE.B.DSL = 0;
240 MODULE_ETH.BUS_MODE.B.DA = 0;
246 MODULE_ETH.MMC_CONTROL.B.CNTFREEZ = 1;
249 MODULE_ETH.INTERRUPT_MASK.B.LPIIM = 1;
250 MODULE_ETH.INTERRUPT_MASK.B.TSIM = 1;
251 MODULE_ETH.INTERRUPT_MASK.B.PMTIM = 1;
252 MODULE_ETH.INTERRUPT_MASK.B.PCSANCIM = 1;
253 MODULE_ETH.INTERRUPT_MASK.B.PCSLCHGIM = 1;
254 MODULE_ETH.INTERRUPT_MASK.B.RGSMIIIM = 1;
257 MODULE_ETH.INTERRUPT_ENABLE.B.TIE = 1;
258 MODULE_ETH.INTERRUPT_ENABLE.B.RIE = 1;
259 MODULE_ETH.INTERRUPT_ENABLE.B.NIE = 1;
265 MODULE_ETH.MAC_CONFIGURATION.B.TE = 1;
266 MODULE_ETH.MAC_CONFIGURATION.B.RE = 1;
269 MODULE_ETH.OPERATION_MODE.B.ST = 1;
270 MODULE_ETH.OPERATION_MODE.B.SR = 1;
288 #if defined(USE_KIT_AURIX_TC265_TRB)
290 MODULE_P11.IOCR0.B.PC2 = 22;
293 MODULE_P11.IOCR0.B.PC3 = 22;
296 MODULE_P11.IOCR4.B.PC6 = 22;
299 MODULE_P11.IOCR8.B.PC9 = 0;
300 MODULE_ETH.GPCTL.B.ALTI7 = 0;
303 MODULE_P11.IOCR8.B.PC10 = 0;
304 MODULE_ETH.GPCTL.B.ALTI6 = 0;
307 MODULE_P11.IOCR8.B.PC11 = 0;
308 MODULE_ETH.GPCTL.B.ALTI4 = 0;
311 MODULE_P11.IOCR12.B.PC12 = 0;
312 MODULE_ETH.GPCTL.B.ALTI1 = 0;
315 MODULE_P21.IOCR0.B.PC0 = 22;
318 MODULE_P21.IOCR0.B.PC1 = 22;
319 MODULE_ETH.GPCTL.B.ALTI0 = 1;
322 unlock_safety_wdtcon();
325 MODULE_P11.PCSR.B.SEL2 = 1;
326 MODULE_P11.PCSR.B.SEL3 = 1;
327 MODULE_P11.PCSR.B.SEL6 = 1;
330 lock_safety_wdtcon();
336 MODULE_P11.PDR0.B.PD2 = 0;
337 MODULE_P11.PDR0.B.PL2 = 0;
338 MODULE_P11.PDR0.B.PD3 = 0;
339 MODULE_P11.PDR0.B.PL3 = 0;
340 MODULE_P11.PDR0.B.PD6 = 0;
341 MODULE_P11.PDR0.B.PL6 = 0;
343 MODULE_P11.PDR1.B.PD9 = 0;
344 MODULE_P11.PDR1.B.PL9 = 0;
345 MODULE_P11.PDR1.B.PD10 = 0;
346 MODULE_P11.PDR1.B.PL10 = 0;
347 MODULE_P11.PDR1.B.PD11 = 0;
348 MODULE_P11.PDR1.B.PL11 = 0;
349 MODULE_P11.PDR1.B.PD12 = 0;
350 MODULE_P11.PDR1.B.PL12 = 0;
352 MODULE_P21.PDR0.B.PD0 = 0;
353 MODULE_P21.PDR0.B.PL0 = 0;
354 MODULE_P21.PDR0.B.PD1 = 3;
355 MODULE_P21.PDR0.B.PL1 = 0;
361 MODULE_ETH.GPCTL.B.EPR = 1;
364 #elif defined(USE_KIT_AURIX_TC277_TFT) || defined(USE_KIT_AURIX_TC297_TFT)
366 MODULE_P11.IOCR0.B.PC2 = 22;
369 MODULE_P11.IOCR0.B.PC3 = 22;
372 MODULE_P11.IOCR4.B.PC6 = 22;
375 MODULE_P11.IOCR8.B.PC9 = 0;
376 MODULE_ETH.GPCTL.B.ALTI7 = 0;
379 MODULE_P11.IOCR8.B.PC10 = 0;
380 MODULE_ETH.GPCTL.B.ALTI6 = 0;
383 MODULE_P11.IOCR8.B.PC11 = 0;
384 MODULE_ETH.GPCTL.B.ALTI4 = 0;
387 MODULE_P11.IOCR12.B.PC12 = 0;
388 MODULE_ETH.GPCTL.B.ALTI1 = 0;
391 MODULE_P21.IOCR0.B.PC2 = 21;
394 MODULE_P21.IOCR0.B.PC3 = 0;
395 MODULE_ETH.GPCTL.B.ALTI0 = 3;
398 unlock_safety_wdtcon();
401 MODULE_P11.PCSR.B.SEL2 = 1;
402 MODULE_P11.PCSR.B.SEL3 = 1;
403 MODULE_P11.PCSR.B.SEL6 = 1;
406 lock_safety_wdtcon();
412 MODULE_P11.PDR0.B.PD2 = 0;
413 MODULE_P11.PDR0.B.PL2 = 0;
414 MODULE_P11.PDR0.B.PD3 = 0;
415 MODULE_P11.PDR0.B.PL3 = 0;
416 MODULE_P11.PDR0.B.PD6 = 0;
417 MODULE_P11.PDR0.B.PL6 = 0;
419 MODULE_P11.PDR1.B.PD9 = 0;
420 MODULE_P11.PDR1.B.PL9 = 0;
421 MODULE_P11.PDR1.B.PD10 = 0;
422 MODULE_P11.PDR1.B.PL10 = 0;
423 MODULE_P11.PDR1.B.PD11 = 0;
424 MODULE_P11.PDR1.B.PL11 = 0;
425 MODULE_P11.PDR1.B.PD12 = 0;
426 MODULE_P11.PDR1.B.PL12 = 0;
428 MODULE_P21.PDR0.B.PD2 = 0;
429 MODULE_P21.PDR0.B.PL2 = 0;
430 MODULE_P21.PDR0.B.PD3 = 0;
431 MODULE_P21.PDR0.B.PL3 = 0;
437 MODULE_ETH.GPCTL.B.EPR = 1;
519 if(interface->phyDriver != NULL)
522 interface->phyDriver->tick(interface);
524 else if(interface->switchDriver != NULL)
527 interface->switchDriver->tick(interface);
544 InterruptEnable(SRC_ID_ETH);
547 if(interface->phyDriver != NULL)
550 interface->phyDriver->enableIrq(interface);
552 else if(interface->switchDriver != NULL)
555 interface->switchDriver->enableIrq(interface);
572 InterruptDisable(SRC_ID_ETH);
575 if(interface->phyDriver != NULL)
578 interface->phyDriver->disableIrq(interface);
580 else if(interface->switchDriver != NULL)
583 interface->switchDriver->disableIrq(interface);
609 status = MODULE_ETH.STATUS.U;
632 nicDriverInterface->nicEvent =
TRUE;
711 MODULE_ETH.TRANSMIT_POLL_DEMAND.U = 0;
805 MODULE_ETH.RECEIVE_POLL_DEMAND.U = 0;
824 uint32_t hashTable[2];
832 MODULE_ETH.MAC_ADDRESS_G0[0].LOW.U = interface->macAddr.w[0] | (interface->macAddr.w[1] << 16);
833 MODULE_ETH.MAC_ADDRESS_G0[0].HIGH.U = interface->macAddr.w[2];
836 for(i = 0; i < 15; i++)
850 entry = &interface->macAddrFilter[i];
863 k = (crc >> 26) & 0x3F;
866 hashTable[k / 32] |= (1 << (k % 32));
874 unicastMacAddr[j++] = entry->
addr;
881 for(i = 0; i < 15; i++)
884 MODULE_ETH.MAC_ADDRESS_G0[i + 1].LOW.U = unicastMacAddr[0].w[0] | (unicastMacAddr[0].w[1] << 16);
885 MODULE_ETH.MAC_ADDRESS_G0[i + 1].HIGH.U = unicastMacAddr[0].w[2];
890 MODULE_ETH.MAC_ADDRESS_G0[i + 1].HIGH.B.AE = 1;
895 MODULE_ETH.HASH_TABLE_LOW.U = hashTable[0];
896 MODULE_ETH.HASH_TABLE_HIGH.U = hashTable[1];
899 TRACE_DEBUG(
" HASH_TABLE_LOW = %08" PRIX32
"\r\n", MODULE_ETH.HASH_TABLE_LOW.U);
900 TRACE_DEBUG(
" HASH_TABLE_HIGH = %08" PRIX32
"\r\n", MODULE_ETH.HASH_TABLE_HIGH.U);
915 Ifx_ETH_MAC_CONFIGURATION config;
918 config.U = MODULE_ETH.MAC_CONFIGURATION.U;
941 MODULE_ETH.MAC_CONFIGURATION.U = config.U;
963 MODULE_ETH.GMII_ADDRESS.B.GW = 1;
965 MODULE_ETH.GMII_ADDRESS.B.PA = phyAddr;
967 MODULE_ETH.GMII_ADDRESS.B.GR =
regAddr;
970 MODULE_ETH.GMII_DATA.B.GD =
data;
973 MODULE_ETH.GMII_ADDRESS.B.GB = 1;
975 while(MODULE_ETH.GMII_ADDRESS.B.GB)
1003 MODULE_ETH.GMII_ADDRESS.B.GW = 0;
1005 MODULE_ETH.GMII_ADDRESS.B.PA = phyAddr;
1007 MODULE_ETH.GMII_ADDRESS.B.GR =
regAddr;
1010 MODULE_ETH.GMII_ADDRESS.B.GB = 1;
1012 while(MODULE_ETH.GMII_ADDRESS.B.GB)
1017 data = MODULE_ETH.GMII_DATA.B.GD;
1045 p = (uint8_t *)
data;
1050 for(i = 0; i <
length; i++)
1053 for(j = 0; j < 8; j++)
1056 if((((crc >> 31) ^ (
p[i] >> j)) & 0x01) != 0)
1058 crc = (crc << 1) ^ 0x04C11DB7;