@@ -127,24 +127,25 @@ static void update_read_buffer(uint8_t *buf)
127
127
*/
128
128
void Kinetis_EMAC::tx_reclaim ()
129
129
{
130
- /* Get exclusive access */
131
- TXLockMutex.lock ();
132
-
133
- // Traverse all descriptors, looking for the ones modified by the uDMA
134
- while ((tx_consume_index != tx_produce_index) &&
135
- (!(g_handle.txBdDirty ->control & ENET_BUFFDESCRIPTOR_TX_READY_MASK))) {
136
- memory_manager->free (tx_buff[tx_consume_index % ENET_TX_RING_LEN]);
137
- if (g_handle.txBdDirty ->control & ENET_BUFFDESCRIPTOR_TX_WRAP_MASK)
138
- g_handle.txBdDirty = g_handle.txBdBase ;
139
- else
140
- g_handle.txBdDirty ++;
141
-
142
- tx_consume_index += 1 ;
143
- xTXDCountSem.release ();
144
- }
145
-
146
- /* Restore access */
147
- TXLockMutex.unlock ();
130
+ /* Get exclusive access */
131
+ TXLockMutex.lock ();
132
+
133
+ // Traverse all descriptors, looking for the ones modified by the uDMA
134
+ while ((tx_consume_index != tx_produce_index) &&
135
+ (!(g_handle.txBdDirty ->control & ENET_BUFFDESCRIPTOR_TX_READY_MASK))) {
136
+ memory_manager->free (tx_buff[tx_consume_index % ENET_TX_RING_LEN]);
137
+ if (g_handle.txBdDirty ->control & ENET_BUFFDESCRIPTOR_TX_WRAP_MASK) {
138
+ g_handle.txBdDirty = g_handle.txBdBase ;
139
+ } else {
140
+ g_handle.txBdDirty ++;
141
+ }
142
+
143
+ tx_consume_index += 1 ;
144
+ xTXDCountSem.release ();
145
+ }
146
+
147
+ /* Restore access */
148
+ TXLockMutex.unlock ();
148
149
}
149
150
150
151
/* * \brief Ethernet receive interrupt handler
@@ -166,16 +167,15 @@ void Kinetis_EMAC::tx_isr()
166
167
void Kinetis_EMAC::ethernet_callback (ENET_Type *base, enet_handle_t *handle, enet_event_t event, void *param)
167
168
{
168
169
Kinetis_EMAC *enet = static_cast <Kinetis_EMAC *>(param);
169
- switch (event)
170
- {
171
- case kENET_RxEvent :
172
- enet->rx_isr ();
173
- break ;
174
- case kENET_TxEvent :
175
- enet->tx_isr ();
176
- break ;
177
- default :
178
- break ;
170
+ switch (event) {
171
+ case kENET_RxEvent :
172
+ enet->rx_isr ();
173
+ break ;
174
+ case kENET_TxEvent :
175
+ enet->tx_isr ();
176
+ break ;
177
+ default :
178
+ break ;
179
179
}
180
180
}
181
181
@@ -193,24 +193,27 @@ bool Kinetis_EMAC::low_level_init_successful()
193
193
194
194
// Allocate RX descriptors
195
195
rx_desc_start_addr = (uint8_t *)calloc (1 , sizeof (enet_rx_bd_struct_t ) * ENET_RX_RING_LEN + ENET_BUFF_ALIGNMENT);
196
- if (!rx_desc_start_addr)
196
+ if (!rx_desc_start_addr) {
197
197
return false ;
198
+ }
198
199
199
200
// Allocate TX descriptors
200
201
tx_desc_start_addr = (uint8_t *)calloc (1 , sizeof (enet_tx_bd_struct_t ) * ENET_TX_RING_LEN + ENET_BUFF_ALIGNMENT);
201
- if (!tx_desc_start_addr)
202
+ if (!tx_desc_start_addr) {
202
203
return false ;
204
+ }
203
205
204
206
rx_desc_start_addr = (uint8_t *)ENET_ALIGN (rx_desc_start_addr, ENET_BUFF_ALIGNMENT);
205
207
tx_desc_start_addr = (uint8_t *)ENET_ALIGN (tx_desc_start_addr, ENET_BUFF_ALIGNMENT);
206
208
207
209
/* Create buffers for each receive BD */
208
210
for (i = 0 ; i < ENET_RX_RING_LEN; i++) {
209
211
rx_buff[i] = memory_manager->alloc_heap (ENET_ETH_MAX_FLEN, ENET_BUFF_ALIGNMENT);
210
- if (NULL == rx_buff[i])
212
+ if (NULL == rx_buff[i]) {
211
213
return false ;
214
+ }
212
215
213
- rx_ptr[i] = (uint32_t *)memory_manager->get_ptr (rx_buff[i]);
216
+ rx_ptr[i] = (uint32_t *)memory_manager->get_ptr (rx_buff[i]);
214
217
}
215
218
216
219
tx_consume_index = tx_produce_index = 0 ;
@@ -223,7 +226,7 @@ bool Kinetis_EMAC::low_level_init_successful()
223
226
0 ,
224
227
(volatile enet_rx_bd_struct_t *)rx_desc_start_addr,
225
228
(volatile enet_tx_bd_struct_t *)tx_desc_start_addr,
226
- (uint8_t *)&rx_ptr,
229
+ (uint8_t *) &rx_ptr,
227
230
NULL ,
228
231
};
229
232
@@ -293,16 +296,16 @@ emac_mem_buf_t *Kinetis_EMAC::low_level_input(int idx)
293
296
update_read_buffer (NULL );
294
297
295
298
#ifdef LOCK_RX_THREAD
296
- TXLockMutex.unlock ();
299
+ TXLockMutex.unlock ();
297
300
#endif
298
301
299
302
return NULL ;
300
303
}
301
304
302
305
rx_buff[idx] = temp_rxbuf;
303
- rx_ptr[idx] = (uint32_t *)memory_manager->get_ptr (rx_buff[idx]);
306
+ rx_ptr[idx] = (uint32_t *)memory_manager->get_ptr (rx_buff[idx]);
304
307
305
- update_read_buffer ((uint8_t *)rx_ptr[idx]);
308
+ update_read_buffer ((uint8_t *)rx_ptr[idx]);
306
309
}
307
310
308
311
#ifdef LOCK_RX_THREAD
@@ -335,12 +338,12 @@ void Kinetis_EMAC::input(int idx)
335
338
*
336
339
* \param[in] pvParameters pointer to the interface data
337
340
*/
338
- void Kinetis_EMAC::thread_function (void * pvParameters)
341
+ void Kinetis_EMAC::thread_function (void * pvParameters)
339
342
{
340
343
struct Kinetis_EMAC *kinetis_enet = static_cast <Kinetis_EMAC *>(pvParameters);
341
344
342
345
for (;;) {
343
- uint32_t flags = osThreadFlagsWait (FLAG_RX| FLAG_TX, osFlagsWaitAny, osWaitForever);
346
+ uint32_t flags = osThreadFlagsWait (FLAG_RX | FLAG_TX, osFlagsWaitAny, osWaitForever);
344
347
345
348
MBED_ASSERT (!(flags & osFlagsError));
346
349
@@ -391,7 +394,7 @@ bool Kinetis_EMAC::link_out(emac_mem_buf_t *buf)
391
394
{
392
395
// If buffer is chained or not aligned then make a contiguous aligned copy of it
393
396
if (memory_manager->get_next (buf) ||
394
- reinterpret_cast <uint32_t >(memory_manager->get_ptr (buf)) % ENET_BUFF_ALIGNMENT) {
397
+ reinterpret_cast <uint32_t >(memory_manager->get_ptr (buf)) % ENET_BUFF_ALIGNMENT) {
395
398
emac_mem_buf_t *copy_buf;
396
399
copy_buf = memory_manager->alloc_heap (memory_manager->get_total_len (buf), ENET_BUFF_ALIGNMENT);
397
400
if (NULL == copy_buf) {
@@ -542,7 +545,7 @@ bool Kinetis_EMAC::get_hwaddr(uint8_t *addr) const
542
545
void Kinetis_EMAC::set_hwaddr (const uint8_t *addr)
543
546
{
544
547
memcpy (hwaddr, addr, sizeof hwaddr);
545
- ENET_SetMacAddr (ENET, const_cast <uint8_t *>(addr));
548
+ ENET_SetMacAddr (ENET, const_cast <uint8_t *>(addr));
546
549
}
547
550
548
551
void Kinetis_EMAC::set_link_input_cb (emac_link_input_cb_t input_cb)
@@ -587,13 +590,15 @@ void Kinetis_EMAC::set_memory_manager(EMACMemoryManager &mem_mngr)
587
590
}
588
591
589
592
590
- Kinetis_EMAC &Kinetis_EMAC::get_instance () {
593
+ Kinetis_EMAC &Kinetis_EMAC::get_instance ()
594
+ {
591
595
static Kinetis_EMAC emac;
592
596
return emac;
593
597
}
594
598
595
599
// Weak so a module can override
596
- MBED_WEAK EMAC &EMAC::get_default_instance () {
600
+ MBED_WEAK EMAC &EMAC::get_default_instance ()
601
+ {
597
602
return Kinetis_EMAC::get_instance ();
598
603
}
599
604
0 commit comments