From 9e4052e506f863904bc6c5d9a282a94da105f4d6 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 23 Mar 2017 07:20:10 -0600 Subject: [PATCH] Clicker2-STM32: Add some mostly bogus MAC initializatinon logic. --- configs/clicker2-stm32/src/stm32_mrf24j40.c | 31 +++++++++++++++++-- .../wireless/ieee802154/ieee802154_mac.h | 31 ++++++++++++------- wireless/ieee802154/mac802154.c | 18 ++++++++++- wireless/ieee802154/radio802154_device.c | 3 +- 4 files changed, 68 insertions(+), 15 deletions(-) diff --git a/configs/clicker2-stm32/src/stm32_mrf24j40.c b/configs/clicker2-stm32/src/stm32_mrf24j40.c index 99ad2faa06..8d28c54854 100644 --- a/configs/clicker2-stm32/src/stm32_mrf24j40.c +++ b/configs/clicker2-stm32/src/stm32_mrf24j40.c @@ -47,6 +47,8 @@ #include #include +#include +#include #include #include "stm32_gpio.h" @@ -87,6 +89,7 @@ #endif #define RADIO_DEVNAME "/dev/mrf24j40" +#define MAC_DEVNAME "/dev/mrf24j40mac" /**************************************************************************** * Private Types @@ -222,6 +225,9 @@ static void stm32_enable_irq(FAR struct mrf24j40_lower_s *lower, int state) static int stm32_mrf24j40_devsetup(FAR struct stm32_priv_s *priv) { FAR struct ieee802154_radio_s *radio; +#ifdef CONFIG_IEEE802154_MAC + FAR struct ieee802154_mac_s *mac; +#endif FAR struct spi_dev_s *spi; /* Configure the interrupt pin */ @@ -246,9 +252,9 @@ static int stm32_mrf24j40_devsetup(FAR struct stm32_priv_s *priv) return -ENODEV; } -#ifdef CONFIG_IEEE802154_DEV +#if defined(CONFIG_IEEE802154_DEV) /* Register a character driver to access the IEEE 802.15.4 radio from - * user-space + * user-space */ ret = radio802154dev_register(radio, RADIO_DEVNAME); @@ -258,6 +264,27 @@ static int stm32_mrf24j40_devsetup(FAR struct stm32_priv_s *priv) RADIO_DEVNAME, ret); return ret; } + +#elif 0 /* defined(CONFIG_IEEE802154_MAC) */ + /* Create a 802.15.4 MAC device from a 802.15.4 compatible radio device. */ + + mac = mac802154_register(radio, 0); + if (radio == NULL) + { + wlerr("ERROR: Failed to initialize IEEE802.15.4 MAC\n"); + return -ENODEV; + } + + /* If want to call these APIs from userspace, you have to wrap your mac + * in a character device via mac802154_device.c. + */ + + ret = mac802154dev_register(mac, MAC_DEVNAME); + if (ret < 0) + { + wlerr("ERROR: Failed to register the radio device %s: %d\n", + RADIO_DEVNAME, ret); + return ret; #endif return OK; diff --git a/include/nuttx/wireless/ieee802154/ieee802154_mac.h b/include/nuttx/wireless/ieee802154/ieee802154_mac.h index 0cddb694bf..3e0200e7a3 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_mac.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_mac.h @@ -378,17 +378,26 @@ extern "C" * Public Function Prototypes ****************************************************************************/ -/* Instanciate a 802.15.4 MAC from a 802.15.4 radio device. - * To create a 802.15.4 MAC, you need to pass: - * - an instance of a radio driver in radiodev - * - a pointer to a structure that contains MAC callback routines to - * handle confirmations and indications. NULL entries indicate no callback. - * In return you get a mac structure that has pointers to MAC operations and - * responses. - * This API does not create any device accessible to userspace. If you want to - * call these APIs from userspace, you have to wrap your mac in a character - * device via mac802154_device.c . - */ +/**************************************************************************** + * Name: mac802154_register + * + * Description: + * Create a 802.15.4 MAC device from a 802.15.4 compatible radio device. + * To create a 802.15.4 MAC, you need to pass: + * + * - an instance of a radio driver in radiodev + * - a pointer to a structure that contains MAC callback routines to + * handle confirmations and indications. NULL entries indicate no + * callback. + * + * In return you get a mac structure that has pointers to MAC operations + * and responses. + * + * This API does not create any device accessible to userspace. If you + * want to call these APIs from userspace, you have to wrap your mac in a + * character device via mac802154_device.c. + * + ****************************************************************************/ FAR struct ieee802154_mac_s * mac802154_register(FAR struct ieee802154_radio_s *radiodev, diff --git a/wireless/ieee802154/mac802154.c b/wireless/ieee802154/mac802154.c index 3de16fb374..cfa199d54b 100644 --- a/wireless/ieee802154/mac802154.c +++ b/wireless/ieee802154/mac802154.c @@ -524,6 +524,19 @@ static int mac802154_rsporphan(FAR struct ieee802154_mac_s *mac, * * Description: * Create a 802.15.4 MAC device from a 802.15.4 compatible radio device. + * To create a 802.15.4 MAC, you need to pass: + * + * - an instance of a radio driver in radiodev + * - a pointer to a structure that contains MAC callback routines to + * handle confirmations and indications. NULL entries indicate no + * callback. + * + * In return you get a mac structure that has pointers to MAC operations + * and responses. + * + * This API does not create any device accessible to userspace. If you + * want to call these APIs from userspace, you have to wrap your mac in a + * character device via mac802154_device.c. * ****************************************************************************/ @@ -537,7 +550,8 @@ FAR struct ieee802154_mac_s * mac = (FAR struct ieee802154_privmac_s *) kmm_zalloc(sizeof(struct ieee802154_privmac_s)); - if(!mac) + + if (mac == NULL) { return NULL; } @@ -546,7 +560,9 @@ FAR struct ieee802154_mac_s * mac->pubmac.radio = radiodev; mac->pubmac.ops = mac802154ops; + mac802154_defaultmib(mac); mac802154_applymib(mac); + return &mac->pubmac; } diff --git a/wireless/ieee802154/radio802154_device.c b/wireless/ieee802154/radio802154_device.c index bdd1e07c81..2bab563e5b 100644 --- a/wireless/ieee802154/radio802154_device.c +++ b/wireless/ieee802154/radio802154_device.c @@ -487,7 +487,8 @@ static int radio802154dev_ioctl(FAR struct file *filep, int cmd, * ****************************************************************************/ -int radio802154dev_register(FAR struct ieee802154_radio_s *radio, FAR char *devname) +int radio802154dev_register(FAR struct ieee802154_radio_s *radio, + FAR char *devname) { FAR struct radio802154_devwrapper_s *dev;