EE445M RTOS
Taken at the University of Texas Spring 2015
emac.c
Go to the documentation of this file.
1 //*****************************************************************************
2 //
3 // emac.c - Driver for the Integrated Ethernet Controller on Snowflake-class
4 // Tiva devices.
5 //
6 // Copyright (c) 2013-2014 Texas Instruments Incorporated. All rights reserved.
7 // Software License Agreement
8 //
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions
11 // are met:
12 //
13 // Redistributions of source code must retain the above copyright
14 // notice, this list of conditions and the following disclaimer.
15 //
16 // Redistributions in binary form must reproduce the above copyright
17 // notice, this list of conditions and the following disclaimer in the
18 // documentation and/or other materials provided with the
19 // distribution.
20 //
21 // Neither the name of Texas Instruments Incorporated nor the names of
22 // its contributors may be used to endorse or promote products derived
23 // from this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // This is part of revision 2.1.0.12573 of the Tiva Peripheral Driver Library.
38 //
39 //*****************************************************************************
40 
41 //*****************************************************************************
42 //
45 //
46 //*****************************************************************************
47 
48 #include <stdbool.h>
49 #include <stdint.h>
50 #include "inc/hw_ints.h"
51 #include "inc/hw_memmap.h"
52 #include "inc/hw_types.h"
53 #include "inc/hw_emac.h"
54 #include "driverlib/debug.h"
55 #include "driverlib/emac.h"
56 #include "driverlib/sysctl.h"
57 #include "driverlib/interrupt.h"
58 #include "driverlib/sw_crc.h"
59 
60 //*****************************************************************************
61 //
62 // Combined defines used in parameter validity checks.
63 //
64 //*****************************************************************************
65 
66 //*****************************************************************************
67 //
68 // Combined valid configuration flags.
69 //
70 //*****************************************************************************
71 #define VALID_CONFIG_FLAGS (EMAC_CONFIG_USE_MACADDR1 | \
72  EMAC_CONFIG_SA_INSERT | \
73  EMAC_CONFIG_SA_REPLACE | \
74  EMAC_CONFIG_2K_PACKETS | \
75  EMAC_CONFIG_STRIP_CRC | \
76  EMAC_CONFIG_JABBER_DISABLE | \
77  EMAC_CONFIG_JUMBO_ENABLE | \
78  EMAC_CONFIG_IF_GAP_MASK | \
79  EMAC_CONFIG_CS_DISABLE | \
80  EMAC_CONFIG_100MBPS | \
81  EMAC_CONFIG_RX_OWN_DISABLE | \
82  EMAC_CONFIG_LOOPBACK | \
83  EMAC_CONFIG_FULL_DUPLEX | \
84  EMAC_CONFIG_CHECKSUM_OFFLOAD | \
85  EMAC_CONFIG_RETRY_DISABLE | \
86  EMAC_CONFIG_AUTO_CRC_STRIPPING | \
87  EMAC_CONFIG_BO_MASK | \
88  EMAC_CONFIG_DEFERRAL_CHK_ENABLE | \
89  EMAC_CONFIG_PREAMBLE_MASK)
90 
91 //*****************************************************************************
92 //
93 // Combined valid frame filter flags.
94 //
95 //*****************************************************************************
96 #define VALID_FRMFILTER_FLAGS (EMAC_FRMFILTER_RX_ALL | \
97  EMAC_FRMFILTER_VLAN | \
98  EMAC_FRMFILTER_HASH_AND_PERFECT | \
99  EMAC_FRMFILTER_SADDR | \
100  EMAC_FRMFILTER_INV_SADDR | \
101  EMAC_FRMFILTER_PASS_NO_PAUSE | \
102  EMAC_FRMFILTER_PASS_ALL_CTRL | \
103  EMAC_FRMFILTER_PASS_ADDR_CTRL | \
104  EMAC_FRMFILTER_BROADCAST | \
105  EMAC_FRMFILTER_PASS_MULTICAST | \
106  EMAC_FRMFILTER_INV_DADDR | \
107  EMAC_FRMFILTER_HASH_MULTICAST | \
108  EMAC_FRMFILTER_HASH_UNICAST | \
109  EMAC_FRMFILTER_PROMISCUOUS)
110 
111 //*****************************************************************************
112 //
113 // Combined valid maskable interrupts.
114 //
115 //*****************************************************************************
116 #define EMAC_MASKABLE_INTS (EMAC_INT_EARLY_RECEIVE | \
117  EMAC_INT_BUS_ERROR | \
118  EMAC_INT_EARLY_TRANSMIT | \
119  EMAC_INT_RX_WATCHDOG | \
120  EMAC_INT_RX_STOPPED | \
121  EMAC_INT_RX_NO_BUFFER | \
122  EMAC_INT_RECEIVE | \
123  EMAC_INT_TX_UNDERFLOW | \
124  EMAC_INT_RX_OVERFLOW | \
125  EMAC_INT_TX_JABBER | \
126  EMAC_INT_TX_NO_BUFFER | \
127  EMAC_INT_TX_STOPPED | \
128  EMAC_INT_TRANSMIT | \
129  EMAC_INT_NORMAL_INT | \
130  EMAC_INT_ABNORMAL_INT | \
131  EMAC_INT_PHY)
132 
133 //*****************************************************************************
134 //
135 // Combined valid normal interrupts.
136 //
137 //*****************************************************************************
138 #define EMAC_NORMAL_INTS (EMAC_INT_TRANSMIT | \
139  EMAC_INT_RECEIVE | \
140  EMAC_INT_EARLY_RECEIVE | \
141  EMAC_INT_TX_NO_BUFFER)
142 
143 //*****************************************************************************
144 //
145 // Combined valid abnormal interrupts.
146 //
147 //*****************************************************************************
148 #define EMAC_ABNORMAL_INTS (EMAC_INT_TX_STOPPED | \
149  EMAC_INT_TX_JABBER | \
150  EMAC_INT_RX_OVERFLOW | \
151  EMAC_INT_TX_UNDERFLOW | \
152  EMAC_INT_RX_NO_BUFFER | \
153  EMAC_INT_RX_STOPPED | \
154  EMAC_INT_RX_WATCHDOG | \
155  EMAC_INT_EARLY_TRANSMIT | \
156  EMAC_INT_BUS_ERROR)
157 
158 //*****************************************************************************
159 //
160 // Interrupt sources reported via the DMARIS register but which are not
161 // masked (or enabled) via the DMAIM register.
162 //
163 //*****************************************************************************
164 #define EMAC_NON_MASKED_INTS (EMAC_DMARIS_TT | \
165  EMAC_DMARIS_PMT | \
166  EMAC_DMARIS_MMC)
167 
168 //*****************************************************************************
169 //
170 // The number of MAC addresses the module can store for filtering purposes.
171 //
172 //*****************************************************************************
173 #define NUM_MAC_ADDR 4
174 
175 //*****************************************************************************
176 //
177 // Macros aiding access to the MAC address registers.
178 //
179 //*****************************************************************************
180 #define MAC_ADDR_OFFSET (EMAC_O_ADDR1L - EMAC_O_ADDR0L)
181 #define EMAC_O_ADDRL(n) (EMAC_O_ADDR0L + (MAC_ADDR_OFFSET * (n)))
182 #define EMAC_O_ADDRH(n) (EMAC_O_ADDR0H + (MAC_ADDR_OFFSET * (n)))
183 
184 //*****************************************************************************
185 //
186 // A structure used to help in choosing the correct clock divisor for the MII
187 // based on the current system clock rate.
188 //
189 //*****************************************************************************
190 static const struct
191 {
192  uint32_t ui32SysClockMax;
193  uint32_t ui32Divisor;
194 }
196 {
197  { 64000000, EMAC_MIIADDR_CR_35_60 },
198  { 104000000, EMAC_MIIADDR_CR_60_100 },
199  { 150000000, EMAC_MIIADDR_CR_100_150 }
200 };
201 
202 //*****************************************************************************
203 //
204 // The number of clock divisors in the above table.
205 //
206 //*****************************************************************************
207 #define NUM_CLOCK_DIVISORS (sizeof(g_pi16MIIClockDiv) / \
208  sizeof(g_pi16MIIClockDiv[0]))
209 
210 //*****************************************************************************
211 //
302 //
303 //*****************************************************************************
304 void
305 EMACInit(uint32_t ui32Base, uint32_t ui32SysClk, uint32_t ui32BusConfig,
306  uint32_t ui32RxBurst, uint32_t ui32TxBurst, uint32_t ui32DescSkipSize)
307 {
308  uint32_t ui32Val, ui32Div;
309 
310  //
311  // Parameter sanity checks.
312  //
313  ASSERT(ui32DescSkipSize < 32);
314  ASSERT(ui32TxBurst < (32 * 8));
315  ASSERT(ui32RxBurst < (32 * 8));
316 
317  //
318  // Make sure that the DMA software reset is clear before continuing.
319  //
321  {
322  }
323 
324  //
325  // Set common flags. Note that this driver assumes we are always using
326  // 8 word descriptors so we need to OR in EMAC_DMABUSMOD_ATDS here.
327  //
328  ui32Val = (ui32BusConfig | (ui32DescSkipSize << EMAC_DMABUSMOD_DSL_S) |
330 
331  //
332  // Do we need to use the 8X burst length multiplier?
333  //
334  if((ui32TxBurst > 32) || (ui32RxBurst > 32))
335  {
336  //
337  // Divide both burst lengths by 8 and set the 8X burst length
338  // multiplier.
339  //
340  ui32Val |= EMAC_DMABUSMOD_8XPBL;
341  ui32TxBurst >>= 3;
342  ui32RxBurst >>= 3;
343 
344  //
345  // Sanity check - neither burst length should have become zero. If
346  // they did, this indicates that the values passed are invalid.
347  //
348  ASSERT(ui32RxBurst);
349  ASSERT(ui32TxBurst);
350  }
351 
352  //
353  // Are the receive and transmit burst lengths the same?
354  //
355  if(ui32RxBurst == ui32TxBurst)
356  {
357  //
358  // Yes - set up to use a single burst length.
359  //
360  ui32Val |= (ui32TxBurst << EMAC_DMABUSMOD_PBL_S);
361  }
362  else
363  {
364  //
365  // No - we need to use separate burst lengths for each.
366  //
367  ui32Val |= (EMAC_DMABUSMOD_USP |
368  (ui32TxBurst << EMAC_DMABUSMOD_PBL_S) |
369  (ui32RxBurst << EMAC_DMABUSMOD_RPBL_S));
370  }
371 
372  //
373  // Finally, write the bus mode register.
374  //
375  HWREG(ui32Base + EMAC_O_DMABUSMOD) = ui32Val;
376 
377  //
378  // Default the MII CSR clock divider based on the fastest system clock.
379  //
380  ui32Div = g_pi16MIIClockDiv[NUM_CLOCK_DIVISORS - 1].ui32Divisor;
381 
382  //
383  // Find the MII CSR clock divider to use based on the current system clock.
384  //
385  for(ui32Val = 0; ui32Val < NUM_CLOCK_DIVISORS; ui32Val++)
386  {
387  if(ui32SysClk <= g_pi16MIIClockDiv[ui32Val].ui32SysClockMax)
388  {
389  ui32Div = g_pi16MIIClockDiv[ui32Val].ui32Divisor;
390  break;
391  }
392  }
393 
394  //
395  // Set the MII CSR clock speed.
396  //
397  HWREG(ui32Base + EMAC_O_MIIADDR) = ((HWREG(ui32Base + EMAC_O_MIIADDR) &
398  ~EMAC_MIIADDR_CR_M) | ui32Div);
399 
400  //
401  // Disable all the MMC interrupts as these are enabled by default at reset.
402  //
403  HWREG(ui32Base + EMAC_O_MMCRXIM) = 0xFFFFFFFF;
404  HWREG(ui32Base + EMAC_O_MMCTXIM) = 0xFFFFFFFF;
405 }
406 
407 //*****************************************************************************
408 //
422 //
423 //*****************************************************************************
424 void
425 EMACReset(uint32_t ui32Base)
426 {
427  //
428  // Reset the Ethernet MAC.
429  //
431 
432  //
433  // Wait for the reset to complete.
434  //
435  while(HWREG(ui32Base + EMAC_O_DMABUSMOD) & EMAC_DMABUSMOD_SWR)
436  {
437  }
438 }
439 
440 //*****************************************************************************
441 //
575 //
576 //*****************************************************************************
577 void
578 EMACPHYConfigSet(uint32_t ui32Base, uint32_t ui32Config)
579 {
580  //
581  // Write the Ethernet PHY configuration to the peripheral configuration
582  // register.
583  //
584  HWREG(ui32Base + EMAC_O_PC) = ui32Config;
585 
586  //
587  // If using the internal PHY, reset it to ensure that new configuration is
588  // latched there.
589  //
590  if((ui32Config & EMAC_PHY_TYPE_MASK) == EMAC_PHY_TYPE_INTERNAL)
591  {
594  {
595  //
596  // Wait for the PHY reset to complete.
597  //
598  }
599 
600  //
601  // Delay a bit longer to ensure that the PHY reset has completed.
602  //
603  SysCtlDelay(10000);
604  }
605 
606  //
607  // If using an external RMII PHY, we must set 2 bits in the Ethernet MAC
608  // Clock Configuration Register.
609  //
610  if((ui32Config & EMAC_PHY_TYPE_MASK) == EMAC_PHY_TYPE_EXTERNAL_RMII)
611  {
612  //
613  // Select and enable the external clock from the RMII PHY.
614  //
616  }
617  else
618  {
619  //
620  // Disable the external clock.
621  //
623  }
624 
625  //
626  // Reset the MAC regardless of whether the PHY connection changed or not.
627  //
629 
630  SysCtlDelay(1000);
631 }
632 
633 //*****************************************************************************
634 //
816 //
817 //*****************************************************************************
818 void
819 EMACConfigSet(uint32_t ui32Base, uint32_t ui32Config, uint32_t ui32ModeFlags,
820  uint32_t ui32RxMaxFrameSize)
821 {
822  //
823  // Parameter sanity check. Note that we allow TX_ENABLED and RX_ENABLED
824  // here because we'll mask them off before writing the value and this
825  // makes back-to-back EMACConfigGet/EMACConfigSet calls work without the
826  // caller needing to explicitly remove these bits from the parameter.
827  //
829  EMAC_CONFIG_RX_ENABLED)) == 0);
830  ASSERT(!ui32RxMaxFrameSize || ((ui32RxMaxFrameSize < 0x4000) &&
831  (ui32RxMaxFrameSize > 1522)));
832 
833  //
834  // Set the configuration flags as specified. Note that we unconditionally
835  // OR in the EMAC_CFG_PS bit here since this implementation supports only
836  // MII and RMII interfaces to the PHYs.
837  //
838  HWREG(ui32Base + EMAC_O_CFG) =
839  ((HWREG(ui32Base + EMAC_O_CFG) & ~VALID_CONFIG_FLAGS) | ui32Config |
840  EMAC_CFG_PS);
841 
842  //
843  // Set the maximum receive frame size. If 0 is passed, this implies
844  // that the default maximum frame size should be used so just turn off
845  // the override.
846  //
847  if(ui32RxMaxFrameSize)
848  {
849  HWREG(ui32Base + EMAC_O_WDOGTO) = ui32RxMaxFrameSize | EMAC_WDOGTO_PWE;
850  }
851  else
852  {
853  HWREG(ui32Base + EMAC_O_WDOGTO) &= ~EMAC_WDOGTO_PWE;
854  }
855 
856  //
857  // Set the operating mode register.
858  //
859  HWREG(ui32Base + EMAC_O_DMAOPMODE) = ui32ModeFlags;
860 }
861 
862 //*****************************************************************************
863 //
1051 //
1052 //*****************************************************************************
1053 void
1054 EMACConfigGet(uint32_t ui32Base, uint32_t *pui32Config, uint32_t *pui32Mode,
1055  uint32_t *pui32RxMaxFrameSize)
1056 {
1057  uint32_t ui32Value;
1058 
1059  //
1060  // Parameter sanity check.
1061  //
1062  ASSERT(pui32Mode);
1063  ASSERT(pui32Config);
1064  ASSERT(pui32RxMaxFrameSize);
1065 
1066  //
1067  // Return the mode information from the operation mode register.
1068  //
1069  *pui32Mode = HWREG(ui32Base + EMAC_O_DMAOPMODE);
1070 
1071  //
1072  // Return the current configuration flags from the EMAC_O_CFG register.
1073  //
1074  *pui32Config = (HWREG(ui32Base + EMAC_O_CFG) &
1077 
1078  //
1079  // Get the receive packet size watchdog value.
1080  //
1081  ui32Value = HWREG(ui32Base + EMAC_O_WDOGTO);
1082  if(ui32Value & EMAC_WDOGTO_PWE)
1083  {
1084  //
1085  // The watchdog is enables so the maximum packet length can be read
1086  // from the watchdog timeout register.
1087  //
1088  *pui32RxMaxFrameSize = ui32Value & EMAC_WDOGTO_WTO_M;
1089  }
1090  else
1091  {
1092  //
1093  // The maximum packet size override found in the watchdog timer
1094  // register is not enabled so the maximum packet size is determined
1095  // by whether or not jumbo frame mode is enabled.
1096  //
1097  if(HWREG(ui32Base + EMAC_O_CFG) & EMAC_CFG_JFEN)
1098  {
1099  //
1100  // Jumbo frames are enabled so the watchdog kicks in at 10240
1101  // bytes.
1102  //
1103  *pui32RxMaxFrameSize = 10240;
1104  }
1105  else
1106  {
1107  //
1108  // Jumbo frames are not enabled so the watchdog kicks in at
1109  // 2048 bytes.
1110  //
1111  *pui32RxMaxFrameSize = 2048;
1112  }
1113  }
1114 }
1115 
1116 //*****************************************************************************
1117 //
1168 //
1169 //*****************************************************************************
1170 void
1171 EMACAddrSet(uint32_t ui32Base, uint32_t ui32Index, const uint8_t *pui8MACAddr)
1172 {
1173  //
1174  // Parameter sanity check.
1175  //
1176  ASSERT(ui32Index < NUM_MAC_ADDR);
1177  ASSERT(pui8MACAddr);
1178 
1179  //
1180  // Set the high 2 bytes of the MAC address. Note that we must set the
1181  // registers in this order since the address is latched internally
1182  // on the write to EMAC_O_ADDRL.
1183  //
1184  HWREG(ui32Base + EMAC_O_ADDRH(ui32Index)) =
1185  ((HWREG(ui32Base + EMAC_O_ADDRH(ui32Index)) & 0xFFFF0000) |
1186  pui8MACAddr[4] | (pui8MACAddr[5] << 8));
1187 
1188  //
1189  // Set the first 4 bytes of the MAC address
1190  //
1191  HWREG(ui32Base + EMAC_O_ADDRL(ui32Index)) =
1192  (pui8MACAddr[0] | (pui8MACAddr[1] << 8) | (pui8MACAddr[2] << 16) |
1193  (pui8MACAddr[3] << 24));
1194 }
1195 
1196 //*****************************************************************************
1197 //
1223 //
1224 //*****************************************************************************
1225 void
1226 EMACAddrGet(uint32_t ui32Base, uint32_t ui32Index, uint8_t *pui8MACAddr)
1227 {
1228  uint32_t ui32Val;
1229 
1230  //
1231  // Parameter sanity check.
1232  //
1233  ASSERT(ui32Index < NUM_MAC_ADDR);
1234  ASSERT(pui8MACAddr);
1235 
1236  //
1237  // Get the first 4 bytes of the MAC address.
1238  //
1239  ui32Val = HWREG(ui32Base + EMAC_O_ADDRL(ui32Index));
1240  pui8MACAddr[0] = ui32Val & 0xFF;
1241  pui8MACAddr[1] = (ui32Val >> 8) & 0xFF;
1242  pui8MACAddr[2] = (ui32Val >> 16) & 0xFF;
1243  pui8MACAddr[3] = (ui32Val >> 24) & 0xFF;
1244 
1245  //
1246  // Get the last 2 bytes of the MAC address.
1247  //
1248  ui32Val = HWREG(ui32Base + EMAC_O_ADDRH(ui32Index));
1249  pui8MACAddr[4] = ui32Val & 0xFF;
1250  pui8MACAddr[5] = (ui32Val >> 8) & 0xFF;
1251 }
1252 
1253 //*****************************************************************************
1254 //
1264 //
1265 //*****************************************************************************
1266 uint32_t
1267 EMACNumAddrGet(uint32_t ui32Base)
1268 {
1269  //
1270  // The only Ethernet controller on Snowflake supports 4 MAC addresses.
1271  //
1272  return(NUM_MAC_ADDR);
1273 }
1274 
1275 //*****************************************************************************
1276 //
1320 //
1321 //*****************************************************************************
1322 void
1323 EMACAddrFilterSet(uint32_t ui32Base, uint32_t ui32Index, uint32_t ui32Config)
1324 {
1325  uint32_t ui32Val;
1326 
1327  //
1328  // Parameter sanity check.
1329  //
1330  ASSERT(ui32Index < NUM_MAC_ADDR);
1331  ASSERT((ui32Config & ~(EMAC_FILTER_BYTE_MASK_M |
1333  EMAC_FILTER_SOURCE_ADDR)) == 0);
1334  ASSERT(ui32Index);
1335 
1336  //
1337  // Set the filter configuration for a particular MAC address.
1338  //
1339  HWREG(ui32Base + EMAC_O_ADDRH(ui32Index)) =
1340  (HWREG(ui32Base + EMAC_O_ADDRH(ui32Index)) & 0xFFFF) | ui32Config;
1341 
1342  //
1343  // Read and rewrite the low half of the MAC address register to ensure
1344  // that the upper half's data is latched.
1345  //
1346  ui32Val = HWREG(ui32Base + EMAC_O_ADDRL(ui32Index));
1347  HWREG(ui32Base + EMAC_O_ADDRL(ui32Index)) = ui32Val;
1348 }
1349 
1350 //*****************************************************************************
1351 //
1391 //
1392 //*****************************************************************************
1393 uint32_t
1394 EMACAddrFilterGet(uint32_t ui32Base, uint32_t ui32Index)
1395 {
1396  //
1397  // Parameter sanity check.
1398  //
1399  ASSERT(ui32Index < NUM_MAC_ADDR);
1400  ASSERT(ui32Index);
1401 
1402  //
1403  // Read and return the filter settings for the requested MAC address slot.
1404  //
1405  return(HWREG(ui32Base + EMAC_O_ADDRH(ui32Index)) &
1408 }
1409 
1410 //*****************************************************************************
1411 //
1481 //
1482 //*****************************************************************************
1483 void
1484 EMACFrameFilterSet(uint32_t ui32Base, uint32_t ui32FilterOpts)
1485 {
1486  ASSERT((ui32FilterOpts & ~VALID_FRMFILTER_FLAGS) == 0);
1487 
1488  //
1489  // Set the Ethernet MAC frame filter according to the flags passed.
1490  //
1491  HWREG(ui32Base + EMAC_O_FRAMEFLTR) =
1492  ((HWREG(ui32Base + EMAC_O_FRAMEFLTR) & ~VALID_FRMFILTER_FLAGS) |
1493  ui32FilterOpts);
1494 }
1495 
1496 //*****************************************************************************
1497 //
1561 //
1562 //*****************************************************************************
1563 uint32_t
1564 EMACFrameFilterGet(uint32_t ui32Base)
1565 {
1566  //
1567  // Return the current MAC frame filter setting.
1568  //
1569  return(HWREG(ui32Base + EMAC_O_FRAMEFLTR) & VALID_FRMFILTER_FLAGS);
1570 }
1571 
1572 //*****************************************************************************
1573 //
1600 //
1601 //*****************************************************************************
1602 void
1603 EMACHashFilterSet(uint32_t ui32Base, uint32_t ui32HashHi, uint32_t ui32HashLo)
1604 {
1605  // Set the hash table with the values provided.
1606  HWREG(ui32Base + EMAC_O_HASHTBLL) = ui32HashLo;
1607  HWREG(ui32Base + EMAC_O_HASHTBLH) = ui32HashHi;
1608 }
1609 
1610 //*****************************************************************************
1611 //
1635 //
1636 //*****************************************************************************
1637 void
1638 EMACHashFilterGet(uint32_t ui32Base, uint32_t *pui32HashHi,
1639  uint32_t *pui32HashLo)
1640 {
1641  ASSERT(pui32HashHi);
1642  ASSERT(pui32HashLo);
1643 
1644  //
1645  // Get the current hash table values.
1646  //
1647  *pui32HashLo = HWREG(ui32Base + EMAC_O_HASHTBLL);
1648  *pui32HashHi = HWREG(ui32Base + EMAC_O_HASHTBLH);
1649 }
1650 
1651 //*****************************************************************************
1652 //
1669 //
1670 //*****************************************************************************
1671 uint32_t
1672 EMACHashFilterBitCalculate(uint8_t *pui8MACAddr)
1673 {
1674  uint32_t ui32CRC, ui32Mask, ui32Loop;
1675 
1676  //
1677  // Parameter sanity check.
1678  //
1679  ASSERT(pui8MACAddr);
1680 
1681  //
1682  // Calculate the CRC for the MAC address.
1683  //
1684  ui32CRC = Crc32(0xFFFFFFFF, pui8MACAddr, 6);
1685  ui32CRC ^= 0xFFFFFFFF;
1686 
1687  //
1688  // Determine the hash bit to use from the calculated CRC. This is the
1689  // top 6 bits of the reversed CRC (or the bottom 6 bits of the calculated
1690  // CRC with the bit order of those 6 bits reversed).
1691  //
1692  ui32Mask = 0;
1693 
1694  //
1695  // Reverse the order of the bottom 6 bits of the calculated CRC.
1696  //
1697  for(ui32Loop = 0; ui32Loop < 6; ui32Loop++)
1698  {
1699  ui32Mask <<= 1;
1700  ui32Mask |= (ui32CRC & 1);
1701  ui32CRC >>= 1;
1702  }
1703 
1704  //
1705  // Return the final hash table bit index.
1706  //
1707  return(ui32Mask);
1708 }
1709 
1710 //*****************************************************************************
1711 //
1730 //
1731 //*****************************************************************************
1732 void
1733 EMACRxWatchdogTimerSet(uint32_t ui32Base, uint8_t ui8Timeout)
1734 {
1735  //
1736  // Set the receive interrupt watchdog timeout period.
1737  //
1738  HWREG(ui32Base + EMAC_O_RXINTWDT) = (uint32_t)ui8Timeout;
1739 }
1740 
1741 //*****************************************************************************
1742 //
1797 //
1798 //*****************************************************************************
1799 uint32_t
1800 EMACStatusGet(uint32_t ui32Base)
1801 {
1802  //
1803  // Read and return the MAC status register content.
1804  //
1805  return(HWREG(ui32Base + EMAC_O_STATUS));
1806 }
1807 
1808 //*****************************************************************************
1809 //
1823 //
1824 //*****************************************************************************
1825 void
1826 EMACTxDMAPollDemand(uint32_t ui32Base)
1827 {
1828  //
1829  // Any write to the MACTXPOLLD register causes the transmit DMA to attempt
1830  // to resume.
1831  //
1832  HWREG(ui32Base + EMAC_O_TXPOLLD) = 0;
1833 }
1834 
1835 //*****************************************************************************
1836 //
1850 //
1851 //*****************************************************************************
1852 void
1853 EMACRxDMAPollDemand(uint32_t ui32Base)
1854 {
1855  //
1856  // Any write to the MACRXPOLLD register causes the receive DMA to attempt
1857  // to resume.
1858  //
1859  HWREG(ui32Base + EMAC_O_RXPOLLD) = 0;
1860 }
1861 
1862 //*****************************************************************************
1863 //
1899 //
1900 //*****************************************************************************
1901 void
1902 EMACRxDMADescriptorListSet(uint32_t ui32Base, tEMACDMADescriptor *pDescriptor)
1903 {
1904  //
1905  // Parameter sanity check.
1906  //
1907  ASSERT(pDescriptor);
1908  ASSERT(((uint32_t)pDescriptor & 3) == 0);
1909 
1910  //
1911  // Write the supplied address to the MACRXDLADDR register.
1912  //
1913  HWREG(ui32Base + EMAC_O_RXDLADDR) = (uint32_t)pDescriptor;
1914 }
1915 
1916 //*****************************************************************************
1917 //
1927 //
1928 //*****************************************************************************
1930 EMACRxDMADescriptorListGet(uint32_t ui32Base)
1931 {
1932  //
1933  // Return the current receive DMA descriptor list pointer.
1934  //
1935  return((tEMACDMADescriptor *)HWREG(ui32Base + EMAC_O_RXDLADDR));
1936 }
1937 
1938 //*****************************************************************************
1939 //
1949 //
1950 //*****************************************************************************
1953 {
1954  //
1955  // Return the address of the current receive descriptor written by the DMA.
1956  //
1957  return((tEMACDMADescriptor *)HWREG(ui32Base + EMAC_O_HOSRXDESC));
1958 }
1959 
1960 //*****************************************************************************
1961 //
1971 //
1972 //*****************************************************************************
1973 uint8_t *
1974 EMACRxDMACurrentBufferGet(uint32_t ui32Base)
1975 {
1976  //
1977  // Return the receive buffer address currently being written by the DMA.
1978  //
1979  return((uint8_t *)HWREG(ui32Base + EMAC_O_HOSRXBA));
1980 }
1981 
1982 //*****************************************************************************
1983 //
2019 //
2020 //*****************************************************************************
2021 void
2022 EMACTxDMADescriptorListSet(uint32_t ui32Base, tEMACDMADescriptor *pDescriptor)
2023 {
2024  //
2025  // Parameter sanity check.
2026  //
2027  ASSERT(pDescriptor);
2028  ASSERT(((uint32_t)pDescriptor & 3) == 0);
2029 
2030  //
2031  // Write the supplied address to the MACTXDLADDR register.
2032  //
2033  HWREG(ui32Base + EMAC_O_TXDLADDR) = (uint32_t)pDescriptor;
2034 }
2035 
2036 //*****************************************************************************
2037 //
2047 //
2048 //*****************************************************************************
2050 EMACTxDMADescriptorListGet(uint32_t ui32Base)
2051 {
2052  //
2053  // Return the current transmit DMA descriptor list pointer.
2054  //
2055  return((tEMACDMADescriptor *)HWREG(ui32Base + EMAC_O_TXDLADDR));
2056 }
2057 
2058 //*****************************************************************************
2059 //
2069 //
2070 //*****************************************************************************
2073 {
2074  //
2075  // Return the address of the current transmit descriptor read by the DMA.
2076  //
2077  return((tEMACDMADescriptor *)HWREG(ui32Base + EMAC_O_HOSTXDESC));
2078 }
2079 
2080 //*****************************************************************************
2081 //
2091 //
2092 //*****************************************************************************
2093 uint8_t *
2094 EMACTxDMACurrentBufferGet(uint32_t ui32Base)
2095 {
2096  //
2097  // Return the transmit buffer address currently being read by the DMA.
2098  //
2099  return((uint8_t *)HWREG(ui32Base + EMAC_O_HOSTXBA));
2100 }
2101 
2102 //*****************************************************************************
2103 //
2170 //
2171 //*****************************************************************************
2172 uint32_t
2173 EMACDMAStateGet(uint32_t ui32Base)
2174 {
2175  //
2176  // Return the status of the DMA channels.
2177  //
2178  return(HWREG(ui32Base + EMAC_O_DMARIS) &
2180  EMAC_DMARIS_TS_M));
2181 }
2182 
2183 //*****************************************************************************
2184 //
2195 //
2196 //*****************************************************************************
2197 void
2198 EMACTxFlush(uint32_t ui32Base)
2199 {
2200  //
2201  // Check to make sure that the FIFO is not already empty.
2202  //
2203  if(HWREG(ui32Base + EMAC_O_STATUS) & EMAC_STATUS_TXFE)
2204  {
2205  //
2206  // Flush the transmit FIFO since it is not currently empty.
2207  //
2208  HWREG(ui32Base + EMAC_O_DMAOPMODE) |= EMAC_DMAOPMODE_FTF;
2209 
2210  //
2211  // Wait for the flush to complete.
2212  //
2213  while(HWREG(ui32Base + EMAC_O_DMAOPMODE) & EMAC_DMAOPMODE_FTF)
2214  {
2215  }
2216  }
2217 }
2218 
2219 //*****************************************************************************
2220 //
2230 //
2231 //*****************************************************************************
2232 void
2233 EMACTxEnable(uint32_t ui32Base)
2234 {
2235  //
2236  // Enable the MAC transmit path in the opmode register.
2237  //
2238  HWREG(ui32Base + EMAC_O_DMAOPMODE) |= EMAC_DMAOPMODE_ST;
2239 
2240  //
2241  // Enable transmission in the MAC configuration register.
2242  //
2243  HWREG(ui32Base + EMAC_O_CFG) |= EMAC_CFG_TE;
2244 }
2245 
2246 //*****************************************************************************
2247 //
2256 //
2257 //*****************************************************************************
2258 void
2259 EMACTxDisable(uint32_t ui32Base)
2260 {
2261  //
2262  // Disable transmission in the MAC configuration register.
2263  //
2264  HWREG(ui32Base + EMAC_O_CFG) &= ~EMAC_CFG_TE;
2265 
2266  //
2267  // Disable the MAC transmit path in the opmode register.
2268  //
2269  HWREG(ui32Base + EMAC_O_DMAOPMODE) &= ~EMAC_DMAOPMODE_ST;
2270 }
2271 
2272 //*****************************************************************************
2273 //
2283 //
2284 //*****************************************************************************
2285 void
2286 EMACRxEnable(uint32_t ui32Base)
2287 {
2288  //
2289  // Enable the MAC receive path.
2290  //
2291  HWREG(ui32Base + EMAC_O_DMAOPMODE) |= EMAC_DMAOPMODE_SR;
2292 
2293  //
2294  // Enable receive in the MAC configuration register.
2295  //
2296  HWREG(ui32Base + EMAC_O_CFG) |= EMAC_CFG_RE;
2297 }
2298 
2299 //*****************************************************************************
2300 //
2309 //
2310 //*****************************************************************************
2311 void
2312 EMACRxDisable(uint32_t ui32Base)
2313 {
2314  //
2315  // Disable reception in the MAC configuration register.
2316  //
2317  HWREG(ui32Base + EMAC_O_CFG) &= ~EMAC_CFG_RE;
2318 
2319  //
2320  // Disable the MAC receive path.
2321  //
2322  HWREG(ui32Base + EMAC_O_DMAOPMODE) &= ~EMAC_DMAOPMODE_SR;
2323 }
2324 
2325 //*****************************************************************************
2326 //
2343 //
2344 //*****************************************************************************
2345 void
2346 EMACIntRegister(uint32_t ui32Base, void (*pfnHandler)(void))
2347 {
2348  //
2349  // Check the arguments.
2350  //
2351  ASSERT(pfnHandler != 0);
2352 
2353  //
2354  // Register the interrupt handler.
2355  //
2356  IntRegister(INT_EMAC0_TM4C129, pfnHandler);
2357 
2358  //
2359  // Enable the Ethernet interrupt.
2360  //
2362 }
2363 
2364 //*****************************************************************************
2365 //
2378 //
2379 //*****************************************************************************
2380 void
2381 EMACIntUnregister(uint32_t ui32Base)
2382 {
2383  //
2384  // Disable the interrupt.
2385  //
2387 
2388  //
2389  // Unregister the interrupt handler.
2390  //
2392 }
2393 
2394 //*****************************************************************************
2395 //
2452 //
2453 //*****************************************************************************
2454 void
2455 EMACIntEnable(uint32_t ui32Base, uint32_t ui32IntFlags)
2456 {
2457  //
2458  // Parameter sanity check.
2459  //
2460  ASSERT((ui32IntFlags & ~EMAC_MASKABLE_INTS) == 0);
2461 
2462  //
2463  // Enable the normal interrupt if any of its individual sources are
2464  // enabled.
2465  //
2466  if(ui32IntFlags & EMAC_NORMAL_INTS)
2467  {
2468  ui32IntFlags |= EMAC_INT_NORMAL_INT;
2469  }
2470 
2471  //
2472  // Similarly, enable the abnormal interrupt if any of its individual
2473  // sources are enabled.
2474  //
2475  if(ui32IntFlags & EMAC_ABNORMAL_INTS)
2476  {
2477  ui32IntFlags |= EMAC_INT_ABNORMAL_INT;
2478  }
2479 
2480  //
2481  // Set the MAC DMA interrupt mask appropriately if any of the sources
2482  // we've been asked to enable are found in that register.
2483  //
2484  if(ui32IntFlags & ~EMAC_INT_PHY)
2485  {
2486  HWREG(ui32Base + EMAC_O_DMAIM) |= ui32IntFlags & ~EMAC_INT_PHY;
2487  }
2488 
2489  //
2490  // Enable the PHY interrupt if we've been asked to do this.
2491  //
2492  if(ui32IntFlags & EMAC_INT_PHY)
2493  {
2494  HWREG(ui32Base + EMAC_O_EPHYIM) |= EMAC_EPHYIM_INT;
2495  }
2496 }
2497 
2498 //*****************************************************************************
2499 //
2558 //
2559 //*****************************************************************************
2560 void
2561 EMACIntDisable(uint32_t ui32Base, uint32_t ui32IntFlags)
2562 {
2563  uint32_t ui32Mask;
2564 
2565  //
2566  // Parameter sanity check.
2567  //
2568  ASSERT(ui32Base == EMAC0_BASE);
2569  ASSERT((ui32IntFlags & ~EMAC_MASKABLE_INTS) == 0);
2570 
2571  //
2572  // Get the current interrupt mask.
2573  //
2574  ui32Mask = HWREG(ui32Base + EMAC_O_DMAIM);
2575 
2576  //
2577  // Clear the requested bits.
2578  //
2579  ui32Mask &= ~(ui32IntFlags & ~EMAC_INT_PHY);
2580 
2581  //
2582  // If none of the normal interrupt sources are enabled, disable the
2583  // normal interrupt.
2584  //
2585  if(!(ui32Mask & EMAC_NORMAL_INTS))
2586  {
2587  ui32Mask &= ~EMAC_INT_NORMAL_INT;
2588  }
2589 
2590  //
2591  // Similarly, if none of the abnormal interrupt sources are enabled,
2592  // disable the abnormal interrupt.
2593  //
2594  if(!(ui32Mask & EMAC_ABNORMAL_INTS))
2595  {
2596  ui32Mask &= ~EMAC_INT_ABNORMAL_INT;
2597  }
2598 
2599  //
2600  // Write the new mask back to the hardware.
2601  //
2602  HWREG(ui32Base + EMAC_O_DMAIM) = ui32Mask;
2603 
2604  //
2605  // Disable the PHY interrupt if we've been asked to do this.
2606  //
2607  if(ui32IntFlags & EMAC_INT_PHY)
2608  {
2609  HWREG(ui32Base + EMAC_O_EPHYIM) &= ~EMAC_EPHYIM_INT;
2610  }
2611 }
2612 
2613 //*****************************************************************************
2614 //
2673 //
2674 //*****************************************************************************
2675 uint32_t
2676 EMACIntStatus(uint32_t ui32Base, bool bMasked)
2677 {
2678  uint32_t ui32Val, ui32PHYStat;
2679 
2680  //
2681  // Parameter sanity check.
2682  //
2683  ASSERT(ui32Base == EMAC0_BASE);
2684 
2685  //
2686  // Get the unmasked interrupt status and clear any unwanted status fields.
2687  //
2688  ui32Val = HWREG(ui32Base + EMAC_O_DMARIS);
2690 
2691  //
2692  // This peripheral doesn't have a masked interrupt status register
2693  // so perform the masking manually. Note that only the bottom 16 bits
2694  // of the register can be masked so make sure we take this into account.
2695  //
2696  if(bMasked)
2697  {
2698  ui32Val &= (EMAC_NON_MASKED_INTS | HWREG(ui32Base + EMAC_O_DMAIM));
2699  }
2700 
2701  //
2702  // Read the PHY interrupt status.
2703  //
2704  if(bMasked)
2705  {
2706  ui32PHYStat = HWREG(ui32Base + EMAC_O_EPHYMISC);
2707  }
2708  else
2709  {
2710  ui32PHYStat = HWREG(ui32Base + EMAC_O_EPHYRIS);
2711  }
2712 
2713  //
2714  // If the PHY interrupt is reported, add the appropriate flag to the
2715  // return value.
2716  //
2717  if(ui32PHYStat & EMAC_EPHYMISC_INT)
2718  {
2719  ui32Val |= EMAC_INT_PHY;
2720  }
2721 
2722  return(ui32Val);
2723 }
2724 
2725 //*****************************************************************************
2726 //
2778 //
2779 //*****************************************************************************
2780 void
2781 EMACIntClear(uint32_t ui32Base, uint32_t ui32IntFlags)
2782 {
2783  //
2784  // Parameter sanity check.
2785  //
2786  ASSERT(ui32Base == EMAC0_BASE);
2787 
2788  //
2789  // Mask in the normal interrupt if one of the sources it relates to is
2790  // specified.
2791  //
2792  if(ui32IntFlags & EMAC_NORMAL_INTS)
2793  {
2794  ui32IntFlags |= EMAC_INT_NORMAL_INT;
2795  }
2796 
2797  //
2798  // Similarly, mask in the abnormal interrupt if one of the sources it
2799  // relates to is specified.
2800  //
2801  if(ui32IntFlags & EMAC_ABNORMAL_INTS)
2802  {
2803  ui32IntFlags |= EMAC_INT_ABNORMAL_INT;
2804  }
2805 
2806  //
2807  // Clear the maskable interrupt sources. We write exactly the value passed
2808  // (with the summary sources added if necessary) but remember that only
2809  // the bottom 17 bits of the register are actually clearable. Only do
2810  // this if some bits are actually set that refer to the DMA interrupt
2811  // sources.
2812  //
2813  if(ui32IntFlags & ~EMAC_INT_PHY)
2814  {
2815  HWREG(ui32Base + EMAC_O_DMARIS) = (ui32IntFlags & ~EMAC_INT_PHY);
2816  }
2817 
2818  //
2819  // Clear the PHY interrupt if we've been asked to do this.
2820  //
2821  if(ui32IntFlags & EMAC_INT_PHY)
2822  {
2823  HWREG(ui32Base + EMAC_O_EPHYMISC) |= EMAC_EPHYMISC_INT;
2824  }
2825 }
2826 
2827 //*****************************************************************************
2828 //
2840 //
2841 //*****************************************************************************
2842 void
2843 EMACPHYWrite(uint32_t ui32Base, uint8_t ui8PhyAddr, uint8_t ui8RegAddr,
2844  uint16_t ui16Data)
2845 {
2846  //
2847  // Parameter sanity check.
2848  //
2849  ASSERT(ui32Base == EMAC0_BASE);
2850 
2851  //
2852  // Parameter sanity check.
2853  //
2854  ASSERT(ui8PhyAddr < 32);
2855 
2856  //
2857  // Make sure the MII is idle.
2858  //
2859  while(HWREG(ui32Base + EMAC_O_MIIADDR) & EMAC_MIIADDR_MIIB)
2860  {
2861  }
2862 
2863  //
2864  // Write the value provided.
2865  //
2866  HWREG(ui32Base + EMAC_O_MIIDATA) = ui16Data;
2867 
2868  //
2869  // Tell the MAC to write the given PHY register.
2870  //
2871  HWREG(ui32Base + EMAC_O_MIIADDR) =
2872  ((HWREG(ui32Base + EMAC_O_MIIADDR) &
2873  EMAC_MIIADDR_CR_M) | (ui8RegAddr << EMAC_MIIADDR_MII_S) |
2874  (ui8PhyAddr << EMAC_MIIADDR_PLA_S) | EMAC_MIIADDR_MIIW |
2875  EMAC_MIIADDR_MIIB);
2876 
2877  //
2878  // Wait for the write to complete.
2879  //
2880  while(HWREG(ui32Base + EMAC_O_MIIADDR) & EMAC_MIIADDR_MIIB)
2881  {
2882  }
2883 }
2884 
2885 //*****************************************************************************
2886 //
2897 //
2898 //*****************************************************************************
2899 uint16_t
2900 EMACPHYRead(uint32_t ui32Base, uint8_t ui8PhyAddr, uint8_t ui8RegAddr)
2901 {
2902  //
2903  // Parameter sanity check.
2904  //
2905  ASSERT(ui8PhyAddr < 32);
2906  ASSERT(ui32Base == EMAC0_BASE);
2907 
2908  //
2909  // Make sure the MII is idle.
2910  //
2911  while(HWREG(ui32Base + EMAC_O_MIIADDR) & EMAC_MIIADDR_MIIB)
2912  {
2913  }
2914 
2915  //
2916  // Tell the MAC to read the given PHY register.
2917  //
2918  HWREG(ui32Base + EMAC_O_MIIADDR) =
2919  ((HWREG(ui32Base + EMAC_O_MIIADDR) & EMAC_MIIADDR_CR_M) |
2920  (ui8RegAddr << EMAC_MIIADDR_MII_S) |
2921  (ui8PhyAddr << EMAC_MIIADDR_PLA_S) | EMAC_MIIADDR_MIIB);
2922 
2923  //
2924  // Wait for the read to complete.
2925  //
2926  while(HWREG(ui32Base + EMAC_O_MIIADDR) & EMAC_MIIADDR_MIIB)
2927  {
2928  }
2929 
2930  //
2931  // Return the result.
2932  //
2933  return(HWREG(ui32Base + EMAC_O_MIIDATA) & EMAC_MIIDATA_DATA_M);
2934 }
2935 
2936 //*****************************************************************************
2937 //
2950 //
2951 //*****************************************************************************
2952 uint16_t
2953 EMACPHYExtendedRead(uint32_t ui32Base, uint8_t ui8PhyAddr,
2954  uint16_t ui16RegAddr)
2955 {
2956  //
2957  // Parameter sanity check.
2958  //
2959  ASSERT(ui8PhyAddr < 32);
2960  ASSERT(ui32Base == EMAC0_BASE);
2961 
2962  //
2963  // Set the address of the register we're about to read.
2964  //
2965  EMACPHYWrite(EMAC0_BASE, ui8PhyAddr, EPHY_REGCTL, 0x001F);
2966  EMACPHYWrite(EMAC0_BASE, ui8PhyAddr, EPHY_ADDAR, ui16RegAddr);
2967 
2968  //
2969  // Read the extended register value.
2970  //
2971  EMACPHYWrite(EMAC0_BASE, ui8PhyAddr, EPHY_REGCTL, 0x401F);
2972  return(EMACPHYRead(EMAC0_BASE, ui8PhyAddr, EPHY_ADDAR));
2973 }
2974 
2975 //*****************************************************************************
2976 //
2990 //
2991 //*****************************************************************************
2992 void
2993 EMACPHYExtendedWrite(uint32_t ui32Base, uint8_t ui8PhyAddr,
2994  uint16_t ui16RegAddr, uint16_t ui16Value)
2995 {
2996  //
2997  // Parameter sanity check.
2998  //
2999  ASSERT(ui8PhyAddr < 32);
3000  ASSERT(ui32Base == EMAC0_BASE);
3001 
3002  //
3003  // Set the address of the register we're about to write.
3004  //
3005  EMACPHYWrite(EMAC0_BASE, ui8PhyAddr, EPHY_REGCTL, 0x001F);
3006  EMACPHYWrite(EMAC0_BASE, ui8PhyAddr, EPHY_ADDAR, ui16RegAddr);
3007 
3008  //
3009  // Write the extended register.
3010  //
3011  EMACPHYWrite(EMAC0_BASE, ui8PhyAddr, EPHY_REGCTL, 0x401F);
3012  EMACPHYWrite(EMAC0_BASE, ui8PhyAddr, EPHY_ADDAR, ui16Value);
3013 }
3014 
3015 //*****************************************************************************
3016 //
3027 //
3028 //*****************************************************************************
3029 void
3030 EMACPHYPowerOff(uint32_t ui32Base, uint8_t ui8PhyAddr)
3031 {
3032  //
3033  // Set the PWRDN bit and clear the ANEN bit in the PHY, putting it into
3034  // its low power mode.
3035  //
3036  EMACPHYWrite(ui32Base, ui8PhyAddr, EPHY_BMCR,
3037  (EMACPHYRead(ui32Base, ui8PhyAddr, EPHY_BMCR) &
3039 }
3040 
3041 //*****************************************************************************
3042 //
3053 //
3054 //*****************************************************************************
3055 void
3056 EMACPHYPowerOn(uint32_t ui32Base, uint8_t ui8PhyAddr)
3057 {
3058  //
3059  // Clear the PWRDN bit and set the ANEGEN bit in the PHY, putting it into
3060  // normal operating mode.
3061  //
3062  EMACPHYWrite(ui32Base, ui8PhyAddr, EPHY_BMCR,
3063  (EMACPHYRead(ui32Base, ui8PhyAddr, EPHY_BMCR) &
3065 }
3066 
3067 //*****************************************************************************
3068 //
3187 //
3188 //*****************************************************************************
3189 void
3190 EMACTimestampConfigSet(uint32_t ui32Base, uint32_t ui32Config,
3191  uint32_t ui32SubSecondInc)
3192 {
3193  //
3194  // Parameter sanity check.
3195  //
3196  ASSERT(ui32Base == EMAC0_BASE);
3197 
3198  //
3199  // Ensure that the PTP module clock is enabled.
3200  //
3201  HWREG(ui32Base + EMAC_O_CC) |= EMAC_CC_PTPCEN;
3202 
3203  //
3204  // Write the subsecond increment value.
3205  //
3206  HWREG(ui32Base + EMAC_O_SUBSECINC) = ((ui32SubSecondInc <<
3209 
3210  //
3211  // Set the timestamp configuration.
3212  //
3213  HWREG(ui32Base + EMAC_O_TIMSTCTRL) = ui32Config;
3214 }
3215 
3216 //*****************************************************************************
3217 //
3279 //
3280 //*****************************************************************************
3281 uint32_t
3282 EMACTimestampConfigGet(uint32_t ui32Base, uint32_t *pui32SubSecondInc)
3283 {
3284  //
3285  // Parameter sanity check.
3286  //
3287  ASSERT(ui32Base == EMAC0_BASE);
3288  ASSERT(pui32SubSecondInc);
3289 
3290  //
3291  // Read the current subsecond increment value.
3292  //
3293  *pui32SubSecondInc = (HWREG(ui32Base + EMAC_O_SUBSECINC) &
3295 
3296  //
3297  // Return the current timestamp configuration.
3298  //
3299  return(HWREG(ui32Base + EMAC_O_TIMSTCTRL));
3300 }
3301 
3302 //*****************************************************************************
3303 //
3312 //
3313 //*****************************************************************************
3314 void
3315 EMACTimestampEnable(uint32_t ui32Base)
3316 {
3317  //
3318  // Parameter sanity check.
3319  //
3320  ASSERT(ui32Base == EMAC0_BASE);
3321 
3322  //
3323  // Enable IEEE 1588 timestamping.
3324  //
3326 
3327  //
3328  // If necessary, initialize the timestamping system. This bit self-clears
3329  // once the system time is loaded. Only do this if initialization is not
3330  // currently ongoing.
3331  //
3332  if(!(HWREG(ui32Base + EMAC_O_TIMSTCTRL) & EMAC_TIMSTCTRL_TSINIT))
3333  {
3335  }
3336 }
3337 
3338 //*****************************************************************************
3339 //
3348 //
3349 //*****************************************************************************
3350 void
3351 EMACTimestampDisable(uint32_t ui32Base)
3352 {
3353  //
3354  // Parameter sanity check.
3355  //
3356  ASSERT(ui32Base == EMAC0_BASE);
3357 
3358  //
3359  // Disable IEEE 1588 timestamping.
3360  //
3361  HWREG(ui32Base + EMAC_O_TIMSTCTRL) &= ~EMAC_TIMSTCTRL_TSEN;
3362 }
3363 
3364 //*****************************************************************************
3365 //
3384 //
3385 //*****************************************************************************
3386 void
3387 EMACTimestampSysTimeSet(uint32_t ui32Base, uint32_t ui32Seconds,
3388  uint32_t ui32SubSeconds)
3389 {
3390  //
3391  // Parameter sanity check.
3392  //
3393  ASSERT(ui32Base == EMAC0_BASE);
3394 
3395  //
3396  // Write the new time to the system time update registers.
3397  //
3398  HWREG(ui32Base + EMAC_O_TIMSECU) = ui32Seconds;
3399  HWREG(ui32Base + EMAC_O_TIMNANOU) = ui32SubSeconds;
3400 
3401  //
3402  // Wait for any previous update to complete.
3403  //
3404  while(HWREG(ui32Base + EMAC_O_TIMSTCTRL) & EMAC_TIMSTCTRL_TSINIT)
3405  {
3406  //
3407  // Spin for a while.
3408  //
3409  }
3410 
3411  //
3412  // Force the system clock to reset.
3413  //
3415 }
3416 
3417 //*****************************************************************************
3418 //
3434 //
3435 //*****************************************************************************
3436 void
3437 EMACTimestampSysTimeGet(uint32_t ui32Base, uint32_t *pui32Seconds,
3438  uint32_t *pui32SubSeconds)
3439 {
3440  //
3441  // Parameter sanity check.
3442  //
3443  ASSERT(ui32Base == EMAC0_BASE);
3444  ASSERT(pui32Seconds);
3445  ASSERT(pui32SubSeconds);
3446 
3447  //
3448  // Read the two-part system time from the seconds and nanoseconds
3449  // registers. We do this in a way that should guard against us reading
3450  // the registers across a nanosecond wrap.
3451  //
3452  do
3453  {
3454  *pui32Seconds = HWREG(ui32Base + EMAC_O_TIMSEC);
3455  *pui32SubSeconds = HWREG(ui32Base + EMAC_O_TIMNANO);
3456  }
3457  while(*pui32SubSeconds > HWREG(ui32Base + EMAC_O_TIMNANO));
3458 }
3459 
3460 //*****************************************************************************
3461 //
3483 //
3484 //*****************************************************************************
3485 void
3486 EMACTimestampSysTimeUpdate(uint32_t ui32Base, uint32_t ui32Seconds,
3487  uint32_t ui32SubSeconds, bool bInc)
3488 {
3489  //
3490  // Parameter sanity check.
3491  //
3492  ASSERT(ui32Base == EMAC0_BASE);
3493 
3494  //
3495  // Write the new time to the system time update registers.
3496  //
3497  HWREG(ui32Base + EMAC_O_TIMSECU) = ui32Seconds;
3498  HWREG(ui32Base + EMAC_O_TIMNANOU) = ui32SubSeconds |
3499  (bInc ? 0 : EMAC_TIMNANOU_ADDSUB);
3500 
3501  //
3502  // Wait for any previous update to complete.
3503  //
3504  while(HWREG(ui32Base + EMAC_O_TIMSTCTRL) & EMAC_TIMSTCTRL_TSUPDT)
3505  {
3506  //
3507  // Spin for a while.
3508  //
3509  }
3510 
3511  //
3512  // Force the system clock to update by the value provided.
3513  //
3515 }
3516 
3517 //*****************************************************************************
3518 //
3552 //
3553 //*****************************************************************************
3554 void
3555 EMACTimestampAddendSet(uint32_t ui32Base, uint32_t ui32Increment)
3556 {
3557  //
3558  // Parameter sanity check.
3559  //
3560  ASSERT(ui32Base == EMAC0_BASE);
3561 
3562  HWREG(ui32Base + EMAC_O_TIMADD) = ui32Increment;
3563 
3564  //
3565  // Wait for any previous update to complete.
3566  //
3567  while(HWREG(ui32Base + EMAC_O_TIMSTCTRL) & EMAC_TIMSTCTRL_ADDREGUP)
3568  {
3569  //
3570  // Spin for a while.
3571  //
3572  }
3573 
3574  //
3575  // Force the system clock to update by the value provided.
3576  //
3578 }
3579 
3580 //*****************************************************************************
3581 //
3603 //
3604 //*****************************************************************************
3605 void
3606 EMACTimestampTargetSet(uint32_t ui32Base, uint32_t ui32Seconds,
3607  uint32_t ui32SubSeconds)
3608 {
3609  //
3610  // Parameter sanity check.
3611  //
3612  ASSERT(ui32Base == EMAC0_BASE);
3613 
3614  //
3615  // Wait for any previous write to complete.
3616  //
3617  while(HWREG(ui32Base + EMAC_O_TARGNANO) & EMAC_TARGNANO_TRGTBUSY)
3618  {
3619  }
3620 
3621  //
3622  // Write the new target time.
3623  //
3624  HWREG(ui32Base + EMAC_O_TARGSEC) = ui32Seconds;
3625  HWREG(ui32Base + EMAC_O_TARGNANO) = ui32SubSeconds;
3626 }
3627 
3628 //*****************************************************************************
3629 //
3643 //
3644 //*****************************************************************************
3645 void
3647 {
3648  //
3649  // Parameter sanity check.
3650  //
3651  ASSERT(ui32Base == EMAC0_BASE);
3652 
3653  //
3654  // Set the bit to enable the timestamp target interrupt. This bit clears
3655  // automatically when the interrupt fires after which point, you must
3656  // set a new target time and re-enable the interrupts.
3657  //
3659 }
3660 
3661 //*****************************************************************************
3662 //
3672 //
3673 //*****************************************************************************
3674 void
3676 {
3677  //
3678  // Parameter sanity check.
3679  //
3680  ASSERT(ui32Base == EMAC0_BASE);
3681 
3682  //
3683  // Clear the bit to disable the timestamp target interrupt. This bit
3684  // clears automatically when the interrupt fires, so it only must be
3685  // disabled if you want to cancel a previously-set interrupt.
3686  //
3688 }
3689 
3690 //*****************************************************************************
3691 //
3710 //
3711 //*****************************************************************************
3712 uint32_t
3713 EMACTimestampIntStatus(uint32_t ui32Base)
3714 {
3715  //
3716  // Parameter sanity check.
3717  //
3718  ASSERT(ui32Base == EMAC0_BASE);
3719 
3720  //
3721  // Return the current interrupt status from the timestamp module.
3722  //
3723  return(HWREG(ui32Base + EMAC_O_TIMSTAT));
3724 }
3725 
3726 //*****************************************************************************
3727 //
3768 //
3769 //*****************************************************************************
3770 void
3771 EMACTimestampPPSSimpleModeSet(uint32_t ui32Base, uint32_t ui32FreqConfig)
3772 {
3773  bool bDigital;
3774 
3775  //
3776  // Parameter sanity check.
3777  //
3778  ASSERT(ui32Base == EMAC0_BASE);
3779 
3780  //
3781  // Are we currently running the clock in digital or binary rollover mode?
3782  //
3783  bDigital = (HWREG(ui32Base + EMAC_O_TIMSTCTRL) &
3784  EMAC_TS_DIGITAL_ROLLOVER) ? true : false;
3785 
3786  //
3787  // Weed out some unsupported frequencies. The hardware can't produce a
3788  // 1Hz output when we are in binary rollover mode and can't produce a
3789  // 32KHz output when we are digital rollover mode.
3790  //
3791  ASSERT(bDigital || (ui32FreqConfig != EMAC_PPS_1HZ));
3792  ASSERT(!bDigital || (ui32FreqConfig != EMAC_PPS_32768HZ));
3793 
3794  //
3795  // Adjust the supplied frequency if we are currently in binary update mode
3796  // where the control value generates an output that is twice as fast as
3797  // in digital mode.
3798  //
3799  if((ui32FreqConfig != EMAC_PPS_SINGLE_PULSE) && !bDigital)
3800  {
3801  ui32FreqConfig--;
3802  }
3803 
3804  //
3805  // Write the frequency control value to the PPS control register, clearing
3806  // the PPSEN0 bit to ensure that the PPS engine is in simple mode and not
3807  // waiting for a command. We also clear the TRGMODS0 field to revert to
3808  // the default operation of the target time registers.
3809  //
3810  HWREG(ui32Base + EMAC_O_PPSCTRL) = ui32FreqConfig;
3811 }
3812 
3813 //*****************************************************************************
3814 //
3816 
3851 //
3852 //*****************************************************************************
3853 void
3854 EMACTimestampPPSCommandModeSet(uint32_t ui32Base, uint32_t ui32Config)
3855 {
3856  //
3857  // Parameter sanity check.
3858  //
3859  ASSERT(ui32Base == EMAC0_BASE);
3860  ASSERT(!(ui32Config & (EMAC_PPS_TARGET_INT | EMAC_PPS_TARGET_PPS |
3862 
3863  //
3864  // Wait for any previous command write to complete.
3865  //
3866  while(HWREG(ui32Base + EMAC_O_PPSCTRL) & EMAC_PPSCTRL_PPSCTRL_M)
3867  {
3868  //
3869  // Wait a bit.
3870  //
3871  }
3872 
3873  //
3874  // Write the configuration value to the PPS control register, setting the
3875  // PPSEN0 bit to ensure that the PPS engine is in command mode and
3876  // clearing the command in the PPSCTRL field.
3877  //
3878  HWREG(ui32Base + EMAC_O_PPSCTRL) = (EMAC_PPSCTRL_PPSEN0 | ui32Config);
3879 }
3880 
3881 //*****************************************************************************
3882 //
3916 //
3917 //*****************************************************************************
3918 void
3919 EMACTimestampPPSCommand(uint32_t ui32Base, uint8_t ui8Cmd)
3920 {
3921  //
3922  // Parameter sanity check.
3923  //
3924  ASSERT(ui32Base == EMAC0_BASE);
3925 
3926  //
3927  // Wait for any previous command write to complete.
3928  //
3929  while(HWREG(ui32Base + EMAC_O_PPSCTRL) & EMAC_PPSCTRL_PPSCTRL_M)
3930  {
3931  //
3932  // Wait a bit.
3933  //
3934  }
3935 
3936  //
3937  // Write the command to the PPS control register.
3938  //
3939  HWREG(ui32Base + EMAC_O_PPSCTRL) = (EMAC_PPSCTRL_PPSEN0 | ui8Cmd);
3940 }
3941 
3942 //*****************************************************************************
3943 //
3972 //
3973 //*****************************************************************************
3974 void
3975 EMACTimestampPPSPeriodSet(uint32_t ui32Base, uint32_t ui32Period,
3976  uint32_t ui32Width)
3977 {
3978  //
3979  // Parameter sanity check.
3980  //
3981  ASSERT(ui32Base == EMAC0_BASE);
3982 
3983  //
3984  // Write the desired PPS period and pulse width.
3985  //
3986  HWREG(ui32Base + EMAC_O_PPS0INTVL) = ui32Period;
3987  HWREG(ui32Base + EMAC_O_PPS0WIDTH) = ui32Width;
3988 }
3989 
3990 //*****************************************************************************
3991 //
4035 //
4036 //*****************************************************************************
4037 void
4038 EMACVLANRxConfigSet(uint32_t ui32Base, uint16_t ui16Tag, uint32_t ui32Config)
4039 {
4040  //
4041  // Parameter sanity check.
4042  //
4043  ASSERT(ui32Base == EMAC0_BASE);
4044 
4045  //
4046  // Write the VLAN tag register.
4047  //
4048  HWREG(ui32Base + EMAC_O_VLANTG) =
4049  ui32Config | (((uint32_t)ui16Tag) << EMAC_VLANTG_VL_S);
4050 }
4051 
4052 //*****************************************************************************
4053 //
4084 //
4085 //*****************************************************************************
4086 uint32_t
4087 EMACVLANRxConfigGet(uint32_t ui32Base, uint16_t *pui16Tag)
4088 {
4089  uint32_t ui32Value;
4090 
4091  //
4092  // Parameter sanity check.
4093  //
4094  ASSERT(ui32Base == EMAC0_BASE);
4095  ASSERT(pui16Tag);
4096 
4097  //
4098  // Read the VLAN tag register.
4099  //
4100  ui32Value = HWREG(ui32Base + EMAC_O_VLANTG);
4101 
4102  //
4103  // Extract the VLAN tag from the register.
4104  //
4105  *pui16Tag = (ui32Value & EMAC_VLANTG_VL_M) >> EMAC_VLANTG_VL_S;
4106 
4107  //
4108  // Return the configuration flags.
4109  //
4110  return(ui32Value & ~EMAC_VLANTG_VL_M);
4111 }
4112 
4113 //*****************************************************************************
4114 //
4155 //
4156 //*****************************************************************************
4157 void
4158 EMACVLANTxConfigSet(uint32_t ui32Base, uint16_t ui16Tag, uint32_t ui32Config)
4159 {
4160  //
4161  // Parameter sanity check.
4162  //
4163  ASSERT(ui32Base == EMAC0_BASE);
4164 
4165  //
4166  // Write the VLAN Tag Inclusion or Replacement register.
4167  //
4168  HWREG(ui32Base + EMAC_O_VLNINCREP) =
4169  ui32Config | ((uint32_t)ui16Tag << EMAC_VLNINCREP_VLT_S);
4170 }
4171 
4172 //*****************************************************************************
4173 //
4213 //
4214 //*****************************************************************************
4215 uint32_t
4216 EMACVLANTxConfigGet(uint32_t ui32Base, uint16_t *pui16Tag)
4217 {
4218  uint32_t ui32Value;
4219 
4220  //
4221  // Parameter sanity check.
4222  //
4223  ASSERT(ui32Base == EMAC0_BASE);
4224  ASSERT(pui16Tag);
4225 
4226  //
4227  // Read the VLAN Tag Inclusion or Replacement register.
4228  //
4229  ui32Value = HWREG(ui32Base + EMAC_O_VLNINCREP);
4230 
4231  //
4232  // Extract the tag.
4233  //
4234  *pui16Tag = (uint16_t)((ui32Value & EMAC_VLNINCREP_VLT_M) >>
4236 
4237  //
4238  // Return the configuration flags.
4239  //
4240  return(ui32Value & ~EMAC_VLNINCREP_VLT_M);
4241 }
4242 
4243 //*****************************************************************************
4244 //
4259 //
4260 //*****************************************************************************
4261 uint32_t
4263 {
4264  uint32_t ui32CRC, ui32Mask, ui32Loop;
4265 
4266  //
4267  // Calculate the CRC for the MAC address.
4268  //
4269  ui32CRC = Crc32(0xFFFFFFFF, (uint8_t *)&ui16Tag, 2);
4270  ui32CRC ^= 0xFFFFFFFF;
4271 
4272  //
4273  // Determine the hash bit to use from the calculated CRC. This is the
4274  // top 4 bits of the reversed CRC (or the bottom 4 bits of the calculated
4275  // CRC with the bit order of those 4 bits reversed).
4276  //
4277  ui32Mask = 0;
4278 
4279  //
4280  // Reverse the order of the bottom 4 bits of the calculated CRC.
4281  //
4282  for(ui32Loop = 0; ui32Loop < 4; ui32Loop++)
4283  {
4284  ui32Mask <<= 1;
4285  ui32Mask |= (ui32CRC & 1);
4286  ui32CRC >>= 1;
4287  }
4288 
4289  //
4290  // Return the final hash filter bit index.
4291  //
4292  return(ui32Mask);
4293 }
4294 
4295 //*****************************************************************************
4296 //
4314 //
4315 //*****************************************************************************
4316 void
4317 EMACVLANHashFilterSet(uint32_t ui32Base, uint32_t ui32Hash)
4318 {
4319  //
4320  // Parameter sanity check.
4321  //
4322  ASSERT(ui32Base == EMAC0_BASE);
4323 
4324  //
4325  // Write the VLAN Hash Table register.
4326  //
4327  HWREG(ui32Base + EMAC_O_VLANHASH) = ui32Hash;
4328 }
4329 
4330 //*****************************************************************************
4331 //
4343 //
4344 //*****************************************************************************
4345 uint32_t
4346 EMACVLANHashFilterGet(uint32_t ui32Base)
4347 {
4348  //
4349  // Parameter sanity check.
4350  //
4351  ASSERT(ui32Base == EMAC0_BASE);
4352 
4353  //
4354  // Return the VLAN Hash Table register.
4355  //
4356  return(HWREG(ui32Base + EMAC_O_VLANHASH));
4357 }
4358 
4359 //*****************************************************************************
4360 //
4408 //
4409 //*****************************************************************************
4410 void
4412  const tEMACWakeUpFrameFilter *pFilter)
4413 {
4414  uint32_t *pui32Data;
4415  uint32_t ui32Loop;
4416 
4417  //
4418  // Parameter sanity check.
4419  //
4420  ASSERT(ui32Base == EMAC0_BASE);
4421  ASSERT(pFilter);
4422 
4423  //
4424  // Make sure that the internal register counter for the frame filter
4425  // is reset. This bit automatically resets after 1 clock cycle.
4426  //
4428 
4429  //
4430  // Get a word pointer to the supplied structure.
4431  //
4432  pui32Data = (uint32_t *)pFilter;
4433 
4434  //
4435  // Write the 8 words of the wake-up filter definition to the hardware.
4436  //
4437  for(ui32Loop = 0; ui32Loop < 8; ui32Loop++)
4438  {
4439  //
4440  // Write a word of the filter definition.
4441  //
4442  HWREG(ui32Base + EMAC_O_RWUFF) = pui32Data[ui32Loop];
4443  }
4444 }
4445 
4446 //*****************************************************************************
4447 //
4491 //
4492 //*****************************************************************************
4493 void
4495  tEMACWakeUpFrameFilter *pFilter)
4496 {
4497  uint32_t *pui32Data;
4498  uint32_t ui32Loop;
4499 
4500  //
4501  // Parameter sanity check.
4502  //
4503  ASSERT(ui32Base == EMAC0_BASE);
4504  ASSERT(pFilter);
4505 
4506  //
4507  // Make sure that the internal register counter for the frame filter
4508  // is reset. This bit automatically resets after 1 clock cycle.
4509  //
4511 
4512  //
4513  // Get a word pointer to the supplied structure.
4514  //
4515  pui32Data = (uint32_t *)pFilter;
4516 
4517  //
4518  // Read the 8 words of the wake-up filter definition from the hardware.
4519  //
4520  for(ui32Loop = 0; ui32Loop < 8; ui32Loop++)
4521  {
4522  //
4523  // Read a word of the filter definition.
4524  //
4525  pui32Data[ui32Loop] = HWREG(ui32Base + EMAC_O_RWUFF);
4526  }
4527 }
4528 
4529 //*****************************************************************************
4530 //
4573 //
4574 //*****************************************************************************
4575 void
4576 EMACPowerManagementControlSet(uint32_t ui32Base, uint32_t ui32Flags)
4577 {
4578  uint32_t ui32Value;
4579 
4580  //
4581  // Parameter sanity check.
4582  //
4583  ASSERT(ui32Base == EMAC0_BASE);
4584  ASSERT(~(ui32Flags & ~(EMAC_PMT_GLOBAL_UNICAST_ENABLE |
4588 
4589  //
4590  // Read the control/status register, clear all the bits we can set, mask
4591  // in the new values then rewrite the new register value.
4592  //
4593  ui32Value = HWREG(ui32Base + EMAC_O_PMTCTLSTAT);
4596  ui32Value |= ui32Flags;
4597  HWREG(ui32Base + EMAC_O_PMTCTLSTAT) = ui32Value;
4598 }
4599 
4600 //*****************************************************************************
4601 //
4625 //
4626 //*****************************************************************************
4627 uint32_t
4629 {
4630  //
4631  // Parameter sanity check.
4632  //
4633  ASSERT(ui32Base == EMAC0_BASE);
4634 
4635  //
4636  // Read the control/status register and mask off the control bits to return
4637  // them to the caller.
4638  //
4639  return(HWREG(ui32Base + EMAC_O_PMTCTLSTAT) &
4642 }
4643 
4644 //*****************************************************************************
4645 //
4665 //
4666 //*****************************************************************************
4667 uint32_t
4669 {
4670  //
4671  // Parameter sanity check.
4672  //
4673  ASSERT(ui32Base == EMAC0_BASE);
4674 
4675  //
4676  // Read the control/status register and mask off the status bits to return
4677  // them to the caller.
4678  //
4679  return(HWREG(ui32Base + EMAC_O_PMTCTLSTAT) &
4682 }
4683 
4684 //*****************************************************************************
4685 //
4686 // Close the Doxygen group.
4688 //
4689 //*****************************************************************************
uint32_t EMACTimestampIntStatus(uint32_t ui32Base)
Definition: emac.c:3713
#define EMAC_VLANTG_VL_M
Definition: hw_emac.h:328
#define EMAC_DMAOPMODE_FTF
Definition: hw_emac.h:1117
#define EMAC_TS_DIGITAL_ROLLOVER
Definition: emac.h:638
#define EMAC_MIIADDR_CR_100_150
Definition: hw_emac.h:268
uint32_t EMACHashFilterBitCalculate(uint8_t *pui8MACAddr)
Definition: emac.c:1672
#define INT_EMAC0_TM4C129
Definition: hw_ints.h:216
#define EMAC_O_STATUS
Definition: hw_emac.h:56
#define EMAC_PPSCTRL_PPSEN0
Definition: hw_emac.h:874
#define EMAC_O_PMTCTLSTAT
Definition: hw_emac.h:59
uint8_t * EMACTxDMACurrentBufferGet(uint32_t ui32Base)
Definition: emac.c:2094
#define EMAC_PPS_1HZ
Definition: emac.h:736
#define VALID_FRMFILTER_FLAGS
Definition: emac.c:96
#define EMAC_O_TXDLADDR
Definition: hw_emac.h:131
void EMACRxDMADescriptorListSet(uint32_t ui32Base, tEMACDMADescriptor *pDescriptor)
Definition: emac.c:1902
#define EMAC_FILTER_ADDR_ENABLE
Definition: emac.h:605
#define EMAC_ABNORMAL_INTS
Definition: emac.c:148
#define EMAC_EPHYIM_INT
Definition: hw_emac.h:1311
static const struct @0 g_pi16MIIClockDiv[]
void EMACIntEnable(uint32_t ui32Base, uint32_t ui32IntFlags)
Definition: emac.c:2455
void EMACTxFlush(uint32_t ui32Base)
Definition: emac.c:2198
#define EMAC_FILTER_SOURCE_ADDR
Definition: emac.h:606
#define EMAC_O_HASHTBLH
Definition: hw_emac.h:50
uint16_t EMACPHYRead(uint32_t ui32Base, uint8_t ui8PhyAddr, uint8_t ui8RegAddr)
Definition: emac.c:2900
void EMACTxDMAPollDemand(uint32_t ui32Base)
Definition: emac.c:1826
#define EMAC_PMT_GLOBAL_UNICAST_ENABLE
Definition: emac.h:885
void EMACTimestampEnable(uint32_t ui32Base)
Definition: emac.c:3315
uint8_t * EMACRxDMACurrentBufferGet(uint32_t ui32Base)
Definition: emac.c:1974
void EMACTimestampTargetIntEnable(uint32_t ui32Base)
Definition: emac.c:3646
#define EMAC_O_EPHYIM
Definition: hw_emac.h:158
#define HWREG(x)
Definition: hw_types.h:48
#define EMAC_O_DMARIS
Definition: hw_emac.h:133
uint32_t EMACAddrFilterGet(uint32_t ui32Base, uint32_t ui32Index)
Definition: emac.c:1394
void EMACReset(uint32_t ui32Base)
Definition: emac.c:425
void EMACVLANTxConfigSet(uint32_t ui32Base, uint16_t ui16Tag, uint32_t ui32Config)
Definition: emac.c:4158
void EMACAddrFilterSet(uint32_t ui32Base, uint32_t ui32Index, uint32_t ui32Config)
Definition: emac.c:1323
#define EMAC_DMABUSMOD_RPBL_S
Definition: hw_emac.h:993
#define EMAC_O_MMCTXIM
Definition: hw_emac.h:81
void EMACRxWatchdogTimerSet(uint32_t ui32Base, uint8_t ui8Timeout)
Definition: emac.c:1733
#define EMAC_MIIDATA_DATA_M
Definition: hw_emac.h:288
#define EMAC_TIMSTCTRL_INTTRIG
Definition: hw_emac.h:754
#define EMAC_O_HOSTXDESC
Definition: hw_emac.h:142
#define EMAC_DMARIS_AE_M
Definition: hw_emac.h:1046
#define EMAC_O_TIMSTAT
Definition: hw_emac.h:121
bool SysCtlPeripheralReady(uint32_t ui32Peripheral)
Definition: sysctl.c:632
void EMACRxEnable(uint32_t ui32Base)
Definition: emac.c:2286
#define EMAC_PMTCTLSTAT_WUPRX
Definition: hw_emac.h:412
#define EMAC_O_MIIDATA
Definition: hw_emac.h:53
void EMACPHYWrite(uint32_t ui32Base, uint8_t ui8PhyAddr, uint8_t ui8RegAddr, uint16_t ui16Data)
Definition: emac.c:2843
#define EMAC_CC_CLKEN
Definition: hw_emac.h:1296
#define EMAC_EPHYMISC_INT
Definition: hw_emac.h:1319
#define EMAC_DMARIS_FBI
Definition: hw_emac.h:1092
uint32_t EMACPowerManagementStatusGet(uint32_t ui32Base)
Definition: emac.c:4668
#define EMAC_O_RXINTWDT
Definition: hw_emac.h:140
#define ASSERT(expr)
Definition: debug.h:67
void EMACTxEnable(uint32_t ui32Base)
Definition: emac.c:2233
#define EMAC_O_TARGNANO
Definition: hw_emac.h:117
#define EMAC_TIMSTCTRL_TSEN
Definition: hw_emac.h:759
#define EMAC_DMABUSMOD_USP
Definition: hw_emac.h:982
#define EMAC_INT_PHY
Definition: emac.h:677
#define EMAC_MIIADDR_CR_M
Definition: hw_emac.h:263
#define EMAC_MIIADDR_PLA_S
Definition: hw_emac.h:280
#define EMAC_TARGNANO_TRGTBUSY
Definition: hw_emac.h:827
uint32_t Crc32(uint32_t ui32Crc, const uint8_t *pui8Data, uint32_t ui32Count)
Definition: sw_crc.c:654
#define EMAC_PMT_MAGIC_PACKET_ENABLE
Definition: emac.h:887
#define EMAC_PPS_32768HZ
Definition: emac.h:751
void EMACIntClear(uint32_t ui32Base, uint32_t ui32IntFlags)
Definition: emac.c:2781
void SysCtlDelay(uint32_t ui32Count)
uint32_t ui32Divisor
Definition: emac.c:193
#define EMAC_O_PPS0INTVL
Definition: hw_emac.h:123
#define EMAC_CC_PTPCEN
Definition: hw_emac.h:1294
#define EMAC_O_TXPOLLD
Definition: hw_emac.h:126
void EMACTimestampPPSCommand(uint32_t ui32Base, uint8_t ui8Cmd)
Definition: emac.c:3919
#define EMAC_DMABUSMOD_PBL_S
Definition: hw_emac.h:995
#define EMAC_O_MMCRXIM
Definition: hw_emac.h:79
uint32_t ui32SysClockMax
Definition: emac.c:192
void EMACTimestampSysTimeUpdate(uint32_t ui32Base, uint32_t ui32Seconds, uint32_t ui32SubSeconds, bool bInc)
Definition: emac.c:3486
void EMACInit(uint32_t ui32Base, uint32_t ui32SysClk, uint32_t ui32BusConfig, uint32_t ui32RxBurst, uint32_t ui32TxBurst, uint32_t ui32DescSkipSize)
Definition: emac.c:305
uint16_t EMACPHYExtendedRead(uint32_t ui32Base, uint8_t ui8PhyAddr, uint16_t ui16RegAddr)
Definition: emac.c:2953
#define EMAC_O_FRAMEFLTR
Definition: hw_emac.h:49
#define EMAC_PHY_TYPE_MASK
Definition: emac.h:416
#define NUM_MAC_ADDR
Definition: emac.c:173
#define EMAC_TIMSTCTRL_TSINIT
Definition: hw_emac.h:757
#define EMAC_FILTER_BYTE_MASK_M
Definition: emac.h:614
void EMACTimestampPPSPeriodSet(uint32_t ui32Base, uint32_t ui32Period, uint32_t ui32Width)
Definition: emac.c:3975
void EMACTimestampSysTimeGet(uint32_t ui32Base, uint32_t *pui32Seconds, uint32_t *pui32SubSeconds)
Definition: emac.c:3437
#define EMAC_O_ADDRH(n)
Definition: emac.c:182
#define EMAC_PPSCTRL_PPSCTRL_M
Definition: hw_emac.h:875
#define EMAC_MIIADDR_CR_35_60
Definition: hw_emac.h:275
uint32_t EMACFrameFilterGet(uint32_t ui32Base)
Definition: emac.c:1564
#define EMAC_DMARIS_TS_M
Definition: hw_emac.h:1059
void EMACPHYConfigSet(uint32_t ui32Base, uint32_t ui32Config)
Definition: emac.c:578
#define VALID_CONFIG_FLAGS
Definition: emac.c:71
void EMACHashFilterGet(uint32_t ui32Base, uint32_t *pui32HashHi, uint32_t *pui32HashLo)
Definition: emac.c:1638
#define EMAC_DMABUSMOD_DSL_S
Definition: hw_emac.h:996
void EMACRemoteWakeUpFrameFilterSet(uint32_t ui32Base, const tEMACWakeUpFrameFilter *pFilter)
Definition: emac.c:4411
#define EMAC_TIMNANOU_ADDSUB
Definition: hw_emac.h:801
#define EMAC_O_HOSRXDESC
Definition: hw_emac.h:144
#define EMAC_MASKABLE_INTS
Definition: emac.c:116
void EMACVLANRxConfigSet(uint32_t ui32Base, uint16_t ui16Tag, uint32_t ui32Config)
Definition: emac.c:4038
#define EMAC_PPS_TARGET_PPS
Definition: emac.h:760
A structure defining a single Ethernet DMA buffer descriptor.
Definition: emac.h:142
#define EMAC_PMTCTLSTAT_PWRDWN
Definition: hw_emac.h:417
#define EMAC_O_PPSCTRL
Definition: hw_emac.h:122
void EMACAddrGet(uint32_t ui32Base, uint32_t ui32Index, uint8_t *pui8MACAddr)
Definition: emac.c:1226
uint32_t EMACDMAStateGet(uint32_t ui32Base)
Definition: emac.c:2173
#define EMAC_VLANTG_VL_S
Definition: hw_emac.h:330
#define EMAC_DMAOPMODE_SR
Definition: hw_emac.h:1138
#define EMAC_MIIADDR_MII_S
Definition: hw_emac.h:281
#define EMAC_PMTCTLSTAT_WUPFRRST
Definition: hw_emac.h:405
#define EMAC_O_ADDRL(n)
Definition: emac.c:181
void EMACHashFilterSet(uint32_t ui32Base, uint32_t ui32HashHi, uint32_t ui32HashLo)
Definition: emac.c:1603
#define EMAC_CONFIG_TX_ENABLED
Definition: emac.h:495
#define EMAC_O_CFG
Definition: hw_emac.h:48
#define EPHY_BMCR
Definition: hw_emac.h:1327
#define EMAC_O_EPHYMISC
Definition: hw_emac.h:159
void EMACTimestampTargetIntDisable(uint32_t ui32Base)
Definition: emac.c:3675
#define EMAC_PMTCTLSTAT_GLBLUCAST
Definition: hw_emac.h:410
void EMACPHYPowerOn(uint32_t ui32Base, uint8_t ui8PhyAddr)
Definition: emac.c:3056
void EMACTimestampPPSSimpleModeSet(uint32_t ui32Base, uint32_t ui32FreqConfig)
Definition: emac.c:3771
#define EMAC_DMAOPMODE_ST
Definition: hw_emac.h:1127
#define EMAC_O_TIMSECU
Definition: hw_emac.h:111
#define EMAC_O_VLANTG
Definition: hw_emac.h:55
#define EMAC_DMABUSMOD_ATDS
Definition: hw_emac.h:989
#define EMAC_O_DMAOPMODE
Definition: hw_emac.h:135
#define EMAC_DMARIS_RS_M
Definition: hw_emac.h:1074
void EMACVLANHashFilterSet(uint32_t ui32Base, uint32_t ui32Hash)
Definition: emac.c:4317
void EMACPHYPowerOff(uint32_t ui32Base, uint8_t ui8PhyAddr)
Definition: emac.c:3030
#define EMAC_O_MIIADDR
Definition: hw_emac.h:52
#define EMAC_O_SUBSECINC
Definition: hw_emac.h:105
tEMACDMADescriptor * EMACRxDMADescriptorListGet(uint32_t ui32Base)
Definition: emac.c:1930
#define EMAC_TIMSTCTRL_TSUPDT
Definition: hw_emac.h:756
#define EMAC_O_HASHTBLL
Definition: hw_emac.h:51
#define EMAC_PPS_TARGET_INT
Definition: emac.h:759
#define EMAC_PHY_TYPE_EXTERNAL_RMII
Definition: emac.h:385
#define EMAC_INT_ABNORMAL_INT
Definition: emac.h:709
void EMACAddrSet(uint32_t ui32Base, uint32_t ui32Index, const uint8_t *pui8MACAddr)
Definition: emac.c:1171
#define EMAC_CONFIG_RX_ENABLED
Definition: emac.h:496
#define EMAC_CFG_PS
Definition: hw_emac.h:183
void SysCtlPeripheralReset(uint32_t ui32Peripheral)
Definition: sysctl.c:762
void EMACRxDMAPollDemand(uint32_t ui32Base)
Definition: emac.c:1853
#define EMAC_PMTCTLSTAT_MGKPKTEN
Definition: hw_emac.h:415
#define EMAC_WDOGTO_PWE
Definition: hw_emac.h:522
#define EMAC_CFG_RE
Definition: hw_emac.h:198
uint32_t EMACVLANHashFilterBitCalculate(uint16_t ui16Tag)
Definition: emac.c:4262
#define EMAC0_BASE
Definition: hw_memmap.h:132
uint32_t EMACPowerManagementControlGet(uint32_t ui32Base)
Definition: emac.c:4628
void EMACConfigSet(uint32_t ui32Base, uint32_t ui32Config, uint32_t ui32ModeFlags, uint32_t ui32RxMaxFrameSize)
Definition: emac.c:819
void EMACRxDisable(uint32_t ui32Base)
Definition: emac.c:2312
void EMACTxDisable(uint32_t ui32Base)
Definition: emac.c:2259
void EMACTimestampConfigSet(uint32_t ui32Base, uint32_t ui32Config, uint32_t ui32SubSecondInc)
Definition: emac.c:3190
#define EMAC_SUBSECINC_SSINC_M
Definition: hw_emac.h:768
#define EMAC_O_DMAIM
Definition: hw_emac.h:136
#define EMAC_O_CC
Definition: hw_emac.h:154
#define EMAC_O_TIMSTCTRL
Definition: hw_emac.h:104
#define NUM_CLOCK_DIVISORS
Definition: emac.c:207
#define EPHY_BMCR_PWRDWN
Definition: hw_emac.h:1380
#define EMAC_SUBSECINC_SSINC_S
Definition: hw_emac.h:769
#define EMAC_O_TIMNANO
Definition: hw_emac.h:109
#define EMAC_O_EPHYRIS
Definition: hw_emac.h:156
#define EMAC_WDOGTO_WTO_M
Definition: hw_emac.h:523
void IntUnregister(uint32_t ui32Interrupt)
Definition: interrupt.c:381
#define EMAC_PHY_TYPE_INTERNAL
Definition: emac.h:383
void EMACIntDisable(uint32_t ui32Base, uint32_t ui32IntFlags)
Definition: emac.c:2561
tEMACDMADescriptor * EMACTxDMADescriptorListGet(uint32_t ui32Base)
Definition: emac.c:2050
#define EMAC_DMABUSMOD_8XPBL
Definition: hw_emac.h:980
#define EMAC_PPS_SINGLE_PULSE
Definition: emac.h:735
#define EMAC_MIIADDR_MIIB
Definition: hw_emac.h:279
#define EMAC_O_RXPOLLD
Definition: hw_emac.h:128
#define EMAC_O_PC
Definition: hw_emac.h:152
#define EMAC_MIIADDR_MIIW
Definition: hw_emac.h:278
#define EMAC_PMT_POWER_DOWN
Definition: emac.h:888
void EMACTxDMADescriptorListSet(uint32_t ui32Base, tEMACDMADescriptor *pDescriptor)
Definition: emac.c:2022
#define EMAC_O_VLANHASH
Definition: hw_emac.h:103
tEMACDMADescriptor * EMACRxDMACurrentDescriptorGet(uint32_t ui32Base)
Definition: emac.c:1952
#define EPHY_BMCR_ANEN
Definition: hw_emac.h:1379
#define EMAC_PPS_TARGET_BOTH
Definition: emac.h:761
tEMACDMADescriptor * EMACTxDMACurrentDescriptorGet(uint32_t ui32Base)
Definition: emac.c:2072
#define EMAC_CFG_TE
Definition: hw_emac.h:197
#define EMAC_O_WDOGTO
Definition: hw_emac.h:73
void EMACIntRegister(uint32_t ui32Base, void(*pfnHandler)(void))
Definition: emac.c:2346
#define EMAC_O_TIMADD
Definition: hw_emac.h:115
#define EMAC_VLNINCREP_VLT_M
Definition: hw_emac.h:716
uint32_t EMACVLANTxConfigGet(uint32_t ui32Base, uint16_t *pui16Tag)
Definition: emac.c:4216
#define EMAC_O_TIMSEC
Definition: hw_emac.h:107
#define EMAC_O_TARGSEC
Definition: hw_emac.h:116
void EMACTimestampAddendSet(uint32_t ui32Base, uint32_t ui32Increment)
Definition: emac.c:3555
#define EMAC_INT_NORMAL_INT
Definition: emac.h:708
#define EMAC_PMT_WAKEUP_PACKET_ENABLE
Definition: emac.h:886
#define EMAC_O_TIMNANOU
Definition: hw_emac.h:113
#define EPHY_REGCTL
Definition: hw_emac.h:1346
uint32_t EMACVLANRxConfigGet(uint32_t ui32Base, uint16_t *pui16Tag)
Definition: emac.c:4087
#define EMAC_O_VLNINCREP
Definition: hw_emac.h:101
#define EMAC_DMABUSMOD_SWR
Definition: hw_emac.h:992
void EMACTimestampTargetSet(uint32_t ui32Base, uint32_t ui32Seconds, uint32_t ui32SubSeconds)
Definition: emac.c:3606
#define EMAC_O_RWUFF
Definition: hw_emac.h:57
void EMACRemoteWakeUpFrameFilterGet(uint32_t ui32Base, tEMACWakeUpFrameFilter *pFilter)
Definition: emac.c:4494
void EMACIntUnregister(uint32_t ui32Base)
Definition: emac.c:2381
#define EMAC_CFG_JFEN
Definition: hw_emac.h:171
void EMACTimestampSysTimeSet(uint32_t ui32Base, uint32_t ui32Seconds, uint32_t ui32SubSeconds)
Definition: emac.c:3387
void EMACTimestampPPSCommandModeSet(uint32_t ui32Base, uint32_t ui32Config)
Configures the Ethernet MAC PPS output in command mode.
Definition: emac.c:3854
void EMACTimestampDisable(uint32_t ui32Base)
Definition: emac.c:3351
#define EMAC_O_HOSTXBA
Definition: hw_emac.h:146
#define EPHY_ADDAR
Definition: hw_emac.h:1347
void EMACConfigGet(uint32_t ui32Base, uint32_t *pui32Config, uint32_t *pui32Mode, uint32_t *pui32RxMaxFrameSize)
Definition: emac.c:1054
#define EMAC_MIIADDR_CR_60_100
Definition: hw_emac.h:265
#define EMAC_O_RXDLADDR
Definition: hw_emac.h:129
#define EMAC_O_PPS0WIDTH
Definition: hw_emac.h:124
uint32_t EMACVLANHashFilterGet(uint32_t ui32Base)
Definition: emac.c:4346
void EMACFrameFilterSet(uint32_t ui32Base, uint32_t ui32FilterOpts)
Definition: emac.c:1484
uint32_t EMACNumAddrGet(uint32_t ui32Base)
Definition: emac.c:1267
#define EMAC_PMTCTLSTAT_MGKPRX
Definition: hw_emac.h:413
#define SYSCTL_PERIPH_EPHY0
Definition: sysctl.h:69
uint32_t EMACIntStatus(uint32_t ui32Base, bool bMasked)
Definition: emac.c:2676
#define EMAC_PMTCTLSTAT_WUPFREN
Definition: hw_emac.h:414
#define EMAC_NON_MASKED_INTS
Definition: emac.c:164
#define EMAC_NORMAL_INTS
Definition: emac.c:138
void IntDisable(uint32_t ui32Interrupt)
Definition: interrupt.c:684
void IntRegister(uint32_t ui32Interrupt, void(*pfnHandler)(void))
Definition: interrupt.c:309
void EMACPHYExtendedWrite(uint32_t ui32Base, uint8_t ui8PhyAddr, uint16_t ui16RegAddr, uint16_t ui16Value)
Definition: emac.c:2993
#define EMAC_VLNINCREP_VLT_S
Definition: hw_emac.h:717
uint32_t EMACTimestampConfigGet(uint32_t ui32Base, uint32_t *pui32SubSecondInc)
Definition: emac.c:3282
#define EMAC_TIMSTCTRL_ADDREGUP
Definition: hw_emac.h:753
void IntEnable(uint32_t ui32Interrupt)
Definition: interrupt.c:610
void EMACPowerManagementControlSet(uint32_t ui32Base, uint32_t ui32Flags)
Definition: emac.c:4576
#define EMAC_O_DMABUSMOD
Definition: hw_emac.h:125
#define EMAC_O_HOSRXBA
Definition: hw_emac.h:148
#define EMAC_STATUS_TXFE
Definition: hw_emac.h:339
uint32_t EMACStatusGet(uint32_t ui32Base)
Definition: emac.c:1800