106
106
#define ENET_NTOHS (n ) __REV16(n)
107
107
#define ENET_NTOHL (n ) __REV(n)
108
108
109
+ /* Typedef for interrupt handler. */
110
+ typedef void (* enet_isr_t )(ENET_Type * base , enet_handle_t * handle );
109
111
/*******************************************************************************
110
112
* Prototypes
111
113
******************************************************************************/
@@ -132,7 +134,18 @@ static void ENET_SetMacController(ENET_Type *base,
132
134
const enet_buffer_config_t * bufferConfig ,
133
135
uint8_t * macAddr ,
134
136
uint32_t srcClock_Hz );
135
-
137
+ /*!
138
+ * @brief Set ENET handler.
139
+ *
140
+ * @param base ENET peripheral base address.
141
+ * @param handle The ENET handle pointer.
142
+ * @param config ENET configuration stucture pointer.
143
+ * @param bufferConfig ENET buffer configuration.
144
+ */
145
+ static void ENET_SetHandler (ENET_Type * base ,
146
+ enet_handle_t * handle ,
147
+ const enet_config_t * config ,
148
+ const enet_buffer_config_t * bufferConfig );
136
149
/*!
137
150
* @brief Set ENET MAC transmit buffer descriptors.
138
151
*
@@ -226,22 +239,26 @@ static status_t ENET_StoreRxFrameTime(ENET_Type *base, enet_handle_t *handle, en
226
239
static enet_handle_t * s_ENETHandle [FSL_FEATURE_SOC_ENET_COUNT ] = {NULL };
227
240
228
241
/*! @brief Pointers to enet clocks for each instance. */
229
- const clock_ip_name_t s_enetClock [FSL_FEATURE_SOC_ENET_COUNT ] = ENET_CLOCKS ;
242
+ const clock_ip_name_t s_enetClock [] = ENET_CLOCKS ;
230
243
231
244
/*! @brief Pointers to enet transmit IRQ number for each instance. */
232
- const IRQn_Type s_enetTxIrqId [] = ENET_Transmit_IRQS ;
245
+ static const IRQn_Type s_enetTxIrqId [] = ENET_Transmit_IRQS ;
233
246
/*! @brief Pointers to enet receive IRQ number for each instance. */
234
- const IRQn_Type s_enetRxIrqId [] = ENET_Receive_IRQS ;
247
+ static const IRQn_Type s_enetRxIrqId [] = ENET_Receive_IRQS ;
235
248
#if defined(ENET_ENHANCEDBUFFERDESCRIPTOR_MODE ) && ENET_ENHANCEDBUFFERDESCRIPTOR_MODE
236
249
/*! @brief Pointers to enet timestamp IRQ number for each instance. */
237
- const IRQn_Type s_enetTsIrqId [] = ENET_1588_Timer_IRQS ;
250
+ static const IRQn_Type s_enetTsIrqId [] = ENET_1588_Timer_IRQS ;
238
251
#endif /* ENET_ENHANCEDBUFFERDESCRIPTOR_MODE */
239
252
/*! @brief Pointers to enet error IRQ number for each instance. */
240
- const IRQn_Type s_enetErrIrqId [] = ENET_Error_IRQS ;
253
+ static const IRQn_Type s_enetErrIrqId [] = ENET_Error_IRQS ;
241
254
242
255
/*! @brief Pointers to enet bases for each instance. */
243
256
static ENET_Type * const s_enetBases [] = ENET_BASE_PTRS ;
244
257
258
+ /* ENET ISR for transactional APIs. */
259
+ static enet_isr_t s_enetTxIsr ;
260
+ static enet_isr_t s_enetRxIsr ;
261
+ static enet_isr_t s_enetErrIsr ;
245
262
/*******************************************************************************
246
263
* Code
247
264
******************************************************************************/
@@ -312,26 +329,13 @@ void ENET_Init(ENET_Type *base,
312
329
/* Initializes the ENET receive buffer descriptors. */
313
330
ENET_SetRxBufferDescriptors (bufferConfig -> rxBdStartAddrAlign , bufferConfig -> rxBufferAlign ,
314
331
bufferConfig -> rxBuffSizeAlign , bufferConfig -> rxBdNumber ,
315
- !!(config -> interrupt & (kENET_RxFrameInterrupt | kENET_RxByteInterrupt )));
332
+ !!(config -> interrupt & (kENET_RxFrameInterrupt | kENET_RxBufferInterrupt )));
316
333
317
334
/* Initializes the ENET MAC controller. */
318
335
ENET_SetMacController (base , config , bufferConfig , macAddr , srcClock_Hz );
319
336
320
- /* Initialize the handle to zero. */
321
- memset (handle , 0 , sizeof (enet_handle_t ));
322
-
323
- /* Store transfer parameters in handle pointer. */
324
- handle -> rxBdBase = bufferConfig -> rxBdStartAddrAlign ;
325
- handle -> rxBdCurrent = bufferConfig -> rxBdStartAddrAlign ;
326
- handle -> rxBdDirty = bufferConfig -> rxBdStartAddrAlign ;
327
- handle -> txBdBase = bufferConfig -> txBdStartAddrAlign ;
328
- handle -> txBdCurrent = bufferConfig -> txBdStartAddrAlign ;
329
- handle -> txBdDirty = bufferConfig -> txBdStartAddrAlign ;
330
- handle -> rxBuffSizeAlign = bufferConfig -> rxBuffSizeAlign ;
331
- handle -> txBuffSizeAlign = bufferConfig -> txBuffSizeAlign ;
332
-
333
- /* Save the handle pointer in the global variables. */
334
- s_ENETHandle [instance ] = handle ;
337
+ /* Set all buffers or data in handler for data transmit/receive process. */
338
+ ENET_SetHandler (base , handle , config , bufferConfig );
335
339
}
336
340
337
341
void ENET_Deinit (ENET_Type * base )
@@ -355,6 +359,44 @@ void ENET_SetCallback(enet_handle_t *handle, enet_callback_t callback, void *use
355
359
handle -> userData = userData ;
356
360
}
357
361
362
+ static void ENET_SetHandler (ENET_Type * base ,
363
+ enet_handle_t * handle ,
364
+ const enet_config_t * config ,
365
+ const enet_buffer_config_t * bufferConfig )
366
+ {
367
+ uint32_t instance = ENET_GetInstance (base );
368
+
369
+ memset (handle , 0 , sizeof (enet_handle_t ));
370
+
371
+ handle -> rxBdBase = bufferConfig -> rxBdStartAddrAlign ;
372
+ handle -> rxBdCurrent = bufferConfig -> rxBdStartAddrAlign ;
373
+ handle -> txBdBase = bufferConfig -> txBdStartAddrAlign ;
374
+ handle -> txBdCurrent = bufferConfig -> txBdStartAddrAlign ;
375
+ handle -> txBdDirty = bufferConfig -> txBdStartAddrAlign ;
376
+ handle -> rxBuffSizeAlign = bufferConfig -> rxBuffSizeAlign ;
377
+ handle -> txBuffSizeAlign = bufferConfig -> txBuffSizeAlign ;
378
+
379
+ /* Save the handle pointer in the global variables. */
380
+ s_ENETHandle [instance ] = handle ;
381
+
382
+ /* Set the IRQ handler when the interrupt is enabled. */
383
+ if (config -> interrupt & ENET_TX_INTERRUPT )
384
+ {
385
+ s_enetTxIsr = ENET_TransmitIRQHandler ;
386
+ EnableIRQ (s_enetTxIrqId [instance ]);
387
+ }
388
+ if (config -> interrupt & ENET_RX_INTERRUPT )
389
+ {
390
+ s_enetRxIsr = ENET_ReceiveIRQHandler ;
391
+ EnableIRQ (s_enetRxIrqId [instance ]);
392
+ }
393
+ if (config -> interrupt & ENET_ERR_INTERRUPT )
394
+ {
395
+ s_enetErrIsr = ENET_ErrorIRQHandler ;
396
+ EnableIRQ (s_enetErrIrqId [instance ]);
397
+ }
398
+ }
399
+
358
400
static void ENET_SetMacController (ENET_Type * base ,
359
401
const enet_config_t * config ,
360
402
const enet_buffer_config_t * bufferConfig ,
@@ -452,20 +494,6 @@ static void ENET_SetMacController(ENET_Type *base,
452
494
453
495
/* Enables Ethernet interrupt and NVIC. */
454
496
ENET_EnableInterrupts (base , config -> interrupt );
455
- if (config -> interrupt & (kENET_RxByteInterrupt | kENET_RxFrameInterrupt ))
456
- {
457
- EnableIRQ (s_enetRxIrqId [instance ]);
458
- }
459
- if (config -> interrupt & (kENET_TxByteInterrupt | kENET_TxFrameInterrupt ))
460
- {
461
- EnableIRQ (s_enetTxIrqId [instance ]);
462
- }
463
- if (config -> interrupt & (kENET_BabrInterrupt | kENET_BabtInterrupt | kENET_GraceStopInterrupt | kENET_MiiInterrupt |
464
- kENET_EBusERInterrupt | kENET_LateCollisionInterrupt | kENET_RetryLimitInterrupt |
465
- kENET_UnderrunInterrupt | kENET_PayloadRxInterrupt | kENET_WakeupInterrupt ))
466
- {
467
- EnableIRQ (s_enetErrIrqId [instance ]);
468
- }
469
497
470
498
/* ENET control register setting. */
471
499
ecr = base -> ECR ;
@@ -490,10 +518,10 @@ static void ENET_SetTxBufferDescriptors(volatile enet_tx_bd_struct_t *txBdStartA
490
518
491
519
for (count = 0 ; count < txBdNumber ; count ++ )
492
520
{
493
- if (txBuffSizeAlign != NULL )
521
+ if (txBuffStartAlign != NULL )
494
522
{
495
- /* Set data buffer address. */
496
- curBuffDescrip -> buffer = (uint8_t * )((uint32_t )& txBuffStartAlign [count * txBuffSizeAlign ]);
523
+ /* Set data buffer address. */
524
+ curBuffDescrip -> buffer = (uint8_t * )((uint32_t )& txBuffStartAlign [count * txBuffSizeAlign ]);
497
525
}
498
526
else
499
527
{
@@ -517,6 +545,7 @@ static void ENET_SetTxBufferDescriptors(volatile enet_tx_bd_struct_t *txBdStartA
517
545
/* Increase the index. */
518
546
curBuffDescrip ++ ;
519
547
}
548
+
520
549
}
521
550
522
551
static void ENET_SetRxBufferDescriptors (volatile enet_rx_bd_struct_t * rxBdStartAlign ,
@@ -564,12 +593,8 @@ static void ENET_SetRxBufferDescriptors(volatile enet_rx_bd_struct_t *rxBdStartA
564
593
565
594
void ENET_SetMII (ENET_Type * base , enet_mii_speed_t speed , enet_mii_duplex_t duplex )
566
595
{
567
- uint32_t rcr ;
568
- uint32_t tcr ;
569
-
570
- rcr = base -> RCR ;
571
- tcr = base -> TCR ;
572
-
596
+ uint32_t rcr = base -> RCR ;
597
+ uint32_t tcr = base -> TCR ;
573
598
/* Sets speed mode. */
574
599
if (kENET_MiiSpeed10M == speed )
575
600
{
@@ -1274,11 +1299,9 @@ void ENET_Ptp1588Configure(ENET_Type *base, enet_handle_t *handle, enet_ptp_conf
1274
1299
1275
1300
/* Enables the time stamp interrupt for the master clock on a device. */
1276
1301
ENET_EnableInterrupts (base , kENET_TsTimerInterrupt );
1277
- EnableIRQ (s_enetTsIrqId [instance ]);
1278
-
1279
1302
/* Enables the transmit interrupt to store the transmit frame time-stamp. */
1280
1303
ENET_EnableInterrupts (base , kENET_TxFrameInterrupt );
1281
- EnableIRQ ( s_enetTxIrqId [ instance ] );
1304
+ ENET_DisableInterrupts ( base , kENET_TxBufferInterrupt );
1282
1305
1283
1306
/* Setting the receive and transmit state for transaction. */
1284
1307
handle -> rxPtpTsDataRing .ptpTsData = ptpConfig -> rxPtpTsData ;
@@ -1292,6 +1315,11 @@ void ENET_Ptp1588Configure(ENET_Type *base, enet_handle_t *handle, enet_ptp_conf
1292
1315
handle -> msTimerSecond = 0 ;
1293
1316
handle -> txBdDirtyTime = handle -> txBdBase ;
1294
1317
handle -> txBdDirtyStatic = handle -> txBdBase ;
1318
+
1319
+ /* Set the IRQ handler when the interrupt is enabled. */
1320
+ s_enetTxIsr = ENET_TransmitIRQHandler ;
1321
+ EnableIRQ (s_enetTsIrqId [instance ]);
1322
+ EnableIRQ (s_enetTxIrqId [instance ]);
1295
1323
}
1296
1324
1297
1325
void ENET_Ptp1588StartTimer (ENET_Type * base , uint32_t ptpClkSrc )
@@ -1591,14 +1619,19 @@ void ENET_TransmitIRQHandler(ENET_Type *base, enet_handle_t *handle)
1591
1619
assert (handle );
1592
1620
1593
1621
/* Check if the transmit interrupt happen. */
1594
- if ((kENET_TxByteInterrupt | kENET_TxFrameInterrupt ) & base -> EIR )
1622
+ while ((kENET_TxBufferInterrupt | kENET_TxFrameInterrupt ) & base -> EIR )
1595
1623
{
1596
- /* Clear the transmit interrupt event. */
1597
- base -> EIR = kENET_TxFrameInterrupt | kENET_TxByteInterrupt ;
1598
1624
#ifdef ENET_ENHANCEDBUFFERDESCRIPTOR_MODE
1625
+ if (base -> EIR & kENET_TxFrameInterrupt )
1626
+ {
1599
1627
/* Store the transmit timestamp from the buffer descriptor should be done here. */
1600
1628
ENET_StoreTxFrameTime (base , handle );
1629
+ }
1601
1630
#endif /* ENET_ENHANCEDBUFFERDESCRIPTOR_MODE */
1631
+
1632
+ /* Clear the transmit interrupt event. */
1633
+ base -> EIR = kENET_TxFrameInterrupt | kENET_TxBufferInterrupt ;
1634
+
1602
1635
/* Callback function. */
1603
1636
if (handle -> callback )
1604
1637
{
@@ -1612,10 +1645,10 @@ void ENET_ReceiveIRQHandler(ENET_Type *base, enet_handle_t *handle)
1612
1645
assert (handle );
1613
1646
1614
1647
/* Check if the receive interrupt happen. */
1615
- if ((kENET_RxByteInterrupt | kENET_RxFrameInterrupt ) & base -> EIR )
1648
+ while ((kENET_RxBufferInterrupt | kENET_RxFrameInterrupt ) & base -> EIR )
1616
1649
{
1617
1650
/* Clear the transmit interrupt event. */
1618
- base -> EIR = kENET_RxFrameInterrupt | kENET_RxByteInterrupt ;
1651
+ base -> EIR = kENET_RxFrameInterrupt | kENET_RxBufferInterrupt ;
1619
1652
1620
1653
/* Callback function. */
1621
1654
if (handle -> callback )
@@ -1688,26 +1721,24 @@ void ENET_Ptp1588TimerIRQHandler(ENET_Type *base, enet_handle_t *handle)
1688
1721
}
1689
1722
}
1690
1723
}
1724
+
1725
+ void ENET_1588_Timer_IRQHandler (void )
1726
+ {
1727
+ ENET_Ptp1588TimerIRQHandler (ENET , s_ENETHandle [0 ]);
1728
+ }
1691
1729
#endif /* ENET_ENHANCEDBUFFERDESCRIPTOR_MODE */
1692
1730
1693
1731
void ENET_Transmit_IRQHandler (void )
1694
1732
{
1695
- ENET_TransmitIRQHandler (ENET , s_ENETHandle [0 ]);
1733
+ s_enetTxIsr (ENET , s_ENETHandle [0 ]);
1696
1734
}
1697
1735
1698
1736
void ENET_Receive_IRQHandler (void )
1699
1737
{
1700
- ENET_ReceiveIRQHandler (ENET , s_ENETHandle [0 ]);
1738
+ s_enetRxIsr (ENET , s_ENETHandle [0 ]);
1701
1739
}
1702
1740
1703
1741
void ENET_Error_IRQHandler (void )
1704
1742
{
1705
- ENET_ErrorIRQHandler (ENET , s_ENETHandle [0 ]);
1706
- }
1707
-
1708
- void ENET_1588_Timer_IRQHandler (void )
1709
- {
1710
- #ifdef ENET_ENHANCEDBUFFERDESCRIPTOR_MODE
1711
- ENET_Ptp1588TimerIRQHandler (ENET , s_ENETHandle [0 ]);
1712
- #endif /* ENET_ENHANCEDBUFFERDESCRIPTOR_MODE */
1743
+ s_enetErrIsr (ENET , s_ENETHandle [0 ]);
1713
1744
}
0 commit comments