1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

gnrc/lwmac: Reduce code duplication

Both _rx_management_failed and _rx_management_success functions
attempt to sleep after handling the packet reception
failure/success. This commit extracts the sleep attempt in a
new _rx_management_attempt_sleep function.

Signed-off-by: Francois Berder <fberder@outlook.fr>
This commit is contained in:
Francois Berder 2021-05-26 16:50:19 +02:00 committed by Martine Lenders
parent b424711554
commit 7523bb08a3

View File

@ -457,17 +457,8 @@ static void _sleep_management(gnrc_netif_t *netif)
}
}
static void _rx_management_failed(gnrc_netif_t *netif)
static void _rx_management_attempt_sleep(gnrc_netif_t *netif)
{
/* This may happen frequently because we'll receive WA from
* every node in range. */
LOG_DEBUG("[LWMAC] Reception was NOT successful\n");
gnrc_lwmac_rx_stop(netif);
if (netif->mac.rx.rx_bad_exten_count >= CONFIG_GNRC_LWMAC_MAX_RX_EXTENSION_NUM) {
gnrc_lwmac_set_quit_rx(netif, true);
}
/* Here we check if we are close to the end of the cycle. If yes,
* go to sleep. Firstly, get the relative phase. */
uint32_t phase = rtt_get_counter();
@ -492,6 +483,20 @@ static void _rx_management_failed(gnrc_netif_t *netif)
}
}
static void _rx_management_failed(gnrc_netif_t *netif)
{
/* This may happen frequently because we'll receive WA from
* every node in range. */
LOG_DEBUG("[LWMAC] Reception was NOT successful\n");
gnrc_lwmac_rx_stop(netif);
if (netif->mac.rx.rx_bad_exten_count >= CONFIG_GNRC_LWMAC_MAX_RX_EXTENSION_NUM) {
gnrc_lwmac_set_quit_rx(netif, true);
}
_rx_management_attempt_sleep(netif);
}
static void _rx_management_success(gnrc_netif_t *netif)
{
LOG_DEBUG("[LWMAC] Reception was successful\n");
@ -499,28 +504,7 @@ static void _rx_management_success(gnrc_netif_t *netif)
/* Dispatch received packets, timing is not critical anymore */
gnrc_mac_dispatch(&netif->mac.rx);
/* Here we check if we are close to the end of the cycle. If yes,
* go to sleep. Firstly, get the relative phase. */
uint32_t phase = rtt_get_counter();
if (phase < netif->mac.prot.lwmac.last_wakeup) {
phase = (RTT_US_TO_TICKS(GNRC_LWMAC_PHASE_MAX) - netif->mac.prot.lwmac.last_wakeup) +
phase;
}
else {
phase = phase - netif->mac.prot.lwmac.last_wakeup;
}
/* If the relative phase is beyond 4/5 cycle time, go to sleep. */
if (phase > (4 * RTT_US_TO_TICKS(CONFIG_GNRC_LWMAC_WAKEUP_INTERVAL_US) / 5)) {
gnrc_lwmac_set_quit_rx(netif, true);
}
if (gnrc_lwmac_get_quit_rx(netif)) {
lwmac_set_state(netif, GNRC_LWMAC_SLEEPING);
}
else {
/* Go back to LISTENING after successful reception */
lwmac_set_state(netif, GNRC_LWMAC_LISTENING);
}
_rx_management_attempt_sleep(netif);
}
static void _rx_management(gnrc_netif_t *netif)