Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: call effective ETH scheduler only from Timer callback #60

Merged
merged 1 commit into from
Mar 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions src/utility/stm32_eth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ static uint32_t gEhtLinkTickStart = 0;
#if !defined(STM32_CORE_VERSION) || (STM32_CORE_VERSION <= 0x01060100)
/* Handler for stimer */
static stimer_t TimHandle;
#else
HardwareTimer *EthTim = NULL;
#endif

/*************************** Function prototype *******************************/
Expand All @@ -103,6 +105,9 @@ static err_t tcp_recv_callback(void *arg, struct tcp_pcb *tpcb, struct pbuf *p,
static err_t tcp_sent_callback(void *arg, struct tcp_pcb *tpcb, u16_t len);
static void tcp_err_callback(void *arg, err_t err);
static void TIM_scheduler_Config(void);
#if defined(STM32_CORE_VERSION) && (STM32_CORE_VERSION > 0x01060100)
void _stm32_eth_scheduler(void);
#endif

/**
* @brief Configurates the network interface
Expand Down Expand Up @@ -148,7 +153,7 @@ static void Netif_Config(void)
#if (STM32_CORE_VERSION <= 0x01080000)
UNUSED(htim);
#endif
stm32_eth_scheduler();
_stm32_eth_scheduler();
}

#if !defined(STM32_CORE_VERSION) || (STM32_CORE_VERSION <= 0x01060100)
Expand Down Expand Up @@ -176,7 +181,7 @@ static void TIM_scheduler_Config(void)
static void TIM_scheduler_Config(void)
{
/* Configure HardwareTimer */
HardwareTimer *EthTim = new HardwareTimer(DEFAULT_ETHERNET_TIMER);
EthTim = new HardwareTimer(DEFAULT_ETHERNET_TIMER);
EthTim->setMode(1, TIMER_OUTPUT_COMPARE);

/* Timer set to 1ms */
Expand Down Expand Up @@ -265,12 +270,33 @@ uint8_t stm32_eth_link_up(void)
return netif_is_link_up(&gnetif);
}

#if defined(STM32_CORE_VERSION) && (STM32_CORE_VERSION > 0x01060100)
/**
* @brief This function generates Timer Update event to force call to _stm32_eth_scheduler().
* @param None
* @retval None
*/
void stm32_eth_scheduler(void)
{
if (EthTim != NULL) {
EthTim->refresh();
}
}

/**
* @brief This function must be called in main loop in standalone mode.
* @brief This function is called solely by Timer callback to avoid race condition.
* @param None
* @retval None
*/
void _stm32_eth_scheduler(void)
#else
/**
* @brief This function is called solely by Timer callback to avoid race condition.
* @param None
* @retval None
*/
void stm32_eth_scheduler(void)
#endif
{
/* Read a received packet from the Ethernet buffers and send it
to the lwIP for handling */
Expand Down