From c464ab7e7cd43246c12185e19d7144021b04a8cb Mon Sep 17 00:00:00 2001 From: Jose Alamos Date: Tue, 15 Jun 2021 17:03:44 +0200 Subject: [PATCH 1/4] tests/ieee802154_hal: spin if radio is BUSY on trx_state request --- tests/ieee802154_hal/main.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/ieee802154_hal/main.c b/tests/ieee802154_hal/main.c index b5a06f2872..052dde514e 100644 --- a/tests/ieee802154_hal/main.c +++ b/tests/ieee802154_hal/main.c @@ -423,7 +423,14 @@ int _cca(int argc, char **argv) static inline void _set_trx_state(int state, bool verbose) { xtimer_ticks32_t a; - int res = ieee802154_radio_request_set_trx_state(&_radio[0], state); + int res; + + /* Under certain conditions (internal house-keeping or sending ACK frames + * back) the radio could indicate it's busy. Therefore, busy loop until + * the radio doesn't report BUSY + */ + while((res = ieee802154_radio_request_set_trx_state(&_radio[0], state)) == -EBUSY) {} + if (verbose) { a = xtimer_now(); if(res != 0) { From fd81b978fc4969cc516a01d0bebc47d78d2a0e7b Mon Sep 17 00:00:00 2001 From: Jose Alamos Date: Tue, 15 Jun 2021 17:04:18 +0200 Subject: [PATCH 2/4] tests/ieee802154_hal: use _set_trx_state where possible --- tests/ieee802154_hal/main.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tests/ieee802154_hal/main.c b/tests/ieee802154_hal/main.c index 052dde514e..40cbee090d 100644 --- a/tests/ieee802154_hal/main.c +++ b/tests/ieee802154_hal/main.c @@ -106,9 +106,10 @@ void _crc_error_handler(event_t *event) (void) event; puts("Packet with invalid CRC received"); ieee802154_dev_t* dev = &_radio[0]; - /* switch back to RX_ON state */ - ieee802154_radio_request_set_trx_state(dev, IEEE802154_TRX_STATE_RX_ON); - while (ieee802154_radio_confirm_set_trx_state(dev) == -EAGAIN) {} + if (!ieee802154_radio_has_rx_continuous(dev)) { + /* switch back to RX_ON state */ + _set_trx_state(IEEE802154_TRX_STATE_RX_ON, false); + } } static event_t _crc_error_event = { @@ -119,6 +120,7 @@ void _rx_done_handler(event_t *event) { (void) event; ieee802154_rx_info_t info; + ieee802154_dev_t* dev = &_radio[0]; /* Read packet from internal framebuffer * @@ -131,9 +133,10 @@ void _rx_done_handler(event_t *event) _print_packet(size, info.lqi, info.rssi); } - /* Go out of the HAL's FB Lock state after frame reception and trigger a - * state change */ - _set_trx_state(IEEE802154_TRX_STATE_RX_ON, false); + if (!ieee802154_radio_has_rx_continuous(dev)) { + /* switch back to RX_ON state */ + _set_trx_state(IEEE802154_TRX_STATE_RX_ON, false); + } } static event_t _rx_done_event = { From 0f14f826d1b45108d1d5fb73682b9cfe678df1b0 Mon Sep 17 00:00:00 2001 From: Jose Alamos Date: Tue, 15 Jun 2021 17:07:04 +0200 Subject: [PATCH 3/4] tests/ieee802154_hal: wait for IFS during transmission --- tests/ieee802154_hal/main.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/ieee802154_hal/main.c b/tests/ieee802154_hal/main.c index 40cbee090d..6ba798657b 100644 --- a/tests/ieee802154_hal/main.c +++ b/tests/ieee802154_hal/main.c @@ -216,9 +216,16 @@ static void _send(iolist_t *pkt) /* Block until the radio confirms the state change */ while(ieee802154_radio_confirm_set_trx_state(&_radio[0]) == -EAGAIN); - /* Trigger the transmit and wait for the mutex unlock (TX_DONE event) */ + /* Set the frame filter to receive ACKs */ ieee802154_radio_set_frame_filter_mode(&_radio[0], IEEE802154_FILTER_ACK_ONLY); - ieee802154_radio_request_transmit(&_radio[0]); + + /* Trigger the transmit and wait for the mutex unlock (TX_DONE event). + * Spin if the radio is busy before transmission (this indicates the + * transmission is requested before the end of the IFS). + * This won't be necessary anymore when the upper layers take care + * of the IFS. + */ + while (ieee802154_radio_request_transmit(&_radio[0]) == -EBUSY) {} mutex_lock(&lock); event_post(EVENT_PRIO_HIGHEST, &_tx_finish_ev); From 9089d224b85735c153b80513f9a74cd68895370a Mon Sep 17 00:00:00 2001 From: Jose Alamos Date: Tue, 15 Jun 2021 17:07:30 +0200 Subject: [PATCH 4/4] tests/ieee802154_hal: improve error reporting --- tests/ieee802154_hal/main.c | 52 +++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/tests/ieee802154_hal/main.c b/tests/ieee802154_hal/main.c index 6ba798657b..35dcf33b55 100644 --- a/tests/ieee802154_hal/main.c +++ b/tests/ieee802154_hal/main.c @@ -207,8 +207,11 @@ static event_t _tx_finish_ev = { static void _send(iolist_t *pkt) { - /* Request a state change to RX_ON */ - ieee802154_radio_request_set_trx_state(&_radio[0], IEEE802154_TRX_STATE_TX_ON); + /* Request a state change to TX_ON */ + if (ieee802154_radio_request_set_trx_state(&_radio[0], IEEE802154_TRX_STATE_TX_ON) < 0) { + puts("Couldn't send frame"); + return; + } /* Write the packet to the radio */ ieee802154_radio_write(&_radio[0], pkt); @@ -260,6 +263,7 @@ static ieee802154_dev_t *_reg_callback(ieee802154_dev_type_t type, void *opaque) static int _init(void) { + int res; struct _reg_container reg = {0}; ieee802154_hal_test_init_devs(_reg_callback, ®); @@ -274,32 +278,39 @@ static int _init(void) /* Since the device was already initialized, turn on the radio. * The transceiver state will be "TRX_OFF" */ - ieee802154_radio_request_on(&_radio[0]); + res = ieee802154_radio_request_on(&_radio[0]); + assert(res >= 0); while(ieee802154_radio_confirm_on(&_radio[0]) == -EAGAIN) {} ieee802154_radio_set_frame_filter_mode(&_radio[0], IEEE802154_FILTER_ACCEPT); uint16_t panid = CONFIG_IEEE802154_DEFAULT_PANID; + /* Set all IEEE addresses */ - ieee802154_radio_config_addr_filter(&_radio[0], + res = ieee802154_radio_config_addr_filter(&_radio[0], IEEE802154_AF_SHORT_ADDR, &short_addr); - ieee802154_radio_config_addr_filter(&_radio[0], + assert(res >= 0); + res = ieee802154_radio_config_addr_filter(&_radio[0], IEEE802154_AF_EXT_ADDR, &ext_addr); - ieee802154_radio_config_addr_filter(&_radio[0], + assert(res >= 0); + res = ieee802154_radio_config_addr_filter(&_radio[0], IEEE802154_AF_PANID, &panid); + assert(res >= 0); /* Set PHY configuration */ ieee802154_phy_conf_t conf = {.channel=CONFIG_IEEE802154_DEFAULT_CHANNEL, .page=CONFIG_IEEE802154_DEFAULT_SUBGHZ_PAGE, .pow=CONFIG_IEEE802154_DEFAULT_TXPOWER}; - ieee802154_radio_config_phy(&_radio[0], &conf); + res = ieee802154_radio_config_phy(&_radio[0], &conf); + assert(res >= 0); /* ieee802154_radio_set_cca_mode*/ - ieee802154_radio_set_cca_mode(&_radio[0], IEEE802154_CCA_MODE_ED_THRESHOLD); - ieee802154_radio_set_cca_threshold(&_radio[0], CONFIG_IEEE802154_CCA_THRESH_DEFAULT); + res = ieee802154_radio_set_cca_mode(&_radio[0], IEEE802154_CCA_MODE_ED_THRESHOLD); + assert(res >= 0); + res = ieee802154_radio_set_cca_threshold(&_radio[0], CONFIG_IEEE802154_CCA_THRESH_DEFAULT); + assert(res >= 0); /* Set the transceiver state to RX_ON in order to receive packets */ _set_trx_state(IEEE802154_TRX_STATE_RX_ON, false); - return 0; } @@ -415,7 +426,9 @@ int _cca(int argc, char **argv) { (void) argc; (void) argv; - ieee802154_radio_request_cca(&_radio[0]); + if (ieee802154_radio_request_cca(&_radio[0]) < 0) { + puts("Couldn't perform CCA"); + } mutex_lock(&lock); int res = ieee802154_radio_confirm_cca(&_radio[0]); assert(res >= 0); @@ -521,12 +534,12 @@ static int promisc(int argc, char **argv) puts("Disabled promiscuos mode"); } - ieee802154_radio_set_frame_filter_mode(&_radio[0], conf); - return 0; + return ieee802154_radio_set_frame_filter_mode(&_radio[0], conf); } int config_phy(int argc, char **argv) { + int res = -EINVAL; if (argc < 4) { puts("Usage: config_phy "); return 1; @@ -577,16 +590,18 @@ int config_phy(int argc, char **argv) } else { puts("Success!"); + res = 0; } _set_trx_state(IEEE802154_TRX_STATE_RX_ON, false); - return 0; + return res; } int txmode_cmd(int argc, char **argv) { ieee802154_dev_t *dev = &_radio[0]; + int res = -EINVAL; if (argc < 2) { printf("Usage: %s \n", argv[0]); @@ -611,13 +626,16 @@ int txmode_cmd(int argc, char **argv) } else { puts("Ok"); + res = 0; } - return 0; + return res; } static int _config_cca_cmd(int argc, char **argv) { ieee802154_dev_t *dev = &_radio[0]; + int res = -EINVAL; + ieee802154_cca_mode_t mode; if (argc < 2) { @@ -648,13 +666,13 @@ static int _config_cca_cmd(int argc, char **argv) int8_t thresh = atoi(argv[2]); if (ieee802154_radio_set_cca_threshold(dev, thresh) < 0) { puts("Error setting the threshold"); - return 1; } else { printf("Set threshold to %i\n", thresh); + res = 0; } } - return 0; + return res; } static int _caps_cmd(int argc, char **argv)