1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/drivers
Benjamin Valentin 8c6791b136 drivers/at86rf215: return error when switching state while busy
Previously the function attempted to block here and manually service
the ISR.
This lead to unexpected results, in particular messages queuing up in
the threads message queue.

The result was that the radio would not end up in the correct state.
E.g. sending SLEEP to both interfaces while a transmission was ongoing
would lead to the interfaces waking up again.

With this patch the operation will just return -ERRNO so the caller can
try again.

To reproduce, try the attached patch for the `gnrc_networking` example:

On master you will find that the radio still consumes ~2.4mA after 'shutdown'.
(It is in fact in the state TRXOFF as it woke up again)
With this change the radio should consume less than 1µA (DEEP SLEEP).

diff --git a/examples/gnrc_networking/main.c b/examples/gnrc_networking/main.c
index 6301f4291d..93b96eb939 100644
--- a/examples/gnrc_networking/main.c
+++ b/examples/gnrc_networking/main.c
@@ -23,12 +23,47 @@
 #include "shell.h"
 #include "msg.h"

+#include "periph/pm.h"
+
+#include "net/netopt.h"
+#include "net/gnrc/netif.h"
+
 #define MAIN_QUEUE_SIZE     (8)
 static msg_t _main_msg_queue[MAIN_QUEUE_SIZE];

 extern int udp_cmd(int argc, char **argv);

+extern void send(char *addr_str, char *port_str, char *data, unsigned int num,
+                 unsigned int delay);
+
+static int send_and_shutdown(int argc, char **argv)
+{
+    (void) argc;
+    (void) argv;
+
+    /* the address must not exist */
+    char addr[] = "fe80::2068:3123:59f5:d238%7";
+    char port[] = "1234";
+    char data[] = "Hello World!";
+
+    send(addr, port, data, 1, 0);
+
+    /* disable radio */
+    gnrc_netif_t* netif = NULL;
+    netopt_state_t state = NETOPT_STATE_SLEEP;
+    while ((netif = gnrc_netif_iter(netif))) {
+        /* retry while busy */
+        while (gnrc_netapi_set(netif->pid, NETOPT_STATE, 0, &state,
+               sizeof(netopt_state_t)) == -EBUSY);
+    }
+
+    pm_set(0);
+
+    return 0;
+}
+
 static const shell_command_t shell_commands[] = {
+    { "shutdown", "turn off the radio & shut down", send_and_shutdown },
     { "udp", "send data over UDP and listen on UDP ports", udp_cmd },
     { NULL, NULL, NULL }
 };
diff --git a/examples/gnrc_networking/udp.c b/examples/gnrc_networking/udp.c
index e8a559846e..cb80855b76 100644
--- a/examples/gnrc_networking/udp.c
+++ b/examples/gnrc_networking/udp.c
@@ -36,7 +36,7 @@ static gnrc_netreg_entry_t server = GNRC_NETREG_ENTRY_INIT_PID(GNRC_NETREG_DEMUX
                                                                KERNEL_PID_UNDEF);

-static void send(char *addr_str, char *port_str, char *data, unsigned int num,
+void send(char *addr_str, char *port_str, char *data, unsigned int num,
                  unsigned int delay)
 {
     gnrc_netif_t *netif = NULL;
2020-04-01 23:08:44 +02:00
..
ad7746 many typo fixes 2019-11-23 22:39:07 +01:00
adcxx1c drivers/adcxx1c: fix typos 2019-11-23 22:39:39 +01:00
ads101x drivers/ads101x: fix typos 2019-11-23 22:39:39 +01:00
adt7310 drivers/adt7310: Replace binary representation 2019-04-25 21:18:36 +02:00
adxl345 drivers/adxk345: include copy of params in dev struct 2019-01-06 17:24:24 +01:00
apa102 drivers/apa102: fix typos 2019-11-23 22:39:39 +01:00
apds99xx drivers/apd99xx: fix wait long initialization 2020-03-19 10:26:30 +01:00
at driver/at: add return code for CME/CMS errors 2019-06-25 09:59:27 +02:00
at24cxxx drivers/at24cxxx: at24cxxx EEPROM driver 2020-02-24 14:00:25 +01:00
at24mac drivers/at24mac: include kernel_defines.h 2020-02-26 23:41:38 +01:00
at30tse75x
at86rf2xx drivers/netdev: use netdev_trigger_event_isr function 2020-03-06 14:03:43 +01:00
at86rf215 drivers/at86rf215: return error when switching state while busy 2020-04-01 23:08:44 +02:00
ata8520e drivers/ata8520e: fix potentially unused variables 2019-10-22 19:19:36 +02:00
bh1750fvi drivers/bh1750fvi: fix typos 2019-11-23 22:39:39 +01:00
bh1900nux Add bh1900nux driver 2020-02-12 07:34:22 +01:00
bme680 drivers/bme680: add SAUL capabilities 2020-03-12 08:52:10 +01:00
bmp180 drivers/bmp180: fix potentially use of uninitialized variable 2019-10-22 19:30:12 +02:00
bmx055 drivers/bmx055: fix typos 2019-11-23 22:39:39 +01:00
bmx280 drivers/bmx280: provide correct CALIB_T_P_LEN 2020-02-24 15:21:06 +01:00
can_trx
cc1xxx_common gnrc_netif_xxx_create: use external netif allocation 2020-03-26 11:12:23 +01:00
cc110x drivers/cc110x: Handle lost IRQs more gracefully 2020-03-08 12:49:57 +01:00
cc2420 drivers/netdev: use netdev_trigger_event_isr function 2020-03-06 14:03:43 +01:00
ccs811 drivers/ccs811: fix broken links 2020-03-24 10:38:40 +01:00
dcf77 Drivers/DCF77:First implementation 2019-11-22 10:27:01 +01:00
dht drivers/dht: Fixed magic numbers & missing doc 2019-07-29 10:39:50 +02:00
disp_dev sys: add interface for generic display device 2020-03-03 10:25:54 +01:00
dose drivers/dose: fix declaration of signal() 2020-03-23 20:35:54 +01:00
ds18 drivers/ds18: fix doxygen group of ds18_internal.h 2020-02-27 17:43:53 +01:00
ds75lx drivers: sys: add SAUL support for ds75lx sensor 2019-05-22 16:54:20 +02:00
ds1307
ds3234 drivers/ds3234: Minimal driver for DS3234 extremely accurate RTC 2019-02-19 11:57:40 +01:00
dsp0401 boards/nucleo-f411re: rename to marketing name 2018-05-22 21:52:41 +02:00
dynamixel drivers/dynamixel: fix typos 2019-11-23 22:39:39 +01:00
enc28j60 drivers/netdev: use netdev_trigger_event_isr function 2020-03-06 14:03:43 +01:00
encx24j600 drivers/netdev: use netdev_trigger_event_isr function 2020-03-06 14:03:43 +01:00
ethos drivers/netdev: use netdev_trigger_event_isr function 2020-03-06 14:03:43 +01:00
feetech drivers/feetech: fix typos 2019-11-23 22:39:39 +01:00
fxos8700
grove_ledbar
hd44780 Revert "drivers/hd44780: add short delay after each character" 2019-11-07 22:40:01 +01:00
hdc1000 drivers/hdc1000: do normal assignment instead of memcpy 2019-01-10 19:43:44 +01:00
hih6130
hts221 drivers/hts211: fix CTRL_REG2_OS_EN 2019-02-14 18:03:35 +01:00
ili9341 drivers/ili9341: provide adaption to disp_dev interface 2020-03-03 10:25:55 +01:00
ina2xx drivers/ina2xx: Fixed missing i2c_acquire/release 2020-02-10 10:32:27 +01:00
ina3221 drivers/ina3221: Added SAUL integration 2019-11-05 12:37:41 +01:00
include Merge pull request #13766 from akshaim/at_CT_Config 2020-03-31 21:51:44 +02:00
io1_xplained
isl29020 drivers: replace memset by simple assignments 2019-01-07 21:59:25 +01:00
isl29125
itg320x drivers/itg320x: remove not needed MODULE variable 2020-01-11 18:09:13 +01:00
jc42
kw2xrf drivers/netdev: use netdev_trigger_event_isr function 2020-03-06 14:03:43 +01:00
kw41zrf drivers/kw41zrf: Transceiver driver for the KW41Z radio 2020-03-19 17:00:04 -05:00
l3g4200d
lc709203f
lis2dh12 drivers/lis2dh12: added interrupt function 2020-03-04 17:01:58 +01:00
lis3dh
lis3mdl many typo fixes 2019-11-23 22:39:07 +01:00
lpd8808 drivers/lpd8808: do normal assignment instead of memcpy 2019-01-10 19:43:44 +01:00
lpsxxx drivers/lpsxxx: fix typos 2019-11-23 22:39:39 +01:00
lsm6dsl drivers/lsm6dsl: fix typos 2019-11-23 22:39:39 +01:00
lsm303dlhc drivers/lsm303dlhc: correct cast of phydat_t* 2019-01-06 17:08:04 +01:00
ltc4150 drivers: make use of ARRAY_SIZE macro 2019-08-06 19:43:54 +02:00
mag3110 drivers/mag3110: do normal assignment instead of memcpy 2019-01-10 19:43:44 +01:00
mma8x5x drivers/mma8x5x: do normal assignment instead of memcpy 2019-01-10 19:43:44 +01:00
mma7660 drivers/mma7660: do normal assignment instead of memcpy 2019-01-10 19:43:44 +01:00
motor_driver drivers: add licence to motor_driver source files 2019-04-13 00:29:58 +02:00
mpl3115a2 drivers/mpl3115a2: do normal assignment instead of memcpy 2019-01-10 19:43:44 +01:00
mpu9x50 drivers/mpu9x50: Fix prameter placement for docs 2020-01-13 12:50:13 +01:00
mq3
mrf24j40 drivers/netdev: use netdev_trigger_event_isr function 2020-03-06 14:03:43 +01:00
mtd
mtd_flashpage drivers/mtd_flashpage: add 16bit compatibility 2019-11-24 13:19:19 +01:00
mtd_mapper drivers/mtd_mapper: fix NDEBUG compile problem 2020-03-12 18:04:42 +01:00
mtd_sdcard
mtd_spi_nor mtd_spi_nor: Add wait timings to parameters 2020-03-03 09:49:00 +01:00
my9221 drivers/my9221: do normal assignment instead of memcpy 2019-01-10 19:43:44 +01:00
ncv7356 ncv7356: add driver for ncv7356 SW CAN transceiver 2019-08-21 11:05:51 +02:00
netdev_eth drivers/netdev_eth: Use NETOPT_MAX_DPU_SIZE 2019-02-18 20:18:56 +01:00
netdev_ieee802154 drivers/netdev_ieee802154: add mac header filter 2019-03-04 13:21:43 +01:00
netdev_layer
nrf24l01p many typo fixes 2019-11-23 22:39:07 +01:00
nvram
nvram_spi
opt3001 drivers/opt3001: fix typos 2019-11-23 22:39:39 +01:00
pca9685 drivers/pca9685: fix typos 2019-11-23 22:39:39 +01:00
pcd8544 drivers/pcd8544: fix typos 2019-11-23 22:39:39 +01:00
periph_common drivers/wdt: Expose configuration to Kconfig 2020-03-31 13:39:38 +02:00
ph_oem drivers/ph_oem: fix typos 2019-11-23 22:39:39 +01:00
pir drivers: replace memset by simple assignments 2019-01-07 21:59:25 +01:00
pn532
pulse_counter drivers/pulse_counter: refactor the prototypes of read funcs 2019-01-09 23:06:54 +01:00
qmc5883l drivers: add support for QMC5883L mag sensors 2019-11-13 12:56:26 +01:00
rgbled
rn2xx3 drivers/netdev: use netdev_trigger_event_isr function 2020-03-06 14:03:43 +01:00
rtt_rtc rtt_rtc: add RTT based RTC implementation 2020-03-19 15:25:14 +01:00
saul drivers/saul: add auto_init for BME680 2020-03-12 08:52:10 +01:00
sdcard_spi drivers/sdcard_spi: fix broken links 2020-03-24 10:38:40 +01:00
sds011 drivers/sds011: Fix SAUL read error return 2019-01-31 15:35:19 +01:00
servo
sht1x drivers: make use of ARRAY_SIZE macro 2019-08-06 19:43:54 +02:00
sht2x drivers: make use of ARRAY_SIZE macro 2019-08-06 19:43:54 +02:00
sht3x drivers/sht3x: fix broken links 2020-03-24 10:38:40 +01:00
shtc1 Driver/shtc1: add saul integration 2019-12-16 15:29:04 +01:00
si70xx drivers/si70xx: do normal assignment instead of memcpy 2019-01-10 19:43:44 +01:00
si114x
slipdev drivers/netdev: use netdev_trigger_event_isr function 2020-03-06 14:03:43 +01:00
soft_spi drivers: make use of ARRAY_SIZE macro 2019-08-06 19:43:54 +02:00
sps30 drivers/sps30: add saul integration 2020-02-20 14:26:55 +01:00
srf02
srf04 drivers: make use of ARRAY_SIZE macro 2019-08-06 19:43:54 +02:00
srf08 drivers/srf08: refactor driver configuration 2020-02-25 21:24:02 +01:00
stm32_eth drivers/netdev: use netdev_trigger_event_isr function 2020-03-06 14:03:43 +01:00
stmpe811 drivers/stmpe811: add implementation 2020-02-13 09:14:51 +01:00
sx127x drivers/sx127x: fix length check of netstat_opt_tin _set 2020-03-08 17:10:46 +01:00
tcs37727 drivers/tcs37727: do normal assignment instead of memcpy 2019-01-10 19:43:44 +01:00
tja1042
tmp00x drivers/tmp00x: cleanup return codes 2019-11-08 22:17:44 +01:00
tps6274x drivers: Initial support for TPS6274x converter 2019-01-10 00:00:02 +01:00
tsl2561
tsl4531x sys/auto_init: Changes to support SAUL 2018-10-23 17:26:28 +02:00
uart_half_duplex many typo fixes 2019-11-23 22:39:07 +01:00
vcnl40x0 drivers/vcnl40x0: initial implementation 2018-10-15 11:44:10 +02:00
veml6070
w5100 drivers/netdev: use netdev_trigger_event_isr function 2020-03-06 14:03:43 +01:00
ws281x drivers/ws281x: Add ESP32 support 2020-03-25 17:25:35 +01:00
xbee gnrc_netif: document new *_create() out parameter as such 2020-03-26 14:37:44 +01:00
doc.txt doc: create a category for miscellaneous drivers 2020-02-27 08:43:21 +01:00
Kconfig drivers/wdt: Expose configuration to Kconfig 2020-03-31 13:39:38 +02:00
Kconfig.net Kconfig: Expose NRF802154 configurations 2020-01-21 11:29:00 +01:00
Makefile sys/auto_init: allow delayed initialisation of SAUL 2020-03-04 16:13:40 +01:00
Makefile.dep drivers/ws281x: Add ESP32 support 2020-03-25 17:25:35 +01:00
Makefile.include Merge pull request #13583 from benpicco/at86rf215-minimal 2020-03-20 09:33:50 +01:00