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

sys/net/gnrc: Remove code duplication #16502

Merged
merged 2 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
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
48 changes: 1 addition & 47 deletions sys/net/gnrc/link_layer/gomach/gomach.c
Original file line number Diff line number Diff line change
Expand Up @@ -1788,53 +1788,7 @@
/* 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)
Expand Down Expand Up @@ -2214,4 +2168,4 @@
}

return 0;
}

Check warning on line 2171 in sys/net/gnrc/link_layer/gomach/gomach.c

View workflow job for this annotation

GitHub Actions / static-tests

source file is too long
48 changes: 16 additions & 32 deletions sys/net/gnrc/link_layer/lwmac/lwmac.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,13 +345,13 @@
}
/* Trying to send data */
case GNRC_LWMAC_TRANSMITTING: {
rtt_handler(GNRC_LWMAC_EVENT_RTT_PAUSE, netif); /**< No duty cycling while RXing */

Check warning on line 348 in sys/net/gnrc/link_layer/lwmac/lwmac.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
_gnrc_lwmac_set_netdev_state(netif, NETOPT_STATE_IDLE); /**< Power up netdev */
break;
}
/* Receiving incoming data */
case GNRC_LWMAC_RECEIVING: {
rtt_handler(GNRC_LWMAC_EVENT_RTT_PAUSE, netif); /**< No duty cycling while TXing */

Check warning on line 354 in sys/net/gnrc/link_layer/lwmac/lwmac.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
_gnrc_lwmac_set_netdev_state(netif, NETOPT_STATE_IDLE); /**< Power up netdev */
break;
}
Expand Down Expand Up @@ -421,7 +421,7 @@

/* Offset in microseconds when the earliest (phase) destination
* node wakes up that we have packets for. */
uint32_t time_until_tx = RTT_TICKS_TO_US(_gnrc_lwmac_ticks_until_phase(neighbour->phase));

Check warning on line 424 in sys/net/gnrc/link_layer/lwmac/lwmac.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters

/* If there's not enough time to prepare a WR to catch the phase
* postpone to next interval */
Expand Down Expand Up @@ -457,17 +457,8 @@
}
}

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();
Expand All @@ -492,35 +483,28 @@
}
}

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");
gnrc_lwmac_rx_stop(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)
Expand Down Expand Up @@ -649,7 +633,7 @@
/* Set timeout for if there's no successful rx transaction that will
* change state to SLEEPING. */
if (!gnrc_lwmac_timeout_is_running(netif, GNRC_LWMAC_TIMEOUT_WAKEUP_PERIOD)) {
gnrc_lwmac_set_timeout(netif, GNRC_LWMAC_TIMEOUT_WAKEUP_PERIOD, GNRC_LWMAC_WAKEUP_DURATION_US);

Check warning on line 636 in sys/net/gnrc/link_layer/lwmac/lwmac.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
}
else if (gnrc_lwmac_timeout_is_expired(netif, GNRC_LWMAC_TIMEOUT_WAKEUP_PERIOD)) {
/* Dispatch first as there still may be broadcast packets. */
Expand Down
Loading