Skip to content

Commit 9daf450

Browse files
committed
K64F Ethernet: avoid using NULL thread during init
The K64F Ethernet driver installs an interrupt handler that sets thread flags, and this could be called before the thread was initialised, so it would use a NULL thread ID. This triggers an RTX error-checking trap in debug builds, and could also lead to other problems with received packets not being processed. Adjusted so the RX interrupt handler does nothing if the thread isn't initialised yet, and manually trigger a RX event flag after initialising the thread in case any interrupts were ignored. An alternative would have been to implement eth_arch_enable_interrupts, but this mechanism is not present in the EMAC world - drivers will have to start returning interrupts in their power up. Fixes #5680
1 parent a7aaee3 commit 9daf450

File tree

1 file changed

+6
-1
lines changed
  • features/FEATURE_LWIP/lwip-interface/lwip-eth/arch/TARGET_Freescale

1 file changed

+6
-1
lines changed

features/FEATURE_LWIP/lwip-interface/lwip-eth/arch/TARGET_Freescale/k64f_emac.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@ static void k64f_tx_reclaim(struct k64f_enetdata *k64f_enet)
140140
*/
141141
void enet_mac_rx_isr()
142142
{
143-
osThreadFlagsSet(k64f_enetdata.thread, FLAG_RX);
143+
if (k64f_enetdata.thread) {
144+
osThreadFlagsSet(k64f_enetdata.thread, FLAG_RX);
145+
}
144146
}
145147

146148
void enet_mac_tx_isr()
@@ -756,6 +758,9 @@ err_t eth_arch_enetif_init(struct netif *netif)
756758
/* Worker thread */
757759
k64f_enetdata.thread = sys_thread_new("k64f_emac_thread", emac_thread, netif->state, THREAD_STACKSIZE, THREAD_PRIORITY)->id;
758760

761+
/* Trigger thread to deal with any RX packets that arrived before thread was started */
762+
enet_mac_rx_isr();
763+
759764
return ERR_OK;
760765
}
761766

0 commit comments

Comments
 (0)