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

Merge pull request #16502 from francois-berder/remove-code-duplication

sys/net/gnrc: Remove code duplication
This commit is contained in:
Martine Lenders 2024-03-26 16:01:42 +00:00 committed by GitHub
commit 4059244388
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 79 deletions

View File

@ -1788,53 +1788,7 @@ static void gomach_vtdma_end(gnrc_netif_t *netif)
/* Switch the radio to the public-channel. */
gnrc_gomach_turn_channel(netif, netif->mac.prot.gomach.cur_pub_channel);
/* Check if there is packet to send. */
if (gnrc_gomach_find_next_tx_neighbor(netif)) {
if (netif->mac.tx.current_neighbor == &netif->mac.tx.neighbors[0]) {
/* The packet is for broadcasting. */
if (!gnrc_gomach_get_unintd_preamble(netif)) {
netif->mac.prot.gomach.basic_state = GNRC_GOMACH_TRANSMIT;
netif->mac.tx.transmit_state = GNRC_GOMACH_BROADCAST;
}
else {
netif->mac.rx.listen_state = GNRC_GOMACH_LISTEN_SLEEP_INIT;
}
}
else {
switch (netif->mac.tx.current_neighbor->mac_type) {
/* The packet waiting to be sent is for unicast. */
case GNRC_GOMACH_TYPE_UNKNOWN: {
/* The neighbor's phase is unknown yet, try to run t2u (transmission
* to unknown device) procedure to phase-lock the neighbor. */
if (!gnrc_gomach_get_unintd_preamble(netif)) {
netif->mac.prot.gomach.basic_state = GNRC_GOMACH_TRANSMIT;
netif->mac.tx.transmit_state = GNRC_GOMACH_TRANS_TO_UNKNOWN;
}
else {
netif->mac.rx.listen_state = GNRC_GOMACH_LISTEN_SLEEP_INIT;
}
} break;
case GNRC_GOMACH_TYPE_KNOWN: {
/* If the neighbor's phase is known, go to t2k (transmission
* to known device) procedure. Here, we don't worry that the t2k
* unicast transmission will interrupt with possible ongoing
* preamble transmissions of other devices. */
netif->mac.prot.gomach.basic_state = GNRC_GOMACH_TRANSMIT;
netif->mac.tx.transmit_state = GNRC_GOMACH_TRANS_TO_KNOWN;
} break;
default: {
LOG_ERROR("ERROR: [GOMACH] vTDMA: unknown MAC type of the neighbor.\n");
break;
}
}
}
}
else {
/* No packet to send, go to sleep. */
netif->mac.rx.listen_state = GNRC_GOMACH_LISTEN_SLEEP_INIT;
}
gnrc_gomach_set_update(netif, true);
_no_vtdma_after_cp(netif);
}
static void gomach_sleep_init(gnrc_netif_t *netif)

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)