Merge pull request #16922 from jia200x/pr/netdev/signal_netdev_register
netdev: add netdev_register_signal
This commit is contained in:
commit
b4de70e9d8
@ -331,6 +331,14 @@ typedef enum {
|
||||
*/
|
||||
#define NETDEV_INDEX_ANY (0xFF)
|
||||
|
||||
#if DOXYGEN
|
||||
/**
|
||||
* @brief Call @ref netdev_register_signal when the netdev device is
|
||||
* registered.
|
||||
*/
|
||||
#define CONFIG_NETDEV_REGISTER_SIGNAL 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Structure to hold driver state
|
||||
*
|
||||
@ -356,6 +364,21 @@ struct netdev {
|
||||
#endif
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Signal that the @ref netdev_register function registered the device.
|
||||
*
|
||||
* This function is called right after @ref netdev_register registered
|
||||
* the device.
|
||||
*
|
||||
* @note This function is called only if the CFLAG @ref
|
||||
* CONFIG_NETDEV_REGISTER_SIGNAL is set.
|
||||
*
|
||||
* @param[in] dev pointer to the device descriptor
|
||||
* @param[in] type the driver used for the netdev
|
||||
* @param[in] index the index in the config struct
|
||||
*/
|
||||
void netdev_register_signal(struct netdev *dev, netdev_type_t type, uint8_t index);
|
||||
|
||||
/**
|
||||
* @brief Register a device with netdev.
|
||||
* Must by called by the driver's setup function.
|
||||
@ -374,6 +397,10 @@ static inline void netdev_register(struct netdev *dev, netdev_type_t type, uint8
|
||||
(void) type;
|
||||
(void) index;
|
||||
#endif
|
||||
|
||||
if (IS_ACTIVE(CONFIG_NETDEV_REGISTER_SIGNAL)) {
|
||||
netdev_register_signal(dev, type, index);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -5,4 +5,6 @@ USEMODULE += at86rf215
|
||||
USEMODULE += at86rf215_batmon
|
||||
USEMODULE += at86rf215_timestamp
|
||||
|
||||
CFLAGS += -DCONFIG_NETDEV_REGISTER_SIGNAL
|
||||
|
||||
include ../driver_netdev_common/Makefile.netdev.mk
|
||||
|
||||
@ -32,6 +32,18 @@
|
||||
#include "od.h"
|
||||
|
||||
static char batmon_stack[THREAD_STACKSIZE_MAIN];
|
||||
static at86rf215_t *dev;
|
||||
|
||||
void netdev_register_signal(netdev_t *netdev, netdev_type_t type, uint8_t index)
|
||||
{
|
||||
(void) index;
|
||||
netdev_ieee802154_t *netdev_ieee802154 = container_of(netdev,
|
||||
netdev_ieee802154_t,
|
||||
netdev);
|
||||
if (type == NETDEV_AT86RF215 && !dev) {
|
||||
dev = container_of(netdev_ieee802154, at86rf215_t, netdev);
|
||||
}
|
||||
}
|
||||
|
||||
void *batmon_thread(void *arg)
|
||||
{
|
||||
@ -91,19 +103,11 @@ static int cmd_set_trim(int argc, char **argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
gnrc_netif_t *netif = gnrc_netif_get_by_type(NETDEV_AT86RF215, 0);
|
||||
|
||||
if (netif == NULL) {
|
||||
if (dev == NULL) {
|
||||
puts("No at86rf215 radio found");
|
||||
return 1;
|
||||
}
|
||||
|
||||
netdev_t *netdev = netif->dev;
|
||||
netdev_ieee802154_t *netdev_ieee802154 = container_of(netdev,
|
||||
netdev_ieee802154_t,
|
||||
netdev);
|
||||
at86rf215_t* dev = container_of(netdev_ieee802154, at86rf215_t, netdev);
|
||||
|
||||
printf("setting trim to %u fF\n", 300U * trim);
|
||||
at86rf215_set_trim(dev, trim);
|
||||
|
||||
@ -147,19 +151,11 @@ static int cmd_set_clock_out(int argc, char **argv)
|
||||
freq = tmp;
|
||||
}
|
||||
|
||||
gnrc_netif_t *netif = gnrc_netif_get_by_type(NETDEV_AT86RF215, 0);
|
||||
|
||||
if (netif == NULL) {
|
||||
if (dev == NULL) {
|
||||
puts("No at86rf215 radio found");
|
||||
return 1;
|
||||
}
|
||||
|
||||
netdev_t *netdev = netif->dev;
|
||||
netdev_ieee802154_t *netdev_ieee802154 = container_of(netdev,
|
||||
netdev_ieee802154_t,
|
||||
netdev);
|
||||
at86rf215_t* dev = container_of(netdev_ieee802154, at86rf215_t, netdev);
|
||||
|
||||
printf("Clock output set to %s %s\n", keys[freq], freq ? "MHz" : "");
|
||||
at86rf215_set_clock_output(dev, AT86RF215_CLKO_4mA, freq);
|
||||
|
||||
@ -183,19 +179,11 @@ static int cmd_get_random(int argc, char **argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
gnrc_netif_t *netif = gnrc_netif_get_by_type(NETDEV_AT86RF215, 0);
|
||||
|
||||
if (netif == NULL) {
|
||||
if (dev == NULL) {
|
||||
puts("No at86rf215 radio found");
|
||||
return 1;
|
||||
}
|
||||
|
||||
netdev_t *netdev = netif->dev;
|
||||
netdev_ieee802154_t *netdev_ieee802154 = container_of(netdev,
|
||||
netdev_ieee802154_t,
|
||||
netdev);
|
||||
at86rf215_t* dev = container_of(netdev_ieee802154, at86rf215_t, netdev);
|
||||
|
||||
at86rf215_get_random(dev, buffer, values);
|
||||
|
||||
od_hex_dump(buffer, values, 0);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user