[riot-commits] [RIOT-OS/RIOT] 8c6791: drivers/at86rf215: return error when switching sta...

benpicco noreply at github.com
Fri Apr 3 17:50:50 CEST 2020


  Branch: refs/heads/master
  Home:   https://github.com/RIOT-OS/RIOT
  Commit: 8c6791b136b69bdf109108017426746ba5032bd6
      https://github.com/RIOT-OS/RIOT/commit/8c6791b136b69bdf109108017426746ba5032bd6
  Author: Benjamin Valentin <benpicco at googlemail.com>
  Date:   2020-04-01 (Wed, 01 Apr 2020)

  Changed paths:
    M drivers/at86rf215/at86rf215_netdev.c

  Log Message:
  -----------
  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;


  Commit: 5ed88ecb0ad5aff651495e4c9905d5c394976820
      https://github.com/RIOT-OS/RIOT/commit/5ed88ecb0ad5aff651495e4c9905d5c394976820
  Author: Benjamin Valentin <benpicco at googlemail.com>
  Date:   2020-04-01 (Wed, 01 Apr 2020)

  Changed paths:
    M drivers/at86rf215/at86rf215.c
    M drivers/at86rf215/include/at86rf215_internal.h

  Log Message:
  -----------
  drivers/at86rf215: unexport at86rf215_block_while_busy()

It's a private function that should not be used lightly.


  Commit: 46544c5d7a1d6f8f674065380c48b3daf83a2dd1
      https://github.com/RIOT-OS/RIOT/commit/46544c5d7a1d6f8f674065380c48b3daf83a2dd1
  Author: Benjamin Valentin <benpicco at googlemail.com>
  Date:   2020-04-03 (Fri, 03 Apr 2020)

  Changed paths:
    M drivers/at86rf215/at86rf215.c

  Log Message:
  -----------
  drivers/at86rf215: add comment to _tx_ongoing()


  Commit: 750db2a910aed53a568dbc76503f7a70fb4f5eaa
      https://github.com/RIOT-OS/RIOT/commit/750db2a910aed53a568dbc76503f7a70fb4f5eaa
  Author: benpicco <benjamin.valentin at ml-pa.com>
  Date:   2020-04-03 (Fri, 03 Apr 2020)

  Changed paths:
    M drivers/at86rf215/at86rf215.c
    M drivers/at86rf215/at86rf215_netdev.c
    M drivers/at86rf215/include/at86rf215_internal.h

  Log Message:
  -----------
  Merge pull request #13788 from benpicco/drivers/at86rf215_shutdown_fix

drivers/at86rf215: return error when switching state while busy


Compare: https://github.com/RIOT-OS/RIOT/compare/4534e9b77338...750db2a910ae


More information about the commits mailing list