@@ -99,6 +99,9 @@ static void update_read_buffer(uint8_t *buf)
99
99
g_handle.rxBdCurrent [0 ]->buffer = buf;
100
100
}
101
101
102
+ /* Ensures buffer pointer is written before control. */
103
+ __DMB ();
104
+
102
105
/* Clears status. */
103
106
g_handle.rxBdCurrent [0 ]->control &= ENET_BUFFDESCRIPTOR_RX_WRAP_MASK;
104
107
@@ -112,6 +115,9 @@ static void update_read_buffer(uint8_t *buf)
112
115
g_handle.rxBdCurrent [0 ]++;
113
116
}
114
117
118
+ /* Ensures descriptor is written before kicking hardware. */
119
+ __DSB ();
120
+
115
121
/* Actives the receive buffer descriptor. */
116
122
ENET->RDAR = ENET_RDAR_RDAR_MASK;
117
123
}
@@ -195,6 +201,7 @@ bool Kinetis_EMAC::low_level_init_successful()
195
201
return false ;
196
202
197
203
rx_ptr[i] = (uint32_t *)memory_manager->get_ptr (rx_buff[i]);
204
+ SCB_InvalidateDCache_by_Addr (rx_ptr[i], ENET_ALIGN (ENET_ETH_MAX_FLEN, ENET_BUFF_ALIGNMENT));
198
205
}
199
206
200
207
tx_consume_index = tx_produce_index = 0 ;
@@ -277,6 +284,7 @@ emac_mem_buf_t *Kinetis_EMAC::low_level_input(int idx)
277
284
278
285
/* Zero-copy */
279
286
p = rx_buff[idx];
287
+ SCB_InvalidateDCache_by_Addr (rx_ptr[idx], length);
280
288
memory_manager->set_len (p, length);
281
289
282
290
/* Attempt to queue new buffer */
@@ -295,6 +303,7 @@ emac_mem_buf_t *Kinetis_EMAC::low_level_input(int idx)
295
303
296
304
rx_buff[idx] = temp_rxbuf;
297
305
rx_ptr[idx] = (uint32_t *)memory_manager->get_ptr (rx_buff[idx]);
306
+ SCB_InvalidateDCache_by_Addr (rx_ptr[idx], ENET_ALIGN (ENET_ETH_MAX_FLEN, ENET_BUFF_ALIGNMENT));
298
307
299
308
update_read_buffer ((uint8_t *)rx_ptr[idx]);
300
309
}
@@ -399,6 +408,8 @@ bool Kinetis_EMAC::link_out(emac_mem_buf_t *buf)
399
408
buf = copy_buf;
400
409
}
401
410
411
+ SCB_CleanDCache_by_Addr (static_cast <uint32_t *>(memory_manager->get_ptr (buf)), memory_manager->get_len (buf));
412
+
402
413
/* Check if a descriptor is available for the transfer (wait 10ms before dropping the buffer) */
403
414
if (xTXDCountSem.wait (10 ) == 0 ) {
404
415
memory_manager->free (buf);
@@ -415,6 +426,8 @@ bool Kinetis_EMAC::link_out(emac_mem_buf_t *buf)
415
426
/* Setup transfers */
416
427
g_handle.txBdCurrent [0 ]->buffer = static_cast <uint8_t *>(memory_manager->get_ptr (buf));
417
428
g_handle.txBdCurrent [0 ]->length = memory_manager->get_len (buf);
429
+ /* Ensures buffer and length is written before control. */
430
+ __DMB ();
418
431
g_handle.txBdCurrent [0 ]->control |= (ENET_BUFFDESCRIPTOR_TX_READY_MASK | ENET_BUFFDESCRIPTOR_TX_LAST_MASK);
419
432
420
433
/* Increase the buffer descriptor address. */
@@ -424,6 +437,9 @@ bool Kinetis_EMAC::link_out(emac_mem_buf_t *buf)
424
437
g_handle.txBdCurrent [0 ]++;
425
438
}
426
439
440
+ /* Ensures descriptor is written before kicking hardware. */
441
+ __DSB ();
442
+
427
443
/* Active the transmit buffer descriptor. */
428
444
ENET->TDAR = ENET_TDAR_TDAR_MASK;
429
445
0 commit comments