S32 SDK
enet_driver.c
Go to the documentation of this file.
1 /*
2  * Copyright 2017 NXP
3  * All rights reserved.
4  *
5  * THIS SOFTWARE IS PROVIDED BY NXP "AS IS" AND ANY EXPRESSED OR
6  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
7  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
8  * IN NO EVENT SHALL NXP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
9  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
10  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
11  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
12  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
13  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
14  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
15  * THE POSSIBILITY OF SUCH DAMAGE.
16  */
17 
18 #include "enet_driver.h"
19 #include "enet_hw_access.h"
20 #include "clock_manager.h"
21 #include "interrupt_manager.h"
22 
23 /*******************************************************************************
24  * Definitions
25  ******************************************************************************/
26 
27 #define ENET_ROUNDED_UP_DIV(a, b) ((a) + (b) - 1) / (b)
28 #define ENET_NS_IN_SECOND (1000000000U)
29 
30 #define ENET_ALL_INTERRUPTS_MASK (0xFFFFFFFFU)
31 
32 #define ENET_BYTE_0_IN_ADDR_SHIFT (24U)
33 #define ENET_BYTE_1_IN_ADDR_SHIFT (16U)
34 #define ENET_BYTE_2_IN_ADDR_SHIFT (8U)
35 #define ENET_BYTE_3_IN_ADDR_SHIFT (0U)
36 #define ENET_BYTE_4_IN_ADDR_SHIFT (8U)
37 #define ENET_BYTE_5_IN_ADDR_SHIFT (0U)
38 
39 #define ENET_BYTE_MASK (0xFFU)
40 
41 /*******************************************************************************
42  * Variables
43  ******************************************************************************/
44 
47 
54 #ifdef FEATURE_ENET_WAKEUP_IRQS
55 
56 static const IRQn_Type s_enetWakeupIrqId[] = FEATURE_ENET_WAKE_IRQS;
57 #endif
58 
61 
62 /*******************************************************************************
63  * Prototypes
64  ******************************************************************************/
65 
66 static uint32_t ENET_DRV_ComputeCRC32(uint8_t *mac);
67 
68 /*******************************************************************************
69  * Private functions
70  ******************************************************************************/
71 
72 /*FUNCTION**********************************************************************
73  *
74  * Function Name : ENET_DRV_ComputeCRC32
75  * Description : Computes the CRC32 of a given MAC address.
76  *
77  *END**************************************************************************/
78 static uint32_t ENET_DRV_ComputeCRC32(uint8_t *mac)
79 {
80  uint32_t crc = 0xFFFFFFFF;
81  uint8_t i, j;
82 
83  for (i = 0; i < 6U; i++)
84  {
85  crc = crc ^ mac[i];
86  for (j = 0; j < 8U; j++)
87  {
88  if (crc & 0x1U)
89  {
90  crc = (crc >> 1U) ^ 0xEDB88320U;
91  }
92  else
93  {
94  crc = (crc >> 1U);
95  }
96  }
97  }
98 
99  return crc;
100 }
101 
102 /*******************************************************************************
103  * Code
104  ******************************************************************************/
105 
106 /*FUNCTION**********************************************************************
107  *
108  * Function Name : ENET_DRV_GetDefaultConfig
109  * Description : Gets the default configuration structure
110  *
111  * Implements : ENET_DRV_GetDefaultConfig_Activity
112  *END**************************************************************************/
114 {
115  /* Checks input parameter. */
116  DEV_ASSERT(config != NULL);
117 
118  /* No interrupt is enabled by default. */
119  config->interrupt = 0;
120  /* Maximum receive frame length. */
122  /* No special receive/transmit control configuration. */
123  config->rxConfig = 0;
124  config->txConfig = 0;
125  /* No acceleration function enabled. */
126  config->rxAccelerConfig = 0;
127  config->txAccelerConfig = 0;
128  /* RMII/MII mode, full duplex, 100Mbps for MAC and PHY data interface. */
130  config->miiSpeed = ENET_MII_SPEED_100M;
132  /* No callback. */
133  config->callback = NULL;
134 }
135 
136 /*FUNCTION**********************************************************************
137  *
138  * Function Name : ENET_DRV_Init
139  * Description : Initializes the ENET module
140  *
141  * This function initializes and enables the ENET module, configuring receive
142  * and transmit control settings, the receive and transmit descriptors rings,
143  * and the MAC physical address.
144  *
145  * Implements : ENET_DRV_Init_Activity
146  *END**************************************************************************/
147 void ENET_DRV_Init(uint8_t instance,
148  enet_state_t *state,
149  const enet_config_t *config,
150  const enet_buffer_config_t *bufferConfig,
151  uint8_t *macAddr)
152 {
153  ENET_Type *base;
154 
155  DEV_ASSERT(instance < ENET_INSTANCE_COUNT);
156  DEV_ASSERT(state != NULL);
157  DEV_ASSERT(config != NULL);
159  DEV_ASSERT(bufferConfig != NULL);
160  DEV_ASSERT(bufferConfig->rxRingAligned != NULL);
162  DEV_ASSERT(bufferConfig->rxBufferAligned != NULL);
164  DEV_ASSERT(bufferConfig->rxRingSize > 0);
165  DEV_ASSERT(bufferConfig->txRingAligned != NULL);
167  DEV_ASSERT(bufferConfig->txRingSize > 0);
168 
169  base = s_enetBases[instance];
170 
171  /* Reset ENET module. */
172  ENET_Reset(base);
173 
174  /* Configure MAC address. */
175  ENET_DRV_SetMacAddr(instance, macAddr);
176 
177  /* Configure receive and transmit control. */
178  ENET_ConfigReceiveControl(base, config);
179  ENET_ConfigTransmitControl(base, config);
180 
181  /* Configure receive and transmit accelerators. */
182  ENET_ConfigReceiveAccelerator(base, config->rxAccelerConfig);
183  ENET_ConfigTransmitAccelerator(base, config->txAccelerConfig);
184 
185  /* Enable Ethernet interrupts. */
186  INT_SYS_EnableIRQ(s_enetRxIrqId[instance]);
187  INT_SYS_EnableIRQ(s_enetTxIrqId[instance]);
189 #ifdef FEATURE_ENET_WAKEUP_IRQS
190  INT_SYS_EnableIRQ(s_enetWakeupIrqId[instance]);
191 #endif
192 
193  ENET_EnableInterrupts(base, config->interrupt);
194 
195  /* Update state. */
196  state->rxBdBase = bufferConfig->rxRingAligned;
197  state->rxBdCurrent = bufferConfig->rxRingAligned;
198  state->rxBdAlloc = bufferConfig->rxRingAligned;
199  state->txBdBase = bufferConfig->txRingAligned;
200  state->txBdCurrent = bufferConfig->txRingAligned;
201  state->callback = config->callback;
202 
203  g_enetState[instance] = state;
204 
205  /* Configure buffer descriptors and indicate that the receive descriptor has been updated. */
206  ENET_ConfigBufferDescriptors(base, bufferConfig, ENET_BUFF_ALIGN(config->maxFrameLen));
207 
208  ENET_DRV_ConfigCounters(instance, true);
209 
210  /* Enable the module. */
211  ENET_Enable(base);
212 
213  ENET_ActivateReceive(base);
214 }
215 
216 /*FUNCTION**********************************************************************
217  *
218  * Function Name : ENET_DRV_Deinit
219  * Description : Deinitializes the ENET module
220  *
221  * This function disables the interrupts and then disables the ENET module.
222  *
223  * Implements : ENET_DRV_Deinit_Activity
224  *END**************************************************************************/
225 void ENET_DRV_Deinit(uint8_t instance)
226 {
227  ENET_Type *base;
228 
229  DEV_ASSERT(instance < ENET_INSTANCE_COUNT);
230 
231  base = s_enetBases[instance];
232 
233  /* Disable interrupts. */
234  ENET_DisableInterrupts(base, ENET_ALL_INTERRUPTS_MASK);
235 
239 #ifdef FEATURE_ENET_WAKEUP_IRQS
240  INT_SYS_DisableIRQ(s_enetWakeupIrqId[instance]);
241 #endif
242 
243  /* Disable module. */
244  ENET_Disable(base);
245 }
246 
247 /*FUNCTION**********************************************************************
248  *
249  * Function Name : ENET_DRV_ReadFrame
250  * Description : Reads a received Ethernet frame
251  *
252  * This function reads the first received Ethernet frame in the Rx queue. The
253  * buffer received as parameter will be updated by the driver and the .data field
254  * will point to a memory area containing the frame data.
255  *
256  * Important: Once the application finished processing the buffer, it needs to be
257  * released using the ENET_DRV_ProvideRxBuff function.
258  *
259  * Implements : ENET_DRV_ReadFrame_Activity
260  *END**************************************************************************/
261 status_t ENET_DRV_ReadFrame(uint8_t instance,
262  enet_buffer_t * buff)
263 {
264  enet_buffer_descriptor_t *bd;
265  status_t status = STATUS_SUCCESS;
266 
267  DEV_ASSERT(instance < ENET_INSTANCE_COUNT);
268  DEV_ASSERT(g_enetState[instance] != NULL);
269  DEV_ASSERT(buff != NULL);
270 
271  bd = g_enetState[instance]->rxBdCurrent;
272 
273  if ((bd->control & ENET_BUFFDESCR_RX_EMPTY_MASK) != (uint16_t)0)
274  {
276  }
277  else
278  {
279  buff->data = bd->buffer;
280  buff->length = bd->length;
281 
282  /* Update the current buffer descriptor. */
283  if ((bd->control & ENET_BUFFDESCR_RX_WRAP_MASK) != (uint16_t)0)
284  {
285  g_enetState[instance]->rxBdCurrent = g_enetState[instance]->rxBdBase;
286  }
287  else
288  {
289  g_enetState[instance]->rxBdCurrent++;
290  }
291  }
292 
293  return status;
294 }
295 
296 /*FUNCTION**********************************************************************
297  *
298  * Function Name : ENET_DRV_SendFrame
299  * Description : Sends an Ethernet frame
300  *
301  * This function sends an Ethernet frame, represented by the buffer received as
302  * parameter.
303  *
304  * Implements : ENET_DRV_SendFrame_Activity
305  *END**************************************************************************/
306 status_t ENET_DRV_SendFrame(uint8_t instance,
307  enet_buffer_t * buff)
308 {
309  ENET_Type *base;
310  enet_buffer_descriptor_t *bd;
311  status_t status = STATUS_SUCCESS;
312 
313  DEV_ASSERT(instance < ENET_INSTANCE_COUNT);
314  DEV_ASSERT(g_enetState[instance] != NULL);
315  DEV_ASSERT(buff != NULL);
316 
317  base = s_enetBases[instance];
318 
319  bd = g_enetState[instance]->txBdCurrent;
320 
321  if ((bd->control & ENET_BUFFDESCR_TX_READY_MASK) != (uint16_t)0)
322  {
323  status = STATUS_ENET_TX_QUEUE_FULL;
324  }
325  else
326  {
327  /* Configure buffer descriptor. */
328  bd->length = buff->length;
329  bd->buffer = buff->data;
330  bd->control |= (uint16_t)(ENET_BUFFDESCR_TX_READY_MASK | ENET_BUFFDESCR_TX_LAST_MASK);
331 
332  /* Activate the transmit buffer descriptor. */
333  ENET_ActivateTransmit(base);
334 
335  /* Update the current buffer descriptor pointer. */
336  if ((bd->control & ENET_BUFFDESCR_TX_WRAP_MASK) != (uint16_t)0)
337  {
338  g_enetState[instance]->txBdCurrent = g_enetState[instance]->txBdBase;
339  }
340  else
341  {
342  g_enetState[instance]->txBdCurrent++;
343  }
344  }
345 
346  return status;
347 }
348 
349 /*FUNCTION**********************************************************************
350  *
351  * Function Name : ENET_DRV_GetTransmitStatus
352  * Description : Checks if the transmission of a buffer is complete
353  *
354  * This function checks if the transmission of the given buffer is complete.
355  *
356  * Implements : ENET_DRV_GetTransmitStatus_Activity
357  *END**************************************************************************/
359  enet_buffer_t * buff)
360 {
361  enet_buffer_descriptor_t *bd;
362  status_t status = STATUS_SUCCESS;
363 
364  DEV_ASSERT(instance < ENET_INSTANCE_COUNT);
365  DEV_ASSERT(g_enetState[instance] != NULL);
366  DEV_ASSERT(buff != NULL);
367 
368  bd = g_enetState[instance]->txBdBase;
369 
370  /* Search for the buffer descriptor associated with the given buffer. */
371  while ((bd->control & ENET_BUFFDESCR_TX_WRAP_MASK) == (uint16_t)0)
372  {
373  if (bd->buffer == buff->data)
374  {
375  /* Check if the buffer descriptor is still in use. */
376  if ((bd->control & ENET_BUFFDESCR_TX_READY_MASK) != (uint16_t)0)
377  {
378  status = STATUS_BUSY;
379  }
380 
381  break;
382  }
383 
384  bd++;
385  }
386 
387  return status;
388 }
389 
390 /*FUNCTION**********************************************************************
391  *
392  * Function Name : ENET_DRV_ProvideRxBuff
393  * Description : Provides a receive buffer to be used by the driver for reception.
394  *
395  * This function provides a buffer which can further be used by the reception
396  * mechanism in order to store the received data.
397  *
398  * Implements : ENET_DRV_ProvideRxBuff_Activity
399  *END**************************************************************************/
400 void ENET_DRV_ProvideRxBuff(uint8_t instance,
401  enet_buffer_t * buff)
402 {
403  ENET_Type *base;
404  enet_buffer_descriptor_t *bd;
405 
406  DEV_ASSERT(instance < ENET_INSTANCE_COUNT);
407  DEV_ASSERT(g_enetState[instance] != NULL);
408  DEV_ASSERT(buff != NULL);
409 
410  base = s_enetBases[instance];
411 
412  /* This is the left-most allocated buffer descriptor. */
413  bd = g_enetState[instance]->rxBdAlloc;
414 
415  DEV_ASSERT((bd->control & ENET_BUFFDESCR_RX_EMPTY_MASK) == (uint16_t)0);
416 
417  bd->buffer = buff->data;
418 
419  /* Cleanup the left-most allocated buffer descriptor. */
420  bd->control &= ENET_BUFFDESCR_RX_WRAP_MASK;
421  bd->control |= ENET_BUFFDESCR_RX_EMPTY_MASK;
422 
423  /* Update the pointer to the first allocated buffer descriptor. */
424  if ((bd->control & ENET_BUFFDESCR_RX_WRAP_MASK) != (uint16_t)0)
425  {
426  g_enetState[instance]->rxBdAlloc = g_enetState[instance]->rxBdBase;
427  }
428  else
429  {
430  g_enetState[instance]->rxBdAlloc++;
431  }
432 
433  /* New empty buffers have been produced */
434  ENET_ActivateReceive(base);
435 }
436 
437 /*FUNCTION**********************************************************************
438  *
439  * Function Name : ENET_DRV_EnableMDIO
440  * Description : Enables the MDIO interface
441  *
442  * Implements : ENET_DRV_EnableMDIO_Activity
443  *END**************************************************************************/
444 void ENET_DRV_EnableMDIO(uint8_t instance,
445  bool miiPreambleDisabled)
446 {
447  ENET_Type *base;
448  uint32_t moduleClk, holdTime, miiSpeed;
449  uint32_t config;
450 
451  DEV_ASSERT(instance < ENET_INSTANCE_COUNT);
452 
453  base = s_enetBases[instance];
454 
455  CLOCK_SYS_GetFreq(s_enetClkNames[instance], &moduleClk);
456 
457  DEV_ASSERT(moduleClk);
458 
460  miiSpeed = ENET_ROUNDED_UP_DIV(moduleClk, (2U * FEATURE_ENET_MDC_MAX_FREQUENCY)) - 1U;
461 
462  config = ENET_MSCR_MII_SPEED(miiSpeed) | ENET_MSCR_DIS_PRE(miiPreambleDisabled) | ENET_MSCR_HOLDTIME(holdTime);
463  ENET_WriteManagementConfig(base, config);
464 }
465 
466 /*FUNCTION**********************************************************************
467  *
468  * Function Name : ENET_DRV_MDIOWrite
469  * Description : Writes the selected register of the PHY
470  *
471  * Implements : ENET_DRV_MDIOWrite_Activity
472  *END**************************************************************************/
473 status_t ENET_DRV_MDIOWrite(uint8_t instance,
474  uint8_t phyAddr,
475  uint8_t phyReg,
476  uint16_t data,
477  uint32_t timeoutMs)
478 {
479  ENET_Type *base;
480  uint32_t startTime, crtTime;
481  status_t status = STATUS_TIMEOUT;
482 
483  DEV_ASSERT(instance < ENET_INSTANCE_COUNT);
484 
485  base = s_enetBases[instance];
486 
487  /* Write management frame */
488  ENET_WriteManagementFrame(base, phyAddr, phyReg, ENET_MMFR_OP_WRITE, data);
489 
490  /* Wait for completion */
491  startTime = OSIF_GetMilliseconds();
492  do
493  {
494  if ((ENET_GetInterruptStatus(base) & ENET_EIR_MII_MASK) != 0)
495  {
496  status = STATUS_SUCCESS;
497  /* Clear the flag */
498  ENET_ClearInterruptStatus(base, ENET_EIR_MII_MASK);
499  break;
500  }
501  crtTime = OSIF_GetMilliseconds();
502  }
503  while (crtTime < startTime + timeoutMs);
504 
505  return status;
506 }
507 
508 /*FUNCTION**********************************************************************
509  *
510  * Function Name : ENET_DRV_MDIORead
511  * Description : Reads the selected register of the PHY
512  *
513  * Implements : ENET_DRV_MDIORead_Activity
514  *END**************************************************************************/
515 status_t ENET_DRV_MDIORead(uint8_t instance,
516  uint8_t phyAddr,
517  uint8_t phyReg,
518  uint16_t *data,
519  uint32_t timeoutMs)
520 {
521  ENET_Type *base;
522  uint32_t startTime, crtTime;
523  status_t status = STATUS_TIMEOUT;
524 
525  DEV_ASSERT(instance < ENET_INSTANCE_COUNT);
526 
527  base = s_enetBases[instance];
528 
529  /* Write management frame */
530  ENET_WriteManagementFrame(base, phyAddr, phyReg, ENET_MMFR_OP_READ, 0);
531 
532  /* Wait for completion */
533  startTime = OSIF_GetMilliseconds();
534  do
535  {
536  if ((ENET_GetInterruptStatus(base) & ENET_EIR_MII_MASK) != 0U)
537  {
538  *data = ENET_ReadManagementFrameData(base);
539  status = STATUS_SUCCESS;
540  /* Clear the flag */
541  ENET_ClearInterruptStatus(base, ENET_EIR_MII_MASK);
542  break;
543  }
544  crtTime = OSIF_GetMilliseconds();
545  }
546  while (crtTime < startTime + timeoutMs);
547 
548  return status;
549 }
550 
551 /*FUNCTION**********************************************************************
552  *
553  * Function Name : ENET_DRV_SetMacAddr
554  * Description : Configures the physical address of the MAC
555  *
556  * Implements : ENET_DRV_SetMacAddr_Activity
557  *END**************************************************************************/
558 void ENET_DRV_SetMacAddr(uint8_t instance,
559  uint8_t *macAddr)
560 {
561  uint32_t address;
562  ENET_Type *base;
563 
564  DEV_ASSERT(instance < ENET_INSTANCE_COUNT);
565 
566  base = s_enetBases[instance];
567 
568  /* Set physical address lower register. */
569  address = (macAddr[0] << ENET_BYTE_0_IN_ADDR_SHIFT) |
570  (macAddr[1] << ENET_BYTE_1_IN_ADDR_SHIFT) |
571  (macAddr[2] << ENET_BYTE_2_IN_ADDR_SHIFT) |
572  (macAddr[3] << ENET_BYTE_3_IN_ADDR_SHIFT);
573  ENET_SetPhyAddrLower(base, address);
574 
575  /* Set physical address high register. */
576  address = (macAddr[4] << ENET_BYTE_4_IN_ADDR_SHIFT) |
577  (macAddr[5] << ENET_BYTE_5_IN_ADDR_SHIFT);
578 
579  ENET_SetPhyAddrUpper(base, address);
580 }
581 
582 /*FUNCTION**********************************************************************
583  *
584  * Function Name : ENET_DRV_GetMacAddr
585  * Description : Gets the physical address of the MAC
586  *
587  * Implements : ENET_DRV_GetMacAddr_Activity
588  *END**************************************************************************/
589 void ENET_DRV_GetMacAddr(uint8_t instance,
590  uint8_t *macAddr)
591 {
592  ENET_Type *base;
593  uint32_t address;
594 
595  DEV_ASSERT(instance < ENET_INSTANCE_COUNT);
596  DEV_ASSERT(macAddr != NULL);
597 
598  base = s_enetBases[instance];
599 
600  /* Get from physical address lower register. */
601  address = ENET_GetPhyAddrLower(base);
602  macAddr[0] = (uint8_t)(ENET_BYTE_MASK & (address >> ENET_BYTE_0_IN_ADDR_SHIFT));
603  macAddr[1] = (uint8_t)(ENET_BYTE_MASK & (address >> ENET_BYTE_1_IN_ADDR_SHIFT));
604  macAddr[2] = (uint8_t)(ENET_BYTE_MASK & (address >> ENET_BYTE_2_IN_ADDR_SHIFT));
605  macAddr[3] = (uint8_t)(ENET_BYTE_MASK & (address >> ENET_BYTE_3_IN_ADDR_SHIFT));
606 
607  /* Get from physical address high register. */
608  address = ENET_GetPhyAddrUpper(base);
609  macAddr[4] = (uint8_t)(ENET_BYTE_MASK & (address >> ENET_BYTE_4_IN_ADDR_SHIFT));
610  macAddr[5] = (uint8_t)(ENET_BYTE_MASK & (address >> ENET_BYTE_5_IN_ADDR_SHIFT));
611 }
612 
613 /*FUNCTION**********************************************************************
614  *
615  * Function Name : ENET_DRV_SetUnicastForward
616  * Description : Enables/Disables forwarding of unicast traffic having a
617  * specific MAC address as destination.
618  *
619  * Implements : ENET_DRV_SetUnicastForward_Activity
620  *END**************************************************************************/
621 void ENET_DRV_SetUnicastForward(uint8_t instance,
622  uint8_t *macAddr,
623  bool enable)
624 {
625  ENET_Type *base;
626  uint32_t crc;
627 
628  DEV_ASSERT(instance < ENET_INSTANCE_COUNT);
629  DEV_ASSERT(macAddr != NULL);
630 
631  base = s_enetBases[instance];
632  crc = ENET_DRV_ComputeCRC32(macAddr);
633 
634  if (enable)
635  {
636  ENET_AddToIndividualHashTable(base, crc);
637  }
638  else
639  {
640  ENET_RemoveFromIndividualHashTable(base, crc);
641  }
642 }
643 
644 /*FUNCTION**********************************************************************
645  *
646  * Function Name : ENET_DRV_SetMulticastForward
647  * Description : Enables/Disables forwarding of multicast traffic having a
648  * specific MAC address as destination.
649  *
650  * Implements : ENET_DRV_SetMulticastForward_Activity
651  *END**************************************************************************/
652 void ENET_DRV_SetMulticastForward(uint8_t instance,
653  uint8_t *macAddr,
654  bool enable)
655 {
656  ENET_Type *base;
657  uint32_t crc;
658 
659  DEV_ASSERT(instance < ENET_INSTANCE_COUNT);
660  DEV_ASSERT(macAddr != NULL);
661 
662  base = s_enetBases[instance];
663  crc = ENET_DRV_ComputeCRC32(macAddr);
664 
665  if (enable)
666  {
667  ENET_AddToGroupHashTable(base, crc);
668  }
669  else
670  {
671  ENET_RemoveFromGroupHashTable(base, crc);
672  }
673 }
674 
675 /*FUNCTION**********************************************************************
676  *
677  * Function Name : ENET_DRV_SetMulticastForwardAll
678  * Description : Enables/Disables forwarding of the multicast traffic, irrespective
679  * of the destination MAC address.
680  *
681  * Implements : ENET_DRV_SetMulticastForwardAll_Activity
682  *END**************************************************************************/
683 void ENET_DRV_SetMulticastForwardAll(uint8_t instance,
684  bool enable)
685 {
686  ENET_Type *base;
687 
688  DEV_ASSERT(instance < ENET_INSTANCE_COUNT);
689 
690  base = s_enetBases[instance];
691 
692  if (enable)
693  {
694  base->GAUR = 0xFFFFFFFFU;
695  base->GALR = 0xFFFFFFFFU;
696  }
697  else
698  {
699  base->GAUR = 0x0U;
700  base->GALR = 0x0U;
701  }
702 }
703 
704 /*FUNCTION**********************************************************************
705  *
706  * Function Name : ENET_DRV_SetSleepMode
707  * Description : Sets the MAC in sleep mode or normal mode
708  *
709  * Implements : ENET_DRV_SetSleepMode_Activity
710  *END**************************************************************************/
711 void ENET_DRV_SetSleepMode(uint8_t instance,
712  bool enable)
713 {
714  ENET_Type *base;
715 
716  DEV_ASSERT(instance < ENET_INSTANCE_COUNT);
717 
718  base = s_enetBases[instance];
719 
720  if (enable)
721  {
723  }
724  else
725  {
727  }
728 }
729 
730 /*FUNCTION**********************************************************************
731  *
732  * Function Name : ENET_DRV_ConfigCounters
733  * Description : Enables/Disables the MIB counters
734  *
735  * Implements : ENET_DRV_ConfigCounters_Activity
736  *END**************************************************************************/
737 void ENET_DRV_ConfigCounters(uint8_t instance,
738  bool enable)
739 {
740  ENET_Type *base;
741 
742  DEV_ASSERT(instance < ENET_INSTANCE_COUNT);
743 
744  base = s_enetBases[instance];
745 
746  if (enable)
747  {
748  /* Clear counters - MIB_CLEAR bit needs to be set, then cleared */
750  (void) base->MIBC;
751  base->MIBC &= ~ENET_MIBC_MIB_CLEAR_MASK;
752 
753  base->MIBC &= ~ENET_MIBC_MIB_DIS_MASK;
754  }
755  else
756  {
757  base->MIBC |= ENET_MIBC_MIB_DIS_MASK;
758  }
759 }
760 
761 /*FUNCTION**********************************************************************
762  *
763  * Function Name : ENET_DRV_GetCounter
764  * Description : Gets statistics from the specified counter
765  *
766  * Implements : ENET_DRV_GetCounter_Activity
767  *END**************************************************************************/
768 uint32_t ENET_DRV_GetCounter(uint8_t instance,
769  enet_counter_t counter)
770 {
771  ENET_Type *base;
772 
773  DEV_ASSERT(instance < ENET_INSTANCE_COUNT);
774 
775  base = s_enetBases[instance];
776 
777  return *((((uint32_t *)base) + FEATURE_ENET_COUNTERS_OFFSET_WORDS) + (uint32_t)counter);
778 }
779 
780 /*******************************************************************************
781  * EOF
782  ******************************************************************************/
void ENET_DRV_GetMacAddr(uint8_t instance, uint8_t *macAddr)
Gets the physical address of the MAC.
Definition: enet_driver.c:589
#define FEATURE_ENET_COUNTERS_OFFSET_WORDS
The offset of the counters region relative to the base address, in words.
enet_state_t * g_enetState[ENET_INSTANCE_COUNT]
Pointers to ENET internal driver state for each instance.
Definition: enet_driver.c:46
Internal driver state structure Implements : enet_state_t_Class.
Definition: enet_driver.h:263
#define FEATURE_ENET_RX_IRQS
The reception interrupts.
#define ENET_INSTANCE_COUNT
Definition: S32K148.h:3362
#define ENET_MIBC_MIB_CLEAR_MASK
Definition: S32K148.h:3613
#define ENET_BYTE_0_IN_ADDR_SHIFT
Definition: enet_driver.c:32
void ENET_DRV_SetUnicastForward(uint8_t instance, uint8_t *macAddr, bool enable)
Enables/Disables forwarding of unicast traffic having a specific MAC address as destination.
Definition: enet_driver.c:621
Send/Receive buffer information for the user Implements : enet_buffer_t_Class.
Definition: enet_driver.h:177
#define ENET_BYTE_4_IN_ADDR_SHIFT
Definition: enet_driver.c:36
void ENET_DRV_GetDefaultConfig(enet_config_t *config)
Gets the default configuration structure.
Definition: enet_driver.c:113
void ENET_DRV_ConfigCounters(uint8_t instance, bool enable)
Enables/Disables the MIB counters.
Definition: enet_driver.c:737
uint16_t maxFrameLen
Definition: enet_driver.h:246
status_t ENET_DRV_GetTransmitStatus(uint8_t instance, enet_buffer_t *buff)
Checks if the transmission of a buffer is complete.
Definition: enet_driver.c:358
Defines the ENET module configuration structure Implements : enet_config_t_Class. ...
Definition: enet_driver.h:240
enet_callback_t callback
Definition: enet_driver.h:256
uint32_t OSIF_GetMilliseconds(void)
Returns the number of miliseconds elapsed since starting the internal timer or starting the scheduler...
#define ENET_BYTE_MASK
Definition: enet_driver.c:39
#define ENET_MSCR_MII_SPEED(x)
Definition: S32K148.h:3603
IRQn_Type
Defines the Interrupt Numbers definitions.
Definition: S32K148.h:192
#define FEATURE_ENET_MDIO_MIN_HOLD_TIME_NS
Minimum hold time on the MDIO output, in nanoseconds.
void ENET_DRV_EnableMDIO(uint8_t instance, bool miiPreambleDisabled)
Enables the MDIO interface.
Definition: enet_driver.c:444
uint32_t rxConfig
Definition: enet_driver.h:253
void ENET_DRV_Deinit(uint8_t instance)
Deinitializes the ENET module.
Definition: enet_driver.c:225
void INT_SYS_DisableIRQ(IRQn_Type irqNumber)
Disables an interrupt for a given IRQ number.
#define FEATURE_ENET_ERR_IRQS
The error interrupts.
#define ENET_MIN_BUFFERSIZE
ENET minimum buffer size.
Definition: enet_driver.h:42
enet_buffer_descriptor_t * rxBdCurrent
Definition: enet_driver.h:266
#define DEV_ASSERT(x)
Definition: devassert.h:77
#define ENET_BUFF_IS_ALIGNED(x)
Definition: enet_driver.h:46
void ENET_DRV_ProvideRxBuff(uint8_t instance, enet_buffer_t *buff)
Provides a receive buffer to be used by the driver for reception.
Definition: enet_driver.c:400
enet_buffer_descriptor_t * rxBdAlloc
Definition: enet_driver.h:267
#define ENET_MSCR_DIS_PRE(x)
Definition: S32K148.h:3607
#define ENET_ECR_MAGICEN_MASK
Definition: S32K148.h:3554
#define FEATURE_ENET_TX_IRQS
The transmission interrupts.
#define ENET_ECR_SLEEP_MASK
Definition: S32K148.h:3558
#define ENET_EIR_MII_MASK
Definition: S32K148.h:3438
void ENET_DRV_SetMacAddr(uint8_t instance, uint8_t *macAddr)
Configures the physical address of the MAC.
Definition: enet_driver.c:558
static uint32_t ENET_DRV_ComputeCRC32(uint8_t *mac)
Definition: enet_driver.c:78
enet_counter_t
Statistics counters enumeration Implements : enet_counter_t_Class.
Definition: enet_driver.h:277
void ENET_DRV_SetMulticastForwardAll(uint8_t instance, bool enable)
Enables/Disables forwarding of the multicast traffic, irrespective of the destination MAC address...
Definition: enet_driver.c:683
status_t ENET_DRV_MDIOWrite(uint8_t instance, uint8_t phyAddr, uint8_t phyReg, uint16_t data, uint32_t timeoutMs)
Writes the selected register of the PHY.
Definition: enet_driver.c:473
__IO uint32_t MIBC
Definition: S32K148.h:3256
status_t CLOCK_SYS_GetFreq(clock_names_t clockName, uint32_t *frequency)
Gets the clock frequency for a specific clock name.
enet_callback_t callback
Definition: enet_driver.h:270
enet_mii_mode_t miiMode
Definition: enet_driver.h:249
#define FEATURE_ENET_DEFAULT_PHY_IF
Default configuration for the PHY interface.
enet_mii_duplex_t miiDuplex
Definition: enet_driver.h:251
uint32_t interrupt
Definition: enet_driver.h:247
#define ENET_ROUNDED_UP_DIV(a, b)
Definition: enet_driver.c:27
Defines the ENET buffer descriptors ring configuration structure Implements : enet_buffer_config_t_Cl...
Definition: enet_driver.h:227
status_t
Status return codes. Common error codes will be a unified enumeration (C enum) that will contain all ...
Definition: status.h:44
clock_names_t
Clock names.
#define ENET_BYTE_5_IN_ADDR_SHIFT
Definition: enet_driver.c:37
uint8_t rxAccelerConfig
Definition: enet_driver.h:243
status_t ENET_DRV_SendFrame(uint8_t instance, enet_buffer_t *buff)
Sends an Ethernet frame.
Definition: enet_driver.c:306
#define ENET_MSCR_HOLDTIME(x)
Definition: S32K148.h:3611
enet_buffer_descriptor_t * rxRingAligned
Definition: enet_driver.h:231
enet_buffer_descriptor_t * txBdBase
Definition: enet_driver.h:268
enet_mii_speed_t miiSpeed
Definition: enet_driver.h:250
#define ENET_BYTE_2_IN_ADDR_SHIFT
Definition: enet_driver.c:34
static const IRQn_Type s_enetTxIrqId[]
ENET transmit IRQ number for each instance.
Definition: enet_driver.c:49
static const clock_names_t s_enetClkNames[]
Table to save ENET clock indexes in clock configuration.
Definition: enet_driver.c:60
uint8_t * rxBufferAligned
Definition: enet_driver.h:233
#define ENET_BUFF_ALIGN(x)
Definitions used for aligning the data buffers.
Definition: enet_driver.h:45
enet_buffer_descriptor_t * txRingAligned
Definition: enet_driver.h:232
enet_buffer_descriptor_t * rxBdBase
Definition: enet_driver.h:265
#define FEATURE_ENET_WAKE_IRQS
The wakeup interrupts.
#define FEATURE_ENET_CLOCK_NAMES
ENET peripheral clock names.
void ENET_DRV_SetMulticastForward(uint8_t instance, uint8_t *macAddr, bool enable)
Enables/Disables forwarding of multicast traffic having a specific MAC address as destination...
Definition: enet_driver.c:652
__IO uint32_t GAUR
Definition: S32K148.h:3268
enet_buffer_descriptor_t * txBdCurrent
Definition: enet_driver.h:269
#define ENET_BUFFDESCR_IS_ALIGNED(x)
Definition: enet_driver.h:50
#define ENET_BYTE_1_IN_ADDR_SHIFT
Definition: enet_driver.c:33
static const IRQn_Type s_enetRxIrqId[]
ENET receive IRQ number for each instance.
Definition: enet_driver.c:51
void INT_SYS_EnableIRQ(IRQn_Type irqNumber)
Enables an interrupt for a given IRQ number.
#define ENET_FRAME_MAX_FRAMELEN
Defines the maximum Ethernet frame size.
Definition: enet_driver.h:40
uint8_t txAccelerConfig
Definition: enet_driver.h:244
#define ENET_NS_IN_SECOND
Definition: enet_driver.c:28
uint32_t ENET_DRV_GetCounter(uint8_t instance, enet_counter_t counter)
Gets statistics from the specified counter.
Definition: enet_driver.c:768
#define ENET_ALL_INTERRUPTS_MASK
Definition: enet_driver.c:30
uint8_t * data
Definition: enet_driver.h:179
void ENET_DRV_SetSleepMode(uint8_t instance, bool enable)
Sets the MAC in sleep mode or normal mode.
Definition: enet_driver.c:711
uint16_t length
Definition: enet_driver.h:180
#define ENET_BYTE_3_IN_ADDR_SHIFT
Definition: enet_driver.c:35
status_t ENET_DRV_ReadFrame(uint8_t instance, enet_buffer_t *buff)
Reads a received Ethernet frame.
Definition: enet_driver.c:261
#define ENET_MIBC_MIB_DIS_MASK
Definition: S32K148.h:3621
#define FEATURE_ENET_MDC_MAX_FREQUENCY
The maximum supported frequency for MDC, in Hz.
status_t ENET_DRV_MDIORead(uint8_t instance, uint8_t phyAddr, uint8_t phyReg, uint16_t *data, uint32_t timeoutMs)
Reads the selected register of the PHY.
Definition: enet_driver.c:515
static const IRQn_Type s_enetErrIrqId[]
ENET error IRQ number for each instance.
Definition: enet_driver.c:53
__IO uint32_t GALR
Definition: S32K148.h:3269
uint32_t txConfig
Definition: enet_driver.h:254
__IO uint32_t ECR
Definition: S32K148.h:3251
void ENET_DRV_Init(uint8_t instance, enet_state_t *state, const enet_config_t *config, const enet_buffer_config_t *bufferConfig, uint8_t *macAddr)
Initializes the ENET module.
Definition: enet_driver.c:147