From b0afc4807d0e6302991d34084e1fcdfc232a5f85 Mon Sep 17 00:00:00 2001 From: Sebastien Lorquet Date: Wed, 1 Jun 2016 12:12:21 +0200 Subject: [PATCH 001/183] synthetic commit to import ieee branch from old repo --- drivers/wireless/ieee802154/Kconfig | 6 + drivers/wireless/ieee802154/Make.defs | 4 + drivers/wireless/ieee802154/at86rf23x.c | 1479 +++++++++++++++++ drivers/wireless/ieee802154/at86rf23x.h | 204 +++ drivers/wireless/ieee802154/mrf24j40.c | 229 +-- drivers/wireless/ieee802154/mrf24j40.h | 59 +- include/nuttx/fs/ioctl.h | 7 + include/nuttx/wireless/ieee802154/at86rf23x.h | 100 ++ .../wireless/ieee802154/ieee802154_mac.h | 368 ++++ .../wireless/ieee802154/ieee802154_radio.h | 133 +- include/nuttx/wireless/ieee802154/mrf24j40.h | 2 +- wireless/ieee802154/Kconfig | 18 + wireless/ieee802154/Make.defs | 9 + wireless/ieee802154/ieee802154_device.c | 374 +++++ wireless/ieee802154/mac802154.c | 586 +++++++ 15 files changed, 3362 insertions(+), 216 deletions(-) create mode 100644 drivers/wireless/ieee802154/at86rf23x.c create mode 100644 drivers/wireless/ieee802154/at86rf23x.h create mode 100644 include/nuttx/wireless/ieee802154/at86rf23x.h create mode 100644 include/nuttx/wireless/ieee802154/ieee802154_mac.h create mode 100644 wireless/ieee802154/ieee802154_device.c create mode 100644 wireless/ieee802154/mac802154.c diff --git a/drivers/wireless/ieee802154/Kconfig b/drivers/wireless/ieee802154/Kconfig index 93e802323df..6eba028b2a3 100644 --- a/drivers/wireless/ieee802154/Kconfig +++ b/drivers/wireless/ieee802154/Kconfig @@ -11,4 +11,10 @@ config IEEE802154_MRF24J40 ---help--- This selection enables support for the Microchip MRF24J40 device. +config IEEE802154_AT86RF233 + bool "ATMEL RF233 IEEE 802.15.4 transceiver" + default n + ---help--- + This selection enables support for the Atmel RF233 device. + endif # DRIVERS_IEEE802154 diff --git a/drivers/wireless/ieee802154/Make.defs b/drivers/wireless/ieee802154/Make.defs index b0a1406baa4..8e0924d67ff 100644 --- a/drivers/wireless/ieee802154/Make.defs +++ b/drivers/wireless/ieee802154/Make.defs @@ -45,6 +45,10 @@ ifeq ($(CONFIG_IEEE802154_MRF24J40),y) CSRCS += mrf24j40.c endif +ifeq ($(CONFIG_IEEE802154_AT86RF233),y) + CSRCS += at86rf23x.c +endif + # Include IEEE 802.15.4 build support DEPPATH += --dep-path wireless$(DELIM)ieee802154 diff --git a/drivers/wireless/ieee802154/at86rf23x.c b/drivers/wireless/ieee802154/at86rf23x.c new file mode 100644 index 00000000000..fdd2c3ad646 --- /dev/null +++ b/drivers/wireless/ieee802154/at86rf23x.c @@ -0,0 +1,1479 @@ +/**************************************************************************** + * drivers/wireless/ieee802154/at86rf23x.c + * + * Copyright (C) 2016 Matt Poppe. All rights reserved. + * Author: Matt Poppe + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +#include "at86rf23x.h" + +/************************************************************************************ + * Pre-processor Definitions + ************************************************************************************/ + +#ifndef CONFIG_SCHED_HPWORK +#error High priority work queue required in this driver +#endif + +#ifndef CONFIG_IEEE802154_at86rf23x_SPIMODE +# define CONFIG_IEEE802154_at86rf23x_SPIMODE SPIDEV_MODE0 +#endif + +#ifndef CONFIG_IEEE802154_at86rf23x_FREQUENCY +# define CONFIG_IEEE802154_at86rf23x_FREQUENCY 1000000 +#endif + +/* Definitions for the device structure */ + +#define AT86RF23X_RXMODE_NORMAL 0 +#define AT86RF23X_RXMODE_PROMISC 1 +#define AT86RF23X_RXMODE_NOCRC 2 +#define AT86RF23X_RXMODE_AUTOACK 3 + +/* Definitions for PA control on high power modules */ +#define AT86RF23X_PA_AUTO 1 +#define AT86RF23X_PA_ED 2 +#define AT86RF23X_PA_SLEEP 3 + + +/************************************************************************************ + * Private Types + ************************************************************************************/ + +/* + * AT86RF23x device instance + * + * Make sure that struct ieee802154_dev_s remains first. If not it will break the + * code + * + */ +struct at86rf23x_dev_s +{ + struct ieee802154_dev_s ieee; /* Public device instance */ + FAR struct spi_dev_s *spi; /* Saved SPI interface instance */ + struct work_s irqwork; /* Interrupt continuation work queue support */ + FAR const struct at86rf23x_lower_s *lower; /* Low-level MCU-specific support */ + uint16_t panid; /* PAN identifier, FFFF = not set */ + uint16_t saddr; /* short address, FFFF = not set */ + uint8_t eaddr[8]; /* extended address, FFFFFFFFFFFFFFFF = not set */ + uint8_t channel; /* 11 to 26 for the 2.4 GHz band */ + uint8_t devmode; /* device mode: device, coord, pancoord */ + uint8_t paenabled; /* enable usage of PA */ + uint8_t rxmode; /* Reception mode: Main, no CRC, promiscuous */ + int32_t txpower; /* TX power in mBm = dBm/100 */ + struct ieee802154_cca_s cca; /* Clear channel assessement method */ + +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/* Internal operations */ +static void at86rf23x_lock(FAR struct spi_dev_s *spi); +static void at86rf23x_unlock(FAR struct spi_dev_s *spi); +static void at86rf23x_setreg(FAR struct spi_dev_s *spi, uint32_t addr, uint8_t val); +static uint8_t at86rf23x_getreg(FAR struct spi_dev_s *spi, uint32_t addr); +static int at86rf23x_writeframe(FAR struct spi_dev_s *spi, uint8_t *frame, uint8_t len); +static uint8_t at86rf23x_readframe(FAR struct spi_dev_s *spi, uint8_t *frame_rx); +static int at86rf23x_setTRXstate(FAR struct at86rf23x_dev_s *dev, uint8_t state, uint8_t force); +static uint8_t at86rf23x_getTRXstate(FAR struct at86rf23x_dev_s *dev); +static int at86rf23x_resetrf(FAR struct at86rf23x_dev_s *dev); +static int at86rf23x_initialize(FAR struct at86rf23x_dev_s *dev); + +static int at86rf23x_regdump(FAR struct at86rf23x_dev_s *dev); +static void at86rf23x_irqwork_rx(FAR struct at86rf23x_dev_s *dev); +static void at86rf23x_irqwork_tx(FAR struct at86rf23x_dev_s *dev); +static void at86rf23x_irqworker(FAR void *arg); +static int at86rf23x_interrupt(int irq, FAR void *context); + +/* Driver operations */ +static int at86rf23x_setchannel (FAR struct ieee802154_dev_s *ieee, uint8_t chan); +static int at86rf23x_getchannel (FAR struct ieee802154_dev_s *ieee, FAR uint8_t *chan); +static int at86rf23x_setpanid (FAR struct ieee802154_dev_s *ieee, uint16_t panid); +static int at86rf23x_getpanid (FAR struct ieee802154_dev_s *ieee, FAR uint16_t *panid); +static int at86rf23x_setsaddr (FAR struct ieee802154_dev_s *ieee, uint16_t saddr); +static int at86rf23x_getsaddr (FAR struct ieee802154_dev_s *ieee, FAR uint16_t *saddr); +static int at86rf23x_seteaddr (FAR struct ieee802154_dev_s *ieee, FAR uint8_t *eaddr); +static int at86rf23x_geteaddr (FAR struct ieee802154_dev_s *ieee, FAR uint8_t *eaddr); +static int at86rf23x_setpromisc (FAR struct ieee802154_dev_s *ieee, bool promisc); +static int at86rf23x_getpromisc (FAR struct ieee802154_dev_s *ieee, FAR bool *promisc); +static int at86rf23x_setdevmode (FAR struct ieee802154_dev_s *ieee, uint8_t mode); +static int at86rf23x_getdevmode (FAR struct ieee802154_dev_s *ieee, FAR uint8_t *mode); +static int at86rf23x_settxpower (FAR struct ieee802154_dev_s *ieee, int32_t txpwr); +static int at86rf23x_gettxpower (FAR struct ieee802154_dev_s *ieee, FAR int32_t *txpwr); +static int at86rf23x_setcca (FAR struct ieee802154_dev_s *ieee, FAR struct ieee802154_cca_s *cca); +static int at86rf23x_getcca (FAR struct ieee802154_dev_s *ieee, FAR struct ieee802154_cca_s *cca); +static int at86rf23x_ioctl (FAR struct ieee802154_dev_s *ieee, int cmd, unsigned long arg); +static int at86rf23x_energydetect(FAR struct ieee802154_dev_s *ieee, FAR uint8_t *energy); +static int at86rf23x_rxenable (FAR struct ieee802154_dev_s *ieee, bool state, FAR struct ieee802154_packet_s *packet); +static int at86rf23x_transmit (FAR struct ieee802154_dev_s *ieee, FAR struct ieee802154_packet_s *packet); + + +/* These are pointers to ALL registered at86rf23x devices. + * This table is used during irqs to find the context + * Only one device is supported for now. + * More devices can be supported in the future by lookup them up + * using the IRQ number. See the ENC28J60 or CC3000 drivers for reference. + */ + +static struct at86rf23x_dev_s g_at86rf23x_devices[1]; + +static const struct ieee802154_devops_s at86rf23x_devops = +{ + .setchannel = at86rf23x_setchannel, + .getchannel = at86rf23x_getchannel, + .setpanid = at86rf23x_setpanid, + .getpanid = at86rf23x_getpanid, + .setsaddr = at86rf23x_setsaddr, + .getsaddr = at86rf23x_getsaddr, + .seteaddr = at86rf23x_seteaddr, + .geteaddr = at86rf23x_geteaddr, + .setpromisc = at86rf23x_setpromisc, + .getpromisc = at86rf23x_getpromisc, + .setdevmode = at86rf23x_setdevmode, + .getdevmode = at86rf23x_getdevmode, + .settxpower = at86rf23x_settxpower, + .gettxpower = at86rf23x_gettxpower, + .setcca = at86rf23x_setcca, + .getcca = at86rf23x_getcca, + .ioctl = at86rf23x_ioctl, + .energydetect = at86rf23x_energydetect, + .rxenable = at86rf23x_rxenable, + .transmit = at86rf23x_transmit +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ +#ifndef CONFIG_SPI_EXCHANGE +#error CONFIG_SPI_EXCHANGE required for this driver +#endif + +/* hardware access routines */ + +/**************************************************************************** + * Name: at86rf23x_lock + * + * Description: + * Acquire exclusive access to the shared SPI bus. + * + ****************************************************************************/ + +static void at86rf23x_lock(FAR struct spi_dev_s *spi) +{ + SPI_LOCK (spi, 1); + SPI_SETBITS (spi, 8); + SPI_SETMODE (spi, CONFIG_IEEE802154_at86rf23x_SPIMODE ); + SPI_SETFREQUENCY(spi, CONFIG_IEEE802154_at86rf23x_FREQUENCY ); + +} + +/**************************************************************************** + * Name: at86rf23x_unlock + * + * Description: + * Release exclusive access to the shared SPI bus. + * + ****************************************************************************/ + +static void at86rf23x_unlock(FAR struct spi_dev_s *spi) +{ + SPI_LOCK(spi,0); +} + +/**************************************************************************** + * Name: at86rf23x_setreg + * + * Description: + * Define the value of an at86rf23x device register + * + ****************************************************************************/ + +static void at86rf23x_setreg(FAR struct spi_dev_s *spi, uint32_t addr, uint8_t val) +{ + uint8_t reg[2]; + + reg[0] = addr; + reg[0] |= RF23X_SPI_REG_WRITE; + + reg[1] = val; + at86rf23x_lock(spi); + SPI_SELECT(spi, SPIDEV_IEEE802154, true); + SPI_SNDBLOCK(spi, reg, 2); + SPI_SELECT(spi, SPIDEV_IEEE802154, false); + at86rf23x_unlock(spi); + + vdbg("0x%02X->r[0x%02X]\n", val, addr); + +} + +/**************************************************************************** + * Name: at86rf23x_getreg + * + * Description: + * Return the value of an at86rf23x device register + * + ****************************************************************************/ +static uint8_t at86rf23x_getreg(FAR struct spi_dev_s *spi, uint32_t addr) +{ + uint8_t reg[2]; + uint8_t val[2]; + + /* Add Read mask to desired register */ + reg[0] = addr | RF23X_SPI_REG_READ; + + at86rf23x_lock (spi); + + SPI_SELECT (spi, SPIDEV_IEEE802154, true); + SPI_EXCHANGE (spi, reg, val, 2); + SPI_SELECT (spi, SPIDEV_IEEE802154, false); + + at86rf23x_unlock(spi); + + vdbg("r[0x%02X]=0x%02X\n",addr,val[1]); + + return val[1]; +} + +/**************************************************************************** + * Name: at86rf23x_setregbits + * + * Description: + * Read the current value of the register. Change only the portion + * of the register we need to change and write the value back to the + * register. + * + ****************************************************************************/ +static void at86rf23x_setregbits(FAR struct spi_dev_s *spi, + uint8_t addr, + uint8_t pos, + uint8_t mask, + uint8_t val) +{ + uint8_t reg; + + reg = at86rf23x_getreg(spi, addr); + reg = (reg & ~(mask << pos)) | (val << pos); + at86rf23x_setreg(spi, addr, reg); +} + +/**************************************************************************** + * Name: at86rf23x_getregbits + * + * Description: + * Return the value of an section of the at86rf23x device register. + * + ****************************************************************************/ +static uint8_t at86rf23x_getregbits(FAR struct spi_dev_s *spi, + uint8_t addr, + uint8_t pos, + uint8_t mask) +{ + uint8_t val; + + val = at86rf23x_getreg(spi, addr); + val = (val >> pos) & mask; + + return val; +} + +/**************************************************************************** + * Name: at86rf23x_writebuffer + * + * Description: + * Write frame to the transmit buffer of the radio. This does not + * initiate the transfer, just write to the buffer. + * + ****************************************************************************/ +static int at86rf23x_writeframe(FAR struct spi_dev_s *spi, uint8_t *frame, uint8_t len) +{ +// report_packet(frame_wr, len); + uint8_t reg = RF23X_SPI_FRAME_WRITE; + + at86rf23x_lock(spi); + + SPI_SELECT(spi, SPIDEV_IEEE802154, true); + + SPI_SNDBLOCK(spi, ®, 1); + SPI_SNDBLOCK(spi, &frame, len); + + SPI_SELECT(spi, SPIDEV_IEEE802154, false); + + at86rf23x_unlock(spi); + + return len; +} + +/**************************************************************************** + * Name: at86rf23x_readframe + * + * Description: + * Read the buffer memory of the radio. This is used when the radio + * indicates a frame has been received. + * + ****************************************************************************/ +static uint8_t at86rf23x_readframe(FAR struct spi_dev_s *spi, uint8_t *frame_rx) +{ + uint8_t len, reg; + + reg = RF23X_SPI_FRAME_READ; + + at86rf23x_lock(spi); + SPI_SELECT(spi, SPIDEV_IEEE802154, true); + + SPI_SNDBLOCK(spi, ®, 1); + SPI_RECVBLOCK(spi, &len, 1); + SPI_RECVBLOCK(spi, frame_rx, len+3); + + SPI_SELECT(spi, SPIDEV_IEEE802154, false); + at86rf23x_unlock(spi); + + return len; +} + + +/**************************************************************************** + * Name: at86rf23x_getTRXstate + * + * Description: + * Return the current status of the TRX state machine. + * + ****************************************************************************/ +static uint8_t at86rf23x_getTRXstate(FAR struct at86rf23x_dev_s *dev) +{ + return at86rf23x_getregbits(dev->spi, RF23X_TRXSTATUS_STATUS); +} + +/**************************************************************************** + * Name: at86rf23x_setTRXstate + * + * Description: + * Set the TRX state machine to the desired state. If the state machine + * cannot move to the desired state an ERROR is returned. If the transistion + * is successful an OK is returned. This is a long running function due to + * waiting for the transistion delay between states. This can be as long as + * 510us. + * + ****************************************************************************/ +static int at86rf23x_setTRXstate(FAR struct at86rf23x_dev_s *dev, uint8_t state, uint8_t force) +{ + /* Get the current state of the transceiver */ + uint8_t status = at86rf23x_getTRXstate(dev); + + int ret = OK; + + /* TODO I don't have every state included verify this will work with SLEEP */ + if((status != TRX_STATUS_TRXOFF) && + (status != TRX_STATUS_RXON) && + (status != TRX_STATUS_PLLON) && + (status != TRX_STATUS_RXAACKON) && + (status != TRX_STATUS_TXARETON) && + (status != TRX_STATUS_PON)) + { + dbg("Invalid State\n"); + return ERROR; + } + + int8_t init_status = status; + + /* Start the state change */ + switch(state) + { + case TRX_CMD_TRXOFF: + if(status == TRX_STATUS_TRXOFF) + { + break; + } + /* verify in a state that will transfer to TRX_OFF if not check if force is required */ + if( (status == TRX_STATUS_RXON) || + (status == TRX_STATUS_PLLON) || + (status == TRX_STATUS_RXAACKON) || + (status == TRX_STATUS_TXARETON)) + { + at86rf23x_setregbits(dev->spi, RF23X_TRXCMD_STATE, TRX_CMD_TRXOFF); + up_udelay(RF23X_TIME_TRANSITION_PLL_ACTIVE); + } + else if(status == TRX_STATUS_PON) + { + at86rf23x_setregbits(dev->spi, RF23X_TRXCMD_STATE, TRX_CMD_TRXOFF); + up_udelay(RF23X_TIME_P_ON_TO_TRXOFF); + } + else if(force) + { + at86rf23x_setregbits(dev->spi, RF23X_TRXCMD_STATE, TRX_CMD_FORCETRXOFF); + up_udelay(RF23X_TIME_FORCE_TRXOFF); + } + + status = at86rf23x_getregbits(dev->spi, RF23X_TRXSTATUS_STATUS); + + if(status != TRX_STATUS_TRXOFF) + { + ret = ERROR; + } + + break; + + case TRX_CMD_RX_ON: + + if(status == TRX_STATUS_RXON) + { + break; + } + + if (status == TRX_STATUS_TRXOFF) + { + at86rf23x_setregbits(dev->spi, RF23X_TRXCMD_STATE, TRX_CMD_RX_ON); + up_udelay(RF23X_TIME_TRXOFF_TO_PLL); + } + + else if((status == TRX_STATUS_RXAACKON) || + (status == TRX_STATUS_RXON) || + (status == TRX_STATUS_PLLON) || + (status == TRX_STATUS_TXARETON)) + { + at86rf23x_setregbits(dev->spi, RF23X_TRXCMD_STATE, TRX_CMD_RX_ON); + up_udelay(RF23X_TIME_TRANSITION_PLL_ACTIVE); + } + + status = at86rf23x_getregbits(dev->spi, RF23X_TRXSTATUS_STATUS); + + if(status != TRX_STATUS_RXON) + { + ret = ERROR; + } + break; + + /* transition to PLL_ON */ + case TRX_CMD_PLL_ON: + + if(status == TRX_STATUS_PLLON) + { + break; + } + + if (status == TRX_STATUS_TRXOFF) + { + at86rf23x_setregbits(dev->spi, RF23X_TRXCMD_STATE, TRX_CMD_PLL_ON); + up_udelay(RF23X_TIME_TRXOFF_TO_PLL); + } + else + { + at86rf23x_setregbits(dev->spi, RF23X_TRXCMD_STATE, TRX_CMD_PLL_ON); + up_udelay(RF23X_TIME_TRANSITION_PLL_ACTIVE); + } + + status = at86rf23x_getregbits(dev->spi, RF23X_TRXSTATUS_STATUS); + + if(status != TRX_STATUS_PLLON) + { + ret = ERROR; + } + break; + + case TRX_CMD_RX_AACK_ON: + + if(status == TRX_STATUS_RXAACKON) + { + break; + } + + if (status == TRX_STATUS_TRXOFF || status == TRX_STATUS_TXARETON) + { + at86rf23x_setregbits(dev->spi, RF23X_TRXCMD_STATE, TRX_CMD_RX_ON); + + (status == TRX_STATUS_TRXOFF) ? up_udelay(RF23X_TIME_TRXOFF_TO_PLL) : + up_udelay(RF23X_TIME_TRANSITION_PLL_ACTIVE); + } + + status = at86rf23x_getTRXstate(dev); + + if ((status == TRX_STATUS_RXON) || (status == TRX_STATUS_PLLON)) + { + at86rf23x_setregbits(dev->spi, RF23X_TRXCMD_STATE, TRX_CMD_RX_AACK_ON); + up_udelay(RF23X_TIME_TRANSITION_PLL_ACTIVE); + } + + status = at86rf23x_getregbits(dev->spi, RF23X_TRXSTATUS_STATUS); + + if(status != TRX_STATUS_RXAACKON) + { + ret = ERROR; + } + + break; + + case TRX_STATUS_TXARETON: + + if(status == TRX_STATUS_TXARETON) + { + break; + } + + if (status == TRX_STATUS_TRXOFF) + { + at86rf23x_setregbits(dev->spi, RF23X_TRXCMD_STATE, TRX_CMD_RX_ON); + up_udelay(RF23X_TIME_TRXOFF_TO_PLL); + } + + if ((status == TRX_STATUS_RXON) || (status == TRX_STATUS_PLLON)) + { + at86rf23x_setregbits(dev->spi, RF23X_TRXCMD_STATE, TRX_CMD_TX_ARET_ON); + up_udelay(RF23X_TIME_TRANSITION_PLL_ACTIVE); + } + else if (status == TRX_STATUS_RXAACKON) + { + at86rf23x_setregbits(dev->spi, RF23X_TRXCMD_STATE, TRX_CMD_RX_ON); + up_udelay(RF23X_TIME_TRANSITION_PLL_ACTIVE); + + at86rf23x_setregbits(dev->spi, RF23X_TRXCMD_STATE, TRX_CMD_TX_ARET_ON); + up_udelay(RF23X_TIME_TRANSITION_PLL_ACTIVE); + } + + status = at86rf23x_getregbits(dev->spi, RF23X_TRXSTATUS_STATUS); + + if(status != TRX_STATUS_TXARETON) + { + ret = ERROR; + } + + break; + + case TRX_STATUS_SLEEP: + at86rf23x_setregbits(dev->spi, RF23X_TRXCMD_STATE, TRX_CMD_FORCETRXOFF); + up_udelay(RF23X_TIME_CMD_FORCE_TRX_OFF); + + dev->lower->slptr(dev->lower, true); + up_udelay(RF23X_TIME_TRXOFF_TO_SLEEP); + + status = at86rf23x_getregbits(dev->spi, RF23X_TRXSTATUS_STATUS); + break; + + default: + dbg("%s \n", EINVAL_STR); + init_status = 0;/* Placed this here to keep compiler happy when not in debug */ + return -EINVAL; + + } + if(ret == ERROR) + { + dbg("State Transistion Error\n"); + } + + vdbg("Radio state change state[0x%02x]->state[0x%02x]\n", init_status, status); + + return ret; +} + +/* Publicized driver routines */ + +/**************************************************************************** + * Name: at86rf23x_setchannel + * + * Description: + * Define the current radio channel the device is operating on. + * In the 2.4 GHz, there are 16 channels, each 2 MHz wide, 5 MHz spacing: + * Chan MHz Chan MHz Chan MHz Chan MHz + * 11 2405 15 2425 19 2445 23 2465 + * 12 2410 16 2430 20 2450 24 2470 + * 13 2415 17 2435 21 2455 25 2475 + * 14 2420 18 2440 22 2460 26 2480 + * + * + ****************************************************************************/ +static int at86rf23x_setchannel(FAR struct ieee802154_dev_s *ieee, uint8_t chan) +{ + FAR struct at86rf23x_dev_s *dev = (FAR struct at86rf23x_dev_s *)ieee; + uint8_t state; + + /* Validate if chan is a valid channel */ + if(chan<11 || chan>26) + { + dbg("Invalid requested chan: %d\n",chan); + return -EINVAL; + } + + /* Validate we are in an acceptable mode to change the channel */ + state = at86rf23x_getTRXstate(dev); + + if((TRX_STATUS_SLEEP == state) || (TRX_STATUS_PON == state)) { + dbg("Radio in invalid mode [%02x] to set the channel\n", state); + return ERROR; + } + /* Set the Channel on the transceiver */ + + at86rf23x_setregbits(dev->spi, RF23X_CCA_BITS_CHANNEL, chan); + + /* Set the channel within local device */ + dev->channel = chan; + + vdbg("CHANNEL Changed to %d\n", chan); + + return OK; +} + +/**************************************************************************** + * Name: at86rf23x_getchannel + * + * Description: + * Define the current radio channel the device is operating on. + * In the 2.4 GHz, there are 16 channels, each 2 MHz wide, 5 MHz spacing: + * Chan MHz Chan MHz Chan MHz Chan MHz + * 11 2405 15 2425 19 2445 23 2465 + * 12 2410 16 2430 20 2450 24 2470 + * 13 2415 17 2435 21 2455 25 2475 + * 14 2420 18 2440 22 2460 26 2480 + * + * This section assumes that the transceiver is not in SLEEP or P_ON state. + * + * + ****************************************************************************/ +static int at86rf23x_getchannel(FAR struct ieee802154_dev_s *ieee, FAR uint8_t *chan) +{ + FAR struct at86rf23x_dev_s *dev = (FAR struct at86rf23x_dev_s *)ieee; + + /* Set the Channel on the transceiver */ + *chan = at86rf23x_getregbits(dev->spi, RF23X_CCA_BITS_CHANNEL); + + /* Set the channel within local device */ + dev->channel = *chan; + + return OK; +} + +/**************************************************************************** + * Name: at86rf23x_setpanid + * + * Description: + * Define the PAN ID for the network. + * + ****************************************************************************/ +static int at86rf23x_setpanid(FAR struct ieee802154_dev_s *ieee, uint16_t panid) +{ + FAR struct at86rf23x_dev_s *dev = (struct at86rf23x_dev_s *)ieee; + uint8_t *pan = (uint8_t *)&panid; + + at86rf23x_setreg(dev->spi, RF23X_REG_PANID0, pan[0]); + at86rf23x_setreg(dev->spi, RF23X_REG_PANID1, pan[1]); + + return OK; +} + +/**************************************************************************** + * Name: at86rf23x_getpanid + * + * Description: + * Define the PAN ID for the network. + * + ****************************************************************************/ +static int at86rf23x_getpanid(FAR struct ieee802154_dev_s *ieee, FAR uint16_t *panid) +{ + FAR struct at86rf23x_dev_s *dev = (struct at86rf23x_dev_s *)ieee; + uint8_t *pan = (uint8_t *)panid; + /* TODO: Check if we need to pay attention to endianness */ + pan[0] = at86rf23x_getreg(dev->spi, RF23X_REG_PANID0); + pan[1] = at86rf23x_getreg(dev->spi, RF23X_REG_PANID1); + + return OK; +} + +/**************************************************************************** + * Name: at86rf23x_setsaddr + * + * Description: + * Define the Short Address for the device. + * + ****************************************************************************/ +static int at86rf23x_setsaddr(FAR struct ieee802154_dev_s *ieee, uint16_t saddr) +{ + FAR struct at86rf23x_dev_s *dev = (struct at86rf23x_dev_s *)ieee; + uint8_t *addr = (uint8_t *)&saddr; + + at86rf23x_setreg(dev->spi, RF23X_REG_SADDR0, addr[0]); + at86rf23x_setreg(dev->spi, RF23X_REG_SADDR1, addr[1]); + + return OK; +} + +/**************************************************************************** + * Name: at86rf23x_getsaddr + * + * Description: + * Get the short address of the device. + * + ****************************************************************************/ +static int at86rf23x_getsaddr(FAR struct ieee802154_dev_s *ieee, FAR uint16_t *saddr) +{ + FAR struct at86rf23x_dev_s *dev = (struct at86rf23x_dev_s *)ieee; + uint8_t *addr = (uint8_t *)saddr; + /* TODO: Check if we need to pay attention to endianness */ + addr[0] = at86rf23x_getreg(dev->spi, RF23X_REG_SADDR0); + addr[1] = at86rf23x_getreg(dev->spi, RF23X_REG_SADDR1); + + return OK; +} + +/**************************************************************************** + * Name: at86rf23x_seteaddr + * + * Description: + * Set the IEEE address of the device. + * + ****************************************************************************/ +static int at86rf23x_seteaddr(FAR struct ieee802154_dev_s *ieee, FAR uint8_t *eaddr) +{ + FAR struct at86rf23x_dev_s *dev = (struct at86rf23x_dev_s *)ieee; + /* TODO: Check if we need to pay attention to endianness */ + at86rf23x_setreg(dev->spi, RF23X_REG_IEEEADDR0, eaddr[0]); + at86rf23x_setreg(dev->spi, RF23X_REG_IEEEADDR1, eaddr[1]); + at86rf23x_setreg(dev->spi, RF23X_REG_IEEEADDR2, eaddr[2]); + at86rf23x_setreg(dev->spi, RF23X_REG_IEEEADDR3, eaddr[3]); + at86rf23x_setreg(dev->spi, RF23X_REG_IEEEADDR4, eaddr[4]); + at86rf23x_setreg(dev->spi, RF23X_REG_IEEEADDR5, eaddr[5]); + at86rf23x_setreg(dev->spi, RF23X_REG_IEEEADDR6, eaddr[6]); + at86rf23x_setreg(dev->spi, RF23X_REG_IEEEADDR7, eaddr[7]); + + return OK; +} + +/**************************************************************************** + * Name: at86rf23x_geteaddr + * + * Description: + * Get the IEEE address of the device. + * + ****************************************************************************/ +static int at86rf23x_geteaddr(FAR struct ieee802154_dev_s *ieee, FAR uint8_t *eaddr) +{ + FAR struct at86rf23x_dev_s *dev = (struct at86rf23x_dev_s *)ieee; + /* TODO: Check if we need to pay attention to endianness */ + eaddr[0] = at86rf23x_getreg(dev->spi, RF23X_REG_IEEEADDR0); + eaddr[1] = at86rf23x_getreg(dev->spi, RF23X_REG_IEEEADDR1); + eaddr[2] = at86rf23x_getreg(dev->spi, RF23X_REG_IEEEADDR2); + eaddr[3] = at86rf23x_getreg(dev->spi, RF23X_REG_IEEEADDR3); + eaddr[4] = at86rf23x_getreg(dev->spi, RF23X_REG_IEEEADDR4); + eaddr[5] = at86rf23x_getreg(dev->spi, RF23X_REG_IEEEADDR5); + eaddr[6] = at86rf23x_getreg(dev->spi, RF23X_REG_IEEEADDR6); + eaddr[7] = at86rf23x_getreg(dev->spi, RF23X_REG_IEEEADDR7); + + return OK; +} + +/**************************************************************************** + * Name: at86rf23x_setpromisc + * + * Description: + * enable/disable promiscuous mode. + * + ****************************************************************************/ +static int at86rf23x_setpromisc(FAR struct ieee802154_dev_s *ieee, bool promisc) +{ + FAR struct at86rf23x_dev_s *dev = (struct at86rf23x_dev_s *)ieee; + + /* TODO: Check what mode I should be in to activate promiscuous mode: + * This is way to simple of an implementation. Many other things should be set + * and/or checked before we set the device into promiscuous mode + * */ + at86rf23x_setregbits(dev->spi, RF23X_XAHCTRL1_BITS_PROM_MODE, promisc); + + return OK; +} + +/**************************************************************************** + * Name: at86rf23x_getpromisc + * + * Description: + * Check if the device is in promiscuous mode. + * + ****************************************************************************/ +static int at86rf23x_getpromisc(FAR struct ieee802154_dev_s *ieee, FAR bool *promisc) +{ + FAR struct at86rf23x_dev_s *dev = (struct at86rf23x_dev_s *)ieee; + + *promisc = at86rf23x_getregbits(dev->spi, RF23X_XAHCTRL1_BITS_PROM_MODE); + + return OK; +} + +/**************************************************************************** + * Name: at86rf23x_setdevmode + * + * Description: + * Check if the device is in promiscuous mode. + * + ****************************************************************************/ +static int at86rf23x_setdevmode(FAR struct ieee802154_dev_s *ieee, uint8_t mode) +{ + FAR struct at86rf23x_dev_s *dev = (struct at86rf23x_dev_s *)ieee; + + /* define dev mode */ + if(mode == IEEE802154_MODE_PANCOORD) + { + at86rf23x_setregbits(dev->spi, RF23X_CSMASEED1_IAMCOORD_BITS, 0x01); + } + else if(mode == IEEE802154_MODE_COORD) + { + /* ????? */ + } + else if(mode == IEEE802154_MODE_DEVICE) + { + at86rf23x_setregbits(dev->spi, RF23X_CSMASEED1_IAMCOORD_BITS, 0x00); + } + else + { + return -EINVAL; + } + + dev->devmode = mode; + + return OK; +} + +/**************************************************************************** + * Name: at86rf23x_getdevmode + * + * Description: + * get the device mode type of the radio. + * + ****************************************************************************/ +static int at86rf23x_getdevmode (FAR struct ieee802154_dev_s *ieee, FAR uint8_t *mode) +{ + FAR struct at86rf23x_dev_s *dev = (struct at86rf23x_dev_s *)ieee; + int val; + + val = at86rf23x_getregbits(dev->spi, RF23X_CSMASEED1_IAMCOORD_BITS); + + if(val == 1) + { + mode = IEEE802154_MODE_PANCOORD; + } + else + { + mode = IEEE802154_MODE_DEVICE; + } + + return OK; +} + +/**************************************************************************** + * Name: at86rf23x_settxpower + * + * Description: + * set the tx power attenuation or amplification + * + ****************************************************************************/ +static int at86rf23x_settxpower(FAR struct ieee802154_dev_s *ieee, int32_t txpwr) +{ + FAR struct at86rf23x_dev_s *dev = (struct at86rf23x_dev_s *)ieee; + + /* TODO: this needs alot of work to make sure all chips can share this function */ + + /* Right now we only set tx power to 0 */ + at86rf23x_setreg(dev->spi, RF23X_REG_TXPWR, RF23X_TXPWR_0); + + return OK; +} + +/**************************************************************************** + * Name: at86rf23x_gettxpower + * + * Description: + * get the tx power attenuation or amplification. + * + ****************************************************************************/ +static int at86rf23x_gettxpower(FAR struct ieee802154_dev_s *ieee, FAR int32_t *txpwr) +{ + /* TODO: this needs alot of work to make sure all chips can share this function */ + FAR struct at86rf23x_dev_s *dev = (struct at86rf23x_dev_s *)ieee; + uint8_t reg; + /* TODO: this needs alot of work to make sure all chips can share this function */ + + /* Right now we only get negative values */ + reg = at86rf23x_getreg(dev->spi, RF23X_REG_TXPWR); + + switch(reg) + { + case RF23X_TXPWR_POS_4: + *txpwr = 0; + break; + case RF23X_TXPWR_POS_3_7: + *txpwr = 0; + break; + case RF23X_TXPWR_POS_3_4: + *txpwr = 0; + break; + case RF23X_TXPWR_POS_3: + *txpwr = 0; + break; + case RF23X_TXPWR_POS_2_5: + *txpwr = 0; + break; + case RF23X_TXPWR_POS_2: + *txpwr = 0; + break; + case RF23X_TXPWR_POS_1: + *txpwr = 0; + break; + case RF23X_TXPWR_0: + *txpwr = 0; + break; + case RF23X_TXPWR_NEG_1: + *txpwr = 1000; + break; + case RF23X_TXPWR_NEG_2: + *txpwr = 2000; + break; + case RF23X_TXPWR_NEG_3: + *txpwr = 3000; + break; + case RF23X_TXPWR_NEG_4: + *txpwr = 4000; + break; + case RF23X_TXPWR_NEG_6: + *txpwr = 6000; + break; + case RF23X_TXPWR_NEG_8: + *txpwr = 8000; + break; + case RF23X_TXPWR_NEG_12: + *txpwr = 12000; + break; + case RF23X_TXPWR_NEG_17: + *txpwr = 17000; + break; + } + + return OK; +} + +/**************************************************************************** + * Name: at86rf23x_setcca + * + * Description: + * Configures if energy detection is used or carrier sense. The base + * measurement is configured here as well + * + * + ****************************************************************************/ +static int at86rf23x_setcca(FAR struct ieee802154_dev_s *ieee, FAR struct ieee802154_cca_s *cca) +{ + FAR struct at86rf23x_dev_s *dev = (struct at86rf23x_dev_s *)ieee; + + /* TODO: This doesn't fit the RF233 completely come back to this */ + + if (!cca->use_ed && !cca->use_cs) + { + return -EINVAL; + } + if (cca->use_cs && cca->csth > 0x0f) + { + return -EINVAL; + } + + if (cca->use_ed) + { + at86rf23x_setregbits(dev->spi, RF23X_CCA_BITS_MODE, RF23X_CCA_MODE_ED); + } + if (cca->use_cs) + { + at86rf23x_setregbits(dev->spi, RF23X_CCA_BITS_MODE, RF23X_CCA_MODE_CS); + } + + memcpy(&dev->cca, cca, sizeof(struct ieee802154_cca_s)); + + return OK; +} + +/**************************************************************************** + * Name: at86rf23x_getcca + * + * Description: + * Get CCA for ???: TODO: need to implement + * + ****************************************************************************/ +static int at86rf23x_getcca(FAR struct ieee802154_dev_s *ieee, FAR struct ieee802154_cca_s *cca) +{ + FAR struct at86rf23x_dev_s *dev = (struct at86rf23x_dev_s *)ieee; + +#warning at86rf23x_getcca not implemented. + + UNUSED(dev); + UNUSED(cca); + + return ERROR; +} + +/**************************************************************************** + * Name: at86rf23x_ioctl + * + * Description: + * Control operations for the radio. + * + ****************************************************************************/ +static int at86rf23x_ioctl(FAR struct ieee802154_dev_s *ieee, int cmd, unsigned long arg) +{ + FAR struct at86rf23x_dev_s *dev = (FAR struct at86rf23x_dev_s *)ieee; + switch(cmd) + { + case MAC854IORDUMP: return at86rf23x_regdump(dev); + default: return -EINVAL; + } +} +/**************************************************************************** + * Name: at86rf23x_energydetect + * + * Description: + * Perform energy detection scan. TODO: Need to implement. + * + ****************************************************************************/ +static int at86rf23x_energydetect(FAR struct ieee802154_dev_s *ieee, FAR uint8_t *energy) +{ + +#warning at86rf23x_energydetect not implemented. + + /* Not yet implemented */ + + return ERROR; +} + +/**************************************************************************** + * Name: at86rf23x_initialize + * + * Description: + * Initialize the radio. + * + ****************************************************************************/ +int at86rf23x_initialize(FAR struct at86rf23x_dev_s *dev) +{ + uint8_t part; + uint8_t version; + + at86rf23x_resetrf(dev); + + part = at86rf23x_getreg(dev->spi, RF23X_REG_PART); + version = at86rf23x_getreg(dev->spi, RF23X_REG_VERSION); + + dbg("Radio part: 0x%02x version: 0x%02x found\n", part, version); + + return OK; +} + +/**************************************************************************** + * Name: at86rf23x_resetrf + * + * Description: + * Hard Reset of the radio. The reset also brings the radio into the + * TRX_OFF state. + * + ****************************************************************************/ +static int at86rf23x_resetrf(FAR struct at86rf23x_dev_s *dev) +{ + FAR const struct at86rf23x_lower_s *lower = dev->lower; + uint8_t trx_status, retry_cnt = 0; + + /* Reset the radio */ + lower->reset(lower, 0); + lower->slptr(lower, 0); + + up_udelay(RF23X_TIME_RESET); + lower->reset(lower, 1); + + + /* Dummy read of IRQ register */ + at86rf23x_getreg(dev->spi, RF23X_REG_IRQ_STATUS); + + do + { + trx_status = at86rf23x_setTRXstate(dev, TRX_CMD_TRXOFF, true); + + if (retry_cnt == RF23X_MAX_RETRY_RESET_TO_TRX_OFF) + { + dbg("Reset of transceiver failed\n"); + return ERROR; + } + + retry_cnt++; + } while (trx_status != OK); + + return OK; +} + +/**************************************************************************** + * Name: at86rf23x_rxenable + * + * Description: + * puts the radio into RX mode and brings in the buffer to handle + * RX messages. + * + ****************************************************************************/ +static int at86rf23x_rxenable(FAR struct ieee802154_dev_s *ieee, bool state, + FAR struct ieee802154_packet_s *packet) +{ + FAR struct at86rf23x_dev_s *dev = (FAR struct at86rf23x_dev_s *)ieee; + + /* Set the radio to the receive state */ + return at86rf23x_setTRXstate(dev, TRX_CMD_RX_ON, false); + + /* Enable the RX IRQ */ + + /* TODO: + * I am not sure what to do here since the at86rf23x shares the + * irq with the tx finished. Better planning needs to be done on + * my end. + */ + + /* Set buffer to receive next packet */ + ieee->rxbuf = packet; +} + +/**************************************************************************** + * Name: at86rf23x_interrupt + * + * Description: + * Actual interrupt handler ran inside privileged space. + * + ****************************************************************************/ +static int at86rf23x_interrupt(int irq, FAR void *context) +{ + + /* To support multiple devices, + * retrieve the priv structure using the irq number */ + + register FAR struct at86rf23x_dev_s *dev = &g_at86rf23x_devices[0]; + + /* In complex environments, we cannot do SPI transfers from the interrupt + * handler because semaphores are probably used to lock the SPI bus. In + * this case, we will defer processing to the worker thread. This is also + * much kinder in the use of system resources and is, therefore, probably + * a good thing to do in any event. + */ + + DEBUGASSERT(work_available(&dev->irqwork)); + + /* Notice that further GPIO interrupts are disabled until the work is + * actually performed. This is to prevent overrun of the worker thread. + * Interrupts are re-enabled in enc_irqworker() when the work is completed. + */ + dev->lower->irq(dev->lower, NULL, FALSE); + // dev->lower->enable(dev->lower, FALSE); + + return work_queue(HPWORK, &dev->irqwork, at86rf23x_irqworker, (FAR void *)dev, 0); +} + +/**************************************************************************** + * Name: at86rf23x_regdump + * + * Description: + * Dumps all the RF23X radios registers from 00 - 2F there are a few other + * registers that don't get dumped but just fore the ease of code I left + * them out. + * + ****************************************************************************/ +static int at86rf23x_regdump(FAR struct at86rf23x_dev_s *dev) +{ + uint32_t i; + char buf[4+16*3+2+1]; + + int len=0; + printf("RF23X regs:\n"); + + for (i=0;i<0x30;i++) + { + /* First row and every 15 regs */ + if ((i & 0x0f) == 0) + { + len = sprintf(buf, "%02x: ",i&0xFF); + } + + /* print the register value */ + len += sprintf(buf+len, "%02x ", at86rf23x_getreg(dev->spi, i)); + + /* at the end of each 15 regs or end of rf233s regs and actually print dbg message*/ + if ((i&15)==15 || i == 0x2f) + { + sprintf(buf+len, "\n"); + printf("%s",buf); + } + } + + /* TODO: I have a few more regs that are not consecutive. Will print later */ + + return 0; +} + +/**************************************************************************** + * Name: at86rf23x_irqworker + * + * Description: + * Actual thread to handle the irq outside of privaleged mode. + * + ****************************************************************************/ +static void at86rf23x_irqworker(FAR void *arg) +{ + FAR struct at86rf23x_dev_s *dev = (FAR struct at86rf23x_dev_s *)arg; + + uint8_t irq_status = at86rf23x_getreg(dev->spi, RF23X_REG_IRQ_STATUS); + + vdbg("IRQ: 0x%02X\n", irq_status); + + if((irq_status & (1<<3)) != 0) + { + if((irq_status & (1<<2)) != 0) + { + at86rf23x_irqwork_rx(dev); + } + else + { + at86rf23x_irqwork_tx(dev); + } + } + else + { + dbg("Unknown IRQ Status: %d\n", irq_status); + + /* Re enable the IRQ even if we don't know how to handle previous status*/ + dev->lower->irq(dev->lower, NULL, true); + } +} + +/**************************************************************************** + * Name: at86rf23x_irqwork_rx + * + * Description: + * Misc/unofficial device controls. + * + ****************************************************************************/ +static void at86rf23x_irqwork_rx(FAR struct at86rf23x_dev_s *dev) +{ + uint8_t rx_len; + + vdbg("6LOWPAN:Rx IRQ\n"); + + rx_len = at86rf23x_readframe(dev->spi, dev->ieee.rxbuf->data); + + dev->ieee.rxbuf->len = rx_len; + dev->ieee.rxbuf->lqi = 0; + dev->ieee.rxbuf->rssi = 0; + + sem_post(&dev->ieee.rxsem); + /* + * TODO: + * Not to sure yet what I should do here. I will something + * soon. + */ + + /* Re enable the IRQ */ + dev->lower->irq(dev->lower, NULL, true); +} + +/**************************************************************************** + * Name: at86rf23x_irqwork_tx + * + * Description: + * Misc/unofficial device controls. + * + ****************************************************************************/ +static void at86rf23x_irqwork_tx(FAR struct at86rf23x_dev_s *dev) +{ + vdbg("6LOWPAN:Tx IRQ\n"); + + /* + * TODO: + * There needs to be more here but for now just alert the waiting + * thread. Maybe put it back into Rx mode + * + */ + + /* Re enable the IRQ */ + dev->lower->irq(dev->lower, NULL, true); + + sem_post(&dev->ieee.txsem); + + +} + +/**************************************************************************** + * Name: at86rf23x_transmit + * + * Description: + * transmission the packet. Send the packet to the radio and initiate the + * transmit process. Then block the function till we have a successful + * transmission + * + ****************************************************************************/ +static int at86rf23x_transmit(FAR struct ieee802154_dev_s *ieee, FAR struct ieee802154_packet_s *packet) +{ + FAR struct at86rf23x_dev_s *dev = (FAR struct at86rf23x_dev_s *)ieee; + /* + * TODO: + * A plan needs to be made on when we declare the transmission successful. + * 1. If the packet is sent + * 2. If we receive an ACK. + * 3. Where do we control the retry process? + */ + + if(at86rf23x_setTRXstate(dev, TRX_CMD_PLL_ON, false)) + { + at86rf23x_writeframe(dev->spi, packet->data, packet->len); + } + else + { + dbg("Transmit could not put the radio in a Tx state\n"); + return ERROR; + } + + /* put the thread that requested transfer to a waiting state */ + sem_wait(&dev->ieee.txsem); + /*TODO Verify that I want to stay in the PLL state or if I want to roll back to RX_ON */ + return OK; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: at86rf23x_init + * + * Description: + * Return an at86rf23x device for use by other drivers. + * + ****************************************************************************/ + +FAR struct ieee802154_dev_s *at86rf23x_init(FAR struct spi_dev_s *spi, FAR const struct at86rf23x_lower_s *lower) +{ + FAR struct at86rf23x_dev_s *dev; + struct ieee802154_cca_s cca; + + dev = &g_at86rf23x_devices[0]; + /* Attach the interface, lower driver, and devops */ + dev->spi = spi; + dev->lower = lower; + dev->ieee.ops = &at86rf23x_devops; + + /* attach irq */ + if (lower->irq(lower, at86rf23x_interrupt, false) != OK) + { + return NULL; + } + + sem_init(&dev->ieee.rxsem, 0, 0); + sem_init(&dev->ieee.txsem, 0, 0); + + /*Initialize device */ + at86rf23x_initialize(dev); + + /* Configure the desired IRQs of the devices */ + at86rf23x_setreg(dev->spi, RF23X_REG_IRQ_MASK, RF23X_IRQ_MASK_DEFAULT); + + /* Turn the PLL to the on state */ + at86rf23x_setTRXstate(dev, TRX_CMD_PLL_ON, false); + + + /*SEED value of the CSMA backoff algorithm. */ + + +#ifdef RF23X_ANTENNA_DIVERSITY + + /* Use antenna diversity */ + trx_bit_write(SR_ANT_CTRL, ANTENNA_DEFAULT); + trx_bit_write(SR_PDT_THRES, THRES_ANT_DIV_ENABLE); + trx_bit_write(SR_ANT_DIV_EN, ANT_DIV_ENABLE); + trx_bit_write(SR_ANT_EXT_SW_EN, ANT_EXT_SW_ENABLE); + +#endif + +#ifdef RF23X_TIMESTAMP + + /* Enable timestamp init code goes here */ + +#endif + +#ifdef RF23X_RF_FRONTEND_CTRL + + /* Init front end control code goes here */ + +#endif + /* Set the channel of the radio */ + at86rf23x_setchannel(&dev->ieee, 12); + + /* Configure the Pan id */ + // at86rf23x_setpanid (&dev->ieee, IEEE802154_PAN_DEFAULT); + /* Configure the Short Addr */ + // at86rf23x_setsaddr (&dev->ieee, IEEE802154_SADDR_UNSPEC); + /* Configure the IEEE Addr */ +// at86rf23x_seteaddr (&dev->ieee, IEEE802154_EADDR_UNSPEC); + + /* Default device params at86rf23x defaults to energy detect only */ + cca.use_ed = 1; + cca.use_cs = 0; + cca.edth = 0x60; /* CCA mode ED, no carrier sense, recommenced ED threshold -69 dBm */ + at86rf23x_setcca(&dev->ieee, &cca); + + + + /* Put the Device to RX ON Mode */ + // at86rf23x_setTRXstate(dev, TRX_CMD_RX_ON, false ); + + + /* Enable Radio IRQ */ + lower->irq(lower, at86rf23x_interrupt, true); + + return &dev->ieee; +} + diff --git a/drivers/wireless/ieee802154/at86rf23x.h b/drivers/wireless/ieee802154/at86rf23x.h new file mode 100644 index 00000000000..51c96ced3c0 --- /dev/null +++ b/drivers/wireless/ieee802154/at86rf23x.h @@ -0,0 +1,204 @@ +/* + * at86rf23x.h + * + * Created on: Feb 24, 2016 + * Author: poppe + */ + +#ifndef APPS_EXTERNAL_IEEE_AT86RF23X_H_ +#define APPS_EXTERNAL_IEEE_AT86RF23X_H_ + +#define RF23X_SPI_REG_READ 0x80 +#define RF23X_SPI_REG_WRITE 0xC0 +#define RF23X_SPI_FRAME_WRITE 0x60 +#define RF23X_SPI_FRAME_READ 0x20 +#define RF23X_SPI_SRAM_READ 0x00 +#define RF23X_SPI_SRAM_WRITE 0x40 + +/* us Times Constants for the RF233 */ +#define RF23X_TIME_RESET_BOOT 510 +#define RF23X_TIME_FORCE_TRXOFF 100 +#define RF23X_TIME_P_ON_TO_TRXOFF 510 +#define RF23X_TIME_SLEEP_TO_TRXOFF 1200 +#define RF23X_TIME_RESET 6 +#define RF23X_TIME_ED_MEASUREMENT 140 +#define RF23X_TIME_CCA 140 +#define RF23X_TIME_PLL_LOCK 150 +#define RF23X_TIME_FTN_TUNNING 25 +#define RF23X_TIME_NOCLK_TO_WAKE 6 +#define RF23X_TIME_CMD_FORCE_TRX_OFF 1 +#define RF23X_TIME_TRXOFF_TO_PLL 180 +#define RF23X_TIME_TRANSITION_PLL_ACTIVE 1 +#define RF23X_TIME_TRXOFF_TO_SLEEP 1200 + +#define RF23X_MAX_RETRY_RESET_TO_TRX_OFF 5 + + +#define RF23X_REG_TRXSTATUS 0x01 +#define RF23X_REG_TRXSTATE 0x02 +#define RF23X_REG_TRXCTRL0 0x03 +#define RF23X_REG_TRXCTRL1 0x04 +#define RF23X_REG_TXPWR 0x05 +#define RF23X_REG_RSSI 0x06 +#define RF23X_REG_EDLEVEL 0x07 +#define RF23X_REG_CCA 0x08 +#define RF23X_REG_THRES 0x09 +#define RF23X_REG_RXCTRL 0x0a +#define RF23X_REG_SFD 0x0b +#define RF23X_REG_TRXCTRL2 0x0c +#define RF23X_REG_ANT_DIV 0x0d +#define RF23X_REG_IRQ_MASK 0x0e +#define RF23X_REG_IRQ_STATUS 0x0f +#define RF23X_REG_VREG_CTRL 0x10 +#define RF23X_REG_BATMON 0x11 +#define RF23X_REG_XOSC_CTRL 0x12 +#define RF23X_REG_CCCTRL0 0x13 +#define RF23X_REG_CCCTRL1 0x14 +#define RF23X_REG_RXSYN 0x15 +#define RF23X_REG_TRXRPC 0x16 +#define RF23X_REG_XAHCTRL1 0x17 +#define RF23X_REG_FTNCTRL 0x18 +#define RF23X_REG_XAHCTRL2 0x19 +#define RF23X_REG_PLLCF 0x1a +#define RF23X_REG_PLLDCU 0x1b +#define RF23X_REG_PART 0x1c +#define RF23X_REG_VERSION 0x1d +#define RF23X_REG_MANID0 0x1e +#define RF23X_REG_MANID1 0x1f +#define RF23X_REG_SADDR0 0x20 +#define RF23X_REG_SADDR1 0x21 +#define RF23X_REG_PANID0 0x22 +#define RF23X_REG_PANID1 0x23 +#define RF23X_REG_IEEEADDR0 0x24 +#define RF23X_REG_IEEEADDR1 0x25 +#define RF23X_REG_IEEEADDR2 0x26 +#define RF23X_REG_IEEEADDR3 0x27 +#define RF23X_REG_IEEEADDR4 0x28 +#define RF23X_REG_IEEEADDR5 0x29 +#define RF23X_REG_IEEEADDR6 0x2a +#define RF23X_REG_IEEEADDR7 0x2b +#define RF23X_REG_XAHCTRL0 0x2c +#define RF23X_REG_CSMASEED0 0x2d +#define RF23X_REG_CSMASEED1 0x2e +#define RF23X_REG_CSMABE 0x2f +#define RF23X_REG_TSTCTRLDIGI 0x36 +#define RF23X_REG_TSTAGC 0x3c +#define RF23X_REG_SDM 0x3d +#define RF23X_REG_PHYTXTIME 0x3b +#define RF23X_REG_PHYPMUVALUE 0x3b + + +#define RF23X_TRXSTATUS_POS 0 +#define RF23X_TRXSTATUS_MASK 0x1f +#define RF23X_TRXSTATUS_STATUS RF23X_REG_TRXSTATUS, RF23X_TRXSTATUS_POS, RF23X_TRXSTATUS_MASK + +#define RF23X_TRXCMD_POS 0 +#define RF23X_TRXCMD_MASK 0x1f +#define RF23X_TRXCMD_STATE RF23X_REG_TRXSTATE, RF23X_TRXCMD_POS, RF23X_TRXCMD_MASK + + +#define RF23X_TXPWR_POS_4 0x00 +#define RF23X_TXPWR_POS_3_7 0x01 +#define RF23X_TXPWR_POS_3_4 0x02 +#define RF23X_TXPWR_POS_3 0x03 +#define RF23X_TXPWR_POS_2_5 0x04 +#define RF23X_TXPWR_POS_2 0x05 +#define RF23X_TXPWR_POS_1 0x06 +#define RF23X_TXPWR_0 0x07 +#define RF23X_TXPWR_NEG_1 0x08 +#define RF23X_TXPWR_NEG_2 0x09 +#define RF23X_TXPWR_NEG_3 0x0a +#define RF23X_TXPWR_NEG_4 0x0b +#define RF23X_TXPWR_NEG_6 0x0c +#define RF23X_TXPWR_NEG_8 0x0d +#define RF23X_TXPWR_NEG_12 0x0e +#define RF23X_TXPWR_NEG_17 0x0f + +/**************************************************************************** + * CCA_STATUS + ****************************************************************************/ +#define RF23X_CCA_MODE_CS_OR_ED 0x00 +#define RF23X_CCA_MODE_ED 0x01 +#define RF23X_CCA_MODE_CS 0x02 +#define RF23X_CCA_MODE_CS_AND_ED 0x03 + +#define RF23X_CCA_CHANNEL_POS 0 +#define RF23X_CCA_CHANNEL_MASK 0x1f +#define RF23X_CCA_BITS_CHANNEL RF23X_REG_CCA, RF23X_CCA_CHANNEL_POS, RF23X_CCA_CHANNEL_MASK +#define RF23X_CCA_MODE_POS 5 +#define RF23X_CCA_MODE_MASK 0x03 +#define RF23X_CCA_BITS_MODE RF23X_REG_CCA, RF23X_CCA_MODE_POS, RF23X_CCA_MODE_MASK + + +/**************************************************************************** + * XAH CTRL 1 + ****************************************************************************/ +#define RF23X_XAHCTRL1_PROM_MODE_POS 1 +#define RF23X_XAHCTRL1_PROM_MODE_MASK 0x01 +#define RF23X_XAHCTRL1_BITS_PROM_MODE RF23X_REG_XAHCTRL1, RF23X_XAHCTRL1_PROM_MODE_POS, RF23X_XAHCTRL1_PROM_MODE_MASK + +/**************************************************************************** + * CSMA SEED 0 + ****************************************************************************/ + +/**************************************************************************** + * CSMA SEED 1 + ****************************************************************************/ +#define RF23X_CSMASEED1_IAMCOORD_POS 3 +#define RF23X_CSMASEED1_IAMCOORD_MASK 0x1 +#define RF23X_CSMASEED1_IAMCOORD_BITS RF23X_REG_CSMASEED1, RF23X_CSMASEED1_IAMCOORD_POS, RF23X_CSMASEED1_IAMCOORD_MASK + +#define RF23X_CSMASEED1_AACK_DIS_ACK_POS +#define RF23X_CSMASEED1_AACK_SET_PD_POS +#define RF23X_CSMASEED1_AACK_FVN_MODE_POS +#define RF23X_CSMASEED1_ + + +/**************************************************************************** + * TRX Status + ****************************************************************************/ +#define TRX_STATUS_PON 0x00 +#define TRX_STATUS_BUSYRX 0x01 +#define TRX_STATUS_BUSYTX 0x02 +#define TRX_STATUS_RXON 0x06 +#define TRX_STATUS_TRXOFF 0x08 +#define TRX_STATUS_PLLON 0x09 +#define TRX_STATUS_SLEEP 0x0f +#define TRX_STATUS_DEEPSLEEP 0x10 +#define TRX_STATUS_BUSYRXACK 0x11 +#define TRX_STATUS_BUSYTXARET 0x12 +#define TRX_STATUS_RXAACKON 0x16 +#define TRX_STATUS_TXARETON 0x19 +#define TRX_STATUS_STATEINTRANS 0x1f + +/**************************************************************************** + * TRX Command + ****************************************************************************/ +#define TRX_CMD_NOP 0x00 +#define TRX_CMD_TX 0x02 +#define TRX_CMD_FORCETRXOFF 0x03 +#define TRX_CMD_FORCE_PLLON 0x04 +#define TRX_CMD_RX_ON 0x06 +#define TRX_CMD_TRXOFF 0x08 +#define TRX_CMD_PLL_ON 0x09 +#define TRX_CMD_PREP_DEEPSLEEP 0x10 +#define TRX_CMD_RX_AACK_ON 0x16 +#define TRX_CMD_TX_ARET_ON 0x19 + + +/**************************************************************************** + * IRQ MASK 0x0E + ****************************************************************************/ +#define RF23X_IRQ_MASK_LOCK_PLL (1<<0) +#define RF23X_IRQ_MASK_UNLOCK_PLL (1<<1) +#define RF23X_IRQ_MASK_RX_START (1<<2) +#define RF23X_IRQ_MASK_TRX_END (1<<3) +#define RF23X_IRQ_MASK_CCA_ED_DONE (1<<4) +#define RF23X_IRQ_MASK_AMI (1<<5) +#define RF23X_IRQ_MASK_TRX_UR (1<<6) +#define RF23X_IRQ_MASK_BAT_LOW (1<<7) + +#define RF23X_IRQ_MASK_DEFAULT (RF23X_IRQ_MASK_TRX_END) + + +#endif /* APPS_EXTERNAL_IEEE_AT86RF23X_H_ */ diff --git a/drivers/wireless/ieee802154/mrf24j40.c b/drivers/wireless/ieee802154/mrf24j40.c index fa7cfd815d3..cc831fd7830 100644 --- a/drivers/wireless/ieee802154/mrf24j40.c +++ b/drivers/wireless/ieee802154/mrf24j40.c @@ -91,15 +91,53 @@ #define MRF24J40_PA_ED 2 #define MRF24J40_PA_SLEEP 3 +/* IEEE 802.15.4 frame specifics */ + +/* Security Enabled */ + +#define IEEE802154_SEC_OFF 0x00 +#define IEEE802154_SEC_ON 0x08 + +/* Flags */ + +#define IEEE802154_PEND 0x10 +#define IEEE802154_ACK_REQ 0x20 +#define IEEE802154_INTRA 0x40 + +/* Dest Addressing modes */ + +#define IEEE802154_DADDR_NONE 0x00 +#define IEEE802154_DADDR_SHORT 0x08 +#define IEEE802154_DADDR_EXT 0x0A + +/* Src Addressing modes */ + +#define IEEE802154_SADDR_NONE 0x00 +#define IEEE802154_SADDR_SHORT 0x80 +#define IEEE802154_SADDR_EXT 0xA0 + +/* Frame control field masks, 2 bytes + * Seee IEEE 802.15.4/2003 7.2.1.1 page 112 + */ + +#define IEEE802154_FC1_FTYPE 0x03 /* Frame type, bits 0-2 */ +#define IEEE802154_FC1_SEC 0x08 /* Security Enabled, bit 3 */ +#define IEEE802154_FC1_PEND 0x10 /* Frame pending, bit 4 */ +#define IEEE802154_FC1_ACKREQ 0x20 /* Acknowledge request, bit 5 */ +#define IEEE802154_FC1_INTRA 0x40 /* Intra PAN, bit 6 */ +#define IEEE802154_FC2_DADDR 0x0C /* Dest addressing mode, bits 10-11 */ +#define IEEE802154_FC2_VERSION 0x30 /* Source addressing mode, bits 12-13 */ +#define IEEE802154_FC2_SADDR 0xC0 /* Source addressing mode, bits 14-15 */ + /**************************************************************************** * Private Types ****************************************************************************/ /* A MRF24J40 device instance */ -struct mrf24j40_dev_s +struct mrf24j40_radio_s { - struct ieee802154_dev_s ieee; /* The public device instance */ + struct ieee802154_radio_s ieee; /* The public device instance */ FAR struct spi_dev_s *spi; /* Saved SPI interface instance */ struct work_s irqwork; /* Interrupt continuation work queue support */ FAR const struct mrf24j40_lower_s *lower; /* Low-level MCU-specific support */ @@ -126,39 +164,39 @@ static void mrf24j40_lock (FAR struct spi_dev_s *spi); static void mrf24j40_setreg (FAR struct spi_dev_s *spi, uint32_t addr, uint8_t val); static uint8_t mrf24j40_getreg (FAR struct spi_dev_s *spi, uint32_t addr); -static int mrf24j40_resetrfsm (FAR struct mrf24j40_dev_s *dev); -static int mrf24j40_pacontrol (FAR struct mrf24j40_dev_s *dev, int mode); -static int mrf24j40_initialize(FAR struct mrf24j40_dev_s *dev); +static int mrf24j40_resetrfsm (FAR struct mrf24j40_radio_s *dev); +static int mrf24j40_pacontrol (FAR struct mrf24j40_radio_s *dev, int mode); +static int mrf24j40_initialize(FAR struct mrf24j40_radio_s *dev); -static int mrf24j40_setrxmode (FAR struct mrf24j40_dev_s *dev, int mode); -static int mrf24j40_regdump (FAR struct mrf24j40_dev_s *dev); -static void mrf24j40_irqwork_rx(FAR struct mrf24j40_dev_s *dev); -static void mrf24j40_irqwork_tx(FAR struct mrf24j40_dev_s *dev); +static int mrf24j40_setrxmode (FAR struct mrf24j40_radio_s *dev, int mode); +static int mrf24j40_regdump (FAR struct mrf24j40_radio_s *dev); +static void mrf24j40_irqwork_rx(FAR struct mrf24j40_radio_s *dev); +static void mrf24j40_irqwork_tx(FAR struct mrf24j40_radio_s *dev); static void mrf24j40_irqworker (FAR void *arg); static int mrf24j40_interrupt (int irq, FAR void *context); /* Driver operations */ -static int mrf24j40_setchannel (FAR struct ieee802154_dev_s *ieee, uint8_t chan); -static int mrf24j40_getchannel (FAR struct ieee802154_dev_s *ieee, FAR uint8_t *chan); -static int mrf24j40_setpanid (FAR struct ieee802154_dev_s *ieee, uint16_t panid); -static int mrf24j40_getpanid (FAR struct ieee802154_dev_s *ieee, FAR uint16_t *panid); -static int mrf24j40_setsaddr (FAR struct ieee802154_dev_s *ieee, uint16_t saddr); -static int mrf24j40_getsaddr (FAR struct ieee802154_dev_s *ieee, FAR uint16_t *saddr); -static int mrf24j40_seteaddr (FAR struct ieee802154_dev_s *ieee, FAR uint8_t *eaddr); -static int mrf24j40_geteaddr (FAR struct ieee802154_dev_s *ieee, FAR uint8_t *eaddr); -static int mrf24j40_setpromisc (FAR struct ieee802154_dev_s *ieee, bool promisc); -static int mrf24j40_getpromisc (FAR struct ieee802154_dev_s *ieee, FAR bool *promisc); -static int mrf24j40_setdevmode (FAR struct ieee802154_dev_s *ieee, uint8_t mode); -static int mrf24j40_getdevmode (FAR struct ieee802154_dev_s *ieee, FAR uint8_t *mode); -static int mrf24j40_settxpower (FAR struct ieee802154_dev_s *ieee, int32_t txpwr); -static int mrf24j40_gettxpower (FAR struct ieee802154_dev_s *ieee, FAR int32_t *txpwr); -static int mrf24j40_setcca (FAR struct ieee802154_dev_s *ieee, FAR struct ieee802154_cca_s *cca); -static int mrf24j40_getcca (FAR struct ieee802154_dev_s *ieee, FAR struct ieee802154_cca_s *cca); -static int mrf24j40_ioctl (FAR struct ieee802154_dev_s *ieee, int cmd, unsigned long arg); -static int mrf24j40_energydetect(FAR struct ieee802154_dev_s *ieee, FAR uint8_t *energy); -static int mrf24j40_rxenable (FAR struct ieee802154_dev_s *ieee, bool state, FAR struct ieee802154_packet_s *packet); -static int mrf24j40_transmit (FAR struct ieee802154_dev_s *ieee, FAR struct ieee802154_packet_s *packet); +static int mrf24j40_setchannel (FAR struct ieee802154_radio_s *ieee, uint8_t chan); +static int mrf24j40_getchannel (FAR struct ieee802154_radio_s *ieee, FAR uint8_t *chan); +static int mrf24j40_setpanid (FAR struct ieee802154_radio_s *ieee, uint16_t panid); +static int mrf24j40_getpanid (FAR struct ieee802154_radio_s *ieee, FAR uint16_t *panid); +static int mrf24j40_setsaddr (FAR struct ieee802154_radio_s *ieee, uint16_t saddr); +static int mrf24j40_getsaddr (FAR struct ieee802154_radio_s *ieee, FAR uint16_t *saddr); +static int mrf24j40_seteaddr (FAR struct ieee802154_radio_s *ieee, FAR uint8_t *eaddr); +static int mrf24j40_geteaddr (FAR struct ieee802154_radio_s *ieee, FAR uint8_t *eaddr); +static int mrf24j40_setpromisc (FAR struct ieee802154_radio_s *ieee, bool promisc); +static int mrf24j40_getpromisc (FAR struct ieee802154_radio_s *ieee, FAR bool *promisc); +static int mrf24j40_setdevmode (FAR struct ieee802154_radio_s *ieee, uint8_t mode); +static int mrf24j40_getdevmode (FAR struct ieee802154_radio_s *ieee, FAR uint8_t *mode); +static int mrf24j40_settxpower (FAR struct ieee802154_radio_s *ieee, int32_t txpwr); +static int mrf24j40_gettxpower (FAR struct ieee802154_radio_s *ieee, FAR int32_t *txpwr); +static int mrf24j40_setcca (FAR struct ieee802154_radio_s *ieee, FAR struct ieee802154_cca_s *cca); +static int mrf24j40_getcca (FAR struct ieee802154_radio_s *ieee, FAR struct ieee802154_cca_s *cca); +static int mrf24j40_ioctl (FAR struct ieee802154_radio_s *ieee, int cmd, unsigned long arg); +static int mrf24j40_energydetect(FAR struct ieee802154_radio_s *ieee, FAR uint8_t *energy); +static int mrf24j40_rxenable (FAR struct ieee802154_radio_s *ieee, bool state, FAR struct ieee802154_packet_s *packet); +static int mrf24j40_transmit (FAR struct ieee802154_radio_s *ieee, FAR struct ieee802154_packet_s *packet); /* These are pointers to ALL registered MRF24J40 devices. * This table is used during irqs to find the context @@ -167,9 +205,9 @@ static int mrf24j40_transmit (FAR struct ieee802154_dev_s *ieee, FAR stru * using the IRQ number. See the ENC28J60 or CC3000 drivers for reference. */ -static struct mrf24j40_dev_s g_mrf24j40_devices[1]; +static struct mrf24j40_radio_s g_mrf24j40_devices[1]; -static const struct ieee802154_devops_s mrf24j40_devops = +static const struct ieee802154_radioops_s mrf24j40_devops = { mrf24j40_setchannel, mrf24j40_getchannel, mrf24j40_setpanid , mrf24j40_getpanid, @@ -316,7 +354,7 @@ static uint8_t mrf24j40_getreg(FAR struct spi_dev_s *spi, uint32_t addr) * ****************************************************************************/ -static int mrf24j40_resetrfsm(FAR struct mrf24j40_dev_s *dev) +static int mrf24j40_resetrfsm(FAR struct mrf24j40_radio_s *dev) { uint8_t reg; @@ -341,7 +379,7 @@ static int mrf24j40_resetrfsm(FAR struct mrf24j40_dev_s *dev) * GPIO 3: PA power enable (not required on MB) ****************************************************************************/ -static int mrf24j40_pacontrol(FAR struct mrf24j40_dev_s *dev, int mode) +static int mrf24j40_pacontrol(FAR struct mrf24j40_radio_s *dev, int mode) { if (!dev->paenabled) { @@ -383,7 +421,7 @@ static int mrf24j40_pacontrol(FAR struct mrf24j40_dev_s *dev, int mode) * ****************************************************************************/ -static int mrf24j40_initialize(FAR struct mrf24j40_dev_s *dev) +static int mrf24j40_initialize(FAR struct mrf24j40_radio_s *dev) { /* Software reset */ @@ -415,7 +453,7 @@ static int mrf24j40_initialize(FAR struct mrf24j40_dev_s *dev) * ****************************************************************************/ -static int mrf24j40_setrxmode(FAR struct mrf24j40_dev_s *dev, int mode) +static int mrf24j40_setrxmode(FAR struct mrf24j40_radio_s *dev, int mode) { uint8_t reg; if (mode < MRF24J40_RXMODE_NORMAL || mode > MRF24J40_RXMODE_NOCRC) @@ -463,10 +501,10 @@ static int mrf24j40_setrxmode(FAR struct mrf24j40_dev_s *dev, int mode) * ****************************************************************************/ -static int mrf24j40_setchannel(FAR struct ieee802154_dev_s *ieee, +static int mrf24j40_setchannel(FAR struct ieee802154_radio_s *ieee, uint8_t chan) { - FAR struct mrf24j40_dev_s *dev = (FAR struct mrf24j40_dev_s *)ieee; + FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)ieee; if (chan<11 || chan>26) { @@ -498,10 +536,10 @@ static int mrf24j40_setchannel(FAR struct ieee802154_dev_s *ieee, * ****************************************************************************/ -static int mrf24j40_getchannel(FAR struct ieee802154_dev_s *ieee, +static int mrf24j40_getchannel(FAR struct ieee802154_radio_s *ieee, FAR uint8_t *chan) { - FAR struct mrf24j40_dev_s *dev = (FAR struct mrf24j40_dev_s *)ieee; + FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)ieee; *chan = dev->channel; @@ -516,10 +554,10 @@ static int mrf24j40_getchannel(FAR struct ieee802154_dev_s *ieee, * ****************************************************************************/ -static int mrf24j40_setpanid(FAR struct ieee802154_dev_s *ieee, +static int mrf24j40_setpanid(FAR struct ieee802154_radio_s *ieee, uint16_t panid) { - FAR struct mrf24j40_dev_s *dev = (FAR struct mrf24j40_dev_s *)ieee; + FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)ieee; mrf24j40_setreg(dev->spi, MRF24J40_PANIDH, (uint8_t)(panid>>8)); mrf24j40_setreg(dev->spi, MRF24J40_PANIDL, (uint8_t)(panid&0xFF)); @@ -538,10 +576,10 @@ static int mrf24j40_setpanid(FAR struct ieee802154_dev_s *ieee, * ****************************************************************************/ -static int mrf24j40_getpanid(FAR struct ieee802154_dev_s *ieee, +static int mrf24j40_getpanid(FAR struct ieee802154_radio_s *ieee, FAR uint16_t *panid) { - FAR struct mrf24j40_dev_s *dev = (FAR struct mrf24j40_dev_s *)ieee; + FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)ieee; *panid = dev->panid; @@ -558,10 +596,10 @@ static int mrf24j40_getpanid(FAR struct ieee802154_dev_s *ieee, * ****************************************************************************/ -static int mrf24j40_setsaddr(FAR struct ieee802154_dev_s *ieee, +static int mrf24j40_setsaddr(FAR struct ieee802154_radio_s *ieee, uint16_t saddr) { - FAR struct mrf24j40_dev_s *dev = (FAR struct mrf24j40_dev_s *)ieee; + FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)ieee; mrf24j40_setreg(dev->spi, MRF24J40_SADRH, (uint8_t)(saddr>>8)); mrf24j40_setreg(dev->spi, MRF24J40_SADRL, (uint8_t)(saddr&0xFF)); @@ -579,10 +617,10 @@ static int mrf24j40_setsaddr(FAR struct ieee802154_dev_s *ieee, * ****************************************************************************/ -static int mrf24j40_getsaddr(FAR struct ieee802154_dev_s *ieee, +static int mrf24j40_getsaddr(FAR struct ieee802154_radio_s *ieee, FAR uint16_t *saddr) { - FAR struct mrf24j40_dev_s *dev = (FAR struct mrf24j40_dev_s *)ieee; + FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)ieee; *saddr = dev->saddr; @@ -598,10 +636,10 @@ static int mrf24j40_getsaddr(FAR struct ieee802154_dev_s *ieee, * ****************************************************************************/ -static int mrf24j40_seteaddr(FAR struct ieee802154_dev_s *ieee, +static int mrf24j40_seteaddr(FAR struct ieee802154_radio_s *ieee, FAR uint8_t *eaddr) { - FAR struct mrf24j40_dev_s *dev = (FAR struct mrf24j40_dev_s *)ieee; + FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)ieee; int i; @@ -622,10 +660,10 @@ static int mrf24j40_seteaddr(FAR struct ieee802154_dev_s *ieee, * ****************************************************************************/ -static int mrf24j40_geteaddr(FAR struct ieee802154_dev_s *ieee, +static int mrf24j40_geteaddr(FAR struct ieee802154_radio_s *ieee, FAR uint8_t *eaddr) { - FAR struct mrf24j40_dev_s *dev = (FAR struct mrf24j40_dev_s *)ieee; + FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)ieee; memcpy(eaddr, dev->eaddr, 8); @@ -641,10 +679,10 @@ static int mrf24j40_geteaddr(FAR struct ieee802154_dev_s *ieee, * ****************************************************************************/ -static int mrf24j40_setpromisc(FAR struct ieee802154_dev_s *ieee, +static int mrf24j40_setpromisc(FAR struct ieee802154_radio_s *ieee, bool promisc) { - FAR struct mrf24j40_dev_s *dev = (FAR struct mrf24j40_dev_s *)ieee; + FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)ieee; return mrf24j40_setrxmode(dev, promisc ? MRF24J40_RXMODE_PROMISC : MRF24J40_RXMODE_NORMAL); @@ -658,10 +696,10 @@ static int mrf24j40_setpromisc(FAR struct ieee802154_dev_s *ieee, * ****************************************************************************/ -static int mrf24j40_getpromisc(FAR struct ieee802154_dev_s *ieee, +static int mrf24j40_getpromisc(FAR struct ieee802154_radio_s *ieee, FAR bool *promisc) { - FAR struct mrf24j40_dev_s *dev = (FAR struct mrf24j40_dev_s *)ieee; + FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)ieee; *promisc = (dev->rxmode == MRF24J40_RXMODE_PROMISC); @@ -676,10 +714,10 @@ static int mrf24j40_getpromisc(FAR struct ieee802154_dev_s *ieee, * ****************************************************************************/ -static int mrf24j40_setdevmode(FAR struct ieee802154_dev_s *ieee, +static int mrf24j40_setdevmode(FAR struct ieee802154_radio_s *ieee, uint8_t mode) { - FAR struct mrf24j40_dev_s *dev = (FAR struct mrf24j40_dev_s *)ieee; + FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)ieee; int ret = OK; uint8_t reg; @@ -728,10 +766,10 @@ static int mrf24j40_setdevmode(FAR struct ieee802154_dev_s *ieee, * ****************************************************************************/ -static int mrf24j40_getdevmode(FAR struct ieee802154_dev_s *ieee, +static int mrf24j40_getdevmode(FAR struct ieee802154_radio_s *ieee, FAR uint8_t *mode) { - FAR struct mrf24j40_dev_s *dev = (FAR struct mrf24j40_dev_s *)ieee; + FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)ieee; *mode = dev->devmode; @@ -748,10 +786,10 @@ static int mrf24j40_getdevmode(FAR struct ieee802154_dev_s *ieee, * ****************************************************************************/ -static int mrf24j40_settxpower(FAR struct ieee802154_dev_s *ieee, +static int mrf24j40_settxpower(FAR struct ieee802154_radio_s *ieee, int32_t txpwr) { - FAR struct mrf24j40_dev_s *dev = (FAR struct mrf24j40_dev_s *)ieee; + FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)ieee; uint8_t reg; int save_txpwr = txpwr; @@ -809,10 +847,10 @@ static int mrf24j40_settxpower(FAR struct ieee802154_dev_s *ieee, * ****************************************************************************/ -static int mrf24j40_gettxpower(FAR struct ieee802154_dev_s *ieee, +static int mrf24j40_gettxpower(FAR struct ieee802154_radio_s *ieee, FAR int32_t *txpwr) { - FAR struct mrf24j40_dev_s *dev = (FAR struct mrf24j40_dev_s *)ieee; + FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)ieee; *txpwr = dev->txpower; @@ -827,10 +865,10 @@ static int mrf24j40_gettxpower(FAR struct ieee802154_dev_s *ieee, * ****************************************************************************/ -static int mrf24j40_setcca(FAR struct ieee802154_dev_s *ieee, +static int mrf24j40_setcca(FAR struct ieee802154_radio_s *ieee, FAR struct ieee802154_cca_s *cca) { - FAR struct mrf24j40_dev_s *dev = (FAR struct mrf24j40_dev_s *)ieee; + FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)ieee; uint8_t mode; if (!cca->use_ed && !cca->use_cs) @@ -873,10 +911,10 @@ static int mrf24j40_setcca(FAR struct ieee802154_dev_s *ieee, * ****************************************************************************/ -static int mrf24j40_getcca(FAR struct ieee802154_dev_s *ieee, +static int mrf24j40_getcca(FAR struct ieee802154_radio_s *ieee, FAR struct ieee802154_cca_s *cca) { - FAR struct mrf24j40_dev_s *dev = (FAR struct mrf24j40_dev_s *)ieee; + FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)ieee; memcpy(cca, &dev->cca, sizeof(struct ieee802154_cca_s)); @@ -891,7 +929,7 @@ static int mrf24j40_getcca(FAR struct ieee802154_dev_s *ieee, * ****************************************************************************/ -static int mrf24j40_regdump(FAR struct mrf24j40_dev_s *dev) +static int mrf24j40_regdump(FAR struct mrf24j40_radio_s *dev) { uint32_t i; char buf[4+16*3+2+1]; @@ -941,10 +979,10 @@ static int mrf24j40_regdump(FAR struct mrf24j40_dev_s *dev) * ****************************************************************************/ -static int mrf24j40_ioctl(FAR struct ieee802154_dev_s *ieee, int cmd, +static int mrf24j40_ioctl(FAR struct ieee802154_radio_s *ieee, int cmd, unsigned long arg) { - FAR struct mrf24j40_dev_s *dev = (FAR struct mrf24j40_dev_s *)ieee; + FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)ieee; switch(cmd) { @@ -968,10 +1006,10 @@ static int mrf24j40_ioctl(FAR struct ieee802154_dev_s *ieee, int cmd, * ****************************************************************************/ -static int mrf24j40_energydetect(FAR struct ieee802154_dev_s *ieee, +static int mrf24j40_energydetect(FAR struct ieee802154_radio_s *ieee, FAR uint8_t *energy) { - FAR struct mrf24j40_dev_s *dev = (FAR struct mrf24j40_dev_s *)ieee; + FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)ieee; uint8_t reg; /* Manually enable the LNA*/ @@ -1019,9 +1057,9 @@ static int mrf24j40_energydetect(FAR struct ieee802154_dev_s *ieee, * ****************************************************************************/ -static int mrf24j40_transmit(FAR struct ieee802154_dev_s *ieee, FAR struct ieee802154_packet_s *packet) +static int mrf24j40_transmit(FAR struct ieee802154_radio_s *ieee, FAR struct ieee802154_packet_s *packet) { - FAR struct mrf24j40_dev_s *dev = (FAR struct mrf24j40_dev_s *)ieee; + FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)ieee; uint32_t addr; uint8_t reg; int ret; @@ -1030,7 +1068,7 @@ static int mrf24j40_transmit(FAR struct ieee802154_dev_s *ieee, FAR struct ieee8 mrf24j40_pacontrol(dev, MRF24J40_PA_AUTO); - addr = 0x80000000; + addr = MRF24J40_TXBUF_BASE; /* Enable tx int */ @@ -1118,22 +1156,19 @@ static int mrf24j40_transmit(FAR struct ieee802154_dev_s *ieee, FAR struct ieee8 * ****************************************************************************/ -static void mrf24j40_irqwork_tx(FAR struct mrf24j40_dev_s *dev) +static void mrf24j40_irqwork_tx(FAR struct mrf24j40_radio_s *dev) { uint8_t txstat; uint8_t reg; txstat = mrf24j40_getreg(dev->spi, MRF24J40_TXSTAT); - /* 1 means it failed, we want 1 to mean it worked. - * tx_ok = !(tmp & ~(1 << TXNSTAT)); - * retries = tmp >> 6; - * channel_busy = (tmp & (1 << CCAFAIL)); - */ + reg = mrf24j40_getreg(dev->spi, MRF24J40_TXSTAT); - //dbg("TXSTAT%02X!\n", txstat); -#warning TODO report errors - UNUSED(txstat); + /* 1 means it failed, we want 1 to mean it worked. */ + dev->ieee.txok = (reg & MRF24J40_TXSTAT_TXNSTAT) != MRF24J40_TXSTAT_TXNSTAT; + dev->ieee.txretries = (reg & MRF24J40_TXSTAT_X_MASK) >> MRF24J40_TXSTAT_X_SHIFT; + dev->ieee.txbusy = (reg & MRF24J40_TXSTAT_CCAFAIL) == MRF24J40_TXSTAT_CCAFAIL; /* Disable tx int */ @@ -1147,17 +1182,17 @@ static void mrf24j40_irqwork_tx(FAR struct mrf24j40_dev_s *dev) } /**************************************************************************** - * Name: mrf24j40_enablerx + * Name: mrf24j40_rxenable * * Description: * Enable reception of a packet. The interrupt will signal the rx semaphore. * ****************************************************************************/ -static int mrf24j40_rxenable(FAR struct ieee802154_dev_s *ieee, bool state, +static int mrf24j40_rxenable(FAR struct ieee802154_radio_s *ieee, bool state, FAR struct ieee802154_packet_s *packet) { - FAR struct mrf24j40_dev_s *dev = (FAR struct mrf24j40_dev_s *)ieee; + FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)ieee; uint8_t reg; if (state) @@ -1187,7 +1222,7 @@ static int mrf24j40_rxenable(FAR struct ieee802154_dev_s *ieee, bool state, * ****************************************************************************/ -static void mrf24j40_irqwork_rx(FAR struct mrf24j40_dev_s *dev) +static void mrf24j40_irqwork_rx(FAR struct mrf24j40_radio_s *dev) { uint32_t addr; uint32_t index; @@ -1207,7 +1242,7 @@ static void mrf24j40_irqwork_rx(FAR struct mrf24j40_dev_s *dev) /* Read packet */ - addr = 0x80000300; + addr = MRF24J40_RXBUF_BASE; dev->ieee.rxbuf->len = mrf24j40_getreg(dev->spi, addr++); /*dbg("len %3d\n", dev->ieee.rxbuf->len);*/ @@ -1255,7 +1290,7 @@ static void mrf24j40_irqwork_rx(FAR struct mrf24j40_dev_s *dev) static void mrf24j40_irqworker(FAR void *arg) { - FAR struct mrf24j40_dev_s *dev = (FAR struct mrf24j40_dev_s *)arg; + FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)arg; uint8_t intstat; DEBUGASSERT(dev); @@ -1310,7 +1345,7 @@ static int mrf24j40_interrupt(int irq, FAR void *context) * retrieve the priv structure using the irq number */ - register FAR struct mrf24j40_dev_s *dev = &g_mrf24j40_devices[0]; + register FAR struct mrf24j40_radio_s *dev = &g_mrf24j40_devices[0]; /* In complex environments, we cannot do SPI transfers from the interrupt * handler because semaphores are probably used to lock the SPI bus. In @@ -1342,14 +1377,14 @@ static int mrf24j40_interrupt(int irq, FAR void *context) * ****************************************************************************/ -FAR struct ieee802154_dev_s *mrf24j40_init(FAR struct spi_dev_s *spi, +FAR struct ieee802154_radio_s *mrf24j40_init(FAR struct spi_dev_s *spi, FAR const struct mrf24j40_lower_s *lower) { - FAR struct mrf24j40_dev_s *dev; + FAR struct mrf24j40_radio_s *dev; struct ieee802154_cca_s cca; #if 0 - dev = kmm_zalloc(sizeof(struct mrf24j40_dev_s)); + dev = kmm_zalloc(sizeof(struct mrf24j40_radio_s)); if (!dev) { @@ -1379,9 +1414,9 @@ FAR struct ieee802154_dev_s *mrf24j40_init(FAR struct spi_dev_s *spi, mrf24j40_initialize(dev); mrf24j40_setchannel(&dev->ieee, 11); - mrf24j40_setpanid (&dev->ieee, IEEE802154_PAN_DEFAULT); - mrf24j40_setsaddr (&dev->ieee, IEEE802154_SADDR_UNSPEC); - mrf24j40_seteaddr (&dev->ieee, IEEE802154_EADDR_UNSPEC); + mrf24j40_setpanid (&dev->ieee, 0xFFFF); + mrf24j40_setsaddr (&dev->ieee, 0xFFFF); + mrf24j40_seteaddr (&dev->ieee, (uint8_t*)"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"); /* Default device params */ diff --git a/drivers/wireless/ieee802154/mrf24j40.h b/drivers/wireless/ieee802154/mrf24j40.h index de3131e4df4..c530e61d630 100644 --- a/drivers/wireless/ieee802154/mrf24j40.h +++ b/drivers/wireless/ieee802154/mrf24j40.h @@ -97,18 +97,22 @@ #define MRF24J40_BBREG6 0x3E #define MRF24J40_CCAEDTH 0x3F -#define MRF24J40_RFCON0 0x80000200 -#define MRF24J40_RFCON1 0x80000201 -#define MRF24J40_RFCON2 0x80000202 -#define MRF24J40_RFCON3 0x80000203 -#define MRF24J40_RFCON5 0x80000205 -#define MRF24J40_RFCON6 0x80000206 -#define MRF24J40_RFCON7 0x80000207 -#define MRF24J40_RFCON8 0x80000208 -#define MRF24J40_SLPCAL0 0x80000209 -#define MRF24J40_SLPCAL1 0x8000020A -#define MRF24J40_SLPCAL2 0x8000020B -#define MRF24J40_RFSTATE 0x8000020F +#define MRF24J40_TXBUF_BASE 0x80000000 +#define MRF24J40_LONGREG_BASE 0x80000200 +#define MRF24J40_RXBUF_BASE 0x80000300 + +#define MRF24J40_RFCON0 (MRF24J40_LONGREG_BASE + 0x00) +#define MRF24J40_RFCON1 (MRF24J40_LONGREG_BASE + 0x01) +#define MRF24J40_RFCON2 (MRF24J40_LONGREG_BASE + 0x02) +#define MRF24J40_RFCON3 (MRF24J40_LONGREG_BASE + 0x03) +#define MRF24J40_RFCON5 (MRF24J40_LONGREG_BASE + 0x05) +#define MRF24J40_RFCON6 (MRF24J40_LONGREG_BASE + 0x06) +#define MRF24J40_RFCON7 (MRF24J40_LONGREG_BASE + 0x07) +#define MRF24J40_RFCON8 (MRF24J40_LONGREG_BASE + 0x08) +#define MRF24J40_SLPCAL0 (MRF24J40_LONGREG_BASE + 0x09) +#define MRF24J40_SLPCAL1 (MRF24J40_LONGREG_BASE + 0x0A) +#define MRF24J40_SLPCAL2 (MRF24J40_LONGREG_BASE + 0x0B) +#define MRF24J40_RFSTATE (MRF24J40_LONGREG_BASE + 0x0F) #define MRF24J40_RSSI 0x80000210 #define MRF24J40_SLPCON0 0x80000211 #define MRF24J40_SLPCON1 0x80000220 @@ -147,18 +151,18 @@ /* INTSTAT bits */ -#define MRF24J40_INTSTAT_SLPIF 0x80 -#define MRF24J40_INTSTAT_WAKEIF 0x40 -#define MRF24J40_INTSTAT_HSYMTMRIF 0x20 -#define MRF24J40_INTSTAT_SECIF 0x10 -#define MRF24J40_INTSTAT_RXIF 0x08 -#define MRF24J40_INTSTAT_TXG2IF 0x04 -#define MRF24J40_INTSTAT_TXG1IF 0x02 -#define MRF24J40_INTSTAT_TXNIF 0x01 +#define MRF24J40_INTSTAT_TXNIF (1 << 0) +#define MRF24J40_INTSTAT_TXG1IF (1 << 1) +#define MRF24J40_INTSTAT_TXG2IF (1 << 2) +#define MRF24J40_INTSTAT_RXIF (1 << 3) +#define MRF24J40_INTSTAT_SECIF (1 << 4) +#define MRF24J40_INTSTAT_HSYMTMRIF (1 << 5) +#define MRF24J40_INTSTAT_WAKEIF (1 << 6) +#define MRF24J40_INTSTAT_SLPIF (1 << 7) /* RXMCR bits */ -#define MRF24J40_RXMCR_PROMI 0x01 /* Enable promisc mode (rx all valid packets) */ +#define MRF24J40_RXMCR_PROMI (1 << 0) /* Enable promisc mode (rx all valid packets) */ #define MRF24J40_RXMCR_ERRPKT 0x02 /* Do not check CRC */ #define MRF24J40_RXMCR_COORD 0x04 /* Enable coordinator mode ??? DIFFERENCE ??? - not used in datasheet! */ #define MRF24J40_RXMCR_PANCOORD 0x08 /* Enable PAN coordinator mode ??? DIFFERENCE ??? */ @@ -166,7 +170,7 @@ /* TXMCR bits */ -#define MRF24J40_TXMCR_CSMABF0 0x01 +#define MRF24J40_TXMCR_CSMABF0 (1 << 0) #define MRF24J40_TXMCR_CSMABF1 0x02 #define MRF24J40_TXMCR_CSMABF2 0x04 #define MRF24J40_TXMCR_MACMINBE0 0x08 @@ -184,7 +188,7 @@ #define MRF24J40_INTCON_RXIE 0x08 #define MRF24J40_INTCON_TXG2IE 0x04 #define MRF24J40_INTCON_TXG1IE 0x02 -#define MRF24J40_INTCON_TXNIE 0x01 +#define MRF24J40_INTCON_TXNIE (1 << 0) /* BBREG1 bits */ @@ -197,10 +201,17 @@ /* TXNCON bits */ -#define MRF24J40_TXNCON_TXNTRIG 0x01 /* Trigger packet tx, automatically cleared */ +#define MRF24J40_TXNCON_TXNTRIG (1 << 0) /* Trigger packet tx, automatically cleared */ #define MRF24J40_TXNCON_TXNSECEN 0x02 /* Enable security */ #define MRF24J40_TXNCON_TXNACKREQ 0x04 /* An ACK is requested for this pkt */ #define MRF24J40_TXNCON_INDIRECT 0x08 /* Activate indirect tx bit (for coordinators) */ #define MRF24J40_TXNCON_FPSTAT 0x10 /* Status of the frame pending big in txed acks */ +/* TXSTAT bits */ + +#define MRF24J40_TXSTAT_TXNSTAT (1 << 0) +#define MRF24J40_TXSTAT_CCAFAIL (1 << 5) +#define MRF24J40_TXSTAT_X_SHIFT 6 +#define MRF24J40_TXSTAT_X_MASK (3 << MRF24J40_TXSTAT_X_SHIFT) + #endif /* __DRIVERS_IEEE802154_MRF24J40_H */ diff --git a/include/nuttx/fs/ioctl.h b/include/nuttx/fs/ioctl.h index e404057d7e6..1b0e4f9a009 100644 --- a/include/nuttx/fs/ioctl.h +++ b/include/nuttx/fs/ioctl.h @@ -83,6 +83,7 @@ #define _LOOPBASE (0x1e00) /* Loop device commands */ #define _MODEMBASE (0x1f00) /* Modem ioctl commands */ #define _I2CBASE (0x2000) /* I2C driver commands */ +#define _MAC854BASE (0x2100) /* 802.15.4 device ioctl commands */ /* boardctl commands share the same number space */ @@ -381,6 +382,12 @@ #define _I2CIOCVALID(c) (_IOC_TYPE(c)==_I2CBASE) #define _I2CIOC(nr) _IOC(_I2CBASE,nr) +/* 802.15.4 MAC driver ioctl definitions *******************************************/ +/* (see nuttx/ieee802154/ieee802154_dev.h */ + +#define _MAC854IOCVALID(c) (_IOC_TYPE(c)==_MAC854BASE) +#define _MAC854IOC(nr) _IOC(_MAC854BASE,nr) + /* boardctl() command definitions *******************************************/ #define _BOARDIOCVALID(c) (_IOC_TYPE(c)==_BOARDBASE) diff --git a/include/nuttx/wireless/ieee802154/at86rf23x.h b/include/nuttx/wireless/ieee802154/at86rf23x.h new file mode 100644 index 00000000000..974e2456e2d --- /dev/null +++ b/include/nuttx/wireless/ieee802154/at86rf23x.h @@ -0,0 +1,100 @@ +/**************************************************************************** + * include/nuttx/ieee802154/at86rf23x.h + * + * Copyright (C) 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2014-2015 Sebastien Lorquet. All rights reserved. + * Author: Sebastien Lorquet + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_IEEE802154_AT86RF23X_H +#define __INCLUDE_NUTTX_IEEE802154_AT86RF23X_H + +/* The at86rf23x provides interrupts to the MCU via a GPIO pin. The + * following structure provides an MCU-independent mechanixm for controlling + * the at86rf23x GPIO interrupt. + * + * The at86rf23x interrupt is an active low, *level* interrupt. From Datasheet: + * "Note 1: The INTEDGE polarity defaults to: + * 0 = Falling Edge. Ensure that the inter- + * rupt polarity matches the interrupt pin + * polarity of the host microcontroller. + * Note 2: The INT pin will remain high or low, + * depending on INTEDGE polarity setting, + * until INTSTAT register is read." + */ + +struct at86rf23x_lower_s +{ + int (*irq)(FAR const struct at86rf23x_lower_s *lower, xcpt_t handler, int state); + void (*slptr)(FAR const struct at86rf23x_lower_s *lower, int state); + void (*reset)(FAR const struct at86rf23x_lower_s *lower, int state); +}; + +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" { +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Function: at86rf23x_init + * + * Description: + * Initialize the IEEE802.15.4 driver. The at86rf23x device is assumed to be + * in the post-reset state upon entry to this function. + * + * Parameters: + * spi - A reference to the platform's SPI driver for the at86rf23x + * lower - The MCU-specific interrupt used to control low-level MCU + * functions (i.e., at86rf23x GPIO interrupts). + * devno - If more than one at86rf23x is supported, then this is the + * zero based number that identifies the at86rf23x; + * + * Returned Value: + * OK on success; Negated errno on failure. + * + * Assumptions: + * + ****************************************************************************/ + +FAR struct ieee802154_dev_s *at86rf23x_init(FAR struct spi_dev_s *spi, FAR const struct at86rf23x_lower_s *lower); + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* __INCLUDE_NUTTX_IEEE802154__AT86RF23X_H */ diff --git a/include/nuttx/wireless/ieee802154/ieee802154_mac.h b/include/nuttx/wireless/ieee802154/ieee802154_mac.h new file mode 100644 index 00000000000..439825391a9 --- /dev/null +++ b/include/nuttx/wireless/ieee802154/ieee802154_mac.h @@ -0,0 +1,368 @@ +/**************************************************************************** + * include/nuttx/wireless/ieee802154/ieee802154_mac.h + * + * Copyright (C) 2016 Sebastien Lorquet. All rights reserved. + * Author: Sebastien Lorquet + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_WIRELESS_IEEE802154_IEEE802154_MAC_H +#define __INCLUDE_NUTTX_WIRELESS_IEEE802154_IEEE802154_MAC_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/* Configuration ************************************************************/ +/* None at the moment */ + +/* IEEE 802.15.4 MAC Interface **********************************************/ + +/* Some addresses */ + +#define IEEE802154_PAN_UNSPEC (uint16_t)0xFFFF +#define IEEE802154_SADDR_UNSPEC (uint16_t)0xFFFF +#define IEEE802154_SADDR_BCAST (uint16_t)0xFFFE +#define IEEE802154_EADDR_UNSPEC (uint8_t*)"\xff\xff\xff\xff\xff\xff\xff\xff" + +/* IEEE 802.15.4 MAC status codes */ + +enum +{ + MAC802154_STATUS_OK = 0, + MAC802154_STATUS_BEACON_LOSS = 0xE0, + MAC802154_STATUS_CHANNEL_ACCESS_FAILURE, + MAC802154_STATUS_DENIED, + MAC802154_STATUS_DISABLE_TRX_FAILURE, + MAC802154_STATUS_FAILED_SECURITY_CHECK, + MAC802154_STATUS_FRAME_TOO_LONG, + MAC802154_STATUS_INVALID_GTS, + MAC802154_STATUS_INVALID_HANDLE, + MAC802154_STATUS_INVALID_PARAMETER, + MAC802154_STATUS_NO_ACK, + MAC802154_STATUS_NO_BEACON, + MAC802154_STATUS_NO_DATA, + MAC802154_STATUS_NO_SHORT_ADDRESS, + MAC802154_STATUS_OUT_OF_CAP, + MAC802154_STATUS_PAN_ID_CONFLICT, + MAC802154_STATUS_REALIGNMENT, + MAC802154_STATUS_TRANSACTION_EXPIRED, + MAC802154_STATUS_TRANSACTION_OVERFLOW, + MAC802154_STATUS_TX_ACTIVE, + MAC802154_STATUS_UNAVAILABLE_KEY, + MAC802154_STATUS_UNSUPPORTED_ATTRIBUTE +}; + +/* IEEE 802.15.4 PHY constants */ +#define MAC802154_aMaxPHYPacketSize 127 +#define MAC802154_aTurnaroundTime 12 /*symbol periods*/ + +/* IEEE 802.15.4 MAC constants */ +#define MAC802154_aBaseSlotDuration 60 +#define MAC802154_aNumSuperframeSlots 16 +#define MAC802154_aBaseSuperframeDuration (MAC802154_aBaseSlotDuration * MAC802154_aNumSuperframeSlots) +#define MAC802154_aMaxBE 5 +#define MAC802154_aMaxBeaconOverhead 75 +#define MAC802154_aMaxBeaconPayloadLength (MAC802154_aMaxPHYPacketSize - MAC802154_aMaxBeaconOverhead) +#define MAC802154_aGTSDescPersistenceTime 4 +#define MAC802154_aMaxFrameOverhead 25 +#define MAC802154_aMaxFrameResponseTime 1220 +#define MAC802154_aMaxFrameRetries 3 +#define MAC802154_aMaxLostBeacons 4 +#define MAC802154_aMaxMACFrameSize (MAC802154_aMaxPHYPacketSize - MAC802154_aMaxFrameOverhead) +#define MAC802154_aMaxSIFSFrameSize 18 +#define MAC802154_aMinCAPLength 440 +#define MAC802154_aMinLIFSPeriod 40 +#define MAC802154_aMinSIFSPeriod 12 +#define MAC802154_aResponseWaitTime (32 * MAC802154_aBaseSuperframeDuration) +#define MAC802154_aUnitBackoffPeriod 20 + + +/* IEEE 802.15.4 PHY/MAC PIB attributes IDs */ +enum +{ + MAC802154_phyCurrentChannel = 0x00, + MAC802154_phyChannelsSupported, + MAC802154_phyTransmitPower, + MAC802154_phyCCAMode, + MAC802154_macAckWaitDuration = 0x40, + MAC802154_macAssociationPermit, + MAC802154_macAutoRequest, + MAC802154_macBattLifeExt, + MAC802154_macBattLifeExtPeriods, + MAC802154_macBeaconPayload, + MAC802154_macBeaconPayloadLength, + MAC802154_macBeaconOrder, + MAC802154_macBeaconTxTime, + MAC802154_macBSN, + MAC802154_macCoordExtendedAddress, + MAC802154_macCoordShortAddress, + MAC802154_macDSN, + MAC802154_macGTSPermit, + MAC802154_macMaxCSMABackoffs, + MAC802154_macMinBE, + MAC802154_macPANId, + MAC802154_macPromiscuousMode, + MAC802154_macRxOnWhenIdle, + MAC802154_macShortAddress, + MAC802154_macSuperframeOrder, + MAC802154_macTransactionPersistenceTime, + MAC802154_macACLEntryDescriptorSet = 0x70, + MAC802154_macACLEntryDescriptorSetSize, + MAC802154_macDefaultSecurity, + MAC802154_macDefaultSecurityMaterialLength, + MAC802154_macDefaultSecurityMaterial, + MAC802154_macDefaultSecuritySuite, + MAC802154_macSecurityMode +}; + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/* IEEE 802.15.4 Device address + * The addresses in ieee802154 have several formats: + * No address : [none] + * Short address + PAN id : PPPP/SSSS + * Extended address + PAN id : PPPP/LLLLLLLLLLLLLLLL + */ + +struct ieee802154_addr_s +{ + uint8_t ia_len; /* structure length, 0/2/8 */ + uint16_t ia_panid; /* PAN identifier, can be IEEE802154_PAN_UNSPEC */ + union { + uint16_t _ia_saddr; /* short address */ + uint8_t _ia_eaddr[8]; /* extended address */ + } ia_addr; +#define ia_saddr ia_addr._ia_saddr +#define ia_eaddr ia_addr._ia_eaddr +}; +#define IEEE802154_ADDRSTRLEN 22 /* (2*2+1+8*2, PPPP/EEEEEEEEEEEEEEEE) */ + +/* Operations */ + +struct ieee802154_mac_s; + +struct ieee802154_macops_s +{ + /* Requests, confirmed asynchronously via callbacks */ + + CODE int req_data (struct ieee802154_mac_s *mac, /* Transmit a data frame */ + uint8_t handle, + uint8_t *buf, + int len); + + CODE int req_purge (struct ieee802154_mac_s *mac, /* Cancel transmission of a data frame */ + uint8_t handle); + + CODE int req_associate (struct ieee802154_mac_s *mac, /* Start association with coordinator */ + uint16_t panid, + uint8_t *coordeadr); + + CODE int req_disassociate(struct ieee802154_mac_s *mac, /* Start disassociation with coordinator */ + uint8_t *eadr, + uint8_t reason); + + CODE int req_get (struct ieee802154_mac_s *mac, /* Read the PIB */ + int attribute); + + CODE int req_gts (struct ieee802154_mac_s *mac, /* Allocate or deallocate a GTS */ + uint8_t* characteristics); + + CODE int req_reset (struct ieee802154_mac_s *mac, /* MAC layer reset */ + bool setdefaults); + + CODE int req_rxenable (struct ieee802154_mac_s *mac, /* PHY receiver control */ + bool deferrable, + int ontime, + int duration); + + CODE int req_scan (struct ieee802154_mac_s *mac, /* Start a network scan */ + uint8_t type, + uint32_t channels, + int duration); + + CODE int req_set (struct ieee802154_mac_s *mac, /* Change the PIB */ + int attribute, + uint8_t *value, + int valuelen); + + CODE int req_start (struct ieee802154_mac_s *mac, + uint16_t panid, + int channel, + uint8_t bo, + uint8_t fo, + bool coord, + bool batext, + bool realign); + + CODE int req_sync (struct ieee802154_mac_s *mac, + int channel, + bool track); + + CODE int req_poll (struct ieee802154_mac_s *mac, + uint8_t *coordaddr); + + /* Synchronous Responses to Indications received via callbacks */ + + CODE int rsp_associate (struct ieee802154_mac_s *mac, /* Reply to an association request */ + uint8_t eadr, + uint16_t saddr, + int status); + + CODE int rsp_orphan (struct ieee802154_mac_s *mac, /* Orphan device management */ + uint8_t *orphanaddr, + uint16_t saddr, + bool associated); +}; + +/* Notifications */ + +struct ieee802154_maccb_s +{ + /* Asynchronous confirmations to requests */ + + CODE int conf_data (struct ieee802154_mac_s *mac, /* Data frame was received by remote device */ + uint8_t *buf, + int len); + CODE int conf_purge (struct ieee802154_mac_s *mac, /* Data frame was purged */ + uint8_t handle, + int status); + CODE int conf_associate (struct ieee802154_mac_s *mac, /* Association request completed */ + uint16_t saddr, + int status); + CODE int conf_disassociate(struct ieee802154_mac_s *mac, /* Disassociation request completed */ + int status); + CODE int conf_get (struct ieee802154_mac_s *mac, /* PIB data returned */ + int status, + int attribute, + uint8_t *value, + int valuelen); + CODE int conf_gts (struct ieee802154_mac_s *mac, /* GTS management completed */ + uint8_t *characteristics, + int status); + CODE int conf_reset (struct ieee802154_mac_s *mac, /* MAC reset completed */ + int status); + CODE int conf_rxenable (struct ieee802154_mac_s *mac, + int status); + CODE int conf_scan (struct ieee802154_mac_s *mac, + int status, + uint8_t type, + uint32_t unscanned, + int rsltsize, + uint8_t *edlist, + uint8_t *pandescs); + CODE int conf_set (struct ieee802154_mac_s *mac, + int status, int attribute); + CODE int conf_start (struct ieee802154_mac_s *mac, + int status); + CODE int conf_poll (struct ieee802154_mac_s *mac, + int status); + + /* Asynchronous event indications, replied to synchronously with responses */ + + CODE int ind_data (struct ieee802154_mac_s *mac, /* Data frame received */ + uint8_t *buf, + int len); + CODE int ind_associate (struct ieee802154_mac_s *mac, /* Association request received */ + uint16_t clipanid, + uint8_t *clieaddr); + CODE int ind_disassociate (struct ieee802154_mac_s *mac, /* Disassociation request received */ + uint8_t *eadr, + uint8_t reason); + CODE int ind_beaconnotify (struct ieee802154_mac_s *mac, /* Beacon notification */ + uint8_t *bsn, + uint_t *pandesc, + uint8_t *sdu, + int sdulen); + CODE int ind_gts (struct ieee802154_mac_s *mac, /* GTS management request received */ + uint8_t *devaddr, + uint8_t *characteristics); + CODE int ind_orphan (struct ieee802154_mac_s *mac, /* Orphan device detected */ + uint8_t *orphanaddr); + CODE int ind_commstatus (struct ieee802154_mac_s *mac, + uint16_t panid, + uint8_t *src, + uint8_t *dst, + int status); + CODE int ind_syncloss (struct ieee802154_mac_s *mac, + int reason); +}; + +struct ieee802154_radio_s; + +struct ieee802154_mac_s +{ + struct ieee802154_radio_s *radio; + struct ieee802154_macops_s ops; + struct ieee802154_maccb_s cbs; +}; + +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * 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 . + */ +FAR struct ieee802154_mac_s * mac802154_register(FAR struct ieee802154_radio_s *radiodev, struct ieee802154_maccb_s *callbacks); + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* __INCLUDE_NUTTX_WIRELESS_IEEE802154_MRF24J40_H */ diff --git a/include/nuttx/wireless/ieee802154/ieee802154_radio.h b/include/nuttx/wireless/ieee802154/ieee802154_radio.h index c3439feb897..06276b2870e 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_radio.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_radio.h @@ -33,8 +33,8 @@ * ****************************************************************************/ -#ifndef __INCLUDE_NUTTX_WIRELESS_IEEE802154_IEEE802154_H -#define __INCLUDE_NUTTX_WIRELESS_IEEE802154_IEEE802154_H +#ifndef __INCLUDE_NUTTX_WIRELESS_IEEE802154_IEEE802154_RADIO_H +#define __INCLUDE_NUTTX_WIRELESS_IEEE802154_IEEE802154_RADIO_H /**************************************************************************** * Included Files @@ -48,70 +48,13 @@ /**************************************************************************** * Pre-Processor Definitions ****************************************************************************/ + /* Configuration ************************************************************/ -/* None at the moment */ -/* IEEE 802.15.4 MAC Interface **********************************************/ +/* IEEE 802.15.4 Radio Interface **********************************************/ -/* Frame control field masks, 2 bytes - * Seee IEEE 802.15.4/2003 7.2.1.1 page 112 - */ - -#define IEEE802154_FC1_FTYPE 0x03 /* Frame type, bits 0-2 */ -#define IEEE802154_FC1_SEC 0x08 /* Security Enabled, bit 3 */ -#define IEEE802154_FC1_PEND 0x10 /* Frame pending, bit 4 */ -#define IEEE802154_FC1_ACKREQ 0x20 /* Acknowledge request, bit 5 */ -#define IEEE802154_FC1_INTRA 0x40 /* Intra PAN, bit 6 */ -#define IEEE802154_FC2_DADDR 0x0C /* Dest addressing mode, bits 10-11 */ -#define IEEE802154_FC2_VERSION 0x30 /* Source addressing mode, bits 12-13 */ -#define IEEE802154_FC2_SADDR 0xC0 /* Source addressing mode, bits 14-15 */ - -/* Frame Type */ - -#define IEEE802154_FRAME_BEACON 0x00 -#define IEEE802154_FRAME_DATA 0x01 -#define IEEE802154_FRAME_ACK 0x02 -#define IEEE802154_FRAME_COMMAND 0x03 - -/* Security Enabled */ - -#define IEEE802154_SEC_OFF 0x00 -#define IEEE802154_SEC_ON 0x08 - -/* Flags */ - -#define IEEE802154_PEND 0x10 -#define IEEE802154_ACK_REQ 0x20 -#define IEEE802154_INTRA 0x40 - -/* Dest Addressing modes */ - -#define IEEE802154_DADDR_NONE 0x00 -#define IEEE802154_DADDR_SHORT 0x08 -#define IEEE802154_DADDR_EXT 0x0A - -/* Src Addressing modes */ - -#define IEEE802154_SADDR_NONE 0x00 -#define IEEE802154_SADDR_SHORT 0x80 -#define IEEE802154_SADDR_EXT 0xA0 - -/* Some addresses */ - -#define IEEE802154_PAN_DEFAULT (uint16_t)0xFFFF -#define IEEE802154_SADDR_UNSPEC (uint16_t)0xFFFF -#define IEEE802154_SADDR_BCAST (uint16_t)0xFFFE -#define IEEE802154_EADDR_UNSPEC (uint8_t*)"\xff\xff\xff\xff\xff\xff\xff\xff" - -#define IEEE802154_CMD_ASSOC_REQ 0x01 -#define IEEE802154_CMD_ASSOC_RSP 0x02 -#define IEEE802154_CMD_DIS_NOT 0x03 -#define IEEE802154_CMD_DATA_REQ 0x04 -#define IEEE802154_CMD_PANID_CONF_NOT 0x05 -#define IEEE802154_CMD_ORPHAN_NOT 0x06 -#define IEEE802154_CMD_BEACON_REQ 0x07 -#define IEEE802154_CMD_COORD_REALIGN 0x08 -#define IEEE802154_CMD_GTS_REQ 0x09 +/* This layer only knows radio frames. There are no 802.15.4 specific bits + * at this layer. */ /* Device modes */ @@ -135,73 +78,75 @@ struct ieee802154_cca_s { uint8_t use_ed : 1; /* CCA using ED */ uint8_t use_cs : 1; /* CCA using carrier sense */ - uint8_t edth; /* Energy detection threshold for CCA */ - uint8_t csth; /* Carrier sense threshold for CCA */ + uint8_t edth; /* Energy detection threshold for CCA */ + uint8_t csth; /* Carrier sense threshold for CCA */ }; -struct ieee802154_dev_s; +struct ieee802154_radio_s; -struct ieee802154_devops_s +struct ieee802154_radioops_s { - CODE int (*setchannel)(FAR struct ieee802154_dev_s *dev, uint8_t channel); - CODE int (*getchannel)(FAR struct ieee802154_dev_s *dev, + CODE int (*setchannel)(FAR struct ieee802154_radio_s *dev, uint8_t channel); + CODE int (*getchannel)(FAR struct ieee802154_radio_s *dev, FAR uint8_t *channel); - CODE int (*setpanid)(FAR struct ieee802154_dev_s *dev, uint16_t panid); - CODE int (*getpanid)(FAR struct ieee802154_dev_s *dev, + CODE int (*setpanid)(FAR struct ieee802154_radio_s *dev, uint16_t panid); + CODE int (*getpanid)(FAR struct ieee802154_radio_s *dev, FAR uint16_t *panid); - CODE int (*setsaddr)(FAR struct ieee802154_dev_s *dev, uint16_t saddr); - CODE int (*getsaddr)(FAR struct ieee802154_dev_s *dev, + CODE int (*setsaddr)(FAR struct ieee802154_radio_s *dev, uint16_t saddr); + CODE int (*getsaddr)(FAR struct ieee802154_radio_s *dev, FAR uint16_t *saddr); - CODE int (*seteaddr)(FAR struct ieee802154_dev_s *dev, + CODE int (*seteaddr)(FAR struct ieee802154_radio_s *dev, FAR uint8_t *laddr); - CODE int (*geteaddr)(FAR struct ieee802154_dev_s *dev, + CODE int (*geteaddr)(FAR struct ieee802154_radio_s *dev, FAR uint8_t *laddr); - CODE int (*setpromisc)(FAR struct ieee802154_dev_s *dev, bool promisc); - CODE int (*getpromisc)(FAR struct ieee802154_dev_s *dev, + CODE int (*setpromisc)(FAR struct ieee802154_radio_s *dev, bool promisc); + CODE int (*getpromisc)(FAR struct ieee802154_radio_s *dev, FAR bool *promisc); - CODE int (*setdevmode)(FAR struct ieee802154_dev_s *dev, uint8_t devmode); - CODE int (*getdevmode)(FAR struct ieee802154_dev_s *dev, + CODE int (*setdevmode)(FAR struct ieee802154_radio_s *dev, uint8_t devmode); + CODE int (*getdevmode)(FAR struct ieee802154_radio_s *dev, FAR uint8_t *devmode); - CODE int (*settxpower)(FAR struct ieee802154_dev_s *dev, + CODE int (*settxpower)(FAR struct ieee802154_radio_s *dev, int32_t txpwr); /* unit = 1 mBm = 1/100 dBm */ - CODE int (*gettxpower)(FAR struct ieee802154_dev_s *dev, + CODE int (*gettxpower)(FAR struct ieee802154_radio_s *dev, FAR int32_t *txpwr); - CODE int (*setcca)(FAR struct ieee802154_dev_s *dev, + CODE int (*setcca)(FAR struct ieee802154_radio_s *dev, FAR struct ieee802154_cca_s *cca); - CODE int (*getcca)(FAR struct ieee802154_dev_s *dev, + CODE int (*getcca)(FAR struct ieee802154_radio_s *dev, FAR struct ieee802154_cca_s *cca); - CODE int (*ioctl)(FAR struct ieee802154_dev_s *ieee, int cmd, + CODE int (*ioctl)(FAR struct ieee802154_radio_s *ieee, int cmd, unsigned long arg); - CODE int (*energydetect)(FAR struct ieee802154_dev_s *dev, + CODE int (*energydetect)(FAR struct ieee802154_radio_s *dev, FAR uint8_t *energy); - CODE int (*rxenable)(FAR struct ieee802154_dev_s *dev, bool state, + CODE int (*rxenable)(FAR struct ieee802154_radio_s *dev, bool state, FAR struct ieee802154_packet_s *packet); - CODE int (*transmit)(FAR struct ieee802154_dev_s *dev, + CODE int (*transmit)(FAR struct ieee802154_radio_s *dev, FAR struct ieee802154_packet_s *packet); /*TODO beacon/sf order*/ }; -struct ieee802154_dev_s +struct ieee802154_radio_s { - FAR const struct ieee802154_devops_s *ops; + FAR const struct ieee802154_radioops_s *ops; /* Packet reception management */ - struct ieee802154_packet_s *rxbuf; - sem_t rxsem; + struct ieee802154_packet_s *rxbuf; /* packet reception buffer, filled by rx interrupt, NULL if rx not enabled */ + sem_t rxsem; /* Semaphore posted after reception of a packet */ /* Packet transmission management */ - - sem_t txsem; + bool txok; /* Last transmission status, filled by tx interrupt */ + bool txbusy; /* Last transmission failed because channel busy */ + uint8_t txretries; /* Last transmission required this much retries */ + sem_t txsem; /* Semaphore posted after transmission of a packet */ }; #ifdef __cplusplus @@ -221,4 +166,4 @@ extern "C" } #endif -#endif /* __INCLUDE_NUTTX_WIRELESS_IEEE802154_MRF24J40_H */ +#endif /* __INCLUDE_NUTTX_WIRELESS_IEEE802154_IEEE802154_RADIO_H */ diff --git a/include/nuttx/wireless/ieee802154/mrf24j40.h b/include/nuttx/wireless/ieee802154/mrf24j40.h index 2c78faee01a..167f125b33b 100644 --- a/include/nuttx/wireless/ieee802154/mrf24j40.h +++ b/include/nuttx/wireless/ieee802154/mrf24j40.h @@ -100,7 +100,7 @@ extern "C" ****************************************************************************/ struct spi_dev_s; /* Forward reference */ -FAR struct ieee802154_dev_s *mrf24j40_init(FAR struct spi_dev_s *spi, +FAR struct ieee802154_radio_s *mrf24j40_init(FAR struct spi_dev_s *spi, FAR const struct mrf24j40_lower_s *lower); #undef EXTERN diff --git a/wireless/ieee802154/Kconfig b/wireless/ieee802154/Kconfig index 18d5a8753c3..60706d45bc1 100644 --- a/wireless/ieee802154/Kconfig +++ b/wireless/ieee802154/Kconfig @@ -12,4 +12,22 @@ config IEEE802154 if IEEE802154 +config IEEE802154_MAC + bool "Generic Media Access Control layer for 802.15.4 radios" + default n + depends on IEEE802154 + ---help--- + Enables a Media Access Controller for any IEEE802.15.4 radio + device. This in turn can be used by higher layer entities + such as 6lowpan. It is not required to use 802.15.4 radios, + but is strongly suggested to ensure exchange of valid frames. + +config IEEE802154_DEV + bool "Debug character driver for ieee802.15.4 radio interfaces" + default n + depends on IEEE802154 + ---help--- + Enables a device driver to expose ieee802.15.4 radio controls + to user space as IOCTLs. + endif # IEEE802154 diff --git a/wireless/ieee802154/Make.defs b/wireless/ieee802154/Make.defs index 9e0c66391b4..8d7251c148c 100644 --- a/wireless/ieee802154/Make.defs +++ b/wireless/ieee802154/Make.defs @@ -36,9 +36,18 @@ ifeq ($(CONFIG_IEEE802154),y) # Include IEEE 802.15.4 support +CSRCS = # Include wireless devices build support +ifeq ($(CONFIG_IEEE802154_MAC),y) +CSRCS += ieee802154/mac802154.c +endif + +ifeq ($(CONFIG_IEEE802154_DEV),y) +CSRCS += ieee802154/ieee802154_device.c +endif + DEPPATH += --dep-path wireless/ieee802154 VPATH += :wireless/ieee802154 CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)wireless$(DELIM)ieee802154} diff --git a/wireless/ieee802154/ieee802154_device.c b/wireless/ieee802154/ieee802154_device.c new file mode 100644 index 00000000000..75921a88cdd --- /dev/null +++ b/wireless/ieee802154/ieee802154_device.c @@ -0,0 +1,374 @@ +/**************************************************************************** + * drivers/ieee802154/ieee802154_device.c + * + * Copyright (C) 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2014-2015 Sebastien Lorquet. All rights reserved. + * Author: Sebastien Lorquet + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +struct ieee802154_devwrapper_s +{ + FAR struct ieee802154_radio_s *child; + sem_t devsem; /* Device access serialization semaphore */ + int opened; /* this device can only be opened once */ +}; + +/* when rx interrupt is complete, it calls sem_post(&dev->rxsem); */ +/* when tx interrupt is complete, it calls sem_post(&dev->txsem); */ + +static void ieee802154dev_semtake(FAR struct ieee802154_devwrapper_s *dev); +static int ieee802154dev_open (FAR struct file *filep); +static int ieee802154dev_close (FAR struct file *filep); +static ssize_t ieee802154dev_read (FAR struct file *filep, FAR char *buffer, size_t len); +static ssize_t ieee802154dev_write (FAR struct file *filep, FAR const char *buffer, size_t len); +static int ieee802154dev_ioctl (FAR struct file *filep, int cmd, unsigned long arg); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct file_operations ieee802154dev_fops = +{ + ieee802154dev_open , /* open */ + ieee802154dev_close, /* close */ + ieee802154dev_read , /* read */ + ieee802154dev_write, /* write */ + 0 , /* seek */ + ieee802154dev_ioctl /* ioctl */ +#ifndef CONFIG_DISABLE_POLL + , 0 /* poll */ +#endif +}; + +/**************************************************************************** + * Name: ieee802154dev_semtake + * + * Description: + * Acquire the semaphore used for access serialization. + * + ****************************************************************************/ + +static void ieee802154dev_semtake(FAR struct ieee802154_devwrapper_s *dev) +{ + /* Take the semaphore (perhaps waiting) */ + + while (sem_wait(&dev->devsem) != 0) + { + /* The only case that an error should occur here is if + * the wait was awakened by a signal. + */ + ASSERT(errno == EINTR); + } +} + +/**************************************************************************** + * Name: ieee802154dev_semgive + * + * Description: + * Release the semaphore used for access serialization. + * + ****************************************************************************/ + +static inline void ieee802154dev_semgive(FAR struct ieee802154_devwrapper_s *dev) +{ + sem_post(&dev->devsem); +} + +/**************************************************************************** + * Name: ieee802154dev_open + * + * Description: + * Open the MRF24J40 device. + * + ****************************************************************************/ + +static int ieee802154dev_open(FAR struct file *filep) +{ + FAR struct inode *inode = filep->f_inode; + FAR struct ieee802154_devwrapper_s *dev = inode->i_private; + + ieee802154dev_semtake(dev); + + if (dev->opened) + { + return -EMFILE; + } + else + { + + /* Enable interrupts (only rx for now)*/ + + //mrf24j40_setreg(dev->spi, MRF24J40_INTCON, ~(MRF24J40_INTCON_RXIE) ); + //dev->lower->enable(dev->lower, TRUE); + + dev->opened = TRUE; + } + + ieee802154dev_semgive(dev); + return OK; +} + +/**************************************************************************** + * Name: ieee802154dev_close + * + * Description: + * Close the MRF24J40 device. + * + ****************************************************************************/ + +static int ieee802154dev_close(FAR struct file *filep) +{ + FAR struct inode *inode = filep->f_inode; + FAR struct ieee802154_devwrapper_s *dev = inode->i_private; + int ret = OK; + + ieee802154dev_semtake(dev); + + if(!dev->opened) + { + ret = -EIO; + } + else + { + /* Disable interrupts */ + + //mrf24j40_setreg(dev->spi, MRF24J40_INTCON, 0xFF ); + //dev->lower->enable(dev->lower, FALSE); + + dev->opened = FALSE; + } + + ieee802154dev_semgive(dev); + return ret; +} + +/**************************************************************************** + * Name: ieee802154dev_read + * + * Description: + * Return the last received packet. + * TODO: Return a packet from the receive queue. The buffer must be a pointer to a + * struct ieee802154_packet_s structure, with a correct length. + * + ****************************************************************************/ + +static ssize_t ieee802154dev_read(FAR struct file *filep, FAR char *buffer, size_t len) +{ + FAR struct inode *inode = filep->f_inode; + FAR struct ieee802154_devwrapper_s *dev = inode->i_private; + int ret = OK; + + FAR struct ieee802154_packet_s *buf = (FAR struct ieee802154_packet_s*)buffer; + + if (lenchild->ops->rxenable(dev->child, 1, buf); +#if 0 + if (ret < 0) + { + goto done; + } +#endif + + /* if no packet is received, this will produce -EAGAIN + * The user is responsible for sleeping until sth arrives + */ +#if 0 + ret = sem_trywait(&dev->child->rxsem); +#else + ret = sem_wait(&dev->child->rxsem); +#endif + if (ret < 0) + { + ret = -errno; + goto done; + } + + /* disable read until we have process the current read */ + dev->child->ops->rxenable(dev->child, 0, NULL); + + ret = buf->len; + +done: + + return ret; +} + +/**************************************************************************** + * Name: ieee802154dev_write + * + * Description: + * Send a packet immediately. + * TODO: Put a packet in the send queue. The packet will be sent as soon as possible. + * The buffer must point to a struct ieee802154_packet_s with the correct length. + * + ****************************************************************************/ + +static ssize_t ieee802154dev_write(FAR struct file *filep, FAR const char *buffer, size_t len) +{ + FAR struct inode *inode = filep->f_inode; + FAR struct ieee802154_devwrapper_s *dev = inode->i_private; + FAR struct ieee802154_packet_s *packet; + int ret = OK; + + /* TODO: Make this an option or have a new method of doing timeout from ioctrl */ + FAR struct timespec timeout; + + timeout.tv_sec = 1; + timeout.tv_nsec = 0; + + /* sanity checks */ + + if (lenlen > 125) /* Max len 125, 2 FCS bytes auto added by mrf*/ + { + ret = -EPERM; + // goto done; + DEBUGASSERT(0); + } + + /* Copy packet to normal device TX fifo. + * Beacons and GTS transmission will be handled via IOCTLs + */ + ret = dev->child->ops->transmit(dev->child, packet); + + if(ret != packet->len) + { + ret = -EPERM; + goto done; + } + + if(sem_timedwait(&dev->child->txsem, &timeout)) + { + dbg("Radio Device timedout on Tx\n"); + } + +done: + + /* okay, tx interrupt received. check transmission status to decide success. */ + + return ret; +} + +/**************************************************************************** + * Name: ieee802154dev_ioctl + * + * Description: + * Control the MRF24J40 device. This is where the real operations happen. + * + ****************************************************************************/ + +static int ieee802154dev_ioctl(FAR struct file *filep, int cmd, unsigned long arg) +{ + FAR struct inode *inode = filep->f_inode; + FAR struct ieee802154_devwrapper_s *dev = inode->i_private; + FAR struct ieee802154_radio_s *child = dev->child; + int ret = OK; + + switch(cmd) + { + case MAC854IOCSCHAN : ret = child->ops->setchannel (child, (uint8_t) arg); break; + case MAC854IOCGCHAN : ret = child->ops->getchannel (child, (FAR uint8_t*) arg); break; + case MAC854IOCSPANID : ret = child->ops->setpanid (child, (uint16_t) arg); break; + case MAC854IOCGPANID : ret = child->ops->getpanid (child, (FAR uint16_t*) arg); break; + case MAC854IOCSSADDR : ret = child->ops->setsaddr (child, (uint16_t) arg); break; + case MAC854IOCGSADDR : ret = child->ops->getsaddr (child, (FAR uint16_t*) arg); break; + case MAC854IOCSEADDR : ret = child->ops->seteaddr (child, (FAR uint8_t*) arg); break; + case MAC854IOCGEADDR : ret = child->ops->geteaddr (child, (FAR uint8_t*) arg); break; + case MAC854IOCSPROMISC: ret = child->ops->setpromisc (child, (bool) arg); break; + case MAC854IOCGPROMISC: ret = child->ops->getpromisc (child, (FAR bool*) arg); break; + case MAC854IOCSDEVMODE: ret = child->ops->setdevmode (child, (uint8_t) arg); break; + case MAC854IOCGDEVMODE: ret = child->ops->getdevmode (child, (FAR uint8_t*) arg); break; + case MAC854IOCSTXP : ret = child->ops->settxpower (child, (int32_t) arg); break; + case MAC854IOCGTXP : ret = child->ops->gettxpower (child, (FAR int32_t*) arg); break; + case MAC854IOCSCCA : ret = child->ops->setcca (child, (FAR struct ieee802154_cca_s*)arg); break; + case MAC854IOCGCCA : ret = child->ops->getcca (child, (FAR struct ieee802154_cca_s*)arg); break; + case MAC854IOCGED : ret = child->ops->energydetect(child, (FAR uint8_t*) arg); break; + default : ret = child->ops->ioctl (child, cmd, arg); + } + + return ret; +} + +/**************************************************************************** + * Name: ieee802154dev_register + * + * Description: + * Register /dev/ieee%d + * + ****************************************************************************/ + +int ieee802154_register(FAR struct ieee802154_radio_s *ieee, unsigned int minor) +{ + char devname[16]; + FAR struct ieee802154_devwrapper_s *dev; + + dev = kmm_zalloc(sizeof(struct ieee802154_devwrapper_s)); + + if (!dev) + { + return -ENOMEM; + } + + dev->child = ieee; + + sem_init(&dev->devsem , 0, 1); /* Allow the device to be opened once before blocking */ + + sprintf(devname, "/dev/ieee%d", minor); + + return register_driver(devname, &ieee802154dev_fops, 0666, dev); +} + diff --git a/wireless/ieee802154/mac802154.c b/wireless/ieee802154/mac802154.c new file mode 100644 index 00000000000..ad9e1953714 --- /dev/null +++ b/wireless/ieee802154/mac802154.c @@ -0,0 +1,586 @@ +/**************************************************************************** + * wireless/ieee802154/mac802154.c + * + * Copyright (C) 2016 Sebastien Lorquet. All rights reserved. + * Author: Sebastien Lorquet + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include +#include + +#include + +/* Frame Type */ + +#define IEEE802154_FRAME_BEACON 0x00 +#define IEEE802154_FRAME_DATA 0x01 +#define IEEE802154_FRAME_ACK 0x02 +#define IEEE802154_FRAME_COMMAND 0x03 + +/* MAC commands */ + +#define IEEE802154_CMD_ASSOC_REQ 0x01 +#define IEEE802154_CMD_ASSOC_RSP 0x02 +#define IEEE802154_CMD_DIS_NOT 0x03 +#define IEEE802154_CMD_DATA_REQ 0x04 +#define IEEE802154_CMD_PANID_CONF_NOT 0x05 +#define IEEE802154_CMD_ORPHAN_NOT 0x06 +#define IEEE802154_CMD_BEACON_REQ 0x07 +#define IEEE802154_CMD_COORD_REALIGN 0x08 +#define IEEE802154_CMD_GTS_REQ 0x09 + +/* private types */ +/* The privmac structure is an extension of the public ieee802154_mac_s type. + * It contains storage for the IEEE802.15.4 MIB attributes. + */ + +struct ieee802154_privmac_s +{ + struct ieee802154_mac_s pubmac; /* This MUST be the first member */ + + /* MIB attributes, grouped to save memory */ + /* 0x40 */ uint8_t macAckWaitDuration : 1; /* 55 or 120(true) */ + /* 0x41 */ uint8_t macAssociationPermit : 1; + /* 0x42 */ uint8_t macAutoRequest : 1; + /* 0x43 */ uint8_t macBattLifeExt : 1; + /* 0x44 */ uint8_t macBattLifeExtPeriods : 1; /* 6 or 8(true) */ + /* 0x4E */ uint8_t macMaxCSMABackoffs : 3; /* 0-5 */ + + /* 0x47 */ uint8_t macBeaconOrder : 4; + /* 0x54 */ uint8_t macSuperframeOrder : 4; + + /* 0x4F */ uint32_t macMinBE : 2; + /* 0x4D */ uint32_t macGTSPermit : 1; + /* 0x51 */ uint32_t macPromiscuousMode : 1; + /* 0x52 */ uint32_t macRxOnWhenIdle : 1; + uint32_t macPad : 3; + /* 0x48 */ uint32_t macBeaconTxTime : 24; + + /* 0x45 */ uint8_t macBeaconPayload[MAC802154_aMaxBeaconPayloadLength]; + /* 0x46 */ uint8_t macBeaconPayloadLength; + /* 0x49 */ uint8_t macBSN; + /* 0x4A */ uint8_t macCoordExtendedAddress[8]; + /* 0x4B */ uint16_t macCoordShortAddress; + /* 0x4C */ uint8_t macDSN; + /* 0x50 */ uint16_t macPANId; + /* 0x53 */ uint16_t macShortAddress; + /* 0x55 */ uint16_t macTransactionPersistenceTime; +#if 0 + /* Security MIB */ + /* 0x70 */ macACLEntryDescriptorSet + /* 0x71 */ macACLEntryDescriptorSetSize + /* 0x74 */ macDefaultSecurityMaterial + /* 0x72 */ macDefaultSecurity:1 + /* 0x75 */ macDefaultSecuritySuite:3 + /* 0x73 */ macDefaultSecurityMaterialLength:6 + /* 0x76 */ macSecurityMode:2 +#endif +}; + +/* forward declarations */ + +static int mac802154_reqdata (struct ieee802154_mac_s *mac, + uint8_t handle, + uint8_t *buf, + int len); + +static int mac802154_reqpurge (struct ieee802154_mac_s *mac, + uint8_t handle); + +static int mac802154_reqassociate (struct ieee802154_mac_s *mac, + uint16_t panid, + uint8_t *coordeadr); + +static int mac802154_reqdisassociate(struct ieee802154_mac_s *mac, + uint8_t *eadr, + uint8_t reason); + +static int mac802154_reqget (struct ieee802154_mac_s *mac, + int attribute); + +static int mac802154_reqgts (struct ieee802154_mac_s *mac, + uint8_t* characteristics); + +static int mac802154_reqreset (struct ieee802154_mac_s *mac, + bool setdefaults); + +static int mac802154_reqrxenable (struct ieee802154_mac_s *mac, + bool deferrable, + int ontime, + int duration); + +static int mac802154_reqscan (struct ieee802154_mac_s *mac, + uint8_t type, + uint32_t channels, + int duration); + +static int mac802154_reqset (struct ieee802154_mac_s *mac, + int attribute, + uint8_t *value, + int valuelen); + +static int mac802154_reqstart (struct ieee802154_mac_s *mac, + uint16_t panid, + int channel, + uint8_t bo, + uint8_t fo, + bool coord, + bool batext, + bool realign); + +static int mac802154_reqsync (struct ieee802154_mac_s *mac, + int channel, + bool track); + +static int mac802154_reqpoll (struct ieee802154_mac_s *mac, + uint8_t *coordaddr); + +static int mac802154_rspassociate (struct ieee802154_mac_s *mac, + uint8_t eadr, + uint16_t saddr, + int status); + +static int mac802154_rsporphan (struct ieee802154_mac_s *mac, + uint8_t *orphanaddr, + uint16_t saddr, + bool associated); + + +/* data */ +static const struct ieee802154_macops_s mac802154ops = +{ + .req_data = mac802154_reqdata + .req_purge = mac802154_reqpurge + .req_associate = mac802154_reqassociate + .req_disassociate= mac802154_reqdisassociate + .req_get = mac802154_reqget + .req_gts = mac802154_reqgts + .req_reset = mac802154_reqreset + .req_rxenable = mac802154_reqrxenable + .req_scan = mac802154_reqscan + .req_set = mac802154_reqset + .req_start = mac802154_reqstart + .req_sync = mac802154_reqsync + .req_poll = mac802154_reqpoll + .rsp_associate = mac802154_rspassociate + .rsp_orphan = mac802154_rsporphan +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: mac802154_defaultmib + * + * Description: + * Set the MIB to its default values. + * + ****************************************************************************/ + +static int mac802154_defaultmib(FAR struct ieee802154_privmac_s *priv) +{ + priv->macAckWaitDuration = 0; + priv->macAssociationPermit = 0; + priv->macAutoRequest = 1; + priv->macBattLifeExt = 0; + priv->macBattLifeExtPeriods = 0; + priv->macMaxCSMABackoffs = 4; + + priv->macBeaconOrder = 15; + priv->macSuperframeOrder = 15; + + priv->macMinBE = 3; + priv->macGTSPermit = 1; + priv->macPromiscuousMode = 0; + priv->macRxOnWhenIdle = 0; + priv->macBeaconTxTime = 0x000000; + + priv->macBeaconPayloadLength = 0; + priv->macBSN = 0; /*shall be random*/ + priv->macCoordExtendedAddress[8]; + priv->macCoordShortAddress = 0xffff; + priv->macDSN = 0 /*shall be random*/; + priv->macPANId = 0xffff; + priv->macShortAddress = 0xffff; + priv->macTransactionPersistenceTime = 0x01f4; +#if 0 + /* Security MIB */ + priv->macACLEntryDescriptorSetSize = 0; + priv->macDefaultSecurity = 0; + priv->macDefaultSecuritySuite = 0; + priv->macDefaultSecurityMaterialLength = 0x15; + priv->macSecurityMode = 0; +#endif +} + +/**************************************************************************** + * Name: mac802154_applymib + * + * Description: + * Some parts of the MIB must be sent to the radio device. This routine + * calls the radio device routines to store the related parameters in the + * radio driver. It must be called each time a MIB parameter is changed. + * + ****************************************************************************/ + +static int mac802154_applymib(FAR struct ieee802154_privmac_s *priv) +{ + return OK; +} + +/**************************************************************************** + * API Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: mac802154_reqdata + * + * Description: + * The MCPS-DATA.request primitive requests the transfer of a data SPDU + * (i.e., MSDU) from a local SSCS entity to a single peer SSCS entity. + * Confirmation is returned via the + * struct ieee802154_maccb_s->conf_data callback. + * + ****************************************************************************/ + +static int mac802154_reqdata(FAR struct ieee802154_mac_s *mac, + uint8_t handle, + uint8_t *buf, + int len) +{ + FAR struct ieee802154_privmac_s * priv = (FAR struct ieee802154_privmac_s *) mac; + return -ENOTTY; +} + +/**************************************************************************** + * Name: mac802154_reqpurge + * + * Description: + * The MCPS-PURGE.request primitive allows the next higher layer to purge an + * MSDU from the transaction queue. Confirmation is returned via + * the struct ieee802154_maccb_s->conf_purge callback. + * + ****************************************************************************/ + +static int mac802154_reqpurge(FAR struct ieee802154_mac_s *mac, + uint8_t handle) +{ + FAR struct ieee802154_privmac_s * priv = (FAR struct ieee802154_privmac_s *) mac; + return -ENOTTY; +} + +/**************************************************************************** + * Name: mac802154_reqassociate + * + * Description: + * The MLME-ASSOCIATE.request primitive allows a device to request an + * association with a coordinator. Confirmation is returned via the + * struct ieee802154_maccb_s->conf_associate callback. + * + ****************************************************************************/ + +static int mac802154_reqassociate(FAR struct ieee802154_mac_s *mac, + uint16_t panid, + uint8_t *coordeadr) +{ + FAR struct ieee802154_privmac_s * priv = (FAR struct ieee802154_privmac_s *) mac; + return -ENOTTY; +} + +/**************************************************************************** + * Name: mac802154_reqdisassociate + * + * Description: + * The MLME-DISASSOCIATE.request primitive is used by an associated device to + * notify the coordinator of its intent to leave the PAN. It is also used by + * the coordinator to instruct an associated device to leave the PAN. + * Confirmation is returned via the + * struct ieee802154_maccb_s->conf_disassociate callback. + * + ****************************************************************************/ + +static int mac802154_reqdisassociate(FAR struct ieee802154_mac_s *mac, + uint8_t *eadr, + uint8_t reason) +{ + FAR struct ieee802154_privmac_s * priv = (FAR struct ieee802154_privmac_s *) mac; + return -ENOTTY; +} + +/**************************************************************************** + * Name: mac802154_reqget + * + * Description: + * The MLME-GET.request primitive requests information about a given PIB + * attribute. Actual data is returned via the + * struct ieee802154_maccb_s->conf_get callback. + * + ****************************************************************************/ + +static int mac802154_reqget(FAR struct ieee802154_mac_s *mac, + int attribute) +{ + FAR struct ieee802154_privmac_s * priv = (FAR struct ieee802154_privmac_s *) mac; + return -ENOTTY; +} + +/**************************************************************************** + * Name: mac802154_reqgts + * + * Description: + * The MLME-GTS.request primitive allows a device to send a request to the PAN + * coordinator to allocate a new GTS or to deallocate an existing GTS. + * Confirmation is returned via the + * struct ieee802154_maccb_s->conf_gts callback. + * + ****************************************************************************/ + +static int mac802154_reqgts(FAR struct ieee802154_mac_s *mac, + uint8_t* characteristics) +{ + FAR struct ieee802154_privmac_s * priv = (FAR struct ieee802154_privmac_s *) mac; + return -ENOTTY; +} + +/**************************************************************************** + * Name: mac802154_reqreset + * + * Description: + * The MLME-RESET.request primitive allows the next higher layer to request + * that the MLME performs a reset operation. Confirmation is returned via + * the struct ieee802154_maccb_s->conf_reset callback. + * + ****************************************************************************/ + +static int mac802154_reqreset(FAR struct ieee802154_mac_s *mac, + bool setdefaults) +{ + FAR struct ieee802154_privmac_s * priv = (FAR struct ieee802154_privmac_s *) mac; + return -ENOTTY; +} + +/**************************************************************************** + * Name: mac802154_reqrxenable + * + * Description: + * The MLME-RX-ENABLE.request primitive allows the next higher layer to + * request that the receiver is enable for a finite period of time. + * Confirmation is returned via the + * struct ieee802154_maccb_s->conf_rxenable callback. + * + ****************************************************************************/ + +static int mac802154_reqrxenable(FAR struct ieee802154_mac_s *mac, + bool deferrable, + int ontime, + int duration) +{ + FAR struct ieee802154_privmac_s * priv = (FAR struct ieee802154_privmac_s *) mac; + return -ENOTTY; +} + +/**************************************************************************** + * Name: mac802154_reqscan + * + * Description: + * The MLME-SCAN.request primitive is used to initiate a channel scan over a + * given list of channels. A device can use a channel scan to measure the + * energy on the channel, search for the coordinator with which it associated, + * or search for all coordinators transmitting beacon frames within the POS of + * the scanning device. Scan results are returned + * via MULTIPLE calls to the struct ieee802154_maccb_s->conf_scan callback. + * This is a difference with the official 802.15.4 specification, implemented + * here to save memory. + * + ****************************************************************************/ + +static int mac802154_reqscan(FAR struct ieee802154_mac_s *mac, + uint8_t type, + uint32_t channels, + int duration) +{ + FAR struct ieee802154_privmac_s * priv = (FAR struct ieee802154_privmac_s *) mac; + return -ENOTTY; +} + +/**************************************************************************** + * Name: mac802154_reqset + * + * Description: + * The MLME-SET.request primitive attempts to write the given value to the + * indicated MAC PIB attribute. Confirmation is returned via the + * struct ieee802154_maccb_s->conf_set callback. + * + ****************************************************************************/ + +static int mac802154_reqset(FAR struct ieee802154_mac_s *mac, + int attribute, + uint8_t *value, + int valuelen) +{ + FAR struct ieee802154_privmac_s * priv = (FAR struct ieee802154_privmac_s *) mac; + return -ENOTTY; +} + +/**************************************************************************** + * Name: mac802154_reqstart + * + * Description: + * The MLME-START.request primitive makes a request for the device to start + * using a new superframe configuration. Confirmation is returned + * via the struct ieee802154_maccb_s->conf_start callback. + * + ****************************************************************************/ + +static int mac802154_reqstart(FAR struct ieee802154_mac_s *mac, + uint16_t panid, + int channel, + uint8_t bo, + uint8_t fo, + bool coord, + bool batext, + bool realign) +{ + FAR struct ieee802154_privmac_s * priv = (FAR struct ieee802154_privmac_s *) mac; + return -ENOTTY; +} + +/**************************************************************************** + * Name: mac802154_reqsync + * + * Description: + * The MLME-SYNC.request primitive requests to synchronize with the + * coordinator by acquiring and, if specified, tracking its beacons. + * Confirmation is returned via the + * struct ieee802154_maccb_s->int_commstatus callback. TOCHECK. + * + ****************************************************************************/ + +static int mac802154_reqsync(FAR struct ieee802154_mac_s *mac, + int channel, + bool track) +{ + FAR struct ieee802154_privmac_s * priv = (FAR struct ieee802154_privmac_s *) mac; + return -ENOTTY; +} + +/**************************************************************************** + * Name: mac802154_reqpoll + * + * Description: + * The MLME-POLL.request primitive prompts the device to request data from the + * coordinator. Confirmation is returned via the + * struct ieee802154_maccb_s->conf_poll callback, followed by a + * struct ieee802154_maccb_s->ind_data callback. + * + ****************************************************************************/ + +static int mac802154_reqpoll(FAR struct ieee802154_mac_s *mac, + uint8_t *coordaddr) +{ + FAR struct ieee802154_privmac_s * priv = (FAR struct ieee802154_privmac_s *) mac; + return -ENOTTY; +} + +/**************************************************************************** + * Name: mac802154_rspassociate + * + * Description: + * The MLME-ASSOCIATE.response primitive is used to initiate a response to an + * MLME-ASSOCIATE.indication primitive. + * + ****************************************************************************/ + +static int mac802154_rspassociate(FAR struct ieee802154_mac_s *mac, + uint8_t eadr, + uint16_t saddr, + int status) +{ + FAR struct ieee802154_privmac_s * priv = (FAR struct ieee802154_privmac_s *) mac; + return -ENOTTY; +} + +/**************************************************************************** + * Name: mac802154_rsporphan + * + * Description: + * The MLME-ORPHAN.response primitive allows the next higher layer of a + * coordinator to respond to the MLME-ORPHAN.indication primitive. + * + ****************************************************************************/ + +static int mac802154_rsporphan(FAR struct ieee802154_mac_s *mac, + uint8_t *orphanaddr, + uint16_t saddr, + bool associated) +{ + FAR struct ieee802154_privmac_s * priv = (FAR struct ieee802154_privmac_s *) mac; + return -ENOTTY; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: mac802154_register + * + * Description: + * Create a 802.15.4 MAC device from a 802.15.4 compatible radio device. + * + ****************************************************************************/ + +FAR struct ieee802154_mac_s * mac802154_register(FAR struct ieee802154_radio_s *radiodev, unsigned int minor) +{ + FAR struct ieee802154_privmac_s *mac; + + /* allocate object */ + mac = (FAR struct ieee802154_privmac_s *)kmm_zalloc(sizeof(struct ieee802154_privmac_s)); + if(!mac) + { + return NULL; + } + + /* init fields */ + mac->pubmac.radio = radiodev; + mac->pubmac.ops = mac802154ops; + mac802154_defaultmib(mac); + mac802154_applymib(mac); + return &mac->pubmac; +} + From 0ef10e6d0e18bb8edac3d8af6485ad60bfeaf5b1 Mon Sep 17 00:00:00 2001 From: Sebastien Lorquet Date: Wed, 1 Jun 2016 13:11:49 +0200 Subject: [PATCH 002/183] fix atmel driver for new 802154 radio api --- drivers/wireless/ieee802154/at86rf23x.c | 96 +++++++++---------- include/nuttx/wireless/ieee802154/at86rf23x.h | 2 +- 2 files changed, 48 insertions(+), 50 deletions(-) diff --git a/drivers/wireless/ieee802154/at86rf23x.c b/drivers/wireless/ieee802154/at86rf23x.c index fdd2c3ad646..8d2e1cb1337 100644 --- a/drivers/wireless/ieee802154/at86rf23x.c +++ b/drivers/wireless/ieee802154/at86rf23x.c @@ -58,8 +58,6 @@ #include #include -#include - #include "at86rf23x.h" /************************************************************************************ @@ -98,13 +96,13 @@ /* * AT86RF23x device instance * - * Make sure that struct ieee802154_dev_s remains first. If not it will break the + * Make sure that struct ieee802154_radio_s remains first. If not it will break the * code * */ struct at86rf23x_dev_s { - struct ieee802154_dev_s ieee; /* Public device instance */ + struct ieee802154_radio_s ieee; /* Public device instance */ FAR struct spi_dev_s *spi; /* Saved SPI interface instance */ struct work_s irqwork; /* Interrupt continuation work queue support */ FAR const struct at86rf23x_lower_s *lower; /* Low-level MCU-specific support */ @@ -143,26 +141,26 @@ static void at86rf23x_irqworker(FAR void *arg); static int at86rf23x_interrupt(int irq, FAR void *context); /* Driver operations */ -static int at86rf23x_setchannel (FAR struct ieee802154_dev_s *ieee, uint8_t chan); -static int at86rf23x_getchannel (FAR struct ieee802154_dev_s *ieee, FAR uint8_t *chan); -static int at86rf23x_setpanid (FAR struct ieee802154_dev_s *ieee, uint16_t panid); -static int at86rf23x_getpanid (FAR struct ieee802154_dev_s *ieee, FAR uint16_t *panid); -static int at86rf23x_setsaddr (FAR struct ieee802154_dev_s *ieee, uint16_t saddr); -static int at86rf23x_getsaddr (FAR struct ieee802154_dev_s *ieee, FAR uint16_t *saddr); -static int at86rf23x_seteaddr (FAR struct ieee802154_dev_s *ieee, FAR uint8_t *eaddr); -static int at86rf23x_geteaddr (FAR struct ieee802154_dev_s *ieee, FAR uint8_t *eaddr); -static int at86rf23x_setpromisc (FAR struct ieee802154_dev_s *ieee, bool promisc); -static int at86rf23x_getpromisc (FAR struct ieee802154_dev_s *ieee, FAR bool *promisc); -static int at86rf23x_setdevmode (FAR struct ieee802154_dev_s *ieee, uint8_t mode); -static int at86rf23x_getdevmode (FAR struct ieee802154_dev_s *ieee, FAR uint8_t *mode); -static int at86rf23x_settxpower (FAR struct ieee802154_dev_s *ieee, int32_t txpwr); -static int at86rf23x_gettxpower (FAR struct ieee802154_dev_s *ieee, FAR int32_t *txpwr); -static int at86rf23x_setcca (FAR struct ieee802154_dev_s *ieee, FAR struct ieee802154_cca_s *cca); -static int at86rf23x_getcca (FAR struct ieee802154_dev_s *ieee, FAR struct ieee802154_cca_s *cca); -static int at86rf23x_ioctl (FAR struct ieee802154_dev_s *ieee, int cmd, unsigned long arg); -static int at86rf23x_energydetect(FAR struct ieee802154_dev_s *ieee, FAR uint8_t *energy); -static int at86rf23x_rxenable (FAR struct ieee802154_dev_s *ieee, bool state, FAR struct ieee802154_packet_s *packet); -static int at86rf23x_transmit (FAR struct ieee802154_dev_s *ieee, FAR struct ieee802154_packet_s *packet); +static int at86rf23x_setchannel (FAR struct ieee802154_radio_s *ieee, uint8_t chan); +static int at86rf23x_getchannel (FAR struct ieee802154_radio_s *ieee, FAR uint8_t *chan); +static int at86rf23x_setpanid (FAR struct ieee802154_radio_s *ieee, uint16_t panid); +static int at86rf23x_getpanid (FAR struct ieee802154_radio_s *ieee, FAR uint16_t *panid); +static int at86rf23x_setsaddr (FAR struct ieee802154_radio_s *ieee, uint16_t saddr); +static int at86rf23x_getsaddr (FAR struct ieee802154_radio_s *ieee, FAR uint16_t *saddr); +static int at86rf23x_seteaddr (FAR struct ieee802154_radio_s *ieee, FAR uint8_t *eaddr); +static int at86rf23x_geteaddr (FAR struct ieee802154_radio_s *ieee, FAR uint8_t *eaddr); +static int at86rf23x_setpromisc (FAR struct ieee802154_radio_s *ieee, bool promisc); +static int at86rf23x_getpromisc (FAR struct ieee802154_radio_s *ieee, FAR bool *promisc); +static int at86rf23x_setdevmode (FAR struct ieee802154_radio_s *ieee, uint8_t mode); +static int at86rf23x_getdevmode (FAR struct ieee802154_radio_s *ieee, FAR uint8_t *mode); +static int at86rf23x_settxpower (FAR struct ieee802154_radio_s *ieee, int32_t txpwr); +static int at86rf23x_gettxpower (FAR struct ieee802154_radio_s *ieee, FAR int32_t *txpwr); +static int at86rf23x_setcca (FAR struct ieee802154_radio_s *ieee, FAR struct ieee802154_cca_s *cca); +static int at86rf23x_getcca (FAR struct ieee802154_radio_s *ieee, FAR struct ieee802154_cca_s *cca); +static int at86rf23x_ioctl (FAR struct ieee802154_radio_s *ieee, int cmd, unsigned long arg); +static int at86rf23x_energydetect(FAR struct ieee802154_radio_s *ieee, FAR uint8_t *energy); +static int at86rf23x_rxenable (FAR struct ieee802154_radio_s *ieee, bool state, FAR struct ieee802154_packet_s *packet); +static int at86rf23x_transmit (FAR struct ieee802154_radio_s *ieee, FAR struct ieee802154_packet_s *packet); /* These are pointers to ALL registered at86rf23x devices. @@ -174,7 +172,7 @@ static int at86rf23x_transmit (FAR struct ieee802154_dev_s *ieee, FAR str static struct at86rf23x_dev_s g_at86rf23x_devices[1]; -static const struct ieee802154_devops_s at86rf23x_devops = +static const struct ieee802154_radioops_s at86rf23x_devops = { .setchannel = at86rf23x_setchannel, .getchannel = at86rf23x_getchannel, @@ -636,7 +634,7 @@ static int at86rf23x_setTRXstate(FAR struct at86rf23x_dev_s *dev, uint8_t state, * * ****************************************************************************/ -static int at86rf23x_setchannel(FAR struct ieee802154_dev_s *ieee, uint8_t chan) +static int at86rf23x_setchannel(FAR struct ieee802154_radio_s *ieee, uint8_t chan) { FAR struct at86rf23x_dev_s *dev = (FAR struct at86rf23x_dev_s *)ieee; uint8_t state; @@ -683,7 +681,7 @@ static int at86rf23x_setchannel(FAR struct ieee802154_dev_s *ieee, uint8_t chan) * * ****************************************************************************/ -static int at86rf23x_getchannel(FAR struct ieee802154_dev_s *ieee, FAR uint8_t *chan) +static int at86rf23x_getchannel(FAR struct ieee802154_radio_s *ieee, FAR uint8_t *chan) { FAR struct at86rf23x_dev_s *dev = (FAR struct at86rf23x_dev_s *)ieee; @@ -703,7 +701,7 @@ static int at86rf23x_getchannel(FAR struct ieee802154_dev_s *ieee, FAR uint8_t * * Define the PAN ID for the network. * ****************************************************************************/ -static int at86rf23x_setpanid(FAR struct ieee802154_dev_s *ieee, uint16_t panid) +static int at86rf23x_setpanid(FAR struct ieee802154_radio_s *ieee, uint16_t panid) { FAR struct at86rf23x_dev_s *dev = (struct at86rf23x_dev_s *)ieee; uint8_t *pan = (uint8_t *)&panid; @@ -721,7 +719,7 @@ static int at86rf23x_setpanid(FAR struct ieee802154_dev_s *ieee, uint16_t panid) * Define the PAN ID for the network. * ****************************************************************************/ -static int at86rf23x_getpanid(FAR struct ieee802154_dev_s *ieee, FAR uint16_t *panid) +static int at86rf23x_getpanid(FAR struct ieee802154_radio_s *ieee, FAR uint16_t *panid) { FAR struct at86rf23x_dev_s *dev = (struct at86rf23x_dev_s *)ieee; uint8_t *pan = (uint8_t *)panid; @@ -739,7 +737,7 @@ static int at86rf23x_getpanid(FAR struct ieee802154_dev_s *ieee, FAR uint16_t *p * Define the Short Address for the device. * ****************************************************************************/ -static int at86rf23x_setsaddr(FAR struct ieee802154_dev_s *ieee, uint16_t saddr) +static int at86rf23x_setsaddr(FAR struct ieee802154_radio_s *ieee, uint16_t saddr) { FAR struct at86rf23x_dev_s *dev = (struct at86rf23x_dev_s *)ieee; uint8_t *addr = (uint8_t *)&saddr; @@ -757,7 +755,7 @@ static int at86rf23x_setsaddr(FAR struct ieee802154_dev_s *ieee, uint16_t saddr) * Get the short address of the device. * ****************************************************************************/ -static int at86rf23x_getsaddr(FAR struct ieee802154_dev_s *ieee, FAR uint16_t *saddr) +static int at86rf23x_getsaddr(FAR struct ieee802154_radio_s *ieee, FAR uint16_t *saddr) { FAR struct at86rf23x_dev_s *dev = (struct at86rf23x_dev_s *)ieee; uint8_t *addr = (uint8_t *)saddr; @@ -775,7 +773,7 @@ static int at86rf23x_getsaddr(FAR struct ieee802154_dev_s *ieee, FAR uint16_t *s * Set the IEEE address of the device. * ****************************************************************************/ -static int at86rf23x_seteaddr(FAR struct ieee802154_dev_s *ieee, FAR uint8_t *eaddr) +static int at86rf23x_seteaddr(FAR struct ieee802154_radio_s *ieee, FAR uint8_t *eaddr) { FAR struct at86rf23x_dev_s *dev = (struct at86rf23x_dev_s *)ieee; /* TODO: Check if we need to pay attention to endianness */ @@ -798,7 +796,7 @@ static int at86rf23x_seteaddr(FAR struct ieee802154_dev_s *ieee, FAR uint8_t *ea * Get the IEEE address of the device. * ****************************************************************************/ -static int at86rf23x_geteaddr(FAR struct ieee802154_dev_s *ieee, FAR uint8_t *eaddr) +static int at86rf23x_geteaddr(FAR struct ieee802154_radio_s *ieee, FAR uint8_t *eaddr) { FAR struct at86rf23x_dev_s *dev = (struct at86rf23x_dev_s *)ieee; /* TODO: Check if we need to pay attention to endianness */ @@ -821,7 +819,7 @@ static int at86rf23x_geteaddr(FAR struct ieee802154_dev_s *ieee, FAR uint8_t *ea * enable/disable promiscuous mode. * ****************************************************************************/ -static int at86rf23x_setpromisc(FAR struct ieee802154_dev_s *ieee, bool promisc) +static int at86rf23x_setpromisc(FAR struct ieee802154_radio_s *ieee, bool promisc) { FAR struct at86rf23x_dev_s *dev = (struct at86rf23x_dev_s *)ieee; @@ -841,7 +839,7 @@ static int at86rf23x_setpromisc(FAR struct ieee802154_dev_s *ieee, bool promisc) * Check if the device is in promiscuous mode. * ****************************************************************************/ -static int at86rf23x_getpromisc(FAR struct ieee802154_dev_s *ieee, FAR bool *promisc) +static int at86rf23x_getpromisc(FAR struct ieee802154_radio_s *ieee, FAR bool *promisc) { FAR struct at86rf23x_dev_s *dev = (struct at86rf23x_dev_s *)ieee; @@ -857,7 +855,7 @@ static int at86rf23x_getpromisc(FAR struct ieee802154_dev_s *ieee, FAR bool *pro * Check if the device is in promiscuous mode. * ****************************************************************************/ -static int at86rf23x_setdevmode(FAR struct ieee802154_dev_s *ieee, uint8_t mode) +static int at86rf23x_setdevmode(FAR struct ieee802154_radio_s *ieee, uint8_t mode) { FAR struct at86rf23x_dev_s *dev = (struct at86rf23x_dev_s *)ieee; @@ -891,7 +889,7 @@ static int at86rf23x_setdevmode(FAR struct ieee802154_dev_s *ieee, uint8_t mode) * get the device mode type of the radio. * ****************************************************************************/ -static int at86rf23x_getdevmode (FAR struct ieee802154_dev_s *ieee, FAR uint8_t *mode) +static int at86rf23x_getdevmode (FAR struct ieee802154_radio_s *ieee, FAR uint8_t *mode) { FAR struct at86rf23x_dev_s *dev = (struct at86rf23x_dev_s *)ieee; int val; @@ -900,11 +898,11 @@ static int at86rf23x_getdevmode (FAR struct ieee802154_dev_s *ieee, FAR uint8_t if(val == 1) { - mode = IEEE802154_MODE_PANCOORD; + *mode = IEEE802154_MODE_PANCOORD; } else { - mode = IEEE802154_MODE_DEVICE; + *mode = IEEE802154_MODE_DEVICE; } return OK; @@ -917,7 +915,7 @@ static int at86rf23x_getdevmode (FAR struct ieee802154_dev_s *ieee, FAR uint8_t * set the tx power attenuation or amplification * ****************************************************************************/ -static int at86rf23x_settxpower(FAR struct ieee802154_dev_s *ieee, int32_t txpwr) +static int at86rf23x_settxpower(FAR struct ieee802154_radio_s *ieee, int32_t txpwr) { FAR struct at86rf23x_dev_s *dev = (struct at86rf23x_dev_s *)ieee; @@ -936,7 +934,7 @@ static int at86rf23x_settxpower(FAR struct ieee802154_dev_s *ieee, int32_t txpwr * get the tx power attenuation or amplification. * ****************************************************************************/ -static int at86rf23x_gettxpower(FAR struct ieee802154_dev_s *ieee, FAR int32_t *txpwr) +static int at86rf23x_gettxpower(FAR struct ieee802154_radio_s *ieee, FAR int32_t *txpwr) { /* TODO: this needs alot of work to make sure all chips can share this function */ FAR struct at86rf23x_dev_s *dev = (struct at86rf23x_dev_s *)ieee; @@ -1010,7 +1008,7 @@ static int at86rf23x_gettxpower(FAR struct ieee802154_dev_s *ieee, FAR int32_t * * * ****************************************************************************/ -static int at86rf23x_setcca(FAR struct ieee802154_dev_s *ieee, FAR struct ieee802154_cca_s *cca) +static int at86rf23x_setcca(FAR struct ieee802154_radio_s *ieee, FAR struct ieee802154_cca_s *cca) { FAR struct at86rf23x_dev_s *dev = (struct at86rf23x_dev_s *)ieee; @@ -1046,7 +1044,7 @@ static int at86rf23x_setcca(FAR struct ieee802154_dev_s *ieee, FAR struct ieee80 * Get CCA for ???: TODO: need to implement * ****************************************************************************/ -static int at86rf23x_getcca(FAR struct ieee802154_dev_s *ieee, FAR struct ieee802154_cca_s *cca) +static int at86rf23x_getcca(FAR struct ieee802154_radio_s *ieee, FAR struct ieee802154_cca_s *cca) { FAR struct at86rf23x_dev_s *dev = (struct at86rf23x_dev_s *)ieee; @@ -1065,12 +1063,12 @@ static int at86rf23x_getcca(FAR struct ieee802154_dev_s *ieee, FAR struct ieee80 * Control operations for the radio. * ****************************************************************************/ -static int at86rf23x_ioctl(FAR struct ieee802154_dev_s *ieee, int cmd, unsigned long arg) +static int at86rf23x_ioctl(FAR struct ieee802154_radio_s *ieee, int cmd, unsigned long arg) { FAR struct at86rf23x_dev_s *dev = (FAR struct at86rf23x_dev_s *)ieee; switch(cmd) { - case MAC854IORDUMP: return at86rf23x_regdump(dev); + case 1000: return at86rf23x_regdump(dev); default: return -EINVAL; } } @@ -1081,7 +1079,7 @@ static int at86rf23x_ioctl(FAR struct ieee802154_dev_s *ieee, int cmd, unsigned * Perform energy detection scan. TODO: Need to implement. * ****************************************************************************/ -static int at86rf23x_energydetect(FAR struct ieee802154_dev_s *ieee, FAR uint8_t *energy) +static int at86rf23x_energydetect(FAR struct ieee802154_radio_s *ieee, FAR uint8_t *energy) { #warning at86rf23x_energydetect not implemented. @@ -1161,7 +1159,7 @@ static int at86rf23x_resetrf(FAR struct at86rf23x_dev_s *dev) * RX messages. * ****************************************************************************/ -static int at86rf23x_rxenable(FAR struct ieee802154_dev_s *ieee, bool state, +static int at86rf23x_rxenable(FAR struct ieee802154_radio_s *ieee, bool state, FAR struct ieee802154_packet_s *packet) { FAR struct at86rf23x_dev_s *dev = (FAR struct at86rf23x_dev_s *)ieee; @@ -1356,7 +1354,7 @@ static void at86rf23x_irqwork_tx(FAR struct at86rf23x_dev_s *dev) * transmission * ****************************************************************************/ -static int at86rf23x_transmit(FAR struct ieee802154_dev_s *ieee, FAR struct ieee802154_packet_s *packet) +static int at86rf23x_transmit(FAR struct ieee802154_radio_s *ieee, FAR struct ieee802154_packet_s *packet) { FAR struct at86rf23x_dev_s *dev = (FAR struct at86rf23x_dev_s *)ieee; /* @@ -1395,7 +1393,7 @@ static int at86rf23x_transmit(FAR struct ieee802154_dev_s *ieee, FAR struct ieee * ****************************************************************************/ -FAR struct ieee802154_dev_s *at86rf23x_init(FAR struct spi_dev_s *spi, FAR const struct at86rf23x_lower_s *lower) +FAR struct ieee802154_radio_s *at86rf23x_init(FAR struct spi_dev_s *spi, FAR const struct at86rf23x_lower_s *lower) { FAR struct at86rf23x_dev_s *dev; struct ieee802154_cca_s cca; diff --git a/include/nuttx/wireless/ieee802154/at86rf23x.h b/include/nuttx/wireless/ieee802154/at86rf23x.h index 974e2456e2d..1ef6c909d2c 100644 --- a/include/nuttx/wireless/ieee802154/at86rf23x.h +++ b/include/nuttx/wireless/ieee802154/at86rf23x.h @@ -90,7 +90,7 @@ extern "C" { * ****************************************************************************/ -FAR struct ieee802154_dev_s *at86rf23x_init(FAR struct spi_dev_s *spi, FAR const struct at86rf23x_lower_s *lower); +FAR struct ieee802154_radio_s *at86rf23x_init(FAR struct spi_dev_s *spi, FAR const struct at86rf23x_lower_s *lower); #undef EXTERN #ifdef __cplusplus From a122dddb5891f2ce781608d572b49c25b482912e Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 15 Mar 2017 13:24:51 -0600 Subject: [PATCH 003/183] Bring closer to NuttX coding standard. --- wireless/ieee802154/mac802154.c | 232 ++++++++++++++------------------ 1 file changed, 99 insertions(+), 133 deletions(-) diff --git a/wireless/ieee802154/mac802154.c b/wireless/ieee802154/mac802154.c index ad9e1953714..3de16fb374e 100644 --- a/wireless/ieee802154/mac802154.c +++ b/wireless/ieee802154/mac802154.c @@ -44,6 +44,10 @@ #include +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + /* Frame Type */ #define IEEE802154_FRAME_BEACON 0x00 @@ -63,7 +67,10 @@ #define IEEE802154_CMD_COORD_REALIGN 0x08 #define IEEE802154_CMD_GTS_REQ 0x09 -/* private types */ +/**************************************************************************** + * Private Types + ****************************************************************************/ + /* The privmac structure is an extension of the public ieee802154_mac_s type. * It contains storage for the IEEE802.15.4 MIB attributes. */ @@ -111,76 +118,47 @@ struct ieee802154_privmac_s #endif }; -/* forward declarations */ +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ -static int mac802154_reqdata (struct ieee802154_mac_s *mac, - uint8_t handle, - uint8_t *buf, - int len); - -static int mac802154_reqpurge (struct ieee802154_mac_s *mac, - uint8_t handle); - -static int mac802154_reqassociate (struct ieee802154_mac_s *mac, - uint16_t panid, - uint8_t *coordeadr); - -static int mac802154_reqdisassociate(struct ieee802154_mac_s *mac, - uint8_t *eadr, - uint8_t reason); - -static int mac802154_reqget (struct ieee802154_mac_s *mac, - int attribute); - -static int mac802154_reqgts (struct ieee802154_mac_s *mac, - uint8_t* characteristics); - -static int mac802154_reqreset (struct ieee802154_mac_s *mac, - bool setdefaults); - -static int mac802154_reqrxenable (struct ieee802154_mac_s *mac, - bool deferrable, - int ontime, - int duration); - -static int mac802154_reqscan (struct ieee802154_mac_s *mac, - uint8_t type, - uint32_t channels, - int duration); - -static int mac802154_reqset (struct ieee802154_mac_s *mac, - int attribute, - uint8_t *value, - int valuelen); - -static int mac802154_reqstart (struct ieee802154_mac_s *mac, - uint16_t panid, - int channel, - uint8_t bo, - uint8_t fo, - bool coord, - bool batext, - bool realign); - -static int mac802154_reqsync (struct ieee802154_mac_s *mac, - int channel, - bool track); - -static int mac802154_reqpoll (struct ieee802154_mac_s *mac, - uint8_t *coordaddr); - -static int mac802154_rspassociate (struct ieee802154_mac_s *mac, - uint8_t eadr, - uint16_t saddr, - int status); - -static int mac802154_rsporphan (struct ieee802154_mac_s *mac, - uint8_t *orphanaddr, - uint16_t saddr, - bool associated); +static int mac802154_reqdata(FAR struct ieee802154_mac_s *mac, + uint8_t handle, FAR uint8_t *buf, int len); +static int mac802154_reqpurge(FAR struct ieee802154_mac_s *mac, + uint8_t handle); +static int mac802154_reqassociate(FAR struct ieee802154_mac_s *mac, + uint16_t panid, FAR uint8_t *coordeadr); +static int mac802154_reqdisassociate(FAR struct ieee802154_mac_s *mac, + FAR uint8_t *eadr, uint8_t reason); +static int mac802154_reqget(FAR struct ieee802154_mac_s *mac, + int attribute); +static int mac802154_reqgts(FAR struct ieee802154_mac_s *mac, + FAR uint8_t *characteristics); +static int mac802154_reqreset(FAR struct ieee802154_mac_s *mac, + bool setdefaults); +static int mac802154_reqrxenable(FAR struct ieee802154_mac_s *mac, + bool deferrable, int ontime, int duration); +static int mac802154_reqscan(FAR struct ieee802154_mac_s *mac, + uint8_t type, uint32_t channels, int duration); +static int mac802154_reqset(FAR struct ieee802154_mac_s *mac, + int attribute, FAR uint8_t *value, int valuelen); +static int mac802154_reqstart(FAR struct ieee802154_mac_s *mac, + uint16_t panid, int channel, uint8_t bo, uint8_t fo, + bool coord, bool batext, bool realign); +static int mac802154_reqsync(FAR struct ieee802154_mac_s *mac, + int channel, bool track); +static int mac802154_reqpoll(FAR struct ieee802154_mac_s *mac, + FAR uint8_t *coordaddr); +static int mac802154_rspassociate(FAR struct ieee802154_mac_s *mac, + uint8_t eadr, uint16_t saddr, int status); +static int mac802154_rsporphan(FAR struct ieee802154_mac_s *mac, + FAR uint8_t *orphanaddr, uint16_t saddr, bool associated); -/* data */ +/**************************************************************************** + * Private Data + ****************************************************************************/ + static const struct ieee802154_macops_s mac802154ops = { .req_data = mac802154_reqdata @@ -221,30 +199,31 @@ static int mac802154_defaultmib(FAR struct ieee802154_privmac_s *priv) priv->macBattLifeExtPeriods = 0; priv->macMaxCSMABackoffs = 4; - priv->macBeaconOrder = 15; - priv->macSuperframeOrder = 15; + priv->macBeaconOrder = 15; + priv->macSuperframeOrder = 15; - priv->macMinBE = 3; - priv->macGTSPermit = 1; - priv->macPromiscuousMode = 0; - priv->macRxOnWhenIdle = 0; - priv->macBeaconTxTime = 0x000000; + priv->macMinBE = 3; + priv->macGTSPermit = 1; + priv->macPromiscuousMode = 0; + priv->macRxOnWhenIdle = 0; + priv->macBeaconTxTime = 0x000000; priv->macBeaconPayloadLength = 0; - priv->macBSN = 0; /*shall be random*/ + priv->macBSN = 0; /* Shall be random */ priv->macCoordExtendedAddress[8]; - priv->macCoordShortAddress = 0xffff; - priv->macDSN = 0 /*shall be random*/; - priv->macPANId = 0xffff; - priv->macShortAddress = 0xffff; + priv->macCoordShortAddress = 0xffff; + priv->macDSN = 0; /* Shall be random */ + priv->macPANId = 0xffff; + priv->macShortAddress = 0xffff; priv->macTransactionPersistenceTime = 0x01f4; #if 0 /* Security MIB */ - priv->macACLEntryDescriptorSetSize = 0; - priv->macDefaultSecurity = 0; - priv->macDefaultSecuritySuite = 0; + + priv->macACLEntryDescriptorSetSize = 0; + priv->macDefaultSecurity = 0; + priv->macDefaultSecuritySuite = 0; priv->macDefaultSecurityMaterialLength = 0x15; - priv->macSecurityMode = 0; + priv->macSecurityMode = 0; #endif } @@ -279,11 +258,9 @@ static int mac802154_applymib(FAR struct ieee802154_privmac_s *priv) ****************************************************************************/ static int mac802154_reqdata(FAR struct ieee802154_mac_s *mac, - uint8_t handle, - uint8_t *buf, - int len) + uint8_t handle, FAR uint8_t *buf, int len) { - FAR struct ieee802154_privmac_s * priv = (FAR struct ieee802154_privmac_s *) mac; + FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; return -ENOTTY; } @@ -298,9 +275,9 @@ static int mac802154_reqdata(FAR struct ieee802154_mac_s *mac, ****************************************************************************/ static int mac802154_reqpurge(FAR struct ieee802154_mac_s *mac, - uint8_t handle) + uint8_t handle) { - FAR struct ieee802154_privmac_s * priv = (FAR struct ieee802154_privmac_s *) mac; + FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; return -ENOTTY; } @@ -318,7 +295,7 @@ static int mac802154_reqassociate(FAR struct ieee802154_mac_s *mac, uint16_t panid, uint8_t *coordeadr) { - FAR struct ieee802154_privmac_s * priv = (FAR struct ieee802154_privmac_s *) mac; + FAR struct ieee802154_privmac_s * priv = (FAR struct ieee802154_privmac_s *)mac; return -ENOTTY; } @@ -335,10 +312,9 @@ static int mac802154_reqassociate(FAR struct ieee802154_mac_s *mac, ****************************************************************************/ static int mac802154_reqdisassociate(FAR struct ieee802154_mac_s *mac, - uint8_t *eadr, - uint8_t reason) + FAR uint8_t *eadr, uint8_t reason) { - FAR struct ieee802154_privmac_s * priv = (FAR struct ieee802154_privmac_s *) mac; + FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; return -ENOTTY; } @@ -355,7 +331,7 @@ static int mac802154_reqdisassociate(FAR struct ieee802154_mac_s *mac, static int mac802154_reqget(FAR struct ieee802154_mac_s *mac, int attribute) { - FAR struct ieee802154_privmac_s * priv = (FAR struct ieee802154_privmac_s *) mac; + FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; return -ENOTTY; } @@ -371,9 +347,9 @@ static int mac802154_reqget(FAR struct ieee802154_mac_s *mac, ****************************************************************************/ static int mac802154_reqgts(FAR struct ieee802154_mac_s *mac, - uint8_t* characteristics) + FAR uint8_t *characteristics) { - FAR struct ieee802154_privmac_s * priv = (FAR struct ieee802154_privmac_s *) mac; + FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; return -ENOTTY; } @@ -406,11 +382,9 @@ static int mac802154_reqreset(FAR struct ieee802154_mac_s *mac, ****************************************************************************/ static int mac802154_reqrxenable(FAR struct ieee802154_mac_s *mac, - bool deferrable, - int ontime, - int duration) + bool deferrable, int ontime, int duration) { - FAR struct ieee802154_privmac_s * priv = (FAR struct ieee802154_privmac_s *) mac; + FAR struct ieee802154_privmac_s * priv = (FAR struct ieee802154_privmac_s *)mac; return -ENOTTY; } @@ -430,11 +404,9 @@ static int mac802154_reqrxenable(FAR struct ieee802154_mac_s *mac, ****************************************************************************/ static int mac802154_reqscan(FAR struct ieee802154_mac_s *mac, - uint8_t type, - uint32_t channels, - int duration) + uint8_t type, uint32_t channels, int duration) { - FAR struct ieee802154_privmac_s * priv = (FAR struct ieee802154_privmac_s *) mac; + FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; return -ENOTTY; } @@ -449,11 +421,9 @@ static int mac802154_reqscan(FAR struct ieee802154_mac_s *mac, ****************************************************************************/ static int mac802154_reqset(FAR struct ieee802154_mac_s *mac, - int attribute, - uint8_t *value, - int valuelen) + int attribute, FAR uint8_t *value, int valuelen) { - FAR struct ieee802154_privmac_s * priv = (FAR struct ieee802154_privmac_s *) mac; + FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; return -ENOTTY; } @@ -468,15 +438,11 @@ static int mac802154_reqset(FAR struct ieee802154_mac_s *mac, ****************************************************************************/ static int mac802154_reqstart(FAR struct ieee802154_mac_s *mac, - uint16_t panid, - int channel, - uint8_t bo, - uint8_t fo, - bool coord, - bool batext, + uint16_t panid, int channel, uint8_t bo, + uint8_t fo, bool coord, bool batext, bool realign) { - FAR struct ieee802154_privmac_s * priv = (FAR struct ieee802154_privmac_s *) mac; + FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; return -ENOTTY; } @@ -492,10 +458,9 @@ static int mac802154_reqstart(FAR struct ieee802154_mac_s *mac, ****************************************************************************/ static int mac802154_reqsync(FAR struct ieee802154_mac_s *mac, - int channel, - bool track) + int channel, bool track) { - FAR struct ieee802154_privmac_s * priv = (FAR struct ieee802154_privmac_s *) mac; + FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; return -ENOTTY; } @@ -511,9 +476,9 @@ static int mac802154_reqsync(FAR struct ieee802154_mac_s *mac, ****************************************************************************/ static int mac802154_reqpoll(FAR struct ieee802154_mac_s *mac, - uint8_t *coordaddr) + FAR uint8_t *coordaddr) { - FAR struct ieee802154_privmac_s * priv = (FAR struct ieee802154_privmac_s *) mac; + FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; return -ENOTTY; } @@ -527,11 +492,9 @@ static int mac802154_reqpoll(FAR struct ieee802154_mac_s *mac, ****************************************************************************/ static int mac802154_rspassociate(FAR struct ieee802154_mac_s *mac, - uint8_t eadr, - uint16_t saddr, - int status) + uint8_t eadr, uint16_t saddr, int status) { - FAR struct ieee802154_privmac_s * priv = (FAR struct ieee802154_privmac_s *) mac; + FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; return -ENOTTY; } @@ -545,11 +508,10 @@ static int mac802154_rspassociate(FAR struct ieee802154_mac_s *mac, ****************************************************************************/ static int mac802154_rsporphan(FAR struct ieee802154_mac_s *mac, - uint8_t *orphanaddr, - uint16_t saddr, + FAR uint8_t *orphanaddr, uint16_t saddr, bool associated) { - FAR struct ieee802154_privmac_s * priv = (FAR struct ieee802154_privmac_s *) mac; + FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; return -ENOTTY; } @@ -565,22 +527,26 @@ static int mac802154_rsporphan(FAR struct ieee802154_mac_s *mac, * ****************************************************************************/ -FAR struct ieee802154_mac_s * mac802154_register(FAR struct ieee802154_radio_s *radiodev, unsigned int minor) +FAR struct ieee802154_mac_s * + mac802154_register(FAR struct ieee802154_radio_s *radiodev, + unsigned int minor) { FAR struct ieee802154_privmac_s *mac; - /* allocate object */ - mac = (FAR struct ieee802154_privmac_s *)kmm_zalloc(sizeof(struct ieee802154_privmac_s)); + /* Allocate object */ + + mac = (FAR struct ieee802154_privmac_s *) + kmm_zalloc(sizeof(struct ieee802154_privmac_s)); if(!mac) { return NULL; } - /* init fields */ + /* Initialize fields */ + mac->pubmac.radio = radiodev; mac->pubmac.ops = mac802154ops; mac802154_defaultmib(mac); mac802154_applymib(mac); return &mac->pubmac; } - From 7a814ce1dc3b41efb069986ea8071389a0e2e505 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 15 Mar 2017 13:44:03 -0600 Subject: [PATCH 004/183] Bring closer to NuttX coding standard. --- wireless/ieee802154/ieee802154_device.c | 279 +++++++++++++++++------- 1 file changed, 200 insertions(+), 79 deletions(-) diff --git a/wireless/ieee802154/ieee802154_device.c b/wireless/ieee802154/ieee802154_device.c index 75921a88cdd..f1413b31cf0 100644 --- a/wireless/ieee802154/ieee802154_device.c +++ b/wireless/ieee802154/ieee802154_device.c @@ -34,9 +34,14 @@ * ****************************************************************************/ +/**************************************************************************** + * Included Files + ****************************************************************************/ + #include #include +#include #include #include #include @@ -47,22 +52,30 @@ #include #include +/**************************************************************************** + * Private Types + ****************************************************************************/ + struct ieee802154_devwrapper_s { - FAR struct ieee802154_radio_s *child; - sem_t devsem; /* Device access serialization semaphore */ - int opened; /* this device can only be opened once */ + FAR struct ieee802154_radio_s *child; + sem_t devsem; /* Device access serialization semaphore */ + bool opened; /* This device can only be opened once */ }; -/* when rx interrupt is complete, it calls sem_post(&dev->rxsem); */ -/* when tx interrupt is complete, it calls sem_post(&dev->txsem); */ +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ -static void ieee802154dev_semtake(FAR struct ieee802154_devwrapper_s *dev); -static int ieee802154dev_open (FAR struct file *filep); -static int ieee802154dev_close (FAR struct file *filep); -static ssize_t ieee802154dev_read (FAR struct file *filep, FAR char *buffer, size_t len); -static ssize_t ieee802154dev_write (FAR struct file *filep, FAR const char *buffer, size_t len); -static int ieee802154dev_ioctl (FAR struct file *filep, int cmd, unsigned long arg); +static void ieee802154dev_semtake(FAR struct ieee802154_devwrapper_s *dev); +static int ieee802154dev_open(FAR struct file *filep); +static int ieee802154dev_close(FAR struct file *filep); +static ssize_t ieee802154dev_read(FAR struct file *filep, FAR char *buffer, + size_t len); +static ssize_t ieee802154dev_write(FAR struct file *filep, + FAR const char *buffer, size_t len); +static int ieee802154dev_ioctl(FAR struct file *filep, int cmd, + unsigned long arg); /**************************************************************************** * Private Data @@ -74,13 +87,20 @@ static const struct file_operations ieee802154dev_fops = ieee802154dev_close, /* close */ ieee802154dev_read , /* read */ ieee802154dev_write, /* write */ - 0 , /* seek */ + NULL, /* seek */ ieee802154dev_ioctl /* ioctl */ #ifndef CONFIG_DISABLE_POLL - , 0 /* poll */ + , NULL /* poll */ +#endif +#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS + , NULL /* unlink */ #endif }; +/**************************************************************************** + * Private Functions + ****************************************************************************/ + /**************************************************************************** * Name: ieee802154dev_semtake * @@ -98,7 +118,8 @@ static void ieee802154dev_semtake(FAR struct ieee802154_devwrapper_s *dev) /* The only case that an error should occur here is if * the wait was awakened by a signal. */ - ASSERT(errno == EINTR); + + DEBUGASSERT(errno == EINTR); } } @@ -125,24 +146,32 @@ static inline void ieee802154dev_semgive(FAR struct ieee802154_devwrapper_s *dev static int ieee802154dev_open(FAR struct file *filep) { - FAR struct inode *inode = filep->f_inode; - FAR struct ieee802154_devwrapper_s *dev = inode->i_private; + FAR struct inode *inode; + FAR struct ieee802154_devwrapper_s *dev; + + DEBUGASSERT(filep != NULL && filep->f_inode != NULL); + inode = filep->f_inode; + dev = inode->i_private; + DEBUGASSERT(dev != NULL); + + /* Get exclusive access to the driver data structures */ ieee802154dev_semtake(dev); if (dev->opened) { + /* Already opened */ + return -EMFILE; } else { - /* Enable interrupts (only rx for now)*/ //mrf24j40_setreg(dev->spi, MRF24J40_INTCON, ~(MRF24J40_INTCON_RXIE) ); //dev->lower->enable(dev->lower, TRUE); - dev->opened = TRUE; + dev->opened = true; } ieee802154dev_semgive(dev); @@ -159,15 +188,24 @@ static int ieee802154dev_open(FAR struct file *filep) static int ieee802154dev_close(FAR struct file *filep) { - FAR struct inode *inode = filep->f_inode; - FAR struct ieee802154_devwrapper_s *dev = inode->i_private; + FAR struct inode *inode; + FAR struct ieee802154_devwrapper_s *dev; int ret = OK; + DEBUGASSERT(filep != NULL && filep->f_inode != NULL); + inode = filep->f_inode; + dev = inode->i_private; + DEBUGASSERT(dev != NULL); + + /* Get exclusive access to the driver data structures */ + ieee802154dev_semtake(dev); - if(!dev->opened) + if (!dev->opened) { - ret = -EIO; + /* Driver has not been opened */ + + ret = -EIO; } else { @@ -176,7 +214,7 @@ static int ieee802154dev_close(FAR struct file *filep) //mrf24j40_setreg(dev->spi, MRF24J40_INTCON, 0xFF ); //dev->lower->enable(dev->lower, FALSE); - dev->opened = FALSE; + dev->opened = false; } ieee802154dev_semgive(dev); @@ -195,13 +233,20 @@ static int ieee802154dev_close(FAR struct file *filep) static ssize_t ieee802154dev_read(FAR struct file *filep, FAR char *buffer, size_t len) { - FAR struct inode *inode = filep->f_inode; - FAR struct ieee802154_devwrapper_s *dev = inode->i_private; + FAR struct inode *inode; + FAR struct ieee802154_devwrapper_s *dev; + FAR struct ieee802154_packet_s *buf; int ret = OK; - FAR struct ieee802154_packet_s *buf = (FAR struct ieee802154_packet_s*)buffer; + DEBUGASSERT(filep != NULL && filep->f_inode != NULL); + inode = filep->f_inode; + dev = inode->i_private; + DEBUGASSERT(dev != NULL && buffer != NULL); + buf = (FAR struct ieee802154_packet_s*)buffer; - if (lenchild->rxsem); #else @@ -229,13 +275,12 @@ static ssize_t ieee802154dev_read(FAR struct file *filep, FAR char *buffer, size goto done; } - /* disable read until we have process the current read */ - dev->child->ops->rxenable(dev->child, 0, NULL); + /* Disable read until we have process the current read */ + dev->child->ops->rxenable(dev->child, 0, NULL); ret = buf->len; done: - return ret; } @@ -244,61 +289,76 @@ done: * * Description: * Send a packet immediately. - * TODO: Put a packet in the send queue. The packet will be sent as soon as possible. - * The buffer must point to a struct ieee802154_packet_s with the correct length. + * TODO: Put a packet in the send queue. The packet will be sent as soon + * as possible. The buffer must point to a struct ieee802154_packet_s + * with the correct length. * ****************************************************************************/ -static ssize_t ieee802154dev_write(FAR struct file *filep, FAR const char *buffer, size_t len) +static ssize_t ieee802154dev_write(FAR struct file *filep, + FAR const char *buffer, size_t len) { - FAR struct inode *inode = filep->f_inode; - FAR struct ieee802154_devwrapper_s *dev = inode->i_private; - FAR struct ieee802154_packet_s *packet; - int ret = OK; - - /* TODO: Make this an option or have a new method of doing timeout from ioctrl */ + FAR struct inode *inode; + FAR struct ieee802154_devwrapper_s *dev; + FAR struct ieee802154_packet_s *packet; FAR struct timespec timeout; + int ret = OK; + + DEBUGASSERT(filep != NULL && filep->f_inode != NULL); + inode = filep->f_inode; + dev = inode->i_private; + DEBUGASSERT(dev != NULL); + + /* Get exclusive access to the driver data structures */ + + /* TODO: Make this an option or have a new method of doing timeout from + * ioctrl. + */ timeout.tv_sec = 1; timeout.tv_nsec = 0; - /* sanity checks */ + /* Sanity checks */ - if (lenlen > 125) /* Max len 125, 2 FCS bytes auto added by mrf*/ + if (packet->len > 125) /* Max len 125, 2 FCS bytes auto added by mrf */ { ret = -EPERM; - // goto done; + //goto done; DEBUGASSERT(0); } /* Copy packet to normal device TX fifo. * Beacons and GTS transmission will be handled via IOCTLs */ - ret = dev->child->ops->transmit(dev->child, packet); - if(ret != packet->len) + ret = dev->child->ops->transmit(dev->child, packet); + if (ret != packet->len) { ret = -EPERM; goto done; } - if(sem_timedwait(&dev->child->txsem, &timeout)) + if (sem_timedwait(&dev->child->txsem, &timeout)) { dbg("Radio Device timedout on Tx\n"); } done: - /* okay, tx interrupt received. check transmission status to decide success. */ + /* Okay, tx interrupt received. check transmission status to decide success. */ return ret; } @@ -311,33 +371,95 @@ done: * ****************************************************************************/ -static int ieee802154dev_ioctl(FAR struct file *filep, int cmd, unsigned long arg) +static int ieee802154dev_ioctl(FAR struct file *filep, int cmd, + unsigned long arg) { - FAR struct inode *inode = filep->f_inode; - FAR struct ieee802154_devwrapper_s *dev = inode->i_private; - FAR struct ieee802154_radio_s *child = dev->child; + FAR struct inode *inode; + FAR struct ieee802154_devwrapper_s *dev; + FAR struct ieee802154_radio_s *child; int ret = OK; - switch(cmd) + DEBUGASSERT(filep != NULL && filep->f_inode != NULL); + inode = filep->f_inode; + dev = inode->i_private; + DEBUGASSERT(dev != NULL && dev->child != NULL; + child = dev->child; + + /* Get exclusive access to the driver data structures */ + + switch (cmd) { - case MAC854IOCSCHAN : ret = child->ops->setchannel (child, (uint8_t) arg); break; - case MAC854IOCGCHAN : ret = child->ops->getchannel (child, (FAR uint8_t*) arg); break; - case MAC854IOCSPANID : ret = child->ops->setpanid (child, (uint16_t) arg); break; - case MAC854IOCGPANID : ret = child->ops->getpanid (child, (FAR uint16_t*) arg); break; - case MAC854IOCSSADDR : ret = child->ops->setsaddr (child, (uint16_t) arg); break; - case MAC854IOCGSADDR : ret = child->ops->getsaddr (child, (FAR uint16_t*) arg); break; - case MAC854IOCSEADDR : ret = child->ops->seteaddr (child, (FAR uint8_t*) arg); break; - case MAC854IOCGEADDR : ret = child->ops->geteaddr (child, (FAR uint8_t*) arg); break; - case MAC854IOCSPROMISC: ret = child->ops->setpromisc (child, (bool) arg); break; - case MAC854IOCGPROMISC: ret = child->ops->getpromisc (child, (FAR bool*) arg); break; - case MAC854IOCSDEVMODE: ret = child->ops->setdevmode (child, (uint8_t) arg); break; - case MAC854IOCGDEVMODE: ret = child->ops->getdevmode (child, (FAR uint8_t*) arg); break; - case MAC854IOCSTXP : ret = child->ops->settxpower (child, (int32_t) arg); break; - case MAC854IOCGTXP : ret = child->ops->gettxpower (child, (FAR int32_t*) arg); break; - case MAC854IOCSCCA : ret = child->ops->setcca (child, (FAR struct ieee802154_cca_s*)arg); break; - case MAC854IOCGCCA : ret = child->ops->getcca (child, (FAR struct ieee802154_cca_s*)arg); break; - case MAC854IOCGED : ret = child->ops->energydetect(child, (FAR uint8_t*) arg); break; - default : ret = child->ops->ioctl (child, cmd, arg); + case MAC854IOCSCHAN: + ret = child->ops->setchannel(child, (uint8_t)arg); + break; + + case MAC854IOCGCHAN: + ret = child->ops->getchannel(child, (FAR uint8_t*)arg); + break; + + case MAC854IOCSPANID: + ret = child->ops->setpanid(child, (uint16_t)arg); + break; + + case MAC854IOCGPANID: + ret = child->ops->getpanid(child, (FAR uint16_t*)arg); + break; + + case MAC854IOCSSADDR: + ret = child->ops->setsaddr(child, (uint16_t)arg); + break; + + case MAC854IOCGSADDR: + ret = child->ops->getsaddr(child, (FAR uint16_t*)arg); + break; + + case MAC854IOCSEADDR: + ret = child->ops->seteaddr(child, (FAR uint8_t*)arg); + break; + + case MAC854IOCGEADDR: + ret = child->ops->geteaddr(child, (FAR uint8_t*)arg); + break; + + case MAC854IOCSPROMISC: + ret = child->ops->setpromisc(child, (bool)arg); + break; + + case MAC854IOCGPROMISC: + ret = child->ops->getpromisc(child, (FAR bool*)arg); + break; + + case MAC854IOCSDEVMODE: + ret = child->ops->setdevmode(child, (uint8_t)arg); + break; + + case MAC854IOCGDEVMODE: + ret = child->ops->getdevmode(child, (FAR uint8_t*)arg); + break; + + case MAC854IOCSTXP: + ret = child->ops->settxpower(child, (int32_t)arg); + break; + + case MAC854IOCGTXP: + ret = child->ops->gettxpower(child, (FAR int32_t*)arg); + break; + + case MAC854IOCSCCA: + ret = child->ops->setcca(child, (FAR struct ieee802154_cca_s*)arg); + break; + + case MAC854IOCGCCA: + ret = child->ops->getcca(child, (FAR struct ieee802154_cca_s*)arg); + break; + + case MAC854IOCGED: + ret = child->ops->energydetect(child, (FAR uint8_t*)arg); + break; + + default: + ret = child->ops->ioctl(child, cmd,arg); + break; } return ret; @@ -351,24 +473,23 @@ static int ieee802154dev_ioctl(FAR struct file *filep, int cmd, unsigned long ar * ****************************************************************************/ -int ieee802154_register(FAR struct ieee802154_radio_s *ieee, unsigned int minor) +int ieee802154_register(FAR struct ieee802154_radio_s *ieee, + unsigned int minor) { - char devname[16]; FAR struct ieee802154_devwrapper_s *dev; + char devname[16]; dev = kmm_zalloc(sizeof(struct ieee802154_devwrapper_s)); - - if (!dev) + if (dev == NULL) { return -ENOMEM; } dev->child = ieee; - sem_init(&dev->devsem , 0, 1); /* Allow the device to be opened once before blocking */ + sem_init(&dev->devsem, 0, 1); /* Allow the device to be opened once before blocking */ sprintf(devname, "/dev/ieee%d", minor); return register_driver(devname, &ieee802154dev_fops, 0666, dev); } - From fc6405d51995f32789aaa062a2badb6eae36fa46 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 15 Mar 2017 14:16:19 -0600 Subject: [PATCH 005/183] Bring closer to NuttX coding standard. --- drivers/wireless/ieee802154/at86rf23x.c | 1069 +++++++++++++---------- wireless/ieee802154/ieee802154_device.c | 2 +- 2 files changed, 597 insertions(+), 474 deletions(-) diff --git a/drivers/wireless/ieee802154/at86rf23x.c b/drivers/wireless/ieee802154/at86rf23x.c index 8d2e1cb1337..653a92b3131 100644 --- a/drivers/wireless/ieee802154/at86rf23x.c +++ b/drivers/wireless/ieee802154/at86rf23x.c @@ -65,7 +65,11 @@ ************************************************************************************/ #ifndef CONFIG_SCHED_HPWORK -#error High priority work queue required in this driver +# error High priority work queue required in this driver +#endif + +#ifndef CONFIG_SPI_EXCHANGE +# error CONFIG_SPI_EXCHANGE required for this driver #endif #ifndef CONFIG_IEEE802154_at86rf23x_SPIMODE @@ -84,38 +88,36 @@ #define AT86RF23X_RXMODE_AUTOACK 3 /* Definitions for PA control on high power modules */ + #define AT86RF23X_PA_AUTO 1 #define AT86RF23X_PA_ED 2 #define AT86RF23X_PA_SLEEP 3 - /************************************************************************************ * Private Types ************************************************************************************/ -/* - * AT86RF23x device instance +/* AT86RF23x device instance * * Make sure that struct ieee802154_radio_s remains first. If not it will break the * code - * */ + struct at86rf23x_dev_s { - struct ieee802154_radio_s ieee; /* Public device instance */ - FAR struct spi_dev_s *spi; /* Saved SPI interface instance */ - struct work_s irqwork; /* Interrupt continuation work queue support */ - FAR const struct at86rf23x_lower_s *lower; /* Low-level MCU-specific support */ - uint16_t panid; /* PAN identifier, FFFF = not set */ - uint16_t saddr; /* short address, FFFF = not set */ - uint8_t eaddr[8]; /* extended address, FFFFFFFFFFFFFFFF = not set */ - uint8_t channel; /* 11 to 26 for the 2.4 GHz band */ - uint8_t devmode; /* device mode: device, coord, pancoord */ - uint8_t paenabled; /* enable usage of PA */ - uint8_t rxmode; /* Reception mode: Main, no CRC, promiscuous */ - int32_t txpower; /* TX power in mBm = dBm/100 */ - struct ieee802154_cca_s cca; /* Clear channel assessement method */ - + struct ieee802154_radio_s ieee; /* Public device instance */ + FAR struct spi_dev_s *spi; /* Saved SPI interface instance */ + struct work_s irqwork; /* Interrupt continuation work queue support */ + FAR const struct at86rf23x_lower_s *lower; /* Low-level MCU-specific support */ + uint16_t panid; /* PAN identifier, FFFF = not set */ + uint16_t saddr; /* Short address, FFFF = not set */ + uint8_t eaddr[8]; /* Extended address, FFFFFFFFFFFFFFFF = not set */ + uint8_t channel; /* 11 to 26 for the 2.4 GHz band */ + uint8_t devmode; /* Device mode: device, coord, pancoord */ + uint8_t paenabled; /* Enable usage of PA */ + uint8_t rxmode; /* Reception mode: Main, no CRC, promiscuous */ + int32_t txpower; /* TX power in mBm = dBm/100 */ + struct ieee802154_cca_s cca; /* Clear channel assessement method */ }; /**************************************************************************** @@ -123,45 +125,74 @@ struct at86rf23x_dev_s ****************************************************************************/ /* Internal operations */ + static void at86rf23x_lock(FAR struct spi_dev_s *spi); static void at86rf23x_unlock(FAR struct spi_dev_s *spi); -static void at86rf23x_setreg(FAR struct spi_dev_s *spi, uint32_t addr, uint8_t val); +static void at86rf23x_setreg(FAR struct spi_dev_s *spi, uint32_t addr, + uint8_t val); static uint8_t at86rf23x_getreg(FAR struct spi_dev_s *spi, uint32_t addr); -static int at86rf23x_writeframe(FAR struct spi_dev_s *spi, uint8_t *frame, uint8_t len); -static uint8_t at86rf23x_readframe(FAR struct spi_dev_s *spi, uint8_t *frame_rx); -static int at86rf23x_setTRXstate(FAR struct at86rf23x_dev_s *dev, uint8_t state, uint8_t force); +static int at86rf23x_writeframe(FAR struct spi_dev_s *spi, FAR uint8_t *frame, + uint8_t len); +static uint8_t at86rf23x_readframe(FAR struct spi_dev_s *spi, + FAR uint8_t *frame_rx); +static int at86rf23x_setTRXstate(FAR struct at86rf23x_dev_s *dev, + uint8_t state, uint8_t force); static uint8_t at86rf23x_getTRXstate(FAR struct at86rf23x_dev_s *dev); static int at86rf23x_resetrf(FAR struct at86rf23x_dev_s *dev); static int at86rf23x_initialize(FAR struct at86rf23x_dev_s *dev); -static int at86rf23x_regdump(FAR struct at86rf23x_dev_s *dev); -static void at86rf23x_irqwork_rx(FAR struct at86rf23x_dev_s *dev); -static void at86rf23x_irqwork_tx(FAR struct at86rf23x_dev_s *dev); -static void at86rf23x_irqworker(FAR void *arg); -static int at86rf23x_interrupt(int irq, FAR void *context); +static int at86rf23x_regdump(FAR struct at86rf23x_dev_s *dev); +static void at86rf23x_irqwork_rx(FAR struct at86rf23x_dev_s *dev); +static void at86rf23x_irqwork_tx(FAR struct at86rf23x_dev_s *dev); +static void at86rf23x_irqworker(FAR void *arg); +static int at86rf23x_interrupt(int irq, FAR void *context); /* Driver operations */ -static int at86rf23x_setchannel (FAR struct ieee802154_radio_s *ieee, uint8_t chan); -static int at86rf23x_getchannel (FAR struct ieee802154_radio_s *ieee, FAR uint8_t *chan); -static int at86rf23x_setpanid (FAR struct ieee802154_radio_s *ieee, uint16_t panid); -static int at86rf23x_getpanid (FAR struct ieee802154_radio_s *ieee, FAR uint16_t *panid); -static int at86rf23x_setsaddr (FAR struct ieee802154_radio_s *ieee, uint16_t saddr); -static int at86rf23x_getsaddr (FAR struct ieee802154_radio_s *ieee, FAR uint16_t *saddr); -static int at86rf23x_seteaddr (FAR struct ieee802154_radio_s *ieee, FAR uint8_t *eaddr); -static int at86rf23x_geteaddr (FAR struct ieee802154_radio_s *ieee, FAR uint8_t *eaddr); -static int at86rf23x_setpromisc (FAR struct ieee802154_radio_s *ieee, bool promisc); -static int at86rf23x_getpromisc (FAR struct ieee802154_radio_s *ieee, FAR bool *promisc); -static int at86rf23x_setdevmode (FAR struct ieee802154_radio_s *ieee, uint8_t mode); -static int at86rf23x_getdevmode (FAR struct ieee802154_radio_s *ieee, FAR uint8_t *mode); -static int at86rf23x_settxpower (FAR struct ieee802154_radio_s *ieee, int32_t txpwr); -static int at86rf23x_gettxpower (FAR struct ieee802154_radio_s *ieee, FAR int32_t *txpwr); -static int at86rf23x_setcca (FAR struct ieee802154_radio_s *ieee, FAR struct ieee802154_cca_s *cca); -static int at86rf23x_getcca (FAR struct ieee802154_radio_s *ieee, FAR struct ieee802154_cca_s *cca); -static int at86rf23x_ioctl (FAR struct ieee802154_radio_s *ieee, int cmd, unsigned long arg); -static int at86rf23x_energydetect(FAR struct ieee802154_radio_s *ieee, FAR uint8_t *energy); -static int at86rf23x_rxenable (FAR struct ieee802154_radio_s *ieee, bool state, FAR struct ieee802154_packet_s *packet); -static int at86rf23x_transmit (FAR struct ieee802154_radio_s *ieee, FAR struct ieee802154_packet_s *packet); +static int at86rf23x_setchannel(FAR struct ieee802154_radio_s *ieee, + uint8_t chan); +static int at86rf23x_getchannel(FAR struct ieee802154_radio_s *ieee, + FAR uint8_t *chan); +static int at86rf23x_setpanid(FAR struct ieee802154_radio_s *ieee, + uint16_t panid); +static int at86rf23x_getpanid(FAR struct ieee802154_radio_s *ieee, + FAR uint16_t *panid); +static int at86rf23x_setsaddr(FAR struct ieee802154_radio_s *ieee, + uint16_t saddr); +static int at86rf23x_getsaddr(FAR struct ieee802154_radio_s *ieee, + FAR uint16_t *saddr); +static int at86rf23x_seteaddr(FAR struct ieee802154_radio_s *ieee, + FAR uint8_t *eaddr); +static int at86rf23x_geteaddr(FAR struct ieee802154_radio_s *ieee, + FAR uint8_t *eaddr); +static int at86rf23x_setpromisc(FAR struct ieee802154_radio_s *ieee, + bool promisc); +static int at86rf23x_getpromisc(FAR struct ieee802154_radio_s *ieee, + FAR bool *promisc); +static int at86rf23x_setdevmode(FAR struct ieee802154_radio_s *ieee, + uint8_t mode); +static int at86rf23x_getdevmode(FAR struct ieee802154_radio_s *ieee, + FAR uint8_t *mode); +static int at86rf23x_settxpower(FAR struct ieee802154_radio_s *ieee, + int32_t txpwr); +static int at86rf23x_gettxpower(FAR struct ieee802154_radio_s *ieee, + FAR int32_t *txpwr); +static int at86rf23x_setcca(FAR struct ieee802154_radio_s *ieee, + FAR struct ieee802154_cca_s *cca); +static int at86rf23x_getcca(FAR struct ieee802154_radio_s *ieee, + FAR struct ieee802154_cca_s *cca); +static int at86rf23x_ioctl(FAR struct ieee802154_radio_s *ieee, int cmd, + unsigned long arg); +static int at86rf23x_energydetect(FAR struct ieee802154_radio_s *ieee, + FAR uint8_t *energy); +static int at86rf23x_rxenable(FAR struct ieee802154_radio_s *ieee, + bool state, FAR struct ieee802154_packet_s *packet); +static int at86rf23x_transmit(FAR struct ieee802154_radio_s *ieee, + FAR struct ieee802154_packet_s *packet); + +/**************************************************************************** + * Private Data + ****************************************************************************/ /* These are pointers to ALL registered at86rf23x devices. * This table is used during irqs to find the context @@ -174,37 +205,32 @@ static struct at86rf23x_dev_s g_at86rf23x_devices[1]; static const struct ieee802154_radioops_s at86rf23x_devops = { - .setchannel = at86rf23x_setchannel, - .getchannel = at86rf23x_getchannel, - .setpanid = at86rf23x_setpanid, - .getpanid = at86rf23x_getpanid, - .setsaddr = at86rf23x_setsaddr, - .getsaddr = at86rf23x_getsaddr, - .seteaddr = at86rf23x_seteaddr, - .geteaddr = at86rf23x_geteaddr, - .setpromisc = at86rf23x_setpromisc, - .getpromisc = at86rf23x_getpromisc, - .setdevmode = at86rf23x_setdevmode, - .getdevmode = at86rf23x_getdevmode, - .settxpower = at86rf23x_settxpower, - .gettxpower = at86rf23x_gettxpower, - .setcca = at86rf23x_setcca, - .getcca = at86rf23x_getcca, - .ioctl = at86rf23x_ioctl, + .setchannel = at86rf23x_setchannel, + .getchannel = at86rf23x_getchannel, + .setpanid = at86rf23x_setpanid, + .getpanid = at86rf23x_getpanid, + .setsaddr = at86rf23x_setsaddr, + .getsaddr = at86rf23x_getsaddr, + .seteaddr = at86rf23x_seteaddr, + .geteaddr = at86rf23x_geteaddr, + .setpromisc = at86rf23x_setpromisc, + .getpromisc = at86rf23x_getpromisc, + .setdevmode = at86rf23x_setdevmode, + .getdevmode = at86rf23x_getdevmode, + .settxpower = at86rf23x_settxpower, + .gettxpower = at86rf23x_gettxpower, + .setcca = at86rf23x_setcca, + .getcca = at86rf23x_getcca, + .ioctl = at86rf23x_ioctl, .energydetect = at86rf23x_energydetect, - .rxenable = at86rf23x_rxenable, - .transmit = at86rf23x_transmit + .rxenable = at86rf23x_rxenable, + .transmit = at86rf23x_transmit }; /**************************************************************************** * Private Functions ****************************************************************************/ -#ifndef CONFIG_SPI_EXCHANGE -#error CONFIG_SPI_EXCHANGE required for this driver -#endif - -/* hardware access routines */ - + /**************************************************************************** * Name: at86rf23x_lock * @@ -215,11 +241,10 @@ static const struct ieee802154_radioops_s at86rf23x_devops = static void at86rf23x_lock(FAR struct spi_dev_s *spi) { - SPI_LOCK (spi, 1); - SPI_SETBITS (spi, 8); - SPI_SETMODE (spi, CONFIG_IEEE802154_at86rf23x_SPIMODE ); - SPI_SETFREQUENCY(spi, CONFIG_IEEE802154_at86rf23x_FREQUENCY ); - + SPI_LOCK(spi, 1); + SPI_SETBITS(spi, 8); + SPI_SETMODE(spi, CONFIG_IEEE802154_at86rf23x_SPIMODE); + SPI_SETFREQUENCY(spi, CONFIG_IEEE802154_at86rf23x_FREQUENCY); } /**************************************************************************** @@ -232,7 +257,7 @@ static void at86rf23x_lock(FAR struct spi_dev_s *spi) static void at86rf23x_unlock(FAR struct spi_dev_s *spi) { - SPI_LOCK(spi,0); + SPI_LOCK(spi, 0); } /**************************************************************************** @@ -243,7 +268,8 @@ static void at86rf23x_unlock(FAR struct spi_dev_s *spi) * ****************************************************************************/ -static void at86rf23x_setreg(FAR struct spi_dev_s *spi, uint32_t addr, uint8_t val) +static void at86rf23x_setreg(FAR struct spi_dev_s *spi, uint32_t addr, + uint8_t val) { uint8_t reg[2]; @@ -258,7 +284,6 @@ static void at86rf23x_setreg(FAR struct spi_dev_s *spi, uint32_t addr, uint8_t v at86rf23x_unlock(spi); vdbg("0x%02X->r[0x%02X]\n", val, addr); - } /**************************************************************************** @@ -268,25 +293,27 @@ static void at86rf23x_setreg(FAR struct spi_dev_s *spi, uint32_t addr, uint8_t v * Return the value of an at86rf23x device register * ****************************************************************************/ + static uint8_t at86rf23x_getreg(FAR struct spi_dev_s *spi, uint32_t addr) { - uint8_t reg[2]; - uint8_t val[2]; + uint8_t reg[2]; + uint8_t val[2]; - /* Add Read mask to desired register */ - reg[0] = addr | RF23X_SPI_REG_READ; + /* Add Read mask to desired register */ - at86rf23x_lock (spi); + reg[0] = addr | RF23X_SPI_REG_READ; - SPI_SELECT (spi, SPIDEV_IEEE802154, true); - SPI_EXCHANGE (spi, reg, val, 2); - SPI_SELECT (spi, SPIDEV_IEEE802154, false); + at86rf23x_lock (spi); - at86rf23x_unlock(spi); + SPI_SELECT(spi, SPIDEV_IEEE802154, true); + SPI_EXCHANGE(spi, reg, val, 2); + SPI_SELECT(spi, SPIDEV_IEEE802154, false); - vdbg("r[0x%02X]=0x%02X\n",addr,val[1]); + at86rf23x_unlock(spi); - return val[1]; + vdbg("r[0x%02X]=0x%02X\n",addr,val[1]); + + return val[1]; } /**************************************************************************** @@ -298,17 +325,15 @@ static uint8_t at86rf23x_getreg(FAR struct spi_dev_s *spi, uint32_t addr) * register. * ****************************************************************************/ -static void at86rf23x_setregbits(FAR struct spi_dev_s *spi, - uint8_t addr, - uint8_t pos, - uint8_t mask, - uint8_t val) -{ - uint8_t reg; - reg = at86rf23x_getreg(spi, addr); - reg = (reg & ~(mask << pos)) | (val << pos); - at86rf23x_setreg(spi, addr, reg); +static void at86rf23x_setregbits(FAR struct spi_dev_s *spi, uint8_t addr, + uint8_t pos, uint8_t mask, uint8_t val) +{ + uint8_t reg; + + reg = at86rf23x_getreg(spi, addr); + reg = (reg & ~(mask << pos)) | (val << pos); + at86rf23x_setreg(spi, addr, reg); } /**************************************************************************** @@ -318,17 +343,16 @@ static void at86rf23x_setregbits(FAR struct spi_dev_s *spi, * Return the value of an section of the at86rf23x device register. * ****************************************************************************/ -static uint8_t at86rf23x_getregbits(FAR struct spi_dev_s *spi, - uint8_t addr, - uint8_t pos, - uint8_t mask) + +static uint8_t at86rf23x_getregbits(FAR struct spi_dev_s *spi, uint8_t addr, + uint8_t pos, uint8_t mask) { - uint8_t val; + uint8_t val; - val = at86rf23x_getreg(spi, addr); - val = (val >> pos) & mask; + val = at86rf23x_getreg(spi, addr); + val = (val >> pos) & mask; - return val; + return val; } /**************************************************************************** @@ -339,23 +363,25 @@ static uint8_t at86rf23x_getregbits(FAR struct spi_dev_s *spi, * initiate the transfer, just write to the buffer. * ****************************************************************************/ -static int at86rf23x_writeframe(FAR struct spi_dev_s *spi, uint8_t *frame, uint8_t len) + +static int at86rf23x_writeframe(FAR struct spi_dev_s *spi, FAR uint8_t *frame, + uint8_t len) { -// report_packet(frame_wr, len); - uint8_t reg = RF23X_SPI_FRAME_WRITE; +//report_packet(frame_wr, len); + uint8_t reg = RF23X_SPI_FRAME_WRITE; - at86rf23x_lock(spi); + at86rf23x_lock(spi); - SPI_SELECT(spi, SPIDEV_IEEE802154, true); + SPI_SELECT(spi, SPIDEV_IEEE802154, true); - SPI_SNDBLOCK(spi, ®, 1); - SPI_SNDBLOCK(spi, &frame, len); + SPI_SNDBLOCK(spi, ®, 1); + SPI_SNDBLOCK(spi, &frame, len); - SPI_SELECT(spi, SPIDEV_IEEE802154, false); + SPI_SELECT(spi, SPIDEV_IEEE802154, false); - at86rf23x_unlock(spi); + at86rf23x_unlock(spi); - return len; + return len; } /**************************************************************************** @@ -366,26 +392,27 @@ static int at86rf23x_writeframe(FAR struct spi_dev_s *spi, uint8_t *frame, uint8 * indicates a frame has been received. * ****************************************************************************/ -static uint8_t at86rf23x_readframe(FAR struct spi_dev_s *spi, uint8_t *frame_rx) + +static uint8_t at86rf23x_readframe(FAR struct spi_dev_s *spi, + FAR uint8_t *frame_rx) { - uint8_t len, reg; + uint8_t len, reg; - reg = RF23X_SPI_FRAME_READ; + reg = RF23X_SPI_FRAME_READ; - at86rf23x_lock(spi); - SPI_SELECT(spi, SPIDEV_IEEE802154, true); + at86rf23x_lock(spi); + SPI_SELECT(spi, SPIDEV_IEEE802154, true); - SPI_SNDBLOCK(spi, ®, 1); - SPI_RECVBLOCK(spi, &len, 1); - SPI_RECVBLOCK(spi, frame_rx, len+3); + SPI_SNDBLOCK(spi, ®, 1); + SPI_RECVBLOCK(spi, &len, 1); + SPI_RECVBLOCK(spi, frame_rx, len+3); - SPI_SELECT(spi, SPIDEV_IEEE802154, false); - at86rf23x_unlock(spi); + SPI_SELECT(spi, SPIDEV_IEEE802154, false); + at86rf23x_unlock(spi); - return len; + return len; } - /**************************************************************************** * Name: at86rf23x_getTRXstate * @@ -393,9 +420,10 @@ static uint8_t at86rf23x_readframe(FAR struct spi_dev_s *spi, uint8_t *frame_rx) * Return the current status of the TRX state machine. * ****************************************************************************/ + static uint8_t at86rf23x_getTRXstate(FAR struct at86rf23x_dev_s *dev) { - return at86rf23x_getregbits(dev->spi, RF23X_TRXSTATUS_STATUS); + return at86rf23x_getregbits(dev->spi, RF23X_TRXSTATUS_STATUS); } /**************************************************************************** @@ -409,15 +437,19 @@ static uint8_t at86rf23x_getTRXstate(FAR struct at86rf23x_dev_s *dev) * 510us. * ****************************************************************************/ -static int at86rf23x_setTRXstate(FAR struct at86rf23x_dev_s *dev, uint8_t state, uint8_t force) + +static int at86rf23x_setTRXstate(FAR struct at86rf23x_dev_s *dev, + uint8_t state, uint8_t force) { /* Get the current state of the transceiver */ + uint8_t status = at86rf23x_getTRXstate(dev); int ret = OK; /* TODO I don't have every state included verify this will work with SLEEP */ - if((status != TRX_STATUS_TRXOFF) && + + if ((status != TRX_STATUS_TRXOFF) && (status != TRX_STATUS_RXON) && (status != TRX_STATUS_PLLON) && (status != TRX_STATUS_RXAACKON) && @@ -431,164 +463,161 @@ static int at86rf23x_setTRXstate(FAR struct at86rf23x_dev_s *dev, uint8_t state, int8_t init_status = status; /* Start the state change */ + switch(state) { case TRX_CMD_TRXOFF: - if(status == TRX_STATUS_TRXOFF) - { - break; - } - /* verify in a state that will transfer to TRX_OFF if not check if force is required */ - if( (status == TRX_STATUS_RXON) || - (status == TRX_STATUS_PLLON) || - (status == TRX_STATUS_RXAACKON) || - (status == TRX_STATUS_TXARETON)) - { - at86rf23x_setregbits(dev->spi, RF23X_TRXCMD_STATE, TRX_CMD_TRXOFF); - up_udelay(RF23X_TIME_TRANSITION_PLL_ACTIVE); - } - else if(status == TRX_STATUS_PON) - { - at86rf23x_setregbits(dev->spi, RF23X_TRXCMD_STATE, TRX_CMD_TRXOFF); - up_udelay(RF23X_TIME_P_ON_TO_TRXOFF); - } - else if(force) - { - at86rf23x_setregbits(dev->spi, RF23X_TRXCMD_STATE, TRX_CMD_FORCETRXOFF); - up_udelay(RF23X_TIME_FORCE_TRXOFF); - } + if (status == TRX_STATUS_TRXOFF) + { + break; + } + + /* verify in a state that will transfer to TRX_OFF if not check if + * force is required. + */ + + if ((status == TRX_STATUS_RXON) || + (status == TRX_STATUS_PLLON) || + (status == TRX_STATUS_RXAACKON) || + (status == TRX_STATUS_TXARETON)) + { + at86rf23x_setregbits(dev->spi, RF23X_TRXCMD_STATE, TRX_CMD_TRXOFF); + up_udelay(RF23X_TIME_TRANSITION_PLL_ACTIVE); + } + else if (status == TRX_STATUS_PON) + { + at86rf23x_setregbits(dev->spi, RF23X_TRXCMD_STATE, TRX_CMD_TRXOFF); + up_udelay(RF23X_TIME_P_ON_TO_TRXOFF); + } + else if (force) + { + at86rf23x_setregbits(dev->spi, RF23X_TRXCMD_STATE, TRX_CMD_FORCETRXOFF); + up_udelay(RF23X_TIME_FORCE_TRXOFF); + } status = at86rf23x_getregbits(dev->spi, RF23X_TRXSTATUS_STATUS); + if (status != TRX_STATUS_TRXOFF) + { + ret = ERROR; + } - if(status != TRX_STATUS_TRXOFF) - { - ret = ERROR; - } - - break; + break; case TRX_CMD_RX_ON: - - if(status == TRX_STATUS_RXON) - { - break; - } - - if (status == TRX_STATUS_TRXOFF) - { - at86rf23x_setregbits(dev->spi, RF23X_TRXCMD_STATE, TRX_CMD_RX_ON); - up_udelay(RF23X_TIME_TRXOFF_TO_PLL); - } - - else if((status == TRX_STATUS_RXAACKON) || - (status == TRX_STATUS_RXON) || - (status == TRX_STATUS_PLLON) || - (status == TRX_STATUS_TXARETON)) - { - at86rf23x_setregbits(dev->spi, RF23X_TRXCMD_STATE, TRX_CMD_RX_ON); - up_udelay(RF23X_TIME_TRANSITION_PLL_ACTIVE); - } - - status = at86rf23x_getregbits(dev->spi, RF23X_TRXSTATUS_STATUS); - - if(status != TRX_STATUS_RXON) - { - ret = ERROR; - } - break; - - /* transition to PLL_ON */ - case TRX_CMD_PLL_ON: - - if(status == TRX_STATUS_PLLON) - { - break; - } + if (status == TRX_STATUS_RXON) + { + break; + } if (status == TRX_STATUS_TRXOFF) - { - at86rf23x_setregbits(dev->spi, RF23X_TRXCMD_STATE, TRX_CMD_PLL_ON); - up_udelay(RF23X_TIME_TRXOFF_TO_PLL); - } - else - { - at86rf23x_setregbits(dev->spi, RF23X_TRXCMD_STATE, TRX_CMD_PLL_ON); - up_udelay(RF23X_TIME_TRANSITION_PLL_ACTIVE); - } + { + at86rf23x_setregbits(dev->spi, RF23X_TRXCMD_STATE, TRX_CMD_RX_ON); + up_udelay(RF23X_TIME_TRXOFF_TO_PLL); + } + else if ((status == TRX_STATUS_RXAACKON) || + (status == TRX_STATUS_RXON) || + (status == TRX_STATUS_PLLON) || + (status == TRX_STATUS_TXARETON)) + { + at86rf23x_setregbits(dev->spi, RF23X_TRXCMD_STATE, TRX_CMD_RX_ON); + up_udelay(RF23X_TIME_TRANSITION_PLL_ACTIVE); + } status = at86rf23x_getregbits(dev->spi, RF23X_TRXSTATUS_STATUS); + if (status != TRX_STATUS_RXON) + { + ret = ERROR; + } + + break; + + /* Transition to PLL_ON */ + + case TRX_CMD_PLL_ON: + if (status == TRX_STATUS_PLLON) + { + break; + } + + if (status == TRX_STATUS_TRXOFF) + { + at86rf23x_setregbits(dev->spi, RF23X_TRXCMD_STATE, TRX_CMD_PLL_ON); + up_udelay(RF23X_TIME_TRXOFF_TO_PLL); + } + else + { + at86rf23x_setregbits(dev->spi, RF23X_TRXCMD_STATE, TRX_CMD_PLL_ON); + up_udelay(RF23X_TIME_TRANSITION_PLL_ACTIVE); + } + + status = at86rf23x_getregbits(dev->spi, RF23X_TRXSTATUS_STATUS); + if (status != TRX_STATUS_PLLON) + { + ret = ERROR; + } - if(status != TRX_STATUS_PLLON) - { - ret = ERROR; - } break; case TRX_CMD_RX_AACK_ON: - - if(status == TRX_STATUS_RXAACKON) - { - break; - } + if (status == TRX_STATUS_RXAACKON) + { + break; + } if (status == TRX_STATUS_TRXOFF || status == TRX_STATUS_TXARETON) - { - at86rf23x_setregbits(dev->spi, RF23X_TRXCMD_STATE, TRX_CMD_RX_ON); + { + at86rf23x_setregbits(dev->spi, RF23X_TRXCMD_STATE, TRX_CMD_RX_ON); - (status == TRX_STATUS_TRXOFF) ? up_udelay(RF23X_TIME_TRXOFF_TO_PLL) : - up_udelay(RF23X_TIME_TRANSITION_PLL_ACTIVE); - } + (status == TRX_STATUS_TRXOFF) ? up_udelay(RF23X_TIME_TRXOFF_TO_PLL) : + up_udelay(RF23X_TIME_TRANSITION_PLL_ACTIVE); + } status = at86rf23x_getTRXstate(dev); - if ((status == TRX_STATUS_RXON) || (status == TRX_STATUS_PLLON)) - { - at86rf23x_setregbits(dev->spi, RF23X_TRXCMD_STATE, TRX_CMD_RX_AACK_ON); - up_udelay(RF23X_TIME_TRANSITION_PLL_ACTIVE); - } + { + at86rf23x_setregbits(dev->spi, RF23X_TRXCMD_STATE, TRX_CMD_RX_AACK_ON); + up_udelay(RF23X_TIME_TRANSITION_PLL_ACTIVE); + } status = at86rf23x_getregbits(dev->spi, RF23X_TRXSTATUS_STATUS); - - if(status != TRX_STATUS_RXAACKON) - { - ret = ERROR; - } + if (status != TRX_STATUS_RXAACKON) + { + ret = ERROR; + } break; case TRX_STATUS_TXARETON: - - if(status == TRX_STATUS_TXARETON) - { - break; - } + if (status == TRX_STATUS_TXARETON) + { + break; + } if (status == TRX_STATUS_TRXOFF) - { - at86rf23x_setregbits(dev->spi, RF23X_TRXCMD_STATE, TRX_CMD_RX_ON); - up_udelay(RF23X_TIME_TRXOFF_TO_PLL); - } + { + at86rf23x_setregbits(dev->spi, RF23X_TRXCMD_STATE, TRX_CMD_RX_ON); + up_udelay(RF23X_TIME_TRXOFF_TO_PLL); + } if ((status == TRX_STATUS_RXON) || (status == TRX_STATUS_PLLON)) - { - at86rf23x_setregbits(dev->spi, RF23X_TRXCMD_STATE, TRX_CMD_TX_ARET_ON); - up_udelay(RF23X_TIME_TRANSITION_PLL_ACTIVE); - } + { + at86rf23x_setregbits(dev->spi, RF23X_TRXCMD_STATE, TRX_CMD_TX_ARET_ON); + up_udelay(RF23X_TIME_TRANSITION_PLL_ACTIVE); + } else if (status == TRX_STATUS_RXAACKON) - { - at86rf23x_setregbits(dev->spi, RF23X_TRXCMD_STATE, TRX_CMD_RX_ON); - up_udelay(RF23X_TIME_TRANSITION_PLL_ACTIVE); + { + at86rf23x_setregbits(dev->spi, RF23X_TRXCMD_STATE, TRX_CMD_RX_ON); + up_udelay(RF23X_TIME_TRANSITION_PLL_ACTIVE); - at86rf23x_setregbits(dev->spi, RF23X_TRXCMD_STATE, TRX_CMD_TX_ARET_ON); - up_udelay(RF23X_TIME_TRANSITION_PLL_ACTIVE); - } + at86rf23x_setregbits(dev->spi, RF23X_TRXCMD_STATE, TRX_CMD_TX_ARET_ON); + up_udelay(RF23X_TIME_TRANSITION_PLL_ACTIVE); + } status = at86rf23x_getregbits(dev->spi, RF23X_TRXSTATUS_STATUS); - - if(status != TRX_STATUS_TXARETON) - { - ret = ERROR; - } + if (status != TRX_STATUS_TXARETON) + { + ret = ERROR; + } break; @@ -606,20 +635,17 @@ static int at86rf23x_setTRXstate(FAR struct at86rf23x_dev_s *dev, uint8_t state, dbg("%s \n", EINVAL_STR); init_status = 0;/* Placed this here to keep compiler happy when not in debug */ return -EINVAL; - } - if(ret == ERROR) + + if (ret == ERROR) { dbg("State Transistion Error\n"); } vdbg("Radio state change state[0x%02x]->state[0x%02x]\n", init_status, status); - return ret; } -/* Publicized driver routines */ - /**************************************************************************** * Name: at86rf23x_setchannel * @@ -634,34 +660,40 @@ static int at86rf23x_setTRXstate(FAR struct at86rf23x_dev_s *dev, uint8_t state, * * ****************************************************************************/ -static int at86rf23x_setchannel(FAR struct ieee802154_radio_s *ieee, uint8_t chan) + +static int at86rf23x_setchannel(FAR struct ieee802154_radio_s *ieee, + uint8_t chan) { FAR struct at86rf23x_dev_s *dev = (FAR struct at86rf23x_dev_s *)ieee; uint8_t state; /* Validate if chan is a valid channel */ - if(chan<11 || chan>26) + + if (chan < 11 || chan > 26) { dbg("Invalid requested chan: %d\n",chan); return -EINVAL; } /* Validate we are in an acceptable mode to change the channel */ - state = at86rf23x_getTRXstate(dev); - if((TRX_STATUS_SLEEP == state) || (TRX_STATUS_PON == state)) { - dbg("Radio in invalid mode [%02x] to set the channel\n", state); - return ERROR; - } + state = at86rf23x_getTRXstate(dev); + + if ((TRX_STATUS_SLEEP == state) || (TRX_STATUS_PON == state)) + { + dbg("Radio in invalid mode [%02x] to set the channel\n", state); + return ERROR; + } + /* Set the Channel on the transceiver */ at86rf23x_setregbits(dev->spi, RF23X_CCA_BITS_CHANNEL, chan); /* Set the channel within local device */ + dev->channel = chan; vdbg("CHANNEL Changed to %d\n", chan); - return OK; } @@ -681,16 +713,19 @@ static int at86rf23x_setchannel(FAR struct ieee802154_radio_s *ieee, uint8_t cha * * ****************************************************************************/ -static int at86rf23x_getchannel(FAR struct ieee802154_radio_s *ieee, FAR uint8_t *chan) + +static int at86rf23x_getchannel(FAR struct ieee802154_radio_s *ieee, + FAR uint8_t *chan) { FAR struct at86rf23x_dev_s *dev = (FAR struct at86rf23x_dev_s *)ieee; /* Set the Channel on the transceiver */ + *chan = at86rf23x_getregbits(dev->spi, RF23X_CCA_BITS_CHANNEL); /* Set the channel within local device */ - dev->channel = *chan; + dev->channel = *chan; return OK; } @@ -701,7 +736,9 @@ static int at86rf23x_getchannel(FAR struct ieee802154_radio_s *ieee, FAR uint8_t * Define the PAN ID for the network. * ****************************************************************************/ -static int at86rf23x_setpanid(FAR struct ieee802154_radio_s *ieee, uint16_t panid) + +static int at86rf23x_setpanid(FAR struct ieee802154_radio_s *ieee, + uint16_t panid) { FAR struct at86rf23x_dev_s *dev = (struct at86rf23x_dev_s *)ieee; uint8_t *pan = (uint8_t *)&panid; @@ -719,14 +756,17 @@ static int at86rf23x_setpanid(FAR struct ieee802154_radio_s *ieee, uint16_t pani * Define the PAN ID for the network. * ****************************************************************************/ -static int at86rf23x_getpanid(FAR struct ieee802154_radio_s *ieee, FAR uint16_t *panid) + +static int at86rf23x_getpanid(FAR struct ieee802154_radio_s *ieee, + FAR uint16_t *panid) { FAR struct at86rf23x_dev_s *dev = (struct at86rf23x_dev_s *)ieee; uint8_t *pan = (uint8_t *)panid; + /* TODO: Check if we need to pay attention to endianness */ + pan[0] = at86rf23x_getreg(dev->spi, RF23X_REG_PANID0); pan[1] = at86rf23x_getreg(dev->spi, RF23X_REG_PANID1); - return OK; } @@ -737,7 +777,9 @@ static int at86rf23x_getpanid(FAR struct ieee802154_radio_s *ieee, FAR uint16_t * Define the Short Address for the device. * ****************************************************************************/ -static int at86rf23x_setsaddr(FAR struct ieee802154_radio_s *ieee, uint16_t saddr) + +static int at86rf23x_setsaddr(FAR struct ieee802154_radio_s *ieee, + uint16_t saddr) { FAR struct at86rf23x_dev_s *dev = (struct at86rf23x_dev_s *)ieee; uint8_t *addr = (uint8_t *)&saddr; @@ -755,11 +797,15 @@ static int at86rf23x_setsaddr(FAR struct ieee802154_radio_s *ieee, uint16_t sadd * Get the short address of the device. * ****************************************************************************/ -static int at86rf23x_getsaddr(FAR struct ieee802154_radio_s *ieee, FAR uint16_t *saddr) + +static int at86rf23x_getsaddr(FAR struct ieee802154_radio_s *ieee, + FAR uint16_t *saddr) { FAR struct at86rf23x_dev_s *dev = (struct at86rf23x_dev_s *)ieee; uint8_t *addr = (uint8_t *)saddr; + /* TODO: Check if we need to pay attention to endianness */ + addr[0] = at86rf23x_getreg(dev->spi, RF23X_REG_SADDR0); addr[1] = at86rf23x_getreg(dev->spi, RF23X_REG_SADDR1); @@ -773,10 +819,14 @@ static int at86rf23x_getsaddr(FAR struct ieee802154_radio_s *ieee, FAR uint16_t * Set the IEEE address of the device. * ****************************************************************************/ -static int at86rf23x_seteaddr(FAR struct ieee802154_radio_s *ieee, FAR uint8_t *eaddr) + +static int at86rf23x_seteaddr(FAR struct ieee802154_radio_s *ieee, + FAR uint8_t *eaddr) { FAR struct at86rf23x_dev_s *dev = (struct at86rf23x_dev_s *)ieee; + /* TODO: Check if we need to pay attention to endianness */ + at86rf23x_setreg(dev->spi, RF23X_REG_IEEEADDR0, eaddr[0]); at86rf23x_setreg(dev->spi, RF23X_REG_IEEEADDR1, eaddr[1]); at86rf23x_setreg(dev->spi, RF23X_REG_IEEEADDR2, eaddr[2]); @@ -796,10 +846,14 @@ static int at86rf23x_seteaddr(FAR struct ieee802154_radio_s *ieee, FAR uint8_t * * Get the IEEE address of the device. * ****************************************************************************/ -static int at86rf23x_geteaddr(FAR struct ieee802154_radio_s *ieee, FAR uint8_t *eaddr) + +static int at86rf23x_geteaddr(FAR struct ieee802154_radio_s *ieee, + FAR uint8_t *eaddr) { FAR struct at86rf23x_dev_s *dev = (struct at86rf23x_dev_s *)ieee; + /* TODO: Check if we need to pay attention to endianness */ + eaddr[0] = at86rf23x_getreg(dev->spi, RF23X_REG_IEEEADDR0); eaddr[1] = at86rf23x_getreg(dev->spi, RF23X_REG_IEEEADDR1); eaddr[2] = at86rf23x_getreg(dev->spi, RF23X_REG_IEEEADDR2); @@ -819,16 +873,18 @@ static int at86rf23x_geteaddr(FAR struct ieee802154_radio_s *ieee, FAR uint8_t * * enable/disable promiscuous mode. * ****************************************************************************/ -static int at86rf23x_setpromisc(FAR struct ieee802154_radio_s *ieee, bool promisc) + +static int at86rf23x_setpromisc(FAR struct ieee802154_radio_s *ieee, + bool promisc) { FAR struct at86rf23x_dev_s *dev = (struct at86rf23x_dev_s *)ieee; /* TODO: Check what mode I should be in to activate promiscuous mode: * This is way to simple of an implementation. Many other things should be set * and/or checked before we set the device into promiscuous mode - * */ - at86rf23x_setregbits(dev->spi, RF23X_XAHCTRL1_BITS_PROM_MODE, promisc); + */ + at86rf23x_setregbits(dev->spi, RF23X_XAHCTRL1_BITS_PROM_MODE, promisc); return OK; } @@ -839,12 +895,13 @@ static int at86rf23x_setpromisc(FAR struct ieee802154_radio_s *ieee, bool promis * Check if the device is in promiscuous mode. * ****************************************************************************/ -static int at86rf23x_getpromisc(FAR struct ieee802154_radio_s *ieee, FAR bool *promisc) + +static int at86rf23x_getpromisc(FAR struct ieee802154_radio_s *ieee, + FAR bool *promisc) { FAR struct at86rf23x_dev_s *dev = (struct at86rf23x_dev_s *)ieee; *promisc = at86rf23x_getregbits(dev->spi, RF23X_XAHCTRL1_BITS_PROM_MODE); - return OK; } @@ -855,31 +912,33 @@ static int at86rf23x_getpromisc(FAR struct ieee802154_radio_s *ieee, FAR bool *p * Check if the device is in promiscuous mode. * ****************************************************************************/ -static int at86rf23x_setdevmode(FAR struct ieee802154_radio_s *ieee, uint8_t mode) + +static int at86rf23x_setdevmode(FAR struct ieee802154_radio_s *ieee, + uint8_t mode) { FAR struct at86rf23x_dev_s *dev = (struct at86rf23x_dev_s *)ieee; - /* define dev mode */ - if(mode == IEEE802154_MODE_PANCOORD) - { - at86rf23x_setregbits(dev->spi, RF23X_CSMASEED1_IAMCOORD_BITS, 0x01); - } - else if(mode == IEEE802154_MODE_COORD) - { - /* ????? */ - } - else if(mode == IEEE802154_MODE_DEVICE) - { - at86rf23x_setregbits(dev->spi, RF23X_CSMASEED1_IAMCOORD_BITS, 0x00); - } + /* Define dev mode */ + + if (mode == IEEE802154_MODE_PANCOORD) + { + at86rf23x_setregbits(dev->spi, RF23X_CSMASEED1_IAMCOORD_BITS, 0x01); + } + else if (mode == IEEE802154_MODE_COORD) + { + /* ????? */ + } + else if (mode == IEEE802154_MODE_DEVICE) + { + at86rf23x_setregbits(dev->spi, RF23X_CSMASEED1_IAMCOORD_BITS, 0x00); + } else - { - return -EINVAL; - } + { + return -EINVAL; + } - dev->devmode = mode; - - return OK; + dev->devmode = mode; + return OK; } /**************************************************************************** @@ -889,14 +948,15 @@ static int at86rf23x_setdevmode(FAR struct ieee802154_radio_s *ieee, uint8_t mod * get the device mode type of the radio. * ****************************************************************************/ -static int at86rf23x_getdevmode (FAR struct ieee802154_radio_s *ieee, FAR uint8_t *mode) + +static int at86rf23x_getdevmode(FAR struct ieee802154_radio_s *ieee, + FAR uint8_t *mode) { FAR struct at86rf23x_dev_s *dev = (struct at86rf23x_dev_s *)ieee; int val; val = at86rf23x_getregbits(dev->spi, RF23X_CSMASEED1_IAMCOORD_BITS); - - if(val == 1) + if (val == 1) { *mode = IEEE802154_MODE_PANCOORD; } @@ -915,15 +975,17 @@ static int at86rf23x_getdevmode (FAR struct ieee802154_radio_s *ieee, FAR uint8 * set the tx power attenuation or amplification * ****************************************************************************/ -static int at86rf23x_settxpower(FAR struct ieee802154_radio_s *ieee, int32_t txpwr) + +static int at86rf23x_settxpower(FAR struct ieee802154_radio_s *ieee, + int32_t txpwr) { FAR struct at86rf23x_dev_s *dev = (struct at86rf23x_dev_s *)ieee; /* TODO: this needs alot of work to make sure all chips can share this function */ /* Right now we only set tx power to 0 */ - at86rf23x_setreg(dev->spi, RF23X_REG_TXPWR, RF23X_TXPWR_0); + at86rf23x_setreg(dev->spi, RF23X_REG_TXPWR, RF23X_TXPWR_0); return OK; } @@ -934,67 +996,86 @@ static int at86rf23x_settxpower(FAR struct ieee802154_radio_s *ieee, int32_t txp * get the tx power attenuation or amplification. * ****************************************************************************/ -static int at86rf23x_gettxpower(FAR struct ieee802154_radio_s *ieee, FAR int32_t *txpwr) + +static int at86rf23x_gettxpower(FAR struct ieee802154_radio_s *ieee, + FAR int32_t *txpwr) { - /* TODO: this needs alot of work to make sure all chips can share this function */ FAR struct at86rf23x_dev_s *dev = (struct at86rf23x_dev_s *)ieee; uint8_t reg; - /* TODO: this needs alot of work to make sure all chips can share this function */ + + /* TODO: this needs alot of work to make sure all chips can share this + * function. + */ /* Right now we only get negative values */ - reg = at86rf23x_getreg(dev->spi, RF23X_REG_TXPWR); - switch(reg) - { - case RF23X_TXPWR_POS_4: - *txpwr = 0; - break; - case RF23X_TXPWR_POS_3_7: - *txpwr = 0; - break; - case RF23X_TXPWR_POS_3_4: - *txpwr = 0; - break; - case RF23X_TXPWR_POS_3: - *txpwr = 0; - break; - case RF23X_TXPWR_POS_2_5: - *txpwr = 0; - break; - case RF23X_TXPWR_POS_2: - *txpwr = 0; - break; - case RF23X_TXPWR_POS_1: - *txpwr = 0; - break; - case RF23X_TXPWR_0: - *txpwr = 0; - break; - case RF23X_TXPWR_NEG_1: - *txpwr = 1000; - break; - case RF23X_TXPWR_NEG_2: - *txpwr = 2000; - break; - case RF23X_TXPWR_NEG_3: - *txpwr = 3000; - break; - case RF23X_TXPWR_NEG_4: - *txpwr = 4000; - break; - case RF23X_TXPWR_NEG_6: - *txpwr = 6000; - break; - case RF23X_TXPWR_NEG_8: - *txpwr = 8000; - break; - case RF23X_TXPWR_NEG_12: - *txpwr = 12000; - break; - case RF23X_TXPWR_NEG_17: - *txpwr = 17000; - break; - } + reg = at86rf23x_getreg(dev->spi, RF23X_REG_TXPWR); + switch (reg) + { + case RF23X_TXPWR_POS_4: + *txpwr = 0; + break; + + case RF23X_TXPWR_POS_3_7: + *txpwr = 0; + break; + + case RF23X_TXPWR_POS_3_4: + *txpwr = 0; + break; + + case RF23X_TXPWR_POS_3: + *txpwr = 0; + break; + + case RF23X_TXPWR_POS_2_5: + *txpwr = 0; + break; + + case RF23X_TXPWR_POS_2: + *txpwr = 0; + break; + + case RF23X_TXPWR_POS_1: + *txpwr = 0; + break; + + case RF23X_TXPWR_0: + *txpwr = 0; + break; + + case RF23X_TXPWR_NEG_1: + *txpwr = 1000; + break; + + case RF23X_TXPWR_NEG_2: + *txpwr = 2000; + break; + + case RF23X_TXPWR_NEG_3: + *txpwr = 3000; + break; + + case RF23X_TXPWR_NEG_4: + *txpwr = 4000; + break; + + case RF23X_TXPWR_NEG_6: + *txpwr = 6000; + break; + + case RF23X_TXPWR_NEG_8: + *txpwr = 8000; + break; + + case RF23X_TXPWR_NEG_12: + *txpwr = 12000; + break; + + case RF23X_TXPWR_NEG_17: + *txpwr = 17000; + break; + } return OK; } @@ -1008,7 +1089,9 @@ static int at86rf23x_gettxpower(FAR struct ieee802154_radio_s *ieee, FAR int32_t * * ****************************************************************************/ -static int at86rf23x_setcca(FAR struct ieee802154_radio_s *ieee, FAR struct ieee802154_cca_s *cca) + +static int at86rf23x_setcca(FAR struct ieee802154_radio_s *ieee, + FAR struct ieee802154_cca_s *cca) { FAR struct at86rf23x_dev_s *dev = (struct at86rf23x_dev_s *)ieee; @@ -1018,6 +1101,7 @@ static int at86rf23x_setcca(FAR struct ieee802154_radio_s *ieee, FAR struct ieee { return -EINVAL; } + if (cca->use_cs && cca->csth > 0x0f) { return -EINVAL; @@ -1025,15 +1109,15 @@ static int at86rf23x_setcca(FAR struct ieee802154_radio_s *ieee, FAR struct ieee if (cca->use_ed) { - at86rf23x_setregbits(dev->spi, RF23X_CCA_BITS_MODE, RF23X_CCA_MODE_ED); + at86rf23x_setregbits(dev->spi, RF23X_CCA_BITS_MODE, RF23X_CCA_MODE_ED); } + if (cca->use_cs) { - at86rf23x_setregbits(dev->spi, RF23X_CCA_BITS_MODE, RF23X_CCA_MODE_CS); + at86rf23x_setregbits(dev->spi, RF23X_CCA_BITS_MODE, RF23X_CCA_MODE_CS); } memcpy(&dev->cca, cca, sizeof(struct ieee802154_cca_s)); - return OK; } @@ -1044,7 +1128,9 @@ static int at86rf23x_setcca(FAR struct ieee802154_radio_s *ieee, FAR struct ieee * Get CCA for ???: TODO: need to implement * ****************************************************************************/ -static int at86rf23x_getcca(FAR struct ieee802154_radio_s *ieee, FAR struct ieee802154_cca_s *cca) + +static int at86rf23x_getcca(FAR struct ieee802154_radio_s *ieee, + FAR struct ieee802154_cca_s *cca) { FAR struct at86rf23x_dev_s *dev = (struct at86rf23x_dev_s *)ieee; @@ -1063,15 +1149,22 @@ static int at86rf23x_getcca(FAR struct ieee802154_radio_s *ieee, FAR struct ieee * Control operations for the radio. * ****************************************************************************/ -static int at86rf23x_ioctl(FAR struct ieee802154_radio_s *ieee, int cmd, unsigned long arg) + +static int at86rf23x_ioctl(FAR struct ieee802154_radio_s *ieee, int cmd, + unsigned long arg) { FAR struct at86rf23x_dev_s *dev = (FAR struct at86rf23x_dev_s *)ieee; - switch(cmd) + + switch (cmd) { - case 1000: return at86rf23x_regdump(dev); - default: return -EINVAL; + case 1000: + return at86rf23x_regdump(dev); + + default: + return -ENOTTY; } } + /**************************************************************************** * Name: at86rf23x_energydetect * @@ -1079,9 +1172,9 @@ static int at86rf23x_ioctl(FAR struct ieee802154_radio_s *ieee, int cmd, unsigne * Perform energy detection scan. TODO: Need to implement. * ****************************************************************************/ -static int at86rf23x_energydetect(FAR struct ieee802154_radio_s *ieee, FAR uint8_t *energy) +static int at86rf23x_energydetect(FAR struct ieee802154_radio_s *ieee, + FAR uint8_t *energy) { - #warning at86rf23x_energydetect not implemented. /* Not yet implemented */ @@ -1096,19 +1189,19 @@ static int at86rf23x_energydetect(FAR struct ieee802154_radio_s *ieee, FAR uint8 * Initialize the radio. * ****************************************************************************/ + int at86rf23x_initialize(FAR struct at86rf23x_dev_s *dev) { - uint8_t part; - uint8_t version; + uint8_t part; + uint8_t version; - at86rf23x_resetrf(dev); + at86rf23x_resetrf(dev); - part = at86rf23x_getreg(dev->spi, RF23X_REG_PART); - version = at86rf23x_getreg(dev->spi, RF23X_REG_VERSION); + part = at86rf23x_getreg(dev->spi, RF23X_REG_PART); + version = at86rf23x_getreg(dev->spi, RF23X_REG_VERSION); - dbg("Radio part: 0x%02x version: 0x%02x found\n", part, version); - - return OK; + dbg("Radio part: 0x%02x version: 0x%02x found\n", part, version); + return OK; } /**************************************************************************** @@ -1119,34 +1212,37 @@ int at86rf23x_initialize(FAR struct at86rf23x_dev_s *dev) * TRX_OFF state. * ****************************************************************************/ + static int at86rf23x_resetrf(FAR struct at86rf23x_dev_s *dev) { FAR const struct at86rf23x_lower_s *lower = dev->lower; uint8_t trx_status, retry_cnt = 0; /* Reset the radio */ + lower->reset(lower, 0); lower->slptr(lower, 0); up_udelay(RF23X_TIME_RESET); lower->reset(lower, 1); - /* Dummy read of IRQ register */ + at86rf23x_getreg(dev->spi, RF23X_REG_IRQ_STATUS); do - { - trx_status = at86rf23x_setTRXstate(dev, TRX_CMD_TRXOFF, true); - - if (retry_cnt == RF23X_MAX_RETRY_RESET_TO_TRX_OFF) { - dbg("Reset of transceiver failed\n"); - return ERROR; - } + trx_status = at86rf23x_setTRXstate(dev, TRX_CMD_TRXOFF, true); - retry_cnt++; - } while (trx_status != OK); + if (retry_cnt == RF23X_MAX_RETRY_RESET_TO_TRX_OFF) + { + dbg("Reset of transceiver failed\n"); + return ERROR; + } + + retry_cnt++; + } + while (trx_status != OK); return OK; } @@ -1159,12 +1255,14 @@ static int at86rf23x_resetrf(FAR struct at86rf23x_dev_s *dev) * RX messages. * ****************************************************************************/ + static int at86rf23x_rxenable(FAR struct ieee802154_radio_s *ieee, bool state, - FAR struct ieee802154_packet_s *packet) + FAR struct ieee802154_packet_s *packet) { FAR struct at86rf23x_dev_s *dev = (FAR struct at86rf23x_dev_s *)ieee; /* Set the radio to the receive state */ + return at86rf23x_setTRXstate(dev, TRX_CMD_RX_ON, false); /* Enable the RX IRQ */ @@ -1176,6 +1274,7 @@ static int at86rf23x_rxenable(FAR struct ieee802154_radio_s *ieee, bool state, */ /* Set buffer to receive next packet */ + ieee->rxbuf = packet; } @@ -1186,11 +1285,12 @@ static int at86rf23x_rxenable(FAR struct ieee802154_radio_s *ieee, bool state, * Actual interrupt handler ran inside privileged space. * ****************************************************************************/ + static int at86rf23x_interrupt(int irq, FAR void *context) { - - /* To support multiple devices, - * retrieve the priv structure using the irq number */ + /* To support multiple devices, retrieve the priv structure using the irq + * number. + */ register FAR struct at86rf23x_dev_s *dev = &g_at86rf23x_devices[0]; @@ -1207,10 +1307,12 @@ static int at86rf23x_interrupt(int irq, FAR void *context) * actually performed. This is to prevent overrun of the worker thread. * Interrupts are re-enabled in enc_irqworker() when the work is completed. */ - dev->lower->irq(dev->lower, NULL, FALSE); - // dev->lower->enable(dev->lower, FALSE); - return work_queue(HPWORK, &dev->irqwork, at86rf23x_irqworker, (FAR void *)dev, 0); + dev->lower->irq(dev->lower, NULL, FALSE); + //dev->lower->enable(dev->lower, FALSE); + + return work_queue(HPWORK, &dev->irqwork, at86rf23x_irqworker, + (FAR void *)dev, 0); } /**************************************************************************** @@ -1222,31 +1324,35 @@ static int at86rf23x_interrupt(int irq, FAR void *context) * them out. * ****************************************************************************/ + static int at86rf23x_regdump(FAR struct at86rf23x_dev_s *dev) { uint32_t i; char buf[4+16*3+2+1]; - int len=0; + printf("RF23X regs:\n"); for (i=0;i<0x30;i++) { - /* First row and every 15 regs */ - if ((i & 0x0f) == 0) - { - len = sprintf(buf, "%02x: ",i&0xFF); - } + /* First row and every 15 regs */ + + if ((i & 0x0f) == 0) + { + len = sprintf(buf, "%02x: ",i&0xFF); + } + + /* Print the register value */ - /* print the register value */ len += sprintf(buf+len, "%02x ", at86rf23x_getreg(dev->spi, i)); - /* at the end of each 15 regs or end of rf233s regs and actually print dbg message*/ + /* At the end of each 15 regs or end of rf233s regs and actually print dbg message*/ + if ((i&15)==15 || i == 0x2f) - { - sprintf(buf+len, "\n"); - printf("%s",buf); - } + { + sprintf(buf+len, "\n"); + printf("%s",buf); + } } /* TODO: I have a few more regs that are not consecutive. Will print later */ @@ -1261,30 +1367,33 @@ static int at86rf23x_regdump(FAR struct at86rf23x_dev_s *dev) * Actual thread to handle the irq outside of privaleged mode. * ****************************************************************************/ + static void at86rf23x_irqworker(FAR void *arg) { FAR struct at86rf23x_dev_s *dev = (FAR struct at86rf23x_dev_s *)arg; - uint8_t irq_status = at86rf23x_getreg(dev->spi, RF23X_REG_IRQ_STATUS); vdbg("IRQ: 0x%02X\n", irq_status); - if((irq_status & (1<<3)) != 0) + if ((irq_status & (1<<3)) != 0) { - if((irq_status & (1<<2)) != 0) - { - at86rf23x_irqwork_rx(dev); - } + if ((irq_status & (1<<2)) != 0) + { + at86rf23x_irqwork_rx(dev); + } else - { - at86rf23x_irqwork_tx(dev); - } + { + at86rf23x_irqwork_tx(dev); + } } else { dbg("Unknown IRQ Status: %d\n", irq_status); - /* Re enable the IRQ even if we don't know how to handle previous status*/ + /* Re enable the IRQ even if we don't know how to handle previous + * status. + */ + dev->lower->irq(dev->lower, NULL, true); } } @@ -1296,6 +1405,7 @@ static void at86rf23x_irqworker(FAR void *arg) * Misc/unofficial device controls. * ****************************************************************************/ + static void at86rf23x_irqwork_rx(FAR struct at86rf23x_dev_s *dev) { uint8_t rx_len; @@ -1309,13 +1419,14 @@ static void at86rf23x_irqwork_rx(FAR struct at86rf23x_dev_s *dev) dev->ieee.rxbuf->rssi = 0; sem_post(&dev->ieee.rxsem); - /* - * TODO: - * Not to sure yet what I should do here. I will something - * soon. + + /* TODO: + * Not to sure yet what I should do here. I will something + * soon. */ /* Re enable the IRQ */ + dev->lower->irq(dev->lower, NULL, true); } @@ -1326,23 +1437,21 @@ static void at86rf23x_irqwork_rx(FAR struct at86rf23x_dev_s *dev) * Misc/unofficial device controls. * ****************************************************************************/ + static void at86rf23x_irqwork_tx(FAR struct at86rf23x_dev_s *dev) { vdbg("6LOWPAN:Tx IRQ\n"); - /* - * TODO: - * There needs to be more here but for now just alert the waiting - * thread. Maybe put it back into Rx mode - * + /* TODO: + * There needs to be more here but for now just alert the waiting + * thread. Maybe put it back into Rx mode */ /* Re enable the IRQ */ + dev->lower->irq(dev->lower, NULL, true); sem_post(&dev->ieee.txsem); - - } /**************************************************************************** @@ -1354,30 +1463,37 @@ static void at86rf23x_irqwork_tx(FAR struct at86rf23x_dev_s *dev) * transmission * ****************************************************************************/ -static int at86rf23x_transmit(FAR struct ieee802154_radio_s *ieee, FAR struct ieee802154_packet_s *packet) + +static int at86rf23x_transmit(FAR struct ieee802154_radio_s *ieee, + FAR struct ieee802154_packet_s *packet) { FAR struct at86rf23x_dev_s *dev = (FAR struct at86rf23x_dev_s *)ieee; - /* - * TODO: - * A plan needs to be made on when we declare the transmission successful. - * 1. If the packet is sent - * 2. If we receive an ACK. - * 3. Where do we control the retry process? + + /* TODO: + * A plan needs to be made on when we declare the transmission successful. + * 1. If the packet is sent + * 2. If we receive an ACK. + * 3. Where do we control the retry process? */ - if(at86rf23x_setTRXstate(dev, TRX_CMD_PLL_ON, false)) - { + if (at86rf23x_setTRXstate(dev, TRX_CMD_PLL_ON, false)) + { at86rf23x_writeframe(dev->spi, packet->data, packet->len); - } + } else - { + { dbg("Transmit could not put the radio in a Tx state\n"); return ERROR; - } + } + + /* Put the thread that requested transfer to a waiting state */ - /* put the thread that requested transfer to a waiting state */ sem_wait(&dev->ieee.txsem); - /*TODO Verify that I want to stay in the PLL state or if I want to roll back to RX_ON */ + + /* TODO Verify that I want to stay in the PLL state or if I want to roll + * back to RX_ON. + */ + return OK; } @@ -1393,18 +1509,22 @@ static int at86rf23x_transmit(FAR struct ieee802154_radio_s *ieee, FAR struct ie * ****************************************************************************/ -FAR struct ieee802154_radio_s *at86rf23x_init(FAR struct spi_dev_s *spi, FAR const struct at86rf23x_lower_s *lower) +FAR struct ieee802154_radio_s *at86rf23x_init(FAR struct spi_dev_s *spi, + FAR const struct at86rf23x_lower_s *lower) { FAR struct at86rf23x_dev_s *dev; struct ieee802154_cca_s cca; dev = &g_at86rf23x_devices[0]; + /* Attach the interface, lower driver, and devops */ + dev->spi = spi; dev->lower = lower; dev->ieee.ops = &at86rf23x_devops; - /* attach irq */ + /* Attach irq */ + if (lower->irq(lower, at86rf23x_interrupt, false) != OK) { return NULL; @@ -1413,65 +1533,68 @@ FAR struct ieee802154_radio_s *at86rf23x_init(FAR struct spi_dev_s *spi, FAR con sem_init(&dev->ieee.rxsem, 0, 0); sem_init(&dev->ieee.txsem, 0, 0); - /*Initialize device */ + /* Initialize device */ + at86rf23x_initialize(dev); /* Configure the desired IRQs of the devices */ + at86rf23x_setreg(dev->spi, RF23X_REG_IRQ_MASK, RF23X_IRQ_MASK_DEFAULT); /* Turn the PLL to the on state */ + at86rf23x_setTRXstate(dev, TRX_CMD_PLL_ON, false); - - /*SEED value of the CSMA backoff algorithm. */ - + /* SEED value of the CSMA backoff algorithm. */ #ifdef RF23X_ANTENNA_DIVERSITY + /* Use antenna diversity */ - /* Use antenna diversity */ - trx_bit_write(SR_ANT_CTRL, ANTENNA_DEFAULT); - trx_bit_write(SR_PDT_THRES, THRES_ANT_DIV_ENABLE); - trx_bit_write(SR_ANT_DIV_EN, ANT_DIV_ENABLE); - trx_bit_write(SR_ANT_EXT_SW_EN, ANT_EXT_SW_ENABLE); - + trx_bit_write(SR_ANT_CTRL, ANTENNA_DEFAULT); + trx_bit_write(SR_PDT_THRES, THRES_ANT_DIV_ENABLE); + trx_bit_write(SR_ANT_DIV_EN, ANT_DIV_ENABLE); + trx_bit_write(SR_ANT_EXT_SW_EN, ANT_EXT_SW_ENABLE); #endif #ifdef RF23X_TIMESTAMP - - /* Enable timestamp init code goes here */ + /* Enable timestamp init code goes here */ #endif #ifdef RF23X_RF_FRONTEND_CTRL - - /* Init front end control code goes here */ + /* Init front end control code goes here */ #endif + /* Set the channel of the radio */ + at86rf23x_setchannel(&dev->ieee, 12); /* Configure the Pan id */ - // at86rf23x_setpanid (&dev->ieee, IEEE802154_PAN_DEFAULT); + + //at86rf23x_setpanid (&dev->ieee, IEEE802154_PAN_DEFAULT); + /* Configure the Short Addr */ - // at86rf23x_setsaddr (&dev->ieee, IEEE802154_SADDR_UNSPEC); + + //at86rf23x_setsaddr (&dev->ieee, IEEE802154_SADDR_UNSPEC); + /* Configure the IEEE Addr */ -// at86rf23x_seteaddr (&dev->ieee, IEEE802154_EADDR_UNSPEC); + + //at86rf23x_seteaddr (&dev->ieee, IEEE802154_EADDR_UNSPEC); /* Default device params at86rf23x defaults to energy detect only */ + cca.use_ed = 1; cca.use_cs = 0; - cca.edth = 0x60; /* CCA mode ED, no carrier sense, recommenced ED threshold -69 dBm */ + cca.edth = 0x60; /* CCA mode ED, no carrier sense, recommenced ED + * threshold -69 dBm */ at86rf23x_setcca(&dev->ieee, &cca); - - /* Put the Device to RX ON Mode */ - // at86rf23x_setTRXstate(dev, TRX_CMD_RX_ON, false ); - + //at86rf23x_setTRXstate(dev, TRX_CMD_RX_ON, false); /* Enable Radio IRQ */ - lower->irq(lower, at86rf23x_interrupt, true); + lower->irq(lower, at86rf23x_interrupt, true); return &dev->ieee; } - diff --git a/wireless/ieee802154/ieee802154_device.c b/wireless/ieee802154/ieee802154_device.c index f1413b31cf0..792b37ed8d3 100644 --- a/wireless/ieee802154/ieee802154_device.c +++ b/wireless/ieee802154/ieee802154_device.c @@ -353,7 +353,7 @@ static ssize_t ieee802154dev_write(FAR struct file *filep, if (sem_timedwait(&dev->child->txsem, &timeout)) { - dbg("Radio Device timedout on Tx\n"); + _err("Radio Device timedout on Tx\n"); } done: From 5a6c95fddf4ff283dc656c20b96a30d737b7ffd2 Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Wed, 15 Mar 2017 16:18:38 -0400 Subject: [PATCH 006/183] wireless/ieee802154: Renamed file ieee802154_device to radio802154_device --- wireless/ieee802154/{ieee802154_device.c => radio802154_device.c} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename wireless/ieee802154/{ieee802154_device.c => radio802154_device.c} (100%) diff --git a/wireless/ieee802154/ieee802154_device.c b/wireless/ieee802154/radio802154_device.c similarity index 100% rename from wireless/ieee802154/ieee802154_device.c rename to wireless/ieee802154/radio802154_device.c From a4313bd07b7e7c577ece7ae8f72ba799d4323cb6 Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Wed, 15 Mar 2017 16:32:23 -0400 Subject: [PATCH 007/183] wireless/ieee802.15.4: Refactors ieee802154_dev character driver to be radio802154_device --- wireless/ieee802154/radio802154_device.c | 108 ++++++++++++----------- 1 file changed, 57 insertions(+), 51 deletions(-) diff --git a/wireless/ieee802154/radio802154_device.c b/wireless/ieee802154/radio802154_device.c index 792b37ed8d3..a170cec7b60 100644 --- a/wireless/ieee802154/radio802154_device.c +++ b/wireless/ieee802154/radio802154_device.c @@ -1,9 +1,10 @@ /**************************************************************************** - * drivers/ieee802154/ieee802154_device.c + * drivers/ieee802154/radio802154_device.c * * Copyright (C) 2014-2015 Gregory Nutt. All rights reserved. * Copyright (C) 2014-2015 Sebastien Lorquet. All rights reserved. * Author: Sebastien Lorquet + * Author: Anthony Merlino * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -56,7 +57,7 @@ * Private Types ****************************************************************************/ -struct ieee802154_devwrapper_s +struct radio802154_devwrapper_s { FAR struct ieee802154_radio_s *child; sem_t devsem; /* Device access serialization semaphore */ @@ -67,28 +68,28 @@ struct ieee802154_devwrapper_s * Private Function Prototypes ****************************************************************************/ -static void ieee802154dev_semtake(FAR struct ieee802154_devwrapper_s *dev); -static int ieee802154dev_open(FAR struct file *filep); -static int ieee802154dev_close(FAR struct file *filep); -static ssize_t ieee802154dev_read(FAR struct file *filep, FAR char *buffer, +static void radio802154dev_semtake(FAR struct radio802154_devwrapper_s *dev); +static int radio802154dev_open(FAR struct file *filep); +static int radio802154dev_close(FAR struct file *filep); +static ssize_t radio802154dev_read(FAR struct file *filep, FAR char *buffer, size_t len); -static ssize_t ieee802154dev_write(FAR struct file *filep, +static ssize_t radio802154dev_write(FAR struct file *filep, FAR const char *buffer, size_t len); -static int ieee802154dev_ioctl(FAR struct file *filep, int cmd, +static int radio802154dev_ioctl(FAR struct file *filep, int cmd, unsigned long arg); /**************************************************************************** * Private Data ****************************************************************************/ -static const struct file_operations ieee802154dev_fops = +static const struct file_operations radio802154dev_fops = { - ieee802154dev_open , /* open */ - ieee802154dev_close, /* close */ - ieee802154dev_read , /* read */ - ieee802154dev_write, /* write */ + radio802154dev_open , /* open */ + radio802154dev_close, /* close */ + radio802154dev_read , /* read */ + radio802154dev_write, /* write */ NULL, /* seek */ - ieee802154dev_ioctl /* ioctl */ + radio802154dev_ioctl /* ioctl */ #ifndef CONFIG_DISABLE_POLL , NULL /* poll */ #endif @@ -102,14 +103,14 @@ static const struct file_operations ieee802154dev_fops = ****************************************************************************/ /**************************************************************************** - * Name: ieee802154dev_semtake + * Name: radio802154dev_semtake * * Description: * Acquire the semaphore used for access serialization. * ****************************************************************************/ -static void ieee802154dev_semtake(FAR struct ieee802154_devwrapper_s *dev) +static void radio802154dev_semtake(FAR struct radio802154_devwrapper_s *dev) { /* Take the semaphore (perhaps waiting) */ @@ -124,30 +125,30 @@ static void ieee802154dev_semtake(FAR struct ieee802154_devwrapper_s *dev) } /**************************************************************************** - * Name: ieee802154dev_semgive + * Name: radio802154dev_semgive * * Description: * Release the semaphore used for access serialization. * ****************************************************************************/ -static inline void ieee802154dev_semgive(FAR struct ieee802154_devwrapper_s *dev) +static inline void radio802154dev_semgive(FAR struct radio802154_devwrapper_s *dev) { sem_post(&dev->devsem); } /**************************************************************************** - * Name: ieee802154dev_open + * Name: radio802154dev_open * * Description: - * Open the MRF24J40 device. + * Open the 802.15.4 radio character device. * ****************************************************************************/ -static int ieee802154dev_open(FAR struct file *filep) +static int radio802154dev_open(FAR struct file *filep) { FAR struct inode *inode; - FAR struct ieee802154_devwrapper_s *dev; + FAR struct radio802154_devwrapper_s *dev; DEBUGASSERT(filep != NULL && filep->f_inode != NULL); inode = filep->f_inode; @@ -156,7 +157,7 @@ static int ieee802154dev_open(FAR struct file *filep) /* Get exclusive access to the driver data structures */ - ieee802154dev_semtake(dev); + radio802154dev_semtake(dev); if (dev->opened) { @@ -174,22 +175,22 @@ static int ieee802154dev_open(FAR struct file *filep) dev->opened = true; } - ieee802154dev_semgive(dev); + radio802154dev_semgive(dev); return OK; } /**************************************************************************** - * Name: ieee802154dev_close + * Name: radio802154dev_close * * Description: - * Close the MRF24J40 device. + * Close the 802.15.4 radio character device. * ****************************************************************************/ -static int ieee802154dev_close(FAR struct file *filep) +static int radio802154dev_close(FAR struct file *filep) { FAR struct inode *inode; - FAR struct ieee802154_devwrapper_s *dev; + FAR struct radio802154_devwrapper_s *dev; int ret = OK; DEBUGASSERT(filep != NULL && filep->f_inode != NULL); @@ -199,7 +200,7 @@ static int ieee802154dev_close(FAR struct file *filep) /* Get exclusive access to the driver data structures */ - ieee802154dev_semtake(dev); + radio802154dev_semtake(dev); if (!dev->opened) { @@ -217,12 +218,12 @@ static int ieee802154dev_close(FAR struct file *filep) dev->opened = false; } - ieee802154dev_semgive(dev); + radio802154dev_semgive(dev); return ret; } /**************************************************************************** - * Name: ieee802154dev_read + * Name: radio802154dev_read * * Description: * Return the last received packet. @@ -231,10 +232,10 @@ static int ieee802154dev_close(FAR struct file *filep) * ****************************************************************************/ -static ssize_t ieee802154dev_read(FAR struct file *filep, FAR char *buffer, size_t len) +static ssize_t radio802154dev_read(FAR struct file *filep, FAR char *buffer, size_t len) { FAR struct inode *inode; - FAR struct ieee802154_devwrapper_s *dev; + FAR struct radio802154_devwrapper_s *dev; FAR struct ieee802154_packet_s *buf; int ret = OK; @@ -285,21 +286,21 @@ done: } /**************************************************************************** - * Name: ieee802154dev_write + * Name: radio802154dev_write * * Description: * Send a packet immediately. * TODO: Put a packet in the send queue. The packet will be sent as soon - * as possible. The buffer must point to a struct ieee802154_packet_s + * as possible. The buffer must point to a struct radio802154_packet_s * with the correct length. * ****************************************************************************/ -static ssize_t ieee802154dev_write(FAR struct file *filep, +static ssize_t radio802154dev_write(FAR struct file *filep, FAR const char *buffer, size_t len) { FAR struct inode *inode; - FAR struct ieee802154_devwrapper_s *dev; + FAR struct radio802154_devwrapper_s *dev; FAR struct ieee802154_packet_s *packet; FAR struct timespec timeout; int ret = OK; @@ -364,18 +365,18 @@ done: } /**************************************************************************** - * Name: ieee802154dev_ioctl + * Name: radio802154dev_ioctl * * Description: * Control the MRF24J40 device. This is where the real operations happen. * ****************************************************************************/ -static int ieee802154dev_ioctl(FAR struct file *filep, int cmd, +static int radio802154dev_ioctl(FAR struct file *filep, int cmd, unsigned long arg) { FAR struct inode *inode; - FAR struct ieee802154_devwrapper_s *dev; + FAR struct radio802154_devwrapper_s *dev; FAR struct ieee802154_radio_s *child; int ret = OK; @@ -466,30 +467,35 @@ static int ieee802154dev_ioctl(FAR struct file *filep, int cmd, } /**************************************************************************** - * Name: ieee802154dev_register + * Name: radio802154dev_register * * Description: - * Register /dev/ieee%d + * Register a character driver to access the IEEE 802.15.4 radio from + * user-space + * + * Input Parameters: + * radio - Pointer to the radio struct to be registerd. + * devname - The name of the IEEE 802.15.4 radio to be registered. + * + * Returned Values: + * Zero (OK) is returned on success. Otherwise a negated errno value is + * returned to indicate the nature of the failure. * ****************************************************************************/ -int ieee802154_register(FAR struct ieee802154_radio_s *ieee, - unsigned int minor) +int radio802154dev_register(FAR struct ieee802154_radio_s *radio, FAR char *devname) { - FAR struct ieee802154_devwrapper_s *dev; - char devname[16]; + FAR struct radio802154_devwrapper_s *dev; - dev = kmm_zalloc(sizeof(struct ieee802154_devwrapper_s)); + dev = kmm_zalloc(sizeof(struct radio802154_devwrapper_s)); if (dev == NULL) { return -ENOMEM; } - dev->child = ieee; + dev->child = radio; sem_init(&dev->devsem, 0, 1); /* Allow the device to be opened once before blocking */ - sprintf(devname, "/dev/ieee%d", minor); - - return register_driver(devname, &ieee802154dev_fops, 0666, dev); + return register_driver(devname, &radio802154dev_fops, 0666, dev); } From f985b525871d2d0f71a562fab2aeaf016163fa5e Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 15 Mar 2017 14:37:17 -0600 Subject: [PATCH 008/183] Integrate use of new wireless debug macros. Replace ad hoc debug macros. Convert obsolete dbg() macros to current info(), warn(), err() macros. --- drivers/wireless/ieee802154/at86rf23x.c | 38 +++++++++++++------------ drivers/wireless/ieee802154/mrf24j40.c | 36 +++++++++++------------ wireless/ieee802154/ieee802154_device.c | 2 +- 3 files changed, 39 insertions(+), 37 deletions(-) diff --git a/drivers/wireless/ieee802154/at86rf23x.c b/drivers/wireless/ieee802154/at86rf23x.c index 653a92b3131..e0920c3f47d 100644 --- a/drivers/wireless/ieee802154/at86rf23x.c +++ b/drivers/wireless/ieee802154/at86rf23x.c @@ -283,7 +283,7 @@ static void at86rf23x_setreg(FAR struct spi_dev_s *spi, uint32_t addr, SPI_SELECT(spi, SPIDEV_IEEE802154, false); at86rf23x_unlock(spi); - vdbg("0x%02X->r[0x%02X]\n", val, addr); + wlinfo("0x%02X->r[0x%02X]\n", val, addr); } /**************************************************************************** @@ -311,7 +311,7 @@ static uint8_t at86rf23x_getreg(FAR struct spi_dev_s *spi, uint32_t addr) at86rf23x_unlock(spi); - vdbg("r[0x%02X]=0x%02X\n",addr,val[1]); + wlinfo("r[0x%02X]=0x%02X\n",addr,val[1]); return val[1]; } @@ -456,7 +456,7 @@ static int at86rf23x_setTRXstate(FAR struct at86rf23x_dev_s *dev, (status != TRX_STATUS_TXARETON) && (status != TRX_STATUS_PON)) { - dbg("Invalid State\n"); + wlerr("ERROR: Invalid State\n"); return ERROR; } @@ -632,17 +632,17 @@ static int at86rf23x_setTRXstate(FAR struct at86rf23x_dev_s *dev, break; default: - dbg("%s \n", EINVAL_STR); + wlerr("ERRPR: %s \n", EINVAL_STR); init_status = 0;/* Placed this here to keep compiler happy when not in debug */ return -EINVAL; } if (ret == ERROR) { - dbg("State Transistion Error\n"); + wlerr("ERROR: State Transistion Error\n"); } - vdbg("Radio state change state[0x%02x]->state[0x%02x]\n", init_status, status); + wlinfo("Radio state change state[0x%02x]->state[0x%02x]\n", init_status, status); return ret; } @@ -671,7 +671,7 @@ static int at86rf23x_setchannel(FAR struct ieee802154_radio_s *ieee, if (chan < 11 || chan > 26) { - dbg("Invalid requested chan: %d\n",chan); + wlerr("ERROR: Invalid requested chan: %d\n",chan); return -EINVAL; } @@ -681,7 +681,7 @@ static int at86rf23x_setchannel(FAR struct ieee802154_radio_s *ieee, if ((TRX_STATUS_SLEEP == state) || (TRX_STATUS_PON == state)) { - dbg("Radio in invalid mode [%02x] to set the channel\n", state); + wlerr("ERROR: Radio in invalid mode [%02x] to set the channel\n", state); return ERROR; } @@ -693,7 +693,7 @@ static int at86rf23x_setchannel(FAR struct ieee802154_radio_s *ieee, dev->channel = chan; - vdbg("CHANNEL Changed to %d\n", chan); + wlinfo("CHANNEL Changed to %d\n", chan); return OK; } @@ -1200,7 +1200,7 @@ int at86rf23x_initialize(FAR struct at86rf23x_dev_s *dev) part = at86rf23x_getreg(dev->spi, RF23X_REG_PART); version = at86rf23x_getreg(dev->spi, RF23X_REG_VERSION); - dbg("Radio part: 0x%02x version: 0x%02x found\n", part, version); + wlinfo("Radio part: 0x%02x version: 0x%02x found\n", part, version); return OK; } @@ -1236,7 +1236,7 @@ static int at86rf23x_resetrf(FAR struct at86rf23x_dev_s *dev) if (retry_cnt == RF23X_MAX_RETRY_RESET_TO_TRX_OFF) { - dbg("Reset of transceiver failed\n"); + wlerr("ERROR: Reset of transceiver failed\n"); return ERROR; } @@ -1346,9 +1346,11 @@ static int at86rf23x_regdump(FAR struct at86rf23x_dev_s *dev) len += sprintf(buf+len, "%02x ", at86rf23x_getreg(dev->spi, i)); - /* At the end of each 15 regs or end of rf233s regs and actually print dbg message*/ + /* At the end of each 15 regs or end of rf233s regs and actually print + * debug message. + */ - if ((i&15)==15 || i == 0x2f) + if ((i&15) == 15 || i == 0x2f) { sprintf(buf+len, "\n"); printf("%s",buf); @@ -1373,7 +1375,7 @@ static void at86rf23x_irqworker(FAR void *arg) FAR struct at86rf23x_dev_s *dev = (FAR struct at86rf23x_dev_s *)arg; uint8_t irq_status = at86rf23x_getreg(dev->spi, RF23X_REG_IRQ_STATUS); - vdbg("IRQ: 0x%02X\n", irq_status); + wlinfo("IRQ: 0x%02X\n", irq_status); if ((irq_status & (1<<3)) != 0) { @@ -1388,7 +1390,7 @@ static void at86rf23x_irqworker(FAR void *arg) } else { - dbg("Unknown IRQ Status: %d\n", irq_status); + wlerr("ERROR: Unknown IRQ Status: %d\n", irq_status); /* Re enable the IRQ even if we don't know how to handle previous * status. @@ -1410,7 +1412,7 @@ static void at86rf23x_irqwork_rx(FAR struct at86rf23x_dev_s *dev) { uint8_t rx_len; - vdbg("6LOWPAN:Rx IRQ\n"); + wlinfo("6LOWPAN:Rx IRQ\n"); rx_len = at86rf23x_readframe(dev->spi, dev->ieee.rxbuf->data); @@ -1440,7 +1442,7 @@ static void at86rf23x_irqwork_rx(FAR struct at86rf23x_dev_s *dev) static void at86rf23x_irqwork_tx(FAR struct at86rf23x_dev_s *dev) { - vdbg("6LOWPAN:Tx IRQ\n"); + wlinfo("6LOWPAN:Tx IRQ\n"); /* TODO: * There needs to be more here but for now just alert the waiting @@ -1482,7 +1484,7 @@ static int at86rf23x_transmit(FAR struct ieee802154_radio_s *ieee, } else { - dbg("Transmit could not put the radio in a Tx state\n"); + wlerr("ERROR: Transmit could not put the radio in a Tx state\n"); return ERROR; } diff --git a/drivers/wireless/ieee802154/mrf24j40.c b/drivers/wireless/ieee802154/mrf24j40.c index 3c8e9ec8d7e..f9cd98cb2d9 100644 --- a/drivers/wireless/ieee802154/mrf24j40.c +++ b/drivers/wireless/ieee802154/mrf24j40.c @@ -342,7 +342,7 @@ static uint8_t mrf24j40_getreg(FAR struct spi_dev_s *spi, uint32_t addr) SPI_SELECT (spi, SPIDEV_IEEE802154, false); mrf24j40_unlock(spi); - /*winfo("r[%04X]=%02X\n", addr, rx[len-1]);*/ + /*wlinfo("r[%04X]=%02X\n", addr, rx[len-1]);*/ return rx[len-1]; } @@ -482,7 +482,7 @@ static int mrf24j40_setrxmode(FAR struct mrf24j40_radio_s *dev, int mode) mrf24j40_setreg(dev->spi, MRF24J40_RXMCR, reg); dev->rxmode = mode; - winfo("%u\n", (unsigned)mode); + wlinfo("%u\n", (unsigned)mode); return OK; } @@ -508,7 +508,7 @@ static int mrf24j40_setchannel(FAR struct ieee802154_radio_s *ieee, FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)ieee; if (chan<11 || chan>26) { - werr("ERROR: Invalid chan: %d\n",chan); + wlerr("ERROR: Invalid chan: %d\n",chan); return -EINVAL; } @@ -523,7 +523,7 @@ static int mrf24j40_setchannel(FAR struct ieee802154_radio_s *ieee, mrf24j40_resetrfsm(dev); dev->channel = chan; - //winfo("%u\n", (unsigned)chan); + //wlinfo("%u\n", (unsigned)chan); return OK; } @@ -563,7 +563,7 @@ static int mrf24j40_setpanid(FAR struct ieee802154_radio_s *ieee, mrf24j40_setreg(dev->spi, MRF24J40_PANIDL, (uint8_t)(panid&0xFF)); dev->panid = panid; - winfo("%04X\n", (unsigned)panid); + wlinfo("%04X\n", (unsigned)panid); return OK; } @@ -605,7 +605,7 @@ static int mrf24j40_setsaddr(FAR struct ieee802154_radio_s *ieee, mrf24j40_setreg(dev->spi, MRF24J40_SADRL, (uint8_t)(saddr&0xFF)); dev->saddr = saddr; - winfo("%04X\n", (unsigned)saddr); + wlinfo("%04X\n", (unsigned)saddr); return OK; } @@ -817,7 +817,7 @@ static int mrf24j40_settxpower(FAR struct ieee802154_radio_s *ieee, return -EINVAL; } - winfo("remaining attenuation: %d mBm\n",txpwr); + wlinfo("remaining attenuation: %d mBm\n",txpwr); switch(txpwr/100) { @@ -935,7 +935,7 @@ static int mrf24j40_regdump(FAR struct mrf24j40_radio_s *dev) char buf[4+16*3+2+1]; int len=0; - winfo("Short regs:\n"); + wlinfo("Short regs:\n"); for (i = 0; i < 0x40; i++) { @@ -948,11 +948,11 @@ static int mrf24j40_regdump(FAR struct mrf24j40_radio_s *dev) if ((i & 15) == 15) { sprintf(buf+len, "\n"); - winfo("%s", buf); + wlinfo("%s", buf); } } - winfo("Long regs:\n"); + wlinfo("Long regs:\n"); for (i=0x80000200;i<0x80000250;i++) { if ((i&15)==0) @@ -964,7 +964,7 @@ static int mrf24j40_regdump(FAR struct mrf24j40_radio_s *dev) if ((i & 15) == 15) { sprintf(buf+len, "\n"); - winfo("%s", buf); + wlinfo("%s", buf); } } @@ -990,7 +990,7 @@ static int mrf24j40_ioctl(FAR struct ieee802154_radio_s *ieee, int cmd, return mrf24j40_regdump(dev); case 1001: dev->paenabled = (uint8_t)arg; - winfo("PA %sabled\n", arg ? "en" : "dis"); + wlinfo("PA %sabled\n", arg ? "en" : "dis"); return OK; default: @@ -1081,7 +1081,7 @@ static int mrf24j40_transmit(FAR struct ieee802154_radio_s *ieee, FAR struct iee fc1 = packet->data[0]; fc2 = packet->data[1]; - // winfo("fc1 %02X fc2 %02X\n", fc1,fc2); + // wlinfo("fc1 %02X fc2 %02X\n", fc1,fc2); if ((fc2 & IEEE802154_FC2_DADDR) == IEEE802154_DADDR_SHORT) { @@ -1111,7 +1111,7 @@ static int mrf24j40_transmit(FAR struct ieee802154_radio_s *ieee, FAR struct iee hlen += 8; /* Ext saddr */ } -// winfo("hlen %d\n",hlen); +// wlinfo("hlen %d\n",hlen); /* Header len, 0, TODO for security modes */ @@ -1170,7 +1170,7 @@ static void mrf24j40_irqwork_tx(FAR struct mrf24j40_radio_s *dev) dev->ieee.txretries = (reg & MRF24J40_TXSTAT_X_MASK) >> MRF24J40_TXSTAT_X_SHIFT; dev->ieee.txbusy = (reg & MRF24J40_TXSTAT_CCAFAIL) == MRF24J40_TXSTAT_CCAFAIL; - //winfo("TXSTAT%02X!\n", txstat); + //wlinfo("TXSTAT%02X!\n", txstat); #warning TODO report errors UNUSED(txstat); @@ -1232,7 +1232,7 @@ static void mrf24j40_irqwork_rx(FAR struct mrf24j40_radio_s *dev) uint32_t index; uint8_t reg; - /*winfo("!\n");*/ + /*wlinfo("!\n");*/ /* Disable rx int */ @@ -1248,7 +1248,7 @@ static void mrf24j40_irqwork_rx(FAR struct mrf24j40_radio_s *dev) addr = MRF24J40_RXBUF_BASE; dev->ieee.rxbuf->len = mrf24j40_getreg(dev->spi, addr++); - /*winfo("len %3d\n", dev->ieee.rxbuf->len);*/ + /*wlinfo("len %3d\n", dev->ieee.rxbuf->len);*/ for (index = 0; index < dev->ieee.rxbuf->len; index++) { @@ -1303,7 +1303,7 @@ static void mrf24j40_irqworker(FAR void *arg) /* Read and store INTSTAT - this clears the register. */ intstat = mrf24j40_getreg(dev->spi, MRF24J40_INTSTAT); -// winfo("INT%02X\n", intstat); +// wlinfo("INT%02X\n", intstat); /* Do work according to the pending interrupts */ diff --git a/wireless/ieee802154/ieee802154_device.c b/wireless/ieee802154/ieee802154_device.c index 792b37ed8d3..aa77a7e1057 100644 --- a/wireless/ieee802154/ieee802154_device.c +++ b/wireless/ieee802154/ieee802154_device.c @@ -353,7 +353,7 @@ static ssize_t ieee802154dev_write(FAR struct file *filep, if (sem_timedwait(&dev->child->txsem, &timeout)) { - _err("Radio Device timedout on Tx\n"); + wlerr("Radio Device timedout on Tx\n"); } done: From 25e4e3c3146579fc550cf43584ac132bbedb0c5b Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 15 Mar 2017 14:57:13 -0600 Subject: [PATCH 009/183] Bring closer to NuttX coding standard. --- drivers/wireless/ieee802154/Kconfig | 8 +- drivers/wireless/ieee802154/at86rf23x.c | 1 + drivers/wireless/ieee802154/at86rf23x.h | 391 ++++++++++++------------ drivers/wireless/ieee802154/mrf24j40.c | 186 ++++++----- drivers/wireless/ieee802154/mrf24j40.h | 6 +- 5 files changed, 328 insertions(+), 264 deletions(-) diff --git a/drivers/wireless/ieee802154/Kconfig b/drivers/wireless/ieee802154/Kconfig index 6eba028b2a3..d0d8c550ece 100644 --- a/drivers/wireless/ieee802154/Kconfig +++ b/drivers/wireless/ieee802154/Kconfig @@ -12,9 +12,9 @@ config IEEE802154_MRF24J40 This selection enables support for the Microchip MRF24J40 device. config IEEE802154_AT86RF233 - bool "ATMEL RF233 IEEE 802.15.4 transceiver" - default n - ---help--- - This selection enables support for the Atmel RF233 device. + bool "ATMEL RF233 IEEE 802.15.4 transceiver" + default n + ---help--- + This selection enables support for the Atmel RF233 device. endif # DRIVERS_IEEE802154 diff --git a/drivers/wireless/ieee802154/at86rf23x.c b/drivers/wireless/ieee802154/at86rf23x.c index e0920c3f47d..3bcf2033736 100644 --- a/drivers/wireless/ieee802154/at86rf23x.c +++ b/drivers/wireless/ieee802154/at86rf23x.c @@ -32,6 +32,7 @@ * POSSIBILITY OF SUCH DAMAGE. * ****************************************************************************/ + /**************************************************************************** * Included Files ****************************************************************************/ diff --git a/drivers/wireless/ieee802154/at86rf23x.h b/drivers/wireless/ieee802154/at86rf23x.h index 51c96ced3c0..4d64fed0c8b 100644 --- a/drivers/wireless/ieee802154/at86rf23x.h +++ b/drivers/wireless/ieee802154/at86rf23x.h @@ -1,204 +1,221 @@ -/* - * at86rf23x.h +/**************************************************************************** + * drivers/wireless/ieee802154/at86rf23x.c + * + * Copyright (C) 2016 Matt Poppe. All rights reserved. + * Author: Matt Poppe + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. * - * Created on: Feb 24, 2016 - * Author: poppe - */ - -#ifndef APPS_EXTERNAL_IEEE_AT86RF23X_H_ -#define APPS_EXTERNAL_IEEE_AT86RF23X_H_ - -#define RF23X_SPI_REG_READ 0x80 -#define RF23X_SPI_REG_WRITE 0xC0 -#define RF23X_SPI_FRAME_WRITE 0x60 -#define RF23X_SPI_FRAME_READ 0x20 -#define RF23X_SPI_SRAM_READ 0x00 -#define RF23X_SPI_SRAM_WRITE 0x40 - -/* us Times Constants for the RF233 */ -#define RF23X_TIME_RESET_BOOT 510 -#define RF23X_TIME_FORCE_TRXOFF 100 -#define RF23X_TIME_P_ON_TO_TRXOFF 510 -#define RF23X_TIME_SLEEP_TO_TRXOFF 1200 -#define RF23X_TIME_RESET 6 -#define RF23X_TIME_ED_MEASUREMENT 140 -#define RF23X_TIME_CCA 140 -#define RF23X_TIME_PLL_LOCK 150 -#define RF23X_TIME_FTN_TUNNING 25 -#define RF23X_TIME_NOCLK_TO_WAKE 6 -#define RF23X_TIME_CMD_FORCE_TRX_OFF 1 -#define RF23X_TIME_TRXOFF_TO_PLL 180 -#define RF23X_TIME_TRANSITION_PLL_ACTIVE 1 -#define RF23X_TIME_TRXOFF_TO_SLEEP 1200 - -#define RF23X_MAX_RETRY_RESET_TO_TRX_OFF 5 - - -#define RF23X_REG_TRXSTATUS 0x01 -#define RF23X_REG_TRXSTATE 0x02 -#define RF23X_REG_TRXCTRL0 0x03 -#define RF23X_REG_TRXCTRL1 0x04 -#define RF23X_REG_TXPWR 0x05 -#define RF23X_REG_RSSI 0x06 -#define RF23X_REG_EDLEVEL 0x07 -#define RF23X_REG_CCA 0x08 -#define RF23X_REG_THRES 0x09 -#define RF23X_REG_RXCTRL 0x0a -#define RF23X_REG_SFD 0x0b -#define RF23X_REG_TRXCTRL2 0x0c -#define RF23X_REG_ANT_DIV 0x0d -#define RF23X_REG_IRQ_MASK 0x0e -#define RF23X_REG_IRQ_STATUS 0x0f -#define RF23X_REG_VREG_CTRL 0x10 -#define RF23X_REG_BATMON 0x11 -#define RF23X_REG_XOSC_CTRL 0x12 -#define RF23X_REG_CCCTRL0 0x13 -#define RF23X_REG_CCCTRL1 0x14 -#define RF23X_REG_RXSYN 0x15 -#define RF23X_REG_TRXRPC 0x16 -#define RF23X_REG_XAHCTRL1 0x17 -#define RF23X_REG_FTNCTRL 0x18 -#define RF23X_REG_XAHCTRL2 0x19 -#define RF23X_REG_PLLCF 0x1a -#define RF23X_REG_PLLDCU 0x1b -#define RF23X_REG_PART 0x1c -#define RF23X_REG_VERSION 0x1d -#define RF23X_REG_MANID0 0x1e -#define RF23X_REG_MANID1 0x1f -#define RF23X_REG_SADDR0 0x20 -#define RF23X_REG_SADDR1 0x21 -#define RF23X_REG_PANID0 0x22 -#define RF23X_REG_PANID1 0x23 -#define RF23X_REG_IEEEADDR0 0x24 -#define RF23X_REG_IEEEADDR1 0x25 -#define RF23X_REG_IEEEADDR2 0x26 -#define RF23X_REG_IEEEADDR3 0x27 -#define RF23X_REG_IEEEADDR4 0x28 -#define RF23X_REG_IEEEADDR5 0x29 -#define RF23X_REG_IEEEADDR6 0x2a -#define RF23X_REG_IEEEADDR7 0x2b -#define RF23X_REG_XAHCTRL0 0x2c -#define RF23X_REG_CSMASEED0 0x2d -#define RF23X_REG_CSMASEED1 0x2e -#define RF23X_REG_CSMABE 0x2f -#define RF23X_REG_TSTCTRLDIGI 0x36 -#define RF23X_REG_TSTAGC 0x3c -#define RF23X_REG_SDM 0x3d -#define RF23X_REG_PHYTXTIME 0x3b -#define RF23X_REG_PHYPMUVALUE 0x3b - - -#define RF23X_TRXSTATUS_POS 0 -#define RF23X_TRXSTATUS_MASK 0x1f -#define RF23X_TRXSTATUS_STATUS RF23X_REG_TRXSTATUS, RF23X_TRXSTATUS_POS, RF23X_TRXSTATUS_MASK - -#define RF23X_TRXCMD_POS 0 -#define RF23X_TRXCMD_MASK 0x1f -#define RF23X_TRXCMD_STATE RF23X_REG_TRXSTATE, RF23X_TRXCMD_POS, RF23X_TRXCMD_MASK - - -#define RF23X_TXPWR_POS_4 0x00 -#define RF23X_TXPWR_POS_3_7 0x01 -#define RF23X_TXPWR_POS_3_4 0x02 -#define RF23X_TXPWR_POS_3 0x03 -#define RF23X_TXPWR_POS_2_5 0x04 -#define RF23X_TXPWR_POS_2 0x05 -#define RF23X_TXPWR_POS_1 0x06 -#define RF23X_TXPWR_0 0x07 -#define RF23X_TXPWR_NEG_1 0x08 -#define RF23X_TXPWR_NEG_2 0x09 -#define RF23X_TXPWR_NEG_3 0x0a -#define RF23X_TXPWR_NEG_4 0x0b -#define RF23X_TXPWR_NEG_6 0x0c -#define RF23X_TXPWR_NEG_8 0x0d -#define RF23X_TXPWR_NEG_12 0x0e -#define RF23X_TXPWR_NEG_17 0x0f - -/**************************************************************************** - * CCA_STATUS - ****************************************************************************/ -#define RF23X_CCA_MODE_CS_OR_ED 0x00 -#define RF23X_CCA_MODE_ED 0x01 -#define RF23X_CCA_MODE_CS 0x02 -#define RF23X_CCA_MODE_CS_AND_ED 0x03 - -#define RF23X_CCA_CHANNEL_POS 0 -#define RF23X_CCA_CHANNEL_MASK 0x1f -#define RF23X_CCA_BITS_CHANNEL RF23X_REG_CCA, RF23X_CCA_CHANNEL_POS, RF23X_CCA_CHANNEL_MASK -#define RF23X_CCA_MODE_POS 5 -#define RF23X_CCA_MODE_MASK 0x03 -#define RF23X_CCA_BITS_MODE RF23X_REG_CCA, RF23X_CCA_MODE_POS, RF23X_CCA_MODE_MASK - - -/**************************************************************************** - * XAH CTRL 1 - ****************************************************************************/ -#define RF23X_XAHCTRL1_PROM_MODE_POS 1 -#define RF23X_XAHCTRL1_PROM_MODE_MASK 0x01 -#define RF23X_XAHCTRL1_BITS_PROM_MODE RF23X_REG_XAHCTRL1, RF23X_XAHCTRL1_PROM_MODE_POS, RF23X_XAHCTRL1_PROM_MODE_MASK - -/**************************************************************************** - * CSMA SEED 0 ****************************************************************************/ +#ifndef __DRIVERS_WIRELESS_IEEE802154_AT86RF23X_H +#define __DRIVERS_WIRELESS_IEEE802154_AT86RF23X_H + /**************************************************************************** - * CSMA SEED 1 + * Pre-processor Definitions ****************************************************************************/ -#define RF23X_CSMASEED1_IAMCOORD_POS 3 -#define RF23X_CSMASEED1_IAMCOORD_MASK 0x1 -#define RF23X_CSMASEED1_IAMCOORD_BITS RF23X_REG_CSMASEED1, RF23X_CSMASEED1_IAMCOORD_POS, RF23X_CSMASEED1_IAMCOORD_MASK + +#define RF23X_SPI_REG_READ 0x80 +#define RF23X_SPI_REG_WRITE 0xc0 +#define RF23X_SPI_FRAME_WRITE 0x60 +#define RF23X_SPI_FRAME_READ 0x20 +#define RF23X_SPI_SRAM_READ 0x00 +#define RF23X_SPI_SRAM_WRITE 0x40 + +/* US Times Constants for the RF233 */ + +#define RF23X_TIME_RESET_BOOT 510 +#define RF23X_TIME_FORCE_TRXOFF 100 +#define RF23X_TIME_P_ON_TO_TRXOFF 510 +#define RF23X_TIME_SLEEP_TO_TRXOFF 1200 +#define RF23X_TIME_RESET 6 +#define RF23X_TIME_ED_MEASUREMENT 140 +#define RF23X_TIME_CCA 140 +#define RF23X_TIME_PLL_LOCK 150 +#define RF23X_TIME_FTN_TUNNING 25 +#define RF23X_TIME_NOCLK_TO_WAKE 6 +#define RF23X_TIME_CMD_FORCE_TRX_OFF 1 +#define RF23X_TIME_TRXOFF_TO_PLL 180 +#define RF23X_TIME_TRANSITION_PLL_ACTIVE 1 +#define RF23X_TIME_TRXOFF_TO_SLEEP 1200 + +#define RF23X_MAX_RETRY_RESET_TO_TRX_OFF 5 + +#define RF23X_REG_TRXSTATUS 0x01 +#define RF23X_REG_TRXSTATE 0x02 +#define RF23X_REG_TRXCTRL0 0x03 +#define RF23X_REG_TRXCTRL1 0x04 +#define RF23X_REG_TXPWR 0x05 +#define RF23X_REG_RSSI 0x06 +#define RF23X_REG_EDLEVEL 0x07 +#define RF23X_REG_CCA 0x08 +#define RF23X_REG_THRES 0x09 +#define RF23X_REG_RXCTRL 0x0a +#define RF23X_REG_SFD 0x0b +#define RF23X_REG_TRXCTRL2 0x0c +#define RF23X_REG_ANT_DIV 0x0d +#define RF23X_REG_IRQ_MASK 0x0e +#define RF23X_REG_IRQ_STATUS 0x0f +#define RF23X_REG_VREG_CTRL 0x10 +#define RF23X_REG_BATMON 0x11 +#define RF23X_REG_XOSC_CTRL 0x12 +#define RF23X_REG_CCCTRL0 0x13 +#define RF23X_REG_CCCTRL1 0x14 +#define RF23X_REG_RXSYN 0x15 +#define RF23X_REG_TRXRPC 0x16 +#define RF23X_REG_XAHCTRL1 0x17 +#define RF23X_REG_FTNCTRL 0x18 +#define RF23X_REG_XAHCTRL2 0x19 +#define RF23X_REG_PLLCF 0x1a +#define RF23X_REG_PLLDCU 0x1b +#define RF23X_REG_PART 0x1c +#define RF23X_REG_VERSION 0x1d +#define RF23X_REG_MANID0 0x1e +#define RF23X_REG_MANID1 0x1f +#define RF23X_REG_SADDR0 0x20 +#define RF23X_REG_SADDR1 0x21 +#define RF23X_REG_PANID0 0x22 +#define RF23X_REG_PANID1 0x23 +#define RF23X_REG_IEEEADDR0 0x24 +#define RF23X_REG_IEEEADDR1 0x25 +#define RF23X_REG_IEEEADDR2 0x26 +#define RF23X_REG_IEEEADDR3 0x27 +#define RF23X_REG_IEEEADDR4 0x28 +#define RF23X_REG_IEEEADDR5 0x29 +#define RF23X_REG_IEEEADDR6 0x2a +#define RF23X_REG_IEEEADDR7 0x2b +#define RF23X_REG_XAHCTRL0 0x2c +#define RF23X_REG_CSMASEED0 0x2d +#define RF23X_REG_CSMASEED1 0x2e +#define RF23X_REG_CSMABE 0x2f +#define RF23X_REG_TSTCTRLDIGI 0x36 +#define RF23X_REG_TSTAGC 0x3c +#define RF23X_REG_SDM 0x3d +#define RF23X_REG_PHYTXTIME 0x3b +#define RF23X_REG_PHYPMUVALUE 0x3b + +#define RF23X_TRXSTATUS_POS 0 +#define RF23X_TRXSTATUS_MASK 0x1f +#define RF23X_TRXSTATUS_STATUS RF23X_REG_TRXSTATUS, RF23X_TRXSTATUS_POS, RF23X_TRXSTATUS_MASK + +#define RF23X_TRXCMD_POS 0 +#define RF23X_TRXCMD_MASK 0x1f +#define RF23X_TRXCMD_STATE RF23X_REG_TRXSTATE, RF23X_TRXCMD_POS, RF23X_TRXCMD_MASK + +#define RF23X_TXPWR_POS_4 0x00 +#define RF23X_TXPWR_POS_3_7 0x01 +#define RF23X_TXPWR_POS_3_4 0x02 +#define RF23X_TXPWR_POS_3 0x03 +#define RF23X_TXPWR_POS_2_5 0x04 +#define RF23X_TXPWR_POS_2 0x05 +#define RF23X_TXPWR_POS_1 0x06 +#define RF23X_TXPWR_0 0x07 +#define RF23X_TXPWR_NEG_1 0x08 +#define RF23X_TXPWR_NEG_2 0x09 +#define RF23X_TXPWR_NEG_3 0x0a +#define RF23X_TXPWR_NEG_4 0x0b +#define RF23X_TXPWR_NEG_6 0x0c +#define RF23X_TXPWR_NEG_8 0x0d +#define RF23X_TXPWR_NEG_12 0x0e +#define RF23X_TXPWR_NEG_17 0x0f + +/* CCA_STATUS */ + +#define RF23X_CCA_MODE_CS_OR_ED 0x00 +#define RF23X_CCA_MODE_ED 0x01 +#define RF23X_CCA_MODE_CS 0x02 +#define RF23X_CCA_MODE_CS_AND_ED 0x03 + +#define RF23X_CCA_CHANNEL_POS 0 +#define RF23X_CCA_CHANNEL_MASK 0x1f +#define RF23X_CCA_BITS_CHANNEL RF23X_REG_CCA, RF23X_CCA_CHANNEL_POS, RF23X_CCA_CHANNEL_MASK +#define RF23X_CCA_MODE_POS 5 +#define RF23X_CCA_MODE_MASK 0x03 +#define RF23X_CCA_BITS_MODE RF23X_REG_CCA, RF23X_CCA_MODE_POS, RF23X_CCA_MODE_MASK + +/* XAH CTRL 1 */ + +#define RF23X_XAHCTRL1_PROM_MODE_POS 1 +#define RF23X_XAHCTRL1_PROM_MODE_MASK 0x01 +#define RF23X_XAHCTRL1_BITS_PROM_MODE RF23X_REG_XAHCTRL1, RF23X_XAHCTRL1_PROM_MODE_POS, RF23X_XAHCTRL1_PROM_MODE_MASK + +/* CSMA SEED 0 */ + +/* CSMA SEED 1 */ + +#define RF23X_CSMASEED1_IAMCOORD_POS 3 +#define RF23X_CSMASEED1_IAMCOORD_MASK 0x1 +#define RF23X_CSMASEED1_IAMCOORD_BITS RF23X_REG_CSMASEED1, RF23X_CSMASEED1_IAMCOORD_POS, RF23X_CSMASEED1_IAMCOORD_MASK #define RF23X_CSMASEED1_AACK_DIS_ACK_POS #define RF23X_CSMASEED1_AACK_SET_PD_POS #define RF23X_CSMASEED1_AACK_FVN_MODE_POS -#define RF23X_CSMASEED1_ +/* TRX Status */ -/**************************************************************************** - * TRX Status - ****************************************************************************/ -#define TRX_STATUS_PON 0x00 -#define TRX_STATUS_BUSYRX 0x01 -#define TRX_STATUS_BUSYTX 0x02 -#define TRX_STATUS_RXON 0x06 -#define TRX_STATUS_TRXOFF 0x08 -#define TRX_STATUS_PLLON 0x09 -#define TRX_STATUS_SLEEP 0x0f -#define TRX_STATUS_DEEPSLEEP 0x10 -#define TRX_STATUS_BUSYRXACK 0x11 -#define TRX_STATUS_BUSYTXARET 0x12 -#define TRX_STATUS_RXAACKON 0x16 -#define TRX_STATUS_TXARETON 0x19 -#define TRX_STATUS_STATEINTRANS 0x1f +#define TRX_STATUS_PON 0x00 +#define TRX_STATUS_BUSYRX 0x01 +#define TRX_STATUS_BUSYTX 0x02 +#define TRX_STATUS_RXON 0x06 +#define TRX_STATUS_TRXOFF 0x08 +#define TRX_STATUS_PLLON 0x09 +#define TRX_STATUS_SLEEP 0x0f +#define TRX_STATUS_DEEPSLEEP 0x10 +#define TRX_STATUS_BUSYRXACK 0x11 +#define TRX_STATUS_BUSYTXARET 0x12 +#define TRX_STATUS_RXAACKON 0x16 +#define TRX_STATUS_TXARETON 0x19 +#define TRX_STATUS_STATEINTRANS 0x1f -/**************************************************************************** - * TRX Command - ****************************************************************************/ -#define TRX_CMD_NOP 0x00 -#define TRX_CMD_TX 0x02 -#define TRX_CMD_FORCETRXOFF 0x03 -#define TRX_CMD_FORCE_PLLON 0x04 -#define TRX_CMD_RX_ON 0x06 -#define TRX_CMD_TRXOFF 0x08 -#define TRX_CMD_PLL_ON 0x09 -#define TRX_CMD_PREP_DEEPSLEEP 0x10 -#define TRX_CMD_RX_AACK_ON 0x16 -#define TRX_CMD_TX_ARET_ON 0x19 +/* TRX Command */ +#define TRX_CMD_NOP 0x00 +#define TRX_CMD_TX 0x02 +#define TRX_CMD_FORCETRXOFF 0x03 +#define TRX_CMD_FORCE_PLLON 0x04 +#define TRX_CMD_RX_ON 0x06 +#define TRX_CMD_TRXOFF 0x08 +#define TRX_CMD_PLL_ON 0x09 +#define TRX_CMD_PREP_DEEPSLEEP 0x10 +#define TRX_CMD_RX_AACK_ON 0x16 +#define TRX_CMD_TX_ARET_ON 0x19 -/**************************************************************************** - * IRQ MASK 0x0E - ****************************************************************************/ -#define RF23X_IRQ_MASK_LOCK_PLL (1<<0) -#define RF23X_IRQ_MASK_UNLOCK_PLL (1<<1) -#define RF23X_IRQ_MASK_RX_START (1<<2) -#define RF23X_IRQ_MASK_TRX_END (1<<3) -#define RF23X_IRQ_MASK_CCA_ED_DONE (1<<4) -#define RF23X_IRQ_MASK_AMI (1<<5) -#define RF23X_IRQ_MASK_TRX_UR (1<<6) -#define RF23X_IRQ_MASK_BAT_LOW (1<<7) +/* IRQ MASK 0x0e */ -#define RF23X_IRQ_MASK_DEFAULT (RF23X_IRQ_MASK_TRX_END) +#define RF23X_IRQ_MASK_LOCK_PLL (1 << 0) +#define RF23X_IRQ_MASK_UNLOCK_PLL (1 << 1) +#define RF23X_IRQ_MASK_RX_START (1 << 2) +#define RF23X_IRQ_MASK_TRX_END (1 << 3) +#define RF23X_IRQ_MASK_CCA_ED_DONE (1 << 4) +#define RF23X_IRQ_MASK_AMI (1 << 5) +#define RF23X_IRQ_MASK_TRX_UR (1 << 6) +#define RF23X_IRQ_MASK_BAT_LOW (1 << 7) +#define RF23X_IRQ_MASK_DEFAULT (RF23X_IRQ_MASK_TRX_END) -#endif /* APPS_EXTERNAL_IEEE_AT86RF23X_H_ */ +#endif /* __DRIVERS_WIRELESS_IEEE802154_AT86RF23X_H */ diff --git a/drivers/wireless/ieee802154/mrf24j40.c b/drivers/wireless/ieee802154/mrf24j40.c index f9cd98cb2d9..4cb4ed99340 100644 --- a/drivers/wireless/ieee802154/mrf24j40.c +++ b/drivers/wireless/ieee802154/mrf24j40.c @@ -65,7 +65,7 @@ ****************************************************************************/ #ifndef CONFIG_SCHED_HPWORK -#error High priority work queue required in this driver +# error High priority work queue required in this driver #endif #ifndef CONFIG_IEEE802154_MRF24J40_SPIMODE @@ -160,44 +160,69 @@ struct mrf24j40_radio_s /* Internal operations */ -static void mrf24j40_lock (FAR struct spi_dev_s *spi); +static void mrf24j40_lock(FAR struct spi_dev_s *spi); -static void mrf24j40_setreg (FAR struct spi_dev_s *spi, uint32_t addr, uint8_t val); -static uint8_t mrf24j40_getreg (FAR struct spi_dev_s *spi, uint32_t addr); +static void mrf24j40_setreg(FAR struct spi_dev_s *spi, uint32_t addr, + uint8_t val); +static uint8_t mrf24j40_getreg(FAR struct spi_dev_s *spi, uint32_t addr); -static int mrf24j40_resetrfsm (FAR struct mrf24j40_radio_s *dev); -static int mrf24j40_pacontrol (FAR struct mrf24j40_radio_s *dev, int mode); -static int mrf24j40_initialize(FAR struct mrf24j40_radio_s *dev); +static int mrf24j40_resetrfsm(FAR struct mrf24j40_radio_s *dev); +static int mrf24j40_pacontrol(FAR struct mrf24j40_radio_s *dev, int mode); +static int mrf24j40_initialize(FAR struct mrf24j40_radio_s *dev); -static int mrf24j40_setrxmode (FAR struct mrf24j40_radio_s *dev, int mode); -static int mrf24j40_regdump (FAR struct mrf24j40_radio_s *dev); -static void mrf24j40_irqwork_rx(FAR struct mrf24j40_radio_s *dev); -static void mrf24j40_irqwork_tx(FAR struct mrf24j40_radio_s *dev); -static void mrf24j40_irqworker (FAR void *arg); -static int mrf24j40_interrupt (int irq, FAR void *context); +static int mrf24j40_setrxmode(FAR struct mrf24j40_radio_s *dev, int mode); +static int mrf24j40_regdump(FAR struct mrf24j40_radio_s *dev); +static void mrf24j40_irqwork_rx(FAR struct mrf24j40_radio_s *dev); +static void mrf24j40_irqwork_tx(FAR struct mrf24j40_radio_s *dev); +static void mrf24j40_irqworker(FAR void *arg); +static int mrf24j40_interrupt(int irq, FAR void *context); /* Driver operations */ -static int mrf24j40_setchannel (FAR struct ieee802154_radio_s *ieee, uint8_t chan); -static int mrf24j40_getchannel (FAR struct ieee802154_radio_s *ieee, FAR uint8_t *chan); -static int mrf24j40_setpanid (FAR struct ieee802154_radio_s *ieee, uint16_t panid); -static int mrf24j40_getpanid (FAR struct ieee802154_radio_s *ieee, FAR uint16_t *panid); -static int mrf24j40_setsaddr (FAR struct ieee802154_radio_s *ieee, uint16_t saddr); -static int mrf24j40_getsaddr (FAR struct ieee802154_radio_s *ieee, FAR uint16_t *saddr); -static int mrf24j40_seteaddr (FAR struct ieee802154_radio_s *ieee, FAR uint8_t *eaddr); -static int mrf24j40_geteaddr (FAR struct ieee802154_radio_s *ieee, FAR uint8_t *eaddr); -static int mrf24j40_setpromisc (FAR struct ieee802154_radio_s *ieee, bool promisc); -static int mrf24j40_getpromisc (FAR struct ieee802154_radio_s *ieee, FAR bool *promisc); -static int mrf24j40_setdevmode (FAR struct ieee802154_radio_s *ieee, uint8_t mode); -static int mrf24j40_getdevmode (FAR struct ieee802154_radio_s *ieee, FAR uint8_t *mode); -static int mrf24j40_settxpower (FAR struct ieee802154_radio_s *ieee, int32_t txpwr); -static int mrf24j40_gettxpower (FAR struct ieee802154_radio_s *ieee, FAR int32_t *txpwr); -static int mrf24j40_setcca (FAR struct ieee802154_radio_s *ieee, FAR struct ieee802154_cca_s *cca); -static int mrf24j40_getcca (FAR struct ieee802154_radio_s *ieee, FAR struct ieee802154_cca_s *cca); -static int mrf24j40_ioctl (FAR struct ieee802154_radio_s *ieee, int cmd, unsigned long arg); -static int mrf24j40_energydetect(FAR struct ieee802154_radio_s *ieee, FAR uint8_t *energy); -static int mrf24j40_rxenable (FAR struct ieee802154_radio_s *ieee, bool state, FAR struct ieee802154_packet_s *packet); -static int mrf24j40_transmit (FAR struct ieee802154_radio_s *ieee, FAR struct ieee802154_packet_s *packet); +static int mrf24j40_setchannel(FAR struct ieee802154_radio_s *ieee, + uint8_t chan); +static int mrf24j40_getchannel(FAR struct ieee802154_radio_s *ieee, + FAR uint8_t *chan); +static int mrf24j40_setpanid(FAR struct ieee802154_radio_s *ieee, + uint16_t panid); +static int mrf24j40_getpanid(FAR struct ieee802154_radio_s *ieee, + FAR uint16_t *panid); +static int mrf24j40_setsaddr(FAR struct ieee802154_radio_s *ieee, + uint16_t saddr); +static int mrf24j40_getsaddr(FAR struct ieee802154_radio_s *ieee, + FAR uint16_t *saddr); +static int mrf24j40_seteaddr(FAR struct ieee802154_radio_s *ieee, + FAR uint8_t *eaddr); +static int mrf24j40_geteaddr(FAR struct ieee802154_radio_s *ieee, + FAR uint8_t *eaddr); +static int mrf24j40_setpromisc(FAR struct ieee802154_radio_s *ieee, + bool promisc); +static int mrf24j40_getpromisc(FAR struct ieee802154_radio_s *ieee, + FAR bool *promisc); +static int mrf24j40_setdevmode(FAR struct ieee802154_radio_s *ieee, + uint8_t mode); +static int mrf24j40_getdevmode(FAR struct ieee802154_radio_s *ieee, + FAR uint8_t *mode); +static int mrf24j40_settxpower(FAR struct ieee802154_radio_s *ieee, + int32_t txpwr); +static int mrf24j40_gettxpower(FAR struct ieee802154_radio_s *ieee, + FAR int32_t *txpwr); +static int mrf24j40_setcca(FAR struct ieee802154_radio_s *ieee, + FAR struct ieee802154_cca_s *cca); +static int mrf24j40_getcca(FAR struct ieee802154_radio_s *ieee, + FAR struct ieee802154_cca_s *cca); +static int mrf24j40_ioctl(FAR struct ieee802154_radio_s *ieee, int cmd, + unsigned long arg); +static int mrf24j40_energydetect(FAR struct ieee802154_radio_s *ieee, + FAR uint8_t *energy); +static int mrf24j40_rxenable(FAR struct ieee802154_radio_s *ieee, + bool state, FAR struct ieee802154_packet_s *packet); +static int mrf24j40_transmit(FAR struct ieee802154_radio_s *ieee, + FAR struct ieee802154_packet_s *packet); + +/**************************************************************************** + * Private Data + ****************************************************************************/ /* These are pointers to ALL registered MRF24J40 devices. * This table is used during irqs to find the context @@ -228,8 +253,6 @@ static const struct ieee802154_radioops_s mrf24j40_devops = * Private Functions ****************************************************************************/ -/* Hardware access routines */ - /**************************************************************************** * Name: mrf24j40_lock * @@ -240,9 +263,9 @@ static const struct ieee802154_radioops_s mrf24j40_devops = static void mrf24j40_lock(FAR struct spi_dev_s *spi) { - SPI_LOCK (spi, 1); - SPI_SETBITS (spi, 8); - SPI_SETMODE (spi, CONFIG_IEEE802154_MRF24J40_SPIMODE); + SPI_LOCK(spi, 1); + SPI_SETBITS(spi, 8); + SPI_SETMODE(spi, CONFIG_IEEE802154_MRF24J40_SPIMODE); SPI_SETFREQUENCY(spi, CONFIG_IEEE802154_MRF24J40_FREQUENCY); } @@ -267,7 +290,8 @@ static inline void mrf24j40_unlock(FAR struct spi_dev_s *spi) * ****************************************************************************/ -static void mrf24j40_setreg(FAR struct spi_dev_s *spi, uint32_t addr, uint8_t val) +static void mrf24j40_setreg(FAR struct spi_dev_s *spi, uint32_t addr, + uint8_t val) { uint8_t buf[3]; int len; @@ -342,8 +366,8 @@ static uint8_t mrf24j40_getreg(FAR struct spi_dev_s *spi, uint32_t addr) SPI_SELECT (spi, SPIDEV_IEEE802154, false); mrf24j40_unlock(spi); - /*wlinfo("r[%04X]=%02X\n", addr, rx[len-1]);*/ - return rx[len-1]; + /* wlinfo("r[%04X]=%02X\n", addr, rx[len - 1]); */ + return rx[len - 1]; } /**************************************************************************** @@ -457,12 +481,13 @@ static int mrf24j40_initialize(FAR struct mrf24j40_radio_s *dev) static int mrf24j40_setrxmode(FAR struct mrf24j40_radio_s *dev, int mode) { uint8_t reg; + if (mode < MRF24J40_RXMODE_NORMAL || mode > MRF24J40_RXMODE_NOCRC) { return -EINVAL; } - reg = mrf24j40_getreg(dev->spi, MRF24J40_RXMCR); + reg = mrf24j40_getreg(dev->spi, MRF24J40_RXMCR); reg &= ~0x03; reg |= mode; @@ -471,11 +496,13 @@ static int mrf24j40_setrxmode(FAR struct mrf24j40_radio_s *dev, int mode) if (mode != MRF24J40_RXMODE_NORMAL) { /* Promisc and error modes: Disable auto ACK */ + reg |= MRF24J40_RXMCR_NOACKRSP; } else { /* Normal mode : enable auto-ACK */ + reg &= ~MRF24J40_RXMCR_NOACKRSP; } @@ -486,8 +513,6 @@ static int mrf24j40_setrxmode(FAR struct mrf24j40_radio_s *dev, int mode) return OK; } -/* Publicized driver routines */ - /**************************************************************************** * Name: mrf24j40_setchannel * @@ -506,7 +531,8 @@ static int mrf24j40_setchannel(FAR struct ieee802154_radio_s *ieee, uint8_t chan) { FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)ieee; - if (chan<11 || chan>26) + + if (chan < 11 || chan > 26) { wlerr("ERROR: Invalid chan: %d\n",chan); return -EINVAL; @@ -640,10 +666,9 @@ static int mrf24j40_seteaddr(FAR struct ieee802154_radio_s *ieee, FAR uint8_t *eaddr) { FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)ieee; - int i; - for (i=0; i<8; i++) + for (i = 0; i < 8; i++) { mrf24j40_setreg(dev->spi, MRF24J40_EADR0 + i, eaddr[i]); dev->eaddr[i] = eaddr[i]; @@ -824,14 +849,36 @@ static int mrf24j40_settxpower(FAR struct ieee802154_radio_s *ieee, case -9: case -8: case -7: - case -6: reg |= 0x07; break; - case -5: reg |= 0x06; break; - case -4: reg |= 0x05; break; - case -3: reg |= 0x04; break; - case -2: reg |= 0x03; break; - case -1: reg |= 0x02; break; - case 0: reg |= 0x00; break; /* value 0x01 is 0.5 db, not used */ - default: return -EINVAL; + case -6: + reg |= 0x07; + break; + + case -5: + reg |= 0x06; + break; + + case -4: + reg |= 0x05; + break; + + case -3: + reg |= 0x04; + break; + + case -2: + reg |= 0x03; + break; + + case -1: + reg |= 0x02; + break; + + case 0: + reg |= 0x00; /* value 0x01 is 0.5 db, not used */ + break; + + default: + return -EINVAL; } mrf24j40_setreg(dev->spi, MRF24J40_RFCON3, reg); @@ -899,7 +946,6 @@ static int mrf24j40_setcca(FAR struct ieee802154_radio_s *ieee, mrf24j40_setreg(dev->spi, MRF24J40_BBREG2, mode); memcpy(&dev->cca, cca, sizeof(struct ieee802154_cca_s)); - return OK; } @@ -933,7 +979,7 @@ static int mrf24j40_regdump(FAR struct mrf24j40_radio_s *dev) { uint32_t i; char buf[4+16*3+2+1]; - int len=0; + int len = 0; wlinfo("Short regs:\n"); @@ -953,9 +999,9 @@ static int mrf24j40_regdump(FAR struct mrf24j40_radio_s *dev) } wlinfo("Long regs:\n"); - for (i=0x80000200;i<0x80000250;i++) + for (i = 0x80000200; i < 0x80000250; i++) { - if ((i&15)==0) + if ((i & 15) == 0) { len=sprintf(buf, "%02x: ",i&0xFF); } @@ -1043,7 +1089,6 @@ static int mrf24j40_energydetect(FAR struct ieee802154_radio_s *ieee, /* Back to automatic control */ mrf24j40_pacontrol(dev, MRF24J40_PA_AUTO); - return OK; } @@ -1057,13 +1102,14 @@ static int mrf24j40_energydetect(FAR struct ieee802154_radio_s *ieee, * ****************************************************************************/ -static int mrf24j40_transmit(FAR struct ieee802154_radio_s *ieee, FAR struct ieee802154_packet_s *packet) +static int mrf24j40_transmit(FAR struct ieee802154_radio_s *ieee, + FAR struct ieee802154_packet_s *packet) { FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)ieee; uint32_t addr; uint8_t reg; int ret; - int hlen = 3; /* include frame control and seq number */ + int hlen = 3; /* Include frame control and seq number */ uint8_t fc1, fc2; mrf24j40_pacontrol(dev, MRF24J40_PA_AUTO); @@ -1081,7 +1127,7 @@ static int mrf24j40_transmit(FAR struct ieee802154_radio_s *ieee, FAR struct iee fc1 = packet->data[0]; fc2 = packet->data[1]; - // wlinfo("fc1 %02X fc2 %02X\n", fc1,fc2); + //wlinfo("fc1 %02X fc2 %02X\n", fc1,fc2); if ((fc2 & IEEE802154_FC2_DADDR) == IEEE802154_DADDR_SHORT) { @@ -1111,7 +1157,7 @@ static int mrf24j40_transmit(FAR struct ieee802154_radio_s *ieee, FAR struct iee hlen += 8; /* Ext saddr */ } -// wlinfo("hlen %d\n",hlen); + //wlinfo("hlen %d\n",hlen); /* Header len, 0, TODO for security modes */ @@ -1166,6 +1212,7 @@ static void mrf24j40_irqwork_tx(FAR struct mrf24j40_radio_s *dev) reg = mrf24j40_getreg(dev->spi, MRF24J40_TXSTAT); /* 1 means it failed, we want 1 to mean it worked. */ + dev->ieee.txok = (reg & MRF24J40_TXSTAT_TXNSTAT) != MRF24J40_TXSTAT_TXNSTAT; dev->ieee.txretries = (reg & MRF24J40_TXSTAT_X_MASK) >> MRF24J40_TXSTAT_X_SHIFT; dev->ieee.txbusy = (reg & MRF24J40_TXSTAT_CCAFAIL) == MRF24J40_TXSTAT_CCAFAIL; @@ -1232,7 +1279,7 @@ static void mrf24j40_irqwork_rx(FAR struct mrf24j40_radio_s *dev) uint32_t index; uint8_t reg; - /*wlinfo("!\n");*/ + /* wlinfo("!\n"); */ /* Disable rx int */ @@ -1248,7 +1295,7 @@ static void mrf24j40_irqwork_rx(FAR struct mrf24j40_radio_s *dev) addr = MRF24J40_RXBUF_BASE; dev->ieee.rxbuf->len = mrf24j40_getreg(dev->spi, addr++); - /*wlinfo("len %3d\n", dev->ieee.rxbuf->len);*/ + /* wlinfo("len %3d\n", dev->ieee.rxbuf->len); */ for (index = 0; index < dev->ieee.rxbuf->len; index++) { @@ -1303,7 +1350,7 @@ static void mrf24j40_irqworker(FAR void *arg) /* Read and store INTSTAT - this clears the register. */ intstat = mrf24j40_getreg(dev->spi, MRF24J40_INTSTAT); -// wlinfo("INT%02X\n", intstat); + //wlinfo("INT%02X\n", intstat); /* Do work according to the pending interrupts */ @@ -1382,15 +1429,14 @@ static int mrf24j40_interrupt(int irq, FAR void *context) ****************************************************************************/ FAR struct ieee802154_radio_s *mrf24j40_init(FAR struct spi_dev_s *spi, - FAR const struct mrf24j40_lower_s *lower) + FAR const struct mrf24j40_lower_s *lower) { FAR struct mrf24j40_radio_s *dev; struct ieee802154_cca_s cca; #if 0 dev = kmm_zalloc(sizeof(struct mrf24j40_radio_s)); - - if (!dev) + if (dev == NULL) { return NULL; } diff --git a/drivers/wireless/ieee802154/mrf24j40.h b/drivers/wireless/ieee802154/mrf24j40.h index c530e61d630..62b2bee888c 100644 --- a/drivers/wireless/ieee802154/mrf24j40.h +++ b/drivers/wireless/ieee802154/mrf24j40.h @@ -33,8 +33,8 @@ * ****************************************************************************/ -#ifndef __DRIVERS_IEEE802154_MRF24J40_H -#define __DRIVERS_IEEE802154_MRF24J40_H +#ifndef __DRIVERS_WIRELESS_IEEE802154_MRF24J40_H +#define __DRIVERS_WIRELESS_IEEE802154_MRF24J40_H /* MRF24J40 Registers *******************************************************/ @@ -214,4 +214,4 @@ #define MRF24J40_TXSTAT_X_SHIFT 6 #define MRF24J40_TXSTAT_X_MASK (3 << MRF24J40_TXSTAT_X_SHIFT) -#endif /* __DRIVERS_IEEE802154_MRF24J40_H */ +#endif /* __DRIVERS_WIRELESS_IEEE802154_MRF24J40_H */ From f449b45b5d19db6ab81d707b727f2456e8f39107 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 15 Mar 2017 14:59:58 -0600 Subject: [PATCH 010/183] Trivial spacing fix --- wireless/ieee802154/radio802154_device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wireless/ieee802154/radio802154_device.c b/wireless/ieee802154/radio802154_device.c index e925b1cf5ee..feb4410465b 100644 --- a/wireless/ieee802154/radio802154_device.c +++ b/wireless/ieee802154/radio802154_device.c @@ -88,7 +88,7 @@ static const struct file_operations radio802154dev_fops = radio802154dev_close, /* close */ radio802154dev_read , /* read */ radio802154dev_write, /* write */ - NULL, /* seek */ + NULL, /* seek */ radio802154dev_ioctl /* ioctl */ #ifndef CONFIG_DISABLE_POLL , NULL /* poll */ From e897949e6d5e7e5bc001b1e2d6567550c60f00be Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 15 Mar 2017 15:47:26 -0600 Subject: [PATCH 011/183] Trivial correction of a typo in a comment. --- Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Kconfig b/Kconfig index 1116ba6ccc5..5496d5920a0 100644 --- a/Kconfig +++ b/Kconfig @@ -737,7 +737,7 @@ config DEBUG_WIRELESS default n depends on WIRELESS || DRIVERS_WIRELESS ---help--- - Enable DEBUG_WIRELESS debug features. + Enable wireless debug features. if DEBUG_WIRELESS From fbd7e2ae34a9b4567e415b3e3cb72378baf19629 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 15 Mar 2017 16:08:56 -0600 Subject: [PATCH 012/183] Bring closer to NuttX coding standard. --- include/nuttx/wireless/ieee802154/at86rf23x.h | 6 +- .../wireless/ieee802154/ieee802154_mac.h | 322 ++++++++++-------- 2 files changed, 182 insertions(+), 146 deletions(-) diff --git a/include/nuttx/wireless/ieee802154/at86rf23x.h b/include/nuttx/wireless/ieee802154/at86rf23x.h index 1ef6c909d2c..b33e58020fd 100644 --- a/include/nuttx/wireless/ieee802154/at86rf23x.h +++ b/include/nuttx/wireless/ieee802154/at86rf23x.h @@ -60,7 +60,8 @@ struct at86rf23x_lower_s #ifdef __cplusplus #define EXTERN extern "C" -extern "C" { +extern "C" +{ #else #define EXTERN extern #endif @@ -90,7 +91,8 @@ extern "C" { * ****************************************************************************/ -FAR struct ieee802154_radio_s *at86rf23x_init(FAR struct spi_dev_s *spi, FAR const struct at86rf23x_lower_s *lower); +FAR struct ieee802154_radio_s *at86rf23x_init(FAR struct spi_dev_s *spi, + FAR const struct at86rf23x_lower_s *lower); #undef EXTERN #ifdef __cplusplus diff --git a/include/nuttx/wireless/ieee802154/ieee802154_mac.h b/include/nuttx/wireless/ieee802154/ieee802154_mac.h index 439825391a9..0cddb694bf7 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_mac.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_mac.h @@ -60,6 +60,36 @@ #define IEEE802154_SADDR_BCAST (uint16_t)0xFFFE #define IEEE802154_EADDR_UNSPEC (uint8_t*)"\xff\xff\xff\xff\xff\xff\xff\xff" +/* IEEE 802.15.4 PHY constants */ + +#define MAC802154_aMaxPHYPacketSize 127 +#define MAC802154_aTurnaroundTime 12 /*symbol periods*/ + +/* IEEE 802.15.4 MAC constants */ + +#define MAC802154_aBaseSlotDuration 60 +#define MAC802154_aNumSuperframeSlots 16 +#define MAC802154_aBaseSuperframeDuration (MAC802154_aBaseSlotDuration * MAC802154_aNumSuperframeSlots) +#define MAC802154_aMaxBE 5 +#define MAC802154_aMaxBeaconOverhead 75 +#define MAC802154_aMaxBeaconPayloadLength (MAC802154_aMaxPHYPacketSize - MAC802154_aMaxBeaconOverhead) +#define MAC802154_aGTSDescPersistenceTime 4 +#define MAC802154_aMaxFrameOverhead 25 +#define MAC802154_aMaxFrameResponseTime 1220 +#define MAC802154_aMaxFrameRetries 3 +#define MAC802154_aMaxLostBeacons 4 +#define MAC802154_aMaxMACFrameSize (MAC802154_aMaxPHYPacketSize - MAC802154_aMaxFrameOverhead) +#define MAC802154_aMaxSIFSFrameSize 18 +#define MAC802154_aMinCAPLength 440 +#define MAC802154_aMinLIFSPeriod 40 +#define MAC802154_aMinSIFSPeriod 12 +#define MAC802154_aResponseWaitTime (32 * MAC802154_aBaseSuperframeDuration) +#define MAC802154_aUnitBackoffPeriod 20 + +/**************************************************************************** + * Public Types + ****************************************************************************/ + /* IEEE 802.15.4 MAC status codes */ enum @@ -88,32 +118,8 @@ enum MAC802154_STATUS_UNSUPPORTED_ATTRIBUTE }; -/* IEEE 802.15.4 PHY constants */ -#define MAC802154_aMaxPHYPacketSize 127 -#define MAC802154_aTurnaroundTime 12 /*symbol periods*/ - -/* IEEE 802.15.4 MAC constants */ -#define MAC802154_aBaseSlotDuration 60 -#define MAC802154_aNumSuperframeSlots 16 -#define MAC802154_aBaseSuperframeDuration (MAC802154_aBaseSlotDuration * MAC802154_aNumSuperframeSlots) -#define MAC802154_aMaxBE 5 -#define MAC802154_aMaxBeaconOverhead 75 -#define MAC802154_aMaxBeaconPayloadLength (MAC802154_aMaxPHYPacketSize - MAC802154_aMaxBeaconOverhead) -#define MAC802154_aGTSDescPersistenceTime 4 -#define MAC802154_aMaxFrameOverhead 25 -#define MAC802154_aMaxFrameResponseTime 1220 -#define MAC802154_aMaxFrameRetries 3 -#define MAC802154_aMaxLostBeacons 4 -#define MAC802154_aMaxMACFrameSize (MAC802154_aMaxPHYPacketSize - MAC802154_aMaxFrameOverhead) -#define MAC802154_aMaxSIFSFrameSize 18 -#define MAC802154_aMinCAPLength 440 -#define MAC802154_aMinLIFSPeriod 40 -#define MAC802154_aMinSIFSPeriod 12 -#define MAC802154_aResponseWaitTime (32 * MAC802154_aBaseSuperframeDuration) -#define MAC802154_aUnitBackoffPeriod 20 - - /* IEEE 802.15.4 PHY/MAC PIB attributes IDs */ + enum { MAC802154_phyCurrentChannel = 0x00, @@ -166,90 +172,95 @@ struct ieee802154_addr_s { uint8_t ia_len; /* structure length, 0/2/8 */ uint16_t ia_panid; /* PAN identifier, can be IEEE802154_PAN_UNSPEC */ - union { + union + { uint16_t _ia_saddr; /* short address */ uint8_t _ia_eaddr[8]; /* extended address */ } ia_addr; + #define ia_saddr ia_addr._ia_saddr #define ia_eaddr ia_addr._ia_eaddr }; + #define IEEE802154_ADDRSTRLEN 22 /* (2*2+1+8*2, PPPP/EEEEEEEEEEEEEEEE) */ /* Operations */ -struct ieee802154_mac_s; +struct ieee802154_mac_s; /* Forward reference */ struct ieee802154_macops_s { /* Requests, confirmed asynchronously via callbacks */ - CODE int req_data (struct ieee802154_mac_s *mac, /* Transmit a data frame */ - uint8_t handle, - uint8_t *buf, - int len); + /* Transmit a data frame */ - CODE int req_purge (struct ieee802154_mac_s *mac, /* Cancel transmission of a data frame */ - uint8_t handle); + CODE int (*req_data)(FAR struct ieee802154_mac_s *mac, uint8_t handle, + FAR uint8_t *buf, int len); - CODE int req_associate (struct ieee802154_mac_s *mac, /* Start association with coordinator */ - uint16_t panid, + /* Cancel transmission of a data frame */ + + CODE int (*req_purge)(FAR struct ieee802154_mac_s *mac, uint8_t handle); + + /* Start association with coordinator */ + + CODE int (*req_associate)(FAR struct ieee802154_mac_s *mac, uint16_t panid, uint8_t *coordeadr); - CODE int req_disassociate(struct ieee802154_mac_s *mac, /* Start disassociation with coordinator */ - uint8_t *eadr, - uint8_t reason); + /* Start disassociation with coordinator */ - CODE int req_get (struct ieee802154_mac_s *mac, /* Read the PIB */ - int attribute); + CODE int (*req_disassociate)(FAR struct ieee802154_mac_s *mac, + FAR uint8_t *eadr, uint8_t reason); - CODE int req_gts (struct ieee802154_mac_s *mac, /* Allocate or deallocate a GTS */ - uint8_t* characteristics); + /* Read the PIB */ - CODE int req_reset (struct ieee802154_mac_s *mac, /* MAC layer reset */ - bool setdefaults); + CODE int (*req_get)(FAR struct ieee802154_mac_s *mac, int attribute); - CODE int req_rxenable (struct ieee802154_mac_s *mac, /* PHY receiver control */ - bool deferrable, - int ontime, - int duration); + /* Allocate or deallocate a GTS */ - CODE int req_scan (struct ieee802154_mac_s *mac, /* Start a network scan */ - uint8_t type, - uint32_t channels, - int duration); + CODE int (*req_gts)(FAR struct ieee802154_mac_s *mac, + FAR uint8_t *characteristics); - CODE int req_set (struct ieee802154_mac_s *mac, /* Change the PIB */ - int attribute, - uint8_t *value, - int valuelen); + /* MAC layer reset */ - CODE int req_start (struct ieee802154_mac_s *mac, - uint16_t panid, - int channel, - uint8_t bo, - uint8_t fo, - bool coord, - bool batext, - bool realign); + CODE int (*req_reset)(FAR struct ieee802154_mac_s *mac, bool setdefaults); - CODE int req_sync (struct ieee802154_mac_s *mac, - int channel, - bool track); + /* PHY receiver control */ - CODE int req_poll (struct ieee802154_mac_s *mac, - uint8_t *coordaddr); + CODE int (*req_rxenable)(FAR struct ieee802154_mac_s *mac, bool deferrable, + int ontime, int duration); + + /* Start a network scan */ + + CODE int (*req_scan)(FAR struct ieee802154_mac_s *mac, uint8_t type, + uint32_t channels, int duration); + + /* Change the PIB */ + + CODE int (*req_set)(FAR struct ieee802154_mac_s *mac, int attribute, + FAR uint8_t *value, int valuelen); + + CODE int (*req_start)(FAR struct ieee802154_mac_s *mac, uint16_t panid, + int channel, uint8_t bo, uint8_t fo, bool coord, + bool batext, bool realign); + + CODE int (*req_sync)(FAR struct ieee802154_mac_s *mac, int channel, + bool track); + + CODE int (*req_poll)(FAR struct ieee802154_mac_s *mac, + FAR uint8_t *coordaddr); /* Synchronous Responses to Indications received via callbacks */ - CODE int rsp_associate (struct ieee802154_mac_s *mac, /* Reply to an association request */ - uint8_t eadr, - uint16_t saddr, - int status); + /* Reply to an association request */ - CODE int rsp_orphan (struct ieee802154_mac_s *mac, /* Orphan device management */ - uint8_t *orphanaddr, - uint16_t saddr, - bool associated); + CODE int (*rsp_associate)(FAR struct ieee802154_mac_s *mac, uint8_t eadr, + uint16_t saddr, int status); + + /* Orphan device management */ + + CODE int (*rsp_orphan)(FAR struct ieee802154_mac_s *mac, + FAR uint8_t *orphanaddr, uint16_t saddr, + bool associated); }; /* Notifications */ @@ -258,74 +269,95 @@ struct ieee802154_maccb_s { /* Asynchronous confirmations to requests */ - CODE int conf_data (struct ieee802154_mac_s *mac, /* Data frame was received by remote device */ - uint8_t *buf, - int len); - CODE int conf_purge (struct ieee802154_mac_s *mac, /* Data frame was purged */ - uint8_t handle, - int status); - CODE int conf_associate (struct ieee802154_mac_s *mac, /* Association request completed */ - uint16_t saddr, - int status); - CODE int conf_disassociate(struct ieee802154_mac_s *mac, /* Disassociation request completed */ - int status); - CODE int conf_get (struct ieee802154_mac_s *mac, /* PIB data returned */ - int status, - int attribute, - uint8_t *value, - int valuelen); - CODE int conf_gts (struct ieee802154_mac_s *mac, /* GTS management completed */ - uint8_t *characteristics, - int status); - CODE int conf_reset (struct ieee802154_mac_s *mac, /* MAC reset completed */ - int status); - CODE int conf_rxenable (struct ieee802154_mac_s *mac, - int status); - CODE int conf_scan (struct ieee802154_mac_s *mac, - int status, - uint8_t type, - uint32_t unscanned, - int rsltsize, - uint8_t *edlist, - uint8_t *pandescs); - CODE int conf_set (struct ieee802154_mac_s *mac, - int status, int attribute); - CODE int conf_start (struct ieee802154_mac_s *mac, - int status); - CODE int conf_poll (struct ieee802154_mac_s *mac, - int status); + /* Data frame was received by remote device */ + + CODE int (*conf_data)(FAR struct ieee802154_mac_s *mac, + FAR uint8_t *buf, int len); + + /* Data frame was purged */ + + CODE int (*conf_purge)(FAR struct ieee802154_mac_s *mac, uint8_t handle, + int status); + + /* Association request completed */ + + CODE int (*conf_associate)(FAR struct ieee802154_mac_s *mac, + uint16_t saddr, int status); + + /* Disassociation request completed */ + + CODE int (*conf_disassociate)(FAR struct ieee802154_mac_s *mac, + int status); + + /* PIB data returned */ + + CODE int (*conf_get)(FAR struct ieee802154_mac_s *mac, int status, + int attribute, FAR uint8_t *value, + int valuelen); + + /* GTS management completed */ + + CODE int (*conf_gts)(FAR struct ieee802154_mac_s *mac, + FAR uint8_t *characteristics, int status); + + /* MAC reset completed */ + + CODE int (*conf_reset)(FAR struct ieee802154_mac_s *mac, int status); + + CODE int (*conf_rxenable)(FAR struct ieee802154_mac_s *mac, int status); + + CODE int (*conf_scan)(FAR struct ieee802154_mac_s *mac, int status, + uint8_t type, uint32_t unscanned, int rsltsize, + FAR uint8_t *edlist, FAR uint8_t *pandescs); + + CODE int (*conf_set)(FAR struct ieee802154_mac_s *mac, int status, + int attribute); + + CODE int (*conf_start)(FAR struct ieee802154_mac_s *mac, int status); + + CODE int (*conf_poll)(FAR struct ieee802154_mac_s *mac, int status); /* Asynchronous event indications, replied to synchronously with responses */ - CODE int ind_data (struct ieee802154_mac_s *mac, /* Data frame received */ - uint8_t *buf, - int len); - CODE int ind_associate (struct ieee802154_mac_s *mac, /* Association request received */ - uint16_t clipanid, - uint8_t *clieaddr); - CODE int ind_disassociate (struct ieee802154_mac_s *mac, /* Disassociation request received */ - uint8_t *eadr, - uint8_t reason); - CODE int ind_beaconnotify (struct ieee802154_mac_s *mac, /* Beacon notification */ - uint8_t *bsn, - uint_t *pandesc, - uint8_t *sdu, - int sdulen); - CODE int ind_gts (struct ieee802154_mac_s *mac, /* GTS management request received */ - uint8_t *devaddr, - uint8_t *characteristics); - CODE int ind_orphan (struct ieee802154_mac_s *mac, /* Orphan device detected */ - uint8_t *orphanaddr); - CODE int ind_commstatus (struct ieee802154_mac_s *mac, - uint16_t panid, - uint8_t *src, - uint8_t *dst, - int status); - CODE int ind_syncloss (struct ieee802154_mac_s *mac, - int reason); + /* Data frame received */ + + CODE int (*ind_data)(FAR struct ieee802154_mac_s *mac, FAR uint8_t *buf, + int len); + + /* Association request received */ + + CODE int (*ind_associate)(FAR struct ieee802154_mac_s *mac, + uint16_t clipanid, FAR uint8_t *clieaddr); + + /* Disassociation request received */ + + CODE int (*ind_disassociate)(FAR struct ieee802154_mac_s *mac, + FAR uint8_t *eadr, uint8_t reason); + + /* Beacon notification */ + + CODE int (*ind_beaconnotify)(FAR struct ieee802154_mac_s *mac, + FAR uint8_t *bsn, FAR uint_t *pandesc, + FAR uint8_t *sdu, int sdulen); + + /* GTS management request received */ + + CODE int (*ind_gts)(FAR struct ieee802154_mac_s *mac, + FAR uint8_t *devaddr, FAR uint8_t *characteristics); + + /* Orphan device detected */ + + CODE int (*ind_orphan)(FAR struct ieee802154_mac_s *mac, + FAR uint8_t *orphanaddr); + + CODE int (*ind_commstatus)(FAR struct ieee802154_mac_s *mac, + uint16_t panid, FAR uint8_t *src, + FAR uint8_t *dst, int status); + + CODE int (*ind_syncloss)(FAR struct ieee802154_mac_s *mac, int reason); }; -struct ieee802154_radio_s; +struct ieee802154_radio_s; /* Forware reference */ struct ieee802154_mac_s { @@ -346,8 +378,7 @@ extern "C" * Public Function Prototypes ****************************************************************************/ -/* - * Instanciate a 802.15.4 MAC from a 802.15.4 radio device. +/* 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 @@ -356,9 +387,12 @@ extern "C" * 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 . + * device via mac802154_device.c . */ -FAR struct ieee802154_mac_s * mac802154_register(FAR struct ieee802154_radio_s *radiodev, struct ieee802154_maccb_s *callbacks); + +FAR struct ieee802154_mac_s * + mac802154_register(FAR struct ieee802154_radio_s *radiodev, + FAR struct ieee802154_maccb_s *callbacks); #undef EXTERN #ifdef __cplusplus From 89a907a5827aec756925b06001f8ecc2992b146e Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 15 Mar 2017 16:11:36 -0600 Subject: [PATCH 013/183] Bring closer to NuttX coding standard. --- .../wireless/ieee802154/ieee802154_radio.h | 25 +++++++++++++------ include/nuttx/wireless/ieee802154/mrf24j40.h | 5 ++-- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/include/nuttx/wireless/ieee802154/ieee802154_radio.h b/include/nuttx/wireless/ieee802154/ieee802154_radio.h index 06276b2870e..7adbbfd7ae8 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_radio.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_radio.h @@ -86,7 +86,8 @@ struct ieee802154_radio_s; struct ieee802154_radioops_s { - CODE int (*setchannel)(FAR struct ieee802154_radio_s *dev, uint8_t channel); + CODE int (*setchannel)(FAR struct ieee802154_radio_s *dev, + uint8_t channel); CODE int (*getchannel)(FAR struct ieee802154_radio_s *dev, FAR uint8_t *channel); @@ -107,7 +108,8 @@ struct ieee802154_radioops_s CODE int (*getpromisc)(FAR struct ieee802154_radio_s *dev, FAR bool *promisc); - CODE int (*setdevmode)(FAR struct ieee802154_radio_s *dev, uint8_t devmode); + CODE int (*setdevmode)(FAR struct ieee802154_radio_s *dev, + uint8_t devmode); CODE int (*getdevmode)(FAR struct ieee802154_radio_s *dev, FAR uint8_t *devmode); @@ -139,14 +141,21 @@ struct ieee802154_radio_s /* Packet reception management */ - struct ieee802154_packet_s *rxbuf; /* packet reception buffer, filled by rx interrupt, NULL if rx not enabled */ - sem_t rxsem; /* Semaphore posted after reception of a packet */ + struct ieee802154_packet_s *rxbuf; /* packet reception buffer, filled by + * rx interrupt, NULL if rx not enabled */ + sem_t rxsem; /* Semaphore posted after reception of + * a packet */ /* Packet transmission management */ - bool txok; /* Last transmission status, filled by tx interrupt */ - bool txbusy; /* Last transmission failed because channel busy */ - uint8_t txretries; /* Last transmission required this much retries */ - sem_t txsem; /* Semaphore posted after transmission of a packet */ + + bool txok; /* Last transmission status, filled by + * tx interrupt */ + bool txbusy; /* Last transmission failed because + * channel busy */ + uint8_t txretries; /* Last transmission required this much + * retries */ + sem_t txsem; /* Semaphore posted after transmission + * of a packet */ }; #ifdef __cplusplus diff --git a/include/nuttx/wireless/ieee802154/mrf24j40.h b/include/nuttx/wireless/ieee802154/mrf24j40.h index 167f125b33b..1871769c825 100644 --- a/include/nuttx/wireless/ieee802154/mrf24j40.h +++ b/include/nuttx/wireless/ieee802154/mrf24j40.h @@ -100,8 +100,9 @@ extern "C" ****************************************************************************/ struct spi_dev_s; /* Forward reference */ -FAR struct ieee802154_radio_s *mrf24j40_init(FAR struct spi_dev_s *spi, - FAR const struct mrf24j40_lower_s *lower); +FAR struct ieee802154_radio_s * + mrf24j40_init(FAR struct spi_dev_s *spi, + FAR const struct mrf24j40_lower_s *lower); #undef EXTERN #ifdef __cplusplus From a492a05e34fe1f6bdbb701135d02ee41a2b4c101 Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Wed, 15 Mar 2017 18:14:56 -0400 Subject: [PATCH 014/183] fs/ioctl.h: Changes _MAC854 to _MAC802154 and creates _RADIO802154 --- include/nuttx/fs/ioctl.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/include/nuttx/fs/ioctl.h b/include/nuttx/fs/ioctl.h index 18f20b3d435..35265fad085 100644 --- a/include/nuttx/fs/ioctl.h +++ b/include/nuttx/fs/ioctl.h @@ -86,7 +86,8 @@ #define _SPIBASE (0x2100) /* SPI driver commands */ #define _GPIOBASE (0x2200) /* GPIO driver commands */ #define _CLIOCBASE (0x1200) /* Contactless modules ioctl commands */ -#define _MAC854BASE (0x2300) /* 802.15.4 device ioctl commands */ +#define _MAC802154BASE (0x2300) /* 802.15.4 MAC ioctl commands */ +#define _RADIO802154BASE(0x2400) /* 802.15.4 Radio ioctl commands */ /* boardctl() commands share the same number space */ @@ -403,10 +404,16 @@ #define _CLIOC(nr) _IOC(_CLIOCBASE,nr) /* 802.15.4 MAC driver ioctl definitions *******************************************/ -/* (see nuttx/ieee802154/ieee802154_dev.h */ +/* (see nuttx/include/wireless/ieee802154/ieee802154_mac.h */ -#define _MAC854IOCVALID(c) (_IOC_TYPE(c)==_MAC854BASE) -#define _MAC854IOC(nr) _IOC(_MAC854BASE,nr) +#define _MAC802154IOCVALID(c) (_IOC_TYPE(c)==_MAC802154BASE) +#define _MAC802154IOC(nr) _IOC(_MAC802154BASE,nr) + +/* 802.15.4 Radio driver ioctl definitions *******************************************/ +/* (see nuttx/ieee802154/wireless/ieee802154_radio.h */ + +#define _RADIO802154IOCVALID(c) (_IOC_TYPE(c)==_RADIO802154BASE) +#define _RADIO802154IOC(nr) _IOC(_RADIO802154BASE,nr) /* boardctl() command definitions *******************************************/ From 22651dcae22d0cc3c2dadcb1f38e433839d2cbf9 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 22 Mar 2017 15:20:05 -0600 Subject: [PATCH 015/183] Clicker2-STM32: Add framework for MRF24J40 support. Untested and still some missing logic. --- configs/clicker2-stm32/Kconfig | 16 + configs/clicker2-stm32/src/Makefile | 4 + configs/clicker2-stm32/src/clicker2-stm32.h | 16 + configs/clicker2-stm32/src/stm32_bringup.c | 10 + configs/clicker2-stm32/src/stm32_buttons.c | 1 + configs/clicker2-stm32/src/stm32_mrf24j40.c | 291 +++++++++++++++++++ include/nuttx/wireless/ieee802154/mrf24j40.h | 12 +- 7 files changed, 344 insertions(+), 6 deletions(-) create mode 100644 configs/clicker2-stm32/src/stm32_mrf24j40.c diff --git a/configs/clicker2-stm32/Kconfig b/configs/clicker2-stm32/Kconfig index b2e5965456c..a5d3a68cbcd 100644 --- a/configs/clicker2-stm32/Kconfig +++ b/configs/clicker2-stm32/Kconfig @@ -21,4 +21,20 @@ config CLICKER2_STM32_MB2_SPI ---help--- Enable SPI support on mikroBUS1 (STM32 SPI2) +config CLICKER2_STM32_MB1_BEE + bool "mikroBUS1 MRF24J40 BEE" + default y + depends on IEEE802154_MRF24J40 + select CLICKER2_STM32_MB1_SPI + ---help--- + Enable support for MRF24J40 BEE on mikroBUS1 + +config CLICKER2_STM32_MB2_BEE + bool "mikroBUS2 MRF24J40 BEE" + default n + depends on IEEE802154_MRF24J40 + select CLICKER2_STM32_MB2_SPI + ---help--- + Enable support for MRF24J40 BEE on mikroBUS2 + endif # ARCH_BOARD_CLICKER2_STM32 diff --git a/configs/clicker2-stm32/src/Makefile b/configs/clicker2-stm32/src/Makefile index bafc45bff17..3980c3ac7df 100644 --- a/configs/clicker2-stm32/src/Makefile +++ b/configs/clicker2-stm32/src/Makefile @@ -56,6 +56,10 @@ ifeq ($(CONFIG_LIB_BOARDCTL),y) CSRCS += stm32_appinit.c endif +ifeq ($(CONFIG_IEEE802154_MRF24J40),y) +CSRCS += stm32_mrf24j40.c +endif + ifeq ($(CONFIG_ADC),y) CSRCS += stm32_adc.c endif diff --git a/configs/clicker2-stm32/src/clicker2-stm32.h b/configs/clicker2-stm32/src/clicker2-stm32.h index 544366c8dd2..41081ae7940 100644 --- a/configs/clicker2-stm32/src/clicker2-stm32.h +++ b/configs/clicker2-stm32/src/clicker2-stm32.h @@ -286,5 +286,21 @@ int stm32_adc_setup(void); int stm32_can_setup(void); #endif +/**************************************************************************** + * Name: stm32_mrf24j40_initialize + * + * Description: + * Initialize the MRF24J40 device. + * + * Returned Value: + * Zero is returned on success. Otherwise, a negated errno value is + * returned to indicate the nature of the failure. + * + ****************************************************************************/ + +#if defined(CONFIG_CLICKER2_STM32_MB1_BEE) || defined(CONFIG_CLICKER2_STM32_MB2_BEE) +int stm32_mrf24j40_initialize(void) +#endif + #endif /* __ASSEMBLY__ */ #endif /* __CONFIGS_OLIMEX_STM32_P407_SRC_H */ diff --git a/configs/clicker2-stm32/src/stm32_bringup.c b/configs/clicker2-stm32/src/stm32_bringup.c index 1dcc276812d..b7adf9dcc12 100644 --- a/configs/clicker2-stm32/src/stm32_bringup.c +++ b/configs/clicker2-stm32/src/stm32_bringup.c @@ -153,6 +153,16 @@ int stm32_bringup(void) } #endif +#if defined(CONFIG_CLICKER2_STM32_MB1_BEE) || defined(CONFIG_CLICKER2_STM32_MB2_BEE) + /* Configure MRF24J40 wireless */ + + ret = stm32_mrf24j40_initialize(); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: stm32_mrf24j40_initialize() failed: %d\n", ret); + } +#endif + #ifdef CONFIG_BUTTONS /* Register the BUTTON driver */ diff --git a/configs/clicker2-stm32/src/stm32_buttons.c b/configs/clicker2-stm32/src/stm32_buttons.c index 14da26b9646..3d8122d2aee 100644 --- a/configs/clicker2-stm32/src/stm32_buttons.c +++ b/configs/clicker2-stm32/src/stm32_buttons.c @@ -47,6 +47,7 @@ #include #include "stm32_gpio.h" +#include "stm32_exti.h" #include "clicker2-stm32.h" diff --git a/configs/clicker2-stm32/src/stm32_mrf24j40.c b/configs/clicker2-stm32/src/stm32_mrf24j40.c new file mode 100644 index 00000000000..ef36bc4b3ec --- /dev/null +++ b/configs/clicker2-stm32/src/stm32_mrf24j40.c @@ -0,0 +1,291 @@ +/**************************************************************************** + * configs/freedom-kl25z/src/stm32_mrf24j40.c + * + * Copyright (C) 2017 Gregory Nutt, All rights reserver + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "stm32_gpio.h" +#include "stm32_exti.h" +#include "stm32_spi.h" + +#include "clicker2-stm32.h" + +#ifdef CONFIG_IEEE802154_MRF24J40 + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#ifndef CONFIG_DRIVERS_WIRELESS +# error Wireless support requires CONFIG_DRIVERS_WIRELESS +#endif + +#if !defined(CONFIG_CLICKER2_STM32_MB1_BEE) && !defined(CONFIG_CLICKER2_STM32_MB2_BEE) +# error Only the Mikroe BEE board is supported +#endif + +#ifdef CONFIG_CLICKER2_STM32_MB1_BEE +# ifndef CONFIG_STM32_SPI3 +# error Mikroe BEE on mikroBUS1 requires CONFIG_STM32_SPI3 +# endif +#endif + +#ifdef CONFIG_CLICKER2_STM32_MB2_BEE +# ifndef CONFIG_STM32_SPI2 +# error Mikroe BEE on mikroBUS1 requires CONFIG_STM32_SPI2 +# endif +#endif + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +struct stm32_priv_s +{ + struct mrf24j40_lower_s dev; + xcpt_t handler; + uint32_t intcfg; + uint8_t spidev; +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/* IRQ/GPIO access callbacks. These operations all hidden behind callbacks + * to isolate the MRF24J40 driver from differences in GPIO interrupt handling + * varying boards and MCUs. + * + * irq_attach - Attach the MRF24J40 interrupt handler to the GPIO + interrupt + * irq_enable - Enable or disable the GPIO interrupt + */ + +static int stm32_attach_irq(FAR const struct mrf24j40_lower_s *lower, + xcpt_t handler); +static void stm32_enable_irq(FAR const struct mrf24j40_lower_s *lower, + int state); +static int stm32_mrf24j40_devsetup(FAR struct stm32_priv_s *priv)' + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/* A reference to a structure of this type must be passed to the MRF24J40 + * driver. This structure provides information about the configuration + * of the MRF24J40 and provides some board-specific hooks. + * + * Memory for this structure is provided by the caller. It is not copied + * by the driver and is presumed to persist while the driver is active. The + * memory must be writable because, under certain circumstances, the driver + * may modify frequency or X plate resistance values. + */ + +#ifdef CONFIG_CLICKER2_STM32_MB1_BEE +static struct stm32_priv_s g_mrf24j40_mb1_priv = +{ + .dev.attach = stm32_attach_irq, + .dev.enable = stm32_enable_irq, + .handler = NULL, + .intcfg = GPIO_MB1_INT, + .spidev = 3, +}; +#endif + +#ifdef CONFIG_CLICKER2_STM32_MB2_BEE +static struct stm32_priv_s g_mrf24j40_mb2_priv = +{ + .dev.attach = stm32_attach_irq, + .dev.enable = stm32_enable_irq, + .uint32_t = GPIO_MB2_INT, + .spidev = 2, +}; +#endif + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/* IRQ/GPIO access callbacks. These operations all hidden behind + * callbacks to isolate the MRF24J40 driver from differences in GPIO + * interrupt handling by varying boards and MCUs. If possible, + * interrupts should be configured on both rising and falling edges + * so that contact and loss-of-contact events can be detected. + * + * irq_attach - Attach the MRF24J40 interrupt handler to the GPIO + * interrupt + * irq_enable - Enable or disable the GPIO interrupt + */ + +static int stm32_attach_irq(FAR struct mrf24j40_lower_s *lower, + xcpt_t handler) +{ + FAR struct stm32_priv_s *priv = (FAR struct mrf24j40_lower_s *)lower; + + DEBUASSERT(priv != NULL); + + /* Just save the handler for use when the interrupt is enabled */ + + priv->handler = handler; + return OK; +} + +static void stm32_enable_irq(FAR struct mrf24j40_lower_s *lower, int state) +{ + FAR struct stm32_priv_s *priv = (FAR struct mrf24j40_lower_s *)lower; + + /* The caller should not attempt to enable interrupts if the handler + * has not yet been 'attached' + */ + + DEBUGASSERT(priv != NULL && (priv->handler != NULL || state == 0)); + + /* Attach and enable, or detach and disable */ + + wlinfo("state:%d\n", state); + if (state != 0) + { + (void)stm32_gpiosetevent(priv->intcfg, true, true, true, + priv->handler, lower); + } + else + { + (void)stm32_gpiosetevent(priv->intcfg, false, false, false, + NULL, NULL); + } +} + +/**************************************************************************** + * Name: stm32_mrf24j40_devsetup + * + * Description: + * Initialize one the MRF24J40 device in one mikroBUS slot + * + * Returned Value: + * Zero is returned on success. Otherwise, a negated errno value is + * returned to indicate the nature of the failure. + * + ****************************************************************************/ + +static int stm32_mrf24j40_devsetup(FAR struct stm32_priv_s *priv) +{ + FAR struct ieee802154_radio_s *radio; + FAR struct spi_dev_s *spi; + + /* Configure the interrupt pin */ + + stm32_configgpio(priv->intcfg); + + /* Initialize the SPI bus and get an instance of the SPI interface */ + + spi = stm32_spibus_initialize(priv->spidev); + if (spi == NULL) + { + wlerr("ERROR: Failed to initialize SPI bus %d\n", priv->spidev); + return -ENODEV; + } + + /* Initialize and register the SPI MRF24J40 device */ + + radio = mrf24j40_init(spi, &priv->dev); + if (radio == NULL) + { + wlerr("ERROR: Failed to initialize SPI bus %d\n", priv->spidev); + return -ENODEV; + } + + /* Now.. do what with the MRF24J40 instance? */ +#warning Missing logic + + return OK; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: stm32_mrf24j40_initialize + * + * Description: + * Initialize the MRF24J40 device. + * + * Returned Value: + * Zero is returned on success. Otherwise, a negated errno value is + * returned to indicate the nature of the failure. + * + ****************************************************************************/ + +int stm32_mrf24j40_initialize(void) +{ + int ret; + +#ifdef CONFIG_CLICKER2_STM32_MB1_BEE + wlinfo("Configuring BEE in mikroBUS1\n"); + + ret = stm32_mrf24j40_devsetup(&g_mrf24j40_mb1_priv); + if (ret < 0) + { + wlerr("ERROR: Failed to initialize BD in mikroBUS1: %d\n", ret); + } +#endif + +#ifdef CONFIG_CLICKER2_STM32_MB2_BEE + wlinfo("Configuring BEE in mikroBUS2\n"); + + ret = stm32_mrf24j40_devsetup(&g_mrf24j40_mb2_priv); + if (ret < 0) + { + wlerr("ERROR: Failed to initialize BD in mikroBUS2: %d\n", ret); + } +#endif + + UNUSED(ret); + return OK; +} +#endif /* CONFIG_IEEE802154_MRF24J40 */ diff --git a/include/nuttx/wireless/ieee802154/mrf24j40.h b/include/nuttx/wireless/ieee802154/mrf24j40.h index 1871769c825..8f86abcfcb5 100644 --- a/include/nuttx/wireless/ieee802154/mrf24j40.h +++ b/include/nuttx/wireless/ieee802154/mrf24j40.h @@ -52,12 +52,12 @@ * * The MRF24J40 interrupt is an active low, *level* interrupt. From Datasheet: * "Note 1: The INTEDGE polarity defaults to: - * 0 = Falling Edge. Ensure that the inter- - * rupt polarity matches the interrupt pin - * polarity of the host microcontroller. - * Note 2: The INT pin will remain high or low, - * depending on INTEDGE polarity setting, - * until INTSTAT register is read." + * + * 0 = Falling Edge. Ensure that the interrupt polarity matches the + * interrupt pin polarity of the host microcontroller. + * + * Note 2: The INT pin will remain high or low, depending on INTEDGE + * polarity setting, until INTSTAT register is read." */ struct mrf24j40_lower_s From 40a8ef3c009c0fb813e506e7cd0cf2c69cedb717 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 23 Mar 2017 06:58:54 -0600 Subject: [PATCH 016/183] Clicker2-STM32: Add logic to register the MRF24J40 radio character device. --- configs/clicker2-stm32/src/stm32_mrf24j40.c | 24 ++++++++++++++++--- include/nuttx/wireless/ieee802154/at86rf23x.h | 5 ++-- .../wireless/ieee802154/ieee802154_radio.h | 22 +++++++++++++++++ wireless/ieee802154/radio802154_device.c | 4 ++++ 4 files changed, 50 insertions(+), 5 deletions(-) diff --git a/configs/clicker2-stm32/src/stm32_mrf24j40.c b/configs/clicker2-stm32/src/stm32_mrf24j40.c index ef36bc4b3ec..99ad2faa06d 100644 --- a/configs/clicker2-stm32/src/stm32_mrf24j40.c +++ b/configs/clicker2-stm32/src/stm32_mrf24j40.c @@ -65,7 +65,12 @@ # error Wireless support requires CONFIG_DRIVERS_WIRELESS #endif -#if !defined(CONFIG_CLICKER2_STM32_MB1_BEE) && !defined(CONFIG_CLICKER2_STM32_MB2_BEE) +#ifndef CONFIG_IEEE802154_DEV +# error IEEE802.15.4 radio character device required (CONFIG_IEEE802154_DEV) +#endif + +#if !defined(CONFIG_CLICKER2_STM32_MB1_BEE) && \ + !defined(CONFIG_CLICKER2_STM32_MB2_BEE) # error Only the Mikroe BEE board is supported #endif @@ -81,6 +86,8 @@ # endif #endif +#define RADIO_DEVNAME "/dev/mrf24j40" + /**************************************************************************** * Private Types ****************************************************************************/ @@ -239,8 +246,19 @@ static int stm32_mrf24j40_devsetup(FAR struct stm32_priv_s *priv) return -ENODEV; } - /* Now.. do what with the MRF24J40 instance? */ -#warning Missing logic +#ifdef CONFIG_IEEE802154_DEV + /* Register a character driver to access the IEEE 802.15.4 radio from + * user-space + */ + + ret = radio802154dev_register(radio, RADIO_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/at86rf23x.h b/include/nuttx/wireless/ieee802154/at86rf23x.h index b33e58020fd..7d6f1fe0ce8 100644 --- a/include/nuttx/wireless/ieee802154/at86rf23x.h +++ b/include/nuttx/wireless/ieee802154/at86rf23x.h @@ -91,8 +91,9 @@ extern "C" * ****************************************************************************/ -FAR struct ieee802154_radio_s *at86rf23x_init(FAR struct spi_dev_s *spi, - FAR const struct at86rf23x_lower_s *lower); +FAR struct ieee802154_radio_s * + at86rf23x_init(FAR struct spi_dev_s *spi, + FAR const struct at86rf23x_lower_s *lower); #undef EXTERN #ifdef __cplusplus diff --git a/include/nuttx/wireless/ieee802154/ieee802154_radio.h b/include/nuttx/wireless/ieee802154/ieee802154_radio.h index 7adbbfd7ae8..3e64aa5c603 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_radio.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_radio.h @@ -170,6 +170,28 @@ extern "C" * Public Function Prototypes ****************************************************************************/ +/**************************************************************************** + * Name: radio802154dev_register + * + * Description: + * Register a character driver to access the IEEE 802.15.4 radio from + * user-space + * + * Input Parameters: + * radio - Pointer to the radio struct to be registerd. + * devname - The name of the IEEE 802.15.4 radio to be registered. + * + * Returned Values: + * Zero (OK) is returned on success. Otherwise a negated errno value is + * returned to indicate the nature of the failure. + * + ****************************************************************************/ + +#ifdef CONFIG_IEEE802154_DEV +int radio802154dev_register(FAR struct ieee802154_radio_s *radio, + FAR char *devname); +#endif + #undef EXTERN #ifdef __cplusplus } diff --git a/wireless/ieee802154/radio802154_device.c b/wireless/ieee802154/radio802154_device.c index feb4410465b..bdd1e07c813 100644 --- a/wireless/ieee802154/radio802154_device.c +++ b/wireless/ieee802154/radio802154_device.c @@ -466,6 +466,10 @@ static int radio802154dev_ioctl(FAR struct file *filep, int cmd, return ret; } +/**************************************************************************** + * Public Functions + ****************************************************************************/ + /**************************************************************************** * Name: radio802154dev_register * From 9e4052e506f863904bc6c5d9a282a94da105f4d6 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 23 Mar 2017 07:20:10 -0600 Subject: [PATCH 017/183] 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 99ad2faa06d..8d28c548548 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 0cddb694bf7..3e0200e7a3d 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 3de16fb374e..cfa199d54b6 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 bdd1e07c813..2bab563e5b5 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; From 23b472f907ddae042cc771bba5167ab17793d859 Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Wed, 22 Mar 2017 14:13:28 -0400 Subject: [PATCH 018/183] wireless/ieee802154: Removes unused ieee802154.h header --- .../nuttx/wireless/ieee802154/ieee802154.h | 62 ------------------- 1 file changed, 62 deletions(-) delete mode 100644 include/nuttx/wireless/ieee802154/ieee802154.h diff --git a/include/nuttx/wireless/ieee802154/ieee802154.h b/include/nuttx/wireless/ieee802154/ieee802154.h deleted file mode 100644 index 02119404145..00000000000 --- a/include/nuttx/wireless/ieee802154/ieee802154.h +++ /dev/null @@ -1,62 +0,0 @@ -/**************************************************************************** - * include/nuttx/net/ieee802154.h - * - * Copyright (C) 2016 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Includes some definitions that a compatible with the LGPL GNU C Library - * header file of the same name. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -#ifndef __INCLUDE_NUTTX_WIRELESS_IEEE802154_IEEE802154_H -#define __INCLUDE_NUTTX_WIRELESS_IEEE802154_IEEE802154_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include - -/**************************************************************************** - * Public Type Definitions - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -#endif /* __INCLUDE_NUTTX_WIRELESS_IEEE802154_IEEE802154_H */ From 0658f26a18585a3ddd40759f383bf77a5f55aa97 Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Thu, 23 Mar 2017 14:00:45 -0400 Subject: [PATCH 019/183] wireless/ieee802154: Moves common types to ieee802154.h Since the MAC layer or the PHY radio layer can be accessed independently, common types that are used in both layers should go in a common ieee802154.h file --- .../nuttx/wireless/ieee802154/ieee802154.h | 106 ++++++++++++++++++ .../wireless/ieee802154/ieee802154_mac.h | 23 ---- 2 files changed, 106 insertions(+), 23 deletions(-) create mode 100644 include/nuttx/wireless/ieee802154/ieee802154.h diff --git a/include/nuttx/wireless/ieee802154/ieee802154.h b/include/nuttx/wireless/ieee802154/ieee802154.h new file mode 100644 index 00000000000..1866b9db028 --- /dev/null +++ b/include/nuttx/wireless/ieee802154/ieee802154.h @@ -0,0 +1,106 @@ +/**************************************************************************** + * include/nuttx/wireless/ieee802154/ieee802154.h + * + * Copyright (C) 2014-2016 Sebastien Lorquet. All rights reserved. + * Copyright (C) 2017 Verge Inc. All rights reserved. + * Author: Sebastien Lorquet + * Author: Anthony Merlino + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_WIRELESS_IEEE802154_IEEE802154_H +#define __INCLUDE_NUTTX_WIRELESS_IEEE802154_IEEE802154_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +struct ieee802154_packet_s +{ + uint8_t len; + uint8_t data[127]; + uint8_t lqi; + uint8_t rssi; +}; + +/* IEEE 802.15.4 Device address + * The addresses in ieee802154 have several formats: + * No address : [none] + * Short address + PAN id : PPPP/SSSS + * Extended address + PAN id : PPPP/LLLLLLLLLLLLLLLL + */ + +struct ieee802154_addr_s +{ + uint8_t ia_len; /* structure length, 0/2/8 */ + uint16_t ia_panid; /* PAN identifier, can be IEEE802154_PAN_UNSPEC */ + union + { + uint16_t _ia_saddr; /* short address */ + uint8_t _ia_eaddr[8]; /* extended address */ + } ia_addr; + +#define ia_saddr ia_addr._ia_saddr +#define ia_eaddr ia_addr._ia_eaddr +}; + +#define IEEE802154_ADDRSTRLEN 22 /* (2*2+1+8*2, PPPP/EEEEEEEEEEEEEEEE) */ + + +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* __INCLUDE_NUTTX_WIRELESS_IEEE802154_IEEE802154_H*/ diff --git a/include/nuttx/wireless/ieee802154/ieee802154_mac.h b/include/nuttx/wireless/ieee802154/ieee802154_mac.h index 3e0200e7a3d..d39aa887cbb 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_mac.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_mac.h @@ -161,29 +161,6 @@ enum * Public Types ****************************************************************************/ -/* IEEE 802.15.4 Device address - * The addresses in ieee802154 have several formats: - * No address : [none] - * Short address + PAN id : PPPP/SSSS - * Extended address + PAN id : PPPP/LLLLLLLLLLLLLLLL - */ - -struct ieee802154_addr_s -{ - uint8_t ia_len; /* structure length, 0/2/8 */ - uint16_t ia_panid; /* PAN identifier, can be IEEE802154_PAN_UNSPEC */ - union - { - uint16_t _ia_saddr; /* short address */ - uint8_t _ia_eaddr[8]; /* extended address */ - } ia_addr; - -#define ia_saddr ia_addr._ia_saddr -#define ia_eaddr ia_addr._ia_eaddr -}; - -#define IEEE802154_ADDRSTRLEN 22 /* (2*2+1+8*2, PPPP/EEEEEEEEEEEEEEEE) */ - /* Operations */ struct ieee802154_mac_s; /* Forward reference */ From 2150619d370a44837e8ce6d3bbfdb0196075d755 Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Thu, 23 Mar 2017 14:04:06 -0400 Subject: [PATCH 020/183] fs/ioctl.h: Renames RAD802154 to PHY802154 --- include/nuttx/fs/ioctl.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/nuttx/fs/ioctl.h b/include/nuttx/fs/ioctl.h index df69f56af17..4f6bab1aa15 100644 --- a/include/nuttx/fs/ioctl.h +++ b/include/nuttx/fs/ioctl.h @@ -87,7 +87,7 @@ #define _GPIOBASE (0x2200) /* GPIO driver commands */ #define _CLIOCBASE (0x2300) /* Contactless modules ioctl commands */ #define _MAC802154BASE (0x2400) /* 802.15.4 MAC ioctl commands */ -#define _RAD802154BASE (0x2500) /* 802.15.4 Radio ioctl commands */ +#define _PHY802154BASE (0x2500) /* 802.15.4 Radio ioctl commands */ /* boardctl() commands share the same number space */ @@ -412,8 +412,8 @@ /* 802.15.4 Radio driver ioctl definitions *******************************************/ /* (see nuttx/ieee802154/wireless/ieee802154_radio.h */ -#define _RAD802154IOCVALID(c) (_IOC_TYPE(c)==_RADIO802154BASE) -#define _RAD802154IOC(nr) _IOC(_RADIO802154BASE,nr) +#define _PHY802154IOCVALID(c) (_IOC_TYPE(c)==_PHY802154BASE) +#define _PHY802154IOC(nr) _IOC(_PHY802154BASE,nr) /* boardctl() command definitions *******************************************/ From f5926bd3305282c88e5e0f7f1f5ef4b6905518e0 Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Fri, 24 Mar 2017 11:06:18 -0400 Subject: [PATCH 021/183] wireless/ieee802154: Adds ieee802154_addr_mode_e enumeration --- include/nuttx/wireless/ieee802154/ieee802154.h | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/include/nuttx/wireless/ieee802154/ieee802154.h b/include/nuttx/wireless/ieee802154/ieee802154.h index 1866b9db028..1b89748c1dd 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154.h +++ b/include/nuttx/wireless/ieee802154/ieee802154.h @@ -69,14 +69,20 @@ struct ieee802154_packet_s * Extended address + PAN id : PPPP/LLLLLLLLLLLLLLLL */ +enum ieee802154_addr_mode_e { + IEEE802154_ADDRMODE_NONE = 0, + IEEE802154_ADDRMODE_SHORT = 2, + IEEE802154_ADDRMODE_EXTENDED +}; + struct ieee802154_addr_s { - uint8_t ia_len; /* structure length, 0/2/8 */ - uint16_t ia_panid; /* PAN identifier, can be IEEE802154_PAN_UNSPEC */ + enum ieee802154_addr_mode_e ia_mode; /* Address mode. Short or Extended */ + uint16_t ia_panid; /* PAN identifier, can be IEEE802154_PAN_UNSPEC */ union { - uint16_t _ia_saddr; /* short address */ - uint8_t _ia_eaddr[8]; /* extended address */ + uint16_t _ia_saddr; /* short address */ + uint8_t _ia_eaddr[8]; /* extended address */ } ia_addr; #define ia_saddr ia_addr._ia_saddr @@ -85,7 +91,6 @@ struct ieee802154_addr_s #define IEEE802154_ADDRSTRLEN 22 /* (2*2+1+8*2, PPPP/EEEEEEEEEEEEEEEE) */ - #ifdef __cplusplus #define EXTERN extern "C" extern "C" From a702d6b6381c0e6c1b5aa137d45f369713197eea Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Fri, 24 Mar 2017 11:06:59 -0400 Subject: [PATCH 022/183] wireless/ieee802154: Fixes build and configuration setup --- wireless/ieee802154/Kconfig | 6 +++--- wireless/ieee802154/Make.defs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/wireless/ieee802154/Kconfig b/wireless/ieee802154/Kconfig index 638f887cab6..770bbe03819 100644 --- a/wireless/ieee802154/Kconfig +++ b/wireless/ieee802154/Kconfig @@ -10,12 +10,12 @@ config WIRELESS_IEEE802154 ---help--- Enables support for the IEEE 802.14.5 Wireless library. -if IEEE802154 +if WIRELESS_IEEE802154 config IEEE802154_MAC bool "Generic Media Access Control layer for 802.15.4 radios" default n - depends on IEEE802154 + depends on WIRELESS_IEEE802154 ---help--- Enables a Media Access Controller for any IEEE802.15.4 radio device. This in turn can be used by higher layer entities @@ -25,7 +25,7 @@ config IEEE802154_MAC config IEEE802154_DEV bool "Debug character driver for ieee802.15.4 radio interfaces" default n - depends on IEEE802154 + depends on WIRELESS_IEEE802154 ---help--- Enables a device driver to expose ieee802.15.4 radio controls to user space as IOCTLs. diff --git a/wireless/ieee802154/Make.defs b/wireless/ieee802154/Make.defs index 42856a85abf..5d54b0004d6 100644 --- a/wireless/ieee802154/Make.defs +++ b/wireless/ieee802154/Make.defs @@ -45,7 +45,7 @@ CSRCS += ieee802154/mac802154.c endif ifeq ($(CONFIG_IEEE802154_DEV),y) -CSRCS += ieee802154/ieee802154_device.c +CSRCS += ieee802154/radio802154_device.c endif DEPPATH += --dep-path wireless/ieee802154 From 7a95cc62b4dc8a42c5b81c226bedc80d3577f475 Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Fri, 24 Mar 2017 11:08:31 -0400 Subject: [PATCH 023/183] wireless/ieee802154: Moves and renames MAC preprocessor definitions --- .../wireless/ieee802154/ieee802154_mac.h | 452 ++++++++++++++---- wireless/ieee802154/mac802154.c | 20 +- 2 files changed, 370 insertions(+), 102 deletions(-) diff --git a/include/nuttx/wireless/ieee802154/ieee802154_mac.h b/include/nuttx/wireless/ieee802154/ieee802154_mac.h index d39aa887cbb..992b03e0e8a 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_mac.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_mac.h @@ -41,9 +41,13 @@ ****************************************************************************/ #include + #include #include +#include +#include + /**************************************************************************** * Pre-Processor Definitions ****************************************************************************/ @@ -51,8 +55,63 @@ /* Configuration ************************************************************/ /* None at the moment */ + +/* IEEE 802.15.4 MAC Character Driver IOCTL Commands ************************/ + +/* The IEEE 802.15.4 standard specifies a MLME Service Access Point (SAP) + * including a series of primitives that are used as an interface between + * the MLME and the next highest layer. There are 4 types of primitives: + * - Request + * - Indication + * - Response + * - Confirm + * + * Of these, Request and Response primitives are sent from the next highest layer + * to the MLME. Indication and Confirm primitives are used to notify the next + * highest layer of changes or actions that have taken place. + * + * The MAC802154 character driver exposed here provides IOCTL hooks for all + * Request and Response primitives. + */ + +#define MAC802154IOC_MLME_ASSOC_REQUEST _MAC802154IOC(0x0001) +#define MAC802154IOC_MLME_ASSOC_RESPONSE _MAC802154IOC(0x0002) +#define MAC802154IOC_MLME_DISASSOC_REQUEST _MAC802154IOC(0x0003) +#define MAC802154IOC_MLME_GET_REQUEST _MAC802154IOC(0x0004) +#define MAC802154IOC_MLME_GTS_REQUEST _MAC802154IOC(0x0005) +#define MAC802154IOC_MLME_ORPHAN_RESPONSE _MAC802154IOC(0x0006) +#define MAC802154IOC_MLME_RESET_REQUEST _MAC802154IOC(0x0007) +#define MAC802154IOC_MLME_RXENABLE_REQUEST _MAC802154IOC(0x0008) +#define MAC802154IOC_MLME_SCAN_REQUEST _MAC802154IOC(0x0009) +#define MAC802154IOC_MLME_SET_REQUEST _MAC802154IOC(0x000A) +#define MAC802154IOC_MLME_START_REQUEST _MAC802154IOC(0x000B) +#define MAC802154IOC_MLME_SYNC_REQUEST _MAC802154IOC(0x000C) +#define MAC802154IOC_MLME_POLL_REQUEST _MAC802154IOC(0x000D) +#define MAC802154IOC_MLME_DPS_REQUEST _MAC802154IOC(0x000E) +#define MAC802154IOC_MLME_SOUNDING_REQUEST _MAC802154IOC(0x000F) +#define MAC802154IOC_MLME_CALIBRATE_REQUEST _MAC802154IOC(0x0010) + /* IEEE 802.15.4 MAC Interface **********************************************/ +/* Frame Type */ + +#define IEEE802154_FRAME_BEACON 0x00 +#define IEEE802154_FRAME_DATA 0x01 +#define IEEE802154_FRAME_ACK 0x02 +#define IEEE802154_FRAME_COMMAND 0x03 + +/* MAC commands */ + +#define IEEE802154_CMD_ASSOC_REQ 0x01 +#define IEEE802154_CMD_ASSOC_RSP 0x02 +#define IEEE802154_CMD_DISASSOC_NOT 0x03 +#define IEEE802154_CMD_DATA_REQ 0x04 +#define IEEE802154_CMD_PANID_CONF_NOT 0x05 +#define IEEE802154_CMD_ORPHAN_NOT 0x06 +#define IEEE802154_CMD_BEACON_REQ 0x07 +#define IEEE802154_CMD_COORD_REALIGN 0x08 +#define IEEE802154_CMD_GTS_REQ 0x09 + /* Some addresses */ #define IEEE802154_PAN_UNSPEC (uint16_t)0xFFFF @@ -60,31 +119,53 @@ #define IEEE802154_SADDR_BCAST (uint16_t)0xFFFE #define IEEE802154_EADDR_UNSPEC (uint8_t*)"\xff\xff\xff\xff\xff\xff\xff\xff" +/* Frame control field masks, 2 bytes + * Seee IEEE 802.15.4/2011 5.2.1.1 page 57 + */ + +#define IEEE802154_FRAMECTRL_FTYPE 0x0007 /* Frame type, bits 0-2 */ +#define IEEE802154_FRAMECTRL_SEC 0x0008 /* Security Enabled, bit 3 */ +#define IEEE802154_FRAMECTRL_PEND 0x0010 /* Frame pending, bit 4 */ +#define IEEE802154_FRAMECTRL_ACKREQ 0x0020 /* Acknowledge request, bit 5 */ +#define IEEE802154_FRAMECTRL_INTRA 0x0040 /* Intra PAN, bit 6 */ +#define IEEE802154_FRAMECTRL_DADDR 0x0C00 /* Dest addressing mode, bits 10-11 */ +#define IEEE802154_FRAMECTRL_VERSION 0x3000 /* Source addressing mode, bits 12-13 */ +#define IEEE802154_FRAMECTRL_SADDR 0xC000 /* Source addressing mode, bits 14-15 */ + +#define IEEE802154_FRAMECTRL_SHIFT_FTYPE 0 /* Frame type, bits 0-2 */ +#define IEEE802154_FRAMECTRL_SHIFT_SEC 3 /* Security Enabled, bit 3 */ +#define IEEE802154_FRAMECTRL_SHIFT_PEND 4 /* Frame pending, bit 4 */ +#define IEEE802154_FRAMECTRL_SHIFT_ACKREQ 5 /* Acknowledge request, bit 5 */ +#define IEEE802154_FRAMECTRL_SHIFT_INTRA 6 /* Intra PAN, bit 6 */ +#define IEEE802154_FRAMECTRL_SHIFT_DADDR 10 /* Dest addressing mode, bits 10-11 */ +#define IEEE802154_FRAMECTRL_SHIFT_VERSION 12 /* Source addressing mode, bits 12-13 */ +#define IEEE802154_FRAMECTRL_SHIFT_SADDR 14 /* Source addressing mode, bits 14-15 */ + /* IEEE 802.15.4 PHY constants */ -#define MAC802154_aMaxPHYPacketSize 127 -#define MAC802154_aTurnaroundTime 12 /*symbol periods*/ +#define IEEE802154_aMaxPHYPacketSize 127 +#define IEEE802154_aTurnaroundTime 12 /*symbol periods*/ /* IEEE 802.15.4 MAC constants */ -#define MAC802154_aBaseSlotDuration 60 -#define MAC802154_aNumSuperframeSlots 16 -#define MAC802154_aBaseSuperframeDuration (MAC802154_aBaseSlotDuration * MAC802154_aNumSuperframeSlots) -#define MAC802154_aMaxBE 5 -#define MAC802154_aMaxBeaconOverhead 75 -#define MAC802154_aMaxBeaconPayloadLength (MAC802154_aMaxPHYPacketSize - MAC802154_aMaxBeaconOverhead) -#define MAC802154_aGTSDescPersistenceTime 4 -#define MAC802154_aMaxFrameOverhead 25 -#define MAC802154_aMaxFrameResponseTime 1220 -#define MAC802154_aMaxFrameRetries 3 -#define MAC802154_aMaxLostBeacons 4 -#define MAC802154_aMaxMACFrameSize (MAC802154_aMaxPHYPacketSize - MAC802154_aMaxFrameOverhead) -#define MAC802154_aMaxSIFSFrameSize 18 -#define MAC802154_aMinCAPLength 440 -#define MAC802154_aMinLIFSPeriod 40 -#define MAC802154_aMinSIFSPeriod 12 -#define MAC802154_aResponseWaitTime (32 * MAC802154_aBaseSuperframeDuration) -#define MAC802154_aUnitBackoffPeriod 20 +#define IEEE802154_aBaseSlotDuration 60 +#define IEEE802154_aNumSuperframeSlots 16 +#define IEEE802154_aBaseSuperframeDuration (IEEE802154_aBaseSlotDuration * IEEE802154_aNumSuperframeSlots) +#define IEEE802154_aMaxBE 5 +#define IEEE802154_aMaxBeaconOverhead 75 +#define IEEE802154_aMaxBeaconPayloadLength (IEEE802154_aMaxPHYPacketSize - IEEE802154_aMaxBeaconOverhead) +#define IEEE802154_aGTSDescPersistenceTime 4 +#define IEEE802154_aMaxFrameOverhead 25 +#define IEEE802154_aMaxFrameResponseTime 1220 +#define IEEE802154_aMaxFrameRetries 3 +#define IEEE802154_aMaxLostBeacons 4 +#define IEEE802154_aMaxMACFrameSize (IEEE802154_aMaxPHYPacketSize - IEEE802154_aMaxFrameOverhead) +#define IEEE802154_aMaxSIFSFrameSize 18 +#define IEEE802154_aMinCAPLength 440 +#define IEEE802154_aMinLIFSPeriod 40 +#define IEEE802154_aMinSIFSPeriod 12 +#define IEEE802154_aResponseWaitTime (32 * IEEE802154_aBaseSuperframeDuration) +#define IEEE802154_aUnitBackoffPeriod 20 /**************************************************************************** * Public Types @@ -92,74 +173,279 @@ /* IEEE 802.15.4 MAC status codes */ -enum +enum ieee802154_status_e { - MAC802154_STATUS_OK = 0, - MAC802154_STATUS_BEACON_LOSS = 0xE0, - MAC802154_STATUS_CHANNEL_ACCESS_FAILURE, - MAC802154_STATUS_DENIED, - MAC802154_STATUS_DISABLE_TRX_FAILURE, - MAC802154_STATUS_FAILED_SECURITY_CHECK, - MAC802154_STATUS_FRAME_TOO_LONG, - MAC802154_STATUS_INVALID_GTS, - MAC802154_STATUS_INVALID_HANDLE, - MAC802154_STATUS_INVALID_PARAMETER, - MAC802154_STATUS_NO_ACK, - MAC802154_STATUS_NO_BEACON, - MAC802154_STATUS_NO_DATA, - MAC802154_STATUS_NO_SHORT_ADDRESS, - MAC802154_STATUS_OUT_OF_CAP, - MAC802154_STATUS_PAN_ID_CONFLICT, - MAC802154_STATUS_REALIGNMENT, - MAC802154_STATUS_TRANSACTION_EXPIRED, - MAC802154_STATUS_TRANSACTION_OVERFLOW, - MAC802154_STATUS_TX_ACTIVE, - MAC802154_STATUS_UNAVAILABLE_KEY, - MAC802154_STATUS_UNSUPPORTED_ATTRIBUTE + IEEE802154_STATUS_OK = 0, + IEEE802154_STATUS_BEACON_LOSS = 0xE0, + IEEE802154_STATUS_CHANNEL_ACCESS_FAILURE, + IEEE802154_STATUS_DENIED, + IEEE802154_STATUS_DISABLE_TRX_FAILURE, + IEEE802154_STATUS_FAILED_SECURITY_CHECK, + IEEE802154_STATUS_FRAME_TOO_LONG, + IEEE802154_STATUS_INVALID_GTS, + IEEE802154_STATUS_INVALID_HANDLE, + IEEE802154_STATUS_INVALID_PARAMETER, + IEEE802154_STATUS_NO_ACK, + IEEE802154_STATUS_NO_BEACON, + IEEE802154_STATUS_NO_DATA, + IEEE802154_STATUS_NO_SHORT_ADDRESS, + IEEE802154_STATUS_OUT_OF_CAP, + IEEE802154_STATUS_PAN_ID_CONFLICT, + IEEE802154_STATUS_REALIGNMENT, + IEEE802154_STATUS_TRANSACTION_EXPIRED, + IEEE802154_STATUS_TRANSACTION_OVERFLOW, + IEEE802154_STATUS_TX_ACTIVE, + IEEE802154_STATUS_UNAVAILABLE_KEY, + IEEE802154_STATUS_UNSUPPORTED_ATTRIBUTE }; /* IEEE 802.15.4 PHY/MAC PIB attributes IDs */ enum { - MAC802154_phyCurrentChannel = 0x00, - MAC802154_phyChannelsSupported, - MAC802154_phyTransmitPower, - MAC802154_phyCCAMode, - MAC802154_macAckWaitDuration = 0x40, - MAC802154_macAssociationPermit, - MAC802154_macAutoRequest, - MAC802154_macBattLifeExt, - MAC802154_macBattLifeExtPeriods, - MAC802154_macBeaconPayload, - MAC802154_macBeaconPayloadLength, - MAC802154_macBeaconOrder, - MAC802154_macBeaconTxTime, - MAC802154_macBSN, - MAC802154_macCoordExtendedAddress, - MAC802154_macCoordShortAddress, - MAC802154_macDSN, - MAC802154_macGTSPermit, - MAC802154_macMaxCSMABackoffs, - MAC802154_macMinBE, - MAC802154_macPANId, - MAC802154_macPromiscuousMode, - MAC802154_macRxOnWhenIdle, - MAC802154_macShortAddress, - MAC802154_macSuperframeOrder, - MAC802154_macTransactionPersistenceTime, - MAC802154_macACLEntryDescriptorSet = 0x70, - MAC802154_macACLEntryDescriptorSetSize, - MAC802154_macDefaultSecurity, - MAC802154_macDefaultSecurityMaterialLength, - MAC802154_macDefaultSecurityMaterial, - MAC802154_macDefaultSecuritySuite, - MAC802154_macSecurityMode + IEEE802154_phyCurrentChannel = 0x00, + IEEE802154_phyChannelsSupported, + IEEE802154_phyTransmitPower, + IEEE802154_phyCCAMode, + IEEE802154_macAckWaitDuration = 0x40, + IEEE802154_macAssociationPermit, + IEEE802154_macAutoRequest, + IEEE802154_macBattLifeExt, + IEEE802154_macBattLifeExtPeriods, + IEEE802154_macBeaconPayload, + IEEE802154_macBeaconPayloadLength, + IEEE802154_macBeaconOrder, + IEEE802154_macBeaconTxTime, + IEEE802154_macBSN, + IEEE802154_macCoordExtendedAddress, + IEEE802154_macCoordShortAddress, + IEEE802154_macDSN, + IEEE802154_macGTSPermit, + IEEE802154_macMaxCSMABackoffs, + IEEE802154_macMinBE, + IEEE802154_macPANId, + IEEE802154_macPromiscuousMode, + IEEE802154_macRxOnWhenIdle, + IEEE802154_macShortAddress, + IEEE802154_macSuperframeOrder, + IEEE802154_macTransactionPersistenceTime, + IEEE802154_macACLEntryDescriptorSet = 0x70, + IEEE802154_macACLEntryDescriptorSetSize, + IEEE802154_macDefaultSecurity, + IEEE802154_macDefaultSecurityMaterialLength, + IEEE802154_macDefaultSecurityMaterial, + IEEE802154_macDefaultSecuritySuite, + IEEE802154_macSecurityMode }; -/**************************************************************************** - * Public Types - ****************************************************************************/ +struct ieee802154_capability_info_s +{ + uint8_t reserved_0 : 1; /* Reserved */ + uint8_t device_type : 1; /* 0=RFD, 1=FFD */ + uint8_t power_source : 1; /* 1=AC, 0=Other */ + uint8_t rx_on_idle : 1; /* 0=Receiver off when idle + * 1=Receiver on when idle */ + uint8_t reserved_45 : 2; /* Reserved */ + uint8_t security : 1; /* 0=disabled, 1=enabled */ + uint8_t allocate_addr : 1; /* 1=Coordinator allocates short address + * 0=otherwise */ +}; + +#ifdef CONFIG_IEEE802154_SECURITY +struct ieee802154_security_s +{ + uint8_t level; /* Security level to be used */ + uint8_t key_id_mode; /* Mode used to identify the key to be used */ + uint8_t key_source[8]; /* Originator of the key to be used */ + uint8_t key_index; /* Index of the key to be used */ +}; +#endif + +struct ieee802154_superframe_spec_s +{ + uint16_t beacon_order : 4; /* Transmission interval of beacon */ + uint16_t superframe_order : 4; /* Length of superframe */ + uint16_t final_cap_slot : 4; /* Last slot utilized by CAP */ + uint16_t ble : 1; /* Battery Life Extension (BLE) */ + uint16_t reserved : 1; /* Reserved bit */ + uint16_t pan_coordinator : 1; /* 1 if beacon sent by pan coordinator */ + uint16_t assoc_permit : 1; /* 1 if coordinator is accepting associaton */ +}; + +struct ieee802154_pan_desc_s +{ + /* The coordinator address of the received beacon frame */ + + struct ieee802154_addr_s coord_addr; + + uint8_t channel; /* current channel occupied by the network */ + uint8_t channel_page; /* current channel page occupied by the network */ + + /* The superframe specifications received in the beacon frame */ + + struct ieee802154_superframe_spec_s superframe_spec; + + uint8_t gts_permit; /* 0=No GTS requests allowed + * 1=GTS request allowed */ + uint8_t link_quality; /* LQI at which beacon was received */ + uint32_t timestamp; /* Time at which the beacon frame was received + * in symbols */ +}; + +struct ieee802154_pend_addr_s +{ + union { + uint8_t pa_spec; + struct { + uint8_t num_short_addr : 3; /* Number of short addresses pending */ + uint8_t reserved_3 : 1; /* Reserved bit */ + uint8_t num_ext_addr : 3; /* Number of extended addresses pending */ + uint8_t reserved_7 : 1; /* Reserved bit */ + }; + }; + struct ieee802154_addr_s addr[7]; /* Array of at most 7 addresses */ +}; + +/* Primitive Semantics */ + +struct ieee802154_assoc_request_s +{ + uint8_t channel; /* Channel number to attempt association */ + uint8_t channel_page; /* Channel page to attempt association */ + + /* Coordinator Address with which to associate */ + + struct ieee802154_addr_s coord_addr; + + /* Capabilities of associating device */ + + struct ieee802154_capability_info_s capabilities; + +#ifdef CONFIG_IEEE802154_SECURITY + /* Security information if enabled */ + + struct ieee802154_security_s security; +#endif +}; + +struct ieee802154_assoc_indication_s +{ + /* Address of device requesting association. Always in extended mode */ + + struct ieee802154_addr_s dev_addr; + + /* Capabilities of associating device */ + + struct ieee802154_capability_info_s capabilities; + +#ifdef CONFIG_IEEE802154_SECURITY + /* Security information if enabled */ + + struct ieee802154_security_s security; +#endif +}; + +struct ieee802154_assoc_response_s +{ + /* Address of device requesting association. Always in extended mode */ + + struct ieee802154_addr_s dev_addr; + + /* Status of association attempt */ + + enum ieee802154_status_e status; + +#ifdef CONFIG_IEEE802154_SECURITY + /* Security information if enabled */ + + struct ieee802154_security_s security; +#endif +}; + +struct ieee802154_assoc_confirm_s +{ + /* Associated device address ALWAYS passed in short address mode. The + * address will be IEEE802154_SADDR_UNSPEC if association was unsuccessful */ + + struct ieee802154_addr_s dev_addr; + + /* Status of association attempt */ + + enum ieee802154_status_e status; + +#ifdef CONFIG_IEEE802154_SECURITY + /* Security information if enabled */ + + struct ieee802154_security_s security; +#endif +}; + +struct ieee802154_disassoc_request_s +{ + /* Address of device to send disassociation notification */ + + struct ieee802154_addr_s dev_addr; + + /* Reason for the disassosiation */ + + enum ieee802154_status_e disassoc_reason; + + uint8_t tx_indirect; /* 0=Send Direct, 1=Send Indirect */ + +#ifdef CONFIG_IEEE802154_SECURITY + /* Security information if enabled */ + + struct ieee802154_security_s security; +#endif +}; + +struct ieee802154_disassoc_indication_s +{ + /* Address of device requesting disassociation. Always extended mode */ + + struct ieee802154_addr_s dev_addr; + + /* Reason for the disassosiation */ + + enum ieee802154_status_e disassoc_reason; + +#ifdef CONFIG_IEEE802154_SECURITY + /* Security information if enabled */ + + struct ieee802154_security_s security; +#endif +}; + +struct ieee802154_disassoc_confirm_s +{ + /* Status of the disassociation attempt */ + + enum ieee802154_status_e status; + + /* Address of device either requesting or being intructed to disassociate */ + + struct ieee802154_addr_s dev_addr; +}; + +struct ieee802154_beaconnotify_indication_s +{ + uint8_t bsn; /* Beacon sequence number */ + + /* PAN descriptor for the received beacon */ + + struct ieee802154_pan_desc_s pan_desc; + + /* Beacon pending addresses */ + + struct ieee802154_pend_addr_s pend_addr; + + uint8_t sdu_length; /* Number of octets contained in the beacon + * payload of the received beacond frame */ + + /* Beacon payload */ + + uint8_t sdu[IEEE802154_aMaxBeaconPayloadLength]; +}; /* Operations */ @@ -180,13 +466,13 @@ struct ieee802154_macops_s /* Start association with coordinator */ - CODE int (*req_associate)(FAR struct ieee802154_mac_s *mac, uint16_t panid, - uint8_t *coordeadr); + CODE int (*req_associate)(FAR struct ieee802154_mac_s *mac, + FAR struct ieee802154_assoc_request_s *request); /* Start disassociation with coordinator */ CODE int (*req_disassociate)(FAR struct ieee802154_mac_s *mac, - FAR uint8_t *eadr, uint8_t reason); + FAR struct ieee802154_disassoc_request_s *request); /* Read the PIB */ @@ -314,7 +600,7 @@ struct ieee802154_maccb_s /* Beacon notification */ CODE int (*ind_beaconnotify)(FAR struct ieee802154_mac_s *mac, - FAR uint8_t *bsn, FAR uint_t *pandesc, + FAR uint8_t *bsn, FAR struct ieee802154_pan_desc_s *pandesc, FAR uint8_t *sdu, int sdulen); /* GTS management request received */ diff --git a/wireless/ieee802154/mac802154.c b/wireless/ieee802154/mac802154.c index cfa199d54b6..da4a7119104 100644 --- a/wireless/ieee802154/mac802154.c +++ b/wireless/ieee802154/mac802154.c @@ -48,24 +48,6 @@ * Pre-processor Definitions ****************************************************************************/ -/* Frame Type */ - -#define IEEE802154_FRAME_BEACON 0x00 -#define IEEE802154_FRAME_DATA 0x01 -#define IEEE802154_FRAME_ACK 0x02 -#define IEEE802154_FRAME_COMMAND 0x03 - -/* MAC commands */ - -#define IEEE802154_CMD_ASSOC_REQ 0x01 -#define IEEE802154_CMD_ASSOC_RSP 0x02 -#define IEEE802154_CMD_DIS_NOT 0x03 -#define IEEE802154_CMD_DATA_REQ 0x04 -#define IEEE802154_CMD_PANID_CONF_NOT 0x05 -#define IEEE802154_CMD_ORPHAN_NOT 0x06 -#define IEEE802154_CMD_BEACON_REQ 0x07 -#define IEEE802154_CMD_COORD_REALIGN 0x08 -#define IEEE802154_CMD_GTS_REQ 0x09 /**************************************************************************** * Private Types @@ -97,7 +79,7 @@ struct ieee802154_privmac_s uint32_t macPad : 3; /* 0x48 */ uint32_t macBeaconTxTime : 24; - /* 0x45 */ uint8_t macBeaconPayload[MAC802154_aMaxBeaconPayloadLength]; + /* 0x45 */ uint8_t macBeaconPayload[IEEE802154_aMaxBeaconPayloadLength]; /* 0x46 */ uint8_t macBeaconPayloadLength; /* 0x49 */ uint8_t macBSN; /* 0x4A */ uint8_t macCoordExtendedAddress[8]; From 10d7baca10a98805f6c0388023239747930e2861 Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Fri, 24 Mar 2017 11:09:18 -0400 Subject: [PATCH 024/183] wireless/ieee802154: Adds IOCTL definitions for accessing PHY layer --- .../wireless/ieee802154/ieee802154_radio.h | 40 +++++++++++++++---- wireless/ieee802154/radio802154_device.c | 37 +++++++++-------- 2 files changed, 50 insertions(+), 27 deletions(-) diff --git a/include/nuttx/wireless/ieee802154/ieee802154_radio.h b/include/nuttx/wireless/ieee802154/ieee802154_radio.h index 3e64aa5c603..f87c2010c2f 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_radio.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_radio.h @@ -2,7 +2,9 @@ * include/nuttx/wireless/ieee802154/ieee802154_radio.h * * Copyright (C) 2014-2016 Sebastien Lorquet. All rights reserved. + * Copyright (C) 2017 Verge Inc. All rights reserved. * Author: Sebastien Lorquet + * Author: Anthony Merlino * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -44,6 +46,8 @@ #include #include #include +#include +#include /**************************************************************************** * Pre-Processor Definitions @@ -62,18 +66,38 @@ #define IEEE802154_MODE_COORD 0x01 /* avail in mrf24j40, but why? */ #define IEEE802154_MODE_PANCOORD 0x02 +/* IEEE 802.15.4 Radio Character Driver IOCTL ********************************/ + +#define PHY802154IOC_SET_CHAN _PHY802154IOC(0x0001) +#define PHY802154IOC_GET_CHAN _PHY802154IOC(0x0002) + +#define PHY802154IOC_SET_PANID _PHY802154IOC(0x0003) +#define PHY802154IOC_GET_PANID _PHY802154IOC(0x0004) + +#define PHY802154IOC_SET_SADDR _PHY802154IOC(0x0005) +#define PHY802154IOC_GET_SADDR _PHY802154IOC(0x0006) + +#define PHY802154IOC_SET_EADDR _PHY802154IOC(0x0007) +#define PHY802154IOC_GET_EADDR _PHY802154IOC(0x0008) + +#define PHY802154IOC_SET_PROMISC _PHY802154IOC(0x0009) +#define PHY802154IOC_GET_PROMISC _PHY802154IOC(0x000A) + +#define PHY802154IOC_SET_DEVMODE _PHY802154IOC(0x000B) +#define PHY802154IOC_GET_DEVMODE _PHY802154IOC(0x000C) + +#define PHY802154IOC_SET_TXPWR _PHY802154IOC(0x000D) +#define PHY802154IOC_GET_TXPWR _PHY802154IOC(0x000E) + +#define PHY802154IOC_SET_CCA _PHY802154IOC(0x000F) +#define PHY802154IOC_GET_CCA _PHY802154IOC(0x0010) + +#define PHY802154IOC_ENERGYDETECT _PHY802154IOC(0x0011) + /**************************************************************************** * Public Types ****************************************************************************/ -struct ieee802154_packet_s -{ - uint8_t len; - uint8_t data[127]; - uint8_t lqi; - uint8_t rssi; -}; - struct ieee802154_cca_s { uint8_t use_ed : 1; /* CCA using ED */ diff --git a/wireless/ieee802154/radio802154_device.c b/wireless/ieee802154/radio802154_device.c index 2bab563e5b5..a3a4161ffc7 100644 --- a/wireless/ieee802154/radio802154_device.c +++ b/wireless/ieee802154/radio802154_device.c @@ -51,7 +51,6 @@ #include #include #include -#include /**************************************************************************** * Private Types @@ -383,78 +382,78 @@ static int radio802154dev_ioctl(FAR struct file *filep, int cmd, DEBUGASSERT(filep != NULL && filep->f_inode != NULL); inode = filep->f_inode; dev = inode->i_private; - DEBUGASSERT(dev != NULL && dev->child != NULL; + DEBUGASSERT(dev != NULL && dev->child != NULL); child = dev->child; /* Get exclusive access to the driver data structures */ switch (cmd) { - case MAC854IOCSCHAN: + case PHY802154IOC_SET_CHAN: ret = child->ops->setchannel(child, (uint8_t)arg); break; - case MAC854IOCGCHAN: + case PHY802154IOC_GET_CHAN: ret = child->ops->getchannel(child, (FAR uint8_t*)arg); break; - case MAC854IOCSPANID: + case PHY802154IOC_SET_PANID: ret = child->ops->setpanid(child, (uint16_t)arg); break; - case MAC854IOCGPANID: + case PHY802154IOC_GET_PANID: ret = child->ops->getpanid(child, (FAR uint16_t*)arg); break; - case MAC854IOCSSADDR: + case PHY802154IOC_SET_SADDR: ret = child->ops->setsaddr(child, (uint16_t)arg); break; - case MAC854IOCGSADDR: + case PHY802154IOC_GET_SADDR: ret = child->ops->getsaddr(child, (FAR uint16_t*)arg); break; - case MAC854IOCSEADDR: + case PHY802154IOC_SET_EADDR: ret = child->ops->seteaddr(child, (FAR uint8_t*)arg); break; - case MAC854IOCGEADDR: + case PHY802154IOC_GET_EADDR: ret = child->ops->geteaddr(child, (FAR uint8_t*)arg); break; - case MAC854IOCSPROMISC: + case PHY802154IOC_SET_PROMISC: ret = child->ops->setpromisc(child, (bool)arg); break; - case MAC854IOCGPROMISC: + case PHY802154IOC_GET_PROMISC: ret = child->ops->getpromisc(child, (FAR bool*)arg); break; - case MAC854IOCSDEVMODE: + case PHY802154IOC_SET_DEVMODE: ret = child->ops->setdevmode(child, (uint8_t)arg); break; - case MAC854IOCGDEVMODE: + case PHY802154IOC_GET_DEVMODE: ret = child->ops->getdevmode(child, (FAR uint8_t*)arg); break; - case MAC854IOCSTXP: + case PHY802154IOC_SET_TXPWR: ret = child->ops->settxpower(child, (int32_t)arg); break; - case MAC854IOCGTXP: + case PHY802154IOC_GET_TXPWR: ret = child->ops->gettxpower(child, (FAR int32_t*)arg); break; - case MAC854IOCSCCA: + case PHY802154IOC_SET_CCA: ret = child->ops->setcca(child, (FAR struct ieee802154_cca_s*)arg); break; - case MAC854IOCGCCA: + case PHY802154IOC_GET_CCA: ret = child->ops->getcca(child, (FAR struct ieee802154_cca_s*)arg); break; - case MAC854IOCGED: + case PHY802154IOC_ENERGYDETECT: ret = child->ops->energydetect(child, (FAR uint8_t*)arg); break; From 73888166293a42e3ee9e488671c7185cf8260adc Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Fri, 24 Mar 2017 11:10:35 -0400 Subject: [PATCH 025/183] drivers/ieee802154: Moves defines to MAC layer and adjusts some addressing functionality --- drivers/wireless/ieee802154/mrf24j40.c | 72 +++++--------------------- 1 file changed, 13 insertions(+), 59 deletions(-) diff --git a/drivers/wireless/ieee802154/mrf24j40.c b/drivers/wireless/ieee802154/mrf24j40.c index 4cb4ed99340..c4c353ce008 100644 --- a/drivers/wireless/ieee802154/mrf24j40.c +++ b/drivers/wireless/ieee802154/mrf24j40.c @@ -57,6 +57,7 @@ #include #include +#include #include "mrf24j40.h" @@ -92,44 +93,6 @@ #define MRF24J40_PA_ED 2 #define MRF24J40_PA_SLEEP 3 -/* IEEE 802.15.4 frame specifics */ - -/* Security Enabled */ - -#define IEEE802154_SEC_OFF 0x00 -#define IEEE802154_SEC_ON 0x08 - -/* Flags */ - -#define IEEE802154_PEND 0x10 -#define IEEE802154_ACK_REQ 0x20 -#define IEEE802154_INTRA 0x40 - -/* Dest Addressing modes */ - -#define IEEE802154_DADDR_NONE 0x00 -#define IEEE802154_DADDR_SHORT 0x08 -#define IEEE802154_DADDR_EXT 0x0A - -/* Src Addressing modes */ - -#define IEEE802154_SADDR_NONE 0x00 -#define IEEE802154_SADDR_SHORT 0x80 -#define IEEE802154_SADDR_EXT 0xA0 - -/* Frame control field masks, 2 bytes - * Seee IEEE 802.15.4/2003 7.2.1.1 page 112 - */ - -#define IEEE802154_FC1_FTYPE 0x03 /* Frame type, bits 0-2 */ -#define IEEE802154_FC1_SEC 0x08 /* Security Enabled, bit 3 */ -#define IEEE802154_FC1_PEND 0x10 /* Frame pending, bit 4 */ -#define IEEE802154_FC1_ACKREQ 0x20 /* Acknowledge request, bit 5 */ -#define IEEE802154_FC1_INTRA 0x40 /* Intra PAN, bit 6 */ -#define IEEE802154_FC2_DADDR 0x0C /* Dest addressing mode, bits 10-11 */ -#define IEEE802154_FC2_VERSION 0x30 /* Source addressing mode, bits 12-13 */ -#define IEEE802154_FC2_SADDR 0xC0 /* Source addressing mode, bits 14-15 */ - /**************************************************************************** * Private Types ****************************************************************************/ @@ -1110,7 +1073,7 @@ static int mrf24j40_transmit(FAR struct ieee802154_radio_s *ieee, uint8_t reg; int ret; int hlen = 3; /* Include frame control and seq number */ - uint8_t fc1, fc2; + uint16_t frame_ctrl; mrf24j40_pacontrol(dev, MRF24J40_PA_AUTO); @@ -1124,41 +1087,32 @@ static int mrf24j40_transmit(FAR struct ieee802154_radio_s *ieee, /* Analyze frame control to compute header length */ - fc1 = packet->data[0]; - fc2 = packet->data[1]; + frame_ctrl = packet->data[0]; + frame_ctrl |= packet->data[1] << 8; - //wlinfo("fc1 %02X fc2 %02X\n", fc1,fc2); - - if ((fc2 & IEEE802154_FC2_DADDR) == IEEE802154_DADDR_SHORT) + if ((frame_ctrl & IEEE802154_FRAMECTRL_DADDR)== IEEE802154_ADDRMODE_SHORT) { hlen += 2 + 2; /* Destination PAN + shortaddr */ } - else if ((fc2 & IEEE802154_FC2_DADDR) == IEEE802154_DADDR_EXT) + else if ((frame_ctrl & IEEE802154_FRAMECTRL_DADDR) == IEEE802154_ADDRMODE_EXTENDED) { hlen += 2 + 8; /* Destination PAN + extaddr */ } - if ((fc2 & IEEE802154_FC2_SADDR) == IEEE802154_SADDR_SHORT) + if (!(frame_ctrl & IEEE802154_FRAMECTRL_INTRA)) { - if ((fc1 & IEEE802154_FC1_INTRA) != IEEE802154_INTRA) - { - hlen += 2; /* No PAN compression, source PAN is different from dest PAN */ - } + hlen += 2; /* No PAN compression, source PAN is different from dest PAN */ + } + if ((frame_ctrl & IEEE802154_FRAMECTRL_SADDR)== IEEE802154_ADDRMODE_SHORT) + { hlen += 2; /* Source saddr */ } - else if ((fc2 & IEEE802154_FC2_SADDR) == IEEE802154_SADDR_EXT) + else if ((frame_ctrl & IEEE802154_FRAMECTRL_SADDR) == IEEE802154_ADDRMODE_EXTENDED) { - if ((fc1 & IEEE802154_FC1_INTRA) != IEEE802154_INTRA) - { - hlen += 2; /* No PAN compression, source PAN is different from dest PAN */ - } - hlen += 8; /* Ext saddr */ } - //wlinfo("hlen %d\n",hlen); - /* Header len, 0, TODO for security modes */ mrf24j40_setreg(dev->spi, addr++, hlen); @@ -1180,7 +1134,7 @@ static int mrf24j40_transmit(FAR struct ieee802154_radio_s *ieee, */ reg = MRF24J40_TXNCON_TXNTRIG; - if (fc1 & IEEE802154_FC1_ACKREQ) + if (frame_ctrl & IEEE802154_FRAMECTRL_ACKREQ) { reg |= MRF24J40_TXNCON_TXNACKREQ; } From 4a4805da88c2d3174ffc48e09632944a434f10fb Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Fri, 24 Mar 2017 11:11:04 -0400 Subject: [PATCH 026/183] configs/clicker2-stm32: Fixes issues with stm32_mrf24j40 --- configs/clicker2-stm32/src/stm32_mrf24j40.c | 22 +++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/configs/clicker2-stm32/src/stm32_mrf24j40.c b/configs/clicker2-stm32/src/stm32_mrf24j40.c index 8d28c548548..12131190fbe 100644 --- a/configs/clicker2-stm32/src/stm32_mrf24j40.c +++ b/configs/clicker2-stm32/src/stm32_mrf24j40.c @@ -47,9 +47,9 @@ #include #include -#include -#include -#include +#include +#include +#include #include "stm32_gpio.h" #include "stm32_exti.h" @@ -120,7 +120,7 @@ static int stm32_attach_irq(FAR const struct mrf24j40_lower_s *lower, xcpt_t handler); static void stm32_enable_irq(FAR const struct mrf24j40_lower_s *lower, int state); -static int stm32_mrf24j40_devsetup(FAR struct stm32_priv_s *priv)' +static int stm32_mrf24j40_devsetup(FAR struct stm32_priv_s *priv); /**************************************************************************** * Private Data @@ -172,12 +172,12 @@ static struct stm32_priv_s g_mrf24j40_mb2_priv = * irq_enable - Enable or disable the GPIO interrupt */ -static int stm32_attach_irq(FAR struct mrf24j40_lower_s *lower, +static int stm32_attach_irq(FAR const struct mrf24j40_lower_s *lower, xcpt_t handler) { - FAR struct stm32_priv_s *priv = (FAR struct mrf24j40_lower_s *)lower; + FAR struct stm32_priv_s *priv = (FAR struct stm32_priv_s *)lower; - DEBUASSERT(priv != NULL); + DEBUGASSERT(priv != NULL); /* Just save the handler for use when the interrupt is enabled */ @@ -185,9 +185,9 @@ static int stm32_attach_irq(FAR struct mrf24j40_lower_s *lower, return OK; } -static void stm32_enable_irq(FAR struct mrf24j40_lower_s *lower, int state) +static void stm32_enable_irq(FAR const struct mrf24j40_lower_s *lower, int state) { - FAR struct stm32_priv_s *priv = (FAR struct mrf24j40_lower_s *)lower; + FAR struct stm32_priv_s *priv = (FAR struct stm32_priv_s *)lower; /* The caller should not attempt to enable interrupts if the handler * has not yet been 'attached' @@ -201,7 +201,7 @@ static void stm32_enable_irq(FAR struct mrf24j40_lower_s *lower, int state) if (state != 0) { (void)stm32_gpiosetevent(priv->intcfg, true, true, true, - priv->handler, lower); + priv->handler, NULL); } else { @@ -230,6 +230,8 @@ static int stm32_mrf24j40_devsetup(FAR struct stm32_priv_s *priv) #endif FAR struct spi_dev_s *spi; + int ret; + /* Configure the interrupt pin */ stm32_configgpio(priv->intcfg); From e82600681834a993ac6759e86275da9aa00c73be Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Fri, 24 Mar 2017 11:14:40 -0400 Subject: [PATCH 027/183] configs/clicker2-stm32: Fixes missing semicolon on function prototype --- configs/clicker2-stm32/src/clicker2-stm32.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configs/clicker2-stm32/src/clicker2-stm32.h b/configs/clicker2-stm32/src/clicker2-stm32.h index 41081ae7940..9848165b83a 100644 --- a/configs/clicker2-stm32/src/clicker2-stm32.h +++ b/configs/clicker2-stm32/src/clicker2-stm32.h @@ -299,7 +299,7 @@ int stm32_can_setup(void); ****************************************************************************/ #if defined(CONFIG_CLICKER2_STM32_MB1_BEE) || defined(CONFIG_CLICKER2_STM32_MB2_BEE) -int stm32_mrf24j40_initialize(void) +int stm32_mrf24j40_initialize(void); #endif #endif /* __ASSEMBLY__ */ From 3a07455493130243b72f85d899a92f4abb094f6b Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 24 Mar 2017 10:16:18 -0600 Subject: [PATCH 028/183] Trivial changes from review of last PR --- configs/clicker2-stm32/src/stm32_mrf24j40.c | 1 - include/nuttx/wireless/ieee802154/ieee802154.h | 3 ++- .../nuttx/wireless/ieee802154/ieee802154_mac.h | 16 +++++++++------- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/configs/clicker2-stm32/src/stm32_mrf24j40.c b/configs/clicker2-stm32/src/stm32_mrf24j40.c index 12131190fbe..5c61750f469 100644 --- a/configs/clicker2-stm32/src/stm32_mrf24j40.c +++ b/configs/clicker2-stm32/src/stm32_mrf24j40.c @@ -229,7 +229,6 @@ static int stm32_mrf24j40_devsetup(FAR struct stm32_priv_s *priv) FAR struct ieee802154_mac_s *mac; #endif FAR struct spi_dev_s *spi; - int ret; /* Configure the interrupt pin */ diff --git a/include/nuttx/wireless/ieee802154/ieee802154.h b/include/nuttx/wireless/ieee802154/ieee802154.h index 1b89748c1dd..38410a622f2 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154.h +++ b/include/nuttx/wireless/ieee802154/ieee802154.h @@ -69,7 +69,8 @@ struct ieee802154_packet_s * Extended address + PAN id : PPPP/LLLLLLLLLLLLLLLL */ -enum ieee802154_addr_mode_e { +enum ieee802154_addr_mode_e +{ IEEE802154_ADDRMODE_NONE = 0, IEEE802154_ADDRMODE_SHORT = 2, IEEE802154_ADDRMODE_EXTENDED diff --git a/include/nuttx/wireless/ieee802154/ieee802154_mac.h b/include/nuttx/wireless/ieee802154/ieee802154_mac.h index 992b03e0e8a..f4b408fdb91 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_mac.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_mac.h @@ -55,16 +55,16 @@ /* Configuration ************************************************************/ /* None at the moment */ - /* IEEE 802.15.4 MAC Character Driver IOCTL Commands ************************/ /* The IEEE 802.15.4 standard specifies a MLME Service Access Point (SAP) * including a series of primitives that are used as an interface between * the MLME and the next highest layer. There are 4 types of primitives: - * - Request - * - Indication - * - Response - * - Confirm + * + * - Request + * - Indication + * - Response + * - Confirm * * Of these, Request and Response primitives are sent from the next highest layer * to the MLME. Indication and Confirm primitives are used to notify the next @@ -294,9 +294,11 @@ struct ieee802154_pan_desc_s struct ieee802154_pend_addr_s { - union { + union + { uint8_t pa_spec; - struct { + struct + { uint8_t num_short_addr : 3; /* Number of short addresses pending */ uint8_t reserved_3 : 1; /* Reserved bit */ uint8_t num_ext_addr : 3; /* Number of extended addresses pending */ From e97a13ea900b63ffcd14ff98874ba391d8047ec0 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 24 Mar 2017 13:49:17 -0600 Subject: [PATCH 029/183] MRF24J40/Clicker2: Add an MRF24J40 device configuration to the Clicker2 STM32 board. Fix a few errors discovered during build. --- configs/clicker2-stm32/Kconfig | 6 +- configs/clicker2-stm32/mrf24j40_dev/Make.defs | 122 ++ configs/clicker2-stm32/mrf24j40_dev/defconfig | 1365 +++++++++++++++++ configs/clicker2-stm32/mrf24j40_dev/setenv.sh | 80 + drivers/wireless/Kconfig | 2 - drivers/wireless/ieee802154/mrf24j40.c | 15 +- wireless/Kconfig | 1 - wireless/ieee802154/Kconfig | 1 - 8 files changed, 1581 insertions(+), 11 deletions(-) create mode 100644 configs/clicker2-stm32/mrf24j40_dev/Make.defs create mode 100644 configs/clicker2-stm32/mrf24j40_dev/defconfig create mode 100644 configs/clicker2-stm32/mrf24j40_dev/setenv.sh diff --git a/configs/clicker2-stm32/Kconfig b/configs/clicker2-stm32/Kconfig index a5d3a68cbcd..9344f015da4 100644 --- a/configs/clicker2-stm32/Kconfig +++ b/configs/clicker2-stm32/Kconfig @@ -7,16 +7,14 @@ if ARCH_BOARD_CLICKER2_STM32 config CLICKER2_STM32_MB1_SPI bool "mikroBUS1 SPI" - default n if !STM32_SPI3 - default y if STM32_SPI3 + default n select STM32_SPI3 ---help--- Enable SPI support on mikroBUS1 (STM32 SPI3) config CLICKER2_STM32_MB2_SPI bool "mikroBUS2 SPI" - default n if !STM32_SPI2 - default y if STM32_SPI2 + default n select STM32_SPI2 ---help--- Enable SPI support on mikroBUS1 (STM32 SPI2) diff --git a/configs/clicker2-stm32/mrf24j40_dev/Make.defs b/configs/clicker2-stm32/mrf24j40_dev/Make.defs new file mode 100644 index 00000000000..d86e64844fd --- /dev/null +++ b/configs/clicker2-stm32/mrf24j40_dev/Make.defs @@ -0,0 +1,122 @@ +############################################################################ +# configs/clicker2-stm32/mrf24j40_dev/Make.defs +# +# Copyright (C) 2017 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name NuttX nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + +include ${TOPDIR}/.config +include ${TOPDIR}/tools/Config.mk +include ${TOPDIR}/arch/arm/src/armv7-m/Toolchain.defs + +LDSCRIPT = flash.ld + +ifeq ($(WINTOOL),y) + # Windows-native toolchains + DIRLINK = $(TOPDIR)/tools/copydir.sh + DIRUNLINK = $(TOPDIR)/tools/unlink.sh + MKDEP = $(TOPDIR)/tools/mkwindeps.sh + ARCHINCLUDES = -I. -isystem "${shell cygpath -w $(TOPDIR)/include}" + ARCHXXINCLUDES = -I. -isystem "${shell cygpath -w $(TOPDIR)/include}" -isystem "${shell cygpath -w $(TOPDIR)/include/cxx}" + ARCHSCRIPT = -T "${shell cygpath -w $(TOPDIR)/configs/$(CONFIG_ARCH_BOARD)/scripts/$(LDSCRIPT)}" +else + # Linux/Cygwin-native toolchain + MKDEP = $(TOPDIR)/tools/mkdeps$(HOSTEXEEXT) + ARCHINCLUDES = -I. -isystem $(TOPDIR)/include + ARCHXXINCLUDES = -I. -isystem $(TOPDIR)/include -isystem $(TOPDIR)/include/cxx + ARCHSCRIPT = -T$(TOPDIR)/configs/$(CONFIG_ARCH_BOARD)/scripts/$(LDSCRIPT) +endif + +CC = $(CROSSDEV)gcc +CXX = $(CROSSDEV)g++ +CPP = $(CROSSDEV)gcc -E +LD = $(CROSSDEV)ld +AR = $(CROSSDEV)ar rcs +NM = $(CROSSDEV)nm +OBJCOPY = $(CROSSDEV)objcopy +OBJDUMP = $(CROSSDEV)objdump + +ARCHCCVERSION = ${shell $(CC) -v 2>&1 | sed -n '/^gcc version/p' | sed -e 's/^gcc version \([0-9\.]\)/\1/g' -e 's/[-\ ].*//g' -e '1q'} +ARCHCCMAJOR = ${shell echo $(ARCHCCVERSION) | cut -d'.' -f1} + +ifeq ($(CONFIG_DEBUG_SYMBOLS),y) + ARCHOPTIMIZATION = -g +endif + +ifneq ($(CONFIG_DEBUG_NOOPT),y) + ARCHOPTIMIZATION += $(MAXOPTIMIZATION) -fno-strict-aliasing -fno-strength-reduce -fomit-frame-pointer +endif + +ARCHCFLAGS = -fno-builtin +ARCHCXXFLAGS = -fno-builtin -fno-exceptions -fcheck-new -fno-rtti +ARCHWARNINGS = -Wall -Wstrict-prototypes -Wshadow -Wundef +ARCHWARNINGSXX = -Wall -Wshadow -Wundef +ARCHDEFINES = +ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10 + +CFLAGS = $(ARCHCFLAGS) $(ARCHWARNINGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRADEFINES) -pipe +CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS) +CXXFLAGS = $(ARCHCXXFLAGS) $(ARCHWARNINGSXX) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRADEFINES) -pipe +CXXPICFLAGS = $(ARCHPICFLAGS) $(CXXFLAGS) +CPPFLAGS = $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRADEFINES) +AFLAGS = $(CFLAGS) -D__ASSEMBLY__ + +NXFLATLDFLAGS1 = -r -d -warn-common +NXFLATLDFLAGS2 = $(NXFLATLDFLAGS1) -T$(TOPDIR)/binfmt/libnxflat/gnu-nxflat-gotoff.ld -no-check-sections +LDNXFLATFLAGS = -e main -s 2048 + +# Loadable module definitions + +CMODULEFLAGS = $(CFLAGS) -mlong-calls # --target1-abs + +LDMODULEFLAGS = -r -e module_initialize +ifeq ($(WINTOOL),y) + LDMODULEFLAGS += -T "${shell cygpath -w $(TOPDIR)/libc/modlib/gnu-elf.ld}" +else + LDMODULEFLAGS += -T $(TOPDIR)/libc/modlib/gnu-elf.ld +endif + +ASMEXT = .S +OBJEXT = .o +LIBEXT = .a +EXEEXT = + +ifneq ($(CROSSDEV),arm-nuttx-elf-) + LDFLAGS += -nostartfiles -nodefaultlibs +endif +ifeq ($(CONFIG_DEBUG_SYMBOLS),y) + LDFLAGS += -g +endif + +HOSTCC = gcc +HOSTINCLUDES = -I. +HOSTCFLAGS = -Wall -Wstrict-prototypes -Wshadow -Wundef -g -pipe +HOSTLDFLAGS = diff --git a/configs/clicker2-stm32/mrf24j40_dev/defconfig b/configs/clicker2-stm32/mrf24j40_dev/defconfig new file mode 100644 index 00000000000..5b6ec741f52 --- /dev/null +++ b/configs/clicker2-stm32/mrf24j40_dev/defconfig @@ -0,0 +1,1365 @@ +# +# Automatically generated file; DO NOT EDIT. +# Nuttx/ Configuration +# + +# +# Build Setup +# +# CONFIG_EXPERIMENTAL is not set +# CONFIG_DEFAULT_SMALL is not set +CONFIG_HOST_LINUX=y +# CONFIG_HOST_OSX is not set +# CONFIG_HOST_WINDOWS is not set +# CONFIG_HOST_OTHER is not set + +# +# Build Configuration +# +# CONFIG_APPS_DIR="../apps" +CONFIG_BUILD_FLAT=y +# CONFIG_BUILD_2PASS is not set + +# +# Binary Output Formats +# +# CONFIG_RRLOAD_BINARY is not set +CONFIG_INTELHEX_BINARY=y +# CONFIG_MOTOROLA_SREC is not set +CONFIG_RAW_BINARY=y +# CONFIG_UBOOT_UIMAGE is not set + +# +# Customize Header Files +# +# CONFIG_ARCH_STDINT_H is not set +# CONFIG_ARCH_STDBOOL_H is not set +# CONFIG_ARCH_MATH_H is not set +# CONFIG_ARCH_FLOAT_H is not set +# CONFIG_ARCH_STDARG_H is not set +# CONFIG_ARCH_DEBUG_H is not set + +# +# Debug Options +# +CONFIG_DEBUG_ALERT=y +# CONFIG_DEBUG_FEATURES is not set +CONFIG_ARCH_HAVE_STACKCHECK=y +# CONFIG_STACK_COLORATION is not set +CONFIG_ARCH_HAVE_HEAPCHECK=y +# CONFIG_HEAP_COLORATION is not set +# CONFIG_DEBUG_SYMBOLS is not set +CONFIG_ARCH_HAVE_CUSTOMOPT=y +# CONFIG_DEBUG_NOOPT is not set +# CONFIG_DEBUG_CUSTOMOPT is not set +CONFIG_DEBUG_FULLOPT=y + +# +# System Type +# +CONFIG_ARCH_ARM=y +# CONFIG_ARCH_AVR is not set +# CONFIG_ARCH_HC is not set +# CONFIG_ARCH_MIPS is not set +# CONFIG_ARCH_MISOC is not set +# CONFIG_ARCH_RENESAS is not set +# CONFIG_ARCH_RISCV is not set +# CONFIG_ARCH_SIM is not set +# CONFIG_ARCH_X86 is not set +# CONFIG_ARCH_XTENSA is not set +# CONFIG_ARCH_Z16 is not set +# CONFIG_ARCH_Z80 is not set +CONFIG_ARCH="arm" + +# +# ARM Options +# +# CONFIG_ARCH_CHIP_A1X is not set +# CONFIG_ARCH_CHIP_C5471 is not set +# CONFIG_ARCH_CHIP_DM320 is not set +# CONFIG_ARCH_CHIP_EFM32 is not set +# CONFIG_ARCH_CHIP_IMX1 is not set +# CONFIG_ARCH_CHIP_IMX6 is not set +# CONFIG_ARCH_CHIP_KINETIS is not set +# CONFIG_ARCH_CHIP_KL is not set +# CONFIG_ARCH_CHIP_LM is not set +# CONFIG_ARCH_CHIP_TIVA is not set +# CONFIG_ARCH_CHIP_LPC11XX is not set +# CONFIG_ARCH_CHIP_LPC17XX is not set +# CONFIG_ARCH_CHIP_LPC214X is not set +# CONFIG_ARCH_CHIP_LPC2378 is not set +# CONFIG_ARCH_CHIP_LPC31XX is not set +# CONFIG_ARCH_CHIP_LPC43XX is not set +# CONFIG_ARCH_CHIP_MOXART is not set +# CONFIG_ARCH_CHIP_NUC1XX is not set +# CONFIG_ARCH_CHIP_SAMA5 is not set +# CONFIG_ARCH_CHIP_SAMD is not set +# CONFIG_ARCH_CHIP_SAML is not set +# CONFIG_ARCH_CHIP_SAM34 is not set +# CONFIG_ARCH_CHIP_SAMV7 is not set +CONFIG_ARCH_CHIP_STM32=y +# CONFIG_ARCH_CHIP_STM32F7 is not set +# CONFIG_ARCH_CHIP_STM32L4 is not set +# CONFIG_ARCH_CHIP_STR71X is not set +# CONFIG_ARCH_CHIP_TMS570 is not set +# CONFIG_ARCH_CHIP_XMC4 is not set +# CONFIG_ARCH_ARM7TDMI is not set +# CONFIG_ARCH_ARM926EJS is not set +# CONFIG_ARCH_ARM920T is not set +# CONFIG_ARCH_CORTEXM0 is not set +# CONFIG_ARCH_CORTEXM23 is not set +# CONFIG_ARCH_CORTEXM3 is not set +# CONFIG_ARCH_CORTEXM33 is not set +CONFIG_ARCH_CORTEXM4=y +# CONFIG_ARCH_CORTEXM7 is not set +# CONFIG_ARCH_CORTEXA5 is not set +# CONFIG_ARCH_CORTEXA8 is not set +# CONFIG_ARCH_CORTEXA9 is not set +# CONFIG_ARCH_CORTEXR4 is not set +# CONFIG_ARCH_CORTEXR4F is not set +# CONFIG_ARCH_CORTEXR5 is not set +# CONFIG_ARCH_CORTEX5F is not set +# CONFIG_ARCH_CORTEXR7 is not set +# CONFIG_ARCH_CORTEXR7F is not set +CONFIG_ARCH_FAMILY="armv7-m" +CONFIG_ARCH_CHIP="stm32" +# CONFIG_ARM_TOOLCHAIN_IAR is not set +CONFIG_ARM_TOOLCHAIN_GNU=y +# CONFIG_ARMV7M_USEBASEPRI is not set +CONFIG_ARCH_HAVE_CMNVECTOR=y +# CONFIG_ARMV7M_CMNVECTOR is not set +# CONFIG_ARMV7M_LAZYFPU is not set +CONFIG_ARCH_HAVE_FPU=y +# CONFIG_ARCH_HAVE_DPFPU is not set +CONFIG_ARCH_FPU=y +# CONFIG_ARCH_HAVE_TRUSTZONE is not set +CONFIG_ARM_HAVE_MPU_UNIFIED=y +# CONFIG_ARM_MPU is not set + +# +# ARMV7M Configuration Options +# +# CONFIG_ARMV7M_HAVE_ICACHE is not set +# CONFIG_ARMV7M_HAVE_DCACHE is not set +# CONFIG_ARMV7M_HAVE_ITCM is not set +# CONFIG_ARMV7M_HAVE_DTCM is not set +# CONFIG_ARMV7M_TOOLCHAIN_IARL is not set +# CONFIG_ARMV7M_TOOLCHAIN_BUILDROOT is not set +# CONFIG_ARMV7M_TOOLCHAIN_CODEREDL is not set +# CONFIG_ARMV7M_TOOLCHAIN_CODESOURCERYL is not set +CONFIG_ARMV7M_TOOLCHAIN_GNU_EABIL=y +CONFIG_ARMV7M_HAVE_STACKCHECK=y +# CONFIG_ARMV7M_STACKCHECK is not set +# CONFIG_ARMV7M_ITMSYSLOG is not set +# CONFIG_SERIAL_TERMIOS is not set +# CONFIG_USBHOST_BULK_DISABLE is not set +# CONFIG_USBHOST_INT_DISABLE is not set +# CONFIG_USBHOST_ISOC_DISABLE is not set + +# +# STM32 Configuration Options +# +# CONFIG_ARCH_CHIP_STM32L151C6 is not set +# CONFIG_ARCH_CHIP_STM32L151C8 is not set +# CONFIG_ARCH_CHIP_STM32L151CB is not set +# CONFIG_ARCH_CHIP_STM32L151R6 is not set +# CONFIG_ARCH_CHIP_STM32L151R8 is not set +# CONFIG_ARCH_CHIP_STM32L151RB is not set +# CONFIG_ARCH_CHIP_STM32L151V6 is not set +# CONFIG_ARCH_CHIP_STM32L151V8 is not set +# CONFIG_ARCH_CHIP_STM32L151VB is not set +# CONFIG_ARCH_CHIP_STM32L152C6 is not set +# CONFIG_ARCH_CHIP_STM32L152C8 is not set +# CONFIG_ARCH_CHIP_STM32L152CB is not set +# CONFIG_ARCH_CHIP_STM32L152R6 is not set +# CONFIG_ARCH_CHIP_STM32L152R8 is not set +# CONFIG_ARCH_CHIP_STM32L152RB is not set +# CONFIG_ARCH_CHIP_STM32L152V6 is not set +# CONFIG_ARCH_CHIP_STM32L152V8 is not set +# CONFIG_ARCH_CHIP_STM32L152VB is not set +# CONFIG_ARCH_CHIP_STM32L162ZD is not set +# CONFIG_ARCH_CHIP_STM32L162VE is not set +# CONFIG_ARCH_CHIP_STM32F100C8 is not set +# CONFIG_ARCH_CHIP_STM32F100CB is not set +# CONFIG_ARCH_CHIP_STM32F100R8 is not set +# CONFIG_ARCH_CHIP_STM32F100RB is not set +# CONFIG_ARCH_CHIP_STM32F100RC is not set +# CONFIG_ARCH_CHIP_STM32F100RD is not set +# CONFIG_ARCH_CHIP_STM32F100RE is not set +# CONFIG_ARCH_CHIP_STM32F100V8 is not set +# CONFIG_ARCH_CHIP_STM32F100VB is not set +# CONFIG_ARCH_CHIP_STM32F100VC is not set +# CONFIG_ARCH_CHIP_STM32F100VD is not set +# CONFIG_ARCH_CHIP_STM32F100VE is not set +# CONFIG_ARCH_CHIP_STM32F102CB is not set +# CONFIG_ARCH_CHIP_STM32F103T8 is not set +# CONFIG_ARCH_CHIP_STM32F103TB is not set +# CONFIG_ARCH_CHIP_STM32F103C4 is not set +# CONFIG_ARCH_CHIP_STM32F103C8 is not set +# CONFIG_ARCH_CHIP_STM32F103CB is not set +# CONFIG_ARCH_CHIP_STM32F103R8 is not set +# CONFIG_ARCH_CHIP_STM32F103RB is not set +# CONFIG_ARCH_CHIP_STM32F103RC is not set +# CONFIG_ARCH_CHIP_STM32F103RD is not set +# CONFIG_ARCH_CHIP_STM32F103RE is not set +# CONFIG_ARCH_CHIP_STM32F103RG is not set +# CONFIG_ARCH_CHIP_STM32F103V8 is not set +# CONFIG_ARCH_CHIP_STM32F103VB is not set +# CONFIG_ARCH_CHIP_STM32F103VC is not set +# CONFIG_ARCH_CHIP_STM32F103VE is not set +# CONFIG_ARCH_CHIP_STM32F103ZE is not set +# CONFIG_ARCH_CHIP_STM32F105VB is not set +# CONFIG_ARCH_CHIP_STM32F105RB is not set +# CONFIG_ARCH_CHIP_STM32F107VC is not set +# CONFIG_ARCH_CHIP_STM32F205RG is not set +# CONFIG_ARCH_CHIP_STM32F207IG is not set +# CONFIG_ARCH_CHIP_STM32F207ZE is not set +# CONFIG_ARCH_CHIP_STM32F302K6 is not set +# CONFIG_ARCH_CHIP_STM32F302K8 is not set +# CONFIG_ARCH_CHIP_STM32F302CB is not set +# CONFIG_ARCH_CHIP_STM32F302CC is not set +# CONFIG_ARCH_CHIP_STM32F302RB is not set +# CONFIG_ARCH_CHIP_STM32F302RC is not set +# CONFIG_ARCH_CHIP_STM32F302VB is not set +# CONFIG_ARCH_CHIP_STM32F302VC is not set +# CONFIG_ARCH_CHIP_STM32F303K6 is not set +# CONFIG_ARCH_CHIP_STM32F303K8 is not set +# CONFIG_ARCH_CHIP_STM32F303C6 is not set +# CONFIG_ARCH_CHIP_STM32F303C8 is not set +# CONFIG_ARCH_CHIP_STM32F303CB is not set +# CONFIG_ARCH_CHIP_STM32F303CC is not set +# CONFIG_ARCH_CHIP_STM32F303RB is not set +# CONFIG_ARCH_CHIP_STM32F303RC is not set +# CONFIG_ARCH_CHIP_STM32F303RD is not set +# CONFIG_ARCH_CHIP_STM32F303RE is not set +# CONFIG_ARCH_CHIP_STM32F303VB is not set +# CONFIG_ARCH_CHIP_STM32F303VC is not set +# CONFIG_ARCH_CHIP_STM32F334K4 is not set +# CONFIG_ARCH_CHIP_STM32F334K6 is not set +# CONFIG_ARCH_CHIP_STM32F334K8 is not set +# CONFIG_ARCH_CHIP_STM32F334C4 is not set +# CONFIG_ARCH_CHIP_STM32F334C6 is not set +# CONFIG_ARCH_CHIP_STM32F334C8 is not set +# CONFIG_ARCH_CHIP_STM32F334R4 is not set +# CONFIG_ARCH_CHIP_STM32F334R6 is not set +# CONFIG_ARCH_CHIP_STM32F334R8 is not set +# CONFIG_ARCH_CHIP_STM32F372C8 is not set +# CONFIG_ARCH_CHIP_STM32F372R8 is not set +# CONFIG_ARCH_CHIP_STM32F372V8 is not set +# CONFIG_ARCH_CHIP_STM32F372CB is not set +# CONFIG_ARCH_CHIP_STM32F372RB is not set +# CONFIG_ARCH_CHIP_STM32F372VB is not set +# CONFIG_ARCH_CHIP_STM32F372CC is not set +# CONFIG_ARCH_CHIP_STM32F372RC is not set +# CONFIG_ARCH_CHIP_STM32F372VC is not set +# CONFIG_ARCH_CHIP_STM32F373C8 is not set +# CONFIG_ARCH_CHIP_STM32F373R8 is not set +# CONFIG_ARCH_CHIP_STM32F373V8 is not set +# CONFIG_ARCH_CHIP_STM32F373CB is not set +# CONFIG_ARCH_CHIP_STM32F373RB is not set +# CONFIG_ARCH_CHIP_STM32F373VB is not set +# CONFIG_ARCH_CHIP_STM32F373CC is not set +# CONFIG_ARCH_CHIP_STM32F373RC is not set +# CONFIG_ARCH_CHIP_STM32F373VC is not set +# CONFIG_ARCH_CHIP_STM32F401RE is not set +# CONFIG_ARCH_CHIP_STM32F411RE is not set +# CONFIG_ARCH_CHIP_STM32F411VE is not set +# CONFIG_ARCH_CHIP_STM32F405RG is not set +# CONFIG_ARCH_CHIP_STM32F405VG is not set +# CONFIG_ARCH_CHIP_STM32F405ZG is not set +# CONFIG_ARCH_CHIP_STM32F407VE is not set +CONFIG_ARCH_CHIP_STM32F407VG=y +# CONFIG_ARCH_CHIP_STM32F407ZE is not set +# CONFIG_ARCH_CHIP_STM32F407ZG is not set +# CONFIG_ARCH_CHIP_STM32F407IE is not set +# CONFIG_ARCH_CHIP_STM32F407IG is not set +# CONFIG_ARCH_CHIP_STM32F427V is not set +# CONFIG_ARCH_CHIP_STM32F427Z is not set +# CONFIG_ARCH_CHIP_STM32F427I is not set +# CONFIG_ARCH_CHIP_STM32F429V is not set +# CONFIG_ARCH_CHIP_STM32F429Z is not set +# CONFIG_ARCH_CHIP_STM32F429I is not set +# CONFIG_ARCH_CHIP_STM32F429B is not set +# CONFIG_ARCH_CHIP_STM32F429N is not set +# CONFIG_ARCH_CHIP_STM32F446M is not set +# CONFIG_ARCH_CHIP_STM32F446R is not set +# CONFIG_ARCH_CHIP_STM32F446V is not set +# CONFIG_ARCH_CHIP_STM32F446Z is not set +# CONFIG_ARCH_CHIP_STM32F469A is not set +# CONFIG_ARCH_CHIP_STM32F469I is not set +# CONFIG_ARCH_CHIP_STM32F469B is not set +# CONFIG_ARCH_CHIP_STM32F469N is not set +CONFIG_STM32_FLASH_CONFIG_DEFAULT=y +# CONFIG_STM32_FLASH_CONFIG_4 is not set +# CONFIG_STM32_FLASH_CONFIG_6 is not set +# CONFIG_STM32_FLASH_CONFIG_8 is not set +# CONFIG_STM32_FLASH_CONFIG_B is not set +# CONFIG_STM32_FLASH_CONFIG_C is not set +# CONFIG_STM32_FLASH_CONFIG_D is not set +# CONFIG_STM32_FLASH_CONFIG_E is not set +# CONFIG_STM32_FLASH_CONFIG_F is not set +# CONFIG_STM32_FLASH_CONFIG_G is not set +# CONFIG_STM32_FLASH_CONFIG_I is not set +# CONFIG_STM32_STM32L15XX is not set +# CONFIG_STM32_ENERGYLITE is not set +# CONFIG_STM32_STM32F10XX is not set +# CONFIG_STM32_VALUELINE is not set +# CONFIG_STM32_CONNECTIVITYLINE is not set +# CONFIG_STM32_PERFORMANCELINE is not set +# CONFIG_STM32_USBACCESSLINE is not set +# CONFIG_STM32_HIGHDENSITY is not set +# CONFIG_STM32_MEDIUMDENSITY is not set +# CONFIG_STM32_LOWDENSITY is not set +# CONFIG_STM32_STM32F20XX is not set +# CONFIG_STM32_STM32F205 is not set +# CONFIG_STM32_STM32F207 is not set +# CONFIG_STM32_STM32F30XX is not set +# CONFIG_STM32_STM32F302 is not set +# CONFIG_STM32_STM32F303 is not set +# CONFIG_STM32_STM32F33XX is not set +# CONFIG_STM32_STM32F37XX is not set +CONFIG_STM32_STM32F40XX=y +# CONFIG_STM32_STM32F401 is not set +# CONFIG_STM32_STM32F411 is not set +# CONFIG_STM32_STM32F405 is not set +CONFIG_STM32_STM32F407=y +# CONFIG_STM32_STM32F427 is not set +# CONFIG_STM32_STM32F429 is not set +# CONFIG_STM32_STM32F446 is not set +# CONFIG_STM32_STM32F469 is not set +# CONFIG_STM32_DFU is not set + +# +# STM32 Peripheral Support +# +CONFIG_STM32_HAVE_CCM=y +# CONFIG_STM32_HAVE_USBDEV is not set +CONFIG_STM32_HAVE_OTGFS=y +CONFIG_STM32_HAVE_FSMC=y +# CONFIG_STM32_HAVE_HRTIM1 is not set +# CONFIG_STM32_HAVE_LTDC is not set +CONFIG_STM32_HAVE_USART3=y +CONFIG_STM32_HAVE_UART4=y +CONFIG_STM32_HAVE_UART5=y +CONFIG_STM32_HAVE_USART6=y +# CONFIG_STM32_HAVE_UART7 is not set +# CONFIG_STM32_HAVE_UART8 is not set +CONFIG_STM32_HAVE_TIM1=y +CONFIG_STM32_HAVE_TIM2=y +CONFIG_STM32_HAVE_TIM3=y +CONFIG_STM32_HAVE_TIM4=y +CONFIG_STM32_HAVE_TIM5=y +CONFIG_STM32_HAVE_TIM6=y +CONFIG_STM32_HAVE_TIM7=y +CONFIG_STM32_HAVE_TIM8=y +CONFIG_STM32_HAVE_TIM9=y +CONFIG_STM32_HAVE_TIM10=y +CONFIG_STM32_HAVE_TIM11=y +CONFIG_STM32_HAVE_TIM12=y +CONFIG_STM32_HAVE_TIM13=y +CONFIG_STM32_HAVE_TIM14=y +# CONFIG_STM32_HAVE_TIM15 is not set +# CONFIG_STM32_HAVE_TIM16 is not set +# CONFIG_STM32_HAVE_TIM17 is not set +CONFIG_STM32_HAVE_ADC2=y +CONFIG_STM32_HAVE_ADC3=y +# CONFIG_STM32_HAVE_ADC4 is not set +# CONFIG_STM32_HAVE_ADC1_DMA is not set +# CONFIG_STM32_HAVE_ADC2_DMA is not set +# CONFIG_STM32_HAVE_ADC3_DMA is not set +# CONFIG_STM32_HAVE_ADC4_DMA is not set +# CONFIG_STM32_HAVE_SDADC1 is not set +# CONFIG_STM32_HAVE_SDADC2 is not set +# CONFIG_STM32_HAVE_SDADC3 is not set +# CONFIG_STM32_HAVE_SDADC1_DMA is not set +# CONFIG_STM32_HAVE_SDADC2_DMA is not set +# CONFIG_STM32_HAVE_SDADC3_DMA is not set +CONFIG_STM32_HAVE_CAN1=y +CONFIG_STM32_HAVE_CAN2=y +# CONFIG_STM32_HAVE_COMP2 is not set +# CONFIG_STM32_HAVE_COMP4 is not set +# CONFIG_STM32_HAVE_COMP6 is not set +CONFIG_STM32_HAVE_DAC1=y +CONFIG_STM32_HAVE_DAC2=y +CONFIG_STM32_HAVE_RNG=y +CONFIG_STM32_HAVE_ETHMAC=y +CONFIG_STM32_HAVE_I2C2=y +CONFIG_STM32_HAVE_I2C3=y +CONFIG_STM32_HAVE_SPI2=y +CONFIG_STM32_HAVE_SPI3=y +# CONFIG_STM32_HAVE_SPI4 is not set +# CONFIG_STM32_HAVE_SPI5 is not set +# CONFIG_STM32_HAVE_SPI6 is not set +# CONFIG_STM32_HAVE_SAIPLL is not set +# CONFIG_STM32_HAVE_I2SPLL is not set +# CONFIG_STM32_HAVE_OPAMP is not set +# CONFIG_STM32_ADC1 is not set +# CONFIG_STM32_ADC2 is not set +# CONFIG_STM32_ADC3 is not set +# CONFIG_STM32_BKPSRAM is not set +# CONFIG_STM32_CAN1 is not set +# CONFIG_STM32_CAN2 is not set +# CONFIG_STM32_CCMDATARAM is not set +# CONFIG_STM32_CRC is not set +# CONFIG_STM32_CRYP is not set +# CONFIG_STM32_DMA1 is not set +# CONFIG_STM32_DMA2 is not set +# CONFIG_STM32_DAC1 is not set +# CONFIG_STM32_DAC2 is not set +# CONFIG_STM32_DCMI is not set +# CONFIG_STM32_ETHMAC is not set +# CONFIG_STM32_FSMC is not set +# CONFIG_STM32_HASH is not set +# CONFIG_STM32_I2C1 is not set +# CONFIG_STM32_I2C2 is not set +# CONFIG_STM32_I2C3 is not set +CONFIG_STM32_OTGFS=y +# CONFIG_STM32_OTGHS is not set +CONFIG_STM32_PWR=y +# CONFIG_STM32_RNG is not set +# CONFIG_STM32_SDIO is not set +# CONFIG_STM32_SPI1 is not set +# CONFIG_STM32_SPI2 is not set +CONFIG_STM32_SPI3=y +CONFIG_STM32_SYSCFG=y +# CONFIG_STM32_TIM1 is not set +# CONFIG_STM32_TIM2 is not set +# CONFIG_STM32_TIM3 is not set +# CONFIG_STM32_TIM4 is not set +# CONFIG_STM32_TIM5 is not set +# CONFIG_STM32_TIM6 is not set +# CONFIG_STM32_TIM7 is not set +# CONFIG_STM32_TIM8 is not set +# CONFIG_STM32_TIM9 is not set +# CONFIG_STM32_TIM10 is not set +# CONFIG_STM32_TIM11 is not set +# CONFIG_STM32_TIM12 is not set +# CONFIG_STM32_TIM13 is not set +# CONFIG_STM32_TIM14 is not set +# CONFIG_STM32_USART1 is not set +# CONFIG_STM32_USART2 is not set +CONFIG_STM32_USART3=y +# CONFIG_STM32_UART4 is not set +# CONFIG_STM32_UART5 is not set +# CONFIG_STM32_USART6 is not set +# CONFIG_STM32_IWDG is not set +# CONFIG_STM32_WWDG is not set +CONFIG_STM32_SPI=y +# CONFIG_STM32_NOEXT_VECTORS is not set + +# +# Alternate Pin Mapping +# +# CONFIG_STM32_FLASH_PREFETCH is not set +# CONFIG_STM32_FLASH_WORKAROUND_DATA_CACHE_CORRUPTION_ON_RWW is not set +# CONFIG_STM32_JTAG_DISABLE is not set +# CONFIG_STM32_JTAG_FULL_ENABLE is not set +# CONFIG_STM32_JTAG_NOJNTRST_ENABLE is not set +CONFIG_STM32_JTAG_SW_ENABLE=y +CONFIG_STM32_DISABLE_IDLE_SLEEP_DURING_DEBUG=y +# CONFIG_STM32_FORCEPOWER is not set +# CONFIG_ARCH_BOARD_STM32_CUSTOM_CLOCKCONFIG is not set +CONFIG_STM32_CCMEXCLUDE=y + +# +# Timer Configuration +# +# CONFIG_STM32_ONESHOT is not set +# CONFIG_STM32_FREERUN is not set +# CONFIG_STM32_TIM1_CAP is not set +# CONFIG_STM32_TIM2_CAP is not set +# CONFIG_STM32_TIM3_CAP is not set +# CONFIG_STM32_TIM4_CAP is not set +# CONFIG_STM32_TIM5_CAP is not set +# CONFIG_STM32_TIM8_CAP is not set +# CONFIG_STM32_TIM9_CAP is not set +# CONFIG_STM32_TIM10_CAP is not set +# CONFIG_STM32_TIM11_CAP is not set +# CONFIG_STM32_TIM12_CAP is not set +# CONFIG_STM32_TIM13_CAP is not set +# CONFIG_STM32_TIM14_CAP is not set +CONFIG_STM32_USART=y +CONFIG_STM32_SERIALDRIVER=y + +# +# U[S]ART Configuration +# + +# +# U[S]ART Device Configuration +# +CONFIG_STM32_USART3_SERIALDRIVER=y +# CONFIG_STM32_USART3_1WIREDRIVER is not set +# CONFIG_USART3_RS485 is not set + +# +# Serial Driver Configuration +# +# CONFIG_SERIAL_DISABLE_REORDERING is not set +# CONFIG_STM32_FLOWCONTROL_BROKEN is not set +# CONFIG_STM32_USART_BREAKS is not set +# CONFIG_STM32_USART_SINGLEWIRE is not set + +# +# SPI Configuration +# +# CONFIG_STM32_SPI_INTERRUPTS is not set +# CONFIG_STM32_SPI_DMA is not set +# CONFIG_STM32_HAVE_RTC_COUNTER is not set +# CONFIG_STM32_HAVE_RTC_SUBSECONDS is not set + +# +# USB FS Host Configuration +# +CONFIG_STM32_OTGFS_RXFIFO_SIZE=128 +CONFIG_STM32_OTGFS_NPTXFIFO_SIZE=96 +CONFIG_STM32_OTGFS_PTXFIFO_SIZE=128 +CONFIG_STM32_OTGFS_DESCSIZE=128 +# CONFIG_STM32_OTGFS_SOFINTR is not set + +# +# USB HS Host Configuration +# + +# +# USB Host Debug Configuration +# + +# +# USB Device Configuration +# + +# +# Architecture Options +# +# CONFIG_ARCH_NOINTC is not set +# CONFIG_ARCH_VECNOTIRQ is not set +# CONFIG_ARCH_DMA is not set +CONFIG_ARCH_HAVE_IRQPRIO=y +# CONFIG_ARCH_L2CACHE is not set +# CONFIG_ARCH_HAVE_COHERENT_DCACHE is not set +# CONFIG_ARCH_HAVE_ADDRENV is not set +# CONFIG_ARCH_NEED_ADDRENV_MAPPING is not set +# CONFIG_ARCH_HAVE_MULTICPU is not set +CONFIG_ARCH_HAVE_VFORK=y +# CONFIG_ARCH_HAVE_MMU is not set +CONFIG_ARCH_HAVE_MPU=y +# CONFIG_ARCH_NAND_HWECC is not set +# CONFIG_ARCH_HAVE_EXTCLK is not set +# CONFIG_ARCH_HAVE_POWEROFF is not set +CONFIG_ARCH_HAVE_RESET=y +# CONFIG_ARCH_USE_MPU is not set +# CONFIG_ARCH_IRQPRIO is not set +CONFIG_ARCH_STACKDUMP=y +# CONFIG_ENDIAN_BIG is not set +# CONFIG_ARCH_IDLE_CUSTOM is not set +# CONFIG_ARCH_HAVE_RAMFUNCS is not set +CONFIG_ARCH_HAVE_RAMVECTORS=y +# CONFIG_ARCH_RAMVECTORS is not set +# CONFIG_ARCH_MINIMAL_VECTORTABLE is not set + +# +# Board Settings +# +CONFIG_BOARD_LOOPSPERMSEC=16717 +# CONFIG_ARCH_CALIBRATION is not set + +# +# Interrupt options +# +CONFIG_ARCH_HAVE_INTERRUPTSTACK=y +CONFIG_ARCH_INTERRUPTSTACK=0 +CONFIG_ARCH_HAVE_HIPRI_INTERRUPT=y +# CONFIG_ARCH_HIPRI_INTERRUPT is not set + +# +# Boot options +# +# CONFIG_BOOT_RUNFROMEXTSRAM is not set +CONFIG_BOOT_RUNFROMFLASH=y +# CONFIG_BOOT_RUNFROMISRAM is not set +# CONFIG_BOOT_RUNFROMSDRAM is not set +# CONFIG_BOOT_COPYTORAM is not set + +# +# Boot Memory Configuration +# +CONFIG_RAM_START=0x20000000 +CONFIG_RAM_SIZE=131072 +# CONFIG_ARCH_HAVE_SDRAM is not set + +# +# Board Selection +# +CONFIG_ARCH_BOARD_CLICKER2_STM32=y +# CONFIG_ARCH_BOARD_STM32F4_DISCOVERY is not set +# CONFIG_ARCH_BOARD_MIKROE_STM32F4 is not set +# CONFIG_ARCH_BOARD_CUSTOM is not set +CONFIG_ARCH_BOARD="clicker2-stm32" + +# +# Common Board Options +# +CONFIG_ARCH_HAVE_LEDS=y +CONFIG_ARCH_LEDS=y +CONFIG_ARCH_HAVE_BUTTONS=y +CONFIG_ARCH_BUTTONS=y +CONFIG_ARCH_HAVE_IRQBUTTONS=y +CONFIG_ARCH_IRQBUTTONS=y + +# +# Board-Specific Options +# +CONFIG_CLICKER2_STM32_MB1_SPI=y +# CONFIG_CLICKER2_STM32_MB2_SPI is not set +CONFIG_CLICKER2_STM32_MB1_BEE=y +# CONFIG_CLICKER2_STM32_MB2_BEE is not set +# CONFIG_BOARD_CRASHDUMP is not set +CONFIG_LIB_BOARDCTL=y +# CONFIG_BOARDCTL_RESET is not set +# CONFIG_BOARDCTL_UNIQUEID is not set +# CONFIG_BOARDCTL_TSCTEST is not set +# CONFIG_BOARDCTL_GRAPHICS is not set +# CONFIG_BOARDCTL_IOCTL is not set + +# +# RTOS Features +# +CONFIG_DISABLE_OS_API=y +# CONFIG_DISABLE_POSIX_TIMERS is not set +# CONFIG_DISABLE_PTHREAD is not set +# CONFIG_DISABLE_SIGNALS is not set +# CONFIG_DISABLE_MQUEUE is not set +# CONFIG_DISABLE_ENVIRON is not set + +# +# Clocks and Timers +# +CONFIG_ARCH_HAVE_TICKLESS=y +# CONFIG_SCHED_TICKLESS is not set +CONFIG_USEC_PER_TICK=10000 +# CONFIG_SYSTEM_TIME64 is not set +# CONFIG_CLOCK_MONOTONIC is not set +CONFIG_ARCH_HAVE_TIMEKEEPING=y +# CONFIG_JULIAN_TIME is not set +CONFIG_START_YEAR=2013 +CONFIG_START_MONTH=1 +CONFIG_START_DAY=1 +CONFIG_MAX_WDOGPARMS=2 +CONFIG_PREALLOC_WDOGS=8 +CONFIG_WDOG_INTRESERVE=1 +CONFIG_PREALLOC_TIMERS=4 + +# +# Tasks and Scheduling +# +# CONFIG_SPINLOCK is not set +# CONFIG_INIT_NONE is not set +CONFIG_INIT_ENTRYPOINT=y +# CONFIG_INIT_FILEPATH is not set +CONFIG_USER_ENTRYPOINT="nsh_main" +CONFIG_RR_INTERVAL=200 +# CONFIG_SCHED_SPORADIC is not set +CONFIG_TASK_NAME_SIZE=32 +CONFIG_MAX_TASKS=16 +# CONFIG_SCHED_HAVE_PARENT is not set +CONFIG_SCHED_WAITPID=y + +# +# Pthread Options +# +# CONFIG_MUTEX_TYPES is not set +CONFIG_NPTHREAD_KEYS=4 +# CONFIG_PTHREAD_CLEANUP is not set +# CONFIG_CANCELLATION_POINTS is not set + +# +# Performance Monitoring +# +# CONFIG_SCHED_CPULOAD is not set +# CONFIG_SCHED_INSTRUMENTATION is not set + +# +# Files and I/O +# +CONFIG_DEV_CONSOLE=y +# CONFIG_FDCLONE_DISABLE is not set +# CONFIG_FDCLONE_STDIO is not set +CONFIG_SDCLONE_DISABLE=y +CONFIG_NFILE_DESCRIPTORS=8 +CONFIG_NFILE_STREAMS=8 +CONFIG_NAME_MAX=32 +# CONFIG_PRIORITY_INHERITANCE is not set + +# +# RTOS hooks +# +CONFIG_BOARD_INITIALIZE=y +# CONFIG_BOARD_INITTHREAD is not set +# CONFIG_SCHED_STARTHOOK is not set +# CONFIG_SCHED_ATEXIT is not set +# CONFIG_SCHED_ONEXIT is not set +# CONFIG_SIG_EVTHREAD is not set + +# +# Signal Numbers +# +CONFIG_SIG_SIGUSR1=1 +CONFIG_SIG_SIGUSR2=2 +CONFIG_SIG_SIGALARM=3 +CONFIG_SIG_SIGCONDTIMEDOUT=16 +CONFIG_SIG_SIGWORK=17 + +# +# POSIX Message Queue Options +# +CONFIG_PREALLOC_MQ_MSGS=4 +CONFIG_MQ_MAXMSGSIZE=32 +# CONFIG_MODULE is not set + +# +# Work queue support +# +CONFIG_SCHED_WORKQUEUE=y +CONFIG_SCHED_HPWORK=y +CONFIG_SCHED_HPWORKPRIORITY=192 +CONFIG_SCHED_HPWORKPERIOD=50000 +CONFIG_SCHED_HPWORKSTACKSIZE=2048 +# CONFIG_SCHED_LPWORK is not set + +# +# Stack and heap information +# +CONFIG_IDLETHREAD_STACKSIZE=1024 +CONFIG_USERMAIN_STACKSIZE=2048 +CONFIG_PTHREAD_STACK_MIN=256 +CONFIG_PTHREAD_STACK_DEFAULT=2048 +# CONFIG_LIB_SYSCALL is not set + +# +# Device Drivers +# +CONFIG_DISABLE_POLL=y +CONFIG_DEV_NULL=y +# CONFIG_DEV_ZERO is not set +# CONFIG_DEV_URANDOM is not set +# CONFIG_DEV_LOOP is not set + +# +# Buffering +# +# CONFIG_DRVR_WRITEBUFFER is not set +# CONFIG_DRVR_READAHEAD is not set +# CONFIG_RAMDISK is not set +# CONFIG_CAN is not set +# CONFIG_ARCH_HAVE_PWM_PULSECOUNT is not set +# CONFIG_ARCH_HAVE_PWM_MULTICHAN is not set +# CONFIG_PWM is not set +CONFIG_ARCH_HAVE_I2CRESET=y +# CONFIG_I2C is not set +# CONFIG_ARCH_HAVE_SPI_CRCGENERATION is not set +# CONFIG_ARCH_HAVE_SPI_CS_CONTROL is not set +CONFIG_ARCH_HAVE_SPI_BITORDER=y +CONFIG_SPI=y +# CONFIG_SPI_SLAVE is not set +CONFIG_SPI_EXCHANGE=y +# CONFIG_SPI_CMDDATA is not set +# CONFIG_SPI_CALLBACK is not set +# CONFIG_SPI_HWFEATURES is not set +# CONFIG_SPI_BITORDER is not set +# CONFIG_SPI_CS_DELAY_CONTROL is not set +# CONFIG_SPI_DRIVER is not set +# CONFIG_SPI_BITBANG is not set +# CONFIG_I2S is not set + +# +# Timer Driver Support +# +# CONFIG_TIMER is not set +# CONFIG_ONESHOT is not set +# CONFIG_RTC is not set +# CONFIG_WATCHDOG is not set +# CONFIG_ANALOG is not set +# CONFIG_AUDIO_DEVICES is not set +# CONFIG_VIDEO_DEVICES is not set +# CONFIG_BCH is not set +# CONFIG_INPUT is not set + +# +# IO Expander/GPIO Support +# +# CONFIG_IOEXPANDER is not set +# CONFIG_DEV_GPIO is not set + +# +# LCD Driver Support +# +# CONFIG_LCD is not set +# CONFIG_SLCD is not set + +# +# LED Support +# +# CONFIG_USERLED is not set +# CONFIG_RGBLED is not set +# CONFIG_PCA9635PW is not set +# CONFIG_NCP5623C is not set +# CONFIG_MMCSD is not set +# CONFIG_MODEM is not set +# CONFIG_MTD is not set +# CONFIG_EEPROM is not set +# CONFIG_PIPES is not set +# CONFIG_PM is not set +# CONFIG_POWER is not set +# CONFIG_SENSORS is not set +CONFIG_SERIAL=y +# CONFIG_DEV_LOWCONSOLE is not set +# CONFIG_SERIAL_REMOVABLE is not set +CONFIG_SERIAL_CONSOLE=y +# CONFIG_16550_UART is not set +# CONFIG_UART_SERIALDRIVER is not set +# CONFIG_UART0_SERIALDRIVER is not set +# CONFIG_UART1_SERIALDRIVER is not set +# CONFIG_UART2_SERIALDRIVER is not set +# CONFIG_UART3_SERIALDRIVER is not set +# CONFIG_UART4_SERIALDRIVER is not set +# CONFIG_UART5_SERIALDRIVER is not set +# CONFIG_UART6_SERIALDRIVER is not set +# CONFIG_UART7_SERIALDRIVER is not set +# CONFIG_UART8_SERIALDRIVER is not set +# CONFIG_SCI0_SERIALDRIVER is not set +# CONFIG_SCI1_SERIALDRIVER is not set +# CONFIG_USART0_SERIALDRIVER is not set +# CONFIG_USART1_SERIALDRIVER is not set +# CONFIG_USART2_SERIALDRIVER is not set +CONFIG_USART3_SERIALDRIVER=y +# CONFIG_USART4_SERIALDRIVER is not set +# CONFIG_USART5_SERIALDRIVER is not set +# CONFIG_USART6_SERIALDRIVER is not set +# CONFIG_USART7_SERIALDRIVER is not set +# CONFIG_USART8_SERIALDRIVER is not set +# CONFIG_OTHER_UART_SERIALDRIVER is not set +CONFIG_MCU_SERIAL=y +CONFIG_STANDARD_SERIAL=y +# CONFIG_SERIAL_IFLOWCONTROL is not set +# CONFIG_SERIAL_OFLOWCONTROL is not set +# CONFIG_SERIAL_DMA is not set +CONFIG_ARCH_HAVE_SERIAL_TERMIOS=y +CONFIG_USART3_SERIAL_CONSOLE=y +# CONFIG_OTHER_SERIAL_CONSOLE is not set +# CONFIG_NO_SERIAL_CONSOLE is not set + +# +# USART3 Configuration +# +CONFIG_USART3_RXBUFSIZE=256 +CONFIG_USART3_TXBUFSIZE=256 +CONFIG_USART3_BAUD=115200 +CONFIG_USART3_BITS=8 +CONFIG_USART3_PARITY=0 +CONFIG_USART3_2STOP=0 +# CONFIG_USART3_IFLOWCONTROL is not set +# CONFIG_USART3_OFLOWCONTROL is not set +# CONFIG_USART3_DMA is not set +# CONFIG_PSEUDOTERM is not set +# CONFIG_USBDEV is not set +CONFIG_USBHOST=y +CONFIG_USBHOST_NPREALLOC=4 +CONFIG_USBHOST_HAVE_ASYNCH=y +# CONFIG_USBHOST_ASYNCH is not set +# CONFIG_USBHOST_HUB is not set +# CONFIG_USBHOST_COMPOSITE is not set +CONFIG_USBHOST_MSC=y +# CONFIG_USBHOST_CDCACM is not set +# CONFIG_USBHOST_HIDKBD is not set +# CONFIG_USBHOST_HIDMOUSE is not set +# CONFIG_USBHOST_XBOXCONTROLLER is not set +# CONFIG_USBHOST_TRACE is not set +# CONFIG_HAVE_USBTRACE is not set +CONFIG_DRIVERS_WIRELESS=y +# CONFIG_WL_CC1101 is not set +# CONFIG_WL_CC3000 is not set +CONFIG_DRIVERS_IEEE802154=y +CONFIG_IEEE802154_MRF24J40=y +# CONFIG_IEEE802154_AT86RF233 is not set +# CONFIG_DRIVERS_IEEE80211 is not set +# CONFIG_WL_NRF24L01 is not set +# CONFIG_DRIVERS_CONTACTLESS is not set + +# +# System Logging +# +# CONFIG_ARCH_SYSLOG is not set +# CONFIG_RAMLOG is not set +# CONFIG_SYSLOG_INTBUFFER is not set +# CONFIG_SYSLOG_TIMESTAMP is not set +CONFIG_SYSLOG_SERIAL_CONSOLE=y +# CONFIG_SYSLOG_CHAR is not set +CONFIG_SYSLOG_CONSOLE=y +# CONFIG_SYSLOG_NONE is not set +# CONFIG_SYSLOG_FILE is not set +# CONFIG_SYSLOG_CHARDEV is not set + +# +# Networking Support +# +# CONFIG_ARCH_HAVE_NET is not set +# CONFIG_ARCH_HAVE_PHY is not set +# CONFIG_NET is not set + +# +# Crypto API +# +# CONFIG_CRYPTO is not set + +# +# File Systems +# + +# +# File system configuration +# +# CONFIG_DISABLE_MOUNTPOINT is not set +# CONFIG_FS_AUTOMOUNTER is not set +# CONFIG_DISABLE_PSEUDOFS_OPERATIONS is not set +# CONFIG_PSEUDOFS_SOFTLINKS is not set +CONFIG_FS_READABLE=y +CONFIG_FS_WRITABLE=y +# CONFIG_FS_NAMED_SEMAPHORES is not set +CONFIG_FS_MQUEUE_MPATH="/var/mqueue" +# CONFIG_FS_RAMMAP is not set +CONFIG_FS_FAT=y +CONFIG_FAT_LCNAMES=y +CONFIG_FAT_LFN=y +CONFIG_FAT_MAXFNAME=32 +# CONFIG_FS_FATTIME is not set +# CONFIG_FAT_FORCE_INDIRECT is not set +# CONFIG_FAT_DMAMEMORY is not set +# CONFIG_FAT_DIRECT_RETRY is not set +# CONFIG_FS_NXFFS is not set +# CONFIG_FS_ROMFS is not set +# CONFIG_FS_TMPFS is not set +# CONFIG_FS_SMARTFS is not set +# CONFIG_FS_BINFS is not set +CONFIG_FS_PROCFS=y +# CONFIG_FS_PROCFS_REGISTER is not set + +# +# Exclude individual procfs entries +# +# CONFIG_FS_PROCFS_EXCLUDE_PROCESS is not set +# CONFIG_FS_PROCFS_EXCLUDE_UPTIME is not set +# CONFIG_FS_PROCFS_EXCLUDE_MOUNTS is not set +# CONFIG_FS_UNIONFS is not set + +# +# Graphics Support +# +# CONFIG_NX is not set + +# +# Memory Management +# +# CONFIG_MM_SMALL is not set +CONFIG_MM_REGIONS=1 +# CONFIG_ARCH_HAVE_HEAP2 is not set +# CONFIG_GRAN is not set + +# +# Audio Support +# +# CONFIG_AUDIO is not set + +# +# Wireless Support +# +CONFIG_WIRELESS=y +CONFIG_WIRELESS_IEEE802154=y +CONFIG_IEEE802154_MAC=y +CONFIG_IEEE802154_DEV=y + +# +# Binary Loader +# +# CONFIG_BINFMT_DISABLE is not set +# CONFIG_BINFMT_EXEPATH is not set +# CONFIG_NXFLAT is not set +# CONFIG_ELF is not set +CONFIG_BUILTIN=y +# CONFIG_PIC is not set +# CONFIG_SYMTAB_ORDEREDBYNAME is not set + +# +# Library Routines +# + +# +# Standard C Library Options +# + +# +# Standard C I/O +# +# CONFIG_STDIO_DISABLE_BUFFERING is not set +CONFIG_STDIO_BUFFER_SIZE=64 +CONFIG_STDIO_LINEBUFFER=y +CONFIG_NUNGET_CHARS=2 +# CONFIG_NOPRINTF_FIELDWIDTH is not set +# CONFIG_LIBC_FLOATINGPOINT is not set +CONFIG_LIBC_LONG_LONG=y +# CONFIG_LIBC_SCANSET is not set +# CONFIG_EOL_IS_CR is not set +# CONFIG_EOL_IS_LF is not set +# CONFIG_EOL_IS_BOTH_CRLF is not set +CONFIG_EOL_IS_EITHER_CRLF=y +# CONFIG_MEMCPY_VIK is not set +# CONFIG_LIBM is not set + +# +# Architecture-Specific Support +# +CONFIG_ARCH_LOWPUTC=y +# CONFIG_ARCH_ROMGETC is not set +# CONFIG_LIBC_ARCH_MEMCPY is not set +# CONFIG_LIBC_ARCH_MEMCMP is not set +# CONFIG_LIBC_ARCH_MEMMOVE is not set +# CONFIG_LIBC_ARCH_MEMSET is not set +# CONFIG_LIBC_ARCH_STRCHR is not set +# CONFIG_LIBC_ARCH_STRCMP is not set +# CONFIG_LIBC_ARCH_STRCPY is not set +# CONFIG_LIBC_ARCH_STRNCPY is not set +# CONFIG_LIBC_ARCH_STRLEN is not set +# CONFIG_LIBC_ARCH_STRNLEN is not set +# CONFIG_LIBC_ARCH_ELF is not set +# CONFIG_ARMV7M_MEMCPY is not set + +# +# stdlib Options +# +CONFIG_LIB_RAND_ORDER=1 +CONFIG_LIB_HOMEDIR="/" +CONFIG_LIBC_TMPDIR="/tmp" +CONFIG_LIBC_MAX_TMPFILE=32 + +# +# Program Execution Options +# +# CONFIG_LIBC_EXECFUNCS is not set +CONFIG_POSIX_SPAWN_PROXY_STACKSIZE=1024 +CONFIG_TASK_SPAWN_DEFAULT_STACKSIZE=2048 + +# +# errno Decode Support +# +# CONFIG_LIBC_STRERROR is not set +# CONFIG_LIBC_PERROR_STDOUT is not set + +# +# memcpy/memset Options +# +# CONFIG_MEMSET_OPTSPEED is not set +# CONFIG_LIBC_DLLFCN is not set +# CONFIG_LIBC_MODLIB is not set +# CONFIG_LIBC_WCHAR is not set +# CONFIG_LIBC_LOCALE is not set + +# +# Time/Time Zone Support +# +# CONFIG_LIBC_LOCALTIME is not set +# CONFIG_TIME_EXTENDED is not set +CONFIG_ARCH_HAVE_TLS=y + +# +# Thread Local Storage (TLS) +# +# CONFIG_TLS is not set + +# +# Network-Related Options +# +# CONFIG_LIBC_IPv4_ADDRCONV is not set +# CONFIG_LIBC_IPv6_ADDRCONV is not set +# CONFIG_LIBC_NETDB is not set + +# +# NETDB Support +# +# CONFIG_NETDB_HOSTFILE is not set +# CONFIG_LIBC_IOCTL_VARIADIC is not set +CONFIG_LIB_SENDFILE_BUFSIZE=512 + +# +# Non-standard Library Support +# +# CONFIG_LIB_CRC64_FAST is not set +# CONFIG_LIB_KBDCODEC is not set +# CONFIG_LIB_SLCDCODEC is not set +# CONFIG_LIB_HEX2BIN is not set + +# +# Basic CXX Support +# +# CONFIG_C99_BOOL8 is not set +CONFIG_HAVE_CXX=y +CONFIG_HAVE_CXXINITIALIZE=y +# CONFIG_CXX_NEWLONG is not set + +# +# LLVM C++ Library (libcxx) +# +# CONFIG_LIBCXX is not set + +# +# uClibc++ Standard C++ Library +# +# CONFIG_UCLIBCXX is not set + +# +# Application Configuration +# + +# +# Built-In Applications +# +CONFIG_BUILTIN_PROXY_STACKSIZE=1024 + +# +# CAN Utilities +# + +# +# Examples +# +# CONFIG_EXAMPLES_BUTTONS is not set +# CONFIG_EXAMPLES_CCTYPE is not set +# CONFIG_EXAMPLES_CHAT is not set +# CONFIG_EXAMPLES_CONFIGDATA is not set +# CONFIG_EXAMPLES_CXXTEST is not set +# CONFIG_EXAMPLES_DHCPD is not set +# CONFIG_EXAMPLES_ELF is not set +# CONFIG_EXAMPLES_FSTEST is not set +# CONFIG_EXAMPLES_FTPC is not set +# CONFIG_EXAMPLES_FTPD is not set +# CONFIG_EXAMPLES_HELLO is not set +# CONFIG_EXAMPLES_HELLOXX is not set +# CONFIG_EXAMPLES_HIDKBD is not set +# CONFIG_EXAMPLES_IGMP is not set +# CONFIG_EXAMPLES_JSON is not set +# CONFIG_EXAMPLES_KEYPADTEST is not set +# CONFIG_EXAMPLES_MEDIA is not set +# CONFIG_EXAMPLES_MM is not set +# CONFIG_EXAMPLES_MODBUS is not set +# CONFIG_EXAMPLES_MOUNT is not set +# CONFIG_EXAMPLES_NRF24L01TERM is not set +CONFIG_EXAMPLES_NSH=y +CONFIG_EXAMPLES_NSH_CXXINITIALIZE=y +# CONFIG_EXAMPLES_NULL is not set +# CONFIG_EXAMPLES_NX is not set +# CONFIG_EXAMPLES_NXFFS is not set +# CONFIG_EXAMPLES_NXHELLO is not set +# CONFIG_EXAMPLES_NXIMAGE is not set +# CONFIG_EXAMPLES_NXLINES is not set +# CONFIG_EXAMPLES_NXTERM is not set +# CONFIG_EXAMPLES_NXTEXT is not set +# CONFIG_EXAMPLES_OSTEST is not set +# CONFIG_EXAMPLES_PCA9635 is not set +# CONFIG_EXAMPLES_POSIXSPAWN is not set +# CONFIG_EXAMPLES_PPPD is not set +# CONFIG_EXAMPLES_RFID_READUID is not set +# CONFIG_EXAMPLES_RGBLED is not set +# CONFIG_EXAMPLES_SENDMAIL is not set +# CONFIG_EXAMPLES_SERIALBLASTER is not set +# CONFIG_EXAMPLES_SERIALRX is not set +# CONFIG_EXAMPLES_SERLOOP is not set +# CONFIG_EXAMPLES_SLCD is not set +# CONFIG_EXAMPLES_SMART is not set +# CONFIG_EXAMPLES_SMART_TEST is not set +# CONFIG_EXAMPLES_SMP is not set +# CONFIG_EXAMPLES_STAT is not set +# CONFIG_EXAMPLES_TCPECHO is not set +# CONFIG_EXAMPLES_TELNETD is not set +# CONFIG_EXAMPLES_TIFF is not set +# CONFIG_EXAMPLES_TOUCHSCREEN is not set +# CONFIG_EXAMPLES_USBSERIAL is not set +# CONFIG_EXAMPLES_WATCHDOG is not set +# CONFIG_EXAMPLES_WEBSERVER is not set +# CONFIG_EXAMPLES_XBC_TEST is not set + +# +# File System Utilities +# +# CONFIG_FSUTILS_INIFILE is not set +# CONFIG_FSUTILS_PASSWD is not set + +# +# GPS Utilities +# +# CONFIG_GPSUTILS_MINMEA_LIB is not set + +# +# Graphics Support +# +# CONFIG_TIFF is not set +# CONFIG_GRAPHICS_TRAVELER is not set + +# +# IEEE 802.15.4 applications +# +CONFIG_IEEE802154_COMMON=y +CONFIG_IEEE802154_COORD=y +CONFIG_IEEE802154_I8SAK=y + +# +# Interpreters +# +# CONFIG_INTERPRETERS_BAS is not set +# CONFIG_INTERPRETERS_FICL is not set +# CONFIG_INTERPRETERS_MICROPYTHON is not set +# CONFIG_INTERPRETERS_MINIBASIC is not set +# CONFIG_INTERPRETERS_PCODE is not set + +# +# FreeModBus +# +# CONFIG_MODBUS is not set + +# +# Network Utilities +# +# CONFIG_NETUTILS_CODECS is not set +# CONFIG_NETUTILS_ESP8266 is not set +# CONFIG_NETUTILS_FTPC is not set +# CONFIG_NETUTILS_JSON is not set +# CONFIG_NETUTILS_SMTP is not set + +# +# NSH Library +# +CONFIG_NSH_LIBRARY=y +# CONFIG_NSH_MOTD is not set + +# +# Command Line Configuration +# +CONFIG_NSH_READLINE=y +# CONFIG_NSH_CLE is not set +CONFIG_NSH_LINELEN=64 +# CONFIG_NSH_DISABLE_SEMICOLON is not set +CONFIG_NSH_CMDPARMS=y +CONFIG_NSH_MAXARGUMENTS=6 +CONFIG_NSH_ARGCAT=y +CONFIG_NSH_NESTDEPTH=3 +# CONFIG_NSH_DISABLEBG is not set +CONFIG_NSH_BUILTIN_APPS=y + +# +# Disable Individual commands +# +# CONFIG_NSH_DISABLE_ADDROUTE is not set +# CONFIG_NSH_DISABLE_BASENAME is not set +# CONFIG_NSH_DISABLE_CAT is not set +# CONFIG_NSH_DISABLE_CD is not set +# CONFIG_NSH_DISABLE_CP is not set +# CONFIG_NSH_DISABLE_CMP is not set +CONFIG_NSH_DISABLE_DATE=y +# CONFIG_NSH_DISABLE_DD is not set +# CONFIG_NSH_DISABLE_DF is not set +# CONFIG_NSH_DISABLE_DELROUTE is not set +# CONFIG_NSH_DISABLE_DIRNAME is not set +# CONFIG_NSH_DISABLE_ECHO is not set +# CONFIG_NSH_DISABLE_EXEC is not set +# CONFIG_NSH_DISABLE_EXIT is not set +# CONFIG_NSH_DISABLE_FREE is not set +CONFIG_NSH_DISABLE_GET=y +# CONFIG_NSH_DISABLE_HELP is not set +# CONFIG_NSH_DISABLE_HEXDUMP is not set +# CONFIG_NSH_DISABLE_IFCONFIG is not set +CONFIG_NSH_DISABLE_IFUPDOWN=y +# CONFIG_NSH_DISABLE_KILL is not set +# CONFIG_NSH_DISABLE_LOSETUP is not set +CONFIG_NSH_DISABLE_LOSMART=y +# CONFIG_NSH_DISABLE_LS is not set +# CONFIG_NSH_DISABLE_MB is not set +# CONFIG_NSH_DISABLE_MKDIR is not set +# CONFIG_NSH_DISABLE_MKFATFS is not set +# CONFIG_NSH_DISABLE_MKRD is not set +# CONFIG_NSH_DISABLE_MH is not set +# CONFIG_NSH_DISABLE_MOUNT is not set +# CONFIG_NSH_DISABLE_MV is not set +# CONFIG_NSH_DISABLE_MW is not set +CONFIG_NSH_DISABLE_PRINTF=y +# CONFIG_NSH_DISABLE_PS is not set +CONFIG_NSH_DISABLE_PUT=y +# CONFIG_NSH_DISABLE_PWD is not set +# CONFIG_NSH_DISABLE_RM is not set +# CONFIG_NSH_DISABLE_RMDIR is not set +# CONFIG_NSH_DISABLE_SET is not set +# CONFIG_NSH_DISABLE_SH is not set +# CONFIG_NSH_DISABLE_SLEEP is not set +# CONFIG_NSH_DISABLE_TIME is not set +# CONFIG_NSH_DISABLE_TEST is not set +# CONFIG_NSH_DISABLE_UMOUNT is not set +# CONFIG_NSH_DISABLE_UNAME is not set +# CONFIG_NSH_DISABLE_UNSET is not set +# CONFIG_NSH_DISABLE_USLEEP is not set +CONFIG_NSH_DISABLE_WGET=y +# CONFIG_NSH_DISABLE_XD is not set +CONFIG_NSH_MMCSDMINOR=0 + +# +# Configure Command Options +# +# CONFIG_NSH_CMDOPT_DF_H is not set +# CONFIG_NSH_CMDOPT_DD_STATS is not set +CONFIG_NSH_CODECS_BUFSIZE=128 +CONFIG_NSH_CMDOPT_HEXDUMP=y +CONFIG_NSH_PROC_MOUNTPOINT="/proc" +CONFIG_NSH_FILEIOSIZE=512 + +# +# Scripting Support +# +# CONFIG_NSH_DISABLESCRIPT is not set +# CONFIG_NSH_DISABLE_ITEF is not set +# CONFIG_NSH_DISABLE_LOOPS is not set + +# +# Console Configuration +# +CONFIG_NSH_CONSOLE=y +# CONFIG_NSH_ALTCONDEV is not set +CONFIG_NSH_ARCHINIT=y +# CONFIG_NSH_LOGIN is not set +# CONFIG_NSH_CONSOLE_LOGIN is not set + +# +# NxWidgets/NxWM +# + +# +# Platform-specific Support +# +# CONFIG_PLATFORM_CONFIGDATA is not set + +# +# System Libraries and NSH Add-Ons +# +# CONFIG_SYSTEM_CLE is not set +# CONFIG_SYSTEM_CUTERM is not set +# CONFIG_SYSTEM_FREE is not set +# CONFIG_SYSTEM_HEX2BIN is not set +# CONFIG_SYSTEM_HEXED is not set +# CONFIG_SYSTEM_INSTALL is not set +# CONFIG_SYSTEM_RAMTEST is not set +CONFIG_READLINE_HAVE_EXTMATCH=y +CONFIG_SYSTEM_READLINE=y +CONFIG_READLINE_ECHO=y +# CONFIG_READLINE_TABCOMPLETION is not set +# CONFIG_READLINE_CMD_HISTORY is not set +# CONFIG_SYSTEM_SUDOKU is not set +# CONFIG_SYSTEM_SYSTEM is not set +# CONFIG_SYSTEM_TEE is not set +# CONFIG_SYSTEM_UBLOXMODEM is not set +# CONFIG_SYSTEM_VI is not set +# CONFIG_SYSTEM_ZMODEM is not set diff --git a/configs/clicker2-stm32/mrf24j40_dev/setenv.sh b/configs/clicker2-stm32/mrf24j40_dev/setenv.sh new file mode 100644 index 00000000000..21d46fcc156 --- /dev/null +++ b/configs/clicker2-stm32/mrf24j40_dev/setenv.sh @@ -0,0 +1,80 @@ +#!/bin/bash +# configs/clicker2-stm32/mrf24j40_dev/setenv.sh +# +# Copyright (C) 2017 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name NuttX nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +if [ "$_" = "$0" ] ; then + echo "You must source this script, not run it!" 1>&2 + exit 1 +fi + +WD=`pwd` +if [ ! -x "setenv.sh" ]; then + echo "This script must be executed from the top-level NuttX build directory" + exit 1 +fi + +if [ -z "${PATH_ORIG}" ]; then + export PATH_ORIG="${PATH}" +fi + +# This is the Cygwin path to the location where I installed the CodeSourcery +# toolchain under windows. You will also have to edit this if you install +# the CodeSourcery toolchain in any other location +#export TOOLCHAIN_BIN="/cygdrive/c/Program Files (x86)/CodeSourcery/Sourcery G++ Lite/bin" +#export TOOLCHAIN_BIN="/cygdrive/c/Program Files (x86)/CodeSourcery/Sourcery_CodeBench_Lite_for_ARM_EABI/bin" +# export TOOLCHAIN_BIN="/cygdrive/c/Users/MyName/MentorGraphics/Sourcery_CodeBench_Lite_for_ARM_EABI/bin" + +# This is the location where I installed the ARM "GNU Tools for ARM Embedded Processors" +# You can this free toolchain here https://launchpad.net/gcc-arm-embedded +export TOOLCHAIN_BIN="/cygdrive/c/Program Files (x86)/GNU Tools ARM Embedded/4.9 2015q2/bin" + +# This is the path to the location where I installed the devkitARM toolchain +# You can get this free toolchain from http://devkitpro.org/ or http://sourceforge.net/projects/devkitpro/ +#export TOOLCHAIN_BIN="/cygdrive/c/Program Files (x86)/devkitARM/bin" + +# These are the Cygwin paths to the locations where I installed the Atollic +# toolchain under windows. You will also have to edit this if you install +# the Atollic toolchain in any other location. /usr/bin is added before +# the Atollic bin path because there is are binaries named gcc.exe and g++.exe +# at those locations as well. +#export TOOLCHAIN_BIN="/usr/bin:/cygdrive/c/Program Files (x86)/Atollic/TrueSTUDIO for ARM Pro 2.3.0/ARMTools/bin" +#export TOOLCHAIN_BIN="/usr/bin:/cygdrive/c/Program Files (x86)/Atollic/TrueSTUDIO for STMicroelectronics STM32 Lite 2.3.0/ARMTools/bin" + +# This is the Cygwin path to the location where I build the buildroot +# toolchain. +# export TOOLCHAIN_BIN="${WD}/../buildroot/build_arm_nofpu/staging_dir/bin" + +# Add the path to the toolchain to the PATH varialble +export PATH="${TOOLCHAIN_BIN}:/sbin:/usr/sbin:${PATH_ORIG}" + +echo "PATH : ${PATH}" diff --git a/drivers/wireless/Kconfig b/drivers/wireless/Kconfig index a3bab81d211..39622d66fd7 100644 --- a/drivers/wireless/Kconfig +++ b/drivers/wireless/Kconfig @@ -20,7 +20,6 @@ source drivers/wireless/cc3000/Kconfig menuconfig DRIVERS_IEEE802154 bool "IEEE 802.15.4 Device Support" default n - depends on EXPERIMENTAL ---help--- This directory holds implementations of IEEE802.15.4 device drivers. @@ -29,7 +28,6 @@ source drivers/wireless/ieee802154/Kconfig menuconfig DRIVERS_IEEE80211 bool "IEEE 802.11 Device Support" default n - depends on EXPERIMENTAL ---help--- This directory holds implementations of IEEE802.11 device drivers. diff --git a/drivers/wireless/ieee802154/mrf24j40.c b/drivers/wireless/ieee802154/mrf24j40.c index c4c353ce008..09365ebc838 100644 --- a/drivers/wireless/ieee802154/mrf24j40.c +++ b/drivers/wireless/ieee802154/mrf24j40.c @@ -138,7 +138,7 @@ static int mrf24j40_regdump(FAR struct mrf24j40_radio_s *dev); static void mrf24j40_irqwork_rx(FAR struct mrf24j40_radio_s *dev); static void mrf24j40_irqwork_tx(FAR struct mrf24j40_radio_s *dev); static void mrf24j40_irqworker(FAR void *arg); -static int mrf24j40_interrupt(int irq, FAR void *context); +static int mrf24j40_interrupt(int irq, FAR void *context, FAR void *arg); /* Driver operations */ @@ -1344,10 +1344,15 @@ static void mrf24j40_irqworker(FAR void *arg) * ****************************************************************************/ -static int mrf24j40_interrupt(int irq, FAR void *context) +static int mrf24j40_interrupt(int irq, FAR void *context, FAR void *arg) { /* To support multiple devices, * retrieve the priv structure using the irq number + * + * REVISIT: This will not handler multiple MRF24J40 devices. The correct + * solutions is to pass the struct mrf24j40_radio_s in the call to + * irq_attach() as the third 'arg' parameter. That will be provided here + * and the correct instance can be obtained with a simply case of 'arg'. */ register FAR struct mrf24j40_radio_s *dev = &g_mrf24j40_devices[0]; @@ -1398,7 +1403,11 @@ FAR struct ieee802154_radio_s *mrf24j40_init(FAR struct spi_dev_s *spi, dev = &g_mrf24j40_devices[0]; #endif - /* Attach irq */ + /* Attach irq. + * + * REVISIT: A third argument is required to pass the instance of 'lower' + * to the interrupt handler. + */ if (lower->attach(lower, mrf24j40_interrupt) != OK) { diff --git a/wireless/Kconfig b/wireless/Kconfig index 440e30a665c..75f4ae12891 100644 --- a/wireless/Kconfig +++ b/wireless/Kconfig @@ -6,7 +6,6 @@ config WIRELESS bool "Wireless Support" default n - depends on EXPERIMENTAL ---help--- Enables overall support for Wireless library. diff --git a/wireless/ieee802154/Kconfig b/wireless/ieee802154/Kconfig index 770bbe03819..fa8793af3d8 100644 --- a/wireless/ieee802154/Kconfig +++ b/wireless/ieee802154/Kconfig @@ -6,7 +6,6 @@ config WIRELESS_IEEE802154 bool "IEEE 802.15.4 Wireless Support" default n - depends on EXPERIMENTAL ---help--- Enables support for the IEEE 802.14.5 Wireless library. From fca35f7e5200a3f481e66376cb89c3abc191d784 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 24 Mar 2017 14:15:13 -0600 Subject: [PATCH 030/183] ieee80154: A few changes (some just guesses) to get a clean compilation. --- .../wireless/ieee802154/ieee802154_mac.h | 11 ++++- wireless/ieee802154/mac802154.c | 48 ++++++++++--------- 2 files changed, 35 insertions(+), 24 deletions(-) diff --git a/include/nuttx/wireless/ieee802154/ieee802154_mac.h b/include/nuttx/wireless/ieee802154/ieee802154_mac.h index f4b408fdb91..407360d8157 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_mac.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_mac.h @@ -95,6 +95,7 @@ /* Frame Type */ +#define IEEE802154_FC1_FTYPE 0x03 #define IEEE802154_FRAME_BEACON 0x00 #define IEEE802154_FRAME_DATA 0x01 #define IEEE802154_FRAME_ACK 0x02 @@ -469,12 +470,12 @@ struct ieee802154_macops_s /* Start association with coordinator */ CODE int (*req_associate)(FAR struct ieee802154_mac_s *mac, - FAR struct ieee802154_assoc_request_s *request); + uint16_t panid, FAR uint8_t *coordeadr); /* Start disassociation with coordinator */ CODE int (*req_disassociate)(FAR struct ieee802154_mac_s *mac, - FAR struct ieee802154_disassoc_request_s *request); + FAR uint8_t *eadr, uint8_t reason); /* Read the PIB */ @@ -664,9 +665,15 @@ extern "C" * ****************************************************************************/ +#if 0 /* REVISIT: This form is not currently used by the driver */ FAR struct ieee802154_mac_s * mac802154_register(FAR struct ieee802154_radio_s *radiodev, FAR struct ieee802154_maccb_s *callbacks); +#else /* This is the form used by the driver */ +FAR struct ieee802154_mac_s * + mac802154_register(FAR struct ieee802154_radio_s *radiodev, + unsigned int minor); +#endif #undef EXTERN #ifdef __cplusplus diff --git a/wireless/ieee802154/mac802154.c b/wireless/ieee802154/mac802154.c index da4a7119104..9703a0fe972 100644 --- a/wireless/ieee802154/mac802154.c +++ b/wireless/ieee802154/mac802154.c @@ -38,17 +38,19 @@ ****************************************************************************/ #include -#include -#include -#include +#include +#include +#include +#include + +#include #include /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ - /**************************************************************************** * Private Types ****************************************************************************/ @@ -143,21 +145,21 @@ static int mac802154_rsporphan(FAR struct ieee802154_mac_s *mac, static const struct ieee802154_macops_s mac802154ops = { - .req_data = mac802154_reqdata - .req_purge = mac802154_reqpurge - .req_associate = mac802154_reqassociate - .req_disassociate= mac802154_reqdisassociate - .req_get = mac802154_reqget - .req_gts = mac802154_reqgts - .req_reset = mac802154_reqreset - .req_rxenable = mac802154_reqrxenable - .req_scan = mac802154_reqscan - .req_set = mac802154_reqset - .req_start = mac802154_reqstart - .req_sync = mac802154_reqsync - .req_poll = mac802154_reqpoll - .rsp_associate = mac802154_rspassociate - .rsp_orphan = mac802154_rsporphan + .req_data = mac802154_reqdata, + .req_purge = mac802154_reqpurge, + .req_associate = mac802154_reqassociate, + .req_disassociate = mac802154_reqdisassociate, + .req_get = mac802154_reqget, + .req_gts = mac802154_reqgts, + .req_reset = mac802154_reqreset, + .req_rxenable = mac802154_reqrxenable, + .req_scan = mac802154_reqscan, + .req_set = mac802154_reqset, + .req_start = mac802154_reqstart, + .req_sync = mac802154_reqsync, + .req_poll = mac802154_reqpoll, + .rsp_associate = mac802154_rspassociate, + .rsp_orphan = mac802154_rsporphan, }; /**************************************************************************** @@ -192,12 +194,13 @@ static int mac802154_defaultmib(FAR struct ieee802154_privmac_s *priv) priv->macBeaconPayloadLength = 0; priv->macBSN = 0; /* Shall be random */ - priv->macCoordExtendedAddress[8]; + //priv->macCoordExtendedAddress[8]; priv->macCoordShortAddress = 0xffff; priv->macDSN = 0; /* Shall be random */ priv->macPANId = 0xffff; priv->macShortAddress = 0xffff; priv->macTransactionPersistenceTime = 0x01f4; + #if 0 /* Security MIB */ @@ -207,6 +210,8 @@ static int mac802154_defaultmib(FAR struct ieee802154_privmac_s *priv) priv->macDefaultSecurityMaterialLength = 0x15; priv->macSecurityMode = 0; #endif + + return OK; } /**************************************************************************** @@ -274,8 +279,7 @@ static int mac802154_reqpurge(FAR struct ieee802154_mac_s *mac, ****************************************************************************/ static int mac802154_reqassociate(FAR struct ieee802154_mac_s *mac, - uint16_t panid, - uint8_t *coordeadr) + uint16_t panid, FAR uint8_t *coordeadr) { FAR struct ieee802154_privmac_s * priv = (FAR struct ieee802154_privmac_s *)mac; return -ENOTTY; From 532940ae56a18e2e85adbc7cf0263a92d8d16571 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 24 Mar 2017 17:21:28 -0600 Subject: [PATCH 031/183] configs/: Rename all stm32_wireless.c files to stm32_cc3000.c. --- configs/nucleo-l476rg/src/Makefile | 2 +- configs/nucleo-l476rg/src/{stm32_wireless.c => stm32_cc3000.c} | 2 +- configs/spark/src/Makefile | 2 +- configs/spark/src/{stm32_wireless.c => stm32_cc3000.c} | 2 +- configs/stm32_tiny/src/Makefile | 2 +- configs/stm32_tiny/src/{stm32_wireless.c => stm32_cc3000.c} | 2 +- configs/stm32f103-minimum/src/Makefile | 2 +- .../stm32f103-minimum/src/{stm32_wireless.c => stm32_cc3000.c} | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) rename configs/nucleo-l476rg/src/{stm32_wireless.c => stm32_cc3000.c} (99%) rename configs/spark/src/{stm32_wireless.c => stm32_cc3000.c} (99%) rename configs/stm32_tiny/src/{stm32_wireless.c => stm32_cc3000.c} (99%) rename configs/stm32f103-minimum/src/{stm32_wireless.c => stm32_cc3000.c} (98%) diff --git a/configs/nucleo-l476rg/src/Makefile b/configs/nucleo-l476rg/src/Makefile index a27b0f3b84f..7c908435278 100644 --- a/configs/nucleo-l476rg/src/Makefile +++ b/configs/nucleo-l476rg/src/Makefile @@ -49,7 +49,7 @@ CSRCS += stm32_buttons.c endif ifeq ($(CONFIG_WL_CC3000),y) -CSRCS += stm32_wireless.c +CSRCS += stm32_cc3000.c ifeq ($(CONFIG_CC3000_PROBES),) CSRCS += stm32_io.c endif diff --git a/configs/nucleo-l476rg/src/stm32_wireless.c b/configs/nucleo-l476rg/src/stm32_cc3000.c similarity index 99% rename from configs/nucleo-l476rg/src/stm32_wireless.c rename to configs/nucleo-l476rg/src/stm32_cc3000.c index b65a5eaae5f..d1c94b338e9 100644 --- a/configs/nucleo-l476rg/src/stm32_wireless.c +++ b/configs/nucleo-l476rg/src/stm32_cc3000.c @@ -1,5 +1,5 @@ /************************************************************************************ - * configs/nucleo-l476rg/src/stm32_wireless.c + * configs/nucleo-l476rg/src/stm32_cc3000.c * * Copyright (C) 2014 Gregory Nutt. All rights reserved. * Author: Laurent Latil diff --git a/configs/spark/src/Makefile b/configs/spark/src/Makefile index 51ee3a02805..70a7879f15b 100644 --- a/configs/spark/src/Makefile +++ b/configs/spark/src/Makefile @@ -66,7 +66,7 @@ CSRCS += stm32_composite.c endif ifeq ($(CONFIG_WL_CC3000),y) -CSRCS += stm32_wireless.c +CSRCS += stm32_cc3000.c endif ifeq ($(CONFIG_CC3000_PROBES),) diff --git a/configs/spark/src/stm32_wireless.c b/configs/spark/src/stm32_cc3000.c similarity index 99% rename from configs/spark/src/stm32_wireless.c rename to configs/spark/src/stm32_cc3000.c index afd0f9a819d..7f384213e41 100644 --- a/configs/spark/src/stm32_wireless.c +++ b/configs/spark/src/stm32_cc3000.c @@ -1,5 +1,5 @@ /************************************************************************************ - * configs/spark/src/stm32_wireless.c + * configs/spark/src/stm32_cc3000.c * * Copyright (C) 2009, 2013 Gregory Nutt. All rights reserved. * Author: Laurent Latil diff --git a/configs/stm32_tiny/src/Makefile b/configs/stm32_tiny/src/Makefile index 14ee306846f..02062684c6c 100644 --- a/configs/stm32_tiny/src/Makefile +++ b/configs/stm32_tiny/src/Makefile @@ -44,7 +44,7 @@ CSRCS += stm32_pwm.c endif ifeq ($(CONFIG_WL_NRF24L01),y) -CSRCS += stm32_wireless.c +CSRCS += stm32_cc3000.c endif ifeq ($(CONFIG_LIB_BOARDCTL),y) diff --git a/configs/stm32_tiny/src/stm32_wireless.c b/configs/stm32_tiny/src/stm32_cc3000.c similarity index 99% rename from configs/stm32_tiny/src/stm32_wireless.c rename to configs/stm32_tiny/src/stm32_cc3000.c index a08e48a65ab..9a8a0d3619b 100644 --- a/configs/stm32_tiny/src/stm32_wireless.c +++ b/configs/stm32_tiny/src/stm32_cc3000.c @@ -1,5 +1,5 @@ /************************************************************************************ - * configs/stm32_tiny/src/stm32_wireless.c + * configs/stm32_tiny/src/stm32_cc3000.c * * Copyright (C) 2009, 2013, 2017 Gregory Nutt. All rights reserved. * Author: Laurent Latil diff --git a/configs/stm32f103-minimum/src/Makefile b/configs/stm32f103-minimum/src/Makefile index 7eaf2d9c277..75b6cb29532 100644 --- a/configs/stm32f103-minimum/src/Makefile +++ b/configs/stm32f103-minimum/src/Makefile @@ -86,7 +86,7 @@ CSRCS += stm32_veml6070.c endif ifeq ($(CONFIG_WL_NRF24L01),y) -CSRCS += stm32_wireless.c +CSRCS += stm32_cc3000.c endif ifeq ($(CONFIG_USBDEV),y) diff --git a/configs/stm32f103-minimum/src/stm32_wireless.c b/configs/stm32f103-minimum/src/stm32_cc3000.c similarity index 98% rename from configs/stm32f103-minimum/src/stm32_wireless.c rename to configs/stm32f103-minimum/src/stm32_cc3000.c index c3ddcff7848..23b1144ef51 100644 --- a/configs/stm32f103-minimum/src/stm32_wireless.c +++ b/configs/stm32f103-minimum/src/stm32_cc3000.c @@ -1,5 +1,5 @@ /************************************************************************************ - * configs/stm32f103-minimum//src/stm32_wireless.c + * configs/stm32f103-minimum//src/stm32_cc3000.c * * Copyright (C) 2017 Gregory Nutt. All rights reserved. * Author: Laurent Latil From e77a511a13aeebbee7a4b078ef299994dac34dd1 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 24 Mar 2017 17:30:58 -0600 Subject: [PATCH 032/183] configs/: Rename all xyz_wifi.c files to stm32_cc3000.c. --- .../include/{kl_wifi.h => kl_cc3000.h} | 35 ++++++++++--------- configs/freedom-kl25z/src/Makefile | 2 +- .../src/{kl_wifi.c => kl_cc3000.c} | 4 +-- 3 files changed, 22 insertions(+), 19 deletions(-) rename configs/freedom-kl25z/include/{kl_wifi.h => kl_cc3000.h} (82%) rename configs/freedom-kl25z/src/{kl_wifi.c => kl_cc3000.c} (99%) diff --git a/configs/freedom-kl25z/include/kl_wifi.h b/configs/freedom-kl25z/include/kl_cc3000.h similarity index 82% rename from configs/freedom-kl25z/include/kl_wifi.h rename to configs/freedom-kl25z/include/kl_cc3000.h index ab9ac43564a..117fc57eefc 100644 --- a/configs/freedom-kl25z/include/kl_wifi.h +++ b/configs/freedom-kl25z/include/kl_cc3000.h @@ -1,5 +1,5 @@ /**************************************************************************** - * configs/freedom-kl25z/include/kl_wifi.h + * configs/freedom-kl25z/include/kl_cc300.h * * Copyright (C) 2013 Alan Carvalho de Assis * Author: Alan Carvalho de Assis @@ -38,34 +38,36 @@ * ****************************************************************************/ +#ifndef __CONFIGS_FREEDOM_KL25Z_INCLUDE_KL_CC3000_H +#define __CONFIGS_FREEDOM_KL25Z_INCLUDE_KL_CC3000_H 1 + /**************************************************************************** * Included Files ****************************************************************************/ + #include #include +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ long ReadWlanInterruptPin(void); -/* - * Enable WiFi Interrupt - */ +/* Enable WiFi Interrupt */ void WlanInterruptEnable(void); -/* - * Disable WiFi Interrupt - */ +/* Disable WiFi Interrupt */ + void WlanInterruptDisable(void); -/* - * Enable/Disable WiFi - */ +/* Enable/Disable WiFi */ + void WriteWlanEnablePin(uint8_t val); -/* - * Assert CC3000 CS - */ +/* Assert CC3000 CS */ + void AssertWlanCS(void); /* @@ -73,8 +75,9 @@ void AssertWlanCS(void); */ void DeassertWlanCS(void); -/* - * Setup needed pins - */ +/* Setup needed pins */ + void Wlan_Setup(void); +#endif /* __CONFIGS_FREEDOM_KL25Z_INCLUDE_KL_CC3000_H */ + diff --git a/configs/freedom-kl25z/src/Makefile b/configs/freedom-kl25z/src/Makefile index 2105da11019..37f83bc1ffb 100644 --- a/configs/freedom-kl25z/src/Makefile +++ b/configs/freedom-kl25z/src/Makefile @@ -43,7 +43,7 @@ CSRCS += kl_appinit.c endif ifeq ($(CONFIG_WL_CC3000),y) -CSRCS += kl_wifi.c +CSRCS += kl_cc3000.c endif ifeq ($(CONFIG_KL_TSI),y) diff --git a/configs/freedom-kl25z/src/kl_wifi.c b/configs/freedom-kl25z/src/kl_cc3000.c similarity index 99% rename from configs/freedom-kl25z/src/kl_wifi.c rename to configs/freedom-kl25z/src/kl_cc3000.c index 0f1810da37b..55e96721f3a 100644 --- a/configs/freedom-kl25z/src/kl_wifi.c +++ b/configs/freedom-kl25z/src/kl_cc3000.c @@ -1,5 +1,5 @@ /**************************************************************************** - * configs/freedom-kl25z/src/kl_tsi.c + * configs/freedom-kl25z/src/kl_cc3000.c * * Copyright (C) 2014 Alan Carvalho de Assis * Author: Alan Carvalho de Assis @@ -38,7 +38,7 @@ ****************************************************************************/ #include -#include +#include #include #include From 2506eb32a770477d957e2374fc8a3b188cf48675 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 24 Mar 2017 17:59:09 -0600 Subject: [PATCH 033/183] Fix a comment --- configs/freedom-kl25z/include/kl_cc3000.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/configs/freedom-kl25z/include/kl_cc3000.h b/configs/freedom-kl25z/include/kl_cc3000.h index 117fc57eefc..ce252a67a04 100644 --- a/configs/freedom-kl25z/include/kl_cc3000.h +++ b/configs/freedom-kl25z/include/kl_cc3000.h @@ -70,9 +70,8 @@ void WriteWlanEnablePin(uint8_t val); void AssertWlanCS(void); -/* - * Deassert CC3000 CS - */ +/* Deassert CC3000 CS */ + void DeassertWlanCS(void); /* Setup needed pins */ From dfb9fe9b67db4720401139c88a5c6fe6a9ad4808 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 25 Mar 2017 07:20:04 -0600 Subject: [PATCH 034/183] Clicker2-STM32: Rename configuration to mrf24j40-radio. Update remove. Remove some bad settings in the defconfig file (like OTGFS host support). --- configs/clicker2-stm32/README.txt | 42 +++++++++++++++++++ .../Make.defs | 2 +- .../defconfig | 33 ++------------- .../setenv.sh | 2 +- 4 files changed, 47 insertions(+), 32 deletions(-) rename configs/clicker2-stm32/{mrf24j40_dev => mrf24j40-radio}/Make.defs (98%) rename configs/clicker2-stm32/{mrf24j40_dev => mrf24j40-radio}/defconfig (97%) rename configs/clicker2-stm32/{mrf24j40_dev => mrf24j40-radio}/setenv.sh (98%) diff --git a/configs/clicker2-stm32/README.txt b/configs/clicker2-stm32/README.txt index e265d475c0f..b2b4a54821a 100644 --- a/configs/clicker2-stm32/README.txt +++ b/configs/clicker2-stm32/README.txt @@ -226,6 +226,48 @@ Configurations Configuration sub-directories ----------------------------- + mrf24j40-radio + + This is a version of nsh that was used for testing the MRF24J40 be as a + character device. The most important configuration differences are + summarized below: + + 1. Support for the BEE click and SPI are in enabled in the mikroBUS1 slot: + + CONFIG_CLICKER2_STM32_MB1_BEE=y + CONFIG_CLICKER2_STM32_MB1_SPI=y + + 2. SPI support and STM32 SPI3, in particular, are enabled: + + CONFIG_SPI=y + CONFIG_SPI_EXCHANGE=y + + CONFIG_STM32_SPI=y + CONFIG_STM32_SPI3=y + + 4. Support for the IEEE802.15.4 "upper half" character driver is enabled: + + CONFIG_WIRELESS=y + CONFIG_WIRELESS_IEEE802154=y + CONFIG_IEEE802154_DEV=y + + 5. Support for the lower half MRF24J40 character driver is enabled + + CONFIG_DRIVERS_WIRELESS=y + CONFIG_DRIVERS_IEEE802154=y + CONFIG_IEEE802154_MRF24J40=y + + 6. Support for the test program at apps/ieee802154 is enabled: + + CONFIG_IEEE802154_COMMON=y + CONFIG_IEEE802154_COORD=y + CONFIG_IEEE802154_I8SAK=y + + 7. Initialization hooks are provided to enable the MRF24J40 and to + register the radio character driver. + + CONFIG_NSH_ARCHINIT=y + nsh: Configures the NuttShell (nsh) located at examples/nsh. This diff --git a/configs/clicker2-stm32/mrf24j40_dev/Make.defs b/configs/clicker2-stm32/mrf24j40-radio/Make.defs similarity index 98% rename from configs/clicker2-stm32/mrf24j40_dev/Make.defs rename to configs/clicker2-stm32/mrf24j40-radio/Make.defs index d86e64844fd..4aa245f38b7 100644 --- a/configs/clicker2-stm32/mrf24j40_dev/Make.defs +++ b/configs/clicker2-stm32/mrf24j40-radio/Make.defs @@ -1,5 +1,5 @@ ############################################################################ -# configs/clicker2-stm32/mrf24j40_dev/Make.defs +# configs/clicker2-stm32/mrf24j40-radio/Make.defs # # Copyright (C) 2017 Gregory Nutt. All rights reserved. # Author: Gregory Nutt diff --git a/configs/clicker2-stm32/mrf24j40_dev/defconfig b/configs/clicker2-stm32/mrf24j40-radio/defconfig similarity index 97% rename from configs/clicker2-stm32/mrf24j40_dev/defconfig rename to configs/clicker2-stm32/mrf24j40-radio/defconfig index 5b6ec741f52..db009c3ed3b 100644 --- a/configs/clicker2-stm32/mrf24j40_dev/defconfig +++ b/configs/clicker2-stm32/mrf24j40-radio/defconfig @@ -152,9 +152,6 @@ CONFIG_ARMV7M_HAVE_STACKCHECK=y # CONFIG_ARMV7M_STACKCHECK is not set # CONFIG_ARMV7M_ITMSYSLOG is not set # CONFIG_SERIAL_TERMIOS is not set -# CONFIG_USBHOST_BULK_DISABLE is not set -# CONFIG_USBHOST_INT_DISABLE is not set -# CONFIG_USBHOST_ISOC_DISABLE is not set # # STM32 Configuration Options @@ -413,7 +410,7 @@ CONFIG_STM32_HAVE_SPI3=y # CONFIG_STM32_I2C1 is not set # CONFIG_STM32_I2C2 is not set # CONFIG_STM32_I2C3 is not set -CONFIG_STM32_OTGFS=y +# CONFIG_STM32_OTGFS is not set # CONFIG_STM32_OTGHS is not set CONFIG_STM32_PWR=y # CONFIG_STM32_RNG is not set @@ -511,11 +508,6 @@ CONFIG_STM32_USART3_SERIALDRIVER=y # # USB FS Host Configuration # -CONFIG_STM32_OTGFS_RXFIFO_SIZE=128 -CONFIG_STM32_OTGFS_NPTXFIFO_SIZE=96 -CONFIG_STM32_OTGFS_PTXFIFO_SIZE=128 -CONFIG_STM32_OTGFS_DESCSIZE=128 -# CONFIG_STM32_OTGFS_SOFINTR is not set # # USB HS Host Configuration @@ -863,18 +855,7 @@ CONFIG_USART3_2STOP=0 # CONFIG_USART3_DMA is not set # CONFIG_PSEUDOTERM is not set # CONFIG_USBDEV is not set -CONFIG_USBHOST=y -CONFIG_USBHOST_NPREALLOC=4 -CONFIG_USBHOST_HAVE_ASYNCH=y -# CONFIG_USBHOST_ASYNCH is not set -# CONFIG_USBHOST_HUB is not set -# CONFIG_USBHOST_COMPOSITE is not set -CONFIG_USBHOST_MSC=y -# CONFIG_USBHOST_CDCACM is not set -# CONFIG_USBHOST_HIDKBD is not set -# CONFIG_USBHOST_HIDMOUSE is not set -# CONFIG_USBHOST_XBOXCONTROLLER is not set -# CONFIG_USBHOST_TRACE is not set +# CONFIG_USBHOST is not set # CONFIG_HAVE_USBTRACE is not set CONFIG_DRIVERS_WIRELESS=y # CONFIG_WL_CC1101 is not set @@ -928,14 +909,7 @@ CONFIG_FS_WRITABLE=y # CONFIG_FS_NAMED_SEMAPHORES is not set CONFIG_FS_MQUEUE_MPATH="/var/mqueue" # CONFIG_FS_RAMMAP is not set -CONFIG_FS_FAT=y -CONFIG_FAT_LCNAMES=y -CONFIG_FAT_LFN=y -CONFIG_FAT_MAXFNAME=32 -# CONFIG_FS_FATTIME is not set -# CONFIG_FAT_FORCE_INDIRECT is not set -# CONFIG_FAT_DMAMEMORY is not set -# CONFIG_FAT_DIRECT_RETRY is not set +# CONFIG_FS_FAT is not set # CONFIG_FS_NXFFS is not set # CONFIG_FS_ROMFS is not set # CONFIG_FS_TMPFS is not set @@ -1282,7 +1256,6 @@ CONFIG_NSH_DISABLE_LOSMART=y # CONFIG_NSH_DISABLE_LS is not set # CONFIG_NSH_DISABLE_MB is not set # CONFIG_NSH_DISABLE_MKDIR is not set -# CONFIG_NSH_DISABLE_MKFATFS is not set # CONFIG_NSH_DISABLE_MKRD is not set # CONFIG_NSH_DISABLE_MH is not set # CONFIG_NSH_DISABLE_MOUNT is not set diff --git a/configs/clicker2-stm32/mrf24j40_dev/setenv.sh b/configs/clicker2-stm32/mrf24j40-radio/setenv.sh similarity index 98% rename from configs/clicker2-stm32/mrf24j40_dev/setenv.sh rename to configs/clicker2-stm32/mrf24j40-radio/setenv.sh index 21d46fcc156..a235db68fb3 100644 --- a/configs/clicker2-stm32/mrf24j40_dev/setenv.sh +++ b/configs/clicker2-stm32/mrf24j40-radio/setenv.sh @@ -1,5 +1,5 @@ #!/bin/bash -# configs/clicker2-stm32/mrf24j40_dev/setenv.sh +# configs/clicker2-stm32/mrf24j40-radio/setenv.sh # # Copyright (C) 2017 Gregory Nutt. All rights reserved. # Author: Gregory Nutt From b315f0d851625709ed327b2bdb466818289025d9 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 27 Mar 2017 10:28:03 -0600 Subject: [PATCH 035/183] AT86RF23x: Clean-up, standardize lower half interface. Take advantage of new OS features for interrupt parameter passing. --- drivers/wireless/ieee802154/at86rf23x.c | 33 +++++++++---------- include/nuttx/wireless/ieee802154/at86rf23x.h | 31 +++++++++++------ 2 files changed, 36 insertions(+), 28 deletions(-) diff --git a/drivers/wireless/ieee802154/at86rf23x.c b/drivers/wireless/ieee802154/at86rf23x.c index 3bcf2033736..45094e99ff6 100644 --- a/drivers/wireless/ieee802154/at86rf23x.c +++ b/drivers/wireless/ieee802154/at86rf23x.c @@ -146,7 +146,7 @@ static int at86rf23x_regdump(FAR struct at86rf23x_dev_s *dev); static void at86rf23x_irqwork_rx(FAR struct at86rf23x_dev_s *dev); static void at86rf23x_irqwork_tx(FAR struct at86rf23x_dev_s *dev); static void at86rf23x_irqworker(FAR void *arg); -static int at86rf23x_interrupt(int irq, FAR void *context); +static int at86rf23x_interrupt(int irq, FAR void *context, FAR void *arg); /* Driver operations */ @@ -1221,11 +1221,11 @@ static int at86rf23x_resetrf(FAR struct at86rf23x_dev_s *dev) /* Reset the radio */ - lower->reset(lower, 0); - lower->slptr(lower, 0); + lower->reset(lower, false); + lower->slptr(lower, false); up_udelay(RF23X_TIME_RESET); - lower->reset(lower, 1); + lower->reset(lower, true); /* Dummy read of IRQ register */ @@ -1287,13 +1287,11 @@ static int at86rf23x_rxenable(FAR struct ieee802154_radio_s *ieee, bool state, * ****************************************************************************/ -static int at86rf23x_interrupt(int irq, FAR void *context) +static int at86rf23x_interrupt(int irq, FAR void *context, FAR void *arg) { - /* To support multiple devices, retrieve the priv structure using the irq - * number. - */ + FAR struct at86rf23x_dev_s *dev = (FAR struct at86rf23x_dev_s *)arg; - register FAR struct at86rf23x_dev_s *dev = &g_at86rf23x_devices[0]; + DEBUGASSERT(dev != NULL); /* In complex environments, we cannot do SPI transfers from the interrupt * handler because semaphores are probably used to lock the SPI bus. In @@ -1309,8 +1307,7 @@ static int at86rf23x_interrupt(int irq, FAR void *context) * Interrupts are re-enabled in enc_irqworker() when the work is completed. */ - dev->lower->irq(dev->lower, NULL, FALSE); - //dev->lower->enable(dev->lower, FALSE); + dev->lower->enable(dev->lower, false); return work_queue(HPWORK, &dev->irqwork, at86rf23x_irqworker, (FAR void *)dev, 0); @@ -1393,11 +1390,11 @@ static void at86rf23x_irqworker(FAR void *arg) { wlerr("ERROR: Unknown IRQ Status: %d\n", irq_status); - /* Re enable the IRQ even if we don't know how to handle previous + /* Re-enable the IRQ even if we don't know how to handle previous * status. */ - dev->lower->irq(dev->lower, NULL, true); + dev->lower->enable(dev->lower, true); } } @@ -1428,9 +1425,9 @@ static void at86rf23x_irqwork_rx(FAR struct at86rf23x_dev_s *dev) * soon. */ - /* Re enable the IRQ */ + /* Re-enable the IRQ */ - dev->lower->irq(dev->lower, NULL, true); + dev->lower->enable(dev->lower, true); } /**************************************************************************** @@ -1452,7 +1449,7 @@ static void at86rf23x_irqwork_tx(FAR struct at86rf23x_dev_s *dev) /* Re enable the IRQ */ - dev->lower->irq(dev->lower, NULL, true); + dev->lower->enable(dev->lower, true); sem_post(&dev->ieee.txsem); } @@ -1528,7 +1525,7 @@ FAR struct ieee802154_radio_s *at86rf23x_init(FAR struct spi_dev_s *spi, /* Attach irq */ - if (lower->irq(lower, at86rf23x_interrupt, false) != OK) + if (lower->attach(lower, at86rf23x_interrupt, dev) != OK) { return NULL; } @@ -1598,6 +1595,6 @@ FAR struct ieee802154_radio_s *at86rf23x_init(FAR struct spi_dev_s *spi, /* Enable Radio IRQ */ - lower->irq(lower, at86rf23x_interrupt, true); + lower->enable(lower, true); return &dev->ieee; } diff --git a/include/nuttx/wireless/ieee802154/at86rf23x.h b/include/nuttx/wireless/ieee802154/at86rf23x.h index 7d6f1fe0ce8..2cdf6218cf6 100644 --- a/include/nuttx/wireless/ieee802154/at86rf23x.h +++ b/include/nuttx/wireless/ieee802154/at86rf23x.h @@ -37,25 +37,36 @@ #ifndef __INCLUDE_NUTTX_IEEE802154_AT86RF23X_H #define __INCLUDE_NUTTX_IEEE802154_AT86RF23X_H +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +/**************************************************************************** + * Public Types + ****************************************************************************/ + /* The at86rf23x provides interrupts to the MCU via a GPIO pin. The * following structure provides an MCU-independent mechanixm for controlling * the at86rf23x GPIO interrupt. * * The at86rf23x interrupt is an active low, *level* interrupt. From Datasheet: - * "Note 1: The INTEDGE polarity defaults to: - * 0 = Falling Edge. Ensure that the inter- - * rupt polarity matches the interrupt pin - * polarity of the host microcontroller. - * Note 2: The INT pin will remain high or low, - * depending on INTEDGE polarity setting, - * until INTSTAT register is read." + * "Note 1: The INTEDGE polarity defaults to: 0 = Falling Edge. Ensure that + * the interrupt polarity matches the interrupt pin polarity of the host + * microcontroller. + * "Note 2: The INT pin will remain high or low, depending on INTEDGE polarity + * setting, until INTSTAT register is read." */ struct at86rf23x_lower_s { - int (*irq)(FAR const struct at86rf23x_lower_s *lower, xcpt_t handler, int state); - void (*slptr)(FAR const struct at86rf23x_lower_s *lower, int state); - void (*reset)(FAR const struct at86rf23x_lower_s *lower, int state); + int (*attach)(FAR const struct at86rf23x_lower_s *lower, xcpt_t handler, + FAR void *arg); + void (*enable)(FAR const struct at86rf23x_lower_s *lower, bool state); + void (*slptr)(FAR const struct at86rf23x_lower_s *lower, bool state); + void (*reset)(FAR const struct at86rf23x_lower_s *lower, bool state); }; #ifdef __cplusplus From 3fbf59e2bc7b0545d90c0efb728c850afd3e02fb Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 27 Mar 2017 10:48:58 -0600 Subject: [PATCH 036/183] MRF24J40: Take advantage of new OS features for interrupt parameter passing. --- configs/clicker2-stm32/src/stm32_mrf24j40.c | 19 +++++++------ drivers/wireless/ieee802154/mrf24j40.c | 30 ++++++-------------- include/nuttx/wireless/ieee802154/mrf24j40.h | 7 +++-- 3 files changed, 25 insertions(+), 31 deletions(-) diff --git a/configs/clicker2-stm32/src/stm32_mrf24j40.c b/configs/clicker2-stm32/src/stm32_mrf24j40.c index 5c61750f469..f32c9ed2086 100644 --- a/configs/clicker2-stm32/src/stm32_mrf24j40.c +++ b/configs/clicker2-stm32/src/stm32_mrf24j40.c @@ -99,6 +99,7 @@ struct stm32_priv_s { struct mrf24j40_lower_s dev; xcpt_t handler; + FAR void *arg; uint32_t intcfg; uint8_t spidev; }; @@ -117,9 +118,9 @@ struct stm32_priv_s */ static int stm32_attach_irq(FAR const struct mrf24j40_lower_s *lower, - xcpt_t handler); + xcpt_t handler, FAR void *arg); static void stm32_enable_irq(FAR const struct mrf24j40_lower_s *lower, - int state); + bool state); static int stm32_mrf24j40_devsetup(FAR struct stm32_priv_s *priv); /**************************************************************************** @@ -173,7 +174,7 @@ static struct stm32_priv_s g_mrf24j40_mb2_priv = */ static int stm32_attach_irq(FAR const struct mrf24j40_lower_s *lower, - xcpt_t handler) + xcpt_t handler, FAR void *arg) { FAR struct stm32_priv_s *priv = (FAR struct stm32_priv_s *)lower; @@ -182,10 +183,12 @@ static int stm32_attach_irq(FAR const struct mrf24j40_lower_s *lower, /* Just save the handler for use when the interrupt is enabled */ priv->handler = handler; + priv->arg = arg; return OK; } -static void stm32_enable_irq(FAR const struct mrf24j40_lower_s *lower, int state) +static void stm32_enable_irq(FAR const struct mrf24j40_lower_s *lower, + bool state) { FAR struct stm32_priv_s *priv = (FAR struct stm32_priv_s *)lower; @@ -193,15 +196,15 @@ static void stm32_enable_irq(FAR const struct mrf24j40_lower_s *lower, int state * has not yet been 'attached' */ - DEBUGASSERT(priv != NULL && (priv->handler != NULL || state == 0)); + DEBUGASSERT(priv != NULL && (priv->handler != NULL || !state)); /* Attach and enable, or detach and disable */ - wlinfo("state:%d\n", state); - if (state != 0) + wlinfo("state:%d\n", (int)state); + if (state) { (void)stm32_gpiosetevent(priv->intcfg, true, true, true, - priv->handler, NULL); + priv->handler, priv->arg); } else { diff --git a/drivers/wireless/ieee802154/mrf24j40.c b/drivers/wireless/ieee802154/mrf24j40.c index 09365ebc838..300e0d50e53 100644 --- a/drivers/wireless/ieee802154/mrf24j40.c +++ b/drivers/wireless/ieee802154/mrf24j40.c @@ -196,7 +196,7 @@ static int mrf24j40_transmit(FAR struct ieee802154_radio_s *ieee, static struct mrf24j40_radio_s g_mrf24j40_devices[1]; -static const struct ieee802154_radioops_s mrf24j40_devops = +static const struct ieee802154_radioops_s mrf24j40_devops = { mrf24j40_setchannel, mrf24j40_getchannel, mrf24j40_setpanid , mrf24j40_getpanid, @@ -1322,9 +1322,9 @@ static void mrf24j40_irqworker(FAR void *arg) mrf24j40_irqwork_tx(dev); } - /* Re-Enable GPIO interrupts */ + /* Re-enable GPIO interrupts */ - dev->lower->enable(dev->lower, TRUE); + dev->lower->enable(dev->lower, true); } /**************************************************************************** @@ -1346,16 +1346,9 @@ static void mrf24j40_irqworker(FAR void *arg) static int mrf24j40_interrupt(int irq, FAR void *context, FAR void *arg) { - /* To support multiple devices, - * retrieve the priv structure using the irq number - * - * REVISIT: This will not handler multiple MRF24J40 devices. The correct - * solutions is to pass the struct mrf24j40_radio_s in the call to - * irq_attach() as the third 'arg' parameter. That will be provided here - * and the correct instance can be obtained with a simply case of 'arg'. - */ + FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)arg; - register FAR struct mrf24j40_radio_s *dev = &g_mrf24j40_devices[0]; + DEBUGASSERT(dev != NULL); /* In complex environments, we cannot do SPI transfers from the interrupt * handler because semaphores are probably used to lock the SPI bus. In @@ -1371,7 +1364,7 @@ static int mrf24j40_interrupt(int irq, FAR void *context, FAR void *arg) * Interrupts are re-enabled in enc_irqworker() when the work is completed. */ - dev->lower->enable(dev->lower, FALSE); + dev->lower->enable(dev->lower, false); return work_queue(HPWORK, &dev->irqwork, mrf24j40_irqworker, (FAR void *)dev, 0); } @@ -1403,13 +1396,9 @@ FAR struct ieee802154_radio_s *mrf24j40_init(FAR struct spi_dev_s *spi, dev = &g_mrf24j40_devices[0]; #endif - /* Attach irq. - * - * REVISIT: A third argument is required to pass the instance of 'lower' - * to the interrupt handler. - */ + /* Attach irq */ - if (lower->attach(lower, mrf24j40_interrupt) != OK) + if (lower->attach(lower, mrf24j40_interrupt, dev) != OK) { #if 0 free(dev); @@ -1454,7 +1443,6 @@ FAR struct ieee802154_radio_s *mrf24j40_init(FAR struct spi_dev_s *spi, mrf24j40_pacontrol(dev, MRF24J40_PA_AUTO); - dev->lower->enable(dev->lower, TRUE); - + dev->lower->enable(dev->lower, true); return &dev->ieee; } diff --git a/include/nuttx/wireless/ieee802154/mrf24j40.h b/include/nuttx/wireless/ieee802154/mrf24j40.h index 8f86abcfcb5..c5d1375923b 100644 --- a/include/nuttx/wireless/ieee802154/mrf24j40.h +++ b/include/nuttx/wireless/ieee802154/mrf24j40.h @@ -40,6 +40,8 @@ * Included files ****************************************************************************/ +#include +#include #include /**************************************************************************** @@ -62,8 +64,9 @@ struct mrf24j40_lower_s { - int (*attach)(FAR const struct mrf24j40_lower_s *lower, xcpt_t handler); - void (*enable)(FAR const struct mrf24j40_lower_s *lower, int state); + int (*attach)(FAR const struct mrf24j40_lower_s *lower, xcpt_t handler, + FAR void *arg); + void (*enable)(FAR const struct mrf24j40_lower_s *lower, bool state); }; #ifdef __cplusplus From 4c6e4b2344846e6309cd322037460fb40f1db2a9 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 28 Mar 2017 14:30:46 -0600 Subject: [PATCH 037/183] Remove some garbage from wireless/Makefile --- wireless/Makefile | 8 -------- wireless/ieee802154/Make.defs | 1 + 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/wireless/Makefile b/wireless/Makefile index 008d23ff1c8..f05d957943d 100644 --- a/wireless/Makefile +++ b/wireless/Makefile @@ -52,14 +52,6 @@ VPATH = . include ieee802154$(DELIM)Make.defs -# Include support for various drivers. Each Make.defs file will add its -# files to the source file list, add its DEPPATH info, and will add -# the appropriate paths to the VPATH variable - -ifeq ($(CONFIG_WIRELESS_FORMAT_PCM),y) - CSRCS += pcm_decode.c -endif - AOBJS = $(ASRCS:.S=$(OBJEXT)) COBJS = $(CSRCS:.c=$(OBJEXT)) diff --git a/wireless/ieee802154/Make.defs b/wireless/ieee802154/Make.defs index 5d54b0004d6..834b3da2108 100644 --- a/wireless/ieee802154/Make.defs +++ b/wireless/ieee802154/Make.defs @@ -36,6 +36,7 @@ ifeq ($(CONFIG_WIRELESS_IEEE802154),y) # Include IEEE 802.15.4 support + CSRCS = # Include wireless devices build support From 95f7d4dca750efe60019ad945f2c0863b0bb62ab Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 28 Mar 2017 14:33:45 -0600 Subject: [PATCH 038/183] There should not be paths on C file names in wireless/ieee802154/Make.defs --- wireless/ieee802154/Make.defs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wireless/ieee802154/Make.defs b/wireless/ieee802154/Make.defs index 834b3da2108..051bf50ee68 100644 --- a/wireless/ieee802154/Make.defs +++ b/wireless/ieee802154/Make.defs @@ -42,11 +42,11 @@ CSRCS = # Include wireless devices build support ifeq ($(CONFIG_IEEE802154_MAC),y) -CSRCS += ieee802154/mac802154.c +CSRCS += mac802154.c endif ifeq ($(CONFIG_IEEE802154_DEV),y) -CSRCS += ieee802154/radio802154_device.c +CSRCS += radio802154_device.c endif DEPPATH += --dep-path wireless/ieee802154 From e360492f0c63831091ecc6eb4729c39beef8c0ea Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Tue, 28 Mar 2017 16:58:18 -0400 Subject: [PATCH 039/183] wireless/ieee802154: Removes wireless path prefix from VPATH, DEPPATH --- wireless/ieee802154/Make.defs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wireless/ieee802154/Make.defs b/wireless/ieee802154/Make.defs index 051bf50ee68..e2f205aabc1 100644 --- a/wireless/ieee802154/Make.defs +++ b/wireless/ieee802154/Make.defs @@ -49,8 +49,8 @@ ifeq ($(CONFIG_IEEE802154_DEV),y) CSRCS += radio802154_device.c endif -DEPPATH += --dep-path wireless/ieee802154 -VPATH += :wireless/ieee802154 +DEPPATH += --dep-path ieee802154 +VPATH += :ieee802154 CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)wireless$(DELIM)ieee802154} endif # CONFIG_WIRELESS_IEEE802154 From 3809f2cc97365c844b29036febdcb4ee0b70fb32 Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Tue, 28 Mar 2017 17:20:24 -0400 Subject: [PATCH 040/183] wireless/ieee802154: Removes unnecessary define --- include/nuttx/wireless/ieee802154/ieee802154_mac.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/nuttx/wireless/ieee802154/ieee802154_mac.h b/include/nuttx/wireless/ieee802154/ieee802154_mac.h index 407360d8157..1b43c3c3bb5 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_mac.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_mac.h @@ -95,7 +95,6 @@ /* Frame Type */ -#define IEEE802154_FC1_FTYPE 0x03 #define IEEE802154_FRAME_BEACON 0x00 #define IEEE802154_FRAME_DATA 0x01 #define IEEE802154_FRAME_ACK 0x02 From 8f67ec30a76d3a4cb4e5c201272bb7c5a814ffd4 Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Wed, 29 Mar 2017 12:39:52 -0400 Subject: [PATCH 041/183] wireless/ieee802154: Removes ieee802154.h and makes other minor changes --- drivers/wireless/ieee802154/at86rf23x.c | 2 +- drivers/wireless/ieee802154/mrf24j40.c | 2 +- .../nuttx/wireless/ieee802154/ieee802154.h | 112 ----------------- .../wireless/ieee802154/ieee802154_mac.h | 116 +++++++++++++++--- .../wireless/ieee802154/ieee802154_radio.h | 9 +- wireless/ieee802154/mac802154.c | 2 +- 6 files changed, 109 insertions(+), 134 deletions(-) delete mode 100644 include/nuttx/wireless/ieee802154/ieee802154.h diff --git a/drivers/wireless/ieee802154/at86rf23x.c b/drivers/wireless/ieee802154/at86rf23x.c index 45094e99ff6..7b6193c0aad 100644 --- a/drivers/wireless/ieee802154/at86rf23x.c +++ b/drivers/wireless/ieee802154/at86rf23x.c @@ -56,7 +56,7 @@ #include #include -#include + #include #include "at86rf23x.h" diff --git a/drivers/wireless/ieee802154/mrf24j40.c b/drivers/wireless/ieee802154/mrf24j40.c index 300e0d50e53..9ede37739e5 100644 --- a/drivers/wireless/ieee802154/mrf24j40.c +++ b/drivers/wireless/ieee802154/mrf24j40.c @@ -1099,7 +1099,7 @@ static int mrf24j40_transmit(FAR struct ieee802154_radio_s *ieee, hlen += 2 + 8; /* Destination PAN + extaddr */ } - if (!(frame_ctrl & IEEE802154_FRAMECTRL_INTRA)) + if (!(frame_ctrl & IEEE802154_FRAMECTRL_PANIDCOMP)) { hlen += 2; /* No PAN compression, source PAN is different from dest PAN */ } diff --git a/include/nuttx/wireless/ieee802154/ieee802154.h b/include/nuttx/wireless/ieee802154/ieee802154.h deleted file mode 100644 index 38410a622f2..00000000000 --- a/include/nuttx/wireless/ieee802154/ieee802154.h +++ /dev/null @@ -1,112 +0,0 @@ -/**************************************************************************** - * include/nuttx/wireless/ieee802154/ieee802154.h - * - * Copyright (C) 2014-2016 Sebastien Lorquet. All rights reserved. - * Copyright (C) 2017 Verge Inc. All rights reserved. - * Author: Sebastien Lorquet - * Author: Anthony Merlino - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -#ifndef __INCLUDE_NUTTX_WIRELESS_IEEE802154_IEEE802154_H -#define __INCLUDE_NUTTX_WIRELESS_IEEE802154_IEEE802154_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include - -/**************************************************************************** - * Pre-Processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -struct ieee802154_packet_s -{ - uint8_t len; - uint8_t data[127]; - uint8_t lqi; - uint8_t rssi; -}; - -/* IEEE 802.15.4 Device address - * The addresses in ieee802154 have several formats: - * No address : [none] - * Short address + PAN id : PPPP/SSSS - * Extended address + PAN id : PPPP/LLLLLLLLLLLLLLLL - */ - -enum ieee802154_addr_mode_e -{ - IEEE802154_ADDRMODE_NONE = 0, - IEEE802154_ADDRMODE_SHORT = 2, - IEEE802154_ADDRMODE_EXTENDED -}; - -struct ieee802154_addr_s -{ - enum ieee802154_addr_mode_e ia_mode; /* Address mode. Short or Extended */ - uint16_t ia_panid; /* PAN identifier, can be IEEE802154_PAN_UNSPEC */ - union - { - uint16_t _ia_saddr; /* short address */ - uint8_t _ia_eaddr[8]; /* extended address */ - } ia_addr; - -#define ia_saddr ia_addr._ia_saddr -#define ia_eaddr ia_addr._ia_eaddr -}; - -#define IEEE802154_ADDRSTRLEN 22 /* (2*2+1+8*2, PPPP/EEEEEEEEEEEEEEEE) */ - -#ifdef __cplusplus -#define EXTERN extern "C" -extern "C" -{ -#else -#define EXTERN extern -#endif - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -#undef EXTERN -#ifdef __cplusplus -} -#endif - -#endif /* __INCLUDE_NUTTX_WIRELESS_IEEE802154_IEEE802154_H*/ diff --git a/include/nuttx/wireless/ieee802154/ieee802154_mac.h b/include/nuttx/wireless/ieee802154/ieee802154_mac.h index 1b43c3c3bb5..10f691a9b28 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_mac.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_mac.h @@ -46,7 +46,6 @@ #include #include -#include /**************************************************************************** * Pre-Processor Definitions @@ -123,23 +122,23 @@ * Seee IEEE 802.15.4/2011 5.2.1.1 page 57 */ -#define IEEE802154_FRAMECTRL_FTYPE 0x0007 /* Frame type, bits 0-2 */ -#define IEEE802154_FRAMECTRL_SEC 0x0008 /* Security Enabled, bit 3 */ -#define IEEE802154_FRAMECTRL_PEND 0x0010 /* Frame pending, bit 4 */ -#define IEEE802154_FRAMECTRL_ACKREQ 0x0020 /* Acknowledge request, bit 5 */ -#define IEEE802154_FRAMECTRL_INTRA 0x0040 /* Intra PAN, bit 6 */ -#define IEEE802154_FRAMECTRL_DADDR 0x0C00 /* Dest addressing mode, bits 10-11 */ -#define IEEE802154_FRAMECTRL_VERSION 0x3000 /* Source addressing mode, bits 12-13 */ -#define IEEE802154_FRAMECTRL_SADDR 0xC000 /* Source addressing mode, bits 14-15 */ +#define IEEE802154_FRAMECTRL_FTYPE 0x0007 /* Frame type, bits 0-2 */ +#define IEEE802154_FRAMECTRL_SEC 0x0008 /* Security Enabled, bit 3 */ +#define IEEE802154_FRAMECTRL_PEND 0x0010 /* Frame pending, bit 4 */ +#define IEEE802154_FRAMECTRL_ACKREQ 0x0020 /* Acknowledge request, bit 5 */ +#define IEEE802154_FRAMECTRL_PANIDCOMP 0x0040 /* PAN ID Compression, bit 6 */ +#define IEEE802154_FRAMECTRL_DADDR 0x0C00 /* Dest addressing mode, bits 10-11 */ +#define IEEE802154_FRAMECTRL_VERSION 0x3000 /* Source addressing mode, bits 12-13 */ +#define IEEE802154_FRAMECTRL_SADDR 0xC000 /* Source addressing mode, bits 14-15 */ -#define IEEE802154_FRAMECTRL_SHIFT_FTYPE 0 /* Frame type, bits 0-2 */ -#define IEEE802154_FRAMECTRL_SHIFT_SEC 3 /* Security Enabled, bit 3 */ -#define IEEE802154_FRAMECTRL_SHIFT_PEND 4 /* Frame pending, bit 4 */ -#define IEEE802154_FRAMECTRL_SHIFT_ACKREQ 5 /* Acknowledge request, bit 5 */ -#define IEEE802154_FRAMECTRL_SHIFT_INTRA 6 /* Intra PAN, bit 6 */ -#define IEEE802154_FRAMECTRL_SHIFT_DADDR 10 /* Dest addressing mode, bits 10-11 */ -#define IEEE802154_FRAMECTRL_SHIFT_VERSION 12 /* Source addressing mode, bits 12-13 */ -#define IEEE802154_FRAMECTRL_SHIFT_SADDR 14 /* Source addressing mode, bits 14-15 */ +#define IEEE802154_FRAMECTRL_SHIFT_FTYPE 0 /* Frame type, bits 0-2 */ +#define IEEE802154_FRAMECTRL_SHIFT_SEC 3 /* Security Enabled, bit 3 */ +#define IEEE802154_FRAMECTRL_SHIFT_PEND 4 /* Frame pending, bit 4 */ +#define IEEE802154_FRAMECTRL_SHIFT_ACKREQ 5 /* Acknowledge request, bit 5 */ +#define IEEE802154_FRAMECTRL_SHIFT_PANIDCOMP 6 /* PAN ID Compression, bit 6 */ +#define IEEE802154_FRAMECTRL_SHIFT_DADDR 10 /* Dest addressing mode, bits 10-11 */ +#define IEEE802154_FRAMECTRL_SHIFT_VERSION 12 /* Source addressing mode, bits 12-13 */ +#define IEEE802154_FRAMECTRL_SHIFT_SADDR 14 /* Source addressing mode, bits 14-15 */ /* IEEE 802.15.4 PHY constants */ @@ -238,6 +237,87 @@ enum IEEE802154_macSecurityMode }; +/* IEEE 802.15.4 Device address + * The addresses in ieee802154 have several formats: + * No address : [none] + * Short address + PAN id : PPPP/SSSS + * Extended address + PAN id : PPPP/LLLLLLLLLLLLLLLL + */ + +enum ieee802154_addr_mode_e +{ + IEEE802154_ADDRMODE_NONE = 0, + IEEE802154_ADDRMODE_SHORT = 2, + IEEE802154_ADDRMODE_EXTENDED +}; + +struct ieee802154_addr_s +{ + enum ieee802154_addr_mode_e ia_mode; /* Address mode. Short or Extended */ + uint16_t ia_panid; /* PAN identifier, can be IEEE802154_PAN_UNSPEC */ + union + { + uint16_t _ia_saddr; /* short address */ + uint8_t _ia_eaddr[8]; /* extended address */ + } ia_addr; + +#define ia_saddr ia_addr._ia_saddr +#define ia_eaddr ia_addr._ia_eaddr +}; + +#define IEEE802154_ADDRSTRLEN 22 /* (2*2+1+8*2, PPPP/EEEEEEEEEEEEEEEE) */ + +struct ieee802154_framecontrol_s +{ + /* Frame type + * + * Should be a value from: ieee802154_frametype_e + * + * Bits 0-1 + */ + + uint16_t frame_type : 3; + + uint16_t security_en : 1; /* Security Enabled flag, bit 3 */ + uint16_t frame_pending : 1; /* Frame Pending flag, bit 4 */ + uint16_t ack_req : 1; /* Acknowledge Request flag, bit 5 */ + uint16_t panid_comp : 1; /* PAN ID Compression flag, bit 6 */ + uint16_t reserved : 3; /* Reserved, bits 7-9 */ + + /* Destination Addressing Mode + * + * Should be a value from: ieee802154_addr_mode_e + * + * Bits 10-11 + */ + + uint16_t dest_addr_mode : 2; + + uint16_t frame_version : 2; /* Frame Version, bits 12-13 */ + + /* Source Addressing Mode + * + * Should be a value from: ieee802154_addr_mode_e + * + * Bits 14-15 + */ + + uint16_t src_addr_mode : 2; +}; + +struct ieee802154_frame_s +{ + struct ieee802154_framecontrol_s frame_control; + uint8_t seq_num; + struct ieee802154_addr_s dest_addr; + struct ieee802154_addr_s src_addr; +#ifdef CONFIG_IEEE802154_SECURITY + struct ieee802154_auxsec_s aux_sec_hdr; +#endif + void *payload; + uint16_t fcs; +}; + struct ieee802154_capability_info_s { uint8_t reserved_0 : 1; /* Reserved */ @@ -679,4 +759,4 @@ FAR struct ieee802154_mac_s * } #endif -#endif /* __INCLUDE_NUTTX_WIRELESS_IEEE802154_MRF24J40_H */ +#endif /* __INCLUDE_NUTTX_WIRELESS_IEEE802154_IEEE802154_MAC_H */ diff --git a/include/nuttx/wireless/ieee802154/ieee802154_radio.h b/include/nuttx/wireless/ieee802154/ieee802154_radio.h index f87c2010c2f..0f8b7b187e8 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_radio.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_radio.h @@ -47,7 +47,6 @@ #include #include #include -#include /**************************************************************************** * Pre-Processor Definitions @@ -106,6 +105,14 @@ struct ieee802154_cca_s uint8_t csth; /* Carrier sense threshold for CCA */ }; +struct ieee802154_packet_s +{ + uint8_t len; + uint8_t data[127]; + uint8_t lqi; + uint8_t rssi; +}; + struct ieee802154_radio_s; struct ieee802154_radioops_s diff --git a/wireless/ieee802154/mac802154.c b/wireless/ieee802154/mac802154.c index 9703a0fe972..59d5f57d792 100644 --- a/wireless/ieee802154/mac802154.c +++ b/wireless/ieee802154/mac802154.c @@ -77,7 +77,7 @@ struct ieee802154_privmac_s /* 0x4F */ uint32_t macMinBE : 2; /* 0x4D */ uint32_t macGTSPermit : 1; /* 0x51 */ uint32_t macPromiscuousMode : 1; - /* 0x52 */ uint32_t macRxOnWhenIdle : 1; + /* 0x52 */ uint32_t macRxOnWhenIdle : 1; uint32_t macPad : 3; /* 0x48 */ uint32_t macBeaconTxTime : 24; From 8df78cc74bc47d59c1e3ee382905bfbb770822b7 Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Wed, 29 Mar 2017 12:51:01 -0400 Subject: [PATCH 042/183] wireless/ieee802154: Adds MAC character driver structure. Nonfunctional --- .../wireless/ieee802154/ieee802154_mac.h | 53 +- wireless/ieee802154/Kconfig | 8 + wireless/ieee802154/Make.defs | 4 + wireless/ieee802154/mac802154.c | 27 +- wireless/ieee802154/mac802154_device.c | 503 ++++++++++++++++++ 5 files changed, 565 insertions(+), 30 deletions(-) create mode 100644 wireless/ieee802154/mac802154_device.c diff --git a/include/nuttx/wireless/ieee802154/ieee802154_mac.h b/include/nuttx/wireless/ieee802154/ieee802154_mac.h index 10f691a9b28..19af457bf65 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_mac.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_mac.h @@ -724,35 +724,52 @@ extern "C" ****************************************************************************/ /**************************************************************************** - * Name: mac802154_register + * Name: mac802154_create * * 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. + * The returned MAC structure should be passed to either the next highest + * layer in the network stack, or registered with a mac802154dev character + * driver. In either of these scenarios, the next highest layer should + * register a set of callbacks with the MAC layer by setting the mac->cbs + * member. * - * 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 + * NOTE: 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. * + * Input Parameters: + * radiodev - an instance of an IEEE 802.15.4 radio + * + * Returned Value: + * A MAC structure that has pointers to MAC operations + * and responses. + * ****************************************************************************/ -#if 0 /* REVISIT: This form is not currently used by the driver */ FAR struct ieee802154_mac_s * - mac802154_register(FAR struct ieee802154_radio_s *radiodev, - FAR struct ieee802154_maccb_s *callbacks); -#else /* This is the form used by the driver */ -FAR struct ieee802154_mac_s * - mac802154_register(FAR struct ieee802154_radio_s *radiodev, - unsigned int minor); -#endif + mac802154_create(FAR struct ieee802154_radio_s *radiodev); + +/**************************************************************************** + * Name: mac802154dev_register + * + * Description: + * Register a character driver to access the IEEE 802.15.4 MAC layer from + * user-space + * + * Input Parameters: + * mac - Pointer to the mac layer struct to be registerd. + * minor - The device minor number. The IEEE802.15.4 MAC character device + * will be registered as /dev/ieeeN where N is the minor number + * + * Returned Values: + * Zero (OK) is returned on success. Otherwise a negated errno value is + * returned to indicate the nature of the failure. + * + ****************************************************************************/ + +int mac802154dev_register(FAR struct ieee802154_mac_s *mac, int minor); #undef EXTERN #ifdef __cplusplus diff --git a/wireless/ieee802154/Kconfig b/wireless/ieee802154/Kconfig index fa8793af3d8..5470894a7de 100644 --- a/wireless/ieee802154/Kconfig +++ b/wireless/ieee802154/Kconfig @@ -21,6 +21,14 @@ config IEEE802154_MAC such as 6lowpan. It is not required to use 802.15.4 radios, but is strongly suggested to ensure exchange of valid frames. +config IEEE802154_MAC_DEV + bool "Character driver for IEEE 802.15.4 MAC layer" + default n + depends on IEEE802154_MAC + ---help--- + Enable the device driver to expose the IEEE 802.15.4 MAC layer + access to user space as IOCTLs + config IEEE802154_DEV bool "Debug character driver for ieee802.15.4 radio interfaces" default n diff --git a/wireless/ieee802154/Make.defs b/wireless/ieee802154/Make.defs index e2f205aabc1..4a69b065118 100644 --- a/wireless/ieee802154/Make.defs +++ b/wireless/ieee802154/Make.defs @@ -45,6 +45,10 @@ ifeq ($(CONFIG_IEEE802154_MAC),y) CSRCS += mac802154.c endif +ifeq ($(CONFIG_IEEE802154_MAC_DEV),y) +CSRCS += mac802154_device.c +endif + ifeq ($(CONFIG_IEEE802154_DEV),y) CSRCS += radio802154_device.c endif diff --git a/wireless/ieee802154/mac802154.c b/wireless/ieee802154/mac802154.c index 59d5f57d792..d0a0a3ce504 100644 --- a/wireless/ieee802154/mac802154.c +++ b/wireless/ieee802154/mac802154.c @@ -506,29 +506,32 @@ static int mac802154_rsporphan(FAR struct ieee802154_mac_s *mac, ****************************************************************************/ /**************************************************************************** - * Name: mac802154_register + * Name: mac802154_create * * 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. + * The returned MAC structure should be passed to either the next highest + * layer in the network stack, or registered with a mac802154dev character + * driver. In either of these scenarios, the next highest layer should + * register a set of callbacks with the MAC layer by setting the mac->cbs + * member. * - * 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 + * NOTE: 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. * + * Input Parameters: + * radiodev - an instance of an IEEE 802.15.4 radio + * + * Returned Value: + * A MAC structure that has pointers to MAC operations + * and responses. + * ****************************************************************************/ FAR struct ieee802154_mac_s * - mac802154_register(FAR struct ieee802154_radio_s *radiodev, - unsigned int minor) + mac802154_create(FAR struct ieee802154_radio_s *radiodev) { FAR struct ieee802154_privmac_s *mac; diff --git a/wireless/ieee802154/mac802154_device.c b/wireless/ieee802154/mac802154_device.c new file mode 100644 index 00000000000..88f36ee5147 --- /dev/null +++ b/wireless/ieee802154/mac802154_device.c @@ -0,0 +1,503 @@ +/**************************************************************************** + * drivers/ieee802154/mac802154_device.c + * + * Copyright (C) 2017 Verge Inc. All rights reserved. + * Author: Anthony Merlino + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Device naming ************************************************************/ + +#define DEVNAME_FMT "/dev/ieee%d" +#define DEVNAME_FMTLEN (9 + 3 + 1) + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +struct mac802154_devwrapper_s +{ + FAR struct ieee802154_mac_s *md_mac; /* Saved binding to the mac layer */ + sem_t md_exclsem; /* Exclusive device access */ + + /* The following is a singly linked list of open references to the + * MAC device. + */ + + FAR struct mac802154_open_s *md_open; +}; + +/* This structure describes the state of one open mac driver instance */ + +struct mac802154_open_s +{ + /* Supports a singly linked list */ + + FAR struct mac802154_open_s *md_flink; + + /* The following will be true if we are closing */ + + volatile bool md_closing; +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + + /* Semaphore helpers */ + +static inline int mac802154dev_takesem(sem_t *sem); +#define mac802154dev_givesem(s) sem_post(s); + +static int mac802154dev_open(FAR struct file *filep); +static int mac802154dev_close(FAR struct file *filep); +static ssize_t mac802154dev_read(FAR struct file *filep, FAR char *buffer, + size_t len); +static ssize_t mac802154dev_write(FAR struct file *filep, + FAR const char *buffer, size_t len); +static int mac802154dev_ioctl(FAR struct file *filep, int cmd, + unsigned long arg); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct file_operations mac802154dev_fops = +{ + mac802154dev_open , /* open */ + mac802154dev_close, /* close */ + mac802154dev_read , /* read */ + mac802154dev_write, /* write */ + NULL, /* seek */ + mac802154dev_ioctl /* ioctl */ +#ifndef CONFIG_DISABLE_POLL + , NULL /* poll */ +#endif +#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS + , NULL /* unlink */ +#endif +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: mac802154dev_semtake + * + * Description: + * Acquire the semaphore used for access serialization. + * + ****************************************************************************/ + +static inline int mac802154dev_takesem(sem_t *sem) +{ + /* Take a count from the semaphore, possibly waiting */ + + if (sem_wait(sem) < 0) + { + /* EINTR is the only error that we expect */ + + int errcode = get_errno(); + DEBUGASSERT(errcode == EINTR); + return -errcode; + } + + return OK; +} + +/**************************************************************************** + * Name: mac802154dev_open + * + * Description: + * Open the 802.15.4 MAC character device. + * + ****************************************************************************/ + +static int mac802154dev_open(FAR struct file *filep) +{ + FAR struct inode *inode; + FAR struct mac802154_devwrapper_s *dev; + FAR struct mac802154_open_s *opriv; + int ret; + + DEBUGASSERT(filep != NULL && filep->f_inode != NULL); + inode = filep->f_inode; + + dev = inode->i_private; + DEBUGASSERT(dev != NULL); + + /* Get exclusive access to the MAC driver data structure */ + + ret = mac802154dev_takesem(&dev->md_exclsem); + if (ret < 0) + { + wlerr("ERROR: mac802154dev_takesem failed: %d\n", ret); + return ret; + } + + /* Allocate a new open struct */ + + opriv = (FAR struct mac802154_open_s *)kmm_zalloc(sizeof(struct mac802154_open_s)); + if (!opriv) + { + wlerr("ERROR: Failed to allocate new open struct\n"); + ret = -ENOMEM; + goto errout_with_sem; + } + + /* Attach the open struct to the device */ + + opriv->md_flink = dev->md_open; + dev->md_open = opriv; + + /* Attach the open struct to the file structure */ + + filep->f_priv = (FAR void *)opriv; + ret = OK; + +errout_with_sem: + mac802154dev_givesem(&dev->md_exclsem); + return ret; +} + +/**************************************************************************** + * Name: mac802154dev_close + * + * Description: + * Close the 802.15.4 MAC character device. + * + ****************************************************************************/ + +static int mac802154dev_close(FAR struct file *filep) +{ + FAR struct inode *inode; + FAR struct mac802154_devwrapper_s *dev; + FAR struct mac802154_open_s *opriv; + FAR struct mac802154_open_s *curr; + FAR struct mac802154_open_s *prev; + irqstate_t flags; + bool closing; + int ret; + + DEBUGASSERT(filep && filep->f_priv && filep->f_inode); + opriv = filep->f_priv; + inode = filep->f_inode; + DEBUGASSERT(inode->i_private); + dev = (FAR struct mac802154_devwrapper_s *)inode->i_private; + + /* Handle an improbable race conditions with the following atomic test + * and set. + * + * This is actually a pretty feeble attempt to handle this. The + * improbable race condition occurs if two different threads try to + * close the joystick driver at the same time. The rule: don't do + * that! It is feeble because we do not really enforce stale pointer + * detection anyway. + */ + + flags = enter_critical_section(); + closing = opriv->md_closing; + opriv->md_closing = true; + leave_critical_section(flags); + + if (closing) + { + /* Another thread is doing the close */ + + return OK; + } + + /* Get exclusive access to the driver structure */ + + ret = mac802154dev_takesem(&dev->md_exclsem); + if (ret < 0) + { + wlerr("ERROR: mac802154_takesem failed: %d\n", ret); + return ret; + } + + /* Find the open structure in the list of open structures for the device */ + + for (prev = NULL, curr = dev->md_open; + curr && curr != opriv; + prev = curr, curr = curr->md_flink); + + DEBUGASSERT(curr); + if (!curr) + { + wlerr("ERROR: Failed to find open entry\n"); + ret = -ENOENT; + goto errout_with_exclsem; + } + + /* Remove the structure from the device */ + + if (prev) + { + prev->md_flink = opriv->md_flink; + } + else + { + dev->md_open = opriv->md_flink; + } + + /* And free the open structure */ + + kmm_free(opriv); + + ret = OK; + +errout_with_exclsem: + mac802154dev_givesem(&dev->md_exclsem); + return ret; +} + +/**************************************************************************** + * Name: mac802154dev_read + * + * Description: + * Return the last received packet. + * + ****************************************************************************/ + +static ssize_t mac802154dev_read(FAR struct file *filep, FAR char *buffer, size_t len) +{ + FAR struct inode *inode; + FAR struct mac802154_devwrapper_s *dev; + int ret; + + DEBUGASSERT(filep && filep->f_inode); + inode = filep->f_inode; + DEBUGASSERT(inode->i_private); + dev = (FAR struct mac802154_devwrapper_s *)inode->i_private; + + /* Check to make sure that the buffer is big enough to hold at least one + * packet. + */ + + if (len < sizeof(struct ieee802154_frame_s)) + { + wlerr("ERROR: buffer too small: %lu\n", (unsigned long)len); + return -EINVAL; + } + + /* Get exclusive access to the driver structure */ + + ret = mac802154dev_takesem(&dev->md_exclsem); + if (ret < 0) + { + wlerr("ERROR: mac802154dev_takesem failed: %d\n", ret); + return ret; + } + + /* TODO: Add code to read a packet and return it */ + ret = -ENOTSUP; + + mac802154dev_givesem(&dev->md_exclsem); + return ret; +} + +/**************************************************************************** + * Name: mac802154dev_write + * + * Description: + * Send a packet over the IEEE802.15.4 network. + * + ****************************************************************************/ + +static ssize_t mac802154dev_write(FAR struct file *filep, + FAR const char *buffer, size_t len) +{ + FAR struct inode *inode; + FAR struct mac802154_devwrapper_s *dev; + struct ieee802154_frame_s frame; + int ret; + + DEBUGASSERT(filep && filep->f_inode); + inode = filep->f_inode; + DEBUGASSERT(inode->i_private); + dev = (FAR struct mac802154_devwrapper_s *)inode->i_private; + + /* Check to make sure that the buffer is big enough to hold at least one + * packet. + */ + + if (len < sizeof(struct ieee802154_frame_s)) + { + wlerr("ERROR: buffer too small: %lu\n", (unsigned long)len); + return -EINVAL; + } + + DEBUGASSERT(buffer != NULL); + frame = *(FAR struct ieee802154_frame_s *)buffer; + + /* Get exclusive access to the driver structure */ + + ret = mac802154dev_takesem(&dev->md_exclsem); + if (ret < 0) + { + wlerr("ERROR: mac802154dev_takesem failed: %d\n", ret); + return ret; + } + + /* TODO: Send the frame out */ + ret = -ENOTSUP; + + mac802154dev_givesem(&dev->md_exclsem); + return ret; +} + +/**************************************************************************** + * Name: mac802154dev_ioctl + * + * Description: + * Control the MAC layer via MLME IOCTL commands. + * + ****************************************************************************/ + +static int mac802154dev_ioctl(FAR struct file *filep, int cmd, + unsigned long arg) +{ + FAR struct inode *inode; + FAR struct mac802154_devwrapper_s *dev; + FAR struct ieee802154_mac_s *mac; + int ret; + + DEBUGASSERT(filep != NULL && filep->f_priv != NULL && filep->f_inode != NULL); + inode = filep->f_inode; + DEBUGASSERT(inode->i_private); + dev = (FAR struct mac802154_devwrapper_s *)inode->i_private; + + /* Get exclusive access to the driver structure */ + + ret = mac802154dev_takesem(&dev->md_exclsem); + if (ret < 0) + { + wlerr("ERROR: mac802154dev_takesem failed: %d\n", ret); + return ret; + } + + /* Handle the ioctl command */ + + switch (cmd) + { + default: + wlerr("ERROR: Unrecognized command %ld\n", cmd); + ret = -EINVAL; + break; + } + + mac802154dev_givesem(&dev->md_exclsem); + return ret; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: mac802154dev_register + * + * Description: + * Register a character driver to access the IEEE 802.15.4 MAC layer from + * user-space + * + * Input Parameters: + * mac - Pointer to the mac layer struct to be registerd. + * minor - The device minor number. The IEEE802.15.4 MAC character device + * will be registered as /dev/ieeeN where N is the minor number + * + * Returned Values: + * Zero (OK) is returned on success. Otherwise a negated errno value is + * returned to indicate the nature of the failure. + * + ****************************************************************************/ + +int mac802154dev_register(FAR struct ieee802154_mac_s *mac, int minor) +{ + FAR struct mac802154_devwrapper_s *dev; + char devname[DEVNAME_FMTLEN]; + int ret; + + dev = kmm_zalloc(sizeof(struct mac802154_devwrapper_s)); + if (!dev) + { + wlerr("ERROR: Failed to allocate device structure\n"); + return -ENOMEM; + } + + /* Initialize the new mac driver instance */ + + dev->md_mac = mac; + sem_init(&dev->md_exclsem, 0, 1); /* Allow the device to be opened once before blocking */ + + /* Create the character device name */ + + snprintf(devname, DEVNAME_FMTLEN, DEVNAME_FMT, minor); + + /* Register the mac character driver */ + + ret = register_driver(devname, &mac802154dev_fops, 0666, dev); + if (ret < 0) + { + wlerr("ERROR: register_driver failed: %d\n", ret); + goto errout_with_priv; + } + + return OK; + +errout_with_priv: + sem_destroy(&dev->md_exclsem); + kmm_free(dev); + return ret; +} From 68f2709078663a962d5febc1f5bbba53268f7908 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 29 Mar 2017 11:03:10 -0600 Subject: [PATCH 043/183] Review from last PR --- wireless/ieee802154/mac802154_device.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/wireless/ieee802154/mac802154_device.c b/wireless/ieee802154/mac802154_device.c index 88f36ee5147..0478522834b 100644 --- a/wireless/ieee802154/mac802154_device.c +++ b/wireless/ieee802154/mac802154_device.c @@ -117,10 +117,10 @@ static const struct file_operations mac802154dev_fops = mac802154dev_close, /* close */ mac802154dev_read , /* read */ mac802154dev_write, /* write */ - NULL, /* seek */ + NULL, /* seek */ mac802154dev_ioctl /* ioctl */ #ifndef CONFIG_DISABLE_POLL - , NULL /* poll */ + , NULL /* poll */ #endif #ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS , NULL /* unlink */ @@ -187,7 +187,9 @@ static int mac802154dev_open(FAR struct file *filep) /* Allocate a new open struct */ - opriv = (FAR struct mac802154_open_s *)kmm_zalloc(sizeof(struct mac802154_open_s)); + opriv = (FAR struct mac802154_open_s *) + kmm_zalloc(sizeof(struct mac802154_open_s)); + if (!opriv) { wlerr("ERROR: Failed to allocate new open struct\n"); @@ -294,7 +296,6 @@ static int mac802154dev_close(FAR struct file *filep) /* And free the open structure */ kmm_free(opriv); - ret = OK; errout_with_exclsem: @@ -310,7 +311,8 @@ errout_with_exclsem: * ****************************************************************************/ -static ssize_t mac802154dev_read(FAR struct file *filep, FAR char *buffer, size_t len) +static ssize_t mac802154dev_read(FAR struct file *filep, FAR char *buffer, + size_t len) { FAR struct inode *inode; FAR struct mac802154_devwrapper_s *dev; @@ -356,7 +358,7 @@ static ssize_t mac802154dev_read(FAR struct file *filep, FAR char *buffer, size_ ****************************************************************************/ static ssize_t mac802154dev_write(FAR struct file *filep, - FAR const char *buffer, size_t len) + FAR const char *buffer, size_t len) { FAR struct inode *inode; FAR struct mac802154_devwrapper_s *dev; @@ -413,7 +415,8 @@ static int mac802154dev_ioctl(FAR struct file *filep, int cmd, FAR struct ieee802154_mac_s *mac; int ret; - DEBUGASSERT(filep != NULL && filep->f_priv != NULL && filep->f_inode != NULL); + DEBUGASSERT(filep != NULL && filep->f_priv != NULL && + filep->f_inode != NULL); inode = filep->f_inode; DEBUGASSERT(inode->i_private); dev = (FAR struct mac802154_devwrapper_s *)inode->i_private; @@ -479,7 +482,8 @@ int mac802154dev_register(FAR struct ieee802154_mac_s *mac, int minor) /* Initialize the new mac driver instance */ dev->md_mac = mac; - sem_init(&dev->md_exclsem, 0, 1); /* Allow the device to be opened once before blocking */ + sem_init(&dev->md_exclsem, 0, 1); /* Allow the device to be opened once + * before blocking */ /* Create the character device name */ From e7863aed731b0f5b58a80d469ac1b988ae503cb8 Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Wed, 29 Mar 2017 14:09:27 -0400 Subject: [PATCH 044/183] configs/clicker2-stm32: Adds logic to create an 802.15.4 MAC and register a character driver --- configs/clicker2-stm32/src/stm32_mrf24j40.c | 47 +++++++++++---------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/configs/clicker2-stm32/src/stm32_mrf24j40.c b/configs/clicker2-stm32/src/stm32_mrf24j40.c index f32c9ed2086..17eb70ea96a 100644 --- a/configs/clicker2-stm32/src/stm32_mrf24j40.c +++ b/configs/clicker2-stm32/src/stm32_mrf24j40.c @@ -89,7 +89,6 @@ #endif #define RADIO_DEVNAME "/dev/mrf24j40" -#define MAC_DEVNAME "/dev/mrf24j40mac" /**************************************************************************** * Private Types @@ -256,7 +255,30 @@ static int stm32_mrf24j40_devsetup(FAR struct stm32_priv_s *priv) return -ENODEV; } -#if defined(CONFIG_IEEE802154_DEV) +#if defined(CONFIG_IEEE802154_MAC) + /* Create a 802.15.4 MAC device from a 802.15.4 compatible radio device. */ + + mac = mac802154_create(radio); + if (mac == NULL) + { + wlerr("ERROR: Failed to initialize IEEE802.15.4 MAC\n"); + return -ENODEV; + } +#endif + +#if defined(CONFIG_IEEE802154_MAC_DEV) + /* 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, 0); + if (ret < 0) + { + wlerr("ERROR: Failed to register the MAC character driver ieee%d: %d\n", + 0, ret); + return ret; + } +#elif defined(CONFIG_IEEE802154_DEV) /* Register a character driver to access the IEEE 802.15.4 radio from * user-space */ @@ -268,27 +290,6 @@ 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; From 86dc312ae4ba21f15b0a4d9eec5ba027f7dda3b2 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 2 Apr 2017 16:29:02 -0600 Subject: [PATCH 045/183] iee802154 loopback: Eliminate dependency on CONFIG_NET_LOOPBACK --- wireless/ieee802154/Kconfig | 31 ++ wireless/ieee802154/Make.defs | 4 + wireless/ieee802154/mac802154_loopback.c | 585 +++++++++++++++++++++++ 3 files changed, 620 insertions(+) create mode 100644 wireless/ieee802154/mac802154_loopback.c diff --git a/wireless/ieee802154/Kconfig b/wireless/ieee802154/Kconfig index 5470894a7de..d030f5bd39b 100644 --- a/wireless/ieee802154/Kconfig +++ b/wireless/ieee802154/Kconfig @@ -37,4 +37,35 @@ config IEEE802154_DEV Enables a device driver to expose ieee802.15.4 radio controls to user space as IOCTLs. +config IEEE802154_LOOPBACK + bool "IEEE802154 6loWPAN Loopback" + default n + depends on NET_6LOWPAN && NET_IPv6 + select ARCH_HAVE_NETDEV_STATISTICS + ---help--- + Add support for the IEEE802154 6loWPAN Loopback test device. + +if IEEE802154_LOOPBACK + +choice + prompt "Work queue" + default IEEE802154_LOOPBACK_LPWORK if SCHED_LPWORK + default IEEE802154_LOOPBACK_HPWORK if !SCHED_LPWORK && SCHED_HPWORK + depends on SCHED_WORKQUEUE + ---help--- + Work queue support is required to use the loopback driver. If the + low priority work queue is available, then it should be used by the + loopback driver. + +config IEEE802154_LOOPBACK_HPWORK + bool "High priority" + depends on SCHED_HPWORK + +config IEEE802154_LOOPBACK_LPWORK + bool "Low priority" + depends on SCHED_LPWORK + +endchoice # Work queue +endif # IEEE802154_LOOPBACK + endif # IEEE802154 diff --git a/wireless/ieee802154/Make.defs b/wireless/ieee802154/Make.defs index 4a69b065118..bb2531e3e75 100644 --- a/wireless/ieee802154/Make.defs +++ b/wireless/ieee802154/Make.defs @@ -53,6 +53,10 @@ ifeq ($(CONFIG_IEEE802154_DEV),y) CSRCS += radio802154_device.c endif +ifeq ($(CONFIG_IEEE802154_LOOPBACK),y) +CSRCS += mac802154_loopback.c +endif + DEPPATH += --dep-path ieee802154 VPATH += :ieee802154 CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)wireless$(DELIM)ieee802154} diff --git a/wireless/ieee802154/mac802154_loopback.c b/wireless/ieee802154/mac802154_loopback.c new file mode 100644 index 00000000000..5bbd6f5bebc --- /dev/null +++ b/wireless/ieee802154/mac802154_loopback.c @@ -0,0 +1,585 @@ +/**************************************************************************** + * wireless/iee802154/mac802154_loopback.c + * + * Copyright (C) 2017 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +#ifndef CONFIG_NET_LOOPBACK +# include +#endif + +#ifdef CONFIG_IEEE802154_LOOPBACK + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* We need to have the work queue to handle SPI interrupts */ + +#if !defined(CONFIG_SCHED_WORKQUEUE) +# error Worker thread support is required (CONFIG_SCHED_WORKQUEUE) +#else +# if defined(CONFIG_IEEE802154_LOOPBACK_HPWORK) +# define LPBKWORK HPWORK +# elif defined(CONFIG_IEEE802154_LOOPBACK_LPWORK) +# define LPBKWORK LPWORK +# else +# error Neither CONFIG_IEEE802154_LOOPBACK_HPWORK nor CONFIG_IEEE802154_LOOPBACK_LPWORK defined +# endif +#endif + +/* TX poll delay = 1 seconds. CLK_TCK is the number of clock ticks per second */ + +#define LO_WDDELAY (1*CLK_TCK) + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/* The lo_driver_s encapsulates all state information for a single hardware + * interface + */ + +struct lo_driver_s +{ + bool lo_bifup; /* true:ifup false:ifdown */ + bool lo_txdone; /* One RX packet was looped back */ + WDOG_ID lo_polldog; /* TX poll timer */ + struct work_s lo_work; /* For deferring poll work to the work queue */ + + /* This holds the information visible to the NuttX network */ + + struct ieee802154_driver_s lo_ieee; /* Interface understood by the network */ +}; + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static struct lo_driver_s g_loopback; +static uint8_t g_iobuffer[CONFIG_NET_6LOWPAN_MTU + CONFIG_NET_GUARDSIZE]; + +#ifndef CONFIG_NET_LOOPBACK +static const net_ipv6addr_t g_lo_ipv6addr = +{ + HTONS(0), HTONS(0), HTONS(0), HTONS(0), + HTONS(0), HTONS(0), HTONS(0), HTONS(1) +}; +#endif + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/* Polling logic */ + +static int lo_txpoll(FAR struct net_driver_s *dev); +static void lo_poll_work(FAR void *arg); +static void lo_poll_expiry(int argc, wdparm_t arg, ...); + +/* NuttX callback functions */ + +static int lo_ifup(FAR struct net_driver_s *dev); +static int lo_ifdown(FAR struct net_driver_s *dev); +static void lo_txavail_work(FAR void *arg); +static int lo_txavail(FAR struct net_driver_s *dev); +#if defined(CONFIG_NET_IGMP) || defined(CONFIG_NET_ICMPv6) +static int lo_addmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac); +#ifdef CONFIG_NET_IGMP +static int lo_rmmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac); +#endif +#endif + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: lo_txpoll + * + * Description: + * Check if the network has any outgoing packets ready to send. This is + * a callback from devif_poll() or devif_timer(). devif_poll() will be + * called only during normal TX polling. + * + * Parameters: + * dev - Reference to the NuttX driver state structure + * + * Returned Value: + * OK on success; a negated errno on failure + * + * Assumptions: + * May or may not be called from an interrupt handler. In either case, + * the network is locked. + * + ****************************************************************************/ + +static int lo_txpoll(FAR struct net_driver_s *dev) +{ + FAR struct lo_driver_s *priv = (FAR struct lo_driver_s *)dev->d_private; + FAR struct iob_s *head; + FAR struct iob_s *tail; + FAR struct iob_s *iob; + int ret; + + /* Remove the queued IOBs from driver structure */ + + head = priv->lo_ieee.i_framelist; + + /* Find the tail of the IOB queue */ + + for (tail = NULL, iob = head; + iob != NULL; + tail = iob, iob = iob->io_flink); + + /* Loop while there frames to be sent, i.e., while the IOB list is not + * emtpy. Sending, of course, just means relaying back through the network + * for this driver. + */ + + while (!FRAME_IOB_EMPTY(&priv->lo_ieee)) + { + /* Remove the IOB from the queue */ + + FRAME_IOB_REMOVE(&priv->lo_ieee, iob); + + /* Is the queue now empty? */ + + if (FRAME_IOB_EMPTY(&priv->lo_ieee)) + { + tail = NULL; + } + + /* Return the next frame to the network */ + + iob->io_flink = NULL; + priv->lo_ieee.i_framelist = iob; + + ninfo("Send frame %p to the network. Length=%u\n", iob, iob->io_len); + ret = sixlowpan_input(&priv->lo_ieee); + if (ret < 0) + { + nerr("ERROR: sixlowpan_input returned %d\n", ret); + } + + /* What if the network responds with more frames to send? */ + + if (priv->lo_ieee.i_framelist != NULL) + { + /* Append the new list to the tail of the queue */ + + iob = priv->lo_ieee.i_framelist; + priv->lo_ieee.i_framelist = NULL; + + if (tail == NULL) + { + head = iob; + } + else + { + tail->io_flink = iob; + } + + /* Find the new tail of the IOB queue */ + + for (tail = iob, iob = iob->io_flink; + iob != NULL; + tail = iob, iob = iob->io_flink); + } + + priv->lo_txdone = true; + } + + return 0; +} + +/**************************************************************************** + * Function: lo_poll_work + * + * Description: + * Perform periodic polling from the worker thread + * + * Parameters: + * arg - The argument passed when work_queue() as called. + * + * Returned Value: + * OK on success + * + * Assumptions: + * The network is locked + * + ****************************************************************************/ + +static void lo_poll_work(FAR void *arg) +{ + FAR struct lo_driver_s *priv = (FAR struct lo_driver_s *)arg; + + /* Perform the poll */ + + net_lock(); + priv->lo_txdone = false; + (void)devif_timer(&priv->lo_ieee.i_dev, lo_txpoll); + + /* Was something received and looped back? */ + + while (priv->lo_txdone) + { + /* Yes, poll again for more TX data */ + + priv->lo_txdone = false; + (void)devif_poll(&priv->lo_ieee.i_dev, lo_txpoll); + } + + /* Setup the watchdog poll timer again */ + + (void)wd_start(priv->lo_polldog, LO_WDDELAY, lo_poll_expiry, 1, priv); + net_unlock(); +} + +/**************************************************************************** + * Function: lo_poll_expiry + * + * Description: + * Periodic timer handler. Called from the timer interrupt handler. + * + * Parameters: + * argc - The number of available arguments + * arg - The first argument + * + * Returned Value: + * None + * + * Assumptions: + * The network is locked. + * + ****************************************************************************/ + +static void lo_poll_expiry(int argc, wdparm_t arg, ...) +{ + FAR struct lo_driver_s *priv = (FAR struct lo_driver_s *)arg; + + /* Schedule to perform the interrupt processing on the worker thread. */ + + work_queue(LPBKWORK, &priv->lo_work, lo_poll_work, priv, 0); +} + +/**************************************************************************** + * Function: lo_ifup + * + * Description: + * NuttX Callback: Bring up the Ethernet interface when an IP address is + * provided + * + * Parameters: + * dev - Reference to the NuttX driver state structure + * + * Returned Value: + * None + * + * Assumptions: + * + ****************************************************************************/ + +static int lo_ifup(FAR struct net_driver_s *dev) +{ + FAR struct lo_driver_s *priv = (FAR struct lo_driver_s *)dev->d_private; + +#if CONFIG_NET_6LOWPAN_RIMEADDR_SIZE == 2 + ninfo("Bringing up: Rime %02x:%02x PANID=%04x\n", + dev->d_ipv6addr[0], dev->d_ipv6addr[1], priv->lo_ieee.i_panid); +#elif CONFIG_NET_6LOWPAN_RIMEADDR_SIZE == 8 + ninfo("Bringing up: Rime %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x PANID=%04x\n", + dev->d_ipv6addr[0], dev->d_ipv6addr[1], dev->d_ipv6addr[2], + dev->d_ipv6addr[3], dev->d_ipv6addr[4], dev->d_ipv6addr[5], + dev->d_ipv6addr[6], dev->d_ipv6addr[7], priv->lo_ieee.i_panid); +#endif + + /* Set and activate a timer process */ + + (void)wd_start(priv->lo_polldog, LO_WDDELAY, lo_poll_expiry, + 1, (wdparm_t)priv); + + priv->lo_bifup = true; + return OK; +} + +/**************************************************************************** + * Function: lo_ifdown + * + * Description: + * NuttX Callback: Stop the interface. + * + * Parameters: + * dev - Reference to the NuttX driver state structure + * + * Returned Value: + * None + * + * Assumptions: + * + ****************************************************************************/ + +static int lo_ifdown(FAR struct net_driver_s *dev) +{ + FAR struct lo_driver_s *priv = (FAR struct lo_driver_s *)dev->d_private; + + /* Cancel the TX poll timer and TX timeout timers */ + + wd_cancel(priv->lo_polldog); + + /* Mark the device "down" */ + + priv->lo_bifup = false; + return OK; +} + +/**************************************************************************** + * Function: lo_txavail_work + * + * Description: + * Perform an out-of-cycle poll on the worker thread. + * + * Parameters: + * arg - Reference to the NuttX driver state structure (cast to void*) + * + * Returned Value: + * None + * + * Assumptions: + * Called on the higher priority worker thread. + * + ****************************************************************************/ + +static void lo_txavail_work(FAR void *arg) +{ + FAR struct lo_driver_s *priv = (FAR struct lo_driver_s *)arg; + + /* Ignore the notification if the interface is not yet up */ + + net_lock(); + if (priv->lo_bifup) + { + do + { + /* If so, then poll the network for new XMIT data */ + + priv->lo_txdone = false; + (void)devif_poll(&priv->lo_ieee.i_dev, lo_txpoll); + } + while (priv->lo_txdone); + } + + net_unlock(); +} + +/**************************************************************************** + * Function: lo_txavail + * + * Description: + * Driver callback invoked when new TX data is available. This is a + * stimulus perform an out-of-cycle poll and, thereby, reduce the TX + * latency. + * + * Parameters: + * dev - Reference to the NuttX driver state structure + * + * Returned Value: + * None + * + * Assumptions: + * Called in normal user mode + * + ****************************************************************************/ + +static int lo_txavail(FAR struct net_driver_s *dev) +{ + FAR struct lo_driver_s *priv = (FAR struct lo_driver_s *)dev->d_private; + + /* Is our single work structure available? It may not be if there are + * pending interrupt actions and we will have to ignore the Tx + * availability action. + */ + + if (work_available(&priv->lo_work)) + { + /* Schedule to serialize the poll on the worker thread. */ + + work_queue(LPBKWORK, &priv->lo_work, lo_txavail_work, priv, 0); + } + + return OK; +} + +/**************************************************************************** + * Function: lo_addmac + * + * Description: + * NuttX Callback: Add the specified MAC address to the hardware multicast + * address filtering + * + * Parameters: + * dev - Reference to the NuttX driver state structure + * mac - The MAC address to be added + * + * Returned Value: + * None + * + * Assumptions: + * + ****************************************************************************/ + +#if defined(CONFIG_NET_IGMP) || defined(CONFIG_NET_ICMPv6) +static int lo_addmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac) +{ + /* There is no multicast support in the loopback driver */ + + return OK; +} +#endif + +/**************************************************************************** + * Function: lo_rmmac + * + * Description: + * NuttX Callback: Remove the specified MAC address from the hardware multicast + * address filtering + * + * Parameters: + * dev - Reference to the NuttX driver state structure + * mac - The MAC address to be removed + * + * Returned Value: + * None + * + * Assumptions: + * + ****************************************************************************/ + +#ifdef CONFIG_NET_IGMP +static int lo_rmmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac) +{ + /* There is no multicast support in the loopback driver */ + + return OK; +} +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: localhost_initialize + * + * Description: + * Initialize the Ethernet controller and driver + * + * Parameters: + * intf - In the case where there are multiple EMACs, this value + * identifies which EMAC is to be initialized. + * + * Returned Value: + * OK on success; Negated errno on failure. + * + * Assumptions: + * + ****************************************************************************/ + +int localhost_initialize(void) +{ + FAR struct lo_driver_s *priv; + FAR struct net_driver_s *dev; + + /* Get the interface structure associated with this interface number. */ + + priv = &g_loopback; + + /* Initialize the driver structure */ + + memset(priv, 0, sizeof(struct lo_driver_s)); + + dev = &priv->lo_ieee.i_dev; + dev->d_ifup = lo_ifup; /* I/F up (new IP address) callback */ + dev->d_ifdown = lo_ifdown; /* I/F down callback */ + dev->d_txavail = lo_txavail; /* New TX data callback */ +#ifdef CONFIG_NET_IGMP + dev->d_addmac = lo_addmac; /* Add multicast MAC address */ + dev->d_rmmac = lo_rmmac; /* Remove multicast MAC address */ +#endif + dev->d_buf = g_iobuffer; /* Attach the IO buffer */ + dev->d_private = (FAR void *)priv; /* Used to recover private state from dev */ + + /* Create a watchdog for timing polling for and timing of transmissions */ + + priv->lo_polldog = wd_create(); /* Create periodic poll timer */ + + /* Register the loopabck device with the OS so that socket IOCTLs can b + * performed. + */ + + (void)netdev_register(&priv->lo_ieee.i_dev, NET_LL_IEEE802154); + + /* Set the local loopback IP address */ + + net_ipv6addr_copy(dev->d_ipv6addr, g_lo_ipv6addr); + net_ipv6addr_copy(dev->d_ipv6draddr, g_lo_ipv6addr); + net_ipv6addr_copy(dev->d_ipv6netmask, g_ipv6_alloneaddr); + + /* Put the network in the UP state */ + + dev->d_flags = IFF_UP; + return lo_ifup(&priv->lo_ieee.i_dev); +} + +#endif /* CONFIG_IEEE802154_LOOPBACK */ From cd643394131720b569a888921b02eb1cc10a0fb4 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 3 Apr 2017 15:31:18 -0600 Subject: [PATCH 046/183] Still try to recover from bad merge. --- wireless/ieee802154/Kconfig | 8 -------- 1 file changed, 8 deletions(-) diff --git a/wireless/ieee802154/Kconfig b/wireless/ieee802154/Kconfig index 90d20d07d64..b46aada66d0 100644 --- a/wireless/ieee802154/Kconfig +++ b/wireless/ieee802154/Kconfig @@ -45,14 +45,6 @@ config IEEE802154_LOOPBACK ---help--- Add support for the IEEE802154 6loWPAN Loopback test device. -config IEEE802154_LOOPBACK - bool "IEEE802154 6loWPAN Loopback" - default n - depends on NET_6LOWPAN && NET_IPv6 - select ARCH_HAVE_NETDEV_STATISTICS - ---help--- - Add support for the IEEE802154 6loWPAN Loopback test device. - if IEEE802154_LOOPBACK choice From aada26f90397c5ef0e743b3c2fc17b322f2f82f9 Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Wed, 5 Apr 2017 15:03:47 -0400 Subject: [PATCH 047/183] wireless/ieee802154: Defines more data types/macros. Some renaming and cleanup --- .../wireless/ieee802154/ieee802154_mac.h | 456 +++++++++++++----- wireless/ieee802154/mac802154.c | 167 +++---- 2 files changed, 417 insertions(+), 206 deletions(-) diff --git a/include/nuttx/wireless/ieee802154/ieee802154_mac.h b/include/nuttx/wireless/ieee802154/ieee802154_mac.h index 19af457bf65..13191bfa405 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_mac.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_mac.h @@ -2,7 +2,13 @@ * include/nuttx/wireless/ieee802154/ieee802154_mac.h * * Copyright (C) 2016 Sebastien Lorquet. All rights reserved. + * Copyright (C) 2017 Verge Inc. All rights reserved. + * * Author: Sebastien Lorquet + * Author: Anthony Merlino + * + * The naming and comments for various fields are taken directly + * from the IEEE 802.15.4 2011 standard. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -142,29 +148,40 @@ /* IEEE 802.15.4 PHY constants */ -#define IEEE802154_aMaxPHYPacketSize 127 -#define IEEE802154_aTurnaroundTime 12 /*symbol periods*/ +#define IEEE802154_MAX_PHY_PACKET_SIZE 127 +#define IEEE802154_TURN_AROUND_TIME 12 /*symbol periods*/ /* IEEE 802.15.4 MAC constants */ -#define IEEE802154_aBaseSlotDuration 60 -#define IEEE802154_aNumSuperframeSlots 16 -#define IEEE802154_aBaseSuperframeDuration (IEEE802154_aBaseSlotDuration * IEEE802154_aNumSuperframeSlots) -#define IEEE802154_aMaxBE 5 -#define IEEE802154_aMaxBeaconOverhead 75 -#define IEEE802154_aMaxBeaconPayloadLength (IEEE802154_aMaxPHYPacketSize - IEEE802154_aMaxBeaconOverhead) -#define IEEE802154_aGTSDescPersistenceTime 4 -#define IEEE802154_aMaxFrameOverhead 25 -#define IEEE802154_aMaxFrameResponseTime 1220 -#define IEEE802154_aMaxFrameRetries 3 -#define IEEE802154_aMaxLostBeacons 4 -#define IEEE802154_aMaxMACFrameSize (IEEE802154_aMaxPHYPacketSize - IEEE802154_aMaxFrameOverhead) -#define IEEE802154_aMaxSIFSFrameSize 18 -#define IEEE802154_aMinCAPLength 440 -#define IEEE802154_aMinLIFSPeriod 40 -#define IEEE802154_aMinSIFSPeriod 12 -#define IEEE802154_aResponseWaitTime (32 * IEEE802154_aBaseSuperframeDuration) -#define IEEE802154_aUnitBackoffPeriod 20 +#define IEEE802154_BASE_SLOT_DURATION 60 +#define IEEE802154_NUM_SUPERFRAME_SLOTS 16 + +#define IEEE802154_BASE_SUPERFRAME_DURATION \ + (IEEE802154_BASE_SLOT_DURATION * IEEE802154_NUM_SUPERFRAME_SLOTS) + +#define IEEE802154_GTS_DESC_PERSISTENCE_TIME 4 +#define IEEE802154_MAX_BEACON_OVERHEAD 75 + +#define IEEE802154_MAX_BEACON_PAYLOAD_LENGTH \ + (IEEE802154_MAX_PHY_PACKET_SIZE - IEEE802154_MAX_BEACON_OVERHEAD) + +#define IEEE802154_MAX_LOST_BEACONS 4 +#define IEEE802514_MIN_MPDU_OVERHEAD 9 +#define IEEE802154_MAX_MPDU_UNSEC_OVERHEAD 25 + +#define IEEE802154_MAX_SAFE_MAC_PAYLOAD_SIZE \ + (IEEE802154_MAX_PHY_PACKET_SIZE - IEEE802154_MAX_MPDU_UNSEC_OVERHEAD) + +#define IEEE802154_MAX_MAC_PAYLOAD_SIZE \ + (IEEE802154_MAX_PHY_PACKET_SIZE - IEEE802154_MIN_MPDU_OVERHEAD) + +#define IEEE802154_MAX_SIFS_FRAME_SIZE 18 +#define IEEE802154_MIN_CAP_LENGTH 440 +#define IEEE802154_UNIT_BACKOFF_PERIOD 20 + +/* IEEE 802.15.4 MAC PIB Attribut Defaults */ + +// TODO: Add macros /**************************************************************************** * Public Types @@ -200,41 +217,100 @@ enum ieee802154_status_e /* IEEE 802.15.4 PHY/MAC PIB attributes IDs */ -enum +enum ieee802154_pib_attr_e { - IEEE802154_phyCurrentChannel = 0x00, - IEEE802154_phyChannelsSupported, - IEEE802154_phyTransmitPower, - IEEE802154_phyCCAMode, - IEEE802154_macAckWaitDuration = 0x40, - IEEE802154_macAssociationPermit, - IEEE802154_macAutoRequest, - IEEE802154_macBattLifeExt, - IEEE802154_macBattLifeExtPeriods, - IEEE802154_macBeaconPayload, - IEEE802154_macBeaconPayloadLength, - IEEE802154_macBeaconOrder, - IEEE802154_macBeaconTxTime, - IEEE802154_macBSN, - IEEE802154_macCoordExtendedAddress, - IEEE802154_macCoordShortAddress, - IEEE802154_macDSN, - IEEE802154_macGTSPermit, - IEEE802154_macMaxCSMABackoffs, - IEEE802154_macMinBE, - IEEE802154_macPANId, - IEEE802154_macPromiscuousMode, - IEEE802154_macRxOnWhenIdle, - IEEE802154_macShortAddress, - IEEE802154_macSuperframeOrder, - IEEE802154_macTransactionPersistenceTime, - IEEE802154_macACLEntryDescriptorSet = 0x70, - IEEE802154_macACLEntryDescriptorSetSize, - IEEE802154_macDefaultSecurity, - IEEE802154_macDefaultSecurityMaterialLength, - IEEE802154_macDefaultSecurityMaterial, - IEEE802154_macDefaultSecuritySuite, - IEEE802154_macSecurityMode + /* PHY PIB Attributes */ + + IEEE802154_PIB_PHY_CURRENT_CHANNEL = 0x00, + IEEE802154_PIB_PHY_CHANNELS_SUPPORTED, + IEEE802154_PIB_PHY_TX_POWER_TOLERANCE, + IEEE802154_PIB_PHY_TX_POWER, + IEEE802154_PIB_PHY_CCA_MODE, + IEEE802154_PIB_PHY_CURRENT_PAGE, + IEEE802154_PIB_PHY_MAX_FRAME_DURATION, + IEEE802154_PIB_PHY_SHR_DURATION, + IEEE802154_PIB_PHY_SYM_PER_OCTET, + IEEE802154_PIB_PHY_PREAMBLE_SYM_LEN, + IEEE802154_PIB_PHY_UWB_DATARATES_SUP, + IEEE802154_PIB_PHY_CSS_LOW_DATARATE_SUP, + IEEE802154_PIB_PHY_UWB_COU_PULSES_SUP, + IEEE802154_PIB_PHY_UWB_CS_PULSES_SUP, + IEEE802154_PIB_PHY_UWB_LCP_PULSES_SUP, + IEEE802154_PIB_PHY_UWB_CURR_PULSE_SHAPE, + IEEE802154_PIB_PHY_UWB_COU_PULSE, + IEEE802154_PIB_PHY_UWB_CS_PULSE, + IEEE802154_PIB_PHY_UWB_LCP_WEIGHT1, + IEEE802154_PIB_PHY_UWB_LCP_WEIGHT2, + IEEE802154_PIB_PHY_UWB_LCP_WEIGHT3, + IEEE802154_PIB_PHY_UWB_LCP_WEIGHT4, + IEEE802154_PIB_PHY_UWB_LCP_DELAY2, + IEEE802154_PIB_PHY_UWB_LCP_DELAY3, + IEEE802154_PIB_PHY_UWB_LCP_DELAY4, + IEEE802154_PIB_PHY_RANGING, + IEEE802154_PIB_PHY_RANGING_CRYSTAL_OFFSET, + IEEE802154_PIB_PHY_RANGING_DPS, + IEEE802154_PIB_PHY_CURRENT_CODE, + IEEE802154_PIB_PHY_NATIVE_PRF, + IEEE802154_PIB_PHY_UWB_SCAN_BINS_PER_CHAN, + IEEE802154_PIB_PHY_UWB_INS_PREAMBLE_INTERVAL, + IEEE802154_PIB_PHY_UWB_TX_RMARKER, + IEEE802154_PIB_PHY_UWB_RX_RMARKER, + IEEE802154_PIB_PHY_RFRAME_PROC_TIME, + IEEE802154_PIB_PHY_CCA_DURATION, + + /* MAC PIB Attributes */ + + IEEE802154_PIB_MAC_EXTENDED_ADDR = 0x40, + IEEE802154_PIB_MAC_ACK_WAIT_DUR, + IEEE802154_PIB_MAC_ASSOCIATED_PANCOORD, + IEEE802154_PIB_MAC_ASSOCIATION_PERMIT, + IEEE802154_PIB_MAC_AUTO_REQUEST, + IEEE802154_PIB_MAC_BATT_LIFE_EXT, + IEEE802154_PIB_MAC_BATT_LIFE_EXT_PERIODS, + IEEE802154_PIB_MAC_BEACON_PAYLOAD, + IEEE802154_PIB_MAC_BEACON_PAYLOAD_LEN, + IEEE802154_PIB_MAC_BEACON_ORDER, + IEEE802154_PIB_MAC_BEACON_TX_TIME, + IEEE802154_PIB_MAC_BSN, + IEEE802154_PIB_MAC_COORD_EXT_ADDR, + IEEE802154_PIB_MAC_COORD_SHORT_ADDR, + IEEE802154_PIB_MAC_DSN, + IEEE802154_PIB_MAC_GTS_PERMIT, + IEEE802154_PIB_MAC_MAX_BE, + IEEE802154_PIB_MAC_MAX_CSMA_BACKOFFS, + IEEE802154_PIB_MAC_FRAME_TOTAL_WAIT_TIME, + IEEE802154_PIB_MAC_MAX_FRAME_RETRIES, + IEEE802154_PIB_MAC_MIN_BE, + IEEE802154_PIB_MAC_LIFS_PERIOD, + IEEE802154_PIB_MAC_SIFS_PERIOD, + IEEE802154_PIB_MAC_PAN_ID, + IEEE802154_PIB_MAC_PROMISCUOUS_MODE, + IEEE802154_PIB_MAC_RANGING_SUPPORT, + IEEE802154_PIB_MAC_RESPONSE_WAIT_TIME, + IEEE802154_PIB_MAC_RX_ON_WHEN_IDLE, + IEEE802154_PIB_MAC_SECURITY_ENABLED, + IEEE802154_PIB_MAC_SHORT_ADDRESS, + IEEE802154_PIB_MAC_SUPERFRAME_ORDER, + IEEE802154_PIB_MAC_SYNC_SYMBOL_OFFSET, + IEEE802154_PIB_MAC_TIMESTAMP_SUPPORT, + IEEE802154_PIB_MAC_TRANSACTION_PERSIST_TIME, + IEEE802154_PIB_MAC_TX_CTRL_ACTIVE_DUR, + IEEE802154_PIB_MAC_TX_CTRL_PAUSE_DUR, + IEEE802154_PIB_MAC_TX_TOTAL_DUR, + + /* MAC Security Attributes */ + + IEEE802154_PIB_MAC_KEY_TABLE = 0x70, + IEEE802154_PIB_MAC_DEV_TABLE, + IEEE802154_PIB_MAC_SEC_LVL_TABLE, + IEEE802154_PIB_MAC_FRAME_COUNTER, + IEEE802154_PIB_MAC_AUTOREQ_SEC_LVL, + IEEE802154_PIB_MAC_AUTOREQ_KEY_ID_MODE, + IEEE802154_PIB_MAC_AUTOREQ_KEY_SOURCE, + IEEE802154_PIB_MAC_AUTOREQ_KEY_INDEX, + IEEE802154_PIB_MAC_DEFAULT_KEY_SRC, + IEEE802154_PIB_MAC_PANCOORD_EXT_ADDR, + IEEE802154_PIB_MAC_PANCOORD_SHORT_ADDR, }; /* IEEE 802.15.4 Device address @@ -253,12 +329,15 @@ enum ieee802154_addr_mode_e struct ieee802154_addr_s { - enum ieee802154_addr_mode_e ia_mode; /* Address mode. Short or Extended */ - uint16_t ia_panid; /* PAN identifier, can be IEEE802154_PAN_UNSPEC */ + /* Address mode. Short or Extended */ + + enum ieee802154_addr_mode_e ia_mode; + + uint16_t ia_panid; /* PAN identifier, can be IEEE802154_PAN_UNSPEC */ union { - uint16_t _ia_saddr; /* short address */ - uint8_t _ia_eaddr[8]; /* extended address */ + uint16_t _ia_saddr; /* short address */ + uint8_t _ia_eaddr[8]; /* extended address */ } ia_addr; #define ia_saddr ia_addr._ia_saddr @@ -305,6 +384,42 @@ struct ieee802154_framecontrol_s uint16_t src_addr_mode : 2; }; +#ifdef CONFIG_IEEE802154_SECURITY +struct ieee802154_security_s +{ + uint8_t level; /* Security level to be used */ + uint8_t key_id_mode; /* Mode used to identify the key to be used */ + uint8_t key_source[8]; /* Originator of the key to be used */ + uint8_t key_index; /* Index of the key to be used */ +}; +#endif + +#ifdef CONFIG_IEEE802154_UWB +enum ieee802154_uwbprf_e +{ + IEEE802154_UWBPRF_OFF = 0, + IEEE802154_UWBPRF_4M, + IEEE802154_UWBPRF_16M, + IEEE802154_UWBPRF_64M +}; + +enum ieee802154_uwb_datarate_e +{ + IEEE802154_UWB_DATARATE_0 = 0, + IEEE802154_UWB_DATARATE_16, + IEEE802154_UWB_DATARATE_64, + IEEE802154_UWB_DATARATE_1024, + IEEE802154_UWB_DATARATE_4096 +}; +#endif + +enum ieee802154_ranging_e +{ + IEEE802154_NON_RANGING = 0, + IEEE802154_ALL_RANGING, + IEEE802154_PHY_HEADER_ONLY +}; + struct ieee802154_frame_s { struct ieee802154_framecontrol_s frame_control; @@ -318,6 +433,99 @@ struct ieee802154_frame_s uint16_t fcs; }; +struct ieee802154_data_req_s +{ + enum ieee802154_addr_mode_e src_addr_mode; /* Source Address Mode */ + struct ieee802154_addr_s dest__addr; /* Destination Address */ + + /* Number of bytes contained in the MAC Service Data Unit (MSDU) + * to be transmitted by the MAC sublayer enitity + * Note: This could be a uint8_t but if anyone ever wants to use + * non-standard frame lengths, they may want a length larger than + * a uint8_t */ + + uint16_t msdu_length; + + + uint8_t msdu_handle; /* Handle assoc. with MSDU */ + struct { + uint8_t ack_tx : 1; /* Acknowledge TX? */ + uint8_t gts_tx : 1; /* 1=GTS used for TX, 0=CAP used for TX */ + uint8_t indirect_tx : 1; /* Should indirect transmission be used? */ + }; + +#ifdef CONFIG_IEEE802154_SECURITY + /* Security information if enabled */ + + struct ieee802154_security_s security; +#endif + +#ifdef CONFIG_IEEE802154_UWB + /* The UWB Pulse Repetion Frequency to be used for the transmission */ + + enum ieee802154_uwbprf_e uwb_prf; + + /* The UWB preamble symbol repititions + * Should be one of: + * 0, 16, 64, 1024, 4096 */ + + uint16_t uwb_presym_rep; + + /* The UWB Data Rate to be used for the transmission */ + + enum ieee802154_uwb_datarate_e data_rate; +#endif + + enum ieee802154_ranging_e ranging; + + /* The MAC service data unit array that is to be transmitted + * This must be at the end of the struct to allow the array + * to continue and make the struct "variable length" */ + + uint8_t msdu[1]; +}; +#define SIZEOF_IEEE802154_DATA_REQ_S(n) \ + (sizeof(struct ieee802154_data_req_s) + (n)) + +struct ieee802154_data_conf_s +{ + uint8_t msdu_handle; /* Handle assoc. with MSDU */ + + /* The time, in symbols, at which the data were transmitted */ + + uint32_t timestamp; + + enum ieee802154_status_e status; /* The status of the MSDU transmission */ + +#ifdef CONFIG_IEEE802154_RANGING + bool rng_rcvd; /* Ranging indicated by MSDU */ + + /* A count of the time units corresponding to an RMARKER at the antenna at + * the beginning of the ranging exchange */ + + uint32_t rng_counter_start; + + /* A count of the time units corresponding to an RMARKER at the antenna at + * end of the ranging exchange */ + + uint32_t rng_counter_stop; + + /* A count of the time units in a message exchange over which the tracking + * offset was measured */ + + uint34_t rng_tracking_interval; + + /* A count of the time units slipped or advanced by the radio tracking + * system over the course of the entire tracking interval */ + + uint32_t rng_offset; + + /* The Figure of Merit (FoM) characterizing the ranging measurement */ + + uint8_t rng_fom; +#endif +}; + struct ieee802154_capability_info_s { uint8_t reserved_0 : 1; /* Reserved */ @@ -331,16 +539,6 @@ struct ieee802154_capability_info_s * 0=otherwise */ }; -#ifdef CONFIG_IEEE802154_SECURITY -struct ieee802154_security_s -{ - uint8_t level; /* Security level to be used */ - uint8_t key_id_mode; /* Mode used to identify the key to be used */ - uint8_t key_source[8]; /* Originator of the key to be used */ - uint8_t key_index; /* Index of the key to be used */ -}; -#endif - struct ieee802154_superframe_spec_s { uint16_t beacon_order : 4; /* Transmission interval of beacon */ @@ -367,7 +565,7 @@ struct ieee802154_pan_desc_s uint8_t gts_permit; /* 0=No GTS requests allowed * 1=GTS request allowed */ - uint8_t link_quality; /* LQI at which beacon was received */ + uint8_t lqi; /* Link Quality Indication of the beacon */ uint32_t timestamp; /* Time at which the beacon frame was received * in symbols */ }; @@ -390,7 +588,7 @@ struct ieee802154_pend_addr_s /* Primitive Semantics */ -struct ieee802154_assoc_request_s +struct ieee802154_assoc_req_s { uint8_t channel; /* Channel number to attempt association */ uint8_t channel_page; /* Channel page to attempt association */ @@ -410,7 +608,7 @@ struct ieee802154_assoc_request_s #endif }; -struct ieee802154_assoc_indication_s +struct ieee802154_assoc_ind_s { /* Address of device requesting association. Always in extended mode */ @@ -427,7 +625,7 @@ struct ieee802154_assoc_indication_s #endif }; -struct ieee802154_assoc_response_s +struct ieee802154_assoc_rsp_s { /* Address of device requesting association. Always in extended mode */ @@ -444,7 +642,7 @@ struct ieee802154_assoc_response_s #endif }; -struct ieee802154_assoc_confirm_s +struct ieee802154_assoc_conf_s { /* Associated device address ALWAYS passed in short address mode. The * address will be IEEE802154_SADDR_UNSPEC if association was unsuccessful */ @@ -462,7 +660,7 @@ struct ieee802154_assoc_confirm_s #endif }; -struct ieee802154_disassoc_request_s +struct ieee802154_disassoc_req_s { /* Address of device to send disassociation notification */ @@ -481,7 +679,7 @@ struct ieee802154_disassoc_request_s #endif }; -struct ieee802154_disassoc_indication_s +struct ieee802154_disassoc_ind_s { /* Address of device requesting disassociation. Always extended mode */ @@ -498,7 +696,7 @@ struct ieee802154_disassoc_indication_s #endif }; -struct ieee802154_disassoc_confirm_s +struct ieee802154_disassoc_conf_s { /* Status of the disassociation attempt */ @@ -509,7 +707,7 @@ struct ieee802154_disassoc_confirm_s struct ieee802154_addr_s dev_addr; }; -struct ieee802154_beaconnotify_indication_s +struct ieee802154_beaconnotify_ind_s { uint8_t bsn; /* Beacon sequence number */ @@ -526,8 +724,11 @@ struct ieee802154_beaconnotify_indication_s /* Beacon payload */ - uint8_t sdu[IEEE802154_aMaxBeaconPayloadLength]; + uint8_t sdu[IEEE802154_MAX_BEACON_PAYLOAD_LENGTH]; }; +#define SIZEOF_IEEE802154_BEACONNOTIFY_IND_S(n) \ + (sizeof(struct ieee802154_beaconnotify_ind_s) \ + - IEEE802154_MAX_BEACON_PAYLOAD_LENGTH + (n)) /* Operations */ @@ -539,8 +740,8 @@ struct ieee802154_macops_s /* Transmit a data frame */ - CODE int (*req_data)(FAR struct ieee802154_mac_s *mac, uint8_t handle, - FAR uint8_t *buf, int len); + CODE int (*req_data)(FAR struct ieee802154_mac_s *mac, + FAR struct ieee802154_data_req_s *req); /* Cancel transmission of a data frame */ @@ -549,16 +750,17 @@ struct ieee802154_macops_s /* Start association with coordinator */ CODE int (*req_associate)(FAR struct ieee802154_mac_s *mac, - uint16_t panid, FAR uint8_t *coordeadr); + FAR struct ieee802154_assoc_req_s *req); /* Start disassociation with coordinator */ CODE int (*req_disassociate)(FAR struct ieee802154_mac_s *mac, - FAR uint8_t *eadr, uint8_t reason); + FAR struct ieee802154_disassoc_req_s *req); /* Read the PIB */ - CODE int (*req_get)(FAR struct ieee802154_mac_s *mac, int attribute); + CODE int (*req_get)(FAR struct ieee802154_mac_s *mac, + enum ieee802154_pib_attr_e attr); /* Allocate or deallocate a GTS */ @@ -612,94 +814,98 @@ struct ieee802154_macops_s struct ieee802154_maccb_s { + /* Context arg for handling callback */ + + FAR void *cb_context; + /* Asynchronous confirmations to requests */ /* Data frame was received by remote device */ - CODE int (*conf_data)(FAR struct ieee802154_mac_s *mac, - FAR uint8_t *buf, int len); + CODE void (*conf_data)(FAR struct ieee802154_mac_s *mac, + FAR struct ieee802154_data_conf_s *conf); /* Data frame was purged */ - CODE int (*conf_purge)(FAR struct ieee802154_mac_s *mac, uint8_t handle, - int status); + CODE void (*conf_purge)(FAR struct ieee802154_mac_s *mac, uint8_t handle, + int status); /* Association request completed */ - CODE int (*conf_associate)(FAR struct ieee802154_mac_s *mac, - uint16_t saddr, int status); + CODE void (*conf_associate)(FAR struct ieee802154_mac_s *mac, + uint16_t saddr, int status); /* Disassociation request completed */ - CODE int (*conf_disassociate)(FAR struct ieee802154_mac_s *mac, - int status); + CODE void (*conf_disassociate)(FAR struct ieee802154_mac_s *mac, + int status); - /* PIB data returned */ + /* PIvoata returned */ - CODE int (*conf_get)(FAR struct ieee802154_mac_s *mac, int status, - int attribute, FAR uint8_t *value, - int valuelen); + CODE void (*conf_get)(FAR struct ieee802154_mac_s *mac, int status, + int attribute, FAR uint8_t *value, + int valuelen); - /* GTS management completed */ + /* GTvoanagement completed */ - CODE int (*conf_gts)(FAR struct ieee802154_mac_s *mac, - FAR uint8_t *characteristics, int status); + CODE void (*conf_gts)(FAR struct ieee802154_mac_s *mac, + FAR uint8_t *characteristics, int status); - /* MAC reset completed */ + /* MAveset completed */ - CODE int (*conf_reset)(FAR struct ieee802154_mac_s *mac, int status); + CODE void (*conf_reset)(FAR struct ieee802154_mac_s *mac, int status); - CODE int (*conf_rxenable)(FAR struct ieee802154_mac_s *mac, int status); + CODE void (*conf_rxenable)(FAR struct ieee802154_mac_s *mac, int status); - CODE int (*conf_scan)(FAR struct ieee802154_mac_s *mac, int status, - uint8_t type, uint32_t unscanned, int rsltsize, - FAR uint8_t *edlist, FAR uint8_t *pandescs); + CODE void (*conf_scan)(FAR struct ieee802154_mac_s *mac, int status, + uint8_t type, uint32_t unscanned, int rsltsize, + FAR uint8_t *edlist, FAR uint8_t *pandescs); - CODE int (*conf_set)(FAR struct ieee802154_mac_s *mac, int status, - int attribute); + CODE void (*conf_set)(FAR struct ieee802154_mac_s *mac, int status, + int attribute); - CODE int (*conf_start)(FAR struct ieee802154_mac_s *mac, int status); + CODE void (*conf_start)(FAR struct ieee802154_mac_s *mac, int status); - CODE int (*conf_poll)(FAR struct ieee802154_mac_s *mac, int status); + CODE void (*conf_poll)(FAR struct ieee802154_mac_s *mac, int status); /* Asynchronous event indications, replied to synchronously with responses */ /* Data frame received */ - CODE int (*ind_data)(FAR struct ieee802154_mac_s *mac, FAR uint8_t *buf, - int len); + CODE void (*ind_data)(FAR struct ieee802154_mac_s *mac, FAR uint8_t *buf, + int len); /* Association request received */ - CODE int (*ind_associate)(FAR struct ieee802154_mac_s *mac, - uint16_t clipanid, FAR uint8_t *clieaddr); + CODE void (*ind_associate)(FAR struct ieee802154_mac_s *mac, + uint16_t clipanid, FAR uint8_t *clieaddr); /* Disassociation request received */ - CODE int (*ind_disassociate)(FAR struct ieee802154_mac_s *mac, - FAR uint8_t *eadr, uint8_t reason); + CODE void (*ind_disassociate)(FAR struct ieee802154_mac_s *mac, + FAR uint8_t *eadr, uint8_t reason); /* Beacon notification */ - CODE int (*ind_beaconnotify)(FAR struct ieee802154_mac_s *mac, - FAR uint8_t *bsn, FAR struct ieee802154_pan_desc_s *pandesc, - FAR uint8_t *sdu, int sdulen); + CODE void (*ind_beaconnotify)(FAR struct ieee802154_mac_s *mac, + FAR uint8_t *bsn, FAR struct ieee802154_pan_desc_s *pandesc, + FAR uint8_t *sdu, int sdulen); /* GTS management request received */ - CODE int (*ind_gts)(FAR struct ieee802154_mac_s *mac, - FAR uint8_t *devaddr, FAR uint8_t *characteristics); + CODE void (*ind_gts)(FAR struct ieee802154_mac_s *mac, + FAR uint8_t *devaddr, FAR uint8_t *characteristics); /* Orphan device detected */ - CODE int (*ind_orphan)(FAR struct ieee802154_mac_s *mac, - FAR uint8_t *orphanaddr); + CODE void (*ind_orphan)(FAR struct ieee802154_mac_s *mac, + FAR uint8_t *orphanaddr); - CODE int (*ind_commstatus)(FAR struct ieee802154_mac_s *mac, - uint16_t panid, FAR uint8_t *src, - FAR uint8_t *dst, int status); + CODE void (*ind_commstatus)(FAR struct ieee802154_mac_s *mac, + uint16_t panid, FAR uint8_t *src, + FAR uint8_t *dst, int status); - CODE int (*ind_syncloss)(FAR struct ieee802154_mac_s *mac, int reason); + CODE void (*ind_syncloss)(FAR struct ieee802154_mac_s *mac, int reason); }; struct ieee802154_radio_s; /* Forware reference */ diff --git a/wireless/ieee802154/mac802154.c b/wireless/ieee802154/mac802154.c index d0a0a3ce504..8e4a3b80559 100644 --- a/wireless/ieee802154/mac802154.c +++ b/wireless/ieee802154/mac802154.c @@ -81,7 +81,7 @@ struct ieee802154_privmac_s uint32_t macPad : 3; /* 0x48 */ uint32_t macBeaconTxTime : 24; - /* 0x45 */ uint8_t macBeaconPayload[IEEE802154_aMaxBeaconPayloadLength]; + /* 0x45 */ uint8_t macBeaconPayload[IEEE802154_MAX_BEACON_PAYLOAD_LENGTH]; /* 0x46 */ uint8_t macBeaconPayloadLength; /* 0x49 */ uint8_t macBSN; /* 0x4A */ uint8_t macCoordExtendedAddress[8]; @@ -106,36 +106,41 @@ struct ieee802154_privmac_s * Private Function Prototypes ****************************************************************************/ -static int mac802154_reqdata(FAR struct ieee802154_mac_s *mac, - uint8_t handle, FAR uint8_t *buf, int len); -static int mac802154_reqpurge(FAR struct ieee802154_mac_s *mac, - uint8_t handle); -static int mac802154_reqassociate(FAR struct ieee802154_mac_s *mac, - uint16_t panid, FAR uint8_t *coordeadr); -static int mac802154_reqdisassociate(FAR struct ieee802154_mac_s *mac, - FAR uint8_t *eadr, uint8_t reason); -static int mac802154_reqget(FAR struct ieee802154_mac_s *mac, - int attribute); -static int mac802154_reqgts(FAR struct ieee802154_mac_s *mac, +/* MAC Data Service (MCPS) functions */ + +static int mac802154_req_data(FAR struct ieee802154_mac_s *mac, + FAR struct ieee802154_data_req_s *req); +static int mac802154_req_purge(FAR struct ieee802154_mac_s *mac, + uint8_t handle); + +/* MAC Sublayer Management Entity (MLME) functions */ + +static int mac802154_req_associate(FAR struct ieee802154_mac_s *mac, + FAR struct ieee802154_assoc_req_s *req); +static int mac802154_req_disassociate(FAR struct ieee802154_mac_s *mac, + FAR struct ieee802154_disassoc_req_s *req); +static int mac802154_req_get(FAR struct ieee802154_mac_s *mac, + enum ieee802154_pib_attr_e attr); +static int mac802154_req_gts(FAR struct ieee802154_mac_s *mac, FAR uint8_t *characteristics); -static int mac802154_reqreset(FAR struct ieee802154_mac_s *mac, +static int mac802154_req_reset(FAR struct ieee802154_mac_s *mac, bool setdefaults); -static int mac802154_reqrxenable(FAR struct ieee802154_mac_s *mac, +static int mac802154_req_rxenable(FAR struct ieee802154_mac_s *mac, bool deferrable, int ontime, int duration); -static int mac802154_reqscan(FAR struct ieee802154_mac_s *mac, +static int mac802154_req_scan(FAR struct ieee802154_mac_s *mac, uint8_t type, uint32_t channels, int duration); -static int mac802154_reqset(FAR struct ieee802154_mac_s *mac, +static int mac802154_req_set(FAR struct ieee802154_mac_s *mac, int attribute, FAR uint8_t *value, int valuelen); -static int mac802154_reqstart(FAR struct ieee802154_mac_s *mac, +static int mac802154_req_start(FAR struct ieee802154_mac_s *mac, uint16_t panid, int channel, uint8_t bo, uint8_t fo, bool coord, bool batext, bool realign); -static int mac802154_reqsync(FAR struct ieee802154_mac_s *mac, +static int mac802154_req_sync(FAR struct ieee802154_mac_s *mac, int channel, bool track); -static int mac802154_reqpoll(FAR struct ieee802154_mac_s *mac, +static int mac802154_req_poll(FAR struct ieee802154_mac_s *mac, FAR uint8_t *coordaddr); -static int mac802154_rspassociate(FAR struct ieee802154_mac_s *mac, +static int mac802154_rsp_associate(FAR struct ieee802154_mac_s *mac, uint8_t eadr, uint16_t saddr, int status); -static int mac802154_rsporphan(FAR struct ieee802154_mac_s *mac, +static int mac802154_rsp_orphan(FAR struct ieee802154_mac_s *mac, FAR uint8_t *orphanaddr, uint16_t saddr, bool associated); @@ -145,21 +150,21 @@ static int mac802154_rsporphan(FAR struct ieee802154_mac_s *mac, static const struct ieee802154_macops_s mac802154ops = { - .req_data = mac802154_reqdata, - .req_purge = mac802154_reqpurge, - .req_associate = mac802154_reqassociate, - .req_disassociate = mac802154_reqdisassociate, - .req_get = mac802154_reqget, - .req_gts = mac802154_reqgts, - .req_reset = mac802154_reqreset, - .req_rxenable = mac802154_reqrxenable, - .req_scan = mac802154_reqscan, - .req_set = mac802154_reqset, - .req_start = mac802154_reqstart, - .req_sync = mac802154_reqsync, - .req_poll = mac802154_reqpoll, - .rsp_associate = mac802154_rspassociate, - .rsp_orphan = mac802154_rsporphan, + .req_data = mac802154_req_data, + .req_purge = mac802154_req_purge, + .req_associate = mac802154_req_associate, + .req_disassociate = mac802154_req_disassociate, + .req_get = mac802154_req_get, + .req_gts = mac802154_req_gts, + .req_reset = mac802154_req_reset, + .req_rxenable = mac802154_req_rxenable, + .req_scan = mac802154_req_scan, + .req_set = mac802154_req_set, + .req_start = mac802154_req_start, + .req_sync = mac802154_req_sync, + .req_poll = mac802154_req_poll, + .rsp_associate = mac802154_rsp_associate, + .rsp_orphan = mac802154_rsp_orphan, }; /**************************************************************************** @@ -244,8 +249,8 @@ static int mac802154_applymib(FAR struct ieee802154_privmac_s *priv) * ****************************************************************************/ -static int mac802154_reqdata(FAR struct ieee802154_mac_s *mac, - uint8_t handle, FAR uint8_t *buf, int len) +static int mac802154_req_data(FAR struct ieee802154_mac_s *mac, + FAR struct ieee802154_data_req_s *req) { FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; return -ENOTTY; @@ -261,7 +266,7 @@ static int mac802154_reqdata(FAR struct ieee802154_mac_s *mac, * ****************************************************************************/ -static int mac802154_reqpurge(FAR struct ieee802154_mac_s *mac, +static int mac802154_req_purge(FAR struct ieee802154_mac_s *mac, uint8_t handle) { FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; @@ -269,7 +274,7 @@ static int mac802154_reqpurge(FAR struct ieee802154_mac_s *mac, } /**************************************************************************** - * Name: mac802154_reqassociate + * Name: mac802154_req_associate * * Description: * The MLME-ASSOCIATE.request primitive allows a device to request an @@ -278,15 +283,15 @@ static int mac802154_reqpurge(FAR struct ieee802154_mac_s *mac, * ****************************************************************************/ -static int mac802154_reqassociate(FAR struct ieee802154_mac_s *mac, - uint16_t panid, FAR uint8_t *coordeadr) +static int mac802154_req_associate(FAR struct ieee802154_mac_s *mac, + FAR struct ieee802154_assoc_req_s *req) { FAR struct ieee802154_privmac_s * priv = (FAR struct ieee802154_privmac_s *)mac; return -ENOTTY; } /**************************************************************************** - * Name: mac802154_reqdisassociate + * Name: mac802154_req_disassociate * * Description: * The MLME-DISASSOCIATE.request primitive is used by an associated device to @@ -297,15 +302,15 @@ static int mac802154_reqassociate(FAR struct ieee802154_mac_s *mac, * ****************************************************************************/ -static int mac802154_reqdisassociate(FAR struct ieee802154_mac_s *mac, - FAR uint8_t *eadr, uint8_t reason) +static int mac802154_req_disassociate(FAR struct ieee802154_mac_s *mac, + FAR struct ieee802154_disassoc_req_s *req) { FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; return -ENOTTY; } /**************************************************************************** - * Name: mac802154_reqget + * Name: mac802154_req_get * * Description: * The MLME-GET.request primitive requests information about a given PIB @@ -314,15 +319,15 @@ static int mac802154_reqdisassociate(FAR struct ieee802154_mac_s *mac, * ****************************************************************************/ -static int mac802154_reqget(FAR struct ieee802154_mac_s *mac, - int attribute) +static int mac802154_req_get(FAR struct ieee802154_mac_s *mac, + enum ieee802154_pib_attr_e attr) { FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; return -ENOTTY; } /**************************************************************************** - * Name: mac802154_reqgts + * Name: mac802154_req_gts * * Description: * The MLME-GTS.request primitive allows a device to send a request to the PAN @@ -332,15 +337,15 @@ static int mac802154_reqget(FAR struct ieee802154_mac_s *mac, * ****************************************************************************/ -static int mac802154_reqgts(FAR struct ieee802154_mac_s *mac, - FAR uint8_t *characteristics) +static int mac802154_req_gts(FAR struct ieee802154_mac_s *mac, + FAR uint8_t *characteristics) { FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; return -ENOTTY; } /**************************************************************************** - * Name: mac802154_reqreset + * Name: mac802154_req_reset * * Description: * The MLME-RESET.request primitive allows the next higher layer to request @@ -349,15 +354,15 @@ static int mac802154_reqgts(FAR struct ieee802154_mac_s *mac, * ****************************************************************************/ -static int mac802154_reqreset(FAR struct ieee802154_mac_s *mac, - bool setdefaults) +static int mac802154_req_reset(FAR struct ieee802154_mac_s *mac, + bool setdefaults) { FAR struct ieee802154_privmac_s * priv = (FAR struct ieee802154_privmac_s *) mac; return -ENOTTY; } /**************************************************************************** - * Name: mac802154_reqrxenable + * Name: mac802154_req_rxenable * * Description: * The MLME-RX-ENABLE.request primitive allows the next higher layer to @@ -367,15 +372,15 @@ static int mac802154_reqreset(FAR struct ieee802154_mac_s *mac, * ****************************************************************************/ -static int mac802154_reqrxenable(FAR struct ieee802154_mac_s *mac, - bool deferrable, int ontime, int duration) +static int mac802154_req_rxenable(FAR struct ieee802154_mac_s *mac, + bool deferrable, int ontime, int duration) { FAR struct ieee802154_privmac_s * priv = (FAR struct ieee802154_privmac_s *)mac; return -ENOTTY; } /**************************************************************************** - * Name: mac802154_reqscan + * Name: mac802154_req_scan * * Description: * The MLME-SCAN.request primitive is used to initiate a channel scan over a @@ -389,15 +394,15 @@ static int mac802154_reqrxenable(FAR struct ieee802154_mac_s *mac, * ****************************************************************************/ -static int mac802154_reqscan(FAR struct ieee802154_mac_s *mac, - uint8_t type, uint32_t channels, int duration) +static int mac802154_req_scan(FAR struct ieee802154_mac_s *mac, + uint8_t type, uint32_t channels, int duration) { FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; return -ENOTTY; } /**************************************************************************** - * Name: mac802154_reqset + * Name: mac802154_req_set * * Description: * The MLME-SET.request primitive attempts to write the given value to the @@ -406,15 +411,15 @@ static int mac802154_reqscan(FAR struct ieee802154_mac_s *mac, * ****************************************************************************/ -static int mac802154_reqset(FAR struct ieee802154_mac_s *mac, - int attribute, FAR uint8_t *value, int valuelen) +static int mac802154_req_set(FAR struct ieee802154_mac_s *mac, + int attribute, FAR uint8_t *value, int valuelen) { FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; return -ENOTTY; } /**************************************************************************** - * Name: mac802154_reqstart + * Name: mac802154_req_start * * Description: * The MLME-START.request primitive makes a request for the device to start @@ -423,17 +428,17 @@ static int mac802154_reqset(FAR struct ieee802154_mac_s *mac, * ****************************************************************************/ -static int mac802154_reqstart(FAR struct ieee802154_mac_s *mac, - uint16_t panid, int channel, uint8_t bo, - uint8_t fo, bool coord, bool batext, - bool realign) +static int mac802154_req_start(FAR struct ieee802154_mac_s *mac, + uint16_t panid, int channel, uint8_t bo, + uint8_t fo, bool coord, bool batext, + bool realign) { FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; return -ENOTTY; } /**************************************************************************** - * Name: mac802154_reqsync + * Name: mac802154_req_sync * * Description: * The MLME-SYNC.request primitive requests to synchronize with the @@ -443,15 +448,15 @@ static int mac802154_reqstart(FAR struct ieee802154_mac_s *mac, * ****************************************************************************/ -static int mac802154_reqsync(FAR struct ieee802154_mac_s *mac, - int channel, bool track) +static int mac802154_req_sync(FAR struct ieee802154_mac_s *mac, + int channel, bool track) { FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; return -ENOTTY; } /**************************************************************************** - * Name: mac802154_reqpoll + * Name: mac802154_req_poll * * Description: * The MLME-POLL.request primitive prompts the device to request data from the @@ -461,15 +466,15 @@ static int mac802154_reqsync(FAR struct ieee802154_mac_s *mac, * ****************************************************************************/ -static int mac802154_reqpoll(FAR struct ieee802154_mac_s *mac, - FAR uint8_t *coordaddr) +static int mac802154_req_poll(FAR struct ieee802154_mac_s *mac, + FAR uint8_t *coordaddr) { FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; return -ENOTTY; } /**************************************************************************** - * Name: mac802154_rspassociate + * Name: mac802154_rsp_associate * * Description: * The MLME-ASSOCIATE.response primitive is used to initiate a response to an @@ -477,15 +482,15 @@ static int mac802154_reqpoll(FAR struct ieee802154_mac_s *mac, * ****************************************************************************/ -static int mac802154_rspassociate(FAR struct ieee802154_mac_s *mac, - uint8_t eadr, uint16_t saddr, int status) +static int mac802154_rsp_associate(FAR struct ieee802154_mac_s *mac, + uint8_t eadr, uint16_t saddr, int status) { FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; return -ENOTTY; } /**************************************************************************** - * Name: mac802154_rsporphan + * Name: mac802154_rsp_orphan * * Description: * The MLME-ORPHAN.response primitive allows the next higher layer of a @@ -493,9 +498,9 @@ static int mac802154_rspassociate(FAR struct ieee802154_mac_s *mac, * ****************************************************************************/ -static int mac802154_rsporphan(FAR struct ieee802154_mac_s *mac, - FAR uint8_t *orphanaddr, uint16_t saddr, - bool associated) +static int mac802154_rsp_orphan(FAR struct ieee802154_mac_s *mac, + FAR uint8_t *orphanaddr, uint16_t saddr, + bool associated) { FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; return -ENOTTY; From 2ecca492ad5fefa712fe0a2ee5599dcea7c020f6 Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Wed, 5 Apr 2017 15:07:58 -0400 Subject: [PATCH 048/183] wireless/ieee802154: WIP for MAC char driver write functionality --- wireless/ieee802154/mac802154_device.c | 82 ++++++++++++++++++++++++-- 1 file changed, 77 insertions(+), 5 deletions(-) diff --git a/wireless/ieee802154/mac802154_device.c b/wireless/ieee802154/mac802154_device.c index 0478522834b..d89e9c9b456 100644 --- a/wireless/ieee802154/mac802154_device.c +++ b/wireless/ieee802154/mac802154_device.c @@ -74,6 +74,8 @@ struct mac802154_devwrapper_s */ FAR struct mac802154_open_s *md_open; + + FAR struct mac802154dev_dwait_s *md_dwait; }; /* This structure describes the state of one open mac driver instance */ @@ -89,6 +91,17 @@ struct mac802154_open_s volatile bool md_closing; }; +struct mac802154dev_dwait_s +{ + uint8_t mw_handle; /* The msdu handle identifying the frame */ + sem_t mw_sem; /* The semaphore used to signal the completion */ + int status; /* The success/error of the transaction */ + + /* Supports a singly linked list */ + + FAR struct mac802154dev_dwait_s *mw_flink; +}; + /**************************************************************************** * Private Function Prototypes ****************************************************************************/ @@ -362,7 +375,8 @@ static ssize_t mac802154dev_write(FAR struct file *filep, { FAR struct inode *inode; FAR struct mac802154_devwrapper_s *dev; - struct ieee802154_frame_s frame; + FAR struct ieee802154_data_req_s *req; + struct mac802154dev_dwait_s dwait; int ret; DEBUGASSERT(filep && filep->f_inode); @@ -391,12 +405,37 @@ static ssize_t mac802154dev_write(FAR struct file *filep, wlerr("ERROR: mac802154dev_takesem failed: %d\n", ret); return ret; } - - /* TODO: Send the frame out */ - ret = -ENOTSUP; + + /* Setup the wait struct */ + + dwait.mw_handle = req->msdu_handle; + + /* Link the wait struct */ + + dwait.mw_flink = dev->md_dwait; + dev->md_wait = &dwait; + + /* Pass the request to the MAC layer */ + + ret = dev->md_mac->ops.req_data(dev->md_mac, req); mac802154dev_givesem(&dev->md_exclsem); - return ret; + + if (ret < 0) + { + wlerr("ERROR: req_data failed %d\n", ret); + return ret; + } + + /* Wait for the DATA.confirm callback to be called for our handle */ + + sem_wait(dwait.mw_sem); + + /* The unlinking of the wait struct happens inside the callback. This + * is more efficient since it will already have to find the struct in + * the list in order to perform the sem_post. */ + + return dwait.status; } /**************************************************************************** @@ -444,6 +483,39 @@ static int mac802154dev_ioctl(FAR struct file *filep, int cmd, return ret; } +void mac802154dev_conf_data(FAR struct ieee802154_mac_s *mac, + FAR struct ieee802154_data_conf_s *conf) +{ + FAR struct mac802154_devwrapper_s *dev; + FAR struct mac802154dev_dwait_s *curr; + FAR struct mac802154dev_dwait_s *prev; + int ret; + + /* Get the dev from the callback context. This should have been set when the + * char driver was registered */ + + dev = mac->cbs.cb_context; + + /* Get exclusive access to the driver structure */ + + ret = mac802154dev_takesem(&dev->md_exclsem); + if (ret < 0) + { + wlerr("ERROR: mac802154dev_takesem failed: %d\n", ret); + return ret; + } + + /* Search to see if there is a dwait pending for this transaction */ + + for (prev = NULL, curr = dev->md_dwait; + curr && curr->mw_handle != conf->msdu_handle; + prev = curr, curr = curr->mw_flink); + + + +} + + /**************************************************************************** * Public Functions ****************************************************************************/ From 9893b7243b340decf78ec3391f2f2beafdc63b9b Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 5 Apr 2017 13:28:35 -0600 Subject: [PATCH 049/183] Trivial changes from review of last PR. --- .../wireless/ieee802154/ieee802154_mac.h | 26 +++++++++++++------ wireless/ieee802154/mac802154_device.c | 12 ++++----- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/include/nuttx/wireless/ieee802154/ieee802154_mac.h b/include/nuttx/wireless/ieee802154/ieee802154_mac.h index 13191bfa405..1299fe98569 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_mac.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_mac.h @@ -448,7 +448,8 @@ struct ieee802154_data_req_s uint8_t msdu_handle; /* Handle assoc. with MSDU */ - struct { + struct + { uint8_t ack_tx : 1; /* Acknowledge TX? */ uint8_t gts_tx : 1; /* 1=GTS used for TX, 0=CAP used for TX */ uint8_t indirect_tx : 1; /* Should indirect transmission be used? */ @@ -467,7 +468,8 @@ struct ieee802154_data_req_s /* The UWB preamble symbol repititions * Should be one of: - * 0, 16, 64, 1024, 4096 */ + * 0, 16, 64, 1024, 4096 + */ uint16_t uwb_presym_rep; @@ -480,10 +482,12 @@ struct ieee802154_data_req_s /* The MAC service data unit array that is to be transmitted * This must be at the end of the struct to allow the array - * to continue and make the struct "variable length" */ + * to continue and make the struct "variable length" + */ uint8_t msdu[1]; }; + #define SIZEOF_IEEE802154_DATA_REQ_S(n) \ (sizeof(struct ieee802154_data_req_s) + (n)) @@ -501,22 +505,26 @@ struct ieee802154_data_conf_s bool rng_rcvd; /* Ranging indicated by MSDU */ /* A count of the time units corresponding to an RMARKER at the antenna at - * the beginning of the ranging exchange */ + * the beginning of the ranging exchange + */ uint32_t rng_counter_start; /* A count of the time units corresponding to an RMARKER at the antenna at - * end of the ranging exchange */ + * end of the ranging exchange + */ uint32_t rng_counter_stop; /* A count of the time units in a message exchange over which the tracking - * offset was measured */ + * offset was measured + */ uint34_t rng_tracking_interval; /* A count of the time units slipped or advanced by the radio tracking - * system over the course of the entire tracking interval */ + * system over the course of the entire tracking interval + */ uint32_t rng_offset; @@ -645,7 +653,8 @@ struct ieee802154_assoc_rsp_s struct ieee802154_assoc_conf_s { /* Associated device address ALWAYS passed in short address mode. The - * address will be IEEE802154_SADDR_UNSPEC if association was unsuccessful */ + * address will be IEEE802154_SADDR_UNSPEC if association was unsuccessful. + */ struct ieee802154_addr_s dev_addr; @@ -726,6 +735,7 @@ struct ieee802154_beaconnotify_ind_s uint8_t sdu[IEEE802154_MAX_BEACON_PAYLOAD_LENGTH]; }; + #define SIZEOF_IEEE802154_BEACONNOTIFY_IND_S(n) \ (sizeof(struct ieee802154_beaconnotify_ind_s) \ - IEEE802154_MAX_BEACON_PAYLOAD_LENGTH + (n)) diff --git a/wireless/ieee802154/mac802154_device.c b/wireless/ieee802154/mac802154_device.c index d89e9c9b456..d2bc2489801 100644 --- a/wireless/ieee802154/mac802154_device.c +++ b/wireless/ieee802154/mac802154_device.c @@ -433,7 +433,8 @@ static ssize_t mac802154dev_write(FAR struct file *filep, /* The unlinking of the wait struct happens inside the callback. This * is more efficient since it will already have to find the struct in - * the list in order to perform the sem_post. */ + * the list in order to perform the sem_post. + */ return dwait.status; } @@ -491,8 +492,9 @@ void mac802154dev_conf_data(FAR struct ieee802154_mac_s *mac, FAR struct mac802154dev_dwait_s *prev; int ret; - /* Get the dev from the callback context. This should have been set when the - * char driver was registered */ + /* Get the dev from the callback context. This should have been set when + * the char driver was registered. + */ dev = mac->cbs.cb_context; @@ -510,12 +512,8 @@ void mac802154dev_conf_data(FAR struct ieee802154_mac_s *mac, for (prev = NULL, curr = dev->md_dwait; curr && curr->mw_handle != conf->msdu_handle; prev = curr, curr = curr->mw_flink); - - - } - /**************************************************************************** * Public Functions ****************************************************************************/ From 83660ac30e7f64b529977b61e183c1e5005bda8d Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 8 Apr 2017 13:27:03 -0600 Subject: [PATCH 050/183] Add configuration/build support for an IEEE802.15.4 network device. --- wireless/ieee802154/Kconfig | 34 +++++++++++++++++++++++++++++++++- wireless/ieee802154/Make.defs | 4 ++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/wireless/ieee802154/Kconfig b/wireless/ieee802154/Kconfig index b46aada66d0..64b9e66e91a 100644 --- a/wireless/ieee802154/Kconfig +++ b/wireless/ieee802154/Kconfig @@ -37,13 +37,45 @@ config IEEE802154_DEV Enables a device driver to expose ieee802.15.4 radio controls to user space as IOCTLs. +config IEEE802154_NETDEV + bool "IEEE802154 6loWPAN Network Device" + default n + depends on NET_6LOWPAN && NET_IPv6 + select ARCH_HAVE_NETDEV_STATISTICS + ---help--- + Add support for the IEEE802.15.4 6loWPAN network device built on + the common IEEE802.15.4 MAC. + +if IEEE802154_NETDEV + +choice + prompt "Work queue" + default IEEE802154_NETDEV_LPWORK if SCHED_LPWORK + default IEEE802154_NETDEV_HPWORK if !SCHED_LPWORK && SCHED_HPWORK + depends on SCHED_WORKQUEUE + ---help--- + Work queue support is required to use the IEEE802.15.4 network + driver. If the low priority work queue is available, then it shoul + be used by the loopback driver. + +config IEEE802154_NETDEV_HPWORK + bool "High priority" + depends on SCHED_HPWORK + +config IEEE802154_NETDEV_LPWORK + bool "Low priority" + depends on SCHED_LPWORK + +endchoice # Work queue +endif # IEEE802154_NETDEV + config IEEE802154_LOOPBACK bool "IEEE802154 6loWPAN Loopback" default n depends on NET_6LOWPAN && NET_IPv6 select ARCH_HAVE_NETDEV_STATISTICS ---help--- - Add support for the IEEE802154 6loWPAN Loopback test device. + Add support for the IEEE802.15.4 6loWPAN Loopback test device. if IEEE802154_LOOPBACK diff --git a/wireless/ieee802154/Make.defs b/wireless/ieee802154/Make.defs index bb2531e3e75..fc4db543bfb 100644 --- a/wireless/ieee802154/Make.defs +++ b/wireless/ieee802154/Make.defs @@ -53,6 +53,10 @@ ifeq ($(CONFIG_IEEE802154_DEV),y) CSRCS += radio802154_device.c endif +ifeq ($(CONFIG_IEEE802154_NETDEV),y) +CSRCS += mac802154_netdev.c +endif + ifeq ($(CONFIG_IEEE802154_LOOPBACK),y) CSRCS += mac802154_loopback.c endif From 11bd9afe5329de69d567df85a7a538e82ae764b9 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 8 Apr 2017 14:21:20 -0600 Subject: [PATCH 051/183] wireless/ieee802154: Add a partial implementation of the IEEE802.15.4 network driver. This is very incomplete on the initial commit. --- wireless/ieee802154/mac802154_loopback.c | 2 +- wireless/ieee802154/mac802154_netdev.c | 1365 ++++++++++++++++++++++ 2 files changed, 1366 insertions(+), 1 deletion(-) create mode 100644 wireless/ieee802154/mac802154_netdev.c diff --git a/wireless/ieee802154/mac802154_loopback.c b/wireless/ieee802154/mac802154_loopback.c index 994289642b3..71255f0d604 100644 --- a/wireless/ieee802154/mac802154_loopback.c +++ b/wireless/ieee802154/mac802154_loopback.c @@ -603,7 +603,7 @@ int ieee8021514_loopback(void) memset(priv, 0, sizeof(struct lo_driver_s)); - dev = &priv->lo_ieee.i_dev; + dev = &priv->lo_ieee.i_dev; dev->d_ifup = lo_ifup; /* I/F up (new IP address) callback */ dev->d_ifdown = lo_ifdown; /* I/F down callback */ dev->d_txavail = lo_txavail; /* New TX data callback */ diff --git a/wireless/ieee802154/mac802154_netdev.c b/wireless/ieee802154/mac802154_netdev.c new file mode 100644 index 00000000000..807320811ce --- /dev/null +++ b/wireless/ieee802154/mac802154_netdev.c @@ -0,0 +1,1365 @@ +/**************************************************************************** + * wireless/ieee802154/mac802154_netdev.c + * + * Copyright (C) 2017 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef CONFIG_NET_6LOWPAN + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* If processing is not done at the interrupt level, then work queue support + * is required. + */ + +#if !defined(CONFIG_SCHED_WORKQUEUE) +# error Work queue support is required in this configuration (CONFIG_SCHED_WORKQUEUE) +#else + + /* Use the selected work queue */ + +# if defined(CONFIG_IEEE802154_NETDEV_HPWORK) +# define ETHWORK HPWORK +# elif defined(CONFIG_IEEE802154_NETDEV_LPWORK) +# define ETHWORK LPWORK +# else +# error Neither CONFIG_IEEE802154_NETDEV_HPWORK nor CONFIG_IEEE802154_NETDEV_LPWORK defined +# endif +#endif + +/* CONFIG_IEEE802154_NETDEV_NINTERFACES determines the number of physical interfaces + * that will be supported. + */ + +#ifndef CONFIG_IEEE802154_NETDEV_NINTERFACES +# define CONFIG_IEEE802154_NETDEV_NINTERFACES 1 +#endif + +/* TX poll delay = 1 seconds. CLK_TCK is the number of clock ticks per second */ + +#define skeleton_WDDELAY (1*CLK_TCK) + +/* TX timeout = 1 minute */ + +#define skeleton_TXTIMEOUT (60*CLK_TCK) + +/* This is a helper pointer for accessing the contents of the Ethernet header */ + +#define BUF ((struct eth_hdr_s *)priv->m8_dev.d_buf) + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/* The mac802154_driver_s encapsulates all state information for a single hardware + * interface + */ + +struct mac802154_driver_s +{ + /* This holds the information visible to the NuttX network */ + + struct ieee802154_driver_s m8_dev; /* Interface understood by the network */ + struct ieee802154_mac_s m8_mac; /* Interface understood by the MAC */ + + /* For internal use by this driver */ + + bool m8_bifup; /* true:ifup false:ifdown */ + WDOG_ID m8_txpoll; /* TX poll timer */ + WDOG_ID m8_txtimeout; /* TX timeout timer */ + struct work_s m8_irqwork; /* For deferring interupt work to the work queue */ + struct work_s m8_pollwork; /* For deferring poll work to the work queue */ +}; + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +struct ieee802154_radio_s; /* Forware reference */ + + +{ + + struct ieee802154_macops_s ops; + struct ieee802154_maccb_s cbs; +}; + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/* A single packet buffer per device is used here. There might be multiple + * packet buffers in a more complex, pipelined design. + */ + +static uint8_t g_pktbuf[MAX_NET_DEV_MTU + CONFIG_NET_GUARDSIZE]; + +/* Driver state structure */ + +static struct mac802154_driver_s g_skel[CONFIG_IEEE802154_NETDEV_NINTERFACES]; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/* IEE802.15.4 MAC callback functions ***************************************/ +/* Asynchronous confirmations to requests */ + +static void mac802154_conf_data(FAR struct ieee802154_mac_s *mac, + FAR struct ieee802154_data_conf_s *conf); +static void mac802154_conf_purge(FAR struct ieee802154_mac_s *mac, + uint8_t handle, int status); +static void mac802154_conf_associate(FAR struct ieee802154_mac_s *mac, + uint16_t saddr, int status); +static void mac802154_conf_disassociate(FAR struct ieee802154_mac_s *mac, +static void mac802154_conf_get(FAR struct ieee802154_mac_s *mac, int status, + int attribute, FAR uint8_t *value, int valuelen); +static void mac802154_conf_gts(FAR struct ieee802154_mac_s *mac, + FAR uint8_t *characteristics, int status); +static void mac802154_conf_reset(FAR struct ieee802154_mac_s *mac, + int status); +static void mac802154_conf_rxenable(FAR struct ieee802154_mac_s *mac, + int status); +static void mac802154_conf_scan(FAR struct ieee802154_mac_s *mac, + int status, uint8_t type, uint32_t unscanned, int rsltsize, + FAR uint8_t *edlist, FAR uint8_t *pandescs); +static void mac802154_conf_set(FAR struct ieee802154_mac_s *mac, int status, + int attribute); +static void mac802154_conf_start(FAR struct ieee802154_mac_s *mac, + int status); +static void mac802154_conf_poll(FAR struct ieee802154_mac_s *mac, + int status); + + /* Asynchronous event indications, replied to synchronously with responses */ + +static void mac802154_ind_data(FAR struct ieee802154_mac_s *mac, + FAR uint8_t *buf, int len); +static void mac802154_ind_associate(FAR struct ieee802154_mac_s *mac, + uint16_t clipanid, FAR uint8_t *clieaddr); +static void mac802154_ind_disassociate(FAR struct ieee802154_mac_s *mac, + FAR uint8_t *eadr, uint8_t reason); +static void mac802154_ind_beaconnotify(FAR struct ieee802154_mac_s *mac, + FAR uint8_t *bsn, FAR struct ieee802154_pan_desc_s *pandesc, + FAR uint8_t *sdu, int sdulen); +static void mac802154_ind_gts(FAR struct ieee802154_mac_s *mac, + FAR uint8_t *devaddr, FAR uint8_t *characteristics); +static void mac802154_ind_orphan(FAR struct ieee802154_mac_s *mac, + FAR uint8_t *orphanaddr); +static void mac802154_ind_commstatus(FAR struct ieee802154_mac_s *mac, + uint16_t panid, FAR uint8_t *src, FAR uint8_t *dst, + int status); +static void mac802154_ind_syncloss(FAR struct ieee802154_mac_s *mac, + int reason); + +/* Network interface support ************************************************/ +/* Common TX logic */ + +static int mac802154_transmit(FAR struct mac802154_driver_s *priv); +static int mac802154_txpoll(FAR struct net_driver_s *dev); + +/* Frame transfer */ + +static void mac802154_receive(FAR struct mac802154_driver_s *priv); +static void mac802154_txdone(FAR struct mac802154_driver_s *priv); + +static void mac802154_transfer_work(FAR void *arg); +static int mac802154_transfer(int irq, FAR void *context, FAR void *arg); + +/* Watchdog timer expirations */ + +static void mac802154_txtimeout_work(FAR void *arg); +static void mac802154_txtimeout_expiry(int argc, wdparm_t arg, ...); + +static void mac802154_poll_work(FAR void *arg); +static void mac802154_poll_expiry(int argc, wdparm_t arg, ...); + +/* NuttX callback functions */ + +static int mac802154_ifup(FAR struct net_driver_s *dev); +static int mac802154_ifdown(FAR struct net_driver_s *dev); + +static void mac802154_txavail_work(FAR void *arg); +static int mac802154_txavail(FAR struct net_driver_s *dev); + +#if defined(CONFIG_NET_IGMP) || defined(CONFIG_NET_ICMPv6) +static int mac802154_addmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac); +#ifdef CONFIG_NET_IGMP +static int mac802154_rmmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac); +#endif +#ifdef CONFIG_NET_ICMPv6 +static void mac802154_ipv6multicast(FAR struct mac802154_driver_s *priv); +#endif +#endif + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: mac802154_conf_data + * + * Description: + * Data frame was received by remote device + * + ****************************************************************************/ + +static void mac802154_conf_data(FAR struct ieee802154_mac_s *mac, + FAR struct ieee802154_data_conf_s *conf) +{ +} + +/**************************************************************************** + * Name: mac802154_conf_purge + * + * Description: + * Data frame was purged + * + ****************************************************************************/ + +static void mac802154_conf_purge(FAR struct ieee802154_mac_s *mac, + uint8_t handle, int status) +{ +} + +/**************************************************************************** + * Name: mac802154_conf_associate + * + * Description: + * Association request completed + * + ****************************************************************************/ + +static void mac802154_conf_associate(FAR struct ieee802154_mac_s *mac, + uint16_t saddr, int status) +{ +} + +/**************************************************************************** + * Name: mac802154_conf_disassociate + * + * Description: + * Disassociation request completed + * + ****************************************************************************/ + +static void mac802154_conf_disassociate(FAR struct ieee802154_mac_s *mac, +{ +} + +/**************************************************************************** + * Name: mac802154_conf_get + * + * Description: + * PIvoata returned + * + ****************************************************************************/ + +static void mac802154_conf_get(FAR struct ieee802154_mac_s *mac, int status, + int attribute, FAR uint8_t *value, + int valuelen) +{ +} + +/**************************************************************************** + * Name: mac802154_conf_gts + * + * Description: + * GTvoanagement completed + * + ****************************************************************************/ + +static void mac802154_conf_gts(FAR struct ieee802154_mac_s *mac, + FAR uint8_t *characteristics, int status) +{ +} + +/**************************************************************************** + * Name: mac802154_conf_reset + * + * Description: + * MAveset completed + * + ****************************************************************************/ + +static void mac802154_conf_reset(FAR struct ieee802154_mac_s *mac, + int status) +{ +} + +/**************************************************************************** + * Name: mac802154_conf_rxenable + * + * Description: + * + ****************************************************************************/ + +static void mac802154_conf_rxenable(FAR struct ieee802154_mac_s *mac, + int status) +{ +} + +/**************************************************************************** + * Name: mac802154_conf_scan + * + * Description: + * + ****************************************************************************/ + +static void mac802154_conf_scan(FAR struct ieee802154_mac_s *mac, + int status, uint8_t type, + uint32_t unscanned, int rsltsize, + FAR uint8_t *edlist, FAR uint8_t *pandescs) +{ +} + +/**************************************************************************** + * Name: mac802154_conf_set + * + * Description: + * + ****************************************************************************/ + +static void mac802154_conf_set(FAR struct ieee802154_mac_s *mac, int status, + int attribute) +{ +} + +/**************************************************************************** + * Name: mac802154_conf_start + * + * Description: + * + ****************************************************************************/ + +static void mac802154_conf_start(FAR struct ieee802154_mac_s *mac, + int status) +{ +} + +/**************************************************************************** + * Name: mac802154_conf_poll + * + * Description: + * + ****************************************************************************/ + +static void mac802154_conf_poll(FAR struct ieee802154_mac_s *mac, + int status) +{ +} + +/**************************************************************************** + * Name: mac802154_ind_data + * + * Description: + * Data frame received + * + ****************************************************************************/ + +static void mac802154_ind_data(FAR struct ieee802154_mac_s *mac, + FAR uint8_t *buf, int len) +{ +} + +/**************************************************************************** + * Name: mac802154_ind_associate + * + * Description: + * Association request received + * + ****************************************************************************/ + +static void mac802154_ind_associate(FAR struct ieee802154_mac_s *mac, + uint16_t clipanid, + FAR uint8_t *clieaddr) +{ +} + +/**************************************************************************** + * Name: mac802154_ind_disassociate + * + * Description: + * Disassociation request received + * + ****************************************************************************/ + +static void mac802154_ind_disassociate(FAR struct ieee802154_mac_s *mac, + FAR uint8_t *eadr, uint8_t reason) +{ +} + +/**************************************************************************** + * Name: mac802154_ind_beaconnotify + * + * Description: + * Beacon notification + * + ****************************************************************************/ + +static void mac802154_ind_beaconnotify(FAR struct ieee802154_mac_s *mac, + FAR uint8_t *bsn, + FAR struct ieee802154_pan_desc_s *pandesc, + FAR uint8_t *sdu, int sdulen) +{ +} + +/**************************************************************************** + * Name: mac802154_ind_gts + * + * Description: + * GTS management request received + * + ****************************************************************************/ + +static void mac802154_ind_gts(FAR struct ieee802154_mac_s *mac, + FAR uint8_t *devaddr, + FAR uint8_t *characteristics) +{ +} + +/**************************************************************************** + * Name: mac802154_ind_orphan + * + * Description: + * Orphan device detected + * + ****************************************************************************/ + +static void mac802154_ind_orphan(FAR struct ieee802154_mac_s *mac, + FAR uint8_t *orphanaddr) +{ +} + +/**************************************************************************** + * Name: mac802154_ind_commstatus + * + * Description: + * + ****************************************************************************/ + +static void mac802154_ind_commstatus(FAR struct ieee802154_mac_s *mac, + uint16_t panid, FAR uint8_t *src, + FAR uint8_t *dst, int status) +{ +} + +/**************************************************************************** + * Name: mac802154_ind_syncloss + * + * Description: + * + ****************************************************************************/ + +static void mac802154_ind_syncloss(FAR struct ieee802154_mac_s *mac, + int reason) +{ +} + +/**************************************************************************** + * Name: mac802154_transmit + * + * Description: + * Start hardware transmission. Called either from the txdone interrupt + * handling or from watchdog based polling. + * + * Parameters: + * priv - Reference to the driver state structure + * + * Returned Value: + * OK on success; a negated errno on failure + * + * Assumptions: + * May or may not be called from an interrupt handler. In either case, + * the network is locked. + * + ****************************************************************************/ + +static int mac802154_transmit(FAR struct mac802154_driver_s *priv) +{ + /* Verify that the hardware is ready to send another packet. If we get + * here, then we are committed to sending a packet; Higher level logic + * must have assured that there is no transmission in progress. + */ + + /* Increment statistics */ + + NETDEV_TXPACKETS(priv->m8_dev); + + /* Send the packet: address=priv->m8_dev.d_buf, length=priv->m8_dev.d_len */ + + /* Enable Tx interrupts */ + + /* Setup the TX timeout watchdog (perhaps restarting the timer) */ + + (void)wd_start(priv->m8_txtimeout, skeleton_TXTIMEOUT, + mac802154_txtimeout_expiry, 1, (wdparm_t)priv); + return OK; +} + +/**************************************************************************** + * Name: mac802154_txpoll + * + * Description: + * The transmitter is available, check if the network has any outgoing + * packets ready to send. This is a callback from devif_poll(). + * devif_poll() may be called: + * + * 1. When the preceding TX packet send is complete, + * 2. When the preceding TX packet send timesout and the interface is reset + * 3. During normal TX polling + * + * Parameters: + * dev - Reference to the NuttX driver state structure + * + * Returned Value: + * OK on success; a negated errno on failure + * + * Assumptions: + * May or may not be called from an interrupt handler. In either case, + * the network is locked. + * + ****************************************************************************/ + +static int mac802154_txpoll(FAR struct net_driver_s *dev) +{ + FAR struct mac802154_driver_s *priv = (FAR struct mac802154_driver_s *)dev->d_private; + + /* If the polling resulted in data that should be sent out, the field + * i_framelist will set to a new, outgoing list of frames. + */ + + if (priv->m8_dev.i_framelist != NULL) + { + /* And send the packet */ + + mac802154_transmit(priv); + } + + /* If zero is returned, the polling will continue until all connections have + * been examined. + */ + + return 0; +} + +/**************************************************************************** + * Name: mac802154_receive + * + * Description: + * An interrupt was received indicating the availability of a new RX packet + * + * Parameters: + * priv - Reference to the driver state structure + * + * Returned Value: + * None + * + * Assumptions: + * The network is locked. + * + ****************************************************************************/ + +static void mac802154_receive(FAR struct mac802154_driver_s *priv) +{ + FAR struct iob_s *iob; + FAR struct iob_s *fptr; + + /* Allocate an IOB to hold the frame */ + + net_lock(); + iob = iob_alloc(false); + if (iob == NULL) + { + nerr("ERROR: Failed to allocate an IOB\n") + return; + } + + /* Copy the frame data into the IOB. + * REVISIT: Can a copy be avoided? + */ + + fptr = iob->io_data; +#warning Missing logic + + /* Transfer the frame to the network logic */ + + priv->m8_dev.framelist = iob; + sixlowpan_input(&priv->m8_dev); + + /* If the above function invocation resulted in data that should be sent + * out, the field i_framelist will set to a new, outgoing list of frames. + */ + + if (priv->m8_dev.i_framelist != NULL) + { + /* And send the packet */ + + mac802154_transmit(priv); + } +} + +/**************************************************************************** + * Name: mac802154_txdone + * + * Description: + * An interrupt was received indicating that the last TX packet(s) is done + * + * Parameters: + * priv - Reference to the driver state structure + * + * Returned Value: + * None + * + * Assumptions: + * The network is locked. + * + ****************************************************************************/ + +static void mac802154_txdone(FAR struct mac802154_driver_s *priv) +{ + int delay; + + /* Check for errors and update statistics */ + + NETDEV_TXDONE(priv->m8_dev); + + /* Check if there are pending transmissions */ + + /* If no further transmissions are pending, then cancel the TX timeout and + * disable further Tx interrupts. + */ + + wd_cancel(priv->m8_txtimeout); + + /* And disable further TX interrupts. */ + + /* In any event, poll the network for new TX data */ + + (void)devif_poll(&priv->m8_dev, mac802154_txpoll); +} + +/**************************************************************************** + * Name: mac802154_transfer_work + * + * Description: + * Perform interrupt related work from the worker thread + * + * Parameters: + * arg - The argument passed when work_queue() was called. + * + * Returned Value: + * OK on success + * + * Assumptions: + * The network is locked. + * + ****************************************************************************/ + +static void mac802154_transfer_work(FAR void *arg) +{ + FAR struct mac802154_driver_s *priv = (FAR struct mac802154_driver_s *)arg; + + /* Lock the network and serialize driver operations if necessary. + * NOTE: Serialization is only required in the case where the driver work + * is performed on an LP worker thread and where more than one LP worker + * thread has been configured. + */ + + net_lock(); + + /* Process pending Ethernet interrupts */ + + /* Get and clear interrupt status bits */ + + /* Handle interrupts according to status bit settings */ + + /* Check if we received an incoming packet, if so, call mac802154_receive() */ + + mac802154_receive(priv); + + /* Check if a packet transmission just completed. If so, call mac802154_txdone. + * This may disable further Tx interrupts if there are no pending + * transmissions. + */ + + mac802154_txdone(priv); + net_unlock(); + + /* Re-enable Ethernet interrupts */ + + up_enable_irq(CONFIG_IEEE802154_NETDEV_IRQ); +} + +/**************************************************************************** + * Name: mac802154_transfer + * + * Description: + * Hardware interrupt handler + * + * Parameters: + * irq - Number of the IRQ that generated the interrupt + * context - Interrupt register state save info (architecture-specific) + * + * Returned Value: + * OK on success + * + * Assumptions: + * + ****************************************************************************/ + +static int mac802154_transfer(int irq, FAR void *context, FAR void *arg) +{ + FAR struct mac802154_driver_s *priv = &g_skel[0]; + + /* Disable further Ethernet interrupts. Because Ethernet interrupts are + * also disabled if the TX timeout event occurs, there can be no race + * condition here. + */ + + up_disable_irq(CONFIG_IEEE802154_NETDEV_IRQ); + + /* TODO: Determine if a TX transfer just completed */ + + { + /* If a TX transfer just completed, then cancel the TX timeout so + * there will be no race condition between any subsequent timeout + * expiration and the deferred interrupt processing. + */ + + wd_cancel(priv->m8_txtimeout); + } + + /* Schedule to perform the interrupt processing on the worker thread. */ + + work_queue(ETHWORK, &priv->m8_irqwork, mac802154_transfer_work, priv, 0); + return OK; +} + +/**************************************************************************** + * Name: mac802154_txtimeout_work + * + * Description: + * Perform TX timeout related work from the worker thread + * + * Parameters: + * arg - The argument passed when work_queue() as called. + * + * Returned Value: + * OK on success + * + * Assumptions: + * The network is locked. + * + ****************************************************************************/ + +static void mac802154_txtimeout_work(FAR void *arg) +{ + FAR struct mac802154_driver_s *priv = (FAR struct mac802154_driver_s *)arg; + + /* Lock the network and serialize driver operations if necessary. + * NOTE: Serialization is only required in the case where the driver work + * is performed on an LP worker thread and where more than one LP worker + * thread has been configured. + */ + + net_lock(); + + /* Increment statistics and dump debug info */ + + NETDEV_TXTIMEOUTS(priv->m8_dev); + + /* Then reset the hardware */ + + /* Then poll the network for new XMIT data */ + + (void)devif_poll(&priv->m8_dev, mac802154_txpoll); + net_unlock(); +} + +/**************************************************************************** + * Name: mac802154_txtimeout_expiry + * + * Description: + * Our TX watchdog timed out. Called from the timer interrupt handler. + * The last TX never completed. Reset the hardware and start again. + * + * Parameters: + * argc - The number of available arguments + * arg - The first argument + * + * Returned Value: + * None + * + * Assumptions: + * Global interrupts are disabled by the watchdog logic. + * + ****************************************************************************/ + +static void mac802154_txtimeout_expiry(int argc, wdparm_t arg, ...) +{ + FAR struct mac802154_driver_s *priv = (FAR struct mac802154_driver_s *)arg; + + /* Disable further Ethernet interrupts. This will prevent some race + * conditions with interrupt work. There is still a potential race + * condition with interrupt work that is already queued and in progress. + */ + + up_disable_irq(CONFIG_IEEE802154_NETDEV_IRQ); + + /* Schedule to perform the TX timeout processing on the worker thread. */ + + work_queue(ETHWORK, &priv->m8_irqwork, mac802154_txtimeout_work, priv, 0); +} + +/**************************************************************************** + * Name: mac802154_poll_process + * + * Description: + * Perform the periodic poll. This may be called either from watchdog + * timer logic or from the worker thread, depending upon the configuration. + * + * Parameters: + * priv - Reference to the driver state structure + * + * Returned Value: + * None + * + * Assumptions: + * + ****************************************************************************/ + +static inline void mac802154_poll_process(FAR struct mac802154_driver_s *priv) +{ +} + +/**************************************************************************** + * Name: mac802154_poll_work + * + * Description: + * Perform periodic polling from the worker thread + * + * Parameters: + * arg - The argument passed when work_queue() as called. + * + * Returned Value: + * OK on success + * + * Assumptions: + * The network is locked. + * + ****************************************************************************/ + +static void mac802154_poll_work(FAR void *arg) +{ + FAR struct mac802154_driver_s *priv = (FAR struct mac802154_driver_s *)arg; + + /* Lock the network and serialize driver operations if necessary. + * NOTE: Serialization is only required in the case where the driver work + * is performed on an LP worker thread and where more than one LP worker + * thread has been configured. + */ + + net_lock(); + + /* Perform the poll */ + + /* Check if there is room in the send another TX packet. We cannot perform + * the TX poll if he are unable to accept another packet for transmission. + */ + + /* If so, update TCP timing states and poll the network for new XMIT data. + * Hmmm.. might be bug here. Does this mean if there is a transmit in + * progress, we will missing TCP time state updates? + */ + + (void)devif_timer(&priv->m8_dev, mac802154_txpoll); + + /* Setup the watchdog poll timer again */ + + (void)wd_start(priv->m8_txpoll, skeleton_WDDELAY, mac802154_poll_expiry, 1, + (wdparm_t)priv); + net_unlock(); +} + +/**************************************************************************** + * Name: mac802154_poll_expiry + * + * Description: + * Periodic timer handler. Called from the timer interrupt handler. + * + * Parameters: + * argc - The number of available arguments + * arg - The first argument + * + * Returned Value: + * None + * + * Assumptions: + * Global interrupts are disabled by the watchdog logic. + * + ****************************************************************************/ + +static void mac802154_poll_expiry(int argc, wdparm_t arg, ...) +{ + FAR struct mac802154_driver_s *priv = (FAR struct mac802154_driver_s *)arg; + + /* Schedule to perform the interrupt processing on the worker thread. */ + + work_queue(ETHWORK, &priv->m8_pollwork, mac802154_poll_work, priv, 0); +} + +/**************************************************************************** + * Name: mac802154_ifup + * + * Description: + * NuttX Callback: Bring up the Ethernet interface when an IP address is + * provided + * + * Parameters: + * dev - Reference to the NuttX driver state structure + * + * Returned Value: + * None + * + * Assumptions: + * + ****************************************************************************/ + +static int mac802154_ifup(FAR struct net_driver_s *dev) +{ + FAR struct mac802154_driver_s *priv = (FAR struct mac802154_driver_s *)dev->d_private; + +#ifdef CONFIG_NET_IPv4 + ninfo("Bringing up: %d.%d.%d.%d\n", + dev->d_ipaddr & 0xff, (dev->d_ipaddr >> 8) & 0xff, + (dev->d_ipaddr >> 16) & 0xff, dev->d_ipaddr >> 24); +#endif +#ifdef CONFIG_NET_IPv6 + ninfo("Bringing up: %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n", + dev->d_ipv6addr[0], dev->d_ipv6addr[1], dev->d_ipv6addr[2], + dev->d_ipv6addr[3], dev->d_ipv6addr[4], dev->d_ipv6addr[5], + dev->d_ipv6addr[6], dev->d_ipv6addr[7]); +#endif + + /* Initialize PHYs, the Ethernet interface, and setup up Ethernet interrupts */ + + /* Instantiate the MAC address from priv->m8_dev.d_mac.ether_addr_octet */ + +#ifdef CONFIG_NET_ICMPv6 + /* Set up IPv6 multicast address filtering */ + + mac802154_ipv6multicast(priv); +#endif + + /* Set and activate a timer process */ + + (void)wd_start(priv->m8_txpoll, skeleton_WDDELAY, mac802154_poll_expiry, 1, + (wdparm_t)priv); + + /* Enable the Ethernet interrupt */ + + priv->m8_bifup = true; + up_enable_irq(CONFIG_IEEE802154_NETDEV_IRQ); + return OK; +} + +/**************************************************************************** + * Name: mac802154_ifdown + * + * Description: + * NuttX Callback: Stop the interface. + * + * Parameters: + * dev - Reference to the NuttX driver state structure + * + * Returned Value: + * None + * + * Assumptions: + * + ****************************************************************************/ + +static int mac802154_ifdown(FAR struct net_driver_s *dev) +{ + FAR struct mac802154_driver_s *priv = (FAR struct mac802154_driver_s *)dev->d_private; + irqstate_t flags; + + /* Disable the Ethernet interrupt */ + + flags = enter_critical_section(); + up_disable_irq(CONFIG_IEEE802154_NETDEV_IRQ); + + /* Cancel the TX poll timer and TX timeout timers */ + + wd_cancel(priv->m8_txpoll); + wd_cancel(priv->m8_txtimeout); + + /* Put the EMAC in its reset, non-operational state. This should be + * a known configuration that will guarantee the mac802154_ifup() always + * successfully brings the interface back up. + */ + + /* Mark the device "down" */ + + priv->m8_bifup = false; + leave_critical_section(flags); + return OK; +} + +/**************************************************************************** + * Name: mac802154_txavail_work + * + * Description: + * Perform an out-of-cycle poll on the worker thread. + * + * Parameters: + * arg - Reference to the NuttX driver state structure (cast to void*) + * + * Returned Value: + * None + * + * Assumptions: + * Called on the higher priority worker thread. + * + ****************************************************************************/ + +static void mac802154_txavail_work(FAR void *arg) +{ + FAR struct mac802154_driver_s *priv = (FAR struct mac802154_driver_s *)arg; + + /* Lock the network and serialize driver operations if necessary. + * NOTE: Serialization is only required in the case where the driver work + * is performed on an LP worker thread and where more than one LP worker + * thread has been configured. + */ + + net_lock(); + + /* Ignore the notification if the interface is not yet up */ + + if (priv->m8_bifup) + { + /* Check if there is room in the hardware to hold another outgoing packet. */ + + /* If so, then poll the network for new XMIT data */ + + (void)devif_poll(&priv->m8_dev, mac802154_txpoll); + } + + net_unlock(); +} + +/**************************************************************************** + * Name: mac802154_txavail + * + * Description: + * Driver callback invoked when new TX data is available. This is a + * stimulus perform an out-of-cycle poll and, thereby, reduce the TX + * latency. + * + * Parameters: + * dev - Reference to the NuttX driver state structure + * + * Returned Value: + * None + * + * Assumptions: + * Called in normal user mode + * + ****************************************************************************/ + +static int mac802154_txavail(FAR struct net_driver_s *dev) +{ + FAR struct mac802154_driver_s *priv = (FAR struct mac802154_driver_s *)dev->d_private; + + /* Is our single work structure available? It may not be if there are + * pending interrupt actions and we will have to ignore the Tx + * availability action. + */ + + if (work_available(&priv->m8_pollwork)) + { + /* Schedule to serialize the poll on the worker thread. */ + + work_queue(ETHWORK, &priv->m8_pollwork, mac802154_txavail_work, priv, 0); + } + + return OK; +} + +/**************************************************************************** + * Name: mac802154_addmac + * + * Description: + * NuttX Callback: Add the specified MAC address to the hardware multicast + * address filtering + * + * Parameters: + * dev - Reference to the NuttX driver state structure + * mac - The MAC address to be added + * + * Returned Value: + * None + * + * Assumptions: + * + ****************************************************************************/ + +#if defined(CONFIG_NET_IGMP) || defined(CONFIG_NET_ICMPv6) +static int mac802154_addmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac) +{ + FAR struct mac802154_driver_s *priv = (FAR struct mac802154_driver_s *)dev->d_private; + + /* Add the MAC address to the hardware multicast routing table */ + + return OK; +} +#endif + +/**************************************************************************** + * Name: mac802154_rmmac + * + * Description: + * NuttX Callback: Remove the specified MAC address from the hardware multicast + * address filtering + * + * Parameters: + * dev - Reference to the NuttX driver state structure + * mac - The MAC address to be removed + * + * Returned Value: + * None + * + * Assumptions: + * + ****************************************************************************/ + +#ifdef CONFIG_NET_IGMP +static int mac802154_rmmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac) +{ + FAR struct mac802154_driver_s *priv = (FAR struct mac802154_driver_s *)dev->d_private; + + /* Add the MAC address to the hardware multicast routing table */ + + return OK; +} +#endif + +/**************************************************************************** + * Name: mac802154_ipv6multicast + * + * Description: + * Configure the IPv6 multicast MAC address. + * + * Parameters: + * priv - A reference to the private driver state structure + * + * Returned Value: + * OK on success; Negated errno on failure. + * + * Assumptions: + * + ****************************************************************************/ + +#ifdef CONFIG_NET_ICMPv6 +static void mac802154_ipv6multicast(FAR struct mac802154_driver_s *priv) +{ + FAR struct net_driver_s *dev; + uint16_t tmp16; + uint8_t mac[6]; + + /* For ICMPv6, we need to add the IPv6 multicast address + * + * For IPv6 multicast addresses, the Ethernet MAC is derived by + * the four low-order octets OR'ed with the MAC 33:33:00:00:00:00, + * so for example the IPv6 address FF02:DEAD:BEEF::1:3 would map + * to the Ethernet MAC address 33:33:00:01:00:03. + * + * NOTES: This appears correct for the ICMPv6 Router Solicitation + * Message, but the ICMPv6 Neighbor Solicitation message seems to + * use 33:33:ff:01:00:03. + */ + + mac[0] = 0x33; + mac[1] = 0x33; + + dev = &priv->dev; + tmp16 = dev->d_ipv6addr[6]; + mac[2] = 0xff; + mac[3] = tmp16 >> 8; + + tmp16 = dev->d_ipv6addr[7]; + mac[4] = tmp16 & 0xff; + mac[5] = tmp16 >> 8; + + ninfo("IPv6 Multicast: %02x:%02x:%02x:%02x:%02x:%02x\n", + mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); + + (void)mac802154_addmac(dev, mac); + +#ifdef CONFIG_NET_ICMPv6_AUTOCONF + /* Add the IPv6 all link-local nodes Ethernet address. This is the + * address that we expect to receive ICMPv6 Router Advertisement + * packets. + */ + + (void)mac802154_addmac(dev, g_ipv6_ethallnodes.ether_addr_octet); + +#endif /* CONFIG_NET_ICMPv6_AUTOCONF */ + +#ifdef CONFIG_NET_ICMPv6_ROUTER + /* Add the IPv6 all link-local routers Ethernet address. This is the + * address that we expect to receive ICMPv6 Router Solicitation + * packets. + */ + + (void)mac802154_addmac(dev, g_ipv6_ethallrouters.ether_addr_octet); + +#endif /* CONFIG_NET_ICMPv6_ROUTER */ +} +#endif /* CONFIG_NET_ICMPv6 */ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: mac802154_initialize + * + * Description: + * Initialize the Ethernet controller and driver + * + * Parameters: + * intf - In the case where there are multiple EMACs, this value + * identifies which EMAC is to be initialized. + * + * Returned Value: + * OK on success; Negated errno on failure. + * + * Assumptions: + * + ****************************************************************************/ + +int mac802154_initialize(FAR struct ieee802154_radio_s *radio) +{ + FAR struct mac802154_driver_s *priv; + FAR struct ieee802154_driver_s *ieee; + FAR struct net_driver_s *dev; + FAR uint8_t *pktbuf; + + DEBUGASSERT(radio != NULL); + + /* Get the interface structure associated with this interface number. */ + + priv = (FAR struct mac802154_driver_s *) + kmm_zalloc(sizeof(struct mac802154_driver_s)); + + if (priv == NULL) + { + nerr("ERROR: Failed to allocate the device structure\n"); + return -ENOMEM; + } + + /* Allocate a packet buffer (not used by this driver, but need by the + * upper networking layer) + */ + + pktbuf = (FAR uint8_t *)kmm_malloc(CONFIG_NET_6LOWPAN_MTU + CONFIG_NET_GUARDSIZE); + if (pktbuf == NULL + { + nerr("ERROR: Failed to allocate the packet buffer\n"); + kmm_free(priv); + return -ENOMEM; + } + + /* Initialize the driver structure */ + + ieee = &priv->m8_dev; + dev = &ieee->i_dev; + + dev->d_buf = pktbuf; /* Single packet buffer */ + dev->d_ifup = mac802154_ifup; /* I/F up (new IP address) callback */ + dev->d_ifdown = mac802154_ifdown; /* I/F down callback */ + dev->d_txavail = mac802154_txavail; /* New TX data callback */ +#ifdef CONFIG_NET_IGMP + dev->d_addmac = mac802154_addmac; /* Add multicast MAC address */ + dev->d_rmmac = mac802154_rmmac; /* Remove multicast MAC address */ +#endif + dev->d_private = (FAR void *)priv; /* Used to recover private state from dev */ + + /* Create a watchdog for timing polling for and timing of transmisstions */ + + priv->m8_txpoll = wd_create(); /* Create periodic poll timer */ + priv->m8_txtimeout = wd_create(); /* Create TX timeout timer */ + + DEBUGASSERT(priv->m8_txpoll != NULL && priv->m8_txtimeout != NULL); + + /* Put the interface in the down state. */ + + mac802154_ifdown(dev); + + /* Register the device with the OS so that socket IOCTLs can be performed */ + + (void)netdev_register(&priv->m8_dev, NET_LL_IEEE802154); + return OK; +} + +#endif /* CONFIG_NET && CONFIG_NET_skeleton */ From 51cd421ce720d78094354c788fdd12f4513192dd Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 8 Apr 2017 19:11:57 -0600 Subject: [PATCH 052/183] Ieee802.15.4 MAC network driver. A little more logic (but still only partial). Add interface definitions to header file. --- configs/clicker2-stm32/src/stm32_mrf24j40.c | 25 +++++-- .../wireless/ieee802154/ieee802154_mac.h | 30 ++++++-- wireless/ieee802154/mac802154.c | 6 +- wireless/ieee802154/mac802154_netdev.c | 70 +++++++++++-------- 4 files changed, 86 insertions(+), 45 deletions(-) diff --git a/configs/clicker2-stm32/src/stm32_mrf24j40.c b/configs/clicker2-stm32/src/stm32_mrf24j40.c index 17eb70ea96a..8f6868f59ea 100644 --- a/configs/clicker2-stm32/src/stm32_mrf24j40.c +++ b/configs/clicker2-stm32/src/stm32_mrf24j40.c @@ -264,20 +264,33 @@ static int stm32_mrf24j40_devsetup(FAR struct stm32_priv_s *priv) wlerr("ERROR: Failed to initialize IEEE802.15.4 MAC\n"); return -ENODEV; } -#endif -#if defined(CONFIG_IEEE802154_MAC_DEV) - /* If want to call these APIs from userspace, you have to wrap your mac - * in a character device via mac802154_device.c. +#if defined(CONFIG_IEEE802154_NETDEV) + /* Use the IEEE802.15.4 MAC interface instance to create a 6loWPAN + * network interface by wrapping the MAC intrface instance in a + * network device driver via mac802154dev_register(). + */ + + ret = mac802154netdev_register(mac); + if (ret < 0) + { + wlerr("ERROR: Failed to register the MAC network driver wpan%d: %d\n", + 0, ret); + return ret; + } +#elif defined(CONFIG_IEEE802154_MAC_DEV) + /* If want to call these APIs from userspace, you have to wrap the MAC + * interface in a character device viamac802154dev_register(). */ ret = mac802154dev_register(mac, 0); if (ret < 0) { - wlerr("ERROR: Failed to register the MAC character driver ieee%d: %d\n", + wlerr("ERROR: Failed to register the MAC character driver /dev/ieee%d: %d\n", 0, ret); return ret; } +#endif #elif defined(CONFIG_IEEE802154_DEV) /* Register a character driver to access the IEEE 802.15.4 radio from * user-space @@ -290,7 +303,7 @@ static int stm32_mrf24j40_devsetup(FAR struct stm32_priv_s *priv) RADIO_DEVNAME, ret); return ret; } -#endif +#endif /* CONFIG_IEEE802154_MAC */ return OK; } diff --git a/include/nuttx/wireless/ieee802154/ieee802154_mac.h b/include/nuttx/wireless/ieee802154/ieee802154_mac.h index 1299fe98569..55830d70fc5 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_mac.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_mac.h @@ -918,11 +918,11 @@ struct ieee802154_maccb_s CODE void (*ind_syncloss)(FAR struct ieee802154_mac_s *mac, int reason); }; -struct ieee802154_radio_s; /* Forware reference */ +struct ieee802154_radio_s; /* Forward reference */ struct ieee802154_mac_s { - struct ieee802154_radio_s *radio; + FAR struct ieee802154_radio_s *radio; struct ieee802154_macops_s ops; struct ieee802154_maccb_s cbs; }; @@ -947,9 +947,9 @@ extern "C" * * The returned MAC structure should be passed to either the next highest * layer in the network stack, or registered with a mac802154dev character - * driver. In either of these scenarios, the next highest layer should - * register a set of callbacks with the MAC layer by setting the mac->cbs - * member. + * or network drivers. In any of these scenarios, the next highest layer + * should register a set of callbacks with the MAC layer by setting the + * mac->cbs member. * * NOTE: 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 @@ -975,7 +975,7 @@ FAR struct ieee802154_mac_s * * user-space * * Input Parameters: - * mac - Pointer to the mac layer struct to be registerd. + * mac - Pointer to the mac layer struct to be registered. * minor - The device minor number. The IEEE802.15.4 MAC character device * will be registered as /dev/ieeeN where N is the minor number * @@ -987,6 +987,24 @@ FAR struct ieee802154_mac_s * int mac802154dev_register(FAR struct ieee802154_mac_s *mac, int minor); +/**************************************************************************** + * Name: mac802154netdev_register + * + * Description: + * Register a network driver to access the IEEE 802.15.4 MAC layer from + * a socket using 6loWPAN + * + * Input Parameters: + * mac - Pointer to the mac layer struct to be registered. + * + * Returned Values: + * Zero (OK) is returned on success. Otherwise a negated errno value is + * returned to indicate the nature of the failure. + * + ****************************************************************************/ + +int mac802154netdev_register(FAR struct ieee802154_mac_s *mac); + #undef EXTERN #ifdef __cplusplus } diff --git a/wireless/ieee802154/mac802154.c b/wireless/ieee802154/mac802154.c index 8e4a3b80559..f291d76199c 100644 --- a/wireless/ieee802154/mac802154.c +++ b/wireless/ieee802154/mac802154.c @@ -518,9 +518,9 @@ static int mac802154_rsp_orphan(FAR struct ieee802154_mac_s *mac, * * The returned MAC structure should be passed to either the next highest * layer in the network stack, or registered with a mac802154dev character - * driver. In either of these scenarios, the next highest layer should - * register a set of callbacks with the MAC layer by setting the mac->cbs - * member. + * or network drivers. In any of these scenarios, the next highest layer + * should register a set of callbacks with the MAC layer by setting the + * mac->cbs member. * * NOTE: 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 diff --git a/wireless/ieee802154/mac802154_netdev.c b/wireless/ieee802154/mac802154_netdev.c index 807320811ce..f3367b82a2b 100644 --- a/wireless/ieee802154/mac802154_netdev.c +++ b/wireless/ieee802154/mac802154_netdev.c @@ -117,8 +117,8 @@ struct mac802154_driver_s { /* This holds the information visible to the NuttX network */ - struct ieee802154_driver_s m8_dev; /* Interface understood by the network */ - struct ieee802154_mac_s m8_mac; /* Interface understood by the MAC */ + struct ieee802154_driver_s m8_dev; /* Interface understood by the network */ + FAR struct ieee802154_mac_s *m8_mac; /* Contained MAC interface */ /* For internal use by this driver */ @@ -129,19 +129,6 @@ struct mac802154_driver_s struct work_s m8_pollwork; /* For deferring poll work to the work queue */ }; -/**************************************************************************** - * Private Data - ****************************************************************************/ - -struct ieee802154_radio_s; /* Forware reference */ - - -{ - - struct ieee802154_macops_s ops; - struct ieee802154_maccb_s cbs; -}; - /**************************************************************************** * Private Data ****************************************************************************/ @@ -1282,26 +1269,25 @@ static void mac802154_ipv6multicast(FAR struct mac802154_driver_s *priv) ****************************************************************************/ /**************************************************************************** - * Name: mac802154_initialize + * Name: mac802154netdev_register * * Description: - * Initialize the Ethernet controller and driver + * Register a network driver to access the IEEE 802.15.4 MAC layer from + * a socket using 6loWPAN * - * Parameters: - * intf - In the case where there are multiple EMACs, this value - * identifies which EMAC is to be initialized. + * Input Parameters: + * mac - Pointer to the mac layer struct to be registered. * - * Returned Value: - * OK on success; Negated errno on failure. - * - * Assumptions: + * Returned Values: + * Zero (OK) is returned on success. Otherwise a negated errno value is + * returned to indicate the nature of the failure. * ****************************************************************************/ -int mac802154_initialize(FAR struct ieee802154_radio_s *radio) +int mac802154netdev_register(FAR struct ieee802154_mac_s *mac); { FAR struct mac802154_driver_s *priv; - FAR struct ieee802154_driver_s *ieee; + FAR truct ieee802154_maccb_s *macb; FAR struct net_driver_s *dev; FAR uint8_t *pktbuf; @@ -1332,9 +1318,7 @@ int mac802154_initialize(FAR struct ieee802154_radio_s *radio) /* Initialize the driver structure */ - ieee = &priv->m8_dev; - dev = &ieee->i_dev; - + dev = &ieee->m8_dev.i_dev; dev->d_buf = pktbuf; /* Single packet buffer */ dev->d_ifup = mac802154_ifup; /* I/F up (new IP address) callback */ dev->d_ifdown = mac802154_ifdown; /* I/F down callback */ @@ -1347,11 +1331,37 @@ int mac802154_initialize(FAR struct ieee802154_radio_s *radio) /* Create a watchdog for timing polling for and timing of transmisstions */ - priv->m8_txpoll = wd_create(); /* Create periodic poll timer */ + priv->m8_mac = mac; /* Save the MAC interface instance */ + priv->m8_txpoll = wd_create(); /* Create periodic poll timer */ priv->m8_txtimeout = wd_create(); /* Create TX timeout timer */ DEBUGASSERT(priv->m8_txpoll != NULL && priv->m8_txtimeout != NULL); + /* Initialize the MAC callbacks */ + + maccb = &mac->cbs; + maccb->cb_context = priv; + maccb->conf_data = mac802154_conf_data; + maccb->conf_purge = mac802154_conf_purge; + maccb->conf_associate = mac802154_conf_associate; + maccb->conf_disassociate = mac802154_conf_disassociate; + maccb->conf_get = mac802154_conf_get; + maccb->conf_gts = mac802154_conf_gts; + maccb->conf_reset = mac802154_conf_reset; + maccb->conf_rxenable = mac802154_conf_rxenable; + maccb->conf_scan = mac802154_conf_scan; + maccb->conf_set = mac802154_conf_set; + maccb->conf_start = mac802154_conf_start; + maccb->conf_poll = mac802154_conf_poll; + maccb->ind_data = mac802154_ind_data; + maccb->ind_associate = mac802154_ind_associate; + maccb->ind_disassociate = mac802154_ind_disassociate; + maccb->ind_beaconnotify = mac802154_ind_beaconnotify; + maccb->ind_gts = mac802154_ind_gts; + maccb->ind_orphan = mac802154_ind_orphan; + maccb->ind_commstatus = mac802154_ind_commstatus; + maccb->ind_syncloss = mac802154_ind_syncloss; + /* Put the interface in the down state. */ mac802154_ifdown(dev); From af1a9db4f6b2374d4be437c39bd3b9b7264dd3c7 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 9 Apr 2017 06:15:55 -0600 Subject: [PATCH 053/183] Some trivial addtions to the still fragmentary IEEE802.15.4 MAC network driver. --- wireless/ieee802154/mac802154_netdev.c | 84 +++++++++++++++++++++++++- 1 file changed, 82 insertions(+), 2 deletions(-) diff --git a/wireless/ieee802154/mac802154_netdev.c b/wireless/ieee802154/mac802154_netdev.c index f3367b82a2b..1f5f2335e18 100644 --- a/wireless/ieee802154/mac802154_netdev.c +++ b/wireless/ieee802154/mac802154_netdev.c @@ -109,8 +109,8 @@ * Private Types ****************************************************************************/ -/* The mac802154_driver_s encapsulates all state information for a single hardware - * interface +/* The mac802154_driver_s encapsulates all state information for a single + * IEEE802.15.4 MAC interface. */ struct mac802154_driver_s @@ -251,6 +251,10 @@ static void mac802154_ipv6multicast(FAR struct mac802154_driver_s *priv); static void mac802154_conf_data(FAR struct ieee802154_mac_s *mac, FAR struct ieee802154_data_conf_s *conf) { + FAR struct mac802154_driver_s *priv; + + DEBUGASSERT(mac != NULL && mac->cb_context); + priv = (FAR struct mac802154_driver_s *)mac->cb_context; } /**************************************************************************** @@ -264,6 +268,10 @@ static void mac802154_conf_data(FAR struct ieee802154_mac_s *mac, static void mac802154_conf_purge(FAR struct ieee802154_mac_s *mac, uint8_t handle, int status) { + FAR struct mac802154_driver_s *priv; + + DEBUGASSERT(mac != NULL && mac->cb_context); + priv = (FAR struct mac802154_driver_s *)mac->cb_context; } /**************************************************************************** @@ -277,6 +285,10 @@ static void mac802154_conf_purge(FAR struct ieee802154_mac_s *mac, static void mac802154_conf_associate(FAR struct ieee802154_mac_s *mac, uint16_t saddr, int status) { + FAR struct mac802154_driver_s *priv; + + DEBUGASSERT(mac != NULL && mac->cb_context); + priv = (FAR struct mac802154_driver_s *)mac->cb_context; } /**************************************************************************** @@ -289,6 +301,10 @@ static void mac802154_conf_associate(FAR struct ieee802154_mac_s *mac, static void mac802154_conf_disassociate(FAR struct ieee802154_mac_s *mac, { + FAR struct mac802154_driver_s *priv; + + DEBUGASSERT(mac != NULL && mac->cb_context); + priv = (FAR struct mac802154_driver_s *)mac->cb_context; } /**************************************************************************** @@ -303,6 +319,10 @@ static void mac802154_conf_get(FAR struct ieee802154_mac_s *mac, int status, int attribute, FAR uint8_t *value, int valuelen) { + FAR struct mac802154_driver_s *priv; + + DEBUGASSERT(mac != NULL && mac->cb_context); + priv = (FAR struct mac802154_driver_s *)mac->cb_context; } /**************************************************************************** @@ -316,6 +336,10 @@ static void mac802154_conf_get(FAR struct ieee802154_mac_s *mac, int status, static void mac802154_conf_gts(FAR struct ieee802154_mac_s *mac, FAR uint8_t *characteristics, int status) { + FAR struct mac802154_driver_s *priv; + + DEBUGASSERT(mac != NULL && mac->cb_context); + priv = (FAR struct mac802154_driver_s *)mac->cb_context; } /**************************************************************************** @@ -329,6 +353,10 @@ static void mac802154_conf_gts(FAR struct ieee802154_mac_s *mac, static void mac802154_conf_reset(FAR struct ieee802154_mac_s *mac, int status) { + FAR struct mac802154_driver_s *priv; + + DEBUGASSERT(mac != NULL && mac->cb_context); + priv = (FAR struct mac802154_driver_s *)mac->cb_context; } /**************************************************************************** @@ -341,6 +369,10 @@ static void mac802154_conf_reset(FAR struct ieee802154_mac_s *mac, static void mac802154_conf_rxenable(FAR struct ieee802154_mac_s *mac, int status) { + FAR struct mac802154_driver_s *priv; + + DEBUGASSERT(mac != NULL && mac->cb_context); + priv = (FAR struct mac802154_driver_s *)mac->cb_context; } /**************************************************************************** @@ -355,6 +387,10 @@ static void mac802154_conf_scan(FAR struct ieee802154_mac_s *mac, uint32_t unscanned, int rsltsize, FAR uint8_t *edlist, FAR uint8_t *pandescs) { + FAR struct mac802154_driver_s *priv; + + DEBUGASSERT(mac != NULL && mac->cb_context); + priv = (FAR struct mac802154_driver_s *)mac->cb_context; } /**************************************************************************** @@ -367,6 +403,10 @@ static void mac802154_conf_scan(FAR struct ieee802154_mac_s *mac, static void mac802154_conf_set(FAR struct ieee802154_mac_s *mac, int status, int attribute) { + FAR struct mac802154_driver_s *priv; + + DEBUGASSERT(mac != NULL && mac->cb_context); + priv = (FAR struct mac802154_driver_s *)mac->cb_context; } /**************************************************************************** @@ -379,6 +419,10 @@ static void mac802154_conf_set(FAR struct ieee802154_mac_s *mac, int status, static void mac802154_conf_start(FAR struct ieee802154_mac_s *mac, int status) { + FAR struct mac802154_driver_s *priv; + + DEBUGASSERT(mac != NULL && mac->cb_context); + priv = (FAR struct mac802154_driver_s *)mac->cb_context; } /**************************************************************************** @@ -391,6 +435,10 @@ static void mac802154_conf_start(FAR struct ieee802154_mac_s *mac, static void mac802154_conf_poll(FAR struct ieee802154_mac_s *mac, int status) { + FAR struct mac802154_driver_s *priv; + + DEBUGASSERT(mac != NULL && mac->cb_context); + priv = (FAR struct mac802154_driver_s *)mac->cb_context; } /**************************************************************************** @@ -404,6 +452,10 @@ static void mac802154_conf_poll(FAR struct ieee802154_mac_s *mac, static void mac802154_ind_data(FAR struct ieee802154_mac_s *mac, FAR uint8_t *buf, int len) { + FAR struct mac802154_driver_s *priv; + + DEBUGASSERT(mac != NULL && mac->cb_context); + priv = (FAR struct mac802154_driver_s *)mac->cb_context; } /**************************************************************************** @@ -418,6 +470,10 @@ static void mac802154_ind_associate(FAR struct ieee802154_mac_s *mac, uint16_t clipanid, FAR uint8_t *clieaddr) { + FAR struct mac802154_driver_s *priv; + + DEBUGASSERT(mac != NULL && mac->cb_context); + priv = (FAR struct mac802154_driver_s *)mac->cb_context; } /**************************************************************************** @@ -431,6 +487,10 @@ static void mac802154_ind_associate(FAR struct ieee802154_mac_s *mac, static void mac802154_ind_disassociate(FAR struct ieee802154_mac_s *mac, FAR uint8_t *eadr, uint8_t reason) { + FAR struct mac802154_driver_s *priv; + + DEBUGASSERT(mac != NULL && mac->cb_context); + priv = (FAR struct mac802154_driver_s *)mac->cb_context; } /**************************************************************************** @@ -446,6 +506,10 @@ static void mac802154_ind_beaconnotify(FAR struct ieee802154_mac_s *mac, FAR struct ieee802154_pan_desc_s *pandesc, FAR uint8_t *sdu, int sdulen) { + FAR struct mac802154_driver_s *priv; + + DEBUGASSERT(mac != NULL && mac->cb_context); + priv = (FAR struct mac802154_driver_s *)mac->cb_context; } /**************************************************************************** @@ -460,6 +524,10 @@ static void mac802154_ind_gts(FAR struct ieee802154_mac_s *mac, FAR uint8_t *devaddr, FAR uint8_t *characteristics) { + FAR struct mac802154_driver_s *priv; + + DEBUGASSERT(mac != NULL && mac->cb_context); + priv = (FAR struct mac802154_driver_s *)mac->cb_context; } /**************************************************************************** @@ -473,6 +541,10 @@ static void mac802154_ind_gts(FAR struct ieee802154_mac_s *mac, static void mac802154_ind_orphan(FAR struct ieee802154_mac_s *mac, FAR uint8_t *orphanaddr) { + FAR struct mac802154_driver_s *priv; + + DEBUGASSERT(mac != NULL && mac->cb_context); + priv = (FAR struct mac802154_driver_s *)mac->cb_context; } /**************************************************************************** @@ -486,6 +558,10 @@ static void mac802154_ind_commstatus(FAR struct ieee802154_mac_s *mac, uint16_t panid, FAR uint8_t *src, FAR uint8_t *dst, int status) { + FAR struct mac802154_driver_s *priv; + + DEBUGASSERT(mac != NULL && mac->cb_context); + priv = (FAR struct mac802154_driver_s *)mac->cb_context; } /**************************************************************************** @@ -498,6 +574,10 @@ static void mac802154_ind_commstatus(FAR struct ieee802154_mac_s *mac, static void mac802154_ind_syncloss(FAR struct ieee802154_mac_s *mac, int reason) { + FAR struct mac802154_driver_s *priv; + + DEBUGASSERT(mac != NULL && mac->cb_context); + priv = (FAR struct mac802154_driver_s *)mac->cb_context; } /**************************************************************************** From 2bfb284989383a52615e2c14198a1af6367e14ce Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 9 Apr 2017 09:19:25 -0600 Subject: [PATCH 054/183] Add support for NuttX controlled LEDS and for board_initialize. Separate initialize logic to stm32_bringup.c so that in initialization can occur either through board_initialize() or through board_app_initialize(). Same as with most other newer board configurations. --- configs/photon/include/board.h | 33 +++++ configs/photon/src/Makefile | 16 ++- configs/photon/src/photon.h | 15 ++ configs/photon/src/stm32_appinit.c | 83 ++--------- configs/photon/src/stm32_autoleds.c | 116 +++++++++++++++ configs/photon/src/stm32_boot.c | 28 ++++ configs/photon/src/stm32_bringup.c | 132 ++++++++++++++++++ configs/photon/src/stm32_usb.c | 12 -- .../src/{stm32_leds.c => stm32_userleds.c} | 6 +- configs/photon/src/stm32_wdt.c | 5 - configs/photon/src/stm32_wlan.c | 17 ++- configs/same70-xplained/src/sam_autoleds.c | 2 +- 12 files changed, 362 insertions(+), 103 deletions(-) create mode 100644 configs/photon/src/stm32_autoleds.c create mode 100644 configs/photon/src/stm32_bringup.c rename configs/photon/src/{stm32_leds.c => stm32_userleds.c} (97%) diff --git a/configs/photon/include/board.h b/configs/photon/include/board.h index 8c2fc655e3f..96115ca57f0 100644 --- a/configs/photon/include/board.h +++ b/configs/photon/include/board.h @@ -152,11 +152,44 @@ #undef BOARD_ENABLE_USBOTG_HSULPI /* LED definitions ******************************************************************/ +/* LEDs + * + * A single LED is available driven by PA13. + */ + +/* LED index values for use with board_userled() */ #define BOARD_LED1 0 #define BOARD_NLEDS 1 + +/* LED bits for use with board_userled_all() */ + #define BOARD_LED1_BIT (1 << BOARD_LED1) +/* These LEDs are not used by the board port unless CONFIG_ARCH_LEDS is + * defined. In that case, the usage by the board port is defined in + * include/board.h and src/sam_autoleds.c. The LEDs are used to encode + * OS-related events as follows: + * + * ------------------- ---------------------------- ------ + * SYMBOL Meaning LED + * ------------------- ---------------------------- ------ */ + +#define LED_STARTED 0 /* NuttX has been started OFF */ +#define LED_HEAPALLOCATE 0 /* Heap has been allocated OFF */ +#define LED_IRQSENABLED 0 /* Interrupts enabled OFF */ +#define LED_STACKCREATED 1 /* Idle stack created ON */ +#define LED_INIRQ 2 /* In an interrupt N/C */ +#define LED_SIGNAL 2 /* In a signal handler N/C */ +#define LED_ASSERTION 2 /* An assertion failed N/C */ +#define LED_PANIC 3 /* The system has crashed FLASH */ +#undef LED_IDLE /* MCU is is sleep mode Not used */ + +/* Thus if LED is statically on, NuttX has successfully booted and is, + * apparently, running normally. If LED is flashing at approximately + * 2Hz, then a fatal error has been detected and the system has halted. + */ + /* Button definitions ***************************************************************/ #define BOARD_BUTTON1 0 diff --git a/configs/photon/src/Makefile b/configs/photon/src/Makefile index 5d9501759c7..23f31b44899 100644 --- a/configs/photon/src/Makefile +++ b/configs/photon/src/Makefile @@ -35,18 +35,24 @@ -include $(TOPDIR)/Make.defs ASRCS = -CSRCS = stm32_boot.c +CSRCS = stm32_boot.c stm32_bringup.c ifeq ($(CONFIG_PHOTON_DFU_BOOTLOADER),y) CSRCS += dfu_signature.c endif +ifeq ($(CONFIG_LIB_BOARDCTL),y) +CSRCS += stm32_appinit.c +endif + ifeq ($(CONFIG_BUTTONS),y) CSRCS += stm32_buttons.c endif -ifeq ($(CONFIG_USERLED),y) -CSRCS += stm32_leds.c +ifeq ($(CONFIG_ARCH_LEDS),y) +CSRCS += stm32_autoleds.c +else +CSRCS += stm32_userleds.c endif ifeq ($(CONFIG_PHOTON_WDG),y) @@ -61,8 +67,4 @@ ifeq ($(CONFIG_STM32_OTGHS),y) CSRCS += stm32_usb.c endif -ifeq ($(CONFIG_NSH_LIBRARY),y) -CSRCS += stm32_appinit.c -endif - include $(TOPDIR)/configs/Board.mk diff --git a/configs/photon/src/photon.h b/configs/photon/src/photon.h index 4e0f312b6c4..5628d1b69c1 100644 --- a/configs/photon/src/photon.h +++ b/configs/photon/src/photon.h @@ -89,6 +89,21 @@ * Public Functions ****************************************************************************/ +/**************************************************************************** + * Name: stm32_bringup + * + * Description: + * Called either by board_intialize() if CONFIG_BOARD_INITIALIZE or by + * board_app_initialize if CONFIG_LIB_BOARDCTL is selected. This function + * initializes and configures all on-board features appropriate for the + * selected configuration. + * + ****************************************************************************/ + +#if defined(CONFIG_LIB_BOARDCTL) || defined(CONFIG_BOARD_INITIALIZE) +int stm32_bringup(void); +#endif + /**************************************************************************** * Name: photon_watchdog_initialize() * diff --git a/configs/photon/src/stm32_appinit.c b/configs/photon/src/stm32_appinit.c index dc2899789fe..946dfbe8e2b 100644 --- a/configs/photon/src/stm32_appinit.c +++ b/configs/photon/src/stm32_appinit.c @@ -2,7 +2,7 @@ * config/photon/src/stm32_appinit.c * * Copyright (C) 2017 Gregory Nutt. All rights reserved. - * Author: Simon Piriou + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -38,23 +38,14 @@ ****************************************************************************/ #include -#include -#include -#include +#include + +#include #include "photon.h" -#include "stm32_wdg.h" -#include -#include -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#ifndef OK -# define OK 0 -#endif +#ifdef CONFIG_LIB_BOARDCTL /**************************************************************************** * Public Functions @@ -87,65 +78,13 @@ int board_app_initialize(uintptr_t arg) { - int ret = OK; +#ifndef CONFIG_BOARD_INITIALIZE + /* Perform board initialization */ -#ifdef CONFIG_USERLED -#ifdef CONFIG_USERLED_LOWER - /* Register the LED driver */ - - ret = userled_lower_initialize("/dev/userleds"); - if (ret != OK) - { - syslog(LOG_ERR, "ERROR: userled_lower_initialize() failed: %d\n", ret); - return ret; - } + return stm32_bringup(); #else - board_userled_initialize(); -#endif /* CONFIG_USERLED_LOWER */ -#endif /* CONFIG_USERLED */ - -#ifdef CONFIG_BUTTONS -#ifdef CONFIG_BUTTONS_LOWER - /* Register the BUTTON driver */ - - ret = btn_lower_initialize("/dev/buttons"); - if (ret != OK) - { - syslog(LOG_ERR, "ERROR: btn_lower_initialize() failed: %d\n", ret); - return ret; - } -#else - board_button_initialize(); -#endif /* CONFIG_BUTTONS_LOWER */ -#endif /* CONFIG_BUTTONS */ - -#ifdef CONFIG_STM32_IWDG - stm32_iwdginitialize("/dev/watchdog0", STM32_LSI_FREQUENCY); + return OK; #endif - -#ifdef CONFIG_PHOTON_WDG - - /* Start WDG kicker thread */ - - ret = photon_watchdog_initialize(); - if (ret != OK) - { - syslog(LOG_ERR, "Failed to start watchdog thread: %d\n", ret); - return ret; - } -#endif - -#ifdef CONFIG_PHOTON_WLAN - - /* Initialize wlan driver and hardware */ - - ret = photon_wlan_initialize(); - if (ret != OK) - { - syslog(LOG_ERR, "Failed to initialize wlan: %d\n", ret); - return ret; - } -#endif - - return ret; } + +#endif /* CONFIG_LIB_BOARDCTL */ diff --git a/configs/photon/src/stm32_autoleds.c b/configs/photon/src/stm32_autoleds.c new file mode 100644 index 00000000000..a490fa5432f --- /dev/null +++ b/configs/photon/src/stm32_autoleds.c @@ -0,0 +1,116 @@ +/**************************************************************************** + * configs/photon/src/stm32_autoleds.c + * + * Copyright (C) 2017 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/* LEDs + * + * A single LED is available driven by PA13. + * + * These LEDs are not used by the board port unless CONFIG_ARCH_LEDS is + * defined. In that case, the usage by the board port is defined in + * include/board.h and src/sam_autoleds.c. The LEDs are used to encode + * OS-related events as follows: + * + * ------------------- ----------------------- ------ + * SYMBOL Meaning LED + * ------------------- ----------------------- ------ + * LED_STARTED NuttX has been started OFF + * LED_HEAPALLOCATE Heap has been allocated OFF + * LED_IRQSENABLED Interrupts enabled OFF + * LED_STACKCREATED Idle stack created ON + * LED_INIRQ In an interrupt N/C + * LED_SIGNAL In a signal handler N/C + * LED_ASSERTION An assertion failed N/C + * LED_PANIC The system has crashed FLASH + * + * Thus is LED is statically on, NuttX has successfully booted and is, + * apparently, running normally. If LED is flashing at approximately + * 2Hz, then a fatal error has been detected and the system has halted. + */ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +#include +#include + +#include "stm32_gpio.h" +#include "photon.h" + +#ifdef CONFIG_ARCH_LEDS + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_autoled_initialize + ****************************************************************************/ + +void board_autoled_initialize(void) +{ + /* Configure Photon LED gpio as output */ + + stm32_configgpio(GPIO_LED1); +} + +/**************************************************************************** + * Name: board_autoled_on + ****************************************************************************/ + +void board_autoled_on(int led) +{ + if (led == 1 || led == 3) + { + stm32_gpiowrite(GPIO_LED1, true); + } +} + +/**************************************************************************** + * Name: board_autoled_off + ****************************************************************************/ + +void board_autoled_off(int led) +{ + if (led == 3) + { + stm32_gpiowrite(GPIO_LED1, false); + } +} + +#endif /* CONFIG_ARCH_LEDS */ diff --git a/configs/photon/src/stm32_boot.c b/configs/photon/src/stm32_boot.c index c9dfe28729a..5adc28f31c2 100644 --- a/configs/photon/src/stm32_boot.c +++ b/configs/photon/src/stm32_boot.c @@ -73,4 +73,32 @@ void stm32_boardinitialize(void) stm32_usbinitialize(); } #endif + +#ifdef CONFIG_ARCH_LEDS + /* Configure on-board LEDs if LED support has been selected. */ + + board_autoled_initialize(); +#endif } + +/**************************************************************************** + * Name: board_initialize + * + * Description: + * If CONFIG_BOARD_INITIALIZE is selected, then an additional + * initialization call will be performed in the boot-up sequence to a + * function called board_initialize(). board_initialize() will be + * called immediately after up_intitialize() is called and just before the + * initial application is started. This additional initialization phase + * may be used, for example, to initialize board-specific device drivers. + * + ****************************************************************************/ + +#ifdef CONFIG_BOARD_INITIALIZE +void board_initialize(void) +{ + /* Perform board initialization */ + + (void)stm32_bringup(); +} +#endif /* CONFIG_BOARD_INITIALIZE */ diff --git a/configs/photon/src/stm32_bringup.c b/configs/photon/src/stm32_bringup.c new file mode 100644 index 00000000000..d83e0493edd --- /dev/null +++ b/configs/photon/src/stm32_bringup.c @@ -0,0 +1,132 @@ +/**************************************************************************** + * config/photon/src/stm32_bringup.c + * + * Copyright (C) 2017 Gregory Nutt. All rights reserved. + * Author: Simon Piriou + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include +#include +#include + +#include + +#include "photon.h" +#include "stm32_wdg.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: stm32_bringup + * + * Description: + * Called either by board_intialize() if CONFIG_BOARD_INITIALIZE or by + * board_app_initialize if CONFIG_LIB_BOARDCTL is selected. This function + * initializes and configures all on-board features appropriate for the + * selected configuration. + * + ****************************************************************************/ + +int stm32_bringup(void) +{ + int ret = OK; + +#ifdef CONFIG_USERLED +#ifdef CONFIG_USERLED_LOWER + /* Register the LED driver */ + + ret = userled_lower_initialize("/dev/userleds"); + if (ret != OK) + { + syslog(LOG_ERR, "ERROR: userled_lower_initialize() failed: %d\n", ret); + return ret; + } +#else + board_userled_initialize(); +#endif /* CONFIG_USERLED_LOWER */ +#endif /* CONFIG_USERLED */ + +#ifdef CONFIG_BUTTONS +#ifdef CONFIG_BUTTONS_LOWER + /* Register the BUTTON driver */ + + ret = btn_lower_initialize("/dev/buttons"); + if (ret != OK) + { + syslog(LOG_ERR, "ERROR: btn_lower_initialize() failed: %d\n", ret); + return ret; + } +#else + board_button_initialize(); +#endif /* CONFIG_BUTTONS_LOWER */ +#endif /* CONFIG_BUTTONS */ + +#ifdef CONFIG_STM32_IWDG + stm32_iwdginitialize("/dev/watchdog0", STM32_LSI_FREQUENCY); +#endif + +#ifdef CONFIG_PHOTON_WDG + + /* Start WDG kicker thread */ + + ret = photon_watchdog_initialize(); + if (ret != OK) + { + syslog(LOG_ERR, "Failed to start watchdog thread: %d\n", ret); + return ret; + } +#endif + +#ifdef CONFIG_PHOTON_WLAN + + /* Initialize wlan driver and hardware */ + + ret = photon_wlan_initialize(); + if (ret != OK) + { + syslog(LOG_ERR, "Failed to initialize wlan: %d\n", ret); + return ret; + } +#endif + + return ret; +} diff --git a/configs/photon/src/stm32_usb.c b/configs/photon/src/stm32_usb.c index 5dc24d5ed84..6f361a2c3fa 100644 --- a/configs/photon/src/stm32_usb.c +++ b/configs/photon/src/stm32_usb.c @@ -43,18 +43,6 @@ #include #include -/************************************************************************************ - * Pre-processor Definitions - ************************************************************************************/ - -/************************************************************************************ - * Private Data - ************************************************************************************/ - -/************************************************************************************ - * Private Functions - ************************************************************************************/ - /************************************************************************************ * Public Functions ************************************************************************************/ diff --git a/configs/photon/src/stm32_leds.c b/configs/photon/src/stm32_userleds.c similarity index 97% rename from configs/photon/src/stm32_leds.c rename to configs/photon/src/stm32_userleds.c index 076df40ad6c..8c7366f8a99 100644 --- a/configs/photon/src/stm32_leds.c +++ b/configs/photon/src/stm32_userleds.c @@ -1,5 +1,5 @@ /**************************************************************************** - * configs/photon/src/stm32_leds.c + * configs/photon/src/stm32_userleds.c * * Copyright (C) 2017 Gregory Nutt. All rights reserved. * Author: Simon Piriou @@ -45,6 +45,8 @@ #include "stm32_gpio.h" +#ifndef CONFIG_ARCH_LEDS + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -80,3 +82,5 @@ void board_userled_all(uint8_t ledset) { stm32_gpiowrite(GPIO_LED1, !!(ledset & BOARD_LED1_BIT)); } + +#endif /* !CONFIG_ARCH_LEDS */ diff --git a/configs/photon/src/stm32_wdt.c b/configs/photon/src/stm32_wdt.c index 1df96707c6d..8ea352925c5 100644 --- a/configs/photon/src/stm32_wdt.c +++ b/configs/photon/src/stm32_wdt.c @@ -53,11 +53,6 @@ #include #include -/************************************************************************************ - * Pre-processor Definitions - ************************************************************************************/ -/* Configuration *******************************************************************/ - /************************************************************************************ * Public Functions ************************************************************************************/ diff --git a/configs/photon/src/stm32_wlan.c b/configs/photon/src/stm32_wlan.c index a0b19e4e0fb..068561d63a4 100644 --- a/configs/photon/src/stm32_wlan.c +++ b/configs/photon/src/stm32_wlan.c @@ -38,16 +38,19 @@ ****************************************************************************/ #include + #include -#include #include #include -#include "photon.h" + +#include #include "stm32_gpio.h" #include "stm32_sdio.h" +#include "photon.h" + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -105,25 +108,29 @@ int photon_wlan_initialize() struct sdio_dev_s *sdio_dev; /* Initialize sdio interface */ - _info("Initializing SDIO slot %d\n", SDIO_WLAN0_SLOTNO); + + wlinfo("Initializing SDIO slot %d\n", SDIO_WLAN0_SLOTNO); sdio_dev = sdio_initialize(SDIO_WLAN0_SLOTNO); if (!sdio_dev) { - _err("ERROR: Failed to initialize SDIO with slot %d\n", + wlerr("ERROR: Failed to initialize SDIO with slot %d\n", SDIO_WLAN0_SLOTNO); return ERROR; } /* Bind the SDIO interface to the bcmf driver */ + ret = bcmf_sdio_initialize(SDIO_WLAN0_MINOR, sdio_dev); if (ret != OK) { - _err("ERROR: Failed to bind SDIO to bcmf driver\n"); + wlerr("ERROR: Failed to bind SDIO to bcmf driver\n"); + /* FIXME deinitialize sdio device */ return ERROR; } + return OK; } diff --git a/configs/same70-xplained/src/sam_autoleds.c b/configs/same70-xplained/src/sam_autoleds.c index 64fd6b663c3..51e5272a19c 100644 --- a/configs/same70-xplained/src/sam_autoleds.c +++ b/configs/same70-xplained/src/sam_autoleds.c @@ -1,5 +1,5 @@ /**************************************************************************** - * configs/same70-xplained/include/sam_autoleds.c + * configs/same70-xplained/src/sam_autoleds.c * * Copyright (C) 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt From 015ae22f28256aabfe13087236aa21e06ca548ec Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 13 Apr 2017 07:35:48 -0600 Subject: [PATCH 055/183] ieee802.15.4 radio: Add data structure definitions for Radio IOCTLs. --- .../wireless/ieee802154/ieee802154_radio.h | 73 +++++++++++++++++-- 1 file changed, 66 insertions(+), 7 deletions(-) diff --git a/include/nuttx/wireless/ieee802154/ieee802154_radio.h b/include/nuttx/wireless/ieee802154/ieee802154_radio.h index 0f8b7b187e8..79ad5ec6dd4 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_radio.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_radio.h @@ -43,9 +43,15 @@ ****************************************************************************/ #include + #include #include #include + +#ifdef CONFIG_NET_6LOWPAN +# include +#endif + #include /**************************************************************************** @@ -97,6 +103,8 @@ * Public Types ****************************************************************************/ +/* Structures used with IEEE802.15.4 radio interface operations *************/ + struct ieee802154_cca_s { uint8_t use_ed : 1; /* CCA using ED */ @@ -105,12 +113,63 @@ struct ieee802154_cca_s uint8_t csth; /* Carrier sense threshold for CCA */ }; -struct ieee802154_packet_s -{ - uint8_t len; - uint8_t data[127]; - uint8_t lqi; - uint8_t rssi; +struct ieee802154_packet_s +{ + uint8_t len; + uint8_t data[127]; + uint8_t lqi; + uint8_t rssi; +}; + +/* IOCTL command data argument **********************************************/ + +/* A pointer to this structure is passed as the argument of each IOCTL + * command. + */ + +union ieee802154_radioarg_u +{ + uint8_t channel; /* PHY802154IOC_GET/SET_CHAN */ + uint16_t panid; /* PHY802154IOC_GET/SET_PANID */ + uint16_t saddr; /* PHY802154IOC_GET/SET_SADDR */ + uint16_t laddr; /* PHY802154IOC_GET/SET_EADDR */ + bool promisc; /* PHY802154IOC_GET/SET_EADDR */ + bool devmode; /* PHY802154IOC_GET/SET_DEVMODE */ + int32_t txpwr; /* PHY802154IOC_GET/SET_TXPWR */ + bool energy /* PHY802154IOC_ENERGYDETECT */ + struct ieee802154_cca_s cca; /* PHY802154IOC_GET/SET_CCA */ +}; + +#ifdef CONFIG_NET_6LOWPAN +/* For the case of network IOCTLs, the network IOCTL to the MAC network + * driver will include a device name like "wpan0" as the destination of + * the IOCTL command. The MAC layer will forward only the payload union + * to the radio IOCTL method. + */ + +struct ieee802154_netradio_s +{ + char ifr_name[IFNAMSIZ]; /* Interface name, e.g. "wpan0" */ + union ieee802154_radioarg_u /* Data payload */ +}; +#endif + +/* IEEE802.15.4 Radio Interface Operations **********************************/ + +struct ieee802154_cca_s +{ + uint8_t use_ed : 1; /* CCA using ED */ + uint8_t use_cs : 1; /* CCA using carrier sense */ + uint8_t edth; /* Energy detection threshold for CCA */ + uint8_t csth; /* Carrier sense threshold for CCA */ +}; + +struct ieee802154_packet_s +{ + uint8_t len; + uint8_t data[127]; + uint8_t lqi; + uint8_t rssi; }; struct ieee802154_radio_s; @@ -163,7 +222,7 @@ struct ieee802154_radioops_s CODE int (*transmit)(FAR struct ieee802154_radio_s *dev, FAR struct ieee802154_packet_s *packet); - /*TODO beacon/sf order*/ + /* TODO beacon/sf order */ }; struct ieee802154_radio_s From 241da3ec49fb7d05a1384ba6a9f9b49a255eb24e Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 13 Apr 2017 08:14:58 -0600 Subject: [PATCH 056/183] ieee802.15.4 MAC: Add data structure definitions for MAC IOCTLs. --- .../wireless/ieee802154/ieee802154_mac.h | 143 +++++++++++++++++- 1 file changed, 142 insertions(+), 1 deletion(-) diff --git a/include/nuttx/wireless/ieee802154/ieee802154_mac.h b/include/nuttx/wireless/ieee802154/ieee802154_mac.h index 55830d70fc5..db06acd083d 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_mac.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_mac.h @@ -51,6 +51,10 @@ #include #include +#ifdef CONFIG_NET_6LOWPAN +# include +#endif + #include /**************************************************************************** @@ -181,6 +185,10 @@ /* IEEE 802.15.4 MAC PIB Attribut Defaults */ +/* Definitions used by IOCTL calls */ + +#define MAX_ORPHAN_ADDR 32 /* REVISIT */ + // TODO: Add macros /**************************************************************************** @@ -740,7 +748,140 @@ struct ieee802154_beaconnotify_ind_s (sizeof(struct ieee802154_beaconnotify_ind_s) \ - IEEE802154_MAX_BEACON_PAYLOAD_LENGTH + (n)) -/* Operations */ +/* IOCTL data arguments *****************************************************/ + +/* Data returned with MAC802154IOC_MLME_ASSOC_RESPONSE */ + +struct ieee802154_assocresp_s +{ + uint8_t eadr; + uint16_t saddr; + int status; +}; + +/* Data provided to MAC802154IOC_MLME_GET_REQUEST */ + +struct ieee802154_getreq_s +{ + enum ieee802154_pib_attr_e attr; +}; + +/* Data provided to MAC802154IOC_MLME_GTS_REQUEST */ + +struct ieee802154_gtsreq_s +{ + uint8_t characteristics; +}; + +/* Data returned with MAC802154IOC_MLME_ORPHAN_RESPONSE */ + +struct ieee802154_orphanresp_s +{ + uint8_t orphanaddr[MAX_ORPHAN_ADDR]; + uint16_t saddr; + bool associated; +}; + +/* Data provided with MAC802154IOC_MLME_RESET_REQUEST */ + +struct ieee802154_resetreq_s +{ + bool setdefaults; +}; + +/* Data provided with MAC802154IOC_MLME_RXENABLE_REQUEST */ + +struct ieee802154_rxenabreq_s +{ + bool deferrable; + int ontime; + int duration; +}; + +/* Data provided with MAC802154IOC_MLME_SCAN_REQUEST */ + +struct ieee802154_scanreq_s +{ + uint8_t type; + uint32_t channels; + int duration; +}; + +/* Data provided with MAC802154IOC_MLME_SET_REQUEST */ + +struct ieee802154_setreq_s +{ + FAR uint8_t *value; + int valuelen; + int attribute; +}; + +/* Data provided with MAC802154IOC_MLME_START_REQUEST */ + +struct ieee802154_startreq_s +{ + int channel; + uint16_t panid; + uint8_t bo; + uint8_t fo; + bool coord; + bool batext; + bool realign; +}; + +/* Data provided with MAC802154IOC_MLME_SYNC_REQUEST */ + +struct ieee802154_syncreq_s +{ + int channel; + bool track; +}; + +/* Data provided with MAC802154IOC_MLME_POLL_REQUEST */ + +struct ieee802154_pollreq_s +{ + FAR uint8_t *coordaddr; +}; + +/* A pointer to this structure is passed as the argument of each IOCTL + * command. + */ + +union ieee802154_macarg_u +{ + struct ieee802154_assoc_req_s assocreq; /* MAC802154IOC_MLME_ASSOC_REQUEST */ + struct ieee802154_assocresp_s assocresp: /* MAC802154IOC_MLME_ASSOC_RESPONSE */ + struct ieee802154_disassoc_req_s disassocreq; /* MAC802154IOC_MLME_DISASSOC_REQUEST */ + struct ieee802154_mlmereq_s getreq; /* MAC802154IOC_MLME_GET_REQUEST */ + struct ieee802154_gtsreq_s gtsreq; /* MAC802154IOC_MLME_GTS_REQUEST */ + struct ieee802154_orphanresp_s orphanresp; /* MAC802154IOC_MLME_ORPHAN_RESPONSE */ + struct ieee802154_resetreq_s resetreq; /* MAC802154IOC_MLME_RESET_REQUEST */ + struct ieee802154_rxenabreq_s rxenabreq; /* MAC802154IOC_MLME_RXENABLE_REQUEST */ + struct ieee802154_scanreq_s scanreq; /* MAC802154IOC_MLME_SCAN_REQUEST */ + struct ieee802154_setreq_s setreq; /* MAC802154IOC_MLME_SET_REQUEST */ + struct ieee802154_startreq_s startreq; /* MAC802154IOC_MLME_START_REQUEST */ + struct ieee802154_syncreq_s syncreq; /* MAC802154IOC_MLME_SYNC_REQUEST */ + struct ieee802154_pollreq_s pollreq; /* MAC802154IOC_MLME_POLL_REQUEST */ + /* To be determined */ /* MAC802154IOC_MLME_DPS_REQUEST */ + /* To be determined */ /* MAC802154IOC_MLME_SOUNDING_REQUEST */ + /* To be determined */ /* MAC802154IOC_MLME_CALIBRATE_REQUEST */ +}; + +#ifdef CONFIG_NET_6LOWPAN +/* For the case of network IOCTLs, the network IOCTL to the MAC network + * driver will include a device name like "wpan0" as the destination of + * the IOCTL command. + */ + +struct ieee802154_netmac_s +{ + char ifr_name[IFNAMSIZ]; /* Interface name, e.g. "wpan0" */ + union ieee802154_macarg_u u; /* Data payload */ +}; +#endif + +/* MAC Interface Operations *************************************************/ struct ieee802154_mac_s; /* Forward reference */ From 32962fa6e39ef0f4d755530567335b59795fd42e Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 13 Apr 2017 08:17:34 -0600 Subject: [PATCH 057/183] Add missing field name --- include/nuttx/wireless/ieee802154/ieee802154_radio.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/nuttx/wireless/ieee802154/ieee802154_radio.h b/include/nuttx/wireless/ieee802154/ieee802154_radio.h index 79ad5ec6dd4..cbd014b0b17 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_radio.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_radio.h @@ -149,8 +149,8 @@ union ieee802154_radioarg_u struct ieee802154_netradio_s { - char ifr_name[IFNAMSIZ]; /* Interface name, e.g. "wpan0" */ - union ieee802154_radioarg_u /* Data payload */ + char ifr_name[IFNAMSIZ]; /* Interface name, e.g. "wpan0" */ + union ieee802154_radioarg_u u; /* Data payload */ }; #endif From 8288f53d4ea0184150459ca6d3ccfabcb7b43f0b Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 13 Apr 2017 09:13:16 -0600 Subject: [PATCH 058/183] ieee802154 radio: Implement IOCTL decode and dispatch in all radio drivers. --- drivers/wireless/ieee802154/at86rf23x.c | 73 ++++++++++++++++++- drivers/wireless/ieee802154/mrf24j40.c | 73 ++++++++++++++++++- .../wireless/ieee802154/ieee802154_radio.h | 20 ++--- 3 files changed, 155 insertions(+), 11 deletions(-) diff --git a/drivers/wireless/ieee802154/at86rf23x.c b/drivers/wireless/ieee802154/at86rf23x.c index 7b6193c0aad..ceebfe79f9e 100644 --- a/drivers/wireless/ieee802154/at86rf23x.c +++ b/drivers/wireless/ieee802154/at86rf23x.c @@ -1154,10 +1154,81 @@ static int at86rf23x_getcca(FAR struct ieee802154_radio_s *ieee, static int at86rf23x_ioctl(FAR struct ieee802154_radio_s *ieee, int cmd, unsigned long arg) { - FAR struct at86rf23x_dev_s *dev = (FAR struct at86rf23x_dev_s *)ieee; + FAR struct at86rf23x_dev_s *dev = + (FAR struct at86rf23x_dev_s *)ieee; + FAR union ieee802154_radioarg_u *u; = + (FAR union ieee802154_radioarg_u *)((uintptr_t)arg) switch (cmd) { + case PHY802154IOC_SET_CHAN: + ret = at86rf23x_setchannel(ieee, u.channel); + break; + + case PHY802154IOC_GET_CHAN: + ret = at86rf23x_getchannel(ieee, &u.channel); + break; + + case PHY802154IOC_SET_PANID: + ret = at86rf23x_setpanid(ieee, u.panid); + break; + + case PHY802154IOC_GET_PANID: + ret = at86rf23x_getpanid(ieee, &u.panid); + break; + + case PHY802154IOC_SET_SADDR: + ret = at86rf23x_setsaddr(ieee, u.saddr); + break; + + case PHY802154IOC_GET_SADDR: + ret = at86rf23x_getsaddr(ieee, &u.saddr); + break; + + case PHY802154IOC_SET_EADDR: + ret = at86rf23x_seteaddr(ieee, u.eaddr); + break; + + case PHY802154IOC_GET_EADDR: + ret = at86rf23x_geteaddr(ieee, u.eaddr); + break; + + case PHY802154IOC_SET_PROMISC: + ret = at86rf23x_setpromisc(ieee, u.promisc); + break; + + case PHY802154IOC_GET_PROMISC: + ret = at86rf23x_getpromisc(ieee, &u.promisc); + break; + + case PHY802154IOC_SET_DEVMODE: + ret = at86rf23x_setdevmode(ieee, u.devmode); + break; + + case PHY802154IOC_GET_DEVMODE: + ret = at86rf23x_getdevmode(ieee, &u.devmode); + break; + + case PHY802154IOC_SET_TXPWR: + ret = at86rf23x_settxpower(ieee, u.txpwr); + break; + + case PHY802154IOC_GET_TXPWR: + ret = at86rf23x_gettxpower(ieee, &u.txpwr); + break; + + case PHY802154IOC_SET_CCA: + ret = at86rf23x_setcca(ieee, &u.cca); + break; + + case PHY802154IOC_GET_CCA: + ret = at86rf23x_getcca(ieee, &u.cca); + break; + + case PHY802154IOC_ENERGYDETECT: + ret = at86rf23x_energydetect(ieee, &u.energy); + break; + case 1000: return at86rf23x_regdump(dev); diff --git a/drivers/wireless/ieee802154/mrf24j40.c b/drivers/wireless/ieee802154/mrf24j40.c index 9ede37739e5..1f3f68bf983 100644 --- a/drivers/wireless/ieee802154/mrf24j40.c +++ b/drivers/wireless/ieee802154/mrf24j40.c @@ -991,10 +991,81 @@ static int mrf24j40_regdump(FAR struct mrf24j40_radio_s *dev) static int mrf24j40_ioctl(FAR struct ieee802154_radio_s *ieee, int cmd, unsigned long arg) { - FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)ieee; + FAR struct mrf24j40_radio_s *dev = + (FAR struct mrf24j40_radio_s *)ieee; + FAR union ieee802154_radioarg_u *u; = + (FAR union ieee802154_radioarg_u *)((uintptr_t)arg) switch(cmd) { + case PHY802154IOC_SET_CHAN: + ret = mrf24j40_setchannel(ieee, u.channel); + break; + + case PHY802154IOC_GET_CHAN: + ret = mrf24j40_getchannel(ieee, &u.channel); + break; + + case PHY802154IOC_SET_PANID: + ret = mrf24j40_setpanid(ieee, u.panid); + break; + + case PHY802154IOC_GET_PANID: + ret = mrf24j40_getpanid(ieee, &u.panid); + break; + + case PHY802154IOC_SET_SADDR: + ret = mrf24j40_setsaddr(ieee, u.saddr); + break; + + case PHY802154IOC_GET_SADDR: + ret = mrf24j40_getsaddr(ieee, &u.saddr); + break; + + case PHY802154IOC_SET_EADDR: + ret = mrf24j40_seteaddr(ieee, u.eaddr); + break; + + case PHY802154IOC_GET_EADDR: + ret = mrf24j40_geteaddr(ieee, u.eaddr); + break; + + case PHY802154IOC_SET_PROMISC: + ret = mrf24j40_setpromisc(ieee, u.promisc); + break; + + case PHY802154IOC_GET_PROMISC: + ret = mrf24j40_getpromisc(ieee, &u.promisc); + break; + + case PHY802154IOC_SET_DEVMODE: + ret = mrf24j40_setdevmode(ieee, u.devmode); + break; + + case PHY802154IOC_GET_DEVMODE: + ret = mrf24j40_getdevmode(ieee, &u.devmode); + break; + + case PHY802154IOC_SET_TXPWR: + ret = mrf24j40_settxpower(ieee, u.txpwr); + break; + + case PHY802154IOC_GET_TXPWR: + ret = mrf24j40_gettxpower(ieee, &u.txpwr); + break; + + case PHY802154IOC_SET_CCA: + ret = mrf24j40_setcca(ieee, &u.cca); + break; + + case PHY802154IOC_GET_CCA: + ret = mrf24j40_getcca(ieee, &u.cca); + break; + + case PHY802154IOC_ENERGYDETECT: + ret = mrf24j40_energydetect(ieee, &u.energy); + break; + case 1000: return mrf24j40_regdump(dev); diff --git a/include/nuttx/wireless/ieee802154/ieee802154_radio.h b/include/nuttx/wireless/ieee802154/ieee802154_radio.h index cbd014b0b17..af44f964450 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_radio.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_radio.h @@ -99,6 +99,8 @@ #define PHY802154IOC_ENERGYDETECT _PHY802154IOC(0x0011) +#define EADDR_SIZE 8 /* REVISIT */ + /**************************************************************************** * Public Types ****************************************************************************/ @@ -129,15 +131,15 @@ struct ieee802154_packet_s union ieee802154_radioarg_u { - uint8_t channel; /* PHY802154IOC_GET/SET_CHAN */ - uint16_t panid; /* PHY802154IOC_GET/SET_PANID */ - uint16_t saddr; /* PHY802154IOC_GET/SET_SADDR */ - uint16_t laddr; /* PHY802154IOC_GET/SET_EADDR */ - bool promisc; /* PHY802154IOC_GET/SET_EADDR */ - bool devmode; /* PHY802154IOC_GET/SET_DEVMODE */ - int32_t txpwr; /* PHY802154IOC_GET/SET_TXPWR */ - bool energy /* PHY802154IOC_ENERGYDETECT */ - struct ieee802154_cca_s cca; /* PHY802154IOC_GET/SET_CCA */ + uint8_t channel; /* PHY802154IOC_GET/SET_CHAN */ + uint16_t panid; /* PHY802154IOC_GET/SET_PANID */ + uint16_t saddr; /* PHY802154IOC_GET/SET_SADDR */ + uint8_t eaddr[EADDR_SIZE]; /* PHY802154IOC_GET/SET_EADDR */ + bool promisc; /* PHY802154IOC_GET/SET_EADDR */ + uint8_t devmode; /* PHY802154IOC_GET/SET_DEVMODE */ + int32_t txpwr; /* PHY802154IOC_GET/SET_TXPWR */ + bool energy /* PHY802154IOC_ENERGYDETECT */ + struct ieee802154_cca_s cca; /* PHY802154IOC_GET/SET_CCA */ }; #ifdef CONFIG_NET_6LOWPAN From fae1df31dca3203a367fd0a522a326106d279cf7 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 13 Apr 2017 10:18:57 -0600 Subject: [PATCH 059/183] ieee802.15.4 netdev: Add IOCTL support. --- .../wireless/ieee802154/ieee802154_mac.h | 5 ++ wireless/ieee802154/mac802154_netdev.c | 69 +++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/include/nuttx/wireless/ieee802154/ieee802154_mac.h b/include/nuttx/wireless/ieee802154/ieee802154_mac.h index db06acd083d..acfcdac6db8 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_mac.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_mac.h @@ -959,6 +959,11 @@ struct ieee802154_macops_s CODE int (*rsp_orphan)(FAR struct ieee802154_mac_s *mac, FAR uint8_t *orphanaddr, uint16_t saddr, bool associated); + + /* IOCTL support */ + + CODE int (*ioctl)(FAR struct ieee802154_mac_s *mac, int cmd, + unsigned long arg); }; /* Notifications */ diff --git a/wireless/ieee802154/mac802154_netdev.c b/wireless/ieee802154/mac802154_netdev.c index 1f5f2335e18..f5b0aed51c2 100644 --- a/wireless/ieee802154/mac802154_netdev.c +++ b/wireless/ieee802154/mac802154_netdev.c @@ -235,6 +235,9 @@ static int mac802154_rmmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac static void mac802154_ipv6multicast(FAR struct mac802154_driver_s *priv); #endif #endif +#ifdef CONFIG_NETDEV_IOCTL +static int mac802154_ioctl(FAR struct net_driver_s *dev, int cmd, long arg); +#endif /**************************************************************************** * Private Functions @@ -1344,6 +1347,69 @@ static void mac802154_ipv6multicast(FAR struct mac802154_driver_s *priv) } #endif /* CONFIG_NET_ICMPv6 */ +/**************************************************************************** + * Name: mac802154_ioctl + * + * Description: + * Handle network IOCTL commands directed to this device. + * + * Parameters: + * dev - Reference to the NuttX driver state structure + * cmd - The IOCTL command + * arg - The argument for the IOCTL command + * + * Returned Value: + * OK on success; Negated errno on failure. + * + * Assumptions: + * + ****************************************************************************/ + +#ifdef CONFIG_NETDEV_IOCTL +static int mac802154_ioctl(FAR struct net_driver_s *dev, int cmd, long arg) +{ + FAR struct mac802154_driver_s *priv = (FAR struct mac802154_driver_s *)dev->d_private; + int ret = -EINVAL; + + /* Check for IOCTLs aimed at the IEEE802.15.4 MAC layer */ + + if (_MAC802154IOCVALID(cmd)) + { + FAR struct ieee802154_netmac_s *netmac = + (FAR struct ieee802154_netmac_s *)arg; + + if (netmac != NULL) + { + unsigned long macarg = (unsigned int)((uintptr_t)&netmac->u); + ret = priv->m8_mac.macops.ioctl(priv->m8_mac, cmd, macarg); + } + } + + /* No, check for IOCTLs aimed at the IEEE802.15.4 radio layer */ + + else if (_PHY802154IOCVALID(cmd)) + { + FAR struct ieee802154_netradio_s *netradio = + (FAR struct ieee802154_netradio_s *)arg; + + if (netradio != NULL) + { + unsigned long radioarg = (unsigned int)((uintptr_t)&netradio->u); + ret = priv->m8_mac.macops.ioctl(priv->m8_mac, cmd, radioarg); + } + } + + /* Okay, we have no idea what this command is.. just give to the + * IEEE802.15.4 MAC layer without modification. + */ + + else + { + ret = priv->m8_mac.macops.ioctl(priv->m8_mac, cmd, arg); + } +} +#endif + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -1406,6 +1472,9 @@ int mac802154netdev_register(FAR struct ieee802154_mac_s *mac); #ifdef CONFIG_NET_IGMP dev->d_addmac = mac802154_addmac; /* Add multicast MAC address */ dev->d_rmmac = mac802154_rmmac; /* Remove multicast MAC address */ +#endif + #ifdef CONFIG_NETDEV_IOCTL + dev->d_ioctl = mac802154_ioctl; /* Handle network IOCTL commands */ #endif dev->d_private = (FAR void *)priv; /* Used to recover private state from dev */ From 6b8a8bda355dc2a711efa5cfeab6654718b4f04e Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 13 Apr 2017 11:14:02 -0600 Subject: [PATCH 060/183] ieee802.15.4 radio: Remove interface methods that duplicate IOCTL commands. --- drivers/wireless/ieee802154/at86rf23x.c | 61 ++++++++----------- drivers/wireless/ieee802154/mrf24j40.c | 18 ++---- .../wireless/ieee802154/ieee802154_radio.h | 39 ------------ 3 files changed, 30 insertions(+), 88 deletions(-) diff --git a/drivers/wireless/ieee802154/at86rf23x.c b/drivers/wireless/ieee802154/at86rf23x.c index ceebfe79f9e..e3429c4d1fa 100644 --- a/drivers/wireless/ieee802154/at86rf23x.c +++ b/drivers/wireless/ieee802154/at86rf23x.c @@ -148,7 +148,7 @@ static void at86rf23x_irqwork_tx(FAR struct at86rf23x_dev_s *dev); static void at86rf23x_irqworker(FAR void *arg); static int at86rf23x_interrupt(int irq, FAR void *context, FAR void *arg); -/* Driver operations */ +/* IOCTL helpers */ static int at86rf23x_setchannel(FAR struct ieee802154_radio_s *ieee, uint8_t chan); @@ -182,10 +182,13 @@ static int at86rf23x_setcca(FAR struct ieee802154_radio_s *ieee, FAR struct ieee802154_cca_s *cca); static int at86rf23x_getcca(FAR struct ieee802154_radio_s *ieee, FAR struct ieee802154_cca_s *cca); -static int at86rf23x_ioctl(FAR struct ieee802154_radio_s *ieee, int cmd, - unsigned long arg); static int at86rf23x_energydetect(FAR struct ieee802154_radio_s *ieee, FAR uint8_t *energy); + +/* Driver operations */ + +static int at86rf23x_ioctl(FAR struct ieee802154_radio_s *ieee, int cmd, + unsigned long arg); static int at86rf23x_rxenable(FAR struct ieee802154_radio_s *ieee, bool state, FAR struct ieee802154_packet_s *packet); static int at86rf23x_transmit(FAR struct ieee802154_radio_s *ieee, @@ -206,24 +209,7 @@ static struct at86rf23x_dev_s g_at86rf23x_devices[1]; static const struct ieee802154_radioops_s at86rf23x_devops = { - .setchannel = at86rf23x_setchannel, - .getchannel = at86rf23x_getchannel, - .setpanid = at86rf23x_setpanid, - .getpanid = at86rf23x_getpanid, - .setsaddr = at86rf23x_setsaddr, - .getsaddr = at86rf23x_getsaddr, - .seteaddr = at86rf23x_seteaddr, - .geteaddr = at86rf23x_geteaddr, - .setpromisc = at86rf23x_setpromisc, - .getpromisc = at86rf23x_getpromisc, - .setdevmode = at86rf23x_setdevmode, - .getdevmode = at86rf23x_getdevmode, - .settxpower = at86rf23x_settxpower, - .gettxpower = at86rf23x_gettxpower, - .setcca = at86rf23x_setcca, - .getcca = at86rf23x_getcca, .ioctl = at86rf23x_ioctl, - .energydetect = at86rf23x_energydetect, .rxenable = at86rf23x_rxenable, .transmit = at86rf23x_transmit }; @@ -1143,6 +1129,24 @@ static int at86rf23x_getcca(FAR struct ieee802154_radio_s *ieee, return ERROR; } +/**************************************************************************** + * Name: at86rf23x_energydetect + * + * Description: + * Perform energy detection scan. TODO: Need to implement. + * + ****************************************************************************/ + +static int at86rf23x_energydetect(FAR struct ieee802154_radio_s *ieee, + FAR uint8_t *energy) +{ +#warning at86rf23x_energydetect not implemented. + + /* Not yet implemented */ + + return ERROR; +} + /**************************************************************************** * Name: at86rf23x_ioctl * @@ -1237,23 +1241,6 @@ static int at86rf23x_ioctl(FAR struct ieee802154_radio_s *ieee, int cmd, } } -/**************************************************************************** - * Name: at86rf23x_energydetect - * - * Description: - * Perform energy detection scan. TODO: Need to implement. - * - ****************************************************************************/ -static int at86rf23x_energydetect(FAR struct ieee802154_radio_s *ieee, - FAR uint8_t *energy) -{ -#warning at86rf23x_energydetect not implemented. - - /* Not yet implemented */ - - return ERROR; -} - /**************************************************************************** * Name: at86rf23x_initialize * diff --git a/drivers/wireless/ieee802154/mrf24j40.c b/drivers/wireless/ieee802154/mrf24j40.c index 1f3f68bf983..263de68eebf 100644 --- a/drivers/wireless/ieee802154/mrf24j40.c +++ b/drivers/wireless/ieee802154/mrf24j40.c @@ -140,7 +140,7 @@ static void mrf24j40_irqwork_tx(FAR struct mrf24j40_radio_s *dev); static void mrf24j40_irqworker(FAR void *arg); static int mrf24j40_interrupt(int irq, FAR void *context, FAR void *arg); -/* Driver operations */ +/* IOCTL helpers */ static int mrf24j40_setchannel(FAR struct ieee802154_radio_s *ieee, uint8_t chan); @@ -174,10 +174,13 @@ static int mrf24j40_setcca(FAR struct ieee802154_radio_s *ieee, FAR struct ieee802154_cca_s *cca); static int mrf24j40_getcca(FAR struct ieee802154_radio_s *ieee, FAR struct ieee802154_cca_s *cca); -static int mrf24j40_ioctl(FAR struct ieee802154_radio_s *ieee, int cmd, - unsigned long arg); static int mrf24j40_energydetect(FAR struct ieee802154_radio_s *ieee, FAR uint8_t *energy); + +/* Driver operations */ + +static int mrf24j40_ioctl(FAR struct ieee802154_radio_s *ieee, int cmd, + unsigned long arg); static int mrf24j40_rxenable(FAR struct ieee802154_radio_s *ieee, bool state, FAR struct ieee802154_packet_s *packet); static int mrf24j40_transmit(FAR struct ieee802154_radio_s *ieee, @@ -198,16 +201,7 @@ static struct mrf24j40_radio_s g_mrf24j40_devices[1]; static const struct ieee802154_radioops_s mrf24j40_devops = { - mrf24j40_setchannel, mrf24j40_getchannel, - mrf24j40_setpanid , mrf24j40_getpanid, - mrf24j40_setsaddr , mrf24j40_getsaddr, - mrf24j40_seteaddr , mrf24j40_geteaddr, - mrf24j40_setpromisc, mrf24j40_getpromisc, - mrf24j40_setdevmode, mrf24j40_getdevmode, - mrf24j40_settxpower, mrf24j40_gettxpower, - mrf24j40_setcca , mrf24j40_getcca, mrf24j40_ioctl, - mrf24j40_energydetect, mrf24j40_rxenable, mrf24j40_transmit }; diff --git a/include/nuttx/wireless/ieee802154/ieee802154_radio.h b/include/nuttx/wireless/ieee802154/ieee802154_radio.h index af44f964450..5bee1e3d52d 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_radio.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_radio.h @@ -178,47 +178,8 @@ struct ieee802154_radio_s; struct ieee802154_radioops_s { - CODE int (*setchannel)(FAR struct ieee802154_radio_s *dev, - uint8_t channel); - CODE int (*getchannel)(FAR struct ieee802154_radio_s *dev, - FAR uint8_t *channel); - - CODE int (*setpanid)(FAR struct ieee802154_radio_s *dev, uint16_t panid); - CODE int (*getpanid)(FAR struct ieee802154_radio_s *dev, - FAR uint16_t *panid); - - CODE int (*setsaddr)(FAR struct ieee802154_radio_s *dev, uint16_t saddr); - CODE int (*getsaddr)(FAR struct ieee802154_radio_s *dev, - FAR uint16_t *saddr); - - CODE int (*seteaddr)(FAR struct ieee802154_radio_s *dev, - FAR uint8_t *laddr); - CODE int (*geteaddr)(FAR struct ieee802154_radio_s *dev, - FAR uint8_t *laddr); - - CODE int (*setpromisc)(FAR struct ieee802154_radio_s *dev, bool promisc); - CODE int (*getpromisc)(FAR struct ieee802154_radio_s *dev, - FAR bool *promisc); - - CODE int (*setdevmode)(FAR struct ieee802154_radio_s *dev, - uint8_t devmode); - CODE int (*getdevmode)(FAR struct ieee802154_radio_s *dev, - FAR uint8_t *devmode); - - CODE int (*settxpower)(FAR struct ieee802154_radio_s *dev, - int32_t txpwr); /* unit = 1 mBm = 1/100 dBm */ - CODE int (*gettxpower)(FAR struct ieee802154_radio_s *dev, - FAR int32_t *txpwr); - - CODE int (*setcca)(FAR struct ieee802154_radio_s *dev, - FAR struct ieee802154_cca_s *cca); - CODE int (*getcca)(FAR struct ieee802154_radio_s *dev, - FAR struct ieee802154_cca_s *cca); - CODE int (*ioctl)(FAR struct ieee802154_radio_s *ieee, int cmd, unsigned long arg); - CODE int (*energydetect)(FAR struct ieee802154_radio_s *dev, - FAR uint8_t *energy); CODE int (*rxenable)(FAR struct ieee802154_radio_s *dev, bool state, FAR struct ieee802154_packet_s *packet); CODE int (*transmit)(FAR struct ieee802154_radio_s *dev, From c1ddae5c5ea2f0546161cf584f539e2150813df1 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 13 Apr 2017 12:17:36 -0600 Subject: [PATCH 061/183] ieee802.15.4: de-couple MAC driver interface. Now works more like other drivers. --- .../wireless/ieee802154/ieee802154_mac.h | 22 +- wireless/ieee802154/mac802154.c | 78 +++++- wireless/ieee802154/mac802154_device.c | 13 +- wireless/ieee802154/mac802154_netdev.c | 226 +++++++++++------- 4 files changed, 236 insertions(+), 103 deletions(-) diff --git a/include/nuttx/wireless/ieee802154/ieee802154_mac.h b/include/nuttx/wireless/ieee802154/ieee802154_mac.h index acfcdac6db8..5dbed05ea77 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_mac.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_mac.h @@ -883,7 +883,8 @@ struct ieee802154_netmac_s /* MAC Interface Operations *************************************************/ -struct ieee802154_mac_s; /* Forward reference */ +struct ieee802154_mac_s; /* Forward reference */ +struct ieee802154_maccb_s; /* Forward reference */ struct ieee802154_macops_s { @@ -960,6 +961,11 @@ struct ieee802154_macops_s FAR uint8_t *orphanaddr, uint16_t saddr, bool associated); + /* Bind callbacks to the IEEE802.15.4 MAC */ + + CODE int (*bind)(FAR struct ieee802154_mac_s *mac, + FAR const struct ieee802154_maccb_s *cb); + /* IOCTL support */ CODE int (*ioctl)(FAR struct ieee802154_mac_s *mac, int cmd, @@ -970,10 +976,6 @@ struct ieee802154_macops_s struct ieee802154_maccb_s { - /* Context arg for handling callback */ - - FAR void *cb_context; - /* Asynchronous confirmations to requests */ /* Data frame was received by remote device */ @@ -1064,13 +1066,13 @@ struct ieee802154_maccb_s CODE void (*ind_syncloss)(FAR struct ieee802154_mac_s *mac, int reason); }; -struct ieee802154_radio_s; /* Forward reference */ - struct ieee802154_mac_s { - FAR struct ieee802154_radio_s *radio; + /* Publicly visiable part of the MAC interface */ + struct ieee802154_macops_s ops; - struct ieee802154_maccb_s cbs; + + /* MAC private data may follow */ }; #ifdef __cplusplus @@ -1085,6 +1087,8 @@ extern "C" * Public Function Prototypes ****************************************************************************/ +struct ieee802154_radio_s; /* Forward reference */ + /**************************************************************************** * Name: mac802154_create * diff --git a/wireless/ieee802154/mac802154.c b/wireless/ieee802154/mac802154.c index f291d76199c..a1bf2655341 100644 --- a/wireless/ieee802154/mac802154.c +++ b/wireless/ieee802154/mac802154.c @@ -61,7 +61,9 @@ struct ieee802154_privmac_s { - struct ieee802154_mac_s pubmac; /* This MUST be the first member */ + struct ieee802154_mac_s pubmac; /* This MUST be the first member */ + FAR struct ieee802154_radio_s *radio; /* Contained IEEE802.15.4 radio dev */ + FAR const struct ieee802154_maccb_s *cb; /* Contained MAC callbacks */ /* MIB attributes, grouped to save memory */ /* 0x40 */ uint8_t macAckWaitDuration : 1; /* 55 or 120(true) */ @@ -143,6 +145,10 @@ static int mac802154_rsp_associate(FAR struct ieee802154_mac_s *mac, static int mac802154_rsp_orphan(FAR struct ieee802154_mac_s *mac, FAR uint8_t *orphanaddr, uint16_t saddr, bool associated); +static int mac802154_bind(FAR struct ieee802154_mac_s *mac, + FAR struct ieee802154_maccb_s *cb); +static int mac802154_ioctl(FAR struct ieee802154_mac_s *mac, int cmd, + unsigned long arg); /**************************************************************************** * Private Data @@ -502,10 +508,76 @@ static int mac802154_rsp_orphan(FAR struct ieee802154_mac_s *mac, FAR uint8_t *orphanaddr, uint16_t saddr, bool associated) { - FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; + FAR struct ieee802154_privmac_s *priv = + (FAR struct ieee802154_privmac_s *)mac; return -ENOTTY; } +/**************************************************************************** + * Name: mac802154_bind + * + * Description: + * Bind the MAC callback table to the MAC state. + * + * Parameters: + * mac - Reference to the MAC driver state structure + * cb - MAC callback operations + * + * Returned Value: + * OK on success; Negated errno on failure. + * + ****************************************************************************/ + +static int mac802154_bind(FAR struct ieee802154_mac_s *mac, + FAR const struct ieee802154_maccb_s *cb) +{ + FAR struct ieee802154_privmac_s *priv = + (FAR struct ieee802154_privmac_s *)mac; + + priv->cb = cb; + return OK; +} + +/**************************************************************************** + * Name: mac802154_ioctl + * + * Description: + * Handle MAC and radio IOCTL commands directed to the MAC. + * + * Parameters: + * mac - Reference to the MAC driver state structure + * cmd - The IOCTL command + * arg - The argument for the IOCTL command + * + * Returned Value: + * OK on success; Negated errno on failure. + * + ****************************************************************************/ + +static int mac802154_ioctl(FAR struct ieee802154_mac_s *mac, int cmd, + unsigned long arg) +{ + FAR struct ieee802154_privmac_s *priv = + (FAR struct ieee802154_privmac_s *)mac; + int ret = -EINVAL; + + /* Check for IOCTLs aimed at the IEEE802.15.4 MAC layer */ + + if (_MAC802154IOCVALID(cmd)) + { + /* Handle the MAC IOCTL command */ +#warning Missing logic + } + + /* No, other IOCTLs must be aimed at the IEEE802.15.4 radio layer */ + + else + { + ret = priv->radio->ioctl(priv->radio, cmd, arg); + } +} +#endif + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -552,7 +624,7 @@ FAR struct ieee802154_mac_s * /* Initialize fields */ - mac->pubmac.radio = radiodev; + mac->radio = radiodev; mac->pubmac.ops = mac802154ops; mac802154_defaultmib(mac); diff --git a/wireless/ieee802154/mac802154_device.c b/wireless/ieee802154/mac802154_device.c index d2bc2489801..83e33f8cf38 100644 --- a/wireless/ieee802154/mac802154_device.c +++ b/wireless/ieee802154/mac802154_device.c @@ -494,9 +494,10 @@ void mac802154dev_conf_data(FAR struct ieee802154_mac_s *mac, /* Get the dev from the callback context. This should have been set when * the char driver was registered. + * + * REVISIT: See mac802154_netdev.c */ - - dev = mac->cbs.cb_context; +#warning Missing logic /* Get exclusive access to the driver structure */ @@ -554,7 +555,13 @@ int mac802154dev_register(FAR struct ieee802154_mac_s *mac, int minor) dev->md_mac = mac; sem_init(&dev->md_exclsem, 0, 1); /* Allow the device to be opened once * before blocking */ - + + /* Initialize the callbacks and bind them to the radio + * + * REVISIT: See mac802154_netdev.c + */ +#warning Missing logic + /* Create the character device name */ snprintf(devname, DEVNAME_FMTLEN, DEVNAME_FMT, minor); diff --git a/wireless/ieee802154/mac802154_netdev.c b/wireless/ieee802154/mac802154_netdev.c index f5b0aed51c2..6dd798f24b5 100644 --- a/wireless/ieee802154/mac802154_netdev.c +++ b/wireless/ieee802154/mac802154_netdev.c @@ -103,12 +103,22 @@ /* This is a helper pointer for accessing the contents of the Ethernet header */ -#define BUF ((struct eth_hdr_s *)priv->m8_dev.d_buf) +#define BUF ((struct eth_hdr_s *)priv->md_dev.d_buf) /**************************************************************************** * Private Types ****************************************************************************/ +/* This is our private version of the MAC callback stucture */ + +struct mac802154_callback_s +{ + /* This holds the information visible to the MAC layer */ + + struct ieee802154_maccb_s mc_cb; /* Interface understood by the MAC layer */ + FAR struct mac802154_driver_s *mc_priv; /* Our priv data */ +}; + /* The mac802154_driver_s encapsulates all state information for a single * IEEE802.15.4 MAC interface. */ @@ -117,16 +127,17 @@ struct mac802154_driver_s { /* This holds the information visible to the NuttX network */ - struct ieee802154_driver_s m8_dev; /* Interface understood by the network */ - FAR struct ieee802154_mac_s *m8_mac; /* Contained MAC interface */ + struct ieee802154_driver_s md_dev; /* Interface understood by the network */ + FAR struct ieee802154_mac_s *md_mac; /* Contained MAC interface */ + struct mac802154_callback_s md_cb; /* Callback information */ /* For internal use by this driver */ - bool m8_bifup; /* true:ifup false:ifdown */ - WDOG_ID m8_txpoll; /* TX poll timer */ - WDOG_ID m8_txtimeout; /* TX timeout timer */ - struct work_s m8_irqwork; /* For deferring interupt work to the work queue */ - struct work_s m8_pollwork; /* For deferring poll work to the work queue */ + bool md_bifup; /* true:ifup false:ifdown */ + WDOG_ID md_txpoll; /* TX poll timer */ + WDOG_ID md_txtimeout; /* TX timeout timer */ + struct work_s md_irqwork; /* For deferring interupt work to the work queue */ + struct work_s md_pollwork; /* For deferring poll work to the work queue */ }; /**************************************************************************** @@ -254,10 +265,11 @@ static int mac802154_ioctl(FAR struct net_driver_s *dev, int cmd, long arg); static void mac802154_conf_data(FAR struct ieee802154_mac_s *mac, FAR struct ieee802154_data_conf_s *conf) { + FAR struct mac802154_callback_s *cb = (FAR struct mac802154_callback_s *)mac; FAR struct mac802154_driver_s *priv; - DEBUGASSERT(mac != NULL && mac->cb_context); - priv = (FAR struct mac802154_driver_s *)mac->cb_context; + DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); + priv = cb->mc_priv; } /**************************************************************************** @@ -271,10 +283,11 @@ static void mac802154_conf_data(FAR struct ieee802154_mac_s *mac, static void mac802154_conf_purge(FAR struct ieee802154_mac_s *mac, uint8_t handle, int status) { + FAR struct mac802154_callback_s *cb = (FAR struct mac802154_callback_s *)mac; FAR struct mac802154_driver_s *priv; - DEBUGASSERT(mac != NULL && mac->cb_context); - priv = (FAR struct mac802154_driver_s *)mac->cb_context; + DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); + priv = cb->mc_priv; } /**************************************************************************** @@ -288,10 +301,11 @@ static void mac802154_conf_purge(FAR struct ieee802154_mac_s *mac, static void mac802154_conf_associate(FAR struct ieee802154_mac_s *mac, uint16_t saddr, int status) { + FAR struct mac802154_callback_s *cb = (FAR struct mac802154_callback_s *)mac; FAR struct mac802154_driver_s *priv; - DEBUGASSERT(mac != NULL && mac->cb_context); - priv = (FAR struct mac802154_driver_s *)mac->cb_context; + DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); + priv = cb->mc_priv; } /**************************************************************************** @@ -304,10 +318,11 @@ static void mac802154_conf_associate(FAR struct ieee802154_mac_s *mac, static void mac802154_conf_disassociate(FAR struct ieee802154_mac_s *mac, { + FAR struct mac802154_callback_s *cb = (FAR struct mac802154_callback_s *)mac; FAR struct mac802154_driver_s *priv; - DEBUGASSERT(mac != NULL && mac->cb_context); - priv = (FAR struct mac802154_driver_s *)mac->cb_context; + DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); + priv = cb->mc_priv; } /**************************************************************************** @@ -322,10 +337,11 @@ static void mac802154_conf_get(FAR struct ieee802154_mac_s *mac, int status, int attribute, FAR uint8_t *value, int valuelen) { + FAR struct mac802154_callback_s *cb = (FAR struct mac802154_callback_s *)mac; FAR struct mac802154_driver_s *priv; - DEBUGASSERT(mac != NULL && mac->cb_context); - priv = (FAR struct mac802154_driver_s *)mac->cb_context; + DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); + priv = cb->mc_priv; } /**************************************************************************** @@ -339,10 +355,11 @@ static void mac802154_conf_get(FAR struct ieee802154_mac_s *mac, int status, static void mac802154_conf_gts(FAR struct ieee802154_mac_s *mac, FAR uint8_t *characteristics, int status) { + FAR struct mac802154_callback_s *cb = (FAR struct mac802154_callback_s *)mac; FAR struct mac802154_driver_s *priv; - DEBUGASSERT(mac != NULL && mac->cb_context); - priv = (FAR struct mac802154_driver_s *)mac->cb_context; + DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); + priv = cb->mc_priv; } /**************************************************************************** @@ -356,10 +373,11 @@ static void mac802154_conf_gts(FAR struct ieee802154_mac_s *mac, static void mac802154_conf_reset(FAR struct ieee802154_mac_s *mac, int status) { + FAR struct mac802154_callback_s *cb = (FAR struct mac802154_callback_s *)mac; FAR struct mac802154_driver_s *priv; - DEBUGASSERT(mac != NULL && mac->cb_context); - priv = (FAR struct mac802154_driver_s *)mac->cb_context; + DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); + priv = cb->mc_priv; } /**************************************************************************** @@ -372,10 +390,11 @@ static void mac802154_conf_reset(FAR struct ieee802154_mac_s *mac, static void mac802154_conf_rxenable(FAR struct ieee802154_mac_s *mac, int status) { + FAR struct mac802154_callback_s *cb = (FAR struct mac802154_callback_s *)mac; FAR struct mac802154_driver_s *priv; - DEBUGASSERT(mac != NULL && mac->cb_context); - priv = (FAR struct mac802154_driver_s *)mac->cb_context; + DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); + priv = cb->mc_priv; } /**************************************************************************** @@ -390,10 +409,11 @@ static void mac802154_conf_scan(FAR struct ieee802154_mac_s *mac, uint32_t unscanned, int rsltsize, FAR uint8_t *edlist, FAR uint8_t *pandescs) { + FAR struct mac802154_callback_s *cb = (FAR struct mac802154_callback_s *)mac; FAR struct mac802154_driver_s *priv; - DEBUGASSERT(mac != NULL && mac->cb_context); - priv = (FAR struct mac802154_driver_s *)mac->cb_context; + DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); + priv = cb->mc_priv; } /**************************************************************************** @@ -406,10 +426,11 @@ static void mac802154_conf_scan(FAR struct ieee802154_mac_s *mac, static void mac802154_conf_set(FAR struct ieee802154_mac_s *mac, int status, int attribute) { + FAR struct mac802154_callback_s *cb = (FAR struct mac802154_callback_s *)mac; FAR struct mac802154_driver_s *priv; - DEBUGASSERT(mac != NULL && mac->cb_context); - priv = (FAR struct mac802154_driver_s *)mac->cb_context; + DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); + priv = cb->mc_priv; } /**************************************************************************** @@ -422,10 +443,11 @@ static void mac802154_conf_set(FAR struct ieee802154_mac_s *mac, int status, static void mac802154_conf_start(FAR struct ieee802154_mac_s *mac, int status) { + FAR struct mac802154_callback_s *cb = (FAR struct mac802154_callback_s *)mac; FAR struct mac802154_driver_s *priv; - DEBUGASSERT(mac != NULL && mac->cb_context); - priv = (FAR struct mac802154_driver_s *)mac->cb_context; + DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); + priv = cb->mc_priv; } /**************************************************************************** @@ -438,10 +460,11 @@ static void mac802154_conf_start(FAR struct ieee802154_mac_s *mac, static void mac802154_conf_poll(FAR struct ieee802154_mac_s *mac, int status) { + FAR struct mac802154_callback_s *cb = (FAR struct mac802154_callback_s *)mac; FAR struct mac802154_driver_s *priv; - DEBUGASSERT(mac != NULL && mac->cb_context); - priv = (FAR struct mac802154_driver_s *)mac->cb_context; + DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); + priv = cb->mc_priv; } /**************************************************************************** @@ -455,10 +478,11 @@ static void mac802154_conf_poll(FAR struct ieee802154_mac_s *mac, static void mac802154_ind_data(FAR struct ieee802154_mac_s *mac, FAR uint8_t *buf, int len) { + FAR struct mac802154_callback_s *cb = (FAR struct mac802154_callback_s *)mac; FAR struct mac802154_driver_s *priv; - DEBUGASSERT(mac != NULL && mac->cb_context); - priv = (FAR struct mac802154_driver_s *)mac->cb_context; + DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); + priv = cb->mc_priv; } /**************************************************************************** @@ -473,10 +497,11 @@ static void mac802154_ind_associate(FAR struct ieee802154_mac_s *mac, uint16_t clipanid, FAR uint8_t *clieaddr) { + FAR struct mac802154_callback_s *cb = (FAR struct mac802154_callback_s *)mac; FAR struct mac802154_driver_s *priv; - DEBUGASSERT(mac != NULL && mac->cb_context); - priv = (FAR struct mac802154_driver_s *)mac->cb_context; + DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); + priv = cb->mc_priv; } /**************************************************************************** @@ -490,10 +515,11 @@ static void mac802154_ind_associate(FAR struct ieee802154_mac_s *mac, static void mac802154_ind_disassociate(FAR struct ieee802154_mac_s *mac, FAR uint8_t *eadr, uint8_t reason) { + FAR struct mac802154_callback_s *cb = (FAR struct mac802154_callback_s *)mac; FAR struct mac802154_driver_s *priv; - DEBUGASSERT(mac != NULL && mac->cb_context); - priv = (FAR struct mac802154_driver_s *)mac->cb_context; + DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); + priv = cb->mc_priv; } /**************************************************************************** @@ -509,10 +535,11 @@ static void mac802154_ind_beaconnotify(FAR struct ieee802154_mac_s *mac, FAR struct ieee802154_pan_desc_s *pandesc, FAR uint8_t *sdu, int sdulen) { + FAR struct mac802154_callback_s *cb = (FAR struct mac802154_callback_s *)mac; FAR struct mac802154_driver_s *priv; - DEBUGASSERT(mac != NULL && mac->cb_context); - priv = (FAR struct mac802154_driver_s *)mac->cb_context; + DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); + priv = cb->mc_priv; } /**************************************************************************** @@ -527,10 +554,11 @@ static void mac802154_ind_gts(FAR struct ieee802154_mac_s *mac, FAR uint8_t *devaddr, FAR uint8_t *characteristics) { + FAR struct mac802154_callback_s *cb = (FAR struct mac802154_callback_s *)mac; FAR struct mac802154_driver_s *priv; - DEBUGASSERT(mac != NULL && mac->cb_context); - priv = (FAR struct mac802154_driver_s *)mac->cb_context; + DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); + priv = cb->mc_priv; } /**************************************************************************** @@ -544,10 +572,11 @@ static void mac802154_ind_gts(FAR struct ieee802154_mac_s *mac, static void mac802154_ind_orphan(FAR struct ieee802154_mac_s *mac, FAR uint8_t *orphanaddr) { + FAR struct mac802154_callback_s *cb = (FAR struct mac802154_callback_s *)mac; FAR struct mac802154_driver_s *priv; - DEBUGASSERT(mac != NULL && mac->cb_context); - priv = (FAR struct mac802154_driver_s *)mac->cb_context; + DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); + priv = cb->mc_priv; } /**************************************************************************** @@ -561,10 +590,11 @@ static void mac802154_ind_commstatus(FAR struct ieee802154_mac_s *mac, uint16_t panid, FAR uint8_t *src, FAR uint8_t *dst, int status) { + FAR struct mac802154_callback_s *cb = (FAR struct mac802154_callback_s *)mac; FAR struct mac802154_driver_s *priv; - DEBUGASSERT(mac != NULL && mac->cb_context); - priv = (FAR struct mac802154_driver_s *)mac->cb_context; + DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); + priv = cb->mc_priv; } /**************************************************************************** @@ -577,10 +607,11 @@ static void mac802154_ind_commstatus(FAR struct ieee802154_mac_s *mac, static void mac802154_ind_syncloss(FAR struct ieee802154_mac_s *mac, int reason) { + FAR struct mac802154_callback_s *cb = (FAR struct mac802154_callback_s *)mac; FAR struct mac802154_driver_s *priv; - DEBUGASSERT(mac != NULL && mac->cb_context); - priv = (FAR struct mac802154_driver_s *)mac->cb_context; + DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); + priv = cb->mc_priv; } /**************************************************************************** @@ -611,15 +642,15 @@ static int mac802154_transmit(FAR struct mac802154_driver_s *priv) /* Increment statistics */ - NETDEV_TXPACKETS(priv->m8_dev); + NETDEV_TXPACKETS(priv->md_dev); - /* Send the packet: address=priv->m8_dev.d_buf, length=priv->m8_dev.d_len */ + /* Send the packet: address=priv->md_dev.d_buf, length=priv->md_dev.d_len */ /* Enable Tx interrupts */ /* Setup the TX timeout watchdog (perhaps restarting the timer) */ - (void)wd_start(priv->m8_txtimeout, skeleton_TXTIMEOUT, + (void)wd_start(priv->md_txtimeout, skeleton_TXTIMEOUT, mac802154_txtimeout_expiry, 1, (wdparm_t)priv); return OK; } @@ -656,7 +687,7 @@ static int mac802154_txpoll(FAR struct net_driver_s *dev) * i_framelist will set to a new, outgoing list of frames. */ - if (priv->m8_dev.i_framelist != NULL) + if (priv->md_dev.i_framelist != NULL) { /* And send the packet */ @@ -711,14 +742,14 @@ static void mac802154_receive(FAR struct mac802154_driver_s *priv) /* Transfer the frame to the network logic */ - priv->m8_dev.framelist = iob; - sixlowpan_input(&priv->m8_dev); + priv->md_dev.framelist = iob; + sixlowpan_input(&priv->md_dev); /* If the above function invocation resulted in data that should be sent * out, the field i_framelist will set to a new, outgoing list of frames. */ - if (priv->m8_dev.i_framelist != NULL) + if (priv->md_dev.i_framelist != NULL) { /* And send the packet */ @@ -749,7 +780,7 @@ static void mac802154_txdone(FAR struct mac802154_driver_s *priv) /* Check for errors and update statistics */ - NETDEV_TXDONE(priv->m8_dev); + NETDEV_TXDONE(priv->md_dev); /* Check if there are pending transmissions */ @@ -757,13 +788,13 @@ static void mac802154_txdone(FAR struct mac802154_driver_s *priv) * disable further Tx interrupts. */ - wd_cancel(priv->m8_txtimeout); + wd_cancel(priv->md_txtimeout); /* And disable further TX interrupts. */ /* In any event, poll the network for new TX data */ - (void)devif_poll(&priv->m8_dev, mac802154_txpoll); + (void)devif_poll(&priv->md_dev, mac802154_txpoll); } /**************************************************************************** @@ -854,12 +885,12 @@ static int mac802154_transfer(int irq, FAR void *context, FAR void *arg) * expiration and the deferred interrupt processing. */ - wd_cancel(priv->m8_txtimeout); + wd_cancel(priv->md_txtimeout); } /* Schedule to perform the interrupt processing on the worker thread. */ - work_queue(ETHWORK, &priv->m8_irqwork, mac802154_transfer_work, priv, 0); + work_queue(ETHWORK, &priv->md_irqwork, mac802154_transfer_work, priv, 0); return OK; } @@ -894,13 +925,13 @@ static void mac802154_txtimeout_work(FAR void *arg) /* Increment statistics and dump debug info */ - NETDEV_TXTIMEOUTS(priv->m8_dev); + NETDEV_TXTIMEOUTS(priv->md_dev); /* Then reset the hardware */ /* Then poll the network for new XMIT data */ - (void)devif_poll(&priv->m8_dev, mac802154_txpoll); + (void)devif_poll(&priv->md_dev, mac802154_txpoll); net_unlock(); } @@ -936,7 +967,7 @@ static void mac802154_txtimeout_expiry(int argc, wdparm_t arg, ...) /* Schedule to perform the TX timeout processing on the worker thread. */ - work_queue(ETHWORK, &priv->m8_irqwork, mac802154_txtimeout_work, priv, 0); + work_queue(ETHWORK, &priv->md_irqwork, mac802154_txtimeout_work, priv, 0); } /**************************************************************************** @@ -1000,11 +1031,11 @@ static void mac802154_poll_work(FAR void *arg) * progress, we will missing TCP time state updates? */ - (void)devif_timer(&priv->m8_dev, mac802154_txpoll); + (void)devif_timer(&priv->md_dev, mac802154_txpoll); /* Setup the watchdog poll timer again */ - (void)wd_start(priv->m8_txpoll, skeleton_WDDELAY, mac802154_poll_expiry, 1, + (void)wd_start(priv->md_txpoll, skeleton_WDDELAY, mac802154_poll_expiry, 1, (wdparm_t)priv); net_unlock(); } @@ -1033,7 +1064,7 @@ static void mac802154_poll_expiry(int argc, wdparm_t arg, ...) /* Schedule to perform the interrupt processing on the worker thread. */ - work_queue(ETHWORK, &priv->m8_pollwork, mac802154_poll_work, priv, 0); + work_queue(ETHWORK, &priv->md_pollwork, mac802154_poll_work, priv, 0); } /**************************************************************************** @@ -1071,7 +1102,7 @@ static int mac802154_ifup(FAR struct net_driver_s *dev) /* Initialize PHYs, the Ethernet interface, and setup up Ethernet interrupts */ - /* Instantiate the MAC address from priv->m8_dev.d_mac.ether_addr_octet */ + /* Instantiate the MAC address from priv->md_dev.d_mac.ether_addr_octet */ #ifdef CONFIG_NET_ICMPv6 /* Set up IPv6 multicast address filtering */ @@ -1081,12 +1112,12 @@ static int mac802154_ifup(FAR struct net_driver_s *dev) /* Set and activate a timer process */ - (void)wd_start(priv->m8_txpoll, skeleton_WDDELAY, mac802154_poll_expiry, 1, + (void)wd_start(priv->md_txpoll, skeleton_WDDELAY, mac802154_poll_expiry, 1, (wdparm_t)priv); /* Enable the Ethernet interrupt */ - priv->m8_bifup = true; + priv->md_bifup = true; up_enable_irq(CONFIG_IEEE802154_NETDEV_IRQ); return OK; } @@ -1119,8 +1150,8 @@ static int mac802154_ifdown(FAR struct net_driver_s *dev) /* Cancel the TX poll timer and TX timeout timers */ - wd_cancel(priv->m8_txpoll); - wd_cancel(priv->m8_txtimeout); + wd_cancel(priv->md_txpoll); + wd_cancel(priv->md_txtimeout); /* Put the EMAC in its reset, non-operational state. This should be * a known configuration that will guarantee the mac802154_ifup() always @@ -1129,7 +1160,7 @@ static int mac802154_ifdown(FAR struct net_driver_s *dev) /* Mark the device "down" */ - priv->m8_bifup = false; + priv->md_bifup = false; leave_critical_section(flags); return OK; } @@ -1165,13 +1196,13 @@ static void mac802154_txavail_work(FAR void *arg) /* Ignore the notification if the interface is not yet up */ - if (priv->m8_bifup) + if (priv->md_bifup) { /* Check if there is room in the hardware to hold another outgoing packet. */ /* If so, then poll the network for new XMIT data */ - (void)devif_poll(&priv->m8_dev, mac802154_txpoll); + (void)devif_poll(&priv->md_dev, mac802154_txpoll); } net_unlock(); @@ -1205,11 +1236,11 @@ static int mac802154_txavail(FAR struct net_driver_s *dev) * availability action. */ - if (work_available(&priv->m8_pollwork)) + if (work_available(&priv->md_pollwork)) { /* Schedule to serialize the poll on the worker thread. */ - work_queue(ETHWORK, &priv->m8_pollwork, mac802154_txavail_work, priv, 0); + work_queue(ETHWORK, &priv->md_pollwork, mac802154_txavail_work, priv, 0); } return OK; @@ -1381,7 +1412,7 @@ static int mac802154_ioctl(FAR struct net_driver_s *dev, int cmd, long arg) if (netmac != NULL) { unsigned long macarg = (unsigned int)((uintptr_t)&netmac->u); - ret = priv->m8_mac.macops.ioctl(priv->m8_mac, cmd, macarg); + ret = priv->md_mac.macops.ioctl(priv->md_mac, cmd, macarg); } } @@ -1395,7 +1426,7 @@ static int mac802154_ioctl(FAR struct net_driver_s *dev, int cmd, long arg) if (netradio != NULL) { unsigned long radioarg = (unsigned int)((uintptr_t)&netradio->u); - ret = priv->m8_mac.macops.ioctl(priv->m8_mac, cmd, radioarg); + ret = priv->md_mac.macops.ioctl(priv->md_mac, cmd, radioarg); } } @@ -1405,7 +1436,7 @@ static int mac802154_ioctl(FAR struct net_driver_s *dev, int cmd, long arg) else { - ret = priv->m8_mac.macops.ioctl(priv->m8_mac, cmd, arg); + ret = priv->md_mac.macops.ioctl(priv->md_mac, cmd, arg); } } #endif @@ -1433,9 +1464,9 @@ static int mac802154_ioctl(FAR struct net_driver_s *dev, int cmd, long arg) int mac802154netdev_register(FAR struct ieee802154_mac_s *mac); { FAR struct mac802154_driver_s *priv; - FAR truct ieee802154_maccb_s *macb; FAR struct net_driver_s *dev; FAR uint8_t *pktbuf; + int ret; DEBUGASSERT(radio != NULL); @@ -1464,7 +1495,7 @@ int mac802154netdev_register(FAR struct ieee802154_mac_s *mac); /* Initialize the driver structure */ - dev = &ieee->m8_dev.i_dev; + dev = &ieee->md_dev.i_dev; dev->d_buf = pktbuf; /* Single packet buffer */ dev->d_ifup = mac802154_ifup; /* I/F up (new IP address) callback */ dev->d_ifdown = mac802154_ifdown; /* I/F down callback */ @@ -1480,16 +1511,17 @@ int mac802154netdev_register(FAR struct ieee802154_mac_s *mac); /* Create a watchdog for timing polling for and timing of transmisstions */ - priv->m8_mac = mac; /* Save the MAC interface instance */ - priv->m8_txpoll = wd_create(); /* Create periodic poll timer */ - priv->m8_txtimeout = wd_create(); /* Create TX timeout timer */ + priv->md_mac = mac; /* Save the MAC interface instance */ + priv->md_txpoll = wd_create(); /* Create periodic poll timer */ + priv->md_txtimeout = wd_create(); /* Create TX timeout timer */ - DEBUGASSERT(priv->m8_txpoll != NULL && priv->m8_txtimeout != NULL); + DEBUGASSERT(priv->md_txpoll != NULL && priv->md_txtimeout != NULL); /* Initialize the MAC callbacks */ - maccb = &mac->cbs; - maccb->cb_context = priv; + priv->md_cb.mc_priv = priv; + + maccb = &priv->md_cb.mc_cb; maccb->conf_data = mac802154_conf_data; maccb->conf_purge = mac802154_conf_purge; maccb->conf_associate = mac802154_conf_associate; @@ -1511,13 +1543,31 @@ int mac802154netdev_register(FAR struct ieee802154_mac_s *mac); maccb->ind_commstatus = mac802154_ind_commstatus; maccb->ind_syncloss = mac802154_ind_syncloss; + /* Bind the callback structure */ + + ret = mac->ops->bind(mac, *priv->md_cb.mc_cb); + if (ret < 0) + { + nerr("ERROR: Failed to bind the MAC callbacks: %d\n", ret); + + /* Release wdog timers */ + + wd_delete(priv->md_txpoll); + wd_delete(priv->md_txtimeout); + + /* Free memory and return the error */ + kmm_free(pktbuf); + kmm_free(priv); + return ret + } + /* Put the interface in the down state. */ mac802154_ifdown(dev); /* Register the device with the OS so that socket IOCTLs can be performed */ - (void)netdev_register(&priv->m8_dev, NET_LL_IEEE802154); + (void)netdev_register(&priv->md_dev, NET_LL_IEEE802154); return OK; } From badd36170d97d617ba4580386b4e19e683ed7ab9 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 14 Apr 2017 10:38:46 -0600 Subject: [PATCH 062/183] IEEE802.15.4: There is only one instance of the IEEE802.15.4 MAC lower level. There is no need for the interface to be indirect via a vtable. In this case, standard global functions should be used. --- configs/clicker2-stm32/src/stm32_mrf24j40.c | 2 +- .../wireless/ieee802154/ieee802154_mac.h | 416 +++++++---- wireless/ieee802154/mac802154.c | 664 ++++++++---------- wireless/ieee802154/mac802154_device.c | 13 +- wireless/ieee802154/mac802154_netdev.c | 544 +++++++------- 5 files changed, 826 insertions(+), 813 deletions(-) diff --git a/configs/clicker2-stm32/src/stm32_mrf24j40.c b/configs/clicker2-stm32/src/stm32_mrf24j40.c index 8f6868f59ea..e1b664f28b1 100644 --- a/configs/clicker2-stm32/src/stm32_mrf24j40.c +++ b/configs/clicker2-stm32/src/stm32_mrf24j40.c @@ -228,7 +228,7 @@ 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; + MACHANDLE mac; #endif FAR struct spi_dev_s *spi; int ret; diff --git a/include/nuttx/wireless/ieee802154/ieee802154_mac.h b/include/nuttx/wireless/ieee802154/ieee802154_mac.h index 5dbed05ea77..acfc541c589 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_mac.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_mac.h @@ -881,96 +881,12 @@ struct ieee802154_netmac_s }; #endif -/* MAC Interface Operations *************************************************/ +/* This is an opaque reference to the MAC's internal private state. It is + * returned by mac802154_create() when it is created. It may then be used + * at other interfaces in order to interact with the MAC. + */ -struct ieee802154_mac_s; /* Forward reference */ -struct ieee802154_maccb_s; /* Forward reference */ - -struct ieee802154_macops_s -{ - /* Requests, confirmed asynchronously via callbacks */ - - /* Transmit a data frame */ - - CODE int (*req_data)(FAR struct ieee802154_mac_s *mac, - FAR struct ieee802154_data_req_s *req); - - /* Cancel transmission of a data frame */ - - CODE int (*req_purge)(FAR struct ieee802154_mac_s *mac, uint8_t handle); - - /* Start association with coordinator */ - - CODE int (*req_associate)(FAR struct ieee802154_mac_s *mac, - FAR struct ieee802154_assoc_req_s *req); - - /* Start disassociation with coordinator */ - - CODE int (*req_disassociate)(FAR struct ieee802154_mac_s *mac, - FAR struct ieee802154_disassoc_req_s *req); - - /* Read the PIB */ - - CODE int (*req_get)(FAR struct ieee802154_mac_s *mac, - enum ieee802154_pib_attr_e attr); - - /* Allocate or deallocate a GTS */ - - CODE int (*req_gts)(FAR struct ieee802154_mac_s *mac, - FAR uint8_t *characteristics); - - /* MAC layer reset */ - - CODE int (*req_reset)(FAR struct ieee802154_mac_s *mac, bool setdefaults); - - /* PHY receiver control */ - - CODE int (*req_rxenable)(FAR struct ieee802154_mac_s *mac, bool deferrable, - int ontime, int duration); - - /* Start a network scan */ - - CODE int (*req_scan)(FAR struct ieee802154_mac_s *mac, uint8_t type, - uint32_t channels, int duration); - - /* Change the PIB */ - - CODE int (*req_set)(FAR struct ieee802154_mac_s *mac, int attribute, - FAR uint8_t *value, int valuelen); - - CODE int (*req_start)(FAR struct ieee802154_mac_s *mac, uint16_t panid, - int channel, uint8_t bo, uint8_t fo, bool coord, - bool batext, bool realign); - - CODE int (*req_sync)(FAR struct ieee802154_mac_s *mac, int channel, - bool track); - - CODE int (*req_poll)(FAR struct ieee802154_mac_s *mac, - FAR uint8_t *coordaddr); - - /* Synchronous Responses to Indications received via callbacks */ - - /* Reply to an association request */ - - CODE int (*rsp_associate)(FAR struct ieee802154_mac_s *mac, uint8_t eadr, - uint16_t saddr, int status); - - /* Orphan device management */ - - CODE int (*rsp_orphan)(FAR struct ieee802154_mac_s *mac, - FAR uint8_t *orphanaddr, uint16_t saddr, - bool associated); - - /* Bind callbacks to the IEEE802.15.4 MAC */ - - CODE int (*bind)(FAR struct ieee802154_mac_s *mac, - FAR const struct ieee802154_maccb_s *cb); - - /* IOCTL support */ - - CODE int (*ioctl)(FAR struct ieee802154_mac_s *mac, int cmd, - unsigned long arg); -}; +typedef FAR void *MACHANDLE; /* Notifications */ @@ -980,99 +896,83 @@ struct ieee802154_maccb_s /* Data frame was received by remote device */ - CODE void (*conf_data)(FAR struct ieee802154_mac_s *mac, + CODE void (*conf_data)(MACHANDLE mac, FAR struct ieee802154_data_conf_s *conf); /* Data frame was purged */ - CODE void (*conf_purge)(FAR struct ieee802154_mac_s *mac, uint8_t handle, - int status); + CODE void (*conf_purge)(MACHANDLE mac, uint8_t handle, int status); /* Association request completed */ - CODE void (*conf_associate)(FAR struct ieee802154_mac_s *mac, - uint16_t saddr, int status); + CODE void (*conf_associate)(MACHANDLE mac, uint16_t saddr, int status); /* Disassociation request completed */ - CODE void (*conf_disassociate)(FAR struct ieee802154_mac_s *mac, - int status); + CODE void (*conf_disassociate)(MACHANDLE mac, int status); /* PIvoata returned */ - CODE void (*conf_get)(FAR struct ieee802154_mac_s *mac, int status, - int attribute, FAR uint8_t *value, - int valuelen); + CODE void (*conf_get)(MACHANDLE mac, int status, int attribute, + FAR uint8_t *value, int valuelen); /* GTvoanagement completed */ - CODE void (*conf_gts)(FAR struct ieee802154_mac_s *mac, - FAR uint8_t *characteristics, int status); + CODE void (*conf_gts)(MACHANDLE mac, FAR uint8_t *characteristics, + int status); /* MAveset completed */ - CODE void (*conf_reset)(FAR struct ieee802154_mac_s *mac, int status); + CODE void (*conf_reset)(MACHANDLE mac, int status); - CODE void (*conf_rxenable)(FAR struct ieee802154_mac_s *mac, int status); + CODE void (*conf_rxenable)(MACHANDLE mac, int status); - CODE void (*conf_scan)(FAR struct ieee802154_mac_s *mac, int status, - uint8_t type, uint32_t unscanned, int rsltsize, + CODE void (*conf_scan)(MACHANDLE mac, int status, uint8_t type, + uint32_t unscanned, int rsltsize, FAR uint8_t *edlist, FAR uint8_t *pandescs); - CODE void (*conf_set)(FAR struct ieee802154_mac_s *mac, int status, - int attribute); + CODE void (*conf_set)(MACHANDLE mac, int status, int attribute); - CODE void (*conf_start)(FAR struct ieee802154_mac_s *mac, int status); + CODE void (*conf_start)(MACHANDLE mac, int status); - CODE void (*conf_poll)(FAR struct ieee802154_mac_s *mac, int status); + CODE void (*conf_poll)(MACHANDLE mac, int status); /* Asynchronous event indications, replied to synchronously with responses */ /* Data frame received */ - CODE void (*ind_data)(FAR struct ieee802154_mac_s *mac, FAR uint8_t *buf, - int len); + CODE void (*ind_data)(MACHANDLE mac, FAR uint8_t *buf, int len); /* Association request received */ - CODE void (*ind_associate)(FAR struct ieee802154_mac_s *mac, - uint16_t clipanid, FAR uint8_t *clieaddr); + CODE void (*ind_associate)(MACHANDLE mac, uint16_t clipanid, + FAR uint8_t *clieaddr); /* Disassociation request received */ - CODE void (*ind_disassociate)(FAR struct ieee802154_mac_s *mac, - FAR uint8_t *eadr, uint8_t reason); + CODE void (*ind_disassociate)(MACHANDLE mac, FAR uint8_t *eadr, + uint8_t reason); /* Beacon notification */ - CODE void (*ind_beaconnotify)(FAR struct ieee802154_mac_s *mac, - FAR uint8_t *bsn, FAR struct ieee802154_pan_desc_s *pandesc, + CODE void (*ind_beaconnotify)(MACHANDLE mac, FAR uint8_t *bsn, + FAR struct ieee802154_pan_desc_s *pandesc, FAR uint8_t *sdu, int sdulen); /* GTS management request received */ - CODE void (*ind_gts)(FAR struct ieee802154_mac_s *mac, - FAR uint8_t *devaddr, FAR uint8_t *characteristics); + CODE void (*ind_gts)(MACHANDLE mac, FAR uint8_t *devaddr, + FAR uint8_t *characteristics); /* Orphan device detected */ - CODE void (*ind_orphan)(FAR struct ieee802154_mac_s *mac, - FAR uint8_t *orphanaddr); + CODE void (*ind_orphan)(MACHANDLE mac, FAR uint8_t *orphanaddr); - CODE void (*ind_commstatus)(FAR struct ieee802154_mac_s *mac, - uint16_t panid, FAR uint8_t *src, - FAR uint8_t *dst, int status); + CODE void (*ind_commstatus)(MACHANDLE mac, uint16_t panid, + FAR uint8_t *src, FAR uint8_t *dst, + int status); - CODE void (*ind_syncloss)(FAR struct ieee802154_mac_s *mac, int reason); -}; - -struct ieee802154_mac_s -{ - /* Publicly visiable part of the MAC interface */ - - struct ieee802154_macops_s ops; - - /* MAC private data may follow */ + CODE void (*ind_syncloss)(MACHANDLE mac, int reason); }; #ifdef __cplusplus @@ -1109,13 +1009,11 @@ struct ieee802154_radio_s; /* Forward reference */ * radiodev - an instance of an IEEE 802.15.4 radio * * Returned Value: - * A MAC structure that has pointers to MAC operations - * and responses. + * An opaque reference to the MAC state data. * ****************************************************************************/ -FAR struct ieee802154_mac_s * - mac802154_create(FAR struct ieee802154_radio_s *radiodev); +MACHANDLE mac802154_create(FAR struct ieee802154_radio_s *radiodev); /**************************************************************************** * Name: mac802154dev_register @@ -1135,7 +1033,7 @@ FAR struct ieee802154_mac_s * * ****************************************************************************/ -int mac802154dev_register(FAR struct ieee802154_mac_s *mac, int minor); +int mac802154dev_register(MACHANDLE mac, int minor); /**************************************************************************** * Name: mac802154netdev_register @@ -1153,7 +1051,245 @@ int mac802154dev_register(FAR struct ieee802154_mac_s *mac, int minor); * ****************************************************************************/ -int mac802154netdev_register(FAR struct ieee802154_mac_s *mac); +int mac802154netdev_register(MACHANDLE mac); + +/**************************************************************************** + * Name: mac802154_bind + * + * Description: + * Bind the MAC callback table to the MAC state. + * + * Parameters: + * mac - Reference to the MAC driver state structure + * cb - MAC callback operations + * + * Returned Value: + * OK on success; Negated errno on failure. + * + ****************************************************************************/ + +int mac802154_bind(MACHANDLE mac, FAR const struct ieee802154_maccb_s *cb); + +/**************************************************************************** + * Name: mac802154_ioctl + * + * Description: + * Handle MAC and radio IOCTL commands directed to the MAC. + * + * Parameters: + * mac - Reference to the MAC driver state structure + * cmd - The IOCTL command + * arg - The argument for the IOCTL command + * + * Returned Value: + * OK on success; Negated errno on failure. + * + ****************************************************************************/ + +int mac802154_ioctl(MACHANDLE mac, int cmd, unsigned long arg); + +/**************************************************************************** + * MAC Interface Operations + ****************************************************************************/ + +/**************************************************************************** + * Name: mac802154_req_data + * + * Description: + * The MCPS-DATA.request primitive requests the transfer of a data SPDU + * (i.e., MSDU) from a local SSCS entity to a single peer SSCS entity. + * Confirmation is returned via the + * struct ieee802154_maccb_s->conf_data callback. + * + ****************************************************************************/ + +int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req); + +/**************************************************************************** + * Name: mac802154_req_purge + * + * Description: + * The MCPS-PURGE.request primitive allows the next higher layer to purge an + * MSDU from the transaction queue. Confirmation is returned via + * the struct ieee802154_maccb_s->conf_purge callback. + * + ****************************************************************************/ + +int mac802154_req_purge(MACHANDLE mac, uint8_t handle); + +/**************************************************************************** + * Name: mac802154_req_associate + * + * Description: + * The MLME-ASSOCIATE.request primitive allows a device to request an + * association with a coordinator. Confirmation is returned via the + * struct ieee802154_maccb_s->conf_associate callback. + * + ****************************************************************************/ + +int mac802154_req_associate(MACHANDLE mac + FAR struct ieee802154_assoc_req_s *req); + +/**************************************************************************** + * Name: mac802154_req_disassociate + * + * Description: + * The MLME-DISASSOCIATE.request primitive is used by an associated device to + * notify the coordinator of its intent to leave the PAN. It is also used by + * the coordinator to instruct an associated device to leave the PAN. + * Confirmation is returned via the + * struct ieee802154_maccb_s->conf_disassociate callback. + * + ****************************************************************************/ + +int mac802154_req_disassociate(MACHANDLE mac, + FAR struct ieee802154_disassoc_req_s *req); + +/**************************************************************************** + * Name: mac802154_req_get + * + * Description: + * The MLME-GET.request primitive requests information about a given PIB + * attribute. Actual data is returned via the + * struct ieee802154_maccb_s->conf_get callback. + * + ****************************************************************************/ + +int mac802154_req_get(MACHANDLE mac, enum ieee802154_pib_attr_e attr); + +/**************************************************************************** + * Name: mac802154_req_gts + * + * Description: + * The MLME-GTS.request primitive allows a device to send a request to the PAN + * coordinator to allocate a new GTS or to deallocate an existing GTS. + * Confirmation is returned via the + * struct ieee802154_maccb_s->conf_gts callback. + * + ****************************************************************************/ + +int mac802154_req_gts(MACHANDLE mac, FAR uint8_t *characteristics); + +/**************************************************************************** + * Name: mac802154_req_reset + * + * Description: + * The MLME-RESET.request primitive allows the next higher layer to request + * that the MLME performs a reset operation. Confirmation is returned via + * the struct ieee802154_maccb_s->conf_reset callback. + * + ****************************************************************************/ + +int mac802154_req_reset(MACHANDLE mac, bool setdefaults); + +/**************************************************************************** + * Name: mac802154_req_rxenable + * + * Description: + * The MLME-RX-ENABLE.request primitive allows the next higher layer to + * request that the receiver is enable for a finite period of time. + * Confirmation is returned via the + * struct ieee802154_maccb_s->conf_rxenable callback. + * + ****************************************************************************/ + +int mac802154_req_rxenable(MACHANDLE mac, bool deferrable, int ontime, + int duration); + +/**************************************************************************** + * Name: mac802154_req_scan + * + * Description: + * The MLME-SCAN.request primitive is used to initiate a channel scan over a + * given list of channels. A device can use a channel scan to measure the + * energy on the channel, search for the coordinator with which it associated, + * or search for all coordinators transmitting beacon frames within the POS of + * the scanning device. Scan results are returned + * via MULTIPLE calls to the struct ieee802154_maccb_s->conf_scan callback. + * This is a difference with the official 802.15.4 specification, implemented + * here to save memory. + * + ****************************************************************************/ + +int mac802154_req_scan(MACHANDLE mac, uint8_t type, uint32_t channels, + int duration); + +/**************************************************************************** + * Name: mac802154_req_set + * + * Description: + * The MLME-SET.request primitive attempts to write the given value to the + * indicated MAC PIB attribute. Confirmation is returned via the + * struct ieee802154_maccb_s->conf_set callback. + * + ****************************************************************************/ + +int mac802154_req_set(MACHANDLE mac, int attribute, FAR uint8_t *value, + int valuelen); + +/**************************************************************************** + * Name: mac802154_req_start + * + * Description: + * The MLME-START.request primitive makes a request for the device to start + * using a new superframe configuration. Confirmation is returned + * via the struct ieee802154_maccb_s->conf_start callback. + * + ****************************************************************************/ + +int mac802154_req_start(MACHANDLE mac, uint16_t panid, int channel, + uint8_t bo, uint8_t fo, bool coord, bool batext, + bool realign); + +/**************************************************************************** + * Name: mac802154_req_sync + * + * Description: + * The MLME-SYNC.request primitive requests to synchronize with the + * coordinator by acquiring and, if specified, tracking its beacons. + * Confirmation is returned via the + * struct ieee802154_maccb_s->int_commstatus callback. TOCHECK. + * + ****************************************************************************/ + +int mac802154_req_sync(MACHANDLE mac, int channel, bool track); + +/**************************************************************************** + * Name: mac802154_req_poll + * + * Description: + * The MLME-POLL.request primitive prompts the device to request data from the + * coordinator. Confirmation is returned via the + * struct ieee802154_maccb_s->conf_poll callback, followed by a + * struct ieee802154_maccb_s->ind_data callback. + * + ****************************************************************************/ + +int mac802154_req_poll(MACHANDLE mac, FAR uint8_t *coordaddr); + +/**************************************************************************** + * Name: mac802154_rsp_associate + * + * Description: + * The MLME-ASSOCIATE.response primitive is used to initiate a response to an + * MLME-ASSOCIATE.indication primitive. + * + ****************************************************************************/ + +int mac802154_rsp_associate(MACHANDLE mac, uint8_t eadr, uint16_t saddr, + int status); + +/**************************************************************************** + * Name: mac802154_rsp_orphan + * + * Description: + * The MLME-ORPHAN.response primitive allows the next higher layer of a + * coordinator to respond to the MLME-ORPHAN.indication primitive. + * + ****************************************************************************/ + +int mac802154_rsp_orphan(MACHANDLE mac, FAR uint8_t *orphanaddr, + uint16_t saddr, bool associated); #undef EXTERN #ifdef __cplusplus diff --git a/wireless/ieee802154/mac802154.c b/wireless/ieee802154/mac802154.c index a1bf2655341..693e2db7711 100644 --- a/wireless/ieee802154/mac802154.c +++ b/wireless/ieee802154/mac802154.c @@ -55,13 +55,13 @@ * Private Types ****************************************************************************/ -/* The privmac structure is an extension of the public ieee802154_mac_s type. - * It contains storage for the IEEE802.15.4 MIB attributes. +/* The privmac structure holds the internal state of the MAC and is the + * underlying represention of the opaque MACHANDLE. It contains storage for + * the IEEE802.15.4 MIB attributes. */ struct ieee802154_privmac_s { - struct ieee802154_mac_s pubmac; /* This MUST be the first member */ FAR struct ieee802154_radio_s *radio; /* Contained IEEE802.15.4 radio dev */ FAR const struct ieee802154_maccb_s *cb; /* Contained MAC callbacks */ @@ -104,75 +104,6 @@ struct ieee802154_privmac_s #endif }; -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/* MAC Data Service (MCPS) functions */ - -static int mac802154_req_data(FAR struct ieee802154_mac_s *mac, - FAR struct ieee802154_data_req_s *req); -static int mac802154_req_purge(FAR struct ieee802154_mac_s *mac, - uint8_t handle); - -/* MAC Sublayer Management Entity (MLME) functions */ - -static int mac802154_req_associate(FAR struct ieee802154_mac_s *mac, - FAR struct ieee802154_assoc_req_s *req); -static int mac802154_req_disassociate(FAR struct ieee802154_mac_s *mac, - FAR struct ieee802154_disassoc_req_s *req); -static int mac802154_req_get(FAR struct ieee802154_mac_s *mac, - enum ieee802154_pib_attr_e attr); -static int mac802154_req_gts(FAR struct ieee802154_mac_s *mac, - FAR uint8_t *characteristics); -static int mac802154_req_reset(FAR struct ieee802154_mac_s *mac, - bool setdefaults); -static int mac802154_req_rxenable(FAR struct ieee802154_mac_s *mac, - bool deferrable, int ontime, int duration); -static int mac802154_req_scan(FAR struct ieee802154_mac_s *mac, - uint8_t type, uint32_t channels, int duration); -static int mac802154_req_set(FAR struct ieee802154_mac_s *mac, - int attribute, FAR uint8_t *value, int valuelen); -static int mac802154_req_start(FAR struct ieee802154_mac_s *mac, - uint16_t panid, int channel, uint8_t bo, uint8_t fo, - bool coord, bool batext, bool realign); -static int mac802154_req_sync(FAR struct ieee802154_mac_s *mac, - int channel, bool track); -static int mac802154_req_poll(FAR struct ieee802154_mac_s *mac, - FAR uint8_t *coordaddr); -static int mac802154_rsp_associate(FAR struct ieee802154_mac_s *mac, - uint8_t eadr, uint16_t saddr, int status); -static int mac802154_rsp_orphan(FAR struct ieee802154_mac_s *mac, - FAR uint8_t *orphanaddr, uint16_t saddr, bool associated); - -static int mac802154_bind(FAR struct ieee802154_mac_s *mac, - FAR struct ieee802154_maccb_s *cb); -static int mac802154_ioctl(FAR struct ieee802154_mac_s *mac, int cmd, - unsigned long arg); - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static const struct ieee802154_macops_s mac802154ops = -{ - .req_data = mac802154_req_data, - .req_purge = mac802154_req_purge, - .req_associate = mac802154_req_associate, - .req_disassociate = mac802154_req_disassociate, - .req_get = mac802154_req_get, - .req_gts = mac802154_req_gts, - .req_reset = mac802154_req_reset, - .req_rxenable = mac802154_req_rxenable, - .req_scan = mac802154_req_scan, - .req_set = mac802154_req_set, - .req_start = mac802154_req_start, - .req_sync = mac802154_req_sync, - .req_poll = mac802154_req_poll, - .rsp_associate = mac802154_rsp_associate, - .rsp_orphan = mac802154_rsp_orphan, -}; - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -241,276 +172,55 @@ static int mac802154_applymib(FAR struct ieee802154_privmac_s *priv) } /**************************************************************************** - * API Functions + * Public Functions ****************************************************************************/ /**************************************************************************** - * Name: mac802154_reqdata + * Name: mac802154_create * * Description: - * The MCPS-DATA.request primitive requests the transfer of a data SPDU - * (i.e., MSDU) from a local SSCS entity to a single peer SSCS entity. - * Confirmation is returned via the - * struct ieee802154_maccb_s->conf_data callback. + * Create a 802.15.4 MAC device from a 802.15.4 compatible radio device. + * + * The returned MAC structure should be passed to either the next highest + * layer in the network stack, or registered with a mac802154dev character + * or network drivers. In any of these scenarios, the next highest layer + * should register a set of callbacks with the MAC layer by setting the + * mac->cbs member. + * + * NOTE: 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. + * + * Input Parameters: + * radiodev - an instance of an IEEE 802.15.4 radio + * + * Returned Value: + * An opaque reference to the MAC state data. * ****************************************************************************/ -static int mac802154_req_data(FAR struct ieee802154_mac_s *mac, - FAR struct ieee802154_data_req_s *req) +MACHANDLE mac802154_create(FAR struct ieee802154_radio_s *radiodev) { - FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; - return -ENOTTY; -} + FAR struct ieee802154_privmac_s *mac; -/**************************************************************************** - * Name: mac802154_reqpurge - * - * Description: - * The MCPS-PURGE.request primitive allows the next higher layer to purge an - * MSDU from the transaction queue. Confirmation is returned via - * the struct ieee802154_maccb_s->conf_purge callback. - * - ****************************************************************************/ + /* Allocate object */ -static int mac802154_req_purge(FAR struct ieee802154_mac_s *mac, - uint8_t handle) -{ - FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; - return -ENOTTY; -} + mac = (FAR struct ieee802154_privmac_s *) + kmm_zalloc(sizeof(struct ieee802154_privmac_s)); -/**************************************************************************** - * Name: mac802154_req_associate - * - * Description: - * The MLME-ASSOCIATE.request primitive allows a device to request an - * association with a coordinator. Confirmation is returned via the - * struct ieee802154_maccb_s->conf_associate callback. - * - ****************************************************************************/ + if (mac == NULL) + { + return NULL; + } -static int mac802154_req_associate(FAR struct ieee802154_mac_s *mac, - FAR struct ieee802154_assoc_req_s *req) -{ - FAR struct ieee802154_privmac_s * priv = (FAR struct ieee802154_privmac_s *)mac; - return -ENOTTY; -} + /* Initialize fields */ -/**************************************************************************** - * Name: mac802154_req_disassociate - * - * Description: - * The MLME-DISASSOCIATE.request primitive is used by an associated device to - * notify the coordinator of its intent to leave the PAN. It is also used by - * the coordinator to instruct an associated device to leave the PAN. - * Confirmation is returned via the - * struct ieee802154_maccb_s->conf_disassociate callback. - * - ****************************************************************************/ + mac->radio = radiodev; -static int mac802154_req_disassociate(FAR struct ieee802154_mac_s *mac, - FAR struct ieee802154_disassoc_req_s *req) -{ - FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; - return -ENOTTY; -} + mac802154_defaultmib(mac); + mac802154_applymib(mac); -/**************************************************************************** - * Name: mac802154_req_get - * - * Description: - * The MLME-GET.request primitive requests information about a given PIB - * attribute. Actual data is returned via the - * struct ieee802154_maccb_s->conf_get callback. - * - ****************************************************************************/ - -static int mac802154_req_get(FAR struct ieee802154_mac_s *mac, - enum ieee802154_pib_attr_e attr) -{ - FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; - return -ENOTTY; -} - -/**************************************************************************** - * Name: mac802154_req_gts - * - * Description: - * The MLME-GTS.request primitive allows a device to send a request to the PAN - * coordinator to allocate a new GTS or to deallocate an existing GTS. - * Confirmation is returned via the - * struct ieee802154_maccb_s->conf_gts callback. - * - ****************************************************************************/ - -static int mac802154_req_gts(FAR struct ieee802154_mac_s *mac, - FAR uint8_t *characteristics) -{ - FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; - return -ENOTTY; -} - -/**************************************************************************** - * Name: mac802154_req_reset - * - * Description: - * The MLME-RESET.request primitive allows the next higher layer to request - * that the MLME performs a reset operation. Confirmation is returned via - * the struct ieee802154_maccb_s->conf_reset callback. - * - ****************************************************************************/ - -static int mac802154_req_reset(FAR struct ieee802154_mac_s *mac, - bool setdefaults) -{ - FAR struct ieee802154_privmac_s * priv = (FAR struct ieee802154_privmac_s *) mac; - return -ENOTTY; -} - -/**************************************************************************** - * Name: mac802154_req_rxenable - * - * Description: - * The MLME-RX-ENABLE.request primitive allows the next higher layer to - * request that the receiver is enable for a finite period of time. - * Confirmation is returned via the - * struct ieee802154_maccb_s->conf_rxenable callback. - * - ****************************************************************************/ - -static int mac802154_req_rxenable(FAR struct ieee802154_mac_s *mac, - bool deferrable, int ontime, int duration) -{ - FAR struct ieee802154_privmac_s * priv = (FAR struct ieee802154_privmac_s *)mac; - return -ENOTTY; -} - -/**************************************************************************** - * Name: mac802154_req_scan - * - * Description: - * The MLME-SCAN.request primitive is used to initiate a channel scan over a - * given list of channels. A device can use a channel scan to measure the - * energy on the channel, search for the coordinator with which it associated, - * or search for all coordinators transmitting beacon frames within the POS of - * the scanning device. Scan results are returned - * via MULTIPLE calls to the struct ieee802154_maccb_s->conf_scan callback. - * This is a difference with the official 802.15.4 specification, implemented - * here to save memory. - * - ****************************************************************************/ - -static int mac802154_req_scan(FAR struct ieee802154_mac_s *mac, - uint8_t type, uint32_t channels, int duration) -{ - FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; - return -ENOTTY; -} - -/**************************************************************************** - * Name: mac802154_req_set - * - * Description: - * The MLME-SET.request primitive attempts to write the given value to the - * indicated MAC PIB attribute. Confirmation is returned via the - * struct ieee802154_maccb_s->conf_set callback. - * - ****************************************************************************/ - -static int mac802154_req_set(FAR struct ieee802154_mac_s *mac, - int attribute, FAR uint8_t *value, int valuelen) -{ - FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; - return -ENOTTY; -} - -/**************************************************************************** - * Name: mac802154_req_start - * - * Description: - * The MLME-START.request primitive makes a request for the device to start - * using a new superframe configuration. Confirmation is returned - * via the struct ieee802154_maccb_s->conf_start callback. - * - ****************************************************************************/ - -static int mac802154_req_start(FAR struct ieee802154_mac_s *mac, - uint16_t panid, int channel, uint8_t bo, - uint8_t fo, bool coord, bool batext, - bool realign) -{ - FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; - return -ENOTTY; -} - -/**************************************************************************** - * Name: mac802154_req_sync - * - * Description: - * The MLME-SYNC.request primitive requests to synchronize with the - * coordinator by acquiring and, if specified, tracking its beacons. - * Confirmation is returned via the - * struct ieee802154_maccb_s->int_commstatus callback. TOCHECK. - * - ****************************************************************************/ - -static int mac802154_req_sync(FAR struct ieee802154_mac_s *mac, - int channel, bool track) -{ - FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; - return -ENOTTY; -} - -/**************************************************************************** - * Name: mac802154_req_poll - * - * Description: - * The MLME-POLL.request primitive prompts the device to request data from the - * coordinator. Confirmation is returned via the - * struct ieee802154_maccb_s->conf_poll callback, followed by a - * struct ieee802154_maccb_s->ind_data callback. - * - ****************************************************************************/ - -static int mac802154_req_poll(FAR struct ieee802154_mac_s *mac, - FAR uint8_t *coordaddr) -{ - FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; - return -ENOTTY; -} - -/**************************************************************************** - * Name: mac802154_rsp_associate - * - * Description: - * The MLME-ASSOCIATE.response primitive is used to initiate a response to an - * MLME-ASSOCIATE.indication primitive. - * - ****************************************************************************/ - -static int mac802154_rsp_associate(FAR struct ieee802154_mac_s *mac, - uint8_t eadr, uint16_t saddr, int status) -{ - FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; - return -ENOTTY; -} - -/**************************************************************************** - * Name: mac802154_rsp_orphan - * - * Description: - * The MLME-ORPHAN.response primitive allows the next higher layer of a - * coordinator to respond to the MLME-ORPHAN.indication primitive. - * - ****************************************************************************/ - -static int mac802154_rsp_orphan(FAR struct ieee802154_mac_s *mac, - FAR uint8_t *orphanaddr, uint16_t saddr, - bool associated) -{ - FAR struct ieee802154_privmac_s *priv = - (FAR struct ieee802154_privmac_s *)mac; - return -ENOTTY; + return (MACHANDLE)mac; } /**************************************************************************** @@ -528,8 +238,7 @@ static int mac802154_rsp_orphan(FAR struct ieee802154_mac_s *mac, * ****************************************************************************/ -static int mac802154_bind(FAR struct ieee802154_mac_s *mac, - FAR const struct ieee802154_maccb_s *cb) +int mac802154_bind(MACHANDLE mac, FAR const struct ieee802154_maccb_s *cb) { FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; @@ -554,8 +263,7 @@ static int mac802154_bind(FAR struct ieee802154_mac_s *mac, * ****************************************************************************/ -static int mac802154_ioctl(FAR struct ieee802154_mac_s *mac, int cmd, - unsigned long arg) +int mac802154_ioctl(MACHANDLE mac, int cmd, unsigned long arg) { FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; @@ -576,59 +284,267 @@ static int mac802154_ioctl(FAR struct ieee802154_mac_s *mac, int cmd, ret = priv->radio->ioctl(priv->radio, cmd, arg); } } -#endif /**************************************************************************** - * Public Functions + * MAC Interface Operations ****************************************************************************/ /**************************************************************************** - * Name: mac802154_create + * Name: mac802154_req_data * * Description: - * Create a 802.15.4 MAC device from a 802.15.4 compatible radio device. - * - * The returned MAC structure should be passed to either the next highest - * layer in the network stack, or registered with a mac802154dev character - * or network drivers. In any of these scenarios, the next highest layer - * should register a set of callbacks with the MAC layer by setting the - * mac->cbs member. - * - * NOTE: 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. - * - * Input Parameters: - * radiodev - an instance of an IEEE 802.15.4 radio - * - * Returned Value: - * A MAC structure that has pointers to MAC operations - * and responses. + * The MCPS-DATA.request primitive requests the transfer of a data SPDU + * (i.e., MSDU) from a local SSCS entity to a single peer SSCS entity. + * Confirmation is returned via the + * struct ieee802154_maccb_s->conf_data callback. * ****************************************************************************/ -FAR struct ieee802154_mac_s * - mac802154_create(FAR struct ieee802154_radio_s *radiodev) +int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) { - FAR struct ieee802154_privmac_s *mac; - - /* Allocate object */ - - mac = (FAR struct ieee802154_privmac_s *) - kmm_zalloc(sizeof(struct ieee802154_privmac_s)); - - if (mac == NULL) - { - return NULL; - } - - /* Initialize fields */ - - mac->radio = radiodev; - mac->pubmac.ops = mac802154ops; - - mac802154_defaultmib(mac); - mac802154_applymib(mac); - - return &mac->pubmac; + FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; + return -ENOTTY; +} + +/**************************************************************************** + * Name: mac802154_req_purge + * + * Description: + * The MCPS-PURGE.request primitive allows the next higher layer to purge an + * MSDU from the transaction queue. Confirmation is returned via + * the struct ieee802154_maccb_s->conf_purge callback. + * + ****************************************************************************/ + +int mac802154_req_purge(MACHANDLE mac, uint8_t handle) +{ + FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; + return -ENOTTY; +} + +/**************************************************************************** + * Name: mac802154_req_associate + * + * Description: + * The MLME-ASSOCIATE.request primitive allows a device to request an + * association with a coordinator. Confirmation is returned via the + * struct ieee802154_maccb_s->conf_associate callback. + * + ****************************************************************************/ + +int mac802154_req_associate(MACHANDLE mac + FAR struct ieee802154_assoc_req_s *req) +{ + FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; + return -ENOTTY; +} + +/**************************************************************************** + * Name: mac802154_req_disassociate + * + * Description: + * The MLME-DISASSOCIATE.request primitive is used by an associated device to + * notify the coordinator of its intent to leave the PAN. It is also used by + * the coordinator to instruct an associated device to leave the PAN. + * Confirmation is returned via the + * struct ieee802154_maccb_s->conf_disassociate callback. + * + ****************************************************************************/ + +int mac802154_req_disassociate(MACHANDLE mac, + FAR struct ieee802154_disassoc_req_s *req) +{ + FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; + return -ENOTTY; +} + +/**************************************************************************** + * Name: mac802154_req_get + * + * Description: + * The MLME-GET.request primitive requests information about a given PIB + * attribute. Actual data is returned via the + * struct ieee802154_maccb_s->conf_get callback. + * + ****************************************************************************/ + +int mac802154_req_get(MACHANDLE mac, enum ieee802154_pib_attr_e attr) +{ + FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; + return -ENOTTY; +} + +/**************************************************************************** + * Name: mac802154_req_gts + * + * Description: + * The MLME-GTS.request primitive allows a device to send a request to the PAN + * coordinator to allocate a new GTS or to deallocate an existing GTS. + * Confirmation is returned via the + * struct ieee802154_maccb_s->conf_gts callback. + * + ****************************************************************************/ + +int mac802154_req_gts(MACHANDLE mac, FAR uint8_t *characteristics) +{ + FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; + return -ENOTTY; +} + +/**************************************************************************** + * Name: mac802154_req_reset + * + * Description: + * The MLME-RESET.request primitive allows the next higher layer to request + * that the MLME performs a reset operation. Confirmation is returned via + * the struct ieee802154_maccb_s->conf_reset callback. + * + ****************************************************************************/ + +int mac802154_req_reset(MACHANDLE mac, bool setdefaults) +{ + FAR struct ieee802154_privmac_s * priv = (FAR struct ieee802154_privmac_s *) mac; + return -ENOTTY; +} + +/**************************************************************************** + * Name: mac802154_req_rxenable + * + * Description: + * The MLME-RX-ENABLE.request primitive allows the next higher layer to + * request that the receiver is enable for a finite period of time. + * Confirmation is returned via the + * struct ieee802154_maccb_s->conf_rxenable callback. + * + ****************************************************************************/ + +int mac802154_req_rxenable(MACHANDLE mac, bool deferrable, int ontime, + int duration) +{ + FAR struct ieee802154_privmac_s * priv = (FAR struct ieee802154_privmac_s *)mac; + return -ENOTTY; +} + +/**************************************************************************** + * Name: mac802154_req_scan + * + * Description: + * The MLME-SCAN.request primitive is used to initiate a channel scan over a + * given list of channels. A device can use a channel scan to measure the + * energy on the channel, search for the coordinator with which it associated, + * or search for all coordinators transmitting beacon frames within the POS of + * the scanning device. Scan results are returned + * via MULTIPLE calls to the struct ieee802154_maccb_s->conf_scan callback. + * This is a difference with the official 802.15.4 specification, implemented + * here to save memory. + * + ****************************************************************************/ + +int mac802154_req_scan(MACHANDLE mac, uint8_t type, uint32_t channels, + int duration) +{ + FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; + return -ENOTTY; +} + +/**************************************************************************** + * Name: mac802154_req_set + * + * Description: + * The MLME-SET.request primitive attempts to write the given value to the + * indicated MAC PIB attribute. Confirmation is returned via the + * struct ieee802154_maccb_s->conf_set callback. + * + ****************************************************************************/ + +int mac802154_req_set(MACHANDLE mac, int attribute, FAR uint8_t *value, + int valuelen) +{ + FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; + return -ENOTTY; +} + +/**************************************************************************** + * Name: mac802154_req_start + * + * Description: + * The MLME-START.request primitive makes a request for the device to start + * using a new superframe configuration. Confirmation is returned + * via the struct ieee802154_maccb_s->conf_start callback. + * + ****************************************************************************/ + +int mac802154_req_start(MACHANDLE mac, uint16_t panid, int channel, + uint8_t bo, uint8_t fo, bool coord, bool batext, + bool realign) +{ + FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; + return -ENOTTY; +} + +/**************************************************************************** + * Name: mac802154_req_sync + * + * Description: + * The MLME-SYNC.request primitive requests to synchronize with the + * coordinator by acquiring and, if specified, tracking its beacons. + * Confirmation is returned via the + * struct ieee802154_maccb_s->int_commstatus callback. TOCHECK. + * + ****************************************************************************/ + +int mac802154_req_sync(MACHANDLE mac, int channel, bool track) +{ + FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; + return -ENOTTY; +} + +/**************************************************************************** + * Name: mac802154_req_poll + * + * Description: + * The MLME-POLL.request primitive prompts the device to request data from the + * coordinator. Confirmation is returned via the + * struct ieee802154_maccb_s->conf_poll callback, followed by a + * struct ieee802154_maccb_s->ind_data callback. + * + ****************************************************************************/ + +int mac802154_req_poll(MACHANDLE mac, FAR uint8_t *coordaddr) +{ + FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; + return -ENOTTY; +} + +/**************************************************************************** + * Name: mac802154_rsp_associate + * + * Description: + * The MLME-ASSOCIATE.response primitive is used to initiate a response to an + * MLME-ASSOCIATE.indication primitive. + * + ****************************************************************************/ + +int mac802154_rsp_associate(MACHANDLE mac, uint8_t eadr, uint16_t saddr, + int status) +{ + FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; + return -ENOTTY; +} + +/**************************************************************************** + * Name: mac802154_rsp_orphan + * + * Description: + * The MLME-ORPHAN.response primitive allows the next higher layer of a + * coordinator to respond to the MLME-ORPHAN.indication primitive. + * + ****************************************************************************/ + +int mac802154_rsp_orphan(MACHANDLE mac, FAR uint8_t *orphanaddr, + uint16_t saddr, bool associated) +{ + FAR struct ieee802154_privmac_s *priv = + (FAR struct ieee802154_privmac_s *)mac; + return -ENOTTY; } diff --git a/wireless/ieee802154/mac802154_device.c b/wireless/ieee802154/mac802154_device.c index 83e33f8cf38..fde4cab707d 100644 --- a/wireless/ieee802154/mac802154_device.c +++ b/wireless/ieee802154/mac802154_device.c @@ -66,15 +66,14 @@ struct mac802154_devwrapper_s { - FAR struct ieee802154_mac_s *md_mac; /* Saved binding to the mac layer */ - sem_t md_exclsem; /* Exclusive device access */ + MACHANDLE md_mac; /* Saved binding to the mac layer */ + sem_t md_exclsem; /* Exclusive device access */ /* The following is a singly linked list of open references to the * MAC device. */ FAR struct mac802154_open_s *md_open; - FAR struct mac802154dev_dwait_s *md_dwait; }; @@ -452,7 +451,7 @@ static int mac802154dev_ioctl(FAR struct file *filep, int cmd, { FAR struct inode *inode; FAR struct mac802154_devwrapper_s *dev; - FAR struct ieee802154_mac_s *mac; + MACHANDLE mac; int ret; DEBUGASSERT(filep != NULL && filep->f_priv != NULL && @@ -484,8 +483,8 @@ static int mac802154dev_ioctl(FAR struct file *filep, int cmd, return ret; } -void mac802154dev_conf_data(FAR struct ieee802154_mac_s *mac, - FAR struct ieee802154_data_conf_s *conf) +void mac802154dev_conf_data(MACHANDLE mac, + FAR struct ieee802154_data_conf_s *conf) { FAR struct mac802154_devwrapper_s *dev; FAR struct mac802154dev_dwait_s *curr; @@ -537,7 +536,7 @@ void mac802154dev_conf_data(FAR struct ieee802154_mac_s *mac, * ****************************************************************************/ -int mac802154dev_register(FAR struct ieee802154_mac_s *mac, int minor) +int mac802154dev_register(MACHANDLE mac, int minor) { FAR struct mac802154_devwrapper_s *dev; char devname[DEVNAME_FMTLEN]; diff --git a/wireless/ieee802154/mac802154_netdev.c b/wireless/ieee802154/mac802154_netdev.c index 6dd798f24b5..616d57adfd0 100644 --- a/wireless/ieee802154/mac802154_netdev.c +++ b/wireless/ieee802154/mac802154_netdev.c @@ -111,25 +111,25 @@ /* This is our private version of the MAC callback stucture */ -struct mac802154_callback_s +struct macnet_callback_s { /* This holds the information visible to the MAC layer */ struct ieee802154_maccb_s mc_cb; /* Interface understood by the MAC layer */ - FAR struct mac802154_driver_s *mc_priv; /* Our priv data */ + FAR struct macnet_driver_s *mc_priv; /* Our priv data */ }; -/* The mac802154_driver_s encapsulates all state information for a single +/* The macnet_driver_s encapsulates all state information for a single * IEEE802.15.4 MAC interface. */ -struct mac802154_driver_s +struct macnet_driver_s { /* This holds the information visible to the NuttX network */ - struct ieee802154_driver_s md_dev; /* Interface understood by the network */ - FAR struct ieee802154_mac_s *md_mac; /* Contained MAC interface */ - struct mac802154_callback_s md_cb; /* Callback information */ + struct ieee802154_driver_s md_dev; /* Interface understood by the network */ + struct macnet_callback_s md_cb; /* Callback information */ + MACHANDLE md_mac; /* Contained MAC interface */ /* For internal use by this driver */ @@ -140,20 +140,6 @@ struct mac802154_driver_s struct work_s md_pollwork; /* For deferring poll work to the work queue */ }; -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* A single packet buffer per device is used here. There might be multiple - * packet buffers in a more complex, pipelined design. - */ - -static uint8_t g_pktbuf[MAX_NET_DEV_MTU + CONFIG_NET_GUARDSIZE]; - -/* Driver state structure */ - -static struct mac802154_driver_s g_skel[CONFIG_IEEE802154_NETDEV_NINTERFACES]; - /**************************************************************************** * Private Function Prototypes ****************************************************************************/ @@ -161,93 +147,84 @@ static struct mac802154_driver_s g_skel[CONFIG_IEEE802154_NETDEV_NINTERFACES]; /* IEE802.15.4 MAC callback functions ***************************************/ /* Asynchronous confirmations to requests */ -static void mac802154_conf_data(FAR struct ieee802154_mac_s *mac, +static void macnet_conf_data(MACHANDLE mac, FAR struct ieee802154_data_conf_s *conf); -static void mac802154_conf_purge(FAR struct ieee802154_mac_s *mac, - uint8_t handle, int status); -static void mac802154_conf_associate(FAR struct ieee802154_mac_s *mac, - uint16_t saddr, int status); -static void mac802154_conf_disassociate(FAR struct ieee802154_mac_s *mac, -static void mac802154_conf_get(FAR struct ieee802154_mac_s *mac, int status, - int attribute, FAR uint8_t *value, int valuelen); -static void mac802154_conf_gts(FAR struct ieee802154_mac_s *mac, - FAR uint8_t *characteristics, int status); -static void mac802154_conf_reset(FAR struct ieee802154_mac_s *mac, - int status); -static void mac802154_conf_rxenable(FAR struct ieee802154_mac_s *mac, - int status); -static void mac802154_conf_scan(FAR struct ieee802154_mac_s *mac, - int status, uint8_t type, uint32_t unscanned, int rsltsize, - FAR uint8_t *edlist, FAR uint8_t *pandescs); -static void mac802154_conf_set(FAR struct ieee802154_mac_s *mac, int status, - int attribute); -static void mac802154_conf_start(FAR struct ieee802154_mac_s *mac, - int status); -static void mac802154_conf_poll(FAR struct ieee802154_mac_s *mac, +static void macnet_conf_purge(MACHANDLE mac, uint8_t handle, int status); +static void macnet_conf_associate(MACHANDLE mac, uint16_t saddr, int status); +static void macnet_conf_disassociate(MACHANDLE mac, int status); +static void macnet_conf_get(MACHANDLE mac, int status, int attribute, + FAR uint8_t *value, int valuelen); +static void macnet_conf_gts(MACHANDLE mac, FAR uint8_t *characteristics, int status); +static void macnet_conf_reset(MACHANDLE mac, int status); +static void macnet_conf_rxenable(MACHANDLE mac, int status); +static void macnet_conf_scan(MACHANDLE mac, int status, uint8_t type, + uint32_t unscanned, int rsltsize, FAR uint8_t *edlist, + FAR uint8_t *pandescs); +static void macnet_conf_set(MACHANDLE mac, int status, int attribute); +static void macnet_conf_start(MACHANDLE mac, int status); +static void macnet_conf_poll(MACHANDLE mac, int status); /* Asynchronous event indications, replied to synchronously with responses */ -static void mac802154_ind_data(FAR struct ieee802154_mac_s *mac, - FAR uint8_t *buf, int len); -static void mac802154_ind_associate(FAR struct ieee802154_mac_s *mac, - uint16_t clipanid, FAR uint8_t *clieaddr); -static void mac802154_ind_disassociate(FAR struct ieee802154_mac_s *mac, - FAR uint8_t *eadr, uint8_t reason); -static void mac802154_ind_beaconnotify(FAR struct ieee802154_mac_s *mac, - FAR uint8_t *bsn, FAR struct ieee802154_pan_desc_s *pandesc, - FAR uint8_t *sdu, int sdulen); -static void mac802154_ind_gts(FAR struct ieee802154_mac_s *mac, - FAR uint8_t *devaddr, FAR uint8_t *characteristics); -static void mac802154_ind_orphan(FAR struct ieee802154_mac_s *mac, - FAR uint8_t *orphanaddr); -static void mac802154_ind_commstatus(FAR struct ieee802154_mac_s *mac, - uint16_t panid, FAR uint8_t *src, FAR uint8_t *dst, - int status); -static void mac802154_ind_syncloss(FAR struct ieee802154_mac_s *mac, - int reason); +static void macnet_ind_data(MACHANDLE mac, FAR uint8_t *buf, int len); +static void macnet_ind_associate(MACHANDLE mac, uint16_t clipanid, + FAR uint8_t *clieaddr); +static void macnet_ind_disassociate(MACHANDLE mac, FAR uint8_t *eadr, + uint8_t reason); +static void macnet_ind_beaconnotify(MACHANDLE mac, FAR uint8_t *bsn, + FAR struct ieee802154_pan_desc_s *pandesc, FAR uint8_t *sdu, + int sdulen); +static void macnet_ind_gts(MACHANDLE mac, FAR uint8_t *devaddr, + FAR uint8_t *characteristics); +static void macnet_ind_orphan(MACHANDLE mac, FAR uint8_t *orphanaddr); +static void macnet_ind_commstatus(MACHANDLE mac, uint16_t panid, + FAR uint8_t *src, FAR uint8_t *dst, int status); +static void macnet_ind_syncloss(MACHANDLE mac, int reason); /* Network interface support ************************************************/ /* Common TX logic */ -static int mac802154_transmit(FAR struct mac802154_driver_s *priv); -static int mac802154_txpoll(FAR struct net_driver_s *dev); +static int macnet_transmit(FAR struct macnet_driver_s *priv); +static int macnet_txpoll(FAR struct net_driver_s *dev); /* Frame transfer */ -static void mac802154_receive(FAR struct mac802154_driver_s *priv); -static void mac802154_txdone(FAR struct mac802154_driver_s *priv); +static void macnet_receive(FAR struct macnet_driver_s *priv); +static void macnet_txdone(FAR struct macnet_driver_s *priv); -static void mac802154_transfer_work(FAR void *arg); -static int mac802154_transfer(int irq, FAR void *context, FAR void *arg); +static void macnet_transfer_work(FAR void *arg); +static int macnet_transfer(int irq, FAR void *context, FAR void *arg); /* Watchdog timer expirations */ -static void mac802154_txtimeout_work(FAR void *arg); -static void mac802154_txtimeout_expiry(int argc, wdparm_t arg, ...); +static void macnet_txtimeout_work(FAR void *arg); +static void macnet_txtimeout_expiry(int argc, wdparm_t arg, ...); -static void mac802154_poll_work(FAR void *arg); -static void mac802154_poll_expiry(int argc, wdparm_t arg, ...); +static void macnet_poll_work(FAR void *arg); +static void macnet_poll_expiry(int argc, wdparm_t arg, ...); /* NuttX callback functions */ -static int mac802154_ifup(FAR struct net_driver_s *dev); -static int mac802154_ifdown(FAR struct net_driver_s *dev); +static int macnet_ifup(FAR struct net_driver_s *dev); +static int macnet_ifdown(FAR struct net_driver_s *dev); -static void mac802154_txavail_work(FAR void *arg); -static int mac802154_txavail(FAR struct net_driver_s *dev); +static void macnet_txavail_work(FAR void *arg); +static int macnet_txavail(FAR struct net_driver_s *dev); #if defined(CONFIG_NET_IGMP) || defined(CONFIG_NET_ICMPv6) -static int mac802154_addmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac); +static int macnet_addmac(FAR struct net_driver_s *dev, + FAR const uint8_t *mac); #ifdef CONFIG_NET_IGMP -static int mac802154_rmmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac); +static int macnet_rmmac(FAR struct net_driver_s *dev, + FAR const uint8_t *mac); #endif #ifdef CONFIG_NET_ICMPv6 -static void mac802154_ipv6multicast(FAR struct mac802154_driver_s *priv); +static void macnet_ipv6multicast(FAR struct macnet_driver_s *priv); #endif #endif #ifdef CONFIG_NETDEV_IOCTL -static int mac802154_ioctl(FAR struct net_driver_s *dev, int cmd, long arg); +static int macnet_ioctl(FAR struct net_driver_s *dev, int cmd, long arg); #endif /**************************************************************************** @@ -255,367 +232,352 @@ static int mac802154_ioctl(FAR struct net_driver_s *dev, int cmd, long arg); ****************************************************************************/ /**************************************************************************** - * Name: mac802154_conf_data + * Name: macnet_conf_data * * Description: * Data frame was received by remote device * ****************************************************************************/ -static void mac802154_conf_data(FAR struct ieee802154_mac_s *mac, - FAR struct ieee802154_data_conf_s *conf) +static void macnet_conf_data(MACHANDLE mac, + FAR struct ieee802154_data_conf_s *conf) { - FAR struct mac802154_callback_s *cb = (FAR struct mac802154_callback_s *)mac; - FAR struct mac802154_driver_s *priv; + FAR struct macnet_callback_s *cb = (FAR struct macnet_callback_s *)mac; + FAR struct macnet_driver_s *priv; DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); priv = cb->mc_priv; } /**************************************************************************** - * Name: mac802154_conf_purge + * Name: macnet_conf_purge * * Description: * Data frame was purged * ****************************************************************************/ -static void mac802154_conf_purge(FAR struct ieee802154_mac_s *mac, - uint8_t handle, int status) +static void macnet_conf_purge(MACHANDLE mac, uint8_t handle, int status) { - FAR struct mac802154_callback_s *cb = (FAR struct mac802154_callback_s *)mac; - FAR struct mac802154_driver_s *priv; + FAR struct macnet_callback_s *cb = (FAR struct macnet_callback_s *)mac; + FAR struct macnet_driver_s *priv; DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); priv = cb->mc_priv; } /**************************************************************************** - * Name: mac802154_conf_associate + * Name: macnet_conf_associate * * Description: * Association request completed * ****************************************************************************/ -static void mac802154_conf_associate(FAR struct ieee802154_mac_s *mac, - uint16_t saddr, int status) +static void macnet_conf_associate(MACHANDLE mac, uint16_t saddr, int status) { - FAR struct mac802154_callback_s *cb = (FAR struct mac802154_callback_s *)mac; - FAR struct mac802154_driver_s *priv; + FAR struct macnet_callback_s *cb = (FAR struct macnet_callback_s *)mac; + FAR struct macnet_driver_s *priv; DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); priv = cb->mc_priv; } /**************************************************************************** - * Name: mac802154_conf_disassociate + * Name: macnet_conf_disassociate * * Description: * Disassociation request completed * ****************************************************************************/ -static void mac802154_conf_disassociate(FAR struct ieee802154_mac_s *mac, +static void macnet_conf_disassociate(MACHANDLE mac, int status) { - FAR struct mac802154_callback_s *cb = (FAR struct mac802154_callback_s *)mac; - FAR struct mac802154_driver_s *priv; + FAR struct macnet_callback_s *cb = (FAR struct macnet_callback_s *)mac; + FAR struct macnet_driver_s *priv; DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); priv = cb->mc_priv; } /**************************************************************************** - * Name: mac802154_conf_get + * Name: macnet_conf_get * * Description: * PIvoata returned * ****************************************************************************/ -static void mac802154_conf_get(FAR struct ieee802154_mac_s *mac, int status, - int attribute, FAR uint8_t *value, - int valuelen) +static void macnet_conf_get(MACHANDLE mac, int status, int attribute, + FAR uint8_t *value, int valuelen) { - FAR struct mac802154_callback_s *cb = (FAR struct mac802154_callback_s *)mac; - FAR struct mac802154_driver_s *priv; + FAR struct macnet_callback_s *cb = (FAR struct macnet_callback_s *)mac; + FAR struct macnet_driver_s *priv; DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); priv = cb->mc_priv; } /**************************************************************************** - * Name: mac802154_conf_gts + * Name: macnet_conf_gts * * Description: * GTvoanagement completed * ****************************************************************************/ -static void mac802154_conf_gts(FAR struct ieee802154_mac_s *mac, - FAR uint8_t *characteristics, int status) +static void macnet_conf_gts(MACHANDLE mac, FAR uint8_t *characteristics, + int status) { - FAR struct mac802154_callback_s *cb = (FAR struct mac802154_callback_s *)mac; - FAR struct mac802154_driver_s *priv; + FAR struct macnet_callback_s *cb = (FAR struct macnet_callback_s *)mac; + FAR struct macnet_driver_s *priv; DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); priv = cb->mc_priv; } /**************************************************************************** - * Name: mac802154_conf_reset + * Name: macnet_conf_reset * * Description: * MAveset completed * ****************************************************************************/ -static void mac802154_conf_reset(FAR struct ieee802154_mac_s *mac, - int status) +static void macnet_conf_reset(MACHANDLE mac, int status) { - FAR struct mac802154_callback_s *cb = (FAR struct mac802154_callback_s *)mac; - FAR struct mac802154_driver_s *priv; + FAR struct macnet_callback_s *cb = (FAR struct macnet_callback_s *)mac; + FAR struct macnet_driver_s *priv; DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); priv = cb->mc_priv; } /**************************************************************************** - * Name: mac802154_conf_rxenable + * Name: macnet_conf_rxenable * * Description: * ****************************************************************************/ -static void mac802154_conf_rxenable(FAR struct ieee802154_mac_s *mac, - int status) +static void macnet_conf_rxenable(MACHANDLE mac, int status) { - FAR struct mac802154_callback_s *cb = (FAR struct mac802154_callback_s *)mac; - FAR struct mac802154_driver_s *priv; + FAR struct macnet_callback_s *cb = (FAR struct macnet_callback_s *)mac; + FAR struct macnet_driver_s *priv; DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); priv = cb->mc_priv; } /**************************************************************************** - * Name: mac802154_conf_scan + * Name: macnet_conf_scan * * Description: * ****************************************************************************/ -static void mac802154_conf_scan(FAR struct ieee802154_mac_s *mac, - int status, uint8_t type, - uint32_t unscanned, int rsltsize, - FAR uint8_t *edlist, FAR uint8_t *pandescs) +static void macnet_conf_scan(MACHANDLE mac, int status, uint8_t type, + uint32_t unscanned, int rsltsize, + FAR uint8_t *edlist, FAR uint8_t *pandescs) { - FAR struct mac802154_callback_s *cb = (FAR struct mac802154_callback_s *)mac; - FAR struct mac802154_driver_s *priv; + FAR struct macnet_callback_s *cb = (FAR struct macnet_callback_s *)mac; + FAR struct macnet_driver_s *priv; DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); priv = cb->mc_priv; } /**************************************************************************** - * Name: mac802154_conf_set + * Name: macnet_conf_set * * Description: * ****************************************************************************/ -static void mac802154_conf_set(FAR struct ieee802154_mac_s *mac, int status, - int attribute) +static void macnet_conf_set(MACHANDLE mac, int status, int attribute) { - FAR struct mac802154_callback_s *cb = (FAR struct mac802154_callback_s *)mac; - FAR struct mac802154_driver_s *priv; + FAR struct macnet_callback_s *cb = (FAR struct macnet_callback_s *)mac; + FAR struct macnet_driver_s *priv; DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); priv = cb->mc_priv; } /**************************************************************************** - * Name: mac802154_conf_start + * Name: macnet_conf_start * * Description: * ****************************************************************************/ -static void mac802154_conf_start(FAR struct ieee802154_mac_s *mac, - int status) +static void macnet_conf_start(MACHANDLE mac, int status) { - FAR struct mac802154_callback_s *cb = (FAR struct mac802154_callback_s *)mac; - FAR struct mac802154_driver_s *priv; + FAR struct macnet_callback_s *cb = (FAR struct macnet_callback_s *)mac; + FAR struct macnet_driver_s *priv; DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); priv = cb->mc_priv; } /**************************************************************************** - * Name: mac802154_conf_poll + * Name: macnet_conf_poll * * Description: * ****************************************************************************/ -static void mac802154_conf_poll(FAR struct ieee802154_mac_s *mac, - int status) +static void macnet_conf_poll(MACHANDLE mac, int status) { - FAR struct mac802154_callback_s *cb = (FAR struct mac802154_callback_s *)mac; - FAR struct mac802154_driver_s *priv; + FAR struct macnet_callback_s *cb = (FAR struct macnet_callback_s *)mac; + FAR struct macnet_driver_s *priv; DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); priv = cb->mc_priv; } /**************************************************************************** - * Name: mac802154_ind_data + * Name: macnet_ind_data * * Description: * Data frame received * ****************************************************************************/ -static void mac802154_ind_data(FAR struct ieee802154_mac_s *mac, - FAR uint8_t *buf, int len) +static void macnet_ind_data(MACHANDLE mac, FAR uint8_t *buf, int len) { - FAR struct mac802154_callback_s *cb = (FAR struct mac802154_callback_s *)mac; - FAR struct mac802154_driver_s *priv; + FAR struct macnet_callback_s *cb = (FAR struct macnet_callback_s *)mac; + FAR struct macnet_driver_s *priv; DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); priv = cb->mc_priv; } /**************************************************************************** - * Name: mac802154_ind_associate + * Name: macnet_ind_associate * * Description: * Association request received * ****************************************************************************/ -static void mac802154_ind_associate(FAR struct ieee802154_mac_s *mac, - uint16_t clipanid, - FAR uint8_t *clieaddr) +static void macnet_ind_associate(MACHANDLE mac, uint16_t clipanid, + FAR uint8_t *clieaddr) { - FAR struct mac802154_callback_s *cb = (FAR struct mac802154_callback_s *)mac; - FAR struct mac802154_driver_s *priv; + FAR struct macnet_callback_s *cb = (FAR struct macnet_callback_s *)mac; + FAR struct macnet_driver_s *priv; DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); priv = cb->mc_priv; } /**************************************************************************** - * Name: mac802154_ind_disassociate + * Name: macnet_ind_disassociate * * Description: * Disassociation request received * ****************************************************************************/ -static void mac802154_ind_disassociate(FAR struct ieee802154_mac_s *mac, - FAR uint8_t *eadr, uint8_t reason) +static void macnet_ind_disassociate(MACHANDLE mac, FAR uint8_t *eadr, + uint8_t reason) { - FAR struct mac802154_callback_s *cb = (FAR struct mac802154_callback_s *)mac; - FAR struct mac802154_driver_s *priv; + FAR struct macnet_callback_s *cb = (FAR struct macnet_callback_s *)mac; + FAR struct macnet_driver_s *priv; DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); priv = cb->mc_priv; } /**************************************************************************** - * Name: mac802154_ind_beaconnotify + * Name: macnet_ind_beaconnotify * * Description: * Beacon notification * ****************************************************************************/ -static void mac802154_ind_beaconnotify(FAR struct ieee802154_mac_s *mac, - FAR uint8_t *bsn, - FAR struct ieee802154_pan_desc_s *pandesc, - FAR uint8_t *sdu, int sdulen) +static void macnet_ind_beaconnotify(MACHANDLE mac, FAR uint8_t *bsn, + FAR struct ieee802154_pan_desc_s *pandesc, + FAR uint8_t *sdu, int sdulen) { - FAR struct mac802154_callback_s *cb = (FAR struct mac802154_callback_s *)mac; - FAR struct mac802154_driver_s *priv; + FAR struct macnet_callback_s *cb = (FAR struct macnet_callback_s *)mac; + FAR struct macnet_driver_s *priv; DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); priv = cb->mc_priv; } /**************************************************************************** - * Name: mac802154_ind_gts + * Name: macnet_ind_gts * * Description: * GTS management request received * ****************************************************************************/ -static void mac802154_ind_gts(FAR struct ieee802154_mac_s *mac, - FAR uint8_t *devaddr, - FAR uint8_t *characteristics) +static void macnet_ind_gts(MACHANDLE mac, FAR uint8_t *devaddr, + FAR uint8_t *characteristics) { - FAR struct mac802154_callback_s *cb = (FAR struct mac802154_callback_s *)mac; - FAR struct mac802154_driver_s *priv; + FAR struct macnet_callback_s *cb = (FAR struct macnet_callback_s *)mac; + FAR struct macnet_driver_s *priv; DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); priv = cb->mc_priv; } /**************************************************************************** - * Name: mac802154_ind_orphan + * Name: macnet_ind_orphan * * Description: * Orphan device detected * ****************************************************************************/ -static void mac802154_ind_orphan(FAR struct ieee802154_mac_s *mac, - FAR uint8_t *orphanaddr) +static void macnet_ind_orphan(MACHANDLE mac, FAR uint8_t *orphanaddr) { - FAR struct mac802154_callback_s *cb = (FAR struct mac802154_callback_s *)mac; - FAR struct mac802154_driver_s *priv; + FAR struct macnet_callback_s *cb = (FAR struct macnet_callback_s *)mac; + FAR struct macnet_driver_s *priv; DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); priv = cb->mc_priv; } /**************************************************************************** - * Name: mac802154_ind_commstatus + * Name: macnet_ind_commstatus * * Description: * ****************************************************************************/ -static void mac802154_ind_commstatus(FAR struct ieee802154_mac_s *mac, - uint16_t panid, FAR uint8_t *src, - FAR uint8_t *dst, int status) +static void macnet_ind_commstatus(MACHANDLE mac, uint16_t panid, + FAR uint8_t *src, FAR uint8_t *dst, + int status) { - FAR struct mac802154_callback_s *cb = (FAR struct mac802154_callback_s *)mac; - FAR struct mac802154_driver_s *priv; + FAR struct macnet_callback_s *cb = (FAR struct macnet_callback_s *)mac; + FAR struct macnet_driver_s *priv; DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); priv = cb->mc_priv; } /**************************************************************************** - * Name: mac802154_ind_syncloss + * Name: macnet_ind_syncloss * * Description: * ****************************************************************************/ -static void mac802154_ind_syncloss(FAR struct ieee802154_mac_s *mac, - int reason) +static void macnet_ind_syncloss(MACHANDLE mac, int reason) { - FAR struct mac802154_callback_s *cb = (FAR struct mac802154_callback_s *)mac; - FAR struct mac802154_driver_s *priv; + FAR struct macnet_callback_s *cb = (FAR struct macnet_callback_s *)mac; + FAR struct macnet_driver_s *priv; DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); priv = cb->mc_priv; } /**************************************************************************** - * Name: mac802154_transmit + * Name: macnet_transmit * * Description: * Start hardware transmission. Called either from the txdone interrupt @@ -633,7 +595,7 @@ static void mac802154_ind_syncloss(FAR struct ieee802154_mac_s *mac, * ****************************************************************************/ -static int mac802154_transmit(FAR struct mac802154_driver_s *priv) +static int macnet_transmit(FAR struct macnet_driver_s *priv) { /* Verify that the hardware is ready to send another packet. If we get * here, then we are committed to sending a packet; Higher level logic @@ -651,12 +613,12 @@ static int mac802154_transmit(FAR struct mac802154_driver_s *priv) /* Setup the TX timeout watchdog (perhaps restarting the timer) */ (void)wd_start(priv->md_txtimeout, skeleton_TXTIMEOUT, - mac802154_txtimeout_expiry, 1, (wdparm_t)priv); + macnet_txtimeout_expiry, 1, (wdparm_t)priv); return OK; } /**************************************************************************** - * Name: mac802154_txpoll + * Name: macnet_txpoll * * Description: * The transmitter is available, check if the network has any outgoing @@ -679,9 +641,9 @@ static int mac802154_transmit(FAR struct mac802154_driver_s *priv) * ****************************************************************************/ -static int mac802154_txpoll(FAR struct net_driver_s *dev) +static int macnet_txpoll(FAR struct net_driver_s *dev) { - FAR struct mac802154_driver_s *priv = (FAR struct mac802154_driver_s *)dev->d_private; + FAR struct macnet_driver_s *priv = (FAR struct macnet_driver_s *)dev->d_private; /* If the polling resulted in data that should be sent out, the field * i_framelist will set to a new, outgoing list of frames. @@ -691,7 +653,7 @@ static int mac802154_txpoll(FAR struct net_driver_s *dev) { /* And send the packet */ - mac802154_transmit(priv); + macnet_transmit(priv); } /* If zero is returned, the polling will continue until all connections have @@ -702,7 +664,7 @@ static int mac802154_txpoll(FAR struct net_driver_s *dev) } /**************************************************************************** - * Name: mac802154_receive + * Name: macnet_receive * * Description: * An interrupt was received indicating the availability of a new RX packet @@ -718,7 +680,7 @@ static int mac802154_txpoll(FAR struct net_driver_s *dev) * ****************************************************************************/ -static void mac802154_receive(FAR struct mac802154_driver_s *priv) +static void macnet_receive(FAR struct macnet_driver_s *priv) { FAR struct iob_s *iob; FAR struct iob_s *fptr; @@ -753,12 +715,12 @@ static void mac802154_receive(FAR struct mac802154_driver_s *priv) { /* And send the packet */ - mac802154_transmit(priv); + macnet_transmit(priv); } } /**************************************************************************** - * Name: mac802154_txdone + * Name: macnet_txdone * * Description: * An interrupt was received indicating that the last TX packet(s) is done @@ -774,7 +736,7 @@ static void mac802154_receive(FAR struct mac802154_driver_s *priv) * ****************************************************************************/ -static void mac802154_txdone(FAR struct mac802154_driver_s *priv) +static void macnet_txdone(FAR struct macnet_driver_s *priv) { int delay; @@ -794,11 +756,11 @@ static void mac802154_txdone(FAR struct mac802154_driver_s *priv) /* In any event, poll the network for new TX data */ - (void)devif_poll(&priv->md_dev, mac802154_txpoll); + (void)devif_poll(&priv->md_dev, macnet_txpoll); } /**************************************************************************** - * Name: mac802154_transfer_work + * Name: macnet_transfer_work * * Description: * Perform interrupt related work from the worker thread @@ -814,9 +776,9 @@ static void mac802154_txdone(FAR struct mac802154_driver_s *priv) * ****************************************************************************/ -static void mac802154_transfer_work(FAR void *arg) +static void macnet_transfer_work(FAR void *arg) { - FAR struct mac802154_driver_s *priv = (FAR struct mac802154_driver_s *)arg; + FAR struct macnet_driver_s *priv = (FAR struct macnet_driver_s *)arg; /* Lock the network and serialize driver operations if necessary. * NOTE: Serialization is only required in the case where the driver work @@ -832,16 +794,16 @@ static void mac802154_transfer_work(FAR void *arg) /* Handle interrupts according to status bit settings */ - /* Check if we received an incoming packet, if so, call mac802154_receive() */ + /* Check if we received an incoming packet, if so, call macnet_receive() */ - mac802154_receive(priv); + macnet_receive(priv); - /* Check if a packet transmission just completed. If so, call mac802154_txdone. + /* Check if a packet transmission just completed. If so, call macnet_txdone. * This may disable further Tx interrupts if there are no pending * transmissions. */ - mac802154_txdone(priv); + macnet_txdone(priv); net_unlock(); /* Re-enable Ethernet interrupts */ @@ -850,7 +812,7 @@ static void mac802154_transfer_work(FAR void *arg) } /**************************************************************************** - * Name: mac802154_transfer + * Name: macnet_transfer * * Description: * Hardware interrupt handler @@ -866,9 +828,9 @@ static void mac802154_transfer_work(FAR void *arg) * ****************************************************************************/ -static int mac802154_transfer(int irq, FAR void *context, FAR void *arg) +static int macnet_transfer(int irq, FAR void *context, FAR void *arg) { - FAR struct mac802154_driver_s *priv = &g_skel[0]; + FAR struct macnet_driver_s *priv = (FAR struct macnet_driver_s *)arg; /* Disable further Ethernet interrupts. Because Ethernet interrupts are * also disabled if the TX timeout event occurs, there can be no race @@ -890,12 +852,12 @@ static int mac802154_transfer(int irq, FAR void *context, FAR void *arg) /* Schedule to perform the interrupt processing on the worker thread. */ - work_queue(ETHWORK, &priv->md_irqwork, mac802154_transfer_work, priv, 0); + work_queue(ETHWORK, &priv->md_irqwork, macnet_transfer_work, priv, 0); return OK; } /**************************************************************************** - * Name: mac802154_txtimeout_work + * Name: macnet_txtimeout_work * * Description: * Perform TX timeout related work from the worker thread @@ -911,9 +873,9 @@ static int mac802154_transfer(int irq, FAR void *context, FAR void *arg) * ****************************************************************************/ -static void mac802154_txtimeout_work(FAR void *arg) +static void macnet_txtimeout_work(FAR void *arg) { - FAR struct mac802154_driver_s *priv = (FAR struct mac802154_driver_s *)arg; + FAR struct macnet_driver_s *priv = (FAR struct macnet_driver_s *)arg; /* Lock the network and serialize driver operations if necessary. * NOTE: Serialization is only required in the case where the driver work @@ -931,12 +893,12 @@ static void mac802154_txtimeout_work(FAR void *arg) /* Then poll the network for new XMIT data */ - (void)devif_poll(&priv->md_dev, mac802154_txpoll); + (void)devif_poll(&priv->md_dev, macnet_txpoll); net_unlock(); } /**************************************************************************** - * Name: mac802154_txtimeout_expiry + * Name: macnet_txtimeout_expiry * * Description: * Our TX watchdog timed out. Called from the timer interrupt handler. @@ -954,9 +916,9 @@ static void mac802154_txtimeout_work(FAR void *arg) * ****************************************************************************/ -static void mac802154_txtimeout_expiry(int argc, wdparm_t arg, ...) +static void macnet_txtimeout_expiry(int argc, wdparm_t arg, ...) { - FAR struct mac802154_driver_s *priv = (FAR struct mac802154_driver_s *)arg; + FAR struct macnet_driver_s *priv = (FAR struct macnet_driver_s *)arg; /* Disable further Ethernet interrupts. This will prevent some race * conditions with interrupt work. There is still a potential race @@ -967,11 +929,11 @@ static void mac802154_txtimeout_expiry(int argc, wdparm_t arg, ...) /* Schedule to perform the TX timeout processing on the worker thread. */ - work_queue(ETHWORK, &priv->md_irqwork, mac802154_txtimeout_work, priv, 0); + work_queue(ETHWORK, &priv->md_irqwork, macnet_txtimeout_work, priv, 0); } /**************************************************************************** - * Name: mac802154_poll_process + * Name: macnet_poll_process * * Description: * Perform the periodic poll. This may be called either from watchdog @@ -987,12 +949,12 @@ static void mac802154_txtimeout_expiry(int argc, wdparm_t arg, ...) * ****************************************************************************/ -static inline void mac802154_poll_process(FAR struct mac802154_driver_s *priv) +static inline void macnet_poll_process(FAR struct macnet_driver_s *priv) { } /**************************************************************************** - * Name: mac802154_poll_work + * Name: macnet_poll_work * * Description: * Perform periodic polling from the worker thread @@ -1008,9 +970,9 @@ static inline void mac802154_poll_process(FAR struct mac802154_driver_s *priv) * ****************************************************************************/ -static void mac802154_poll_work(FAR void *arg) +static void macnet_poll_work(FAR void *arg) { - FAR struct mac802154_driver_s *priv = (FAR struct mac802154_driver_s *)arg; + FAR struct macnet_driver_s *priv = (FAR struct macnet_driver_s *)arg; /* Lock the network and serialize driver operations if necessary. * NOTE: Serialization is only required in the case where the driver work @@ -1031,17 +993,17 @@ static void mac802154_poll_work(FAR void *arg) * progress, we will missing TCP time state updates? */ - (void)devif_timer(&priv->md_dev, mac802154_txpoll); + (void)devif_timer(&priv->md_dev, macnet_txpoll); /* Setup the watchdog poll timer again */ - (void)wd_start(priv->md_txpoll, skeleton_WDDELAY, mac802154_poll_expiry, 1, + (void)wd_start(priv->md_txpoll, skeleton_WDDELAY, macnet_poll_expiry, 1, (wdparm_t)priv); net_unlock(); } /**************************************************************************** - * Name: mac802154_poll_expiry + * Name: macnet_poll_expiry * * Description: * Periodic timer handler. Called from the timer interrupt handler. @@ -1058,17 +1020,17 @@ static void mac802154_poll_work(FAR void *arg) * ****************************************************************************/ -static void mac802154_poll_expiry(int argc, wdparm_t arg, ...) +static void macnet_poll_expiry(int argc, wdparm_t arg, ...) { - FAR struct mac802154_driver_s *priv = (FAR struct mac802154_driver_s *)arg; + FAR struct macnet_driver_s *priv = (FAR struct macnet_driver_s *)arg; /* Schedule to perform the interrupt processing on the worker thread. */ - work_queue(ETHWORK, &priv->md_pollwork, mac802154_poll_work, priv, 0); + work_queue(ETHWORK, &priv->md_pollwork, macnet_poll_work, priv, 0); } /**************************************************************************** - * Name: mac802154_ifup + * Name: macnet_ifup * * Description: * NuttX Callback: Bring up the Ethernet interface when an IP address is @@ -1084,9 +1046,9 @@ static void mac802154_poll_expiry(int argc, wdparm_t arg, ...) * ****************************************************************************/ -static int mac802154_ifup(FAR struct net_driver_s *dev) +static int macnet_ifup(FAR struct net_driver_s *dev) { - FAR struct mac802154_driver_s *priv = (FAR struct mac802154_driver_s *)dev->d_private; + FAR struct macnet_driver_s *priv = (FAR struct macnet_driver_s *)dev->d_private; #ifdef CONFIG_NET_IPv4 ninfo("Bringing up: %d.%d.%d.%d\n", @@ -1107,12 +1069,12 @@ static int mac802154_ifup(FAR struct net_driver_s *dev) #ifdef CONFIG_NET_ICMPv6 /* Set up IPv6 multicast address filtering */ - mac802154_ipv6multicast(priv); + macnet_ipv6multicast(priv); #endif /* Set and activate a timer process */ - (void)wd_start(priv->md_txpoll, skeleton_WDDELAY, mac802154_poll_expiry, 1, + (void)wd_start(priv->md_txpoll, skeleton_WDDELAY, macnet_poll_expiry, 1, (wdparm_t)priv); /* Enable the Ethernet interrupt */ @@ -1123,7 +1085,7 @@ static int mac802154_ifup(FAR struct net_driver_s *dev) } /**************************************************************************** - * Name: mac802154_ifdown + * Name: macnet_ifdown * * Description: * NuttX Callback: Stop the interface. @@ -1138,9 +1100,9 @@ static int mac802154_ifup(FAR struct net_driver_s *dev) * ****************************************************************************/ -static int mac802154_ifdown(FAR struct net_driver_s *dev) +static int macnet_ifdown(FAR struct net_driver_s *dev) { - FAR struct mac802154_driver_s *priv = (FAR struct mac802154_driver_s *)dev->d_private; + FAR struct macnet_driver_s *priv = (FAR struct macnet_driver_s *)dev->d_private; irqstate_t flags; /* Disable the Ethernet interrupt */ @@ -1154,7 +1116,7 @@ static int mac802154_ifdown(FAR struct net_driver_s *dev) wd_cancel(priv->md_txtimeout); /* Put the EMAC in its reset, non-operational state. This should be - * a known configuration that will guarantee the mac802154_ifup() always + * a known configuration that will guarantee the macnet_ifup() always * successfully brings the interface back up. */ @@ -1166,7 +1128,7 @@ static int mac802154_ifdown(FAR struct net_driver_s *dev) } /**************************************************************************** - * Name: mac802154_txavail_work + * Name: macnet_txavail_work * * Description: * Perform an out-of-cycle poll on the worker thread. @@ -1182,9 +1144,9 @@ static int mac802154_ifdown(FAR struct net_driver_s *dev) * ****************************************************************************/ -static void mac802154_txavail_work(FAR void *arg) +static void macnet_txavail_work(FAR void *arg) { - FAR struct mac802154_driver_s *priv = (FAR struct mac802154_driver_s *)arg; + FAR struct macnet_driver_s *priv = (FAR struct macnet_driver_s *)arg; /* Lock the network and serialize driver operations if necessary. * NOTE: Serialization is only required in the case where the driver work @@ -1202,14 +1164,14 @@ static void mac802154_txavail_work(FAR void *arg) /* If so, then poll the network for new XMIT data */ - (void)devif_poll(&priv->md_dev, mac802154_txpoll); + (void)devif_poll(&priv->md_dev, macnet_txpoll); } net_unlock(); } /**************************************************************************** - * Name: mac802154_txavail + * Name: macnet_txavail * * Description: * Driver callback invoked when new TX data is available. This is a @@ -1227,9 +1189,9 @@ static void mac802154_txavail_work(FAR void *arg) * ****************************************************************************/ -static int mac802154_txavail(FAR struct net_driver_s *dev) +static int macnet_txavail(FAR struct net_driver_s *dev) { - FAR struct mac802154_driver_s *priv = (FAR struct mac802154_driver_s *)dev->d_private; + FAR struct macnet_driver_s *priv = (FAR struct macnet_driver_s *)dev->d_private; /* Is our single work structure available? It may not be if there are * pending interrupt actions and we will have to ignore the Tx @@ -1240,14 +1202,14 @@ static int mac802154_txavail(FAR struct net_driver_s *dev) { /* Schedule to serialize the poll on the worker thread. */ - work_queue(ETHWORK, &priv->md_pollwork, mac802154_txavail_work, priv, 0); + work_queue(ETHWORK, &priv->md_pollwork, macnet_txavail_work, priv, 0); } return OK; } /**************************************************************************** - * Name: mac802154_addmac + * Name: macnet_addmac * * Description: * NuttX Callback: Add the specified MAC address to the hardware multicast @@ -1265,9 +1227,9 @@ static int mac802154_txavail(FAR struct net_driver_s *dev) ****************************************************************************/ #if defined(CONFIG_NET_IGMP) || defined(CONFIG_NET_ICMPv6) -static int mac802154_addmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac) +static int macnet_addmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac) { - FAR struct mac802154_driver_s *priv = (FAR struct mac802154_driver_s *)dev->d_private; + FAR struct macnet_driver_s *priv = (FAR struct macnet_driver_s *)dev->d_private; /* Add the MAC address to the hardware multicast routing table */ @@ -1276,7 +1238,7 @@ static int mac802154_addmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac #endif /**************************************************************************** - * Name: mac802154_rmmac + * Name: macnet_rmmac * * Description: * NuttX Callback: Remove the specified MAC address from the hardware multicast @@ -1294,9 +1256,9 @@ static int mac802154_addmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac ****************************************************************************/ #ifdef CONFIG_NET_IGMP -static int mac802154_rmmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac) +static int macnet_rmmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac) { - FAR struct mac802154_driver_s *priv = (FAR struct mac802154_driver_s *)dev->d_private; + FAR struct macnet_driver_s *priv = (FAR struct macnet_driver_s *)dev->d_private; /* Add the MAC address to the hardware multicast routing table */ @@ -1305,7 +1267,7 @@ static int mac802154_rmmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac) #endif /**************************************************************************** - * Name: mac802154_ipv6multicast + * Name: macnet_ipv6multicast * * Description: * Configure the IPv6 multicast MAC address. @@ -1321,7 +1283,7 @@ static int mac802154_rmmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac) ****************************************************************************/ #ifdef CONFIG_NET_ICMPv6 -static void mac802154_ipv6multicast(FAR struct mac802154_driver_s *priv) +static void macnet_ipv6multicast(FAR struct macnet_driver_s *priv) { FAR struct net_driver_s *dev; uint16_t tmp16; @@ -1354,7 +1316,7 @@ static void mac802154_ipv6multicast(FAR struct mac802154_driver_s *priv) ninfo("IPv6 Multicast: %02x:%02x:%02x:%02x:%02x:%02x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); - (void)mac802154_addmac(dev, mac); + (void)macnet_addmac(dev, mac); #ifdef CONFIG_NET_ICMPv6_AUTOCONF /* Add the IPv6 all link-local nodes Ethernet address. This is the @@ -1362,7 +1324,7 @@ static void mac802154_ipv6multicast(FAR struct mac802154_driver_s *priv) * packets. */ - (void)mac802154_addmac(dev, g_ipv6_ethallnodes.ether_addr_octet); + (void)macnet_addmac(dev, g_ipv6_ethallnodes.ether_addr_octet); #endif /* CONFIG_NET_ICMPv6_AUTOCONF */ @@ -1372,14 +1334,14 @@ static void mac802154_ipv6multicast(FAR struct mac802154_driver_s *priv) * packets. */ - (void)mac802154_addmac(dev, g_ipv6_ethallrouters.ether_addr_octet); + (void)macnet_addmac(dev, g_ipv6_ethallrouters.ether_addr_octet); #endif /* CONFIG_NET_ICMPv6_ROUTER */ } #endif /* CONFIG_NET_ICMPv6 */ /**************************************************************************** - * Name: mac802154_ioctl + * Name: macnet_ioctl * * Description: * Handle network IOCTL commands directed to this device. @@ -1397,9 +1359,9 @@ static void mac802154_ipv6multicast(FAR struct mac802154_driver_s *priv) ****************************************************************************/ #ifdef CONFIG_NETDEV_IOCTL -static int mac802154_ioctl(FAR struct net_driver_s *dev, int cmd, long arg) +static int macnet_ioctl(FAR struct net_driver_s *dev, int cmd, long arg) { - FAR struct mac802154_driver_s *priv = (FAR struct mac802154_driver_s *)dev->d_private; + FAR struct macnet_driver_s *priv = (FAR struct macnet_driver_s *)dev->d_private; int ret = -EINVAL; /* Check for IOCTLs aimed at the IEEE802.15.4 MAC layer */ @@ -1461,9 +1423,9 @@ static int mac802154_ioctl(FAR struct net_driver_s *dev, int cmd, long arg) * ****************************************************************************/ -int mac802154netdev_register(FAR struct ieee802154_mac_s *mac); +int mac802154netdev_register(MACHANDLE mac) { - FAR struct mac802154_driver_s *priv; + FAR struct macnet_driver_s *priv; FAR struct net_driver_s *dev; FAR uint8_t *pktbuf; int ret; @@ -1472,8 +1434,8 @@ int mac802154netdev_register(FAR struct ieee802154_mac_s *mac); /* Get the interface structure associated with this interface number. */ - priv = (FAR struct mac802154_driver_s *) - kmm_zalloc(sizeof(struct mac802154_driver_s)); + priv = (FAR struct macnet_driver_s *) + kmm_zalloc(sizeof(struct macnet_driver_s)); if (priv == NULL) { @@ -1497,15 +1459,15 @@ int mac802154netdev_register(FAR struct ieee802154_mac_s *mac); dev = &ieee->md_dev.i_dev; dev->d_buf = pktbuf; /* Single packet buffer */ - dev->d_ifup = mac802154_ifup; /* I/F up (new IP address) callback */ - dev->d_ifdown = mac802154_ifdown; /* I/F down callback */ - dev->d_txavail = mac802154_txavail; /* New TX data callback */ + dev->d_ifup = macnet_ifup; /* I/F up (new IP address) callback */ + dev->d_ifdown = macnet_ifdown; /* I/F down callback */ + dev->d_txavail = macnet_txavail; /* New TX data callback */ #ifdef CONFIG_NET_IGMP - dev->d_addmac = mac802154_addmac; /* Add multicast MAC address */ - dev->d_rmmac = mac802154_rmmac; /* Remove multicast MAC address */ + dev->d_addmac = macnet_addmac; /* Add multicast MAC address */ + dev->d_rmmac = macnet_rmmac; /* Remove multicast MAC address */ #endif #ifdef CONFIG_NETDEV_IOCTL - dev->d_ioctl = mac802154_ioctl; /* Handle network IOCTL commands */ + dev->d_ioctl = macnet_ioctl; /* Handle network IOCTL commands */ #endif dev->d_private = (FAR void *)priv; /* Used to recover private state from dev */ @@ -1522,26 +1484,26 @@ int mac802154netdev_register(FAR struct ieee802154_mac_s *mac); priv->md_cb.mc_priv = priv; maccb = &priv->md_cb.mc_cb; - maccb->conf_data = mac802154_conf_data; - maccb->conf_purge = mac802154_conf_purge; - maccb->conf_associate = mac802154_conf_associate; - maccb->conf_disassociate = mac802154_conf_disassociate; - maccb->conf_get = mac802154_conf_get; - maccb->conf_gts = mac802154_conf_gts; - maccb->conf_reset = mac802154_conf_reset; - maccb->conf_rxenable = mac802154_conf_rxenable; - maccb->conf_scan = mac802154_conf_scan; - maccb->conf_set = mac802154_conf_set; - maccb->conf_start = mac802154_conf_start; - maccb->conf_poll = mac802154_conf_poll; - maccb->ind_data = mac802154_ind_data; - maccb->ind_associate = mac802154_ind_associate; - maccb->ind_disassociate = mac802154_ind_disassociate; - maccb->ind_beaconnotify = mac802154_ind_beaconnotify; - maccb->ind_gts = mac802154_ind_gts; - maccb->ind_orphan = mac802154_ind_orphan; - maccb->ind_commstatus = mac802154_ind_commstatus; - maccb->ind_syncloss = mac802154_ind_syncloss; + maccb->conf_data = macnet_conf_data; + maccb->conf_purge = macnet_conf_purge; + maccb->conf_associate = macnet_conf_associate; + maccb->conf_disassociate = macnet_conf_disassociate; + maccb->conf_get = macnet_conf_get; + maccb->conf_gts = macnet_conf_gts; + maccb->conf_reset = macnet_conf_reset; + maccb->conf_rxenable = macnet_conf_rxenable; + maccb->conf_scan = macnet_conf_scan; + maccb->conf_set = macnet_conf_set; + maccb->conf_start = macnet_conf_start; + maccb->conf_poll = macnet_conf_poll; + maccb->ind_data = macnet_ind_data; + maccb->ind_associate = macnet_ind_associate; + maccb->ind_disassociate = macnet_ind_disassociate; + maccb->ind_beaconnotify = macnet_ind_beaconnotify; + maccb->ind_gts = macnet_ind_gts; + maccb->ind_orphan = macnet_ind_orphan; + maccb->ind_commstatus = macnet_ind_commstatus; + maccb->ind_syncloss = macnet_ind_syncloss; /* Bind the callback structure */ @@ -1563,7 +1525,7 @@ int mac802154netdev_register(FAR struct ieee802154_mac_s *mac); /* Put the interface in the down state. */ - mac802154_ifdown(dev); + macnet_ifdown(dev); /* Register the device with the OS so that socket IOCTLs can be performed */ From 6004f33f617bf4ae56522227d0a391754e399ccd Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 14 Apr 2017 10:47:46 -0600 Subject: [PATCH 063/183] Trivial cleanup --- wireless/ieee802154/mac802154_netdev.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/wireless/ieee802154/mac802154_netdev.c b/wireless/ieee802154/mac802154_netdev.c index 616d57adfd0..1f5e68729f5 100644 --- a/wireless/ieee802154/mac802154_netdev.c +++ b/wireless/ieee802154/mac802154_netdev.c @@ -214,17 +214,18 @@ static int macnet_txavail(FAR struct net_driver_s *dev); #if defined(CONFIG_NET_IGMP) || defined(CONFIG_NET_ICMPv6) static int macnet_addmac(FAR struct net_driver_s *dev, - FAR const uint8_t *mac); + FAR const uint8_t *mac); #ifdef CONFIG_NET_IGMP static int macnet_rmmac(FAR struct net_driver_s *dev, - FAR const uint8_t *mac); + FAR const uint8_t *mac); #endif #ifdef CONFIG_NET_ICMPv6 static void macnet_ipv6multicast(FAR struct macnet_driver_s *priv); #endif #endif #ifdef CONFIG_NETDEV_IOCTL -static int macnet_ioctl(FAR struct net_driver_s *dev, int cmd, long arg); +static int macnet_ioctl(FAR struct net_driver_s *dev, int cmd, + unsigned long arg); #endif /**************************************************************************** @@ -1359,7 +1360,8 @@ static void macnet_ipv6multicast(FAR struct macnet_driver_s *priv) ****************************************************************************/ #ifdef CONFIG_NETDEV_IOCTL -static int macnet_ioctl(FAR struct net_driver_s *dev, int cmd, long arg) +static int macnet_ioctl(FAR struct net_driver_s *dev, int cmd, + unsigned long arg) { FAR struct macnet_driver_s *priv = (FAR struct macnet_driver_s *)dev->d_private; int ret = -EINVAL; From fba8c96540c0af29fd108d885dfc8294905e9fd1 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 14 Apr 2017 11:24:40 -0600 Subject: [PATCH 064/183] ieee802.15.4: New global functions exported by the lower MAC layer should be private to the MAC module. Function prototypes moved from include/nuttx/wireless/ieee802154/ieee802154_mac.h to wireless/ieee802154/mac802154.h --- .../wireless/ieee802154/ieee802154_mac.h | 238 -------------- wireless/ieee802154/Make.defs | 2 +- wireless/ieee802154/mac802154.c | 2 + wireless/ieee802154/mac802154.h | 304 ++++++++++++++++++ wireless/ieee802154/mac802154_device.c | 2 + wireless/ieee802154/mac802154_loopback.c | 2 + wireless/ieee802154/mac802154_netdev.c | 2 + 7 files changed, 313 insertions(+), 239 deletions(-) create mode 100644 wireless/ieee802154/mac802154.h diff --git a/include/nuttx/wireless/ieee802154/ieee802154_mac.h b/include/nuttx/wireless/ieee802154/ieee802154_mac.h index acfc541c589..8bef67a14d4 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_mac.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_mac.h @@ -1053,244 +1053,6 @@ int mac802154dev_register(MACHANDLE mac, int minor); int mac802154netdev_register(MACHANDLE mac); -/**************************************************************************** - * Name: mac802154_bind - * - * Description: - * Bind the MAC callback table to the MAC state. - * - * Parameters: - * mac - Reference to the MAC driver state structure - * cb - MAC callback operations - * - * Returned Value: - * OK on success; Negated errno on failure. - * - ****************************************************************************/ - -int mac802154_bind(MACHANDLE mac, FAR const struct ieee802154_maccb_s *cb); - -/**************************************************************************** - * Name: mac802154_ioctl - * - * Description: - * Handle MAC and radio IOCTL commands directed to the MAC. - * - * Parameters: - * mac - Reference to the MAC driver state structure - * cmd - The IOCTL command - * arg - The argument for the IOCTL command - * - * Returned Value: - * OK on success; Negated errno on failure. - * - ****************************************************************************/ - -int mac802154_ioctl(MACHANDLE mac, int cmd, unsigned long arg); - -/**************************************************************************** - * MAC Interface Operations - ****************************************************************************/ - -/**************************************************************************** - * Name: mac802154_req_data - * - * Description: - * The MCPS-DATA.request primitive requests the transfer of a data SPDU - * (i.e., MSDU) from a local SSCS entity to a single peer SSCS entity. - * Confirmation is returned via the - * struct ieee802154_maccb_s->conf_data callback. - * - ****************************************************************************/ - -int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req); - -/**************************************************************************** - * Name: mac802154_req_purge - * - * Description: - * The MCPS-PURGE.request primitive allows the next higher layer to purge an - * MSDU from the transaction queue. Confirmation is returned via - * the struct ieee802154_maccb_s->conf_purge callback. - * - ****************************************************************************/ - -int mac802154_req_purge(MACHANDLE mac, uint8_t handle); - -/**************************************************************************** - * Name: mac802154_req_associate - * - * Description: - * The MLME-ASSOCIATE.request primitive allows a device to request an - * association with a coordinator. Confirmation is returned via the - * struct ieee802154_maccb_s->conf_associate callback. - * - ****************************************************************************/ - -int mac802154_req_associate(MACHANDLE mac - FAR struct ieee802154_assoc_req_s *req); - -/**************************************************************************** - * Name: mac802154_req_disassociate - * - * Description: - * The MLME-DISASSOCIATE.request primitive is used by an associated device to - * notify the coordinator of its intent to leave the PAN. It is also used by - * the coordinator to instruct an associated device to leave the PAN. - * Confirmation is returned via the - * struct ieee802154_maccb_s->conf_disassociate callback. - * - ****************************************************************************/ - -int mac802154_req_disassociate(MACHANDLE mac, - FAR struct ieee802154_disassoc_req_s *req); - -/**************************************************************************** - * Name: mac802154_req_get - * - * Description: - * The MLME-GET.request primitive requests information about a given PIB - * attribute. Actual data is returned via the - * struct ieee802154_maccb_s->conf_get callback. - * - ****************************************************************************/ - -int mac802154_req_get(MACHANDLE mac, enum ieee802154_pib_attr_e attr); - -/**************************************************************************** - * Name: mac802154_req_gts - * - * Description: - * The MLME-GTS.request primitive allows a device to send a request to the PAN - * coordinator to allocate a new GTS or to deallocate an existing GTS. - * Confirmation is returned via the - * struct ieee802154_maccb_s->conf_gts callback. - * - ****************************************************************************/ - -int mac802154_req_gts(MACHANDLE mac, FAR uint8_t *characteristics); - -/**************************************************************************** - * Name: mac802154_req_reset - * - * Description: - * The MLME-RESET.request primitive allows the next higher layer to request - * that the MLME performs a reset operation. Confirmation is returned via - * the struct ieee802154_maccb_s->conf_reset callback. - * - ****************************************************************************/ - -int mac802154_req_reset(MACHANDLE mac, bool setdefaults); - -/**************************************************************************** - * Name: mac802154_req_rxenable - * - * Description: - * The MLME-RX-ENABLE.request primitive allows the next higher layer to - * request that the receiver is enable for a finite period of time. - * Confirmation is returned via the - * struct ieee802154_maccb_s->conf_rxenable callback. - * - ****************************************************************************/ - -int mac802154_req_rxenable(MACHANDLE mac, bool deferrable, int ontime, - int duration); - -/**************************************************************************** - * Name: mac802154_req_scan - * - * Description: - * The MLME-SCAN.request primitive is used to initiate a channel scan over a - * given list of channels. A device can use a channel scan to measure the - * energy on the channel, search for the coordinator with which it associated, - * or search for all coordinators transmitting beacon frames within the POS of - * the scanning device. Scan results are returned - * via MULTIPLE calls to the struct ieee802154_maccb_s->conf_scan callback. - * This is a difference with the official 802.15.4 specification, implemented - * here to save memory. - * - ****************************************************************************/ - -int mac802154_req_scan(MACHANDLE mac, uint8_t type, uint32_t channels, - int duration); - -/**************************************************************************** - * Name: mac802154_req_set - * - * Description: - * The MLME-SET.request primitive attempts to write the given value to the - * indicated MAC PIB attribute. Confirmation is returned via the - * struct ieee802154_maccb_s->conf_set callback. - * - ****************************************************************************/ - -int mac802154_req_set(MACHANDLE mac, int attribute, FAR uint8_t *value, - int valuelen); - -/**************************************************************************** - * Name: mac802154_req_start - * - * Description: - * The MLME-START.request primitive makes a request for the device to start - * using a new superframe configuration. Confirmation is returned - * via the struct ieee802154_maccb_s->conf_start callback. - * - ****************************************************************************/ - -int mac802154_req_start(MACHANDLE mac, uint16_t panid, int channel, - uint8_t bo, uint8_t fo, bool coord, bool batext, - bool realign); - -/**************************************************************************** - * Name: mac802154_req_sync - * - * Description: - * The MLME-SYNC.request primitive requests to synchronize with the - * coordinator by acquiring and, if specified, tracking its beacons. - * Confirmation is returned via the - * struct ieee802154_maccb_s->int_commstatus callback. TOCHECK. - * - ****************************************************************************/ - -int mac802154_req_sync(MACHANDLE mac, int channel, bool track); - -/**************************************************************************** - * Name: mac802154_req_poll - * - * Description: - * The MLME-POLL.request primitive prompts the device to request data from the - * coordinator. Confirmation is returned via the - * struct ieee802154_maccb_s->conf_poll callback, followed by a - * struct ieee802154_maccb_s->ind_data callback. - * - ****************************************************************************/ - -int mac802154_req_poll(MACHANDLE mac, FAR uint8_t *coordaddr); - -/**************************************************************************** - * Name: mac802154_rsp_associate - * - * Description: - * The MLME-ASSOCIATE.response primitive is used to initiate a response to an - * MLME-ASSOCIATE.indication primitive. - * - ****************************************************************************/ - -int mac802154_rsp_associate(MACHANDLE mac, uint8_t eadr, uint16_t saddr, - int status); - -/**************************************************************************** - * Name: mac802154_rsp_orphan - * - * Description: - * The MLME-ORPHAN.response primitive allows the next higher layer of a - * coordinator to respond to the MLME-ORPHAN.indication primitive. - * - ****************************************************************************/ - -int mac802154_rsp_orphan(MACHANDLE mac, FAR uint8_t *orphanaddr, - uint16_t saddr, bool associated); - #undef EXTERN #ifdef __cplusplus } diff --git a/wireless/ieee802154/Make.defs b/wireless/ieee802154/Make.defs index fc4db543bfb..8a0466eb825 100644 --- a/wireless/ieee802154/Make.defs +++ b/wireless/ieee802154/Make.defs @@ -1,7 +1,7 @@ ############################################################################ # wireless/ieee802145/Make.defs # -# Copyright (C) 2016 Gregory Nutt. All rights reserved. +# Copyright (C) 2016-2017 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without diff --git a/wireless/ieee802154/mac802154.c b/wireless/ieee802154/mac802154.c index 693e2db7711..5dcb8b7fee5 100644 --- a/wireless/ieee802154/mac802154.c +++ b/wireless/ieee802154/mac802154.c @@ -47,6 +47,8 @@ #include #include +#include "mac802154.h" + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ diff --git a/wireless/ieee802154/mac802154.h b/wireless/ieee802154/mac802154.h new file mode 100644 index 00000000000..696977259fd --- /dev/null +++ b/wireless/ieee802154/mac802154.h @@ -0,0 +1,304 @@ +/**************************************************************************** + * wireless/ieee802154/mac802154.h + * + * Copyright (C) 2016 Sebastien Lorquet. All rights reserved. + * Copyright (C) 2017 Verge Inc. All rights reserved. + * Copyright (C) 2017 Gregory Nutt. All rights reserved. + * + * Author: Sebastien Lorquet + * Author: Anthony Merlino + * + * The naming and comments for various fields are taken directly + * from the IEEE 802.15.4 2011 standard. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __WIRELESS_IEEE802154__MAC802154_H +#define __WIRELESS_IEEE802154__MAC802154_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + + /**************************************************************************** + * Name: mac802154_bind + * + * Description: + * Bind the MAC callback table to the MAC state. + * + * Parameters: + * mac - Reference to the MAC driver state structure + * cb - MAC callback operations + * + * Returned Value: + * OK on success; Negated errno on failure. + * + ****************************************************************************/ + +int mac802154_bind(MACHANDLE mac, FAR const struct ieee802154_maccb_s *cb); + +/**************************************************************************** + * Name: mac802154_ioctl + * + * Description: + * Handle MAC and radio IOCTL commands directed to the MAC. + * + * Parameters: + * mac - Reference to the MAC driver state structure + * cmd - The IOCTL command + * arg - The argument for the IOCTL command + * + * Returned Value: + * OK on success; Negated errno on failure. + * + ****************************************************************************/ + +int mac802154_ioctl(MACHANDLE mac, int cmd, unsigned long arg); + +/**************************************************************************** + * MAC Interface Operations + ****************************************************************************/ + +/**************************************************************************** + * Name: mac802154_req_data + * + * Description: + * The MCPS-DATA.request primitive requests the transfer of a data SPDU + * (i.e., MSDU) from a local SSCS entity to a single peer SSCS entity. + * Confirmation is returned via the + * struct ieee802154_maccb_s->conf_data callback. + * + ****************************************************************************/ + +int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req); + +/**************************************************************************** + * Name: mac802154_req_purge + * + * Description: + * The MCPS-PURGE.request primitive allows the next higher layer to purge an + * MSDU from the transaction queue. Confirmation is returned via + * the struct ieee802154_maccb_s->conf_purge callback. + * + ****************************************************************************/ + +int mac802154_req_purge(MACHANDLE mac, uint8_t handle); + +/**************************************************************************** + * Name: mac802154_req_associate + * + * Description: + * The MLME-ASSOCIATE.request primitive allows a device to request an + * association with a coordinator. Confirmation is returned via the + * struct ieee802154_maccb_s->conf_associate callback. + * + ****************************************************************************/ + +int mac802154_req_associate(MACHANDLE mac + FAR struct ieee802154_assoc_req_s *req); + +/**************************************************************************** + * Name: mac802154_req_disassociate + * + * Description: + * The MLME-DISASSOCIATE.request primitive is used by an associated device to + * notify the coordinator of its intent to leave the PAN. It is also used by + * the coordinator to instruct an associated device to leave the PAN. + * Confirmation is returned via the + * struct ieee802154_maccb_s->conf_disassociate callback. + * + ****************************************************************************/ + +int mac802154_req_disassociate(MACHANDLE mac, + FAR struct ieee802154_disassoc_req_s *req); + +/**************************************************************************** + * Name: mac802154_req_get + * + * Description: + * The MLME-GET.request primitive requests information about a given PIB + * attribute. Actual data is returned via the + * struct ieee802154_maccb_s->conf_get callback. + * + ****************************************************************************/ + +int mac802154_req_get(MACHANDLE mac, enum ieee802154_pib_attr_e attr); + +/**************************************************************************** + * Name: mac802154_req_gts + * + * Description: + * The MLME-GTS.request primitive allows a device to send a request to the PAN + * coordinator to allocate a new GTS or to deallocate an existing GTS. + * Confirmation is returned via the + * struct ieee802154_maccb_s->conf_gts callback. + * + ****************************************************************************/ + +int mac802154_req_gts(MACHANDLE mac, FAR uint8_t *characteristics); + +/**************************************************************************** + * Name: mac802154_req_reset + * + * Description: + * The MLME-RESET.request primitive allows the next higher layer to request + * that the MLME performs a reset operation. Confirmation is returned via + * the struct ieee802154_maccb_s->conf_reset callback. + * + ****************************************************************************/ + +int mac802154_req_reset(MACHANDLE mac, bool setdefaults); + +/**************************************************************************** + * Name: mac802154_req_rxenable + * + * Description: + * The MLME-RX-ENABLE.request primitive allows the next higher layer to + * request that the receiver is enable for a finite period of time. + * Confirmation is returned via the + * struct ieee802154_maccb_s->conf_rxenable callback. + * + ****************************************************************************/ + +int mac802154_req_rxenable(MACHANDLE mac, bool deferrable, int ontime, + int duration); + +/**************************************************************************** + * Name: mac802154_req_scan + * + * Description: + * The MLME-SCAN.request primitive is used to initiate a channel scan over a + * given list of channels. A device can use a channel scan to measure the + * energy on the channel, search for the coordinator with which it associated, + * or search for all coordinators transmitting beacon frames within the POS of + * the scanning device. Scan results are returned + * via MULTIPLE calls to the struct ieee802154_maccb_s->conf_scan callback. + * This is a difference with the official 802.15.4 specification, implemented + * here to save memory. + * + ****************************************************************************/ + +int mac802154_req_scan(MACHANDLE mac, uint8_t type, uint32_t channels, + int duration); + +/**************************************************************************** + * Name: mac802154_req_set + * + * Description: + * The MLME-SET.request primitive attempts to write the given value to the + * indicated MAC PIB attribute. Confirmation is returned via the + * struct ieee802154_maccb_s->conf_set callback. + * + ****************************************************************************/ + +int mac802154_req_set(MACHANDLE mac, int attribute, FAR uint8_t *value, + int valuelen); + +/**************************************************************************** + * Name: mac802154_req_start + * + * Description: + * The MLME-START.request primitive makes a request for the device to start + * using a new superframe configuration. Confirmation is returned + * via the struct ieee802154_maccb_s->conf_start callback. + * + ****************************************************************************/ + +int mac802154_req_start(MACHANDLE mac, uint16_t panid, int channel, + uint8_t bo, uint8_t fo, bool coord, bool batext, + bool realign); + +/**************************************************************************** + * Name: mac802154_req_sync + * + * Description: + * The MLME-SYNC.request primitive requests to synchronize with the + * coordinator by acquiring and, if specified, tracking its beacons. + * Confirmation is returned via the + * struct ieee802154_maccb_s->int_commstatus callback. TOCHECK. + * + ****************************************************************************/ + +int mac802154_req_sync(MACHANDLE mac, int channel, bool track); + +/**************************************************************************** + * Name: mac802154_req_poll + * + * Description: + * The MLME-POLL.request primitive prompts the device to request data from the + * coordinator. Confirmation is returned via the + * struct ieee802154_maccb_s->conf_poll callback, followed by a + * struct ieee802154_maccb_s->ind_data callback. + * + ****************************************************************************/ + +int mac802154_req_poll(MACHANDLE mac, FAR uint8_t *coordaddr); + +/**************************************************************************** + * Name: mac802154_rsp_associate + * + * Description: + * The MLME-ASSOCIATE.response primitive is used to initiate a response to an + * MLME-ASSOCIATE.indication primitive. + * + ****************************************************************************/ + +int mac802154_rsp_associate(MACHANDLE mac, uint8_t eadr, uint16_t saddr, + int status); + +/**************************************************************************** + * Name: mac802154_rsp_orphan + * + * Description: + * The MLME-ORPHAN.response primitive allows the next higher layer of a + * coordinator to respond to the MLME-ORPHAN.indication primitive. + * + ****************************************************************************/ + +int mac802154_rsp_orphan(MACHANDLE mac, FAR uint8_t *orphanaddr, + uint16_t saddr, bool associated); + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* __WIRELESS_IEEE802154__MAC802154_H */ diff --git a/wireless/ieee802154/mac802154_device.c b/wireless/ieee802154/mac802154_device.c index fde4cab707d..059514c5d80 100644 --- a/wireless/ieee802154/mac802154_device.c +++ b/wireless/ieee802154/mac802154_device.c @@ -51,6 +51,8 @@ #include +#include "mac802154.h" + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ diff --git a/wireless/ieee802154/mac802154_loopback.c b/wireless/ieee802154/mac802154_loopback.c index 71255f0d604..b3c0c4cdf5b 100644 --- a/wireless/ieee802154/mac802154_loopback.c +++ b/wireless/ieee802154/mac802154_loopback.c @@ -56,6 +56,8 @@ #include #include +#include "mac802154.h" + #ifdef CONFIG_IEEE802154_LOOPBACK /**************************************************************************** diff --git a/wireless/ieee802154/mac802154_netdev.c b/wireless/ieee802154/mac802154_netdev.c index 1f5e68729f5..6cbb6d58404 100644 --- a/wireless/ieee802154/mac802154_netdev.c +++ b/wireless/ieee802154/mac802154_netdev.c @@ -60,6 +60,8 @@ #include #include +#include "mac802154.h" + #ifdef CONFIG_NET_6LOWPAN /**************************************************************************** From beee02843ae8f98a68059d623f41160d2e877963 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 14 Apr 2017 12:05:28 -0600 Subject: [PATCH 065/183] wireless/ieee802154: Fix some easy compilation problems introduced with header file changes. --- .../clicker2-stm32/mrf24j40-radio/defconfig | 35 ++++++++++++++----- .../wireless/ieee802154/ieee802154_mac.h | 4 +-- .../wireless/ieee802154/ieee802154_radio.h | 20 ++--------- wireless/ieee802154/mac802154.c | 13 +++++-- wireless/ieee802154/mac802154.h | 4 +-- 5 files changed, 43 insertions(+), 33 deletions(-) diff --git a/configs/clicker2-stm32/mrf24j40-radio/defconfig b/configs/clicker2-stm32/mrf24j40-radio/defconfig index db009c3ed3b..33284b022cd 100644 --- a/configs/clicker2-stm32/mrf24j40-radio/defconfig +++ b/configs/clicker2-stm32/mrf24j40-radio/defconfig @@ -373,9 +373,13 @@ CONFIG_STM32_HAVE_ADC3=y # CONFIG_STM32_HAVE_SDADC3_DMA is not set CONFIG_STM32_HAVE_CAN1=y CONFIG_STM32_HAVE_CAN2=y +# CONFIG_STM32_HAVE_COMP1 is not set # CONFIG_STM32_HAVE_COMP2 is not set +# CONFIG_STM32_HAVE_COMP3 is not set # CONFIG_STM32_HAVE_COMP4 is not set +# CONFIG_STM32_HAVE_COMP5 is not set # CONFIG_STM32_HAVE_COMP6 is not set +# CONFIG_STM32_HAVE_COMP7 is not set CONFIG_STM32_HAVE_DAC1=y CONFIG_STM32_HAVE_DAC2=y CONFIG_STM32_HAVE_RNG=y @@ -389,7 +393,10 @@ CONFIG_STM32_HAVE_SPI3=y # CONFIG_STM32_HAVE_SPI6 is not set # CONFIG_STM32_HAVE_SAIPLL is not set # CONFIG_STM32_HAVE_I2SPLL is not set -# CONFIG_STM32_HAVE_OPAMP is not set +# CONFIG_STM32_HAVE_OPAMP1 is not set +# CONFIG_STM32_HAVE_OPAMP2 is not set +# CONFIG_STM32_HAVE_OPAMP3 is not set +# CONFIG_STM32_HAVE_OPAMP4 is not set # CONFIG_STM32_ADC1 is not set # CONFIG_STM32_ADC2 is not set # CONFIG_STM32_ADC3 is not set @@ -410,6 +417,7 @@ CONFIG_STM32_HAVE_SPI3=y # CONFIG_STM32_I2C1 is not set # CONFIG_STM32_I2C2 is not set # CONFIG_STM32_I2C3 is not set +# CONFIG_STM32_OPAMP is not set # CONFIG_STM32_OTGFS is not set # CONFIG_STM32_OTGHS is not set CONFIG_STM32_PWR=y @@ -660,7 +668,10 @@ CONFIG_SCHED_WAITPID=y # # Pthread Options # -# CONFIG_MUTEX_TYPES is not set +# CONFIG_PTHREAD_MUTEX_TYPES is not set +CONFIG_PTHREAD_MUTEX_ROBUST=y +# CONFIG_PTHREAD_MUTEX_UNSAFE is not set +# CONFIG_PTHREAD_MUTEX_BOTH is not set CONFIG_NPTHREAD_KEYS=4 # CONFIG_PTHREAD_CLEANUP is not set # CONFIG_CANCELLATION_POINTS is not set @@ -856,6 +867,7 @@ CONFIG_USART3_2STOP=0 # CONFIG_PSEUDOTERM is not set # CONFIG_USBDEV is not set # CONFIG_USBHOST is not set +# CONFIG_USBMISC is not set # CONFIG_HAVE_USBTRACE is not set CONFIG_DRIVERS_WIRELESS=y # CONFIG_WL_CC1101 is not set @@ -950,6 +962,7 @@ CONFIG_MM_REGIONS=1 CONFIG_WIRELESS=y CONFIG_WIRELESS_IEEE802154=y CONFIG_IEEE802154_MAC=y +# CONFIG_IEEE802154_MAC_DEV is not set CONFIG_IEEE802154_DEV=y # @@ -1177,13 +1190,6 @@ CONFIG_EXAMPLES_NSH_CXXINITIALIZE=y # CONFIG_TIFF is not set # CONFIG_GRAPHICS_TRAVELER is not set -# -# IEEE 802.15.4 applications -# -CONFIG_IEEE802154_COMMON=y -CONFIG_IEEE802154_COORD=y -CONFIG_IEEE802154_I8SAK=y - # # Interpreters # @@ -1336,3 +1342,14 @@ CONFIG_READLINE_ECHO=y # CONFIG_SYSTEM_UBLOXMODEM is not set # CONFIG_SYSTEM_VI is not set # CONFIG_SYSTEM_ZMODEM is not set + +# +# Wireless Libraries and NSH Add-Ons +# + +# +# IEEE 802.15.4 applications +# +CONFIG_IEEE802154_COMMON=y +CONFIG_IEEE802154_COORD=y +CONFIG_IEEE802154_I8SAK=y diff --git a/include/nuttx/wireless/ieee802154/ieee802154_mac.h b/include/nuttx/wireless/ieee802154/ieee802154_mac.h index 8bef67a14d4..6ad8158c806 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_mac.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_mac.h @@ -851,9 +851,9 @@ struct ieee802154_pollreq_s union ieee802154_macarg_u { struct ieee802154_assoc_req_s assocreq; /* MAC802154IOC_MLME_ASSOC_REQUEST */ - struct ieee802154_assocresp_s assocresp: /* MAC802154IOC_MLME_ASSOC_RESPONSE */ + struct ieee802154_assocresp_s assocresp; /* MAC802154IOC_MLME_ASSOC_RESPONSE */ struct ieee802154_disassoc_req_s disassocreq; /* MAC802154IOC_MLME_DISASSOC_REQUEST */ - struct ieee802154_mlmereq_s getreq; /* MAC802154IOC_MLME_GET_REQUEST */ + struct ieee802154_getreq_s getreq; /* MAC802154IOC_MLME_GET_REQUEST */ struct ieee802154_gtsreq_s gtsreq; /* MAC802154IOC_MLME_GTS_REQUEST */ struct ieee802154_orphanresp_s orphanresp; /* MAC802154IOC_MLME_ORPHAN_RESPONSE */ struct ieee802154_resetreq_s resetreq; /* MAC802154IOC_MLME_RESET_REQUEST */ diff --git a/include/nuttx/wireless/ieee802154/ieee802154_radio.h b/include/nuttx/wireless/ieee802154/ieee802154_radio.h index 5bee1e3d52d..eef94e328f4 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_radio.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_radio.h @@ -138,7 +138,7 @@ union ieee802154_radioarg_u bool promisc; /* PHY802154IOC_GET/SET_EADDR */ uint8_t devmode; /* PHY802154IOC_GET/SET_DEVMODE */ int32_t txpwr; /* PHY802154IOC_GET/SET_TXPWR */ - bool energy /* PHY802154IOC_ENERGYDETECT */ + bool energy; /* PHY802154IOC_ENERGYDETECT */ struct ieee802154_cca_s cca; /* PHY802154IOC_GET/SET_CCA */ }; @@ -158,23 +158,7 @@ struct ieee802154_netradio_s /* IEEE802.15.4 Radio Interface Operations **********************************/ -struct ieee802154_cca_s -{ - uint8_t use_ed : 1; /* CCA using ED */ - uint8_t use_cs : 1; /* CCA using carrier sense */ - uint8_t edth; /* Energy detection threshold for CCA */ - uint8_t csth; /* Carrier sense threshold for CCA */ -}; - -struct ieee802154_packet_s -{ - uint8_t len; - uint8_t data[127]; - uint8_t lqi; - uint8_t rssi; -}; - -struct ieee802154_radio_s; +struct ieee802154_radio_s; /* Forward reference */ struct ieee802154_radioops_s { diff --git a/wireless/ieee802154/mac802154.c b/wireless/ieee802154/mac802154.c index 5dcb8b7fee5..e8f046f2849 100644 --- a/wireless/ieee802154/mac802154.c +++ b/wireless/ieee802154/mac802154.c @@ -45,6 +45,7 @@ #include #include +#include #include #include "mac802154.h" @@ -271,6 +272,8 @@ int mac802154_ioctl(MACHANDLE mac, int cmd, unsigned long arg) (FAR struct ieee802154_privmac_s *)mac; int ret = -EINVAL; + DEBUGASSERT(priv != NULL); + /* Check for IOCTLs aimed at the IEEE802.15.4 MAC layer */ if (_MAC802154IOCVALID(cmd)) @@ -283,8 +286,14 @@ int mac802154_ioctl(MACHANDLE mac, int cmd, unsigned long arg) else { - ret = priv->radio->ioctl(priv->radio, cmd, arg); + DEBUGASSERT(priv->radio != NULL && + priv->radio->ops != NULL && + priv->radio->ops->ioctl != NULL); + + ret = priv->radio->ops->ioctl(priv->radio, cmd, arg); } + + return ret; } /**************************************************************************** @@ -334,7 +343,7 @@ int mac802154_req_purge(MACHANDLE mac, uint8_t handle) * ****************************************************************************/ -int mac802154_req_associate(MACHANDLE mac +int mac802154_req_associate(MACHANDLE mac, FAR struct ieee802154_assoc_req_s *req) { FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; diff --git a/wireless/ieee802154/mac802154.h b/wireless/ieee802154/mac802154.h index 696977259fd..8321e905ea9 100644 --- a/wireless/ieee802154/mac802154.h +++ b/wireless/ieee802154/mac802154.h @@ -52,7 +52,7 @@ #include #include -#include +#include /**************************************************************************** * Public Function Prototypes @@ -132,7 +132,7 @@ int mac802154_req_purge(MACHANDLE mac, uint8_t handle); * ****************************************************************************/ -int mac802154_req_associate(MACHANDLE mac +int mac802154_req_associate(MACHANDLE mac, FAR struct ieee802154_assoc_req_s *req); /**************************************************************************** From 0c4ff5e60b110925754e58b9f4938df84b6490bb Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 14 Apr 2017 12:59:49 -0600 Subject: [PATCH 066/183] wireless/ieee802154: Add radio IOCTL helpers --- wireless/ieee802154/Make.defs | 2 +- wireless/ieee802154/mac802154_device.c | 2 +- wireless/ieee802154/radio802154_device.c | 2 +- wireless/ieee802154/radio802154_ioctl.c | 487 +++++++++++++++++++++++ wireless/ieee802154/radio802154_ioctl.h | 255 ++++++++++++ 5 files changed, 745 insertions(+), 3 deletions(-) create mode 100644 wireless/ieee802154/radio802154_ioctl.c create mode 100644 wireless/ieee802154/radio802154_ioctl.h diff --git a/wireless/ieee802154/Make.defs b/wireless/ieee802154/Make.defs index 8a0466eb825..a2ec823d3b0 100644 --- a/wireless/ieee802154/Make.defs +++ b/wireless/ieee802154/Make.defs @@ -37,7 +37,7 @@ ifeq ($(CONFIG_WIRELESS_IEEE802154),y) # Include IEEE 802.15.4 support -CSRCS = +CSRCS = radio802154_ioctl.c # Include wireless devices build support diff --git a/wireless/ieee802154/mac802154_device.c b/wireless/ieee802154/mac802154_device.c index 059514c5d80..f4973d0a472 100644 --- a/wireless/ieee802154/mac802154_device.c +++ b/wireless/ieee802154/mac802154_device.c @@ -1,5 +1,5 @@ /**************************************************************************** - * drivers/ieee802154/mac802154_device.c + * wireless/ieee802154/mac802154_device.c * * Copyright (C) 2017 Verge Inc. All rights reserved. * Author: Anthony Merlino diff --git a/wireless/ieee802154/radio802154_device.c b/wireless/ieee802154/radio802154_device.c index a3a4161ffc7..b58c0a6f971 100644 --- a/wireless/ieee802154/radio802154_device.c +++ b/wireless/ieee802154/radio802154_device.c @@ -1,5 +1,5 @@ /**************************************************************************** - * drivers/ieee802154/radio802154_device.c + * wireless/ieee802154/radio802154_device.c * * Copyright (C) 2014-2015 Gregory Nutt. All rights reserved. * Copyright (C) 2014-2015 Sebastien Lorquet. All rights reserved. diff --git a/wireless/ieee802154/radio802154_ioctl.c b/wireless/ieee802154/radio802154_ioctl.c new file mode 100644 index 00000000000..d86366c9872 --- /dev/null +++ b/wireless/ieee802154/radio802154_ioctl.c @@ -0,0 +1,487 @@ +/**************************************************************************** + * wireless/ieee802154/radio802154_ioctl.c + * + * Copyright (C) 2017 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define RADIO_IOCTL(r,c,a) \ + (r)->ops->ioctl((r),(c),(unsigned long)((uintptr_t)(a))) + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: radio802154_setchannel + * + * Description: + * Define the current radio channel the device is operating on. + * In the 2.4 GHz, there are 16 channels, each 2 MHz wide, 5 MHz spacing: + * Chan MHz Chan MHz Chan MHz Chan MHz + * 11 2405 15 2425 19 2445 23 2465 + * 12 2410 16 2430 20 2450 24 2470 + * 13 2415 17 2435 21 2455 25 2475 + * 14 2420 18 2440 22 2460 26 2480 + * + ****************************************************************************/ + +int radio802154_setchannel(FAR struct ieee802154_radio_s *radio, + uint8_t chan) +{ + union ieee802154_radioarg_u arg; + int ret; + + arg.channel = chan; + + ret = RADIO_IOCTL(radio, PHY802154IOC_SET_CHAN, &arg); + if (ret < 0) + { + wlerr("ERROR: PHY802154IOC_SET_CHAN failed: %d\n", ret); + } + + return ret; +} + +/**************************************************************************** + * Name: radio802154_getchannel + * + * Description: + * Define the current radio channel the device is operating on. + * + ****************************************************************************/ + +int radio802154_getchannel(FAR struct ieee802154_radio_s *radio, + FAR uint8_t *chan) +{ + union ieee802154_radioarg_u arg; + int ret; + + ret = RADIO_IOCTL(radio, PHY802154IOC_GET_CHAN, &arg); + if (ret < 0) + { + wlerr("ERROR: PHY802154IOC_GET_CHAN failed: %d\n", ret); + } + + *chan = arg.channel; + return ret; +} + +/**************************************************************************** + * Name: radio802154_setpanid + * + * Description: + * Define the PAN ID the device is operating on. + * + ****************************************************************************/ + +int radio802154_setpanid(FAR struct ieee802154_radio_s *radio, + uint16_t panid) +{ + union ieee802154_radioarg_u arg; + int ret; + + arg.panid = panid; + + ret = RADIO_IOCTL(radio, PHY802154IOC_SET_PANID, &arg); + if (ret < 0) + { + wlerr("ERROR: PHY802154IOC_SET_PANID failed: %d\n", ret); + } + + return ret; +} + +/**************************************************************************** + * Name: radio802154_getpanid + * + * Description: + * Define the current PAN ID the device is operating on. + * + ****************************************************************************/ + +int radio802154_getpanid(FAR struct ieee802154_radio_s *radio, + FAR uint16_t *panid) +{ + union ieee802154_radioarg_u arg; + int ret; + + ret = RADIO_IOCTL(radio, PHY802154IOC_GET_PANID, &arg); + if (ret < 0) + { + wlerr("ERROR: PHY802154IOC_GET_PANID failed: %d\n", ret); + } + + *panid = arg.panid; + return ret; +} + +/**************************************************************************** + * Name: radio802154_setsaddr + * + * Description: + * Define the device short address. The following addresses are special: + * FFFEh : Broadcast + * FFFFh : Unspecified + * + ****************************************************************************/ + +int radio802154_setsaddr(FAR struct ieee802154_radio_s *radio, + uint16_t saddr) +{ + union ieee802154_radioarg_u arg; + int ret; + + arg.saddr = saddr; + + ret = RADIO_IOCTL(radio, PHY802154IOC_SET_SADDR, &arg); + if (ret < 0) + { + wlerr("ERROR: PHY802154IOC_SET_SADDR failed: %d\n", ret); + } + + return ret; +} + +/**************************************************************************** + * Name: radio802154_getsaddr + * + * Description: + * Define the current short address the device is using. + * + ****************************************************************************/ + +int radio802154_getsaddr(FAR struct ieee802154_radio_s *radio, + FAR uint16_t *saddr) +{ + union ieee802154_radioarg_u arg; + int ret; + + ret = RADIO_IOCTL(radio, PHY802154IOC_GET_SADDR, &arg); + if (ret < 0) + { + wlerr("ERROR: PHY802154IOC_GET_SADDR failed: %d\n", ret); + } + + *saddr = arg.saddr; + return ret; +} + +/**************************************************************************** + * Name: radio802154_seteaddr + * + * Description: + * Define the device extended address. The following addresses are special: + * FFFFFFFFFFFFFFFFh : Unspecified + * + ****************************************************************************/ + +int radio802154_seteaddr(FAR struct ieee802154_radio_s *radio, + FAR uint8_t *eaddr) +{ + union ieee802154_radioarg_u arg; + int ret; + + memcpy(arg.eaddr, eaddr, EADDR_SIZE); /* REVISIT */ + + ret = RADIO_IOCTL(radio, PHY802154IOC_SET_EADDR, &arg); + if (ret < 0) + { + wlerr("ERROR: PHY802154IOC_SET_EADDR failed: %d\n", ret); + } + + return ret; +} + +/**************************************************************************** + * Name: radio802154_geteaddr + * + * Description: + * Define the current extended address the device is using. + * + ****************************************************************************/ + +int radio802154_geteaddr(FAR struct ieee802154_radio_s *radio, + FAR uint8_t *eaddr) +{ + union ieee802154_radioarg_u arg; + int ret; + + ret = RADIO_IOCTL(radio, PHY802154IOC_GET_EADDR, &arg); + if (ret < 0) + { + wlerr("ERROR: PHY802154IOC_GET_EADDR failed: %d\n", ret); + } + + memcpy(eaddr, arg.eaddr, EADDR_SIZE); /* REVISIT */ + return ret; +} + +/**************************************************************************** + * Name: radio802154_setpromisc + * + * Description: + * Set the device into promiscuous mode, e.g do not filter any incoming + * frame. + * + ****************************************************************************/ + +int radio802154_setpromisc(FAR struct ieee802154_radio_s *radio, + bool promisc) +{ + union ieee802154_radioarg_u arg; + int ret; + + arg.promisc = promisc; + + ret = RADIO_IOCTL(radio, PHY802154IOC_SET_PROMISC, &arg); + if (ret < 0) + { + wlerr("ERROR: PHY802154IOC_SET_PROMISC failed: %d\n", ret); + } + + return ret; +} + +/**************************************************************************** + * Name: radio802154_getpromisc + * + * Description: + * Get the device receive mode. + * + ****************************************************************************/ + +int radio802154_getpromisc(FAR struct ieee802154_radio_s *radio, + FAR bool *promisc) +{ + union ieee802154_radioarg_u arg; + int ret; + + ret = RADIO_IOCTL(radio, PHY802154IOC_GET_PROMISC, &arg); + if (ret < 0) + { + wlerr("ERROR: PHY802154IOC_GET_PROMISC failed: %d\n", ret); + } + + *promisc = arg.promisc; + return ret; +} + +/**************************************************************************** + * Name: radio802154_setdevmode + * + * Description: + * Define the device behaviour: normal end device or coordinator + * + ****************************************************************************/ + +int radio802154_setdevmode(FAR struct ieee802154_radio_s *radio, + uint8_t mode) +{ + union ieee802154_radioarg_u arg; + int ret; + + arg.devmode = mode; + + ret = RADIO_IOCTL(radio, PHY802154IOC_SET_DEVMODE, &arg); + if (ret < 0) + { + wlerr("ERROR: PHY802154IOC_SET_DEVMODE failed: %d\n", ret); + } + + return ret; +} + +/**************************************************************************** + * Name: radio802154_setdevmode + * + * Description: + * Return the current device mode + * + ****************************************************************************/ + +int radio802154_getdevmode(FAR struct ieee802154_radio_s *radio, + FAR uint8_t *mode) +{ + union ieee802154_radioarg_u arg; + int ret; + + ret = RADIO_IOCTL(radio, PHY802154IOC_GET_DEVMODE, &arg); + if (ret < 0) + { + wlerr("ERROR: PHY802154IOC_GET_DEVMODE failed: %d\n", ret); + } + + *mode = arg.devmode; + return ret; +} + +/**************************************************************************** + * Name: radio802154_settxpower + * + * Description: + * Define the transmit power. Value is passed in mBm, it is rounded to + * the nearest value. Some MRF modules have a power amplifier, this routine + * does not care about this. We only change the CHIP output power. + * + ****************************************************************************/ + +int radio802154_settxpower(FAR struct ieee802154_radio_s *radio, + int32_t txpwr) +{ + union ieee802154_radioarg_u arg; + int ret; + + arg.txpwr = txpwr; + + ret = RADIO_IOCTL(radio, PHY802154IOC_SET_TXPWR, &arg); + if (ret < 0) + { + wlerr("ERROR: PHY802154IOC_SET_TXPWR failed: %d\n", ret); + } + + return ret; +} + +/**************************************************************************** + * Name: radio802154_gettxpower + * + * Description: + * Return the actual transmit power, in mBm. + * + ****************************************************************************/ + +int radio802154_gettxpower(FAR struct ieee802154_radio_s *radio, + FAR int32_t *txpwr) +{ + union ieee802154_radioarg_u arg; + int ret; + + ret = RADIO_IOCTL(radio, PHY802154IOC_GET_TXPWR, &arg); + if (ret < 0) + { + wlerr("ERROR: PHY802154IOC_GET_TXPWR failed: %d\n", ret); + } + + *txpwr = arg.txpwr; + return ret; +} + +/**************************************************************************** + * Name: radio802154_setcca + * + * Description: + * Define the Clear Channel Assessement method. + * + ****************************************************************************/ + +int radio802154_setcca(FAR struct ieee802154_radio_s *radio, + FAR struct ieee802154_cca_s *cca) +{ + union ieee802154_radioarg_u arg; + int ret; + + memcpy(&arg.cca, cca, sizeof(struct ieee802154_cca_s)); + + ret = RADIO_IOCTL(radio, PHY802154IOC_SET_CCA, &arg); + if (ret < 0) + { + wlerr("ERROR: PHY802154IOC_SET_CCA failed: %d\n", ret); + } + + return ret; +} + +/**************************************************************************** + * Name: radio802154_getcca + * + * Description: + * Return the Clear Channel Assessement method. + * + ****************************************************************************/ + +int radio802154_getcca(FAR struct ieee802154_radio_s *radio, + FAR struct ieee802154_cca_s *cca) +{ + union ieee802154_radioarg_u arg; + int ret; + + ret = RADIO_IOCTL(radio, PHY802154IOC_GET_CCA, &arg); + if (ret < 0) + { + wlerr("ERROR: PHY802154IOC_GET_CCA failed: %d\n", ret); + } + + memcpy(cca, &arg.cca, sizeof(struct ieee802154_cca_s)); + return ret; +} + +/**************************************************************************** + * Name: radio802154_energydetect + * + * Description: + * Measure the RSSI level for the current channel. + * + ****************************************************************************/ + +int radio802154_energydetect(FAR struct ieee802154_radio_s *radio, + FAR uint8_t *energy) + +{ + union ieee802154_radioarg_u arg; + int ret; + + ret = RADIO_IOCTL(radio, PHY802154IOC_ENERGYDETECT, &arg); + if (ret < 0) + { + wlerr("ERROR: PHY802154IOC_ENERGYDETECT failed: %d\n", ret); + } + + *energy = arg.energy; + return ret; +} diff --git a/wireless/ieee802154/radio802154_ioctl.h b/wireless/ieee802154/radio802154_ioctl.h new file mode 100644 index 00000000000..d09ad57103e --- /dev/null +++ b/wireless/ieee802154/radio802154_ioctl.h @@ -0,0 +1,255 @@ +/**************************************************************************** + * wireless/ieee802154/radio802154_ioctl.h + * + * Copyright (C) 2017 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __WIRELESS_IEEE802154_RADIO802154_IOCTL_H +#define __WIRELESS_IEEE802154_RADIO802154_IOCTL_H 1 + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +#include "radio802154_ioctl.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: radio802154_setchannel + * + * Description: + * Define the current radio channel the device is operating on. + * In the 2.4 GHz, there are 16 channels, each 2 MHz wide, 5 MHz spacing: + * Chan MHz Chan MHz Chan MHz Chan MHz + * 11 2405 15 2425 19 2445 23 2465 + * 12 2410 16 2430 20 2450 24 2470 + * 13 2415 17 2435 21 2455 25 2475 + * 14 2420 18 2440 22 2460 26 2480 + * + ****************************************************************************/ + +int radio802154_setchannel(FAR struct ieee802154_radio_s *radio, + uint8_t chan); + +/**************************************************************************** + * Name: radio802154_getchannel + * + * Description: + * Define the current radio channel the device is operating on. + * + ****************************************************************************/ + +int radio802154_getchannel(FAR struct ieee802154_radio_s *radio, + FAR uint8_t *chan); + +/**************************************************************************** + * Name: radio802154_setpanid + * + * Description: + * Define the PAN ID the device is operating on. + * + ****************************************************************************/ + +int radio802154_setpanid(FAR struct ieee802154_radio_s *radio, + uint16_t panid); + +/**************************************************************************** + * Name: radio802154_getpanid + * + * Description: + * Define the current PAN ID the device is operating on. + * + ****************************************************************************/ + +int radio802154_getpanid(FAR struct ieee802154_radio_s *radio, + FAR uint16_t *panid); + +/**************************************************************************** + * Name: radio802154_setsaddr + * + * Description: + * Define the device short address. The following addresses are special: + * FFFEh : Broadcast + * FFFFh : Unspecified + * + ****************************************************************************/ + +int radio802154_setsaddr(FAR struct ieee802154_radio_s *radio, + uint16_t saddr); + +/**************************************************************************** + * Name: radio802154_getsaddr + * + * Description: + * Define the current short address the device is using. + * + ****************************************************************************/ + +int radio802154_getsaddr(FAR struct ieee802154_radio_s *radio, + FAR uint16_t *saddr); + +/**************************************************************************** + * Name: radio802154_seteaddr + * + * Description: + * Define the device extended address. The following addresses are special: + * FFFFFFFFFFFFFFFFh : Unspecified + * + ****************************************************************************/ + +int radio802154_seteaddr(FAR struct ieee802154_radio_s *radio, + FAR uint8_t *eaddr); + +/**************************************************************************** + * Name: radio802154_geteaddr + * + * Description: + * Define the current extended address the device is using. + * + ****************************************************************************/ + +int radio802154_geteaddr(FAR struct ieee802154_radio_s *radio, + FAR uint8_t *eaddr); + +/**************************************************************************** + * Name: radio802154_setpromisc + * + * Description: + * Set the device into promiscuous mode, e.g do not filter any incoming + * frame. + * + ****************************************************************************/ + +int radio802154_setpromisc(FAR struct ieee802154_radio_s *radio, + bool promisc); + +/**************************************************************************** + * Name: radio802154_getpromisc + * + * Description: + * Get the device receive mode. + * + ****************************************************************************/ + +int radio802154_getpromisc(FAR struct ieee802154_radio_s *radio, + FAR bool *promisc); + +/**************************************************************************** + * Name: radio802154_setdevmode + * + * Description: + * Define the device behaviour: normal end device or coordinator + * + ****************************************************************************/ + +int radio802154_setdevmode(FAR struct ieee802154_radio_s *radio, + uint8_t mode); + +/**************************************************************************** + * Name: radio802154_setdevmode + * + * Description: + * Return the current device mode + * + ****************************************************************************/ + +int radio802154_getdevmode(FAR struct ieee802154_radio_s *radio, + FAR uint8_t *mode); + +/**************************************************************************** + * Name: radio802154_settxpower + * + * Description: + * Define the transmit power. Value is passed in mBm, it is rounded to + * the nearest value. Some MRF modules have a power amplifier, this routine + * does not care about this. We only change the CHIP output power. + * + ****************************************************************************/ + +int radio802154_settxpower(FAR struct ieee802154_radio_s *radio, + int32_t txpwr); + +/**************************************************************************** + * Name: radio802154_gettxpower + * + * Description: + * Return the actual transmit power, in mBm. + * + ****************************************************************************/ + +int radio802154_gettxpower(FAR struct ieee802154_radio_s *radio, + FAR int32_t *txpwr); + +/**************************************************************************** + * Name: radio802154_setcca + * + * Description: + * Define the Clear Channel Assessement method. + * + ****************************************************************************/ + +int radio802154_setcca(FAR struct ieee802154_radio_s *radio, + FAR struct ieee802154_cca_s *cca); + +/**************************************************************************** + * Name: radio802154_getcca + * + * Description: + * Return the Clear Channel Assessement method. + * + ****************************************************************************/ + +int radio802154_getcca(FAR struct ieee802154_radio_s *radio, + FAR struct ieee802154_cca_s *cca); + +/**************************************************************************** + * Name: radio802154_energydetect + * + * Description: + * Measure the RSSI level for the current channel. + * + ****************************************************************************/ + +int radio802154_energydetect(FAR struct ieee802154_radio_s *radio, + FAR uint8_t *energy); + +#endif /* __WIRELESS_IEEE802154_RADIO802154_IOCTL_H */ From 92c83489ba1142129c910a5987afece88e79d56e Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 14 Apr 2017 13:04:24 -0600 Subject: [PATCH 067/183] radio802154_device.c now accesses the PHY layer via the IOCTL helper functions. --- wireless/ieee802154/radio802154_device.c | 36 +++++++++++++----------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/wireless/ieee802154/radio802154_device.c b/wireless/ieee802154/radio802154_device.c index b58c0a6f971..ac76283c7d7 100644 --- a/wireless/ieee802154/radio802154_device.c +++ b/wireless/ieee802154/radio802154_device.c @@ -52,6 +52,8 @@ #include #include +#include "radio802154_ioctl.h" + /**************************************************************************** * Private Types ****************************************************************************/ @@ -390,71 +392,71 @@ static int radio802154dev_ioctl(FAR struct file *filep, int cmd, switch (cmd) { case PHY802154IOC_SET_CHAN: - ret = child->ops->setchannel(child, (uint8_t)arg); + ret = radio802154_setchannel(child, (uint8_t)arg); break; case PHY802154IOC_GET_CHAN: - ret = child->ops->getchannel(child, (FAR uint8_t*)arg); + ret = radio802154_getchannel(child, (FAR uint8_t*)arg); break; case PHY802154IOC_SET_PANID: - ret = child->ops->setpanid(child, (uint16_t)arg); + ret = radio802154_setpanid(child, (uint16_t)arg); break; case PHY802154IOC_GET_PANID: - ret = child->ops->getpanid(child, (FAR uint16_t*)arg); + ret = radio802154_getpanid(child, (FAR uint16_t*)arg); break; case PHY802154IOC_SET_SADDR: - ret = child->ops->setsaddr(child, (uint16_t)arg); + ret = radio802154_setsaddr(child, (uint16_t)arg); break; case PHY802154IOC_GET_SADDR: - ret = child->ops->getsaddr(child, (FAR uint16_t*)arg); + ret = radio802154_getsaddr(child, (FAR uint16_t*)arg); break; case PHY802154IOC_SET_EADDR: - ret = child->ops->seteaddr(child, (FAR uint8_t*)arg); + ret = radio802154_seteaddr(child, (FAR uint8_t*)arg); break; case PHY802154IOC_GET_EADDR: - ret = child->ops->geteaddr(child, (FAR uint8_t*)arg); + ret = radio802154_geteaddr(child, (FAR uint8_t*)arg); break; case PHY802154IOC_SET_PROMISC: - ret = child->ops->setpromisc(child, (bool)arg); + ret = radio802154_setpromisc(child, (bool)arg); break; case PHY802154IOC_GET_PROMISC: - ret = child->ops->getpromisc(child, (FAR bool*)arg); + ret = radio802154_getpromisc(child, (FAR bool*)arg); break; case PHY802154IOC_SET_DEVMODE: - ret = child->ops->setdevmode(child, (uint8_t)arg); + ret = radio802154_setdevmode(child, (uint8_t)arg); break; case PHY802154IOC_GET_DEVMODE: - ret = child->ops->getdevmode(child, (FAR uint8_t*)arg); + ret = radio802154_getdevmode(child, (FAR uint8_t*)arg); break; case PHY802154IOC_SET_TXPWR: - ret = child->ops->settxpower(child, (int32_t)arg); + ret = radio802154_settxpower(child, (int32_t)arg); break; case PHY802154IOC_GET_TXPWR: - ret = child->ops->gettxpower(child, (FAR int32_t*)arg); + ret = radio802154_gettxpower(child, (FAR int32_t*)arg); break; case PHY802154IOC_SET_CCA: - ret = child->ops->setcca(child, (FAR struct ieee802154_cca_s*)arg); + ret = radio802154_setcca(child, (FAR struct ieee802154_cca_s*)arg); break; case PHY802154IOC_GET_CCA: - ret = child->ops->getcca(child, (FAR struct ieee802154_cca_s*)arg); + ret = radio802154_getcca(child, (FAR struct ieee802154_cca_s*)arg); break; case PHY802154IOC_ENERGYDETECT: - ret = child->ops->energydetect(child, (FAR uint8_t*)arg); + ret = radio802154_energydetect(child, (FAR uint8_t*)arg); break; default: From a8706d8afaa01b9eb723662f9db6c7acea72dbca Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 14 Apr 2017 13:58:25 -0600 Subject: [PATCH 068/183] wireless/ieee802154: Correct a few more compile issues. --- wireless/ieee802154/mac802154_device.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/wireless/ieee802154/mac802154_device.c b/wireless/ieee802154/mac802154_device.c index f4973d0a472..18d88cf9b38 100644 --- a/wireless/ieee802154/mac802154_device.c +++ b/wireless/ieee802154/mac802154_device.c @@ -377,6 +377,7 @@ static ssize_t mac802154dev_write(FAR struct file *filep, FAR struct inode *inode; FAR struct mac802154_devwrapper_s *dev; FAR struct ieee802154_data_req_s *req; + FAR struct ieee802154_frame_s *frame; struct mac802154dev_dwait_s dwait; int ret; @@ -396,7 +397,7 @@ static ssize_t mac802154dev_write(FAR struct file *filep, } DEBUGASSERT(buffer != NULL); - frame = *(FAR struct ieee802154_frame_s *)buffer; + frame = (FAR struct ieee802154_frame_s *)buffer; /* Get exclusive access to the driver structure */ @@ -414,11 +415,11 @@ static ssize_t mac802154dev_write(FAR struct file *filep, /* Link the wait struct */ dwait.mw_flink = dev->md_dwait; - dev->md_wait = &dwait; + dev->md_dwait = &dwait; /* Pass the request to the MAC layer */ - ret = dev->md_mac->ops.req_data(dev->md_mac, req); + ret = mac802154_req_data(dev->md_mac, req); mac802154dev_givesem(&dev->md_exclsem); @@ -430,7 +431,7 @@ static ssize_t mac802154dev_write(FAR struct file *filep, /* Wait for the DATA.confirm callback to be called for our handle */ - sem_wait(dwait.mw_sem); + sem_wait(&dwait.mw_sem); /* The unlinking of the wait struct happens inside the callback. This * is more efficient since it will already have to find the struct in @@ -506,7 +507,7 @@ void mac802154dev_conf_data(MACHANDLE mac, if (ret < 0) { wlerr("ERROR: mac802154dev_takesem failed: %d\n", ret); - return ret; + return; } /* Search to see if there is a dwait pending for this transaction */ From 2576f2b2b1eea5600bbe3c2a5684b6f7c66b1dfd Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 15 Apr 2017 09:11:52 -0600 Subject: [PATCH 069/183] net/: Add IOCTL support for forwarding IEEE802.15.4 MAC and PHY IOCTLs. --- net/netdev/netdev_ioctl.c | 74 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/net/netdev/netdev_ioctl.c b/net/netdev/netdev_ioctl.c index 1a845774fcd..5dc882fbc38 100644 --- a/net/netdev/netdev_ioctl.c +++ b/net/netdev/netdev_ioctl.c @@ -70,6 +70,10 @@ #ifdef CONFIG_NETDEV_WIRELESS_IOCTL # include +#ifdef CONFIG_NET_6LOWPAN +# include +# include +#endif #endif #include "arp/arp.h" @@ -349,6 +353,76 @@ static FAR struct net_driver_s *netdev_wifrdev(FAR struct iwreq *req) } #endif +/**************************************************************************** + * Name: netdev_iee802154_ioctl + * + * Description: + * Perform IEEE802.15.4 network device specific operations. + * + * Parameters: + * psock Socket structure + * dev Ethernet driver device structure + * cmd The ioctl command + * req The argument of the ioctl cmd + * + * Return: + * >=0 on success (positive non-zero values are cmd-specific) + * Negated errno returned on failure. + * + ****************************************************************************/ + +#if defined(CONFIG_NETDEV_IOCTL) && defined(CONFIG_NET_6LOWPAN) +static int netdev_iee802154_ioctl(FAR struct socket *psock, int cmd, + unsigned long arg) +{ + FAR struct net_driver_s *dev; + FAR char *ifname; + int ret = -ENOTTY; + + if (req != NULL) + { + /* Verify that this is either a valid IEEE802.15.4 radio IOCTL command + * or a valid IEEE802.15.4 MAC IOCTL command. + */ + + if (_PHY802154IOCVALID(cmd)) + { + /* Get the IEEE802.15.4 network device to receive the radio IOCTL + * commdand + */ + + FAR struct ieee802154_netradio_s *radio = + (FAR struct ieee802154_netradio_s *)((uintptr_t)arg); + + ifname = radio->ifr_name; + } + else if (_MAC802154IOCVALID(cmd)) + { + /* Get the IEEE802.15.4 MAC device to receive the radio IOCTL + * commdand + */ + + FAR struct ieee802154_netmac_s *netmac = + (FAR struct ieee802154_netmac_s *)((uintptr_t)arg); + + ifname = netmac->ifr_name; + } + else + { + /* The IOCTL command is neither */ + + return -ENOTTY; + } + + /* Perform the device IOCTL */ + + ret = dev->d_ioctl(dev, cmd, arg); + } + + return ret; +} +#endif + /**************************************************************************** * Name: netdev_wifrioctl * From 30db2835a182c2e8c687b023b348c16ee675fc56 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 15 Apr 2017 09:36:11 -0600 Subject: [PATCH 070/183] Trivial fix to spacing --- wireless/ieee802154/mac802154_netdev.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/wireless/ieee802154/mac802154_netdev.c b/wireless/ieee802154/mac802154_netdev.c index 6cbb6d58404..d27daf3ef33 100644 --- a/wireless/ieee802154/mac802154_netdev.c +++ b/wireless/ieee802154/mac802154_netdev.c @@ -1462,24 +1462,24 @@ int mac802154netdev_register(MACHANDLE mac) /* Initialize the driver structure */ dev = &ieee->md_dev.i_dev; - dev->d_buf = pktbuf; /* Single packet buffer */ - dev->d_ifup = macnet_ifup; /* I/F up (new IP address) callback */ - dev->d_ifdown = macnet_ifdown; /* I/F down callback */ - dev->d_txavail = macnet_txavail; /* New TX data callback */ + dev->d_buf = pktbuf; /* Single packet buffer */ + dev->d_ifup = macnet_ifup; /* I/F up (new IP address) callback */ + dev->d_ifdown = macnet_ifdown; /* I/F down callback */ + dev->d_txavail = macnet_txavail; /* New TX data callback */ #ifdef CONFIG_NET_IGMP - dev->d_addmac = macnet_addmac; /* Add multicast MAC address */ - dev->d_rmmac = macnet_rmmac; /* Remove multicast MAC address */ + dev->d_addmac = macnet_addmac; /* Add multicast MAC address */ + dev->d_rmmac = macnet_rmmac; /* Remove multicast MAC address */ #endif #ifdef CONFIG_NETDEV_IOCTL - dev->d_ioctl = macnet_ioctl; /* Handle network IOCTL commands */ + dev->d_ioctl = macnet_ioctl; /* Handle network IOCTL commands */ #endif - dev->d_private = (FAR void *)priv; /* Used to recover private state from dev */ + dev->d_private = (FAR void *)priv; /* Used to recover private state from dev */ /* Create a watchdog for timing polling for and timing of transmisstions */ - priv->md_mac = mac; /* Save the MAC interface instance */ - priv->md_txpoll = wd_create(); /* Create periodic poll timer */ - priv->md_txtimeout = wd_create(); /* Create TX timeout timer */ + priv->md_mac = mac; /* Save the MAC interface instance */ + priv->md_txpoll = wd_create(); /* Create periodic poll timer */ + priv->md_txtimeout = wd_create(); /* Create TX timeout timer */ DEBUGASSERT(priv->md_txpoll != NULL && priv->md_txtimeout != NULL); From 5c32abb4425556b8ba11f0edf49d53e1e9acb3ef Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Wed, 5 Apr 2017 21:07:52 -0400 Subject: [PATCH 071/183] wireless/ieee802154: Adds ability to receive notifications from MAC char driver --- .../wireless/ieee802154/ieee802154_mac.h | 37 +++-- wireless/ieee802154/mac802154_device.c | 154 ++++++++++++++++-- 2 files changed, 157 insertions(+), 34 deletions(-) diff --git a/include/nuttx/wireless/ieee802154/ieee802154_mac.h b/include/nuttx/wireless/ieee802154/ieee802154_mac.h index 6ad8158c806..1a7929cb3e6 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_mac.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_mac.h @@ -83,22 +83,27 @@ * Request and Response primitives. */ -#define MAC802154IOC_MLME_ASSOC_REQUEST _MAC802154IOC(0x0001) -#define MAC802154IOC_MLME_ASSOC_RESPONSE _MAC802154IOC(0x0002) -#define MAC802154IOC_MLME_DISASSOC_REQUEST _MAC802154IOC(0x0003) -#define MAC802154IOC_MLME_GET_REQUEST _MAC802154IOC(0x0004) -#define MAC802154IOC_MLME_GTS_REQUEST _MAC802154IOC(0x0005) -#define MAC802154IOC_MLME_ORPHAN_RESPONSE _MAC802154IOC(0x0006) -#define MAC802154IOC_MLME_RESET_REQUEST _MAC802154IOC(0x0007) -#define MAC802154IOC_MLME_RXENABLE_REQUEST _MAC802154IOC(0x0008) -#define MAC802154IOC_MLME_SCAN_REQUEST _MAC802154IOC(0x0009) -#define MAC802154IOC_MLME_SET_REQUEST _MAC802154IOC(0x000A) -#define MAC802154IOC_MLME_START_REQUEST _MAC802154IOC(0x000B) -#define MAC802154IOC_MLME_SYNC_REQUEST _MAC802154IOC(0x000C) -#define MAC802154IOC_MLME_POLL_REQUEST _MAC802154IOC(0x000D) -#define MAC802154IOC_MLME_DPS_REQUEST _MAC802154IOC(0x000E) -#define MAC802154IOC_MLME_SOUNDING_REQUEST _MAC802154IOC(0x000F) -#define MAC802154IOC_MLME_CALIBRATE_REQUEST _MAC802154IOC(0x0010) +#define MAC802154IOC_MCPS_REGISTER _MAC802154IOC(0x0001) + +#define MAC802154IOC_MLME_REGISER _MAC802154IOC(0x0002); +#define MAC802154IOC_MLME_ASSOC_REQUEST _MAC802154IOC(0x0003) +#define MAC802154IOC_MLME_ASSOC_RESPONSE _MAC802154IOC(0x0004) +#define MAC802154IOC_MLME_DISASSOC_REQUEST _MAC802154IOC(0x0005) +#define MAC802154IOC_MLME_GET_REQUEST _MAC802154IOC(0x0006) +#define MAC802154IOC_MLME_GTS_REQUEST _MAC802154IOC(0x0007) +#define MAC802154IOC_MLME_ORPHAN_RESPONSE _MAC802154IOC(0x0008) +#define MAC802154IOC_MLME_RESET_REQUEST _MAC802154IOC(0x0009) +#define MAC802154IOC_MLME_RXENABLE_REQUEST _MAC802154IOC(0x000A) +#define MAC802154IOC_MLME_SCAN_REQUEST _MAC802154IOC(0x000B) +#define MAC802154IOC_MLME_SET_REQUEST _MAC802154IOC(0x000C) +#define MAC802154IOC_MLME_START_REQUEST _MAC802154IOC(0x000D) +#define MAC802154IOC_MLME_SYNC_REQUEST _MAC802154IOC(0x000E) +#define MAC802154IOC_MLME_POLL_REQUEST _MAC802154IOC(0x000F) +#define MAC802154IOC_MLME_DPS_REQUEST _MAC802154IOC(0x0010) +#define MAC802154IOC_MLME_SOUNDING_REQUEST _MAC802154IOC(0x0011) +#define MAC802154IOC_MLME_CALIBRATE_REQUEST _MAC802154IOC(0x0012) + + /* IEEE 802.15.4 MAC Interface **********************************************/ diff --git a/wireless/ieee802154/mac802154_device.c b/wireless/ieee802154/mac802154_device.c index 18d88cf9b38..67631e7c63b 100644 --- a/wireless/ieee802154/mac802154_device.c +++ b/wireless/ieee802154/mac802154_device.c @@ -77,15 +77,33 @@ struct mac802154_devwrapper_s FAR struct mac802154_open_s *md_open; FAR struct mac802154dev_dwait_s *md_dwait; + +#ifndef CONFIG_DISABLE_SIGNALS + /* MCPS Service notification information */ + + struct mac802154dev_notify_s md_mcps_notify; + pid_t md_mcps_pid; + + /* MLME Service notification information */ + + struct mac802154dev_notify_s md_mlme_notify; + pid_t md_mlme_pid; + +#endif +}; + +struct mac802154dev_notify_s +{ + uint8_t mn_signo; /* Signal number to use in the notification */ }; /* This structure describes the state of one open mac driver instance */ -struct mac802154_open_s +struct mac802154dev_open_s { /* Supports a singly linked list */ - FAR struct mac802154_open_s *md_flink; + FAR struct mac802154dev_open_s *md_flink; /* The following will be true if we are closing */ @@ -96,7 +114,7 @@ struct mac802154dev_dwait_s { uint8_t mw_handle; /* The msdu handle identifying the frame */ sem_t mw_sem; /* The semaphore used to signal the completion */ - int status; /* The success/error of the transaction */ + int mw_status; /* The success/error of the transaction */ /* Supports a singly linked list */ @@ -181,7 +199,7 @@ static int mac802154dev_open(FAR struct file *filep) { FAR struct inode *inode; FAR struct mac802154_devwrapper_s *dev; - FAR struct mac802154_open_s *opriv; + FAR struct mac802154dev_open_s *opriv; int ret; DEBUGASSERT(filep != NULL && filep->f_inode != NULL); @@ -201,8 +219,8 @@ static int mac802154dev_open(FAR struct file *filep) /* Allocate a new open struct */ - opriv = (FAR struct mac802154_open_s *) - kmm_zalloc(sizeof(struct mac802154_open_s)); + opriv = (FAR struct mac802154dev_open_s *) + kmm_zalloc(sizeof(struct mac802154dev_open_s)); if (!opriv) { @@ -238,9 +256,9 @@ static int mac802154dev_close(FAR struct file *filep) { FAR struct inode *inode; FAR struct mac802154_devwrapper_s *dev; - FAR struct mac802154_open_s *opriv; - FAR struct mac802154_open_s *curr; - FAR struct mac802154_open_s *prev; + FAR struct mac802154dev_open_s *opriv; + FAR struct mac802154dev_open_s *curr; + FAR struct mac802154dev_open_s *prev; irqstate_t flags; bool closing; int ret; @@ -431,7 +449,13 @@ static ssize_t mac802154dev_write(FAR struct file *filep, /* Wait for the DATA.confirm callback to be called for our handle */ - sem_wait(&dwait.mw_sem); + if(sem_wait(dwait.mw_sem) < 0) + { + /* This should only happen if the wait was canceled by an signal */ + + DEBUGASSERT(errno == EINTR); + return -EINTR; + } /* The unlinking of the wait struct happens inside the callback. This * is more efficient since it will already have to find the struct in @@ -476,6 +500,57 @@ static int mac802154dev_ioctl(FAR struct file *filep, int cmd, switch (cmd) { +#ifndef CONFIG_DISABLE_SIGNALS + /* Command: MAC802154IOC_MLME_REGISTER, MAC802154IOC_MCPS_REGISTER + * Description: Register to receive a signal whenever there is a + * event primitive sent from the MAC layer. + * Argument: A read-only pointer to an instance of struct + * mac802154dev_notify_s + * Return: Zero (OK) on success. Minus one will be returned on + * failure with the errno value set appropriately. + */ + + case MAC802154IOC_MLME_REGISTER: + { + FAR struct mac802154dev_notify_s *notify = + (FAR struct mac802154dev_notify_s *)((uintptr_t)arg); + + if (notify) + { + /* Save the notification events */ + + dev->md_mlme_notify.mn_signo = notify->mn_signo; + dev->md_mlme_pid = getpid(); + + return OK; + } + } + break; + case MAC802154IOC_MCPS_REGISTER: + { + FAR struct mac802154dev_notify_s *notify = + (FAR struct mac802154dev_notify_s *)((uintptr_t)arg); + + if (notify) + { + /* Save the notification events */ + + dev->md_mcps_notify.mn_signo = notify->mn_signo; + dev->md_mcps_pid = getpid(); + + return OK; + } + } + break; +#endif + case MAC802154IOC_MLME_ASSOC_REQUEST: + { + FAR struct ieee802154_assoc_req_s *req = + (FAR struct ieee802154_assoc_req_s *)((uintptr_t)arg); + + + } + break; default: wlerr("ERROR: Unrecognized command %ld\n", cmd); ret = -EINVAL; @@ -501,20 +576,63 @@ void mac802154dev_conf_data(MACHANDLE mac, */ #warning Missing logic - /* Get exclusive access to the driver structure */ - - ret = mac802154dev_takesem(&dev->md_exclsem); - if (ret < 0) - { - wlerr("ERROR: mac802154dev_takesem failed: %d\n", ret); - return; - } + /* Get exclusive access to the driver structure. We don't care about any + * signals so if we see one, just go back to trying to get access again */ + + while(mac802154dev_takesem(&dev->md_exclsem) != OK); /* Search to see if there is a dwait pending for this transaction */ for (prev = NULL, curr = dev->md_dwait; curr && curr->mw_handle != conf->msdu_handle; prev = curr, curr = curr->mw_flink); + + /* If a dwait is found */ + + if (curr) + { + /* Unlink the structure from the list. The struct should be allocated on + * the calling write's stack, so we don't need to worry about deallocating + * here */ + + if (prev) + { + prev->mw_flink = curr->mw_flink; + } + else + { + dev->md_dwait = curr->mw_flink; + } + + /* Copy the transmission status into the dwait struct */ + + curr->mw_status = conf->msdu_handle; + + /* Wake the thread waiting for the data transmission */ + + sem_post(&curr->mw_sem); + + /* Release the driver */ + + mac802154dev_givesem(&dev->md_exclsem); + } + + +#ifndef CONFIG_DISABLE_SIGNALS + /* Send a signal to the registered application */ + +#ifdef CONFIG_CAN_PASS_STRUCTS + /* Copy the status as the signal data to be optionally used by app */ + + union sigval value; + value.sival_int = (int)conf->status; + (void)sigqueue(dev->md_mcps_pid, dev->md_mcps_notify.mn_signo, value); +#else + (void)sigqueue(dev->md_mcps_pid, dev->md_mcps_notify.mn_signo, + value.sival_ptr); +#endif + +#endif } /**************************************************************************** From dce2e774df9724f81dcd458f58a2cd14316da487 Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Thu, 6 Apr 2017 09:38:09 -0400 Subject: [PATCH 072/183] wireless/ieee802154: Fixes comments from previous commit --- include/nuttx/wireless/ieee802154/ieee802154_mac.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/nuttx/wireless/ieee802154/ieee802154_mac.h b/include/nuttx/wireless/ieee802154/ieee802154_mac.h index 1a7929cb3e6..d26bda9529d 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_mac.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_mac.h @@ -916,17 +916,17 @@ struct ieee802154_maccb_s CODE void (*conf_disassociate)(MACHANDLE mac, int status); - /* PIvoata returned */ + /* PIB data returned */ CODE void (*conf_get)(MACHANDLE mac, int status, int attribute, FAR uint8_t *value, int valuelen); - /* GTvoanagement completed */ + /* GTS management completed */ CODE void (*conf_gts)(MACHANDLE mac, FAR uint8_t *characteristics, int status); - /* MAveset completed */ + /* MAC reset completed */ CODE void (*conf_reset)(MACHANDLE mac, int status); From 54939d46160172eddacf493a5ac89fb9002ee240 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 15 Apr 2017 10:23:29 -0600 Subject: [PATCH 073/183] network IOCTLs: Some corrections and updates to a previous commit --- net/Kconfig | 1 + net/netdev/netdev_ioctl.c | 28 ++++++++++++++++++++++------ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/net/Kconfig b/net/Kconfig index da5eab15d2c..49e927193d7 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -136,6 +136,7 @@ config NET_6LOWPAN default n select NETDEV_MULTINIC if NET_ETHERNET || NET_LOOPBACK || NET_SLIP || NET_TUN select NET_MULTILINK if NET_ETHERNET || NET_LOOPBACK || NET_SLIP || NET_TUN + select NETDEV_IOCTL depends on EXPERIMENTAL && NET_IPv6 ---help--- Enable support for IEEE 802.15.4 Low power Wireless Personal Area diff --git a/net/netdev/netdev_ioctl.c b/net/netdev/netdev_ioctl.c index 3b5ca1f4e1b..bc4d6703798 100644 --- a/net/netdev/netdev_ioctl.c +++ b/net/netdev/netdev_ioctl.c @@ -70,11 +70,12 @@ #ifdef CONFIG_NETDEV_WIRELESS_IOCTL # include -#ifdef CONFIG_NET_6LOWPAN +#endif + +#if defined(CONFIG_NETDEV_IOCTL) && defined(CONFIG_NET_6LOWPAN) # include # include #endif -#endif #include "arp/arp.h" #include "socket/socket.h" @@ -379,7 +380,7 @@ static int netdev_iee802154_ioctl(FAR struct socket *psock, int cmd, FAR char *ifname; int ret = -ENOTTY; - if (req != NULL) + if (arg != 0ul) { /* Verify that this is either a valid IEEE802.15.4 radio IOCTL command * or a valid IEEE802.15.4 MAC IOCTL command. @@ -414,9 +415,15 @@ static int netdev_iee802154_ioctl(FAR struct socket *psock, int cmd, return -ENOTTY; } - /* Perform the device IOCTL */ + /* Find the device with this name */ - ret = dev->d_ioctl(dev, cmd, arg); + dev = netdev_findbyname(ifname); + if (dev != NULL) + { + /* Perform the device IOCTL */ + + ret = dev->d_ioctl(dev, cmd, arg); + } } return ret; @@ -1301,7 +1308,7 @@ int psock_ioctl(FAR struct socket *psock, int cmd, unsigned long arg) ret = netdev_ifrioctl(psock, cmd, (FAR struct ifreq *)((uintptr_t)arg)); #if defined(CONFIG_NETDEV_IOCTL) && defined(CONFIG_NETDEV_WIRELESS_IOCTL) - /* Check a wireless network command */ + /* Check for a wireless network command */ if (ret == -ENOTTY) { @@ -1309,6 +1316,15 @@ int psock_ioctl(FAR struct socket *psock, int cmd, unsigned long arg) } #endif +#if defined(CONFIG_NETDEV_IOCTL) && defined(CONFIG_NET_6LOWPAN) + /* Check for a IEEE802.15.4 network device command */ + + if (ret == -ENOTTY) + { + ret = netdev_iee802154_ioctl(psock, cmd, arg); + } +#endif + #ifdef CONFIG_NET_IGMP /* Check for address filtering commands */ From d9e2139e46789aac8dfb9f8b7995ddf71a7070c8 Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Sat, 15 Apr 2017 13:20:33 -0400 Subject: [PATCH 074/183] wireless/ieee802154/mrf24j40: Renaming, added bind method --- drivers/wireless/ieee802154/mrf24j40.c | 330 ++++++++++++++----------- 1 file changed, 180 insertions(+), 150 deletions(-) diff --git a/drivers/wireless/ieee802154/mrf24j40.c b/drivers/wireless/ieee802154/mrf24j40.c index 263de68eebf..32da714bcad 100644 --- a/drivers/wireless/ieee802154/mrf24j40.c +++ b/drivers/wireless/ieee802154/mrf24j40.c @@ -3,6 +3,7 @@ * * Copyright (C) 2015-2016 Sebastien Lorquet. All rights reserved. * Author: Sebastien Lorquet + * Author: Anthony Merlino * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -101,10 +102,16 @@ struct mrf24j40_radio_s { - struct ieee802154_radio_s ieee; /* The public device instance */ + struct ieee802154_radio_s radio; /* The public device instance */ + + /* Reference to the bound upper layer via the phyif interface */ + + FAR const struct ieee802154_phyif_s *phyif; + FAR struct spi_dev_s *spi; /* Saved SPI interface instance */ struct work_s irqwork; /* Interrupt continuation work queue support */ FAR const struct mrf24j40_lower_s *lower; /* Low-level MCU-specific support */ + sem_t excl_sem; /* Exclusive access to this struct */ uint16_t panid; /* PAN identifier, FFFF = not set */ uint16_t saddr; /* short address, FFFF = not set */ @@ -115,6 +122,13 @@ struct mrf24j40_radio_s uint8_t rxmode; /* Reception mode: Main, no CRC, promiscuous */ int32_t txpower; /* TX power in mBm = dBm/100 */ struct ieee802154_cca_s cca; /* Clear channel assessement method */ + + /* Buffer Allocations */ + + struct ieee802154_txdesc_s csma_desc; + struct ieee802154_txdesc_s gts_desc[2]; + + uint8_t tx_buf[CONFIG_IEEE802154_MTU]; }; /**************************************************************************** @@ -123,7 +137,7 @@ struct mrf24j40_radio_s /* Internal operations */ -static void mrf24j40_lock(FAR struct spi_dev_s *spi); +static void mrf24j40_spi_lock(FAR struct spi_dev_s *spi); static void mrf24j40_setreg(FAR struct spi_dev_s *spi, uint32_t addr, uint8_t val); @@ -142,48 +156,50 @@ static int mrf24j40_interrupt(int irq, FAR void *context, FAR void *arg); /* IOCTL helpers */ -static int mrf24j40_setchannel(FAR struct ieee802154_radio_s *ieee, +static int mrf24j40_setchannel(FAR struct ieee802154_radio_s *radio, uint8_t chan); -static int mrf24j40_getchannel(FAR struct ieee802154_radio_s *ieee, +static int mrf24j40_getchannel(FAR struct ieee802154_radio_s *radio, FAR uint8_t *chan); -static int mrf24j40_setpanid(FAR struct ieee802154_radio_s *ieee, +static int mrf24j40_setpanid(FAR struct ieee802154_radio_s *radio, uint16_t panid); -static int mrf24j40_getpanid(FAR struct ieee802154_radio_s *ieee, +static int mrf24j40_getpanid(FAR struct ieee802154_radio_s *radio, FAR uint16_t *panid); -static int mrf24j40_setsaddr(FAR struct ieee802154_radio_s *ieee, +static int mrf24j40_setsaddr(FAR struct ieee802154_radio_s *radio, uint16_t saddr); -static int mrf24j40_getsaddr(FAR struct ieee802154_radio_s *ieee, +static int mrf24j40_getsaddr(FAR struct ieee802154_radio_s *radio, FAR uint16_t *saddr); -static int mrf24j40_seteaddr(FAR struct ieee802154_radio_s *ieee, +static int mrf24j40_seteaddr(FAR struct ieee802154_radio_s *radio, FAR uint8_t *eaddr); -static int mrf24j40_geteaddr(FAR struct ieee802154_radio_s *ieee, +static int mrf24j40_geteaddr(FAR struct ieee802154_radio_s *radio, FAR uint8_t *eaddr); -static int mrf24j40_setpromisc(FAR struct ieee802154_radio_s *ieee, +static int mrf24j40_setpromisc(FAR struct ieee802154_radio_s *radio, bool promisc); -static int mrf24j40_getpromisc(FAR struct ieee802154_radio_s *ieee, +static int mrf24j40_getpromisc(FAR struct ieee802154_radio_s *radio, FAR bool *promisc); -static int mrf24j40_setdevmode(FAR struct ieee802154_radio_s *ieee, +static int mrf24j40_setdevmode(FAR struct ieee802154_radio_s *radio, uint8_t mode); -static int mrf24j40_getdevmode(FAR struct ieee802154_radio_s *ieee, +static int mrf24j40_getdevmode(FAR struct ieee802154_radio_s *radio, FAR uint8_t *mode); -static int mrf24j40_settxpower(FAR struct ieee802154_radio_s *ieee, +static int mrf24j40_settxpower(FAR struct ieee802154_radio_s *radio, int32_t txpwr); -static int mrf24j40_gettxpower(FAR struct ieee802154_radio_s *ieee, +static int mrf24j40_gettxpower(FAR struct ieee802154_radio_s *radio, FAR int32_t *txpwr); -static int mrf24j40_setcca(FAR struct ieee802154_radio_s *ieee, +static int mrf24j40_setcca(FAR struct ieee802154_radio_s *radio, FAR struct ieee802154_cca_s *cca); -static int mrf24j40_getcca(FAR struct ieee802154_radio_s *ieee, +static int mrf24j40_getcca(FAR struct ieee802154_radio_s *radio, FAR struct ieee802154_cca_s *cca); -static int mrf24j40_energydetect(FAR struct ieee802154_radio_s *ieee, +static int mrf24j40_energydetect(FAR struct ieee802154_radio_s *radio, FAR uint8_t *energy); /* Driver operations */ -static int mrf24j40_ioctl(FAR struct ieee802154_radio_s *ieee, int cmd, +static int mrf24j40_bind(FAR struct ieee802154_radio_s *radio, + FAR struct ieee802154_phyif_s *phyif); +static int mrf24j40_ioctl(FAR struct ieee802154_radio_s *radio, int cmd, unsigned long arg); -static int mrf24j40_rxenable(FAR struct ieee802154_radio_s *ieee, +static int mrf24j40_rxenable(FAR struct ieee802154_radio_s *radio, bool state, FAR struct ieee802154_packet_s *packet); -static int mrf24j40_transmit(FAR struct ieee802154_radio_s *ieee, +static int mrf24j40_transmit(FAR struct ieee802154_radio_s *radio, FAR struct ieee802154_packet_s *packet); /**************************************************************************** @@ -197,10 +213,9 @@ static int mrf24j40_transmit(FAR struct ieee802154_radio_s *ieee, * using the IRQ number. See the ENC28J60 or CC3000 drivers for reference. */ -static struct mrf24j40_radio_s g_mrf24j40_devices[1]; - static const struct ieee802154_radioops_s mrf24j40_devops = { + mrf24j40_bind, mrf24j40_ioctl, mrf24j40_rxenable, mrf24j40_transmit @@ -210,15 +225,73 @@ static const struct ieee802154_radioops_s mrf24j40_devops = * Private Functions ****************************************************************************/ +static void mrf24j40_bind(FAR struct ieee802154_radio_s *radio, + FAR struct ieee802154_phyif_s *phyif) +{ + FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)radio; + + DEBUGASSERT(dev != NULL); + dev->phyif = phyif; + return OK; +} + /**************************************************************************** - * Name: mrf24j40_lock + * Function: mrf24j40_txavail + * + * Description: + * Called from the upper layer, this function is to notify the device that + * the upper layer has a pending transaction. This function checks to see + * if there is availability for the corresponding transaction type. If + * there is, the function will call to the MAC layer to get the transaction + * and then start the transmission + * + ****************************************************************************/ + +static void mrf24j40_txavail(FAR struct ieee802154_radio_s *radio, bool gts) +{ + FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)radio; + uint8_t gts; + + while (sem_wait(dev->exclsem) < 0) { } + + /* If this a CSMA transaction and we have room in the CSMA fifo */ + + if (!gts && !dev->csma_busy) + { + /* need to somehow allow for a handle to be passed */ + + ret = dev->phyif->poll_csma(dev->phyif, &radio->csma_txdesc, + &dev->tx_buf[0]); + + /* Setup the transmit on the device */ + + } + else + { + for(gts = 0; gts < MRF24J40_GTS_SLOTS, gts++) + { + if(!dev->gts_txdesc[i].busy) + { + ret = dev->phyif->poll_gts(dev->phyif, &radio->gts_txdesc[i], + &dev->tx_buf[0]); + + /* Setup the transmit on the device */ + + break; + } + } + } +} + +/**************************************************************************** + * Name: mrf24j40_spi_lock * * Description: * Acquire exclusive access to the shared SPI bus. * ****************************************************************************/ -static void mrf24j40_lock(FAR struct spi_dev_s *spi) +static void mrf24j40_spi_lock(FAR struct spi_dev_s *spi) { SPI_LOCK(spi, 1); SPI_SETBITS(spi, 8); @@ -227,14 +300,14 @@ static void mrf24j40_lock(FAR struct spi_dev_s *spi) } /**************************************************************************** - * Name: mrf24j40_unlock + * Name: mrf24j40_spi_unlock * * Description: * Release exclusive access to the shared SPI bus. * ****************************************************************************/ -static inline void mrf24j40_unlock(FAR struct spi_dev_s *spi) +static inline void mrf24j40_spi_unlock(FAR struct spi_dev_s *spi) { SPI_LOCK(spi,0); } @@ -484,11 +557,8 @@ static int mrf24j40_setrxmode(FAR struct mrf24j40_radio_s *dev, int mode) * ****************************************************************************/ -static int mrf24j40_setchannel(FAR struct ieee802154_radio_s *ieee, - uint8_t chan) +static int mrf24j40_setchannel(FAR struct mrf24j40_radio_s *dev, uint8_t chan) { - FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)ieee; - if (chan < 11 || chan > 26) { wlerr("ERROR: Invalid chan: %d\n",chan); @@ -511,21 +581,11 @@ static int mrf24j40_setchannel(FAR struct ieee802154_radio_s *ieee, return OK; } -/**************************************************************************** - * Name: mrf24j40_getchannel - * - * Description: - * Define the current radio channel the device is operating on. - * - ****************************************************************************/ - -static int mrf24j40_getchannel(FAR struct ieee802154_radio_s *ieee, +static int mrf24j40_getchannel(FAR struct mrf24j40_radio_s *dev, FAR uint8_t *chan) { - FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)ieee; - - *chan = dev->channel; - + chan = dev->channel; + return OK; } @@ -537,11 +597,9 @@ static int mrf24j40_getchannel(FAR struct ieee802154_radio_s *ieee, * ****************************************************************************/ -static int mrf24j40_setpanid(FAR struct ieee802154_radio_s *ieee, +static int mrf24j40_setpanid(FAR struct mrf24j40_radio_s *dev, uint16_t panid) { - FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)ieee; - mrf24j40_setreg(dev->spi, MRF24J40_PANIDH, (uint8_t)(panid>>8)); mrf24j40_setreg(dev->spi, MRF24J40_PANIDL, (uint8_t)(panid&0xFF)); @@ -559,11 +617,9 @@ static int mrf24j40_setpanid(FAR struct ieee802154_radio_s *ieee, * ****************************************************************************/ -static int mrf24j40_getpanid(FAR struct ieee802154_radio_s *ieee, +static int mrf24j40_getpanid(FAR struct mrf24j40_radio_s *dev, FAR uint16_t *panid) { - FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)ieee; - *panid = dev->panid; return OK; @@ -579,11 +635,9 @@ static int mrf24j40_getpanid(FAR struct ieee802154_radio_s *ieee, * ****************************************************************************/ -static int mrf24j40_setsaddr(FAR struct ieee802154_radio_s *ieee, +static int mrf24j40_setsaddr(FAR struct mrf24j40_radio_s *dev, uint16_t saddr) { - FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)ieee; - mrf24j40_setreg(dev->spi, MRF24J40_SADRH, (uint8_t)(saddr>>8)); mrf24j40_setreg(dev->spi, MRF24J40_SADRL, (uint8_t)(saddr&0xFF)); @@ -600,11 +654,9 @@ static int mrf24j40_setsaddr(FAR struct ieee802154_radio_s *ieee, * ****************************************************************************/ -static int mrf24j40_getsaddr(FAR struct ieee802154_radio_s *ieee, +static int mrf24j40_getsaddr(FAR struct mrf24j40_radio_s *dev, FAR uint16_t *saddr) { - FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)ieee; - *saddr = dev->saddr; return OK; @@ -619,10 +671,9 @@ static int mrf24j40_getsaddr(FAR struct ieee802154_radio_s *ieee, * ****************************************************************************/ -static int mrf24j40_seteaddr(FAR struct ieee802154_radio_s *ieee, +static int mrf24j40_seteaddr(FAR struct mrf24j40_radio_s *dev, FAR uint8_t *eaddr) { - FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)ieee; int i; for (i = 0; i < 8; i++) @@ -642,11 +693,9 @@ static int mrf24j40_seteaddr(FAR struct ieee802154_radio_s *ieee, * ****************************************************************************/ -static int mrf24j40_geteaddr(FAR struct ieee802154_radio_s *ieee, +static int mrf24j40_geteaddr(FAR struct mrf24j40_radio_s *dev, FAR uint8_t *eaddr) { - FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)ieee; - memcpy(eaddr, dev->eaddr, 8); return OK; @@ -661,11 +710,9 @@ static int mrf24j40_geteaddr(FAR struct ieee802154_radio_s *ieee, * ****************************************************************************/ -static int mrf24j40_setpromisc(FAR struct ieee802154_radio_s *ieee, +static int mrf24j40_setpromisc(FAR struct mrf24j40_radio_s *dev, bool promisc) { - FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)ieee; - return mrf24j40_setrxmode(dev, promisc ? MRF24J40_RXMODE_PROMISC : MRF24J40_RXMODE_NORMAL); } @@ -678,11 +725,9 @@ static int mrf24j40_setpromisc(FAR struct ieee802154_radio_s *ieee, * ****************************************************************************/ -static int mrf24j40_getpromisc(FAR struct ieee802154_radio_s *ieee, +static int mrf24j40_getpromisc(FAR struct mrf24j40_radio_s *dev, FAR bool *promisc) { - FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)ieee; - *promisc = (dev->rxmode == MRF24J40_RXMODE_PROMISC); return OK; @@ -696,10 +741,9 @@ static int mrf24j40_getpromisc(FAR struct ieee802154_radio_s *ieee, * ****************************************************************************/ -static int mrf24j40_setdevmode(FAR struct ieee802154_radio_s *ieee, +static int mrf24j40_setdevmode(FAR struct mrf24j40_radio_s *dev, uint8_t mode) { - FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)ieee; int ret = OK; uint8_t reg; @@ -748,11 +792,9 @@ static int mrf24j40_setdevmode(FAR struct ieee802154_radio_s *ieee, * ****************************************************************************/ -static int mrf24j40_getdevmode(FAR struct ieee802154_radio_s *ieee, +static int mrf24j40_getdevmode(FAR struct mrf24j40_radio_s *dev, FAR uint8_t *mode) { - FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)ieee; - *mode = dev->devmode; return OK; @@ -768,10 +810,9 @@ static int mrf24j40_getdevmode(FAR struct ieee802154_radio_s *ieee, * ****************************************************************************/ -static int mrf24j40_settxpower(FAR struct ieee802154_radio_s *ieee, +static int mrf24j40_settxpower(FAR struct mrf24j40_radio_s *dev, int32_t txpwr) { - FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)ieee; uint8_t reg; int save_txpwr = txpwr; @@ -851,11 +892,9 @@ static int mrf24j40_settxpower(FAR struct ieee802154_radio_s *ieee, * ****************************************************************************/ -static int mrf24j40_gettxpower(FAR struct ieee802154_radio_s *ieee, +static int mrf24j40_gettxpower(FAR struct mrf24j40_radio_s *radio, FAR int32_t *txpwr) { - FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)ieee; - *txpwr = dev->txpower; return OK; @@ -869,10 +908,9 @@ static int mrf24j40_gettxpower(FAR struct ieee802154_radio_s *ieee, * ****************************************************************************/ -static int mrf24j40_setcca(FAR struct ieee802154_radio_s *ieee, +static int mrf24j40_setcca(FAR struct mrf24j40_radio_s *dev, FAR struct ieee802154_cca_s *cca) { - FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)ieee; uint8_t mode; if (!cca->use_ed && !cca->use_cs) @@ -914,11 +952,9 @@ static int mrf24j40_setcca(FAR struct ieee802154_radio_s *ieee, * ****************************************************************************/ -static int mrf24j40_getcca(FAR struct ieee802154_radio_s *ieee, +static int mrf24j40_getcca(FAR struct mrf24j40_radio_s *dev, FAR struct ieee802154_cca_s *cca) { - FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)ieee; - memcpy(cca, &dev->cca, sizeof(struct ieee802154_cca_s)); return OK; @@ -982,82 +1018,82 @@ static int mrf24j40_regdump(FAR struct mrf24j40_radio_s *dev) * ****************************************************************************/ -static int mrf24j40_ioctl(FAR struct ieee802154_radio_s *ieee, int cmd, +static int mrf24j40_ioctl(FAR struct ieee802154_radio_s *radio, int cmd, unsigned long arg) { - FAR struct mrf24j40_radio_s *dev = - (FAR struct mrf24j40_radio_s *)ieee; + FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)radio; + FAR union ieee802154_radioarg_u *u; = (FAR union ieee802154_radioarg_u *)((uintptr_t)arg) switch(cmd) { case PHY802154IOC_SET_CHAN: - ret = mrf24j40_setchannel(ieee, u.channel); + ret = mrf24j40_setchannel(dev, u.channel); break; case PHY802154IOC_GET_CHAN: - ret = mrf24j40_getchannel(ieee, &u.channel); + ret = mrf24j40_getchannel(dev, &u.channel); break; case PHY802154IOC_SET_PANID: - ret = mrf24j40_setpanid(ieee, u.panid); + ret = mrf24j40_setpanid(dev, u.panid); break; case PHY802154IOC_GET_PANID: - ret = mrf24j40_getpanid(ieee, &u.panid); + ret = mrf24j40_getpanid(dev, &u.panid); break; case PHY802154IOC_SET_SADDR: - ret = mrf24j40_setsaddr(ieee, u.saddr); + ret = mrf24j40_setsaddr(dev, u.saddr); break; case PHY802154IOC_GET_SADDR: - ret = mrf24j40_getsaddr(ieee, &u.saddr); + ret = mrf24j40_getsaddr(dev, &u.saddr); break; case PHY802154IOC_SET_EADDR: - ret = mrf24j40_seteaddr(ieee, u.eaddr); + ret = mrf24j40_seteaddr(dev, u.eaddr); break; case PHY802154IOC_GET_EADDR: - ret = mrf24j40_geteaddr(ieee, u.eaddr); + ret = mrf24j40_geteaddr(dev, u.eaddr); break; case PHY802154IOC_SET_PROMISC: - ret = mrf24j40_setpromisc(ieee, u.promisc); + ret = mrf24j40_setpromisc(dev, u.promisc); break; case PHY802154IOC_GET_PROMISC: - ret = mrf24j40_getpromisc(ieee, &u.promisc); + ret = mrf24j40_getpromisc(dev, &u.promisc); break; case PHY802154IOC_SET_DEVMODE: - ret = mrf24j40_setdevmode(ieee, u.devmode); + ret = mrf24j40_setdevmode(dev, u.devmode); break; case PHY802154IOC_GET_DEVMODE: - ret = mrf24j40_getdevmode(ieee, &u.devmode); + ret = mrf24j40_getdevmode(dev, &u.devmode); break; case PHY802154IOC_SET_TXPWR: - ret = mrf24j40_settxpower(ieee, u.txpwr); + ret = mrf24j40_settxpower(dev, u.txpwr); break; case PHY802154IOC_GET_TXPWR: - ret = mrf24j40_gettxpower(ieee, &u.txpwr); + ret = mrf24j40_gettxpower(dev, &u.txpwr); break; case PHY802154IOC_SET_CCA: - ret = mrf24j40_setcca(ieee, &u.cca); + ret = mrf24j40_setcca(dev, &u.cca); break; case PHY802154IOC_GET_CCA: - ret = mrf24j40_getcca(ieee, &u.cca); + ret = mrf24j40_getcca(dev, &u.cca); break; case PHY802154IOC_ENERGYDETECT: - ret = mrf24j40_energydetect(ieee, &u.energy); + ret = mrf24j40_energydetect(dev, &u.energy); break; case 1000: @@ -1080,10 +1116,9 @@ static int mrf24j40_ioctl(FAR struct ieee802154_radio_s *ieee, int cmd, * ****************************************************************************/ -static int mrf24j40_energydetect(FAR struct ieee802154_radio_s *ieee, +static int mrf24j40_energydetect(FAR struct mrf24j40_radio_s *dev, FAR uint8_t *energy) { - FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)ieee; uint8_t reg; /* Manually enable the LNA*/ @@ -1130,10 +1165,10 @@ static int mrf24j40_energydetect(FAR struct ieee802154_radio_s *ieee, * ****************************************************************************/ -static int mrf24j40_transmit(FAR struct ieee802154_radio_s *ieee, - FAR struct ieee802154_packet_s *packet) +static int mrf24j40_transmit(FAR struct ieee802154_radio_s *radio, + uint8_t *buf, uint16_t buf_len) { - FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)ieee; + FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)radio; uint32_t addr; uint8_t reg; int ret; @@ -1152,8 +1187,8 @@ static int mrf24j40_transmit(FAR struct ieee802154_radio_s *ieee, /* Analyze frame control to compute header length */ - frame_ctrl = packet->data[0]; - frame_ctrl |= packet->data[1] << 8; + frame_ctrl = buf[0]; + frame_ctrl |= (buf[1] << 8); if ((frame_ctrl & IEEE802154_FRAMECTRL_DADDR)== IEEE802154_ADDRMODE_SHORT) { @@ -1184,11 +1219,11 @@ static int mrf24j40_transmit(FAR struct ieee802154_radio_s *ieee, /* Frame length */ - mrf24j40_setreg(dev->spi, addr++, packet->len); + mrf24j40_setreg(dev->spi, addr++, buflen); /* Frame data */ - for (ret = 0; ret < packet->len; ret++) /* this sets the correct val for ret */ + for (ret = 0; ret < buflen; ret++) /* this sets the correct val for ret */ { mrf24j40_setreg(dev->spi, addr++, packet->data[ret]); } @@ -1208,9 +1243,7 @@ static int mrf24j40_transmit(FAR struct ieee802154_radio_s *ieee, mrf24j40_setreg(dev->spi, MRF24J40_TXNCON, reg); - /* Suspend calling thread until transmit is complete */ - - return sem_wait(&ieee->txsem); + return ret; } /**************************************************************************** @@ -1232,9 +1265,9 @@ static void mrf24j40_irqwork_tx(FAR struct mrf24j40_radio_s *dev) /* 1 means it failed, we want 1 to mean it worked. */ - dev->ieee.txok = (reg & MRF24J40_TXSTAT_TXNSTAT) != MRF24J40_TXSTAT_TXNSTAT; - dev->ieee.txretries = (reg & MRF24J40_TXSTAT_X_MASK) >> MRF24J40_TXSTAT_X_SHIFT; - dev->ieee.txbusy = (reg & MRF24J40_TXSTAT_CCAFAIL) == MRF24J40_TXSTAT_CCAFAIL; + dev->radio.txok = (reg & MRF24J40_TXSTAT_TXNSTAT) != MRF24J40_TXSTAT_TXNSTAT; + dev->radio.txretries = (reg & MRF24J40_TXSTAT_X_MASK) >> MRF24J40_TXSTAT_X_SHIFT; + dev->radio.txbusy = (reg & MRF24J40_TXSTAT_CCAFAIL) == MRF24J40_TXSTAT_CCAFAIL; //wlinfo("TXSTAT%02X!\n", txstat); #warning TODO report errors @@ -1248,7 +1281,8 @@ static void mrf24j40_irqwork_tx(FAR struct mrf24j40_radio_s *dev) /* Wake up the thread that triggered the transmission */ - sem_post(&dev->ieee.txsem); + sem_post(&dev->radio.txsem); + } /**************************************************************************** @@ -1259,16 +1293,16 @@ static void mrf24j40_irqwork_tx(FAR struct mrf24j40_radio_s *dev) * ****************************************************************************/ -static int mrf24j40_rxenable(FAR struct ieee802154_radio_s *ieee, bool state, +static int mrf24j40_rxenable(FAR struct ieee802154_radio_s *radio, bool state, FAR struct ieee802154_packet_s *packet) { - FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)ieee; + FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)radio; uint8_t reg; if (state) { mrf24j40_pacontrol(dev, MRF24J40_PA_AUTO); - ieee->rxbuf = packet; + radio->rxbuf = packet; /* Enable rx int */ @@ -1278,7 +1312,7 @@ static int mrf24j40_rxenable(FAR struct ieee802154_radio_s *ieee, bool state, } else { - ieee->rxbuf = NULL; + radio->rxbuf = NULL; } return OK; @@ -1313,20 +1347,20 @@ static void mrf24j40_irqwork_rx(FAR struct mrf24j40_radio_s *dev) /* Read packet */ addr = MRF24J40_RXBUF_BASE; - dev->ieee.rxbuf->len = mrf24j40_getreg(dev->spi, addr++); - /* wlinfo("len %3d\n", dev->ieee.rxbuf->len); */ + dev->radio.rxbuf->len = mrf24j40_getreg(dev->spi, addr++); + /* wlinfo("len %3d\n", dev->radio.rxbuf->len); */ - for (index = 0; index < dev->ieee.rxbuf->len; index++) + for (index = 0; index < dev->radio.rxbuf->len; index++) { - dev->ieee.rxbuf->data[index] = mrf24j40_getreg(dev->spi, addr++); + dev->radio.rxbuf->data[index] = mrf24j40_getreg(dev->spi, addr++); } - dev->ieee.rxbuf->lqi = mrf24j40_getreg(dev->spi, addr++); - dev->ieee.rxbuf->rssi = mrf24j40_getreg(dev->spi, addr++); + dev->radio.rxbuf->lqi = mrf24j40_getreg(dev->spi, addr++); + dev->radio.rxbuf->rssi = mrf24j40_getreg(dev->spi, addr++); /* Reduce len by 2, we only receive frames with correct crc, no check required */ - dev->ieee.rxbuf->len -= 2; + dev->radio.rxbuf->len -= 2; /* Enable reception of next packet by flushing the fifo. * This is an MRF24J40 errata (no. 1). @@ -1338,7 +1372,7 @@ static void mrf24j40_irqwork_rx(FAR struct mrf24j40_radio_s *dev) mrf24j40_setreg(dev->spi, MRF24J40_BBREG1, 0); - sem_post(&dev->ieee.rxsem); + sem_post(&dev->radio.rxsem); } /**************************************************************************** @@ -1446,21 +1480,17 @@ static int mrf24j40_interrupt(int irq, FAR void *context, FAR void *arg) ****************************************************************************/ FAR struct ieee802154_radio_s *mrf24j40_init(FAR struct spi_dev_s *spi, - FAR const struct mrf24j40_lower_s *lower) + FAR const struct mrf24j40_lower_s *lower) { FAR struct mrf24j40_radio_s *dev; struct ieee802154_cca_s cca; -#if 0 dev = kmm_zalloc(sizeof(struct mrf24j40_radio_s)); if (dev == NULL) { return NULL; } -#else - dev = &g_mrf24j40_devices[0]; -#endif - + /* Attach irq */ if (lower->attach(lower, mrf24j40_interrupt, dev) != OK) @@ -1471,43 +1501,43 @@ FAR struct ieee802154_radio_s *mrf24j40_init(FAR struct spi_dev_s *spi, return NULL; } - dev->ieee.ops = &mrf24j40_devops; + dev->radio.ops = &mrf24j40_devops; /* Initialize semaphores */ - sem_init(&dev->ieee.rxsem, 0, 0); - sem_init(&dev->ieee.txsem, 0, 0); + sem_init(&dev->radio.rxsem, 0, 0); + sem_init(&dev->radio.txsem, 0, 0); /* These semaphores are all used for signaling and, hence, should * not have priority inheritance enabled. */ - sem_setprotocol(&dev->ieee.rxsem, SEM_PRIO_NONE); - sem_setprotocol(&dev->ieee.txsem, SEM_PRIO_NONE); + sem_setprotocol(&dev->radio.rxsem, SEM_PRIO_NONE); + sem_setprotocol(&dev->radio.txsem, SEM_PRIO_NONE); dev->lower = lower; dev->spi = spi; mrf24j40_initialize(dev); - mrf24j40_setchannel(&dev->ieee, 11); - mrf24j40_setpanid (&dev->ieee, 0xFFFF); - mrf24j40_setsaddr (&dev->ieee, 0xFFFF); - mrf24j40_seteaddr (&dev->ieee, (uint8_t*)"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"); + mrf24j40_setchannel(&dev->radio, 11); + mrf24j40_setpanid (&dev->radio, 0xFFFF); + mrf24j40_setsaddr (&dev->radio, 0xFFFF); + mrf24j40_seteaddr (&dev->radio, (uint8_t*)"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"); /* Default device params */ cca.use_ed = 1; cca.use_cs = 0; cca.edth = 0x60; /* CCA mode ED, no carrier sense, recommenced ED threshold -69 dBm */ - mrf24j40_setcca(&dev->ieee, &cca); + mrf24j40_setcca(&dev->radio, &cca); mrf24j40_setrxmode(dev, MRF24J40_RXMODE_NORMAL); - mrf24j40_settxpower(&dev->ieee, 0); /*16. Set transmitter power .*/ + mrf24j40_settxpower(&dev->radio, 0); /*16. Set transmitter power .*/ mrf24j40_pacontrol(dev, MRF24J40_PA_AUTO); - dev->lower->enable(dev->lower, true); - return &dev->ieee; + dev->lower->enable(dev->radio, true); + return &dev->radio; } From 2aaec20bbb73709842d2364d5341e7d6e09c46c1 Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Sat, 15 Apr 2017 13:21:07 -0400 Subject: [PATCH 075/183] wireless/ieee802154: Minor formatting and new macros --- .../wireless/ieee802154/ieee802154_mac.h | 82 ++++++------------- 1 file changed, 23 insertions(+), 59 deletions(-) diff --git a/include/nuttx/wireless/ieee802154/ieee802154_mac.h b/include/nuttx/wireless/ieee802154/ieee802154_mac.h index d26bda9529d..838f7fcafd5 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_mac.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_mac.h @@ -146,19 +146,19 @@ #define IEEE802154_FRAMECTRL_VERSION 0x3000 /* Source addressing mode, bits 12-13 */ #define IEEE802154_FRAMECTRL_SADDR 0xC000 /* Source addressing mode, bits 14-15 */ -#define IEEE802154_FRAMECTRL_SHIFT_FTYPE 0 /* Frame type, bits 0-2 */ -#define IEEE802154_FRAMECTRL_SHIFT_SEC 3 /* Security Enabled, bit 3 */ -#define IEEE802154_FRAMECTRL_SHIFT_PEND 4 /* Frame pending, bit 4 */ -#define IEEE802154_FRAMECTRL_SHIFT_ACKREQ 5 /* Acknowledge request, bit 5 */ -#define IEEE802154_FRAMECTRL_SHIFT_PANIDCOMP 6 /* PAN ID Compression, bit 6 */ -#define IEEE802154_FRAMECTRL_SHIFT_DADDR 10 /* Dest addressing mode, bits 10-11 */ -#define IEEE802154_FRAMECTRL_SHIFT_VERSION 12 /* Source addressing mode, bits 12-13 */ -#define IEEE802154_FRAMECTRL_SHIFT_SADDR 14 /* Source addressing mode, bits 14-15 */ +#define IEEE802154_FRAMECTRL_SHIFT_FTYPE 0 /* Frame type, bits 0-2 */ +#define IEEE802154_FRAMECTRL_SHIFT_SEC 3 /* Security Enabled, bit 3 */ +#define IEEE802154_FRAMECTRL_SHIFT_PEND 4 /* Frame pending, bit 4 */ +#define IEEE802154_FRAMECTRL_SHIFT_ACKREQ 5 /* Acknowledge request, bit 5 */ +#define IEEE802154_FRAMECTRL_SHIFT_PANIDCOMP 6 /* PAN ID Compression, bit 6 */ +#define IEEE802154_FRAMECTRL_SHIFT_DADDR 10 /* Dest addressing mode, bits 10-11 */ +#define IEEE802154_FRAMECTRL_SHIFT_VERSION 12 /* Source addressing mode, bits 12-13 */ +#define IEEE802154_FRAMECTRL_SHIFT_SADDR 14 /* Source addressing mode, bits 14-15 */ /* IEEE 802.15.4 PHY constants */ #define IEEE802154_MAX_PHY_PACKET_SIZE 127 -#define IEEE802154_TURN_AROUND_TIME 12 /*symbol periods*/ +#define IEEE802154_TURN_AROUND_TIME 12 /*symbol periods*/ /* IEEE 802.15.4 MAC constants */ @@ -175,8 +175,13 @@ (IEEE802154_MAX_PHY_PACKET_SIZE - IEEE802154_MAX_BEACON_OVERHEAD) #define IEEE802154_MAX_LOST_BEACONS 4 -#define IEEE802514_MIN_MPDU_OVERHEAD 9 -#define IEEE802154_MAX_MPDU_UNSEC_OVERHEAD 25 +#define IEEE802154_MIN_MPDU_OVERHEAD 9 +#define IEEE802154_MAX_UNSEC_MHR_OVERHEAD 23 +#define IEEE802154_MFR_LENGTH 2 + +#define IEEE802154_MAX_MPDU_UNSEC_OVERHEAD \ + (IEEE802154_MAX_UNSEC_MHR_OVERHEAD + IEEE802154_MFR_LENGTH) + #define IEEE802154_MAX_SAFE_MAC_PAYLOAD_SIZE \ (IEEE802154_MAX_PHY_PACKET_SIZE - IEEE802154_MAX_MPDU_UNSEC_OVERHEAD) @@ -344,59 +349,18 @@ struct ieee802154_addr_s { /* Address mode. Short or Extended */ - enum ieee802154_addr_mode_e ia_mode; + enum ieee802154_addr_mode_e mode; - uint16_t ia_panid; /* PAN identifier, can be IEEE802154_PAN_UNSPEC */ + uint16_t panid; /* PAN identifier, can be IEEE802154_PAN_UNSPEC */ union { - uint16_t _ia_saddr; /* short address */ - uint8_t _ia_eaddr[8]; /* extended address */ - } ia_addr; - -#define ia_saddr ia_addr._ia_saddr -#define ia_eaddr ia_addr._ia_eaddr + uint16_t saddr; /* short address */ + uint8_t eaddr[8]; /* extended address */ + }; }; #define IEEE802154_ADDRSTRLEN 22 /* (2*2+1+8*2, PPPP/EEEEEEEEEEEEEEEE) */ -struct ieee802154_framecontrol_s -{ - /* Frame type - * - * Should be a value from: ieee802154_frametype_e - * - * Bits 0-1 - */ - - uint16_t frame_type : 3; - - uint16_t security_en : 1; /* Security Enabled flag, bit 3 */ - uint16_t frame_pending : 1; /* Frame Pending flag, bit 4 */ - uint16_t ack_req : 1; /* Acknowledge Request flag, bit 5 */ - uint16_t panid_comp : 1; /* PAN ID Compression flag, bit 6 */ - uint16_t reserved : 3; /* Reserved, bits 7-9 */ - - /* Destination Addressing Mode - * - * Should be a value from: ieee802154_addr_mode_e - * - * Bits 10-11 - */ - - uint16_t dest_addr_mode : 2; - - uint16_t frame_version : 2; /* Frame Version, bits 12-13 */ - - /* Source Addressing Mode - * - * Should be a value from: ieee802154_addr_mode_e - * - * Bits 14-15 - */ - - uint16_t src_addr_mode : 2; -}; - #ifdef CONFIG_IEEE802154_SECURITY struct ieee802154_security_s { @@ -449,7 +413,7 @@ struct ieee802154_frame_s struct ieee802154_data_req_s { enum ieee802154_addr_mode_e src_addr_mode; /* Source Address Mode */ - struct ieee802154_addr_s dest__addr; /* Destination Address */ + struct ieee802154_addr_s dest_addr; /* Destination Address */ /* Number of bytes contained in the MAC Service Data Unit (MSDU) * to be transmitted by the MAC sublayer enitity @@ -502,7 +466,7 @@ struct ieee802154_data_req_s }; #define SIZEOF_IEEE802154_DATA_REQ_S(n) \ - (sizeof(struct ieee802154_data_req_s) + (n)) + (sizeof(struct ieee802154_data_req_s) + (n) - 1) struct ieee802154_data_conf_s { From 36a6bda755b0a7a78fb370b6a4d4ffadcd0fdc4a Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Sat, 15 Apr 2017 13:22:36 -0400 Subject: [PATCH 076/183] wireless/ieee802154: Starts adding MAC request data functionality --- wireless/ieee802154/mac802154.c | 499 +++++++++++++++++++++++++++----- 1 file changed, 429 insertions(+), 70 deletions(-) diff --git a/wireless/ieee802154/mac802154.c b/wireless/ieee802154/mac802154.c index e8f046f2849..f223f8836e6 100644 --- a/wireless/ieee802154/mac802154.c +++ b/wireless/ieee802154/mac802154.c @@ -68,49 +68,191 @@ struct ieee802154_privmac_s FAR struct ieee802154_radio_s *radio; /* Contained IEEE802.15.4 radio dev */ FAR const struct ieee802154_maccb_s *cb; /* Contained MAC callbacks */ - /* MIB attributes, grouped to save memory */ - /* 0x40 */ uint8_t macAckWaitDuration : 1; /* 55 or 120(true) */ - /* 0x41 */ uint8_t macAssociationPermit : 1; - /* 0x42 */ uint8_t macAutoRequest : 1; - /* 0x43 */ uint8_t macBattLifeExt : 1; - /* 0x44 */ uint8_t macBattLifeExtPeriods : 1; /* 6 or 8(true) */ - /* 0x4E */ uint8_t macMaxCSMABackoffs : 3; /* 0-5 */ + sem_t excl_sem; /* Support exclusive access */ - /* 0x47 */ uint8_t macBeaconOrder : 4; - /* 0x54 */ uint8_t macSuperframeOrder : 4; + /* Support a singly linked list of transactions that will be sent using the + * CSMA algorithm. On a non-beacon enabled PAN, these transactions will be + * sent whenever. On a beacon-enabled PAN, these transactions will be sent + * during the CAP of the Coordinator's superframe. */ - /* 0x4F */ uint32_t macMinBE : 2; - /* 0x4D */ uint32_t macGTSPermit : 1; - /* 0x51 */ uint32_t macPromiscuousMode : 1; - /* 0x52 */ uint32_t macRxOnWhenIdle : 1; - uint32_t macPad : 3; - /* 0x48 */ uint32_t macBeaconTxTime : 24; + FAR struct mac802154_trans_s *csma_head; + FAR struct mac802154_trans_s *csma_tail; - /* 0x45 */ uint8_t macBeaconPayload[IEEE802154_MAX_BEACON_PAYLOAD_LENGTH]; - /* 0x46 */ uint8_t macBeaconPayloadLength; - /* 0x49 */ uint8_t macBSN; - /* 0x4A */ uint8_t macCoordExtendedAddress[8]; - /* 0x4B */ uint16_t macCoordShortAddress; - /* 0x4C */ uint8_t macDSN; - /* 0x50 */ uint16_t macPANId; - /* 0x53 */ uint16_t macShortAddress; - /* 0x55 */ uint16_t macTransactionPersistenceTime; -#if 0 - /* Security MIB */ - /* 0x70 */ macACLEntryDescriptorSet - /* 0x71 */ macACLEntryDescriptorSetSize - /* 0x74 */ macDefaultSecurityMaterial - /* 0x72 */ macDefaultSecurity:1 - /* 0x75 */ macDefaultSecuritySuite:3 - /* 0x73 */ macDefaultSecurityMaterialLength:6 - /* 0x76 */ macSecurityMode:2 -#endif + struct mac802154_trans_s csma_buf[5]; + + /* Support a singly linked list of transactions that will be sent indirectly. + * This list should only be used by a MAC acting as a coordinator. These + * transactions will stay here until the data is extracted by the destination + * device sending a Data Request MAC command or if too much time passes. This + * list should also be used to populate the address list of the outgoing + * beacon frame */ + + FAR struct mac802154_trans_s *indirect_head; + FAR struct mac802154_trans_s *indirect_tail; + + FAR struct mac802154_trans_s *active_trans; + + /* MAC PIB attributes, grouped to save memory */ + + /* Holds all address information (Extended, Short, and PAN ID) for the MAC */ + + struct ieee802154_addr_s addr; + + /* Holds all address information (Extended, Short) for Coordinator */ + + struct ieee802154_addr_s coord_addr; + + /* The maximum number of symbols to wait for an acknowledgement frame to + * arrive following a transmitted data frame. [1] pg. 126 + * + * NOTE: This may be able to be a 16-bit or even an 8-bit number. I wasn't + * sure at the time what the range of reasonable values was */ + + uint32_t ack_wait_dur; + + /* The maximum time to wait either for a frame intended as a response to a + * data request frame or for a broadcast frame following a beacon with the + * Frame Pending field set to one. [1] pg. 127 + * + * NOTE: This may be able to be a 16-bit or even an 8-bit number. I wasn't + * sure at the time what the range of reasonable values was */ + + uint32_t max_frame_wait_time; + + /* The maximum time (in unit periods) that a transaction is stored by a + * coordinator and indicated in its beacon. */ + + uint16_t trans_persist_time; + + /* Contents of beacon payload */ + + uint8_t beacon_payload[IEEE802154_MAX_BEACON_PAYLOAD_LENGTH]; + uint8_t beacon_payload_len; /* Length of beacon payload */ + + uint8_t batt_life_ext_periods; /* # of backoff periods during which rx is + * enabled after the IFS following beacon */ + + uint8_t bsn; /* Seq. num added to tx beacon frame */ + uint8_t dsn; /* Seq. num added to tx data or MAC frame */ + uint8_t max_retries; /* Max # of retries alloed after tx failure */ + + /* The maximum time, in multiples of aBaseSuperframeDuration, a device shall + * wait for a response command frame to be available following a request + * command frame. [1] 128 */ + + uint8_t resp_wait_time; + + /* The total transmit duration (including PHY header and FCS) specified in + * symbols. [1] pg. 129 */ + + uint32_t tx_total_dur; + + struct + { + uint32_t is_assoc : 1; /* Are we associated to the PAN */ + uint32_t assoc_permit : 1; /* Are we allowing assoc. as a coord. */ + uint32_t auto_req : 1; /* Automatically send data req. if addr + * addr is in the beacon frame */ + + uint32_t batt_life_ext : 1; /* Is BLE enabled */ + uint32_t gts_permit : 1; /* Is PAN Coord. accepting GTS reqs. */ + uint32_t promiscuous_mode : 1; /* Is promiscuous mode on? */ + uint32_t ranging_supported : 1; /* Does MAC sublayer support ranging */ + uint32_t rx_when_idle : 1; /* Recvr. on during idle periods */ + uint32_t sec_enabled : 1; /* Does MAC sublayer have security en. */ + + uint32_t max_csma_backoffs : 3; /* Max num backoffs for CSMA algorithm + * before declaring ch access failure */ + + uint32_t beacon_order : 4; /* Freq. that beacon is transmitted */ + + uint32_t superframe_order : 4; /* Length of active portion of outgoing + * superframe, including the beacon */ + + /* The offset, measured is symbols, between the symbol boundary at which the + * MLME captures the timestamp of each transmitted and received frame, and + * the onset of the first symbol past the SFD, namely the first symbol of + * the frames [1] pg. 129 */ + + uint32_t sync_symb_offset : 12; + } + + struct + { + uint32_t beacon_tx_time : 24; /* Time of last beacon transmit */ + uint32_t min_be : 4; /* Min value of backoff exponent (BE) */ + uint32_t max_be : 4; /* Max value of backoff exponent (BE) */ + } + + struct + { + uint32_t tx_ctrl_active_dur : 17; /* Duration for which tx is permitted to + * be active */ + + uint32_t tx_ctrl_pause_dur : 1; /* Duration after tx before another tx is + * permitted. 0=2000, 1= 10000 */ + + uint32_t timestamp_support : 1; /* Does MAC layer supports timestamping */ + } + + /* TODO: Add Security-related MAC PIB attributes */ + +}; + +struct mac802154_trans_s +{ + /* Supports a singly linked list */ + + FAR struct mac802154_trans_s *flink; + + uint8_t msdu_handle; + + uint8_t *mhr_buf; + uint8_t mhr_len; + + uint8_t *d_buf; + uint8_t d_len; + + sem_t sem; +}; + +struct mac802154_unsec_mhr_s +{ + uint8_t length; + union { + uint16_t frame_control; + uint8_t data[IEEE802154_MAX_UNSEC_MHR_OVERHEAD]; + }; }; /**************************************************************************** * Private Functions ****************************************************************************/ +/**************************************************************************** + * Name: mac802154_semtake + * + * Description: + * Acquire the semaphore used for access serialization. + * + ****************************************************************************/ + +static inline int mac802154_takesem(sem_t *sem) +{ + /* Take a count from the semaphore, possibly waiting */ + + if (sem_wait(sem) < 0) + { + /* EINTR is the only error that we expect */ + + int errcode = get_errno(); + DEBUGASSERT(errcode == EINTR); + return -errcode; + } + + return OK; +} + /**************************************************************************** * Name: mac802154_defaultmib * @@ -121,41 +263,7 @@ struct ieee802154_privmac_s static int mac802154_defaultmib(FAR struct ieee802154_privmac_s *priv) { - priv->macAckWaitDuration = 0; - priv->macAssociationPermit = 0; - priv->macAutoRequest = 1; - priv->macBattLifeExt = 0; - priv->macBattLifeExtPeriods = 0; - priv->macMaxCSMABackoffs = 4; - - priv->macBeaconOrder = 15; - priv->macSuperframeOrder = 15; - - priv->macMinBE = 3; - priv->macGTSPermit = 1; - priv->macPromiscuousMode = 0; - priv->macRxOnWhenIdle = 0; - priv->macBeaconTxTime = 0x000000; - - priv->macBeaconPayloadLength = 0; - priv->macBSN = 0; /* Shall be random */ - //priv->macCoordExtendedAddress[8]; - priv->macCoordShortAddress = 0xffff; - priv->macDSN = 0; /* Shall be random */ - priv->macPANId = 0xffff; - priv->macShortAddress = 0xffff; - priv->macTransactionPersistenceTime = 0x01f4; - -#if 0 - /* Security MIB */ - - priv->macACLEntryDescriptorSetSize = 0; - priv->macDefaultSecurity = 0; - priv->macDefaultSecuritySuite = 0; - priv->macDefaultSecurityMaterialLength = 0x15; - priv->macSecurityMode = 0; -#endif - + /* TODO: Set all MAC fields to default values */ return OK; } @@ -314,7 +422,258 @@ int mac802154_ioctl(MACHANDLE mac, int cmd, unsigned long arg) int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) { FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; - return -ENOTTY; + FAR struct mac802154_trans_s *trans; + struct mac802154_unsec_mhr_s mhr; + int ret; + + /* Start off assuming there is only the frame_control field in the MHR */ + + mhr.length = 2; + + /* Do a preliminary check to make sure the MSDU isn't too long for even the + * best case */ + + if (req->msdu_length > IEEE802154_MAX_MAC_PAYLOAD_SIZE) + { + return -EINVAL; + } + + /* Ensure we start with a clear frame control field */ + + mhr.frame_control = 0; + + /* Set the frame type to Data */ + + mhr.frame_control |= IEEE802154_FRAME_DATA << IEEE802154_FRAMECTRL_SHIFT_FTYPE; + + /* If the msduLength is greater than aMaxMACSafePayloadSize, the MAC sublayer + * will set the Frame Version to one. [1] pg. 118 */ + + if (req->msdu_length > IEEE802154_MAX_SAFE_MAC_PAYLOAD_SIZE) + { + mhr.frame_ctrl |= IEEE802154_FRAMECTRL_VERSION; + } + + /* If the TXOptions parameter specifies that an acknowledged transmission is + * required, the AR field will be set appropriately, as described in + * 5.1.6.4 [1] pg. 118 */ + + mhr.frame_ctrl |= (req->ack_tx << IEEE802154_FRAMECTRL_SHIFT_ACKREQ); + + /* If the destination address is present, copy the PAN ID and one of the + * addresses, depending on mode, into the MHR */ + + if (req->dest_addr.mode != IEEE802154_ADDRMODE_NONE) + { + memcpy(&mhr.data[mhr.length], req->dest_addr.panid, 2); + mhr.length += 2; + + if (req->dest_addr.mode == IEEE802154_ADDRMODE_SHORT) + { + memcpy(&mhr.data[mhr.length], req->dest_addr.saddr, 2); + mhr.length += 2; + } + else if (req->dest_addr.mode == IEEE802154_ADDRMODE_EXTENDED) + { + memcpy(&mhr.data[mhr.length], req->dest_addr.eaddr, 8); + mhr.length += 8; + } + } + + /* Set the destination addr mode inside the frame contorl field */ + + mhr.frame_ctrl |= (req->dest_addr.mode << IEEE802154_FRAMECTRL_SHIFT_DADDR); + + /* From this point on, we need exclusive access to the privmac struct */ + + ret = mac802154dev_takesem(&dev->md_exclsem); + if (ret < 0) + { + wlerr("ERROR: mac802154_takesem failed: %d\n", ret); + return ret; + } + + /* If both destination and source addressing information is present, the MAC + * sublayer shall compare the destination and source PAN identifiers. + * [1] pg. 41 */ + + if (req->src_addr_mode != IEEE802154_ADDRMODE_NONE && + req->dest_addr.mode != IEEE802154_ADDRMODE_NONE) + { + /* If the PAN identifiers are identical, the PAN ID Compression field + * shall be set to one, and the source PAN identifier shall be omitted + * from the transmitted frame. [1] pg. 41 */ + + if(req->dest_addr.panid == priv->addr.panid) + { + mhr.frame_control |= IEEE802154_FRAMECTRL_PANIDCOMP; + } + } + + if (req->src_addr_mode != IEEE802154_ADDRMODE_NONE) + { + /* If the destination address is not included, or if PAN ID Compression + * is off, we need to include the Source PAN ID */ + + if (req->dest_addr.mode == IEEE802154_ADDRMODE_NONE || + (mhr.frame_control & IEEE802154_FRAMECTRL_PANIDCOMP) + { + memcpy(&mhr.data[mhr.length], priv->addr.panid, 2); + mhr.length += 2; + } + + if (req->src_addr_mode == IEEE802154_ADDRMODE_SHORT) + { + memcpy(&mhr.data[mhr.length], priv->addr.saddr, 2); + mhr.length += 2; + } + else if (req->src_addr_mode == IEEE802154_ADDRMODE_EXTENDED) + { + memcpy(&mhr.data[mhr.length], priv->addr.eaddr, 8); + mhr.length += 8; + } + } + + /* Set the source addr mode inside the frame contorl field */ + + mhr.frame_ctrl |= (req->src_addr_mode << IEEE802154_FRAMECTRL_SHIFT_SADDR); + + /* Each time a data or a MAC command frame is generated, the MAC sublayer + * shall copy the value of macDSN into the Sequence Number field of the MHR + * of the outgoing frame and then increment it by one. [1] pg. 40 */ + + mhr.data[mhr.length++] = priv.dsn++; + + /* Now that we know which fields are included in the header, we can make + * sure we actually have enough room in the PSDU */ + + if (mhr.length + req->msdu_length + IEEE802154_MFR_LENGTH > + IEEE802154_MAX_PHY_PACKET_SIZE) + { + return -E2BIG; + } + + trans->mhr_buf = &mhr.data[0]; + trans->mhr_len = mhr.length; + + trans->d_buf = &req->msdu[0]; + trans->d_len = req->msdu_length; + + trans->msdu_handle = req->msdu_handle; + + /* If the TxOptions parameter specifies that a GTS transmission is required, + * the MAC sublayer will determine whether it has a valid GTS as described + * 5.1.7.3. If a valid GTS could not be found, the MAC sublayer will discard + * the MSDU. If a valid GTS was found, the MAC sublayer will defer, if + * necessary, until the GTS. If the TxOptions parameter specifies that a GTS + * transmission is not required, the MAC sublayer will transmit the MSDU using + * either slotted CSMA-CA in the CAP for a beacon-enabled PAN or unslotted + * CSMA-CA for a nonbeacon-enabled PAN. Specifying a GTS transmission in the + * TxOptions parameter overrides an indirect transmission request. + * [1] pg. 118 */ + + if (req->gts_tx) + { + /* TODO: Support GTS transmission. This should just change where we link + * the transaction. Instead of going in the CSMA transaction list, it + * should be linked to the GTS' transaction list. We'll need to check if + * the GTS is valid, and then find the GTS, before linking. Note, we also + * don't have to try and kick-off any transmission here. */ + + return -ENOTSUP; + } + else + { + /* If the TxOptions parameter specifies that an indirect transmission is + * required and this primitive is received by the MAC sublayer of a + * coordinator, the data frame is sent using indirect transmission, as + * described in 5.1.5 and 5.1.6.3. [1] */ + + if (req->indirect_tx) + { + /* If the TxOptions parameter specifies that an indirect transmission + * is required and if the device receiving this primitive is not a + * coordinator, the destination address is not present, or the + * TxOptions parameter also specifies a GTS transmission, the indirect + * transmission option will be ignored. [1] */ + + if (priv->is_coord && req->dest_addr.mode != IEEE802154_ADDRMODE_NONE) + { + /* Link the transaction into the indirect_trans list */ + + priv->indirect_tail->flink = trans; + priv->indirect_tail = trans; + } + else + { + /* Override the setting since it wasn't valid */ + + req->indirect_tx = 0; + } + } + + /* If this is a direct transmission not during a GTS */ + + if (!req->indirect_tx) + { + /* Link the transaction into the CSMA transaction list */ + + priv->csma_tail->flink = trans; + priv->csma_tail = trans; + + /* Notify the radio driver that there is data available */ + + priv->radio->tx_notify(priv->radio); + + sem_wait(&trans->sem); + } + } + + return OK; +} + + +/* Called from interrupt level or worker thread with interrupts disabled */ + +static uint16_t mac802154_poll_csma(FAR struct ieee802154_phyif_s *phyif, + FAR struct ieee802154_txdesc_s *tx_desc, + uint8_t *buf) +{ + FAR struct ieee802154_privmac_s *priv = + (FAR struct ieee802154_privmac_s *)&phyif->priv; + + FAR struct mac802154_trans_s *trans; + + /* Check to see if there are any CSMA transactions waiting */ + + if (mac->csma_head) + { + /* Pop a CSMA transaction off the list */ + + trans = mac->csma_head; + mac->csma_head = mac->csma_head.flink; + + /* Setup the transmit descriptor */ + + tx_desc->psdu_handle = trans->msdu_handle; + tx_desc->psdu_length = trans->mhr_len + trans->d_len; + + /* Copy the frame into the buffer */ + + memcpy(&buf[0], trans->mhr_buf, trans->mhr_len); + memcpy(&buf[trans->mhr_len], trans->d_buf, trans->d_len); + + /* Now that we've passed off the data, notify the waiting thread. + * NOTE: The transaction was allocated on the waiting thread's stack so + * it will be automatically deallocated when that thread awakens and + * returns */ + + sem_post(trans->sem); + + return txdesc->psdu_length; + } + + return 0; } /**************************************************************************** From 141d5574f88677cbc869f72cb2d7547bf86c4072 Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Sat, 15 Apr 2017 13:24:25 -0400 Subject: [PATCH 077/183] wireless/ieee802154: Starts defining interface between PHY layer and next highest layer --- .../wireless/ieee802154/ieee802154_radio.h | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/include/nuttx/wireless/ieee802154/ieee802154_radio.h b/include/nuttx/wireless/ieee802154/ieee802154_radio.h index eef94e328f4..0a38ed04022 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_radio.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_radio.h @@ -157,19 +157,51 @@ struct ieee802154_netradio_s #endif /* IEEE802.15.4 Radio Interface Operations **********************************/ +struct ieee802154_trans_s +{ + uint8_t retry_count; /* The number of retries remaining */ + uint8_t msdu_handle; /* The msdu handle identifying the transaction */ + + uint16_t psdu_length; /* The length of the PSDU */ + + /* The PHY Service Data Unit (PSDU) buffer representing the frame to be + * transmitted. This must be at the end of the struct to allow the array + * to continue and make the struct "variable length". Users should allocate + * memory using the SIZEOF_MAC802154_TRANSACTION_S macro below */ + + uint8_t psdu[CONFIG_IEEE802154_MTU]; +}; struct ieee802154_radio_s; /* Forward reference */ +struct ieee802154_phyif_s +{ + CODE int (*poll_csma) (FAR struct ieee802154_phyif_s *phyif, + FAR struct ieee802154_txdesc_s *tx_desc, + uint8_t *buf); + + CODE int (*poll_gts) (FAR struct ieee802154_phyif_s *phyif, + FAR struct ieee802154_txdesc_s *tx_desc, + uint8_t *buf); + + /* Driver-specific information */ + + void * priv; +}; + struct ieee802154_radioops_s { + CODE int (*bind) (FAR struct ieee802154_radio_s *dev, + FAR const struct ieee802154_phyif_s *phyif); + CODE int (*ioctl)(FAR struct ieee802154_radio_s *ieee, int cmd, unsigned long arg); + CODE int (*rxenable)(FAR struct ieee802154_radio_s *dev, bool state, FAR struct ieee802154_packet_s *packet); + CODE int (*transmit)(FAR struct ieee802154_radio_s *dev, FAR struct ieee802154_packet_s *packet); - - /* TODO beacon/sf order */ }; struct ieee802154_radio_s From 16edc77965fffc0446ff9904bd1fc03f83420ef3 Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Sat, 15 Apr 2017 13:26:03 -0400 Subject: [PATCH 078/183] wireless/ieee802154: Skeleton code for request associate --- wireless/ieee802154/mac802154.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/wireless/ieee802154/mac802154.c b/wireless/ieee802154/mac802154.c index f223f8836e6..99e3f27d8aa 100644 --- a/wireless/ieee802154/mac802154.c +++ b/wireless/ieee802154/mac802154.c @@ -706,6 +706,29 @@ int mac802154_req_associate(MACHANDLE mac, FAR struct ieee802154_assoc_req_s *req) { FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; + + /* Set the channel of the PHY layer */ + + /* Set the channel page of the PHY layer */ + + /* Set the macPANId */ + + /* Set either the macCoordExtendedAddress and macCoordShortAddress + * depending on the CoordAddrMode in the primitive */ + + if (req->coord_addr.mode == IEEE802154_ADDRMODE_EXTENDED) + { + + } + else if (req->coord_addr.mode == IEEE802154_ADDRMODE_EXTENDED) + { + + } + else + { + return -EINVAL; + } + return -ENOTTY; } From 2bc758c3ebd0ddccee736e8d166fedcaeb9126ec Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Sat, 15 Apr 2017 13:44:15 -0400 Subject: [PATCH 079/183] wireless/ieee802154: Bind MAC phyif to radio --- .../wireless/ieee802154/ieee802154_radio.h | 12 ++++++++++-- wireless/ieee802154/mac802154.c | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/include/nuttx/wireless/ieee802154/ieee802154_radio.h b/include/nuttx/wireless/ieee802154/ieee802154_radio.h index 0a38ed04022..a26e3321d68 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_radio.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_radio.h @@ -172,9 +172,10 @@ struct ieee802154_trans_s uint8_t psdu[CONFIG_IEEE802154_MTU]; }; -struct ieee802154_radio_s; /* Forward reference */ -struct ieee802154_phyif_s +struct ieee802154_phyif_s; /* Forward Reference */ + +struct ieee802154_phyifops_s { CODE int (*poll_csma) (FAR struct ieee802154_phyif_s *phyif, FAR struct ieee802154_txdesc_s *tx_desc, @@ -183,12 +184,19 @@ struct ieee802154_phyif_s CODE int (*poll_gts) (FAR struct ieee802154_phyif_s *phyif, FAR struct ieee802154_txdesc_s *tx_desc, uint8_t *buf); +}; + +struct ieee802154_phyif_s +{ + FAR const struct ieee802154_phyifops_s *ops; /* Driver-specific information */ void * priv; }; +struct ieee802154_radio_s; /* Forward reference */ + struct ieee802154_radioops_s { CODE int (*bind) (FAR struct ieee802154_radio_s *dev, diff --git a/wireless/ieee802154/mac802154.c b/wireless/ieee802154/mac802154.c index 99e3f27d8aa..ffae80579f8 100644 --- a/wireless/ieee802154/mac802154.c +++ b/wireless/ieee802154/mac802154.c @@ -67,6 +67,7 @@ struct ieee802154_privmac_s { FAR struct ieee802154_radio_s *radio; /* Contained IEEE802.15.4 radio dev */ FAR const struct ieee802154_maccb_s *cb; /* Contained MAC callbacks */ + FAR struct ieee802154_phyif_s phyif; /* Interface to bind to radio */ sem_t excl_sem; /* Support exclusive access */ @@ -225,6 +226,16 @@ struct mac802154_unsec_mhr_s }; }; +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct ieee802154_phyifops_s mac802154_phyifops = +{ + mac802154_poll_csma, + mac802154_poll_gts +}; + /**************************************************************************** * Private Functions ****************************************************************************/ @@ -330,6 +341,13 @@ MACHANDLE mac802154_create(FAR struct ieee802154_radio_s *radiodev) mac802154_defaultmib(mac); mac802154_applymib(mac); + + mac->phyif.ops = &mac802154_phyifops; + mac->phyif.priv = mac; + + /* Bind our PHY interface to the radio */ + + radiodev->ops->bind(radiodev, mac->phyif); return (MACHANDLE)mac; } From 8786770d7d3eb52140cbf416639cdc7fcdd9967f Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 15 Apr 2017 15:59:00 -0600 Subject: [PATCH 080/183] Costmetic change from review of last PR --- wireless/ieee802154/mac802154.c | 191 +++++++++++++---------- wireless/ieee802154/mac802154.h | 48 +++--- wireless/ieee802154/mac802154_device.c | 64 ++++---- wireless/ieee802154/radio802154_device.c | 2 +- 4 files changed, 168 insertions(+), 137 deletions(-) diff --git a/wireless/ieee802154/mac802154.c b/wireless/ieee802154/mac802154.c index ffae80579f8..c4f99480bfb 100644 --- a/wireless/ieee802154/mac802154.c +++ b/wireless/ieee802154/mac802154.c @@ -74,11 +74,11 @@ struct ieee802154_privmac_s /* Support a singly linked list of transactions that will be sent using the * CSMA algorithm. On a non-beacon enabled PAN, these transactions will be * sent whenever. On a beacon-enabled PAN, these transactions will be sent - * during the CAP of the Coordinator's superframe. */ + * during the CAP of the Coordinator's superframe. + */ FAR struct mac802154_trans_s *csma_head; FAR struct mac802154_trans_s *csma_tail; - struct mac802154_trans_s csma_buf[5]; /* Support a singly linked list of transactions that will be sent indirectly. @@ -86,16 +86,16 @@ struct ieee802154_privmac_s * transactions will stay here until the data is extracted by the destination * device sending a Data Request MAC command or if too much time passes. This * list should also be used to populate the address list of the outgoing - * beacon frame */ - + * beacon frame. + */ + FAR struct mac802154_trans_s *indirect_head; FAR struct mac802154_trans_s *indirect_tail; - FAR struct mac802154_trans_s *active_trans; /* MAC PIB attributes, grouped to save memory */ - /* Holds all address information (Extended, Short, and PAN ID) for the MAC */ + /* Holds all address information (Extended, Short, and PAN ID) for the MAC. */ struct ieee802154_addr_s addr; @@ -107,8 +107,9 @@ struct ieee802154_privmac_s * arrive following a transmitted data frame. [1] pg. 126 * * NOTE: This may be able to be a 16-bit or even an 8-bit number. I wasn't - * sure at the time what the range of reasonable values was */ - + * sure at the time what the range of reasonable values was. + */ + uint32_t ack_wait_dur; /* The maximum time to wait either for a frame intended as a response to a @@ -116,19 +117,21 @@ struct ieee802154_privmac_s * Frame Pending field set to one. [1] pg. 127 * * NOTE: This may be able to be a 16-bit or even an 8-bit number. I wasn't - * sure at the time what the range of reasonable values was */ + * sure at the time what the range of reasonable values was. + */ uint32_t max_frame_wait_time; /* The maximum time (in unit periods) that a transaction is stored by a - * coordinator and indicated in its beacon. */ + * coordinator and indicated in its beacon. + */ uint16_t trans_persist_time; - /* Contents of beacon payload */ + /* Contents of beacon payload */ - uint8_t beacon_payload[IEEE802154_MAX_BEACON_PAYLOAD_LENGTH]; - uint8_t beacon_payload_len; /* Length of beacon payload */ + uint8_t beacon_payload[IEEE802154_MAX_BEACON_PAYLOAD_LENGTH]; + uint8_t beacon_payload_len; /* Length of beacon payload */ uint8_t batt_life_ext_periods; /* # of backoff periods during which rx is * enabled after the IFS following beacon */ @@ -138,21 +141,23 @@ struct ieee802154_privmac_s uint8_t max_retries; /* Max # of retries alloed after tx failure */ /* The maximum time, in multiples of aBaseSuperframeDuration, a device shall - * wait for a response command frame to be available following a request - * command frame. [1] 128 */ + * wait for a response command frame to be available following a request + * command frame. [1] 128. + */ uint8_t resp_wait_time; /* The total transmit duration (including PHY header and FCS) specified in - * symbols. [1] pg. 129 */ + * symbols. [1] pg. 129. + */ uint32_t tx_total_dur; struct - { + { uint32_t is_assoc : 1; /* Are we associated to the PAN */ uint32_t assoc_permit : 1; /* Are we allowing assoc. as a coord. */ - uint32_t auto_req : 1; /* Automatically send data req. if addr + uint32_t auto_req : 1; /* Automatically send data req. if addr * addr is in the beacon frame */ uint32_t batt_life_ext : 1; /* Is BLE enabled */ @@ -170,11 +175,12 @@ struct ieee802154_privmac_s uint32_t superframe_order : 4; /* Length of active portion of outgoing * superframe, including the beacon */ - /* The offset, measured is symbols, between the symbol boundary at which the + /* The offset, measured is symbols, between the symbol boundary at which the * MLME captures the timestamp of each transmitted and received frame, and * the onset of the first symbol past the SFD, namely the first symbol of - * the frames [1] pg. 129 */ - + * the frames [1] pg. 129. + */ + uint32_t sync_symb_offset : 12; } @@ -187,17 +193,14 @@ struct ieee802154_privmac_s struct { - uint32_t tx_ctrl_active_dur : 17; /* Duration for which tx is permitted to + uint32_t tx_ctrl_active_dur : 17; /* Duration for which tx is permitted to * be active */ - uint32_t tx_ctrl_pause_dur : 1; /* Duration after tx before another tx is * permitted. 0=2000, 1= 10000 */ - uint32_t timestamp_support : 1; /* Does MAC layer supports timestamping */ } /* TODO: Add Security-related MAC PIB attributes */ - }; struct mac802154_trans_s @@ -220,7 +223,8 @@ struct mac802154_trans_s struct mac802154_unsec_mhr_s { uint8_t length; - union { + union + { uint16_t frame_control; uint8_t data[IEEE802154_MAX_UNSEC_MHR_OVERHEAD]; }; @@ -309,9 +313,9 @@ static int mac802154_applymib(FAR struct ieee802154_privmac_s *priv) * should register a set of callbacks with the MAC layer by setting the * mac->cbs member. * - * NOTE: 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. + * NOTE: 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. * * Input Parameters: * radiodev - an instance of an IEEE 802.15.4 radio @@ -341,7 +345,7 @@ MACHANDLE mac802154_create(FAR struct ieee802154_radio_s *radiodev) mac802154_defaultmib(mac); mac802154_applymib(mac); - + mac->phyif.ops = &mac802154_phyifops; mac->phyif.priv = mac; @@ -431,7 +435,7 @@ int mac802154_ioctl(MACHANDLE mac, int cmd, unsigned long arg) * * Description: * The MCPS-DATA.request primitive requests the transfer of a data SPDU - * (i.e., MSDU) from a local SSCS entity to a single peer SSCS entity. + * (i.e., MSDU) from a local SSCS entity to a single peer SSCS entity. * Confirmation is returned via the * struct ieee802154_maccb_s->conf_data callback. * @@ -439,7 +443,8 @@ int mac802154_ioctl(MACHANDLE mac, int cmd, unsigned long arg) int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) { - FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; + FAR struct ieee802154_privmac_s *priv = + (FAR struct ieee802154_privmac_s *)mac; FAR struct mac802154_trans_s *trans; struct mac802154_unsec_mhr_s mhr; int ret; @@ -450,7 +455,7 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) /* Do a preliminary check to make sure the MSDU isn't too long for even the * best case */ - + if (req->msdu_length > IEEE802154_MAX_MAC_PAYLOAD_SIZE) { return -EINVAL; @@ -465,7 +470,8 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) mhr.frame_control |= IEEE802154_FRAME_DATA << IEEE802154_FRAMECTRL_SHIFT_FTYPE; /* If the msduLength is greater than aMaxMACSafePayloadSize, the MAC sublayer - * will set the Frame Version to one. [1] pg. 118 */ + * will set the Frame Version to one. [1] pg. 118. + */ if (req->msdu_length > IEEE802154_MAX_SAFE_MAC_PAYLOAD_SIZE) { @@ -474,13 +480,15 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) /* If the TXOptions parameter specifies that an acknowledged transmission is * required, the AR field will be set appropriately, as described in - * 5.1.6.4 [1] pg. 118 */ + * 5.1.6.4 [1] pg. 118. + */ mhr.frame_ctrl |= (req->ack_tx << IEEE802154_FRAMECTRL_SHIFT_ACKREQ); - /* If the destination address is present, copy the PAN ID and one of the - * addresses, depending on mode, into the MHR */ - + /* If the destination address is present, copy the PAN ID and one of the + * addresses, depending on mode, into the MHR . + */ + if (req->dest_addr.mode != IEEE802154_ADDRMODE_NONE) { memcpy(&mhr.data[mhr.length], req->dest_addr.panid, 2); @@ -497,7 +505,7 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) mhr.length += 8; } } - + /* Set the destination addr mode inside the frame contorl field */ mhr.frame_ctrl |= (req->dest_addr.mode << IEEE802154_FRAMECTRL_SHIFT_DADDR); @@ -512,15 +520,17 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) } /* If both destination and source addressing information is present, the MAC - * sublayer shall compare the destination and source PAN identifiers. - * [1] pg. 41 */ + * sublayer shall compare the destination and source PAN identifiers. + * [1] pg. 41. + */ if (req->src_addr_mode != IEEE802154_ADDRMODE_NONE && req->dest_addr.mode != IEEE802154_ADDRMODE_NONE) { /* If the PAN identifiers are identical, the PAN ID Compression field * shall be set to one, and the source PAN identifier shall be omitted - * from the transmitted frame. [1] pg. 41 */ + * from the transmitted frame. [1] pg. 41. + */ if(req->dest_addr.panid == priv->addr.panid) { @@ -531,7 +541,8 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) if (req->src_addr_mode != IEEE802154_ADDRMODE_NONE) { /* If the destination address is not included, or if PAN ID Compression - * is off, we need to include the Source PAN ID */ + * is off, we need to include the Source PAN ID. + */ if (req->dest_addr.mode == IEEE802154_ADDRMODE_NONE || (mhr.frame_control & IEEE802154_FRAMECTRL_PANIDCOMP) @@ -558,13 +569,15 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) /* Each time a data or a MAC command frame is generated, the MAC sublayer * shall copy the value of macDSN into the Sequence Number field of the MHR - * of the outgoing frame and then increment it by one. [1] pg. 40 */ + * of the outgoing frame and then increment it by one. [1] pg. 40. + */ mhr.data[mhr.length++] = priv.dsn++; /* Now that we know which fields are included in the header, we can make - * sure we actually have enough room in the PSDU */ - + * sure we actually have enough room in the PSDU. + */ + if (mhr.length + req->msdu_length + IEEE802154_MFR_LENGTH > IEEE802154_MAX_PHY_PACKET_SIZE) { @@ -579,16 +592,17 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) trans->msdu_handle = req->msdu_handle; - /* If the TxOptions parameter specifies that a GTS transmission is required, - * the MAC sublayer will determine whether it has a valid GTS as described + /* If the TxOptions parameter specifies that a GTS transmission is required, + * the MAC sublayer will determine whether it has a valid GTS as described * 5.1.7.3. If a valid GTS could not be found, the MAC sublayer will discard - * the MSDU. If a valid GTS was found, the MAC sublayer will defer, if + * the MSDU. If a valid GTS was found, the MAC sublayer will defer, if * necessary, until the GTS. If the TxOptions parameter specifies that a GTS * transmission is not required, the MAC sublayer will transmit the MSDU using * either slotted CSMA-CA in the CAP for a beacon-enabled PAN or unslotted * CSMA-CA for a nonbeacon-enabled PAN. Specifying a GTS transmission in the * TxOptions parameter overrides an indirect transmission request. - * [1] pg. 118 */ + * [1] pg. 118. + */ if (req->gts_tx) { @@ -596,7 +610,8 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) * the transaction. Instead of going in the CSMA transaction list, it * should be linked to the GTS' transaction list. We'll need to check if * the GTS is valid, and then find the GTS, before linking. Note, we also - * don't have to try and kick-off any transmission here. */ + * don't have to try and kick-off any transmission here. + */ return -ENOTSUP; } @@ -605,17 +620,19 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) /* If the TxOptions parameter specifies that an indirect transmission is * required and this primitive is received by the MAC sublayer of a * coordinator, the data frame is sent using indirect transmission, as - * described in 5.1.5 and 5.1.6.3. [1] */ + * described in 5.1.5 and 5.1.6.3. [1] + */ if (req->indirect_tx) { /* If the TxOptions parameter specifies that an indirect transmission * is required and if the device receiving this primitive is not a - * coordinator, the destination address is not present, or the + * coordinator, the destination address is not present, or the * TxOptions parameter also specifies a GTS transmission, the indirect - * transmission option will be ignored. [1] */ + * transmission option will be ignored. [1] + */ - if (priv->is_coord && req->dest_addr.mode != IEEE802154_ADDRMODE_NONE) + if (priv->is_coord && req->dest_addr.mode != IEEE802154_ADDRMODE_NONE) { /* Link the transaction into the indirect_trans list */ @@ -653,11 +670,11 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) /* Called from interrupt level or worker thread with interrupts disabled */ -static uint16_t mac802154_poll_csma(FAR struct ieee802154_phyif_s *phyif, +static uint16_t mac802154_poll_csma(FAR struct ieee802154_phyif_s *phyif, FAR struct ieee802154_txdesc_s *tx_desc, uint8_t *buf) { - FAR struct ieee802154_privmac_s *priv = + FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)&phyif->priv; FAR struct mac802154_trans_s *trans; @@ -684,7 +701,8 @@ static uint16_t mac802154_poll_csma(FAR struct ieee802154_phyif_s *phyif, /* Now that we've passed off the data, notify the waiting thread. * NOTE: The transaction was allocated on the waiting thread's stack so * it will be automatically deallocated when that thread awakens and - * returns */ + * returns. + */ sem_post(trans->sem); @@ -698,15 +716,16 @@ static uint16_t mac802154_poll_csma(FAR struct ieee802154_phyif_s *phyif, * Name: mac802154_req_purge * * Description: - * The MCPS-PURGE.request primitive allows the next higher layer to purge an - * MSDU from the transaction queue. Confirmation is returned via + * The MCPS-PURGE.request primitive allows the next higher layer to purge + * an MSDU from the transaction queue. Confirmation is returned via * the struct ieee802154_maccb_s->conf_purge callback. * ****************************************************************************/ int mac802154_req_purge(MACHANDLE mac, uint8_t handle) { - FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; + FAR struct ieee802154_privmac_s *priv = + (FAR struct ieee802154_privmac_s *)mac; return -ENOTTY; } @@ -714,7 +733,7 @@ int mac802154_req_purge(MACHANDLE mac, uint8_t handle) * Name: mac802154_req_associate * * Description: - * The MLME-ASSOCIATE.request primitive allows a device to request an + * The MLME-ASSOCIATE.request primitive allows a device to request an * association with a coordinator. Confirmation is returned via the * struct ieee802154_maccb_s->conf_associate callback. * @@ -723,7 +742,8 @@ int mac802154_req_purge(MACHANDLE mac, uint8_t handle) int mac802154_req_associate(MACHANDLE mac, FAR struct ieee802154_assoc_req_s *req) { - FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; + FAR struct ieee802154_privmac_s *priv = + (FAR struct ieee802154_privmac_s *)mac; /* Set the channel of the PHY layer */ @@ -737,12 +757,12 @@ int mac802154_req_associate(MACHANDLE mac, if (req->coord_addr.mode == IEEE802154_ADDRMODE_EXTENDED) { - } + } else if (req->coord_addr.mode == IEEE802154_ADDRMODE_EXTENDED) { } - else + else { return -EINVAL; } @@ -765,7 +785,8 @@ int mac802154_req_associate(MACHANDLE mac, int mac802154_req_disassociate(MACHANDLE mac, FAR struct ieee802154_disassoc_req_s *req) { - FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; + FAR struct ieee802154_privmac_s *priv = + (FAR struct ieee802154_privmac_s *)mac; return -ENOTTY; } @@ -781,7 +802,8 @@ int mac802154_req_disassociate(MACHANDLE mac, int mac802154_req_get(MACHANDLE mac, enum ieee802154_pib_attr_e attr) { - FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; + FAR struct ieee802154_privmac_s *priv = + (FAR struct ieee802154_privmac_s *)mac; return -ENOTTY; } @@ -798,7 +820,8 @@ int mac802154_req_get(MACHANDLE mac, enum ieee802154_pib_attr_e attr) int mac802154_req_gts(MACHANDLE mac, FAR uint8_t *characteristics) { - FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; + FAR struct ieee802154_privmac_s *priv = + (FAR struct ieee802154_privmac_s *)mac; return -ENOTTY; } @@ -814,7 +837,8 @@ int mac802154_req_gts(MACHANDLE mac, FAR uint8_t *characteristics) int mac802154_req_reset(MACHANDLE mac, bool setdefaults) { - FAR struct ieee802154_privmac_s * priv = (FAR struct ieee802154_privmac_s *) mac; + FAR struct ieee802154_privmac_s * priv = + (FAR struct ieee802154_privmac_s *) mac; return -ENOTTY; } @@ -832,7 +856,8 @@ int mac802154_req_reset(MACHANDLE mac, bool setdefaults) int mac802154_req_rxenable(MACHANDLE mac, bool deferrable, int ontime, int duration) { - FAR struct ieee802154_privmac_s * priv = (FAR struct ieee802154_privmac_s *)mac; + FAR struct ieee802154_privmac_s * priv = + (FAR struct ieee802154_privmac_s *)mac; return -ENOTTY; } @@ -854,7 +879,8 @@ int mac802154_req_rxenable(MACHANDLE mac, bool deferrable, int ontime, int mac802154_req_scan(MACHANDLE mac, uint8_t type, uint32_t channels, int duration) { - FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; + FAR struct ieee802154_privmac_s *priv = + (FAR struct ieee802154_privmac_s *)mac; return -ENOTTY; } @@ -871,7 +897,8 @@ int mac802154_req_scan(MACHANDLE mac, uint8_t type, uint32_t channels, int mac802154_req_set(MACHANDLE mac, int attribute, FAR uint8_t *value, int valuelen) { - FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; + FAR struct ieee802154_privmac_s *priv = + (FAR struct ieee802154_privmac_s *)mac; return -ENOTTY; } @@ -889,7 +916,8 @@ int mac802154_req_start(MACHANDLE mac, uint16_t panid, int channel, uint8_t bo, uint8_t fo, bool coord, bool batext, bool realign) { - FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; + FAR struct ieee802154_privmac_s *priv = + (FAR struct ieee802154_privmac_s *)mac; return -ENOTTY; } @@ -906,7 +934,8 @@ int mac802154_req_start(MACHANDLE mac, uint16_t panid, int channel, int mac802154_req_sync(MACHANDLE mac, int channel, bool track) { - FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; + FAR struct ieee802154_privmac_s *priv = + (FAR struct ieee802154_privmac_s *)mac; return -ENOTTY; } @@ -914,8 +943,8 @@ int mac802154_req_sync(MACHANDLE mac, int channel, bool track) * Name: mac802154_req_poll * * Description: - * The MLME-POLL.request primitive prompts the device to request data from the - * coordinator. Confirmation is returned via the + * The MLME-POLL.request primitive prompts the device to request data from + * the coordinator. Confirmation is returned via the * struct ieee802154_maccb_s->conf_poll callback, followed by a * struct ieee802154_maccb_s->ind_data callback. * @@ -923,7 +952,8 @@ int mac802154_req_sync(MACHANDLE mac, int channel, bool track) int mac802154_req_poll(MACHANDLE mac, FAR uint8_t *coordaddr) { - FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; + FAR struct ieee802154_privmac_s *priv = + (FAR struct ieee802154_privmac_s *)mac; return -ENOTTY; } @@ -931,15 +961,16 @@ int mac802154_req_poll(MACHANDLE mac, FAR uint8_t *coordaddr) * Name: mac802154_rsp_associate * * Description: - * The MLME-ASSOCIATE.response primitive is used to initiate a response to an - * MLME-ASSOCIATE.indication primitive. + * The MLME-ASSOCIATE.response primitive is used to initiate a response to + * an MLME-ASSOCIATE.indication primitive. * ****************************************************************************/ int mac802154_rsp_associate(MACHANDLE mac, uint8_t eadr, uint16_t saddr, int status) { - FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; + FAR struct ieee802154_privmac_s *priv = + (FAR struct ieee802154_privmac_s *)mac; return -ENOTTY; } diff --git a/wireless/ieee802154/mac802154.h b/wireless/ieee802154/mac802154.h index 8321e905ea9..3b2cd1de5a8 100644 --- a/wireless/ieee802154/mac802154.h +++ b/wireless/ieee802154/mac802154.h @@ -102,7 +102,7 @@ int mac802154_ioctl(MACHANDLE mac, int cmd, unsigned long arg); * * Description: * The MCPS-DATA.request primitive requests the transfer of a data SPDU - * (i.e., MSDU) from a local SSCS entity to a single peer SSCS entity. + * (i.e., MSDU) from a local SSCS entity to a single peer SSCS entity. * Confirmation is returned via the * struct ieee802154_maccb_s->conf_data callback. * @@ -114,8 +114,8 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req); * Name: mac802154_req_purge * * Description: - * The MCPS-PURGE.request primitive allows the next higher layer to purge an - * MSDU from the transaction queue. Confirmation is returned via + * The MCPS-PURGE.request primitive allows the next higher layer to purge + * an MSDU from the transaction queue. Confirmation is returned via * the struct ieee802154_maccb_s->conf_purge callback. * ****************************************************************************/ @@ -126,7 +126,7 @@ int mac802154_req_purge(MACHANDLE mac, uint8_t handle); * Name: mac802154_req_associate * * Description: - * The MLME-ASSOCIATE.request primitive allows a device to request an + * The MLME-ASSOCIATE.request primitive allows a device to request an * association with a coordinator. Confirmation is returned via the * struct ieee802154_maccb_s->conf_associate callback. * @@ -139,9 +139,11 @@ int mac802154_req_associate(MACHANDLE mac, * Name: mac802154_req_disassociate * * Description: - * The MLME-DISASSOCIATE.request primitive is used by an associated device to - * notify the coordinator of its intent to leave the PAN. It is also used by - * the coordinator to instruct an associated device to leave the PAN. + * The MLME-DISASSOCIATE.request primitive is used by an associated device + * to notify the coordinator of its intent to leave the PAN. It is also + * used by the coordinator to instruct an associated device to leave the + * PAN. + * * Confirmation is returned via the * struct ieee802154_maccb_s->conf_disassociate callback. * @@ -166,8 +168,8 @@ int mac802154_req_get(MACHANDLE mac, enum ieee802154_pib_attr_e attr); * Name: mac802154_req_gts * * Description: - * The MLME-GTS.request primitive allows a device to send a request to the PAN - * coordinator to allocate a new GTS or to deallocate an existing GTS. + * The MLME-GTS.request primitive allows a device to send a request to the + * PAN coordinator to allocate a new GTS or to deallocate an existing GTS. * Confirmation is returned via the * struct ieee802154_maccb_s->conf_gts callback. * @@ -205,14 +207,14 @@ int mac802154_req_rxenable(MACHANDLE mac, bool deferrable, int ontime, * Name: mac802154_req_scan * * Description: - * The MLME-SCAN.request primitive is used to initiate a channel scan over a - * given list of channels. A device can use a channel scan to measure the - * energy on the channel, search for the coordinator with which it associated, - * or search for all coordinators transmitting beacon frames within the POS of - * the scanning device. Scan results are returned - * via MULTIPLE calls to the struct ieee802154_maccb_s->conf_scan callback. - * This is a difference with the official 802.15.4 specification, implemented - * here to save memory. + * The MLME-SCAN.request primitive is used to initiate a channel scan over + * a given list of channels. A device can use a channel scan to measure + * the energy on the channel, search for the coordinator with which it + * associated, or search for all coordinators transmitting beacon frames + * within the POS of the scanning device. Scan results are returned + * via MULTIPLE calls to the struct ieee802154_maccb_s->conf_scan + * callback. This is a difference with the official 802.15.4 + * specification, implemented here to save memory. * ****************************************************************************/ @@ -236,8 +238,8 @@ int mac802154_req_set(MACHANDLE mac, int attribute, FAR uint8_t *value, * Name: mac802154_req_start * * Description: - * The MLME-START.request primitive makes a request for the device to start - * using a new superframe configuration. Confirmation is returned + * The MLME-START.request primitive makes a request for the device to + * start using a new superframe configuration. Confirmation is returned * via the struct ieee802154_maccb_s->conf_start callback. * ****************************************************************************/ @@ -263,8 +265,8 @@ int mac802154_req_sync(MACHANDLE mac, int channel, bool track); * Name: mac802154_req_poll * * Description: - * The MLME-POLL.request primitive prompts the device to request data from the - * coordinator. Confirmation is returned via the + * The MLME-POLL.request primitive prompts the device to request data from + * the coordinator. Confirmation is returned via the * struct ieee802154_maccb_s->conf_poll callback, followed by a * struct ieee802154_maccb_s->ind_data callback. * @@ -276,8 +278,8 @@ int mac802154_req_poll(MACHANDLE mac, FAR uint8_t *coordaddr); * Name: mac802154_rsp_associate * * Description: - * The MLME-ASSOCIATE.response primitive is used to initiate a response to an - * MLME-ASSOCIATE.indication primitive. + * The MLME-ASSOCIATE.response primitive is used to initiate a response to + * an MLME-ASSOCIATE.indication primitive. * ****************************************************************************/ diff --git a/wireless/ieee802154/mac802154_device.c b/wireless/ieee802154/mac802154_device.c index 67631e7c63b..b35049e9ace 100644 --- a/wireless/ieee802154/mac802154_device.c +++ b/wireless/ieee802154/mac802154_device.c @@ -83,12 +83,11 @@ struct mac802154_devwrapper_s struct mac802154dev_notify_s md_mcps_notify; pid_t md_mcps_pid; - + /* MLME Service notification information */ struct mac802154dev_notify_s md_mlme_notify; pid_t md_mlme_pid; - #endif }; @@ -228,7 +227,7 @@ static int mac802154dev_open(FAR struct file *filep) ret = -ENOMEM; goto errout_with_sem; } - + /* Attach the open struct to the device */ opriv->md_flink = dev->md_open; @@ -413,7 +412,7 @@ static ssize_t mac802154dev_write(FAR struct file *filep, wlerr("ERROR: buffer too small: %lu\n", (unsigned long)len); return -EINVAL; } - + DEBUGASSERT(buffer != NULL); frame = (FAR struct ieee802154_frame_s *)buffer; @@ -441,7 +440,7 @@ static ssize_t mac802154dev_write(FAR struct file *filep, mac802154dev_givesem(&dev->md_exclsem); - if (ret < 0) + if (ret < 0) { wlerr("ERROR: req_data failed %d\n", ret); return ret; @@ -449,7 +448,7 @@ static ssize_t mac802154dev_write(FAR struct file *filep, /* Wait for the DATA.confirm callback to be called for our handle */ - if(sem_wait(dwait.mw_sem) < 0) + if (sem_wait(dwait.mw_sem) < 0) { /* This should only happen if the wait was canceled by an signal */ @@ -522,10 +521,11 @@ static int mac802154dev_ioctl(FAR struct file *filep, int cmd, dev->md_mlme_notify.mn_signo = notify->mn_signo; dev->md_mlme_pid = getpid(); - return OK; + return OK; } } break; + case MAC802154IOC_MCPS_REGISTER: { FAR struct mac802154dev_notify_s *notify = @@ -538,19 +538,19 @@ static int mac802154dev_ioctl(FAR struct file *filep, int cmd, dev->md_mcps_notify.mn_signo = notify->mn_signo; dev->md_mcps_pid = getpid(); - return OK; + return OK; } } break; #endif + case MAC802154IOC_MLME_ASSOC_REQUEST: { FAR struct ieee802154_assoc_req_s *req = (FAR struct ieee802154_assoc_req_s *)((uintptr_t)arg); - - } break; + default: wlerr("ERROR: Unrecognized command %ld\n", cmd); ret = -EINVAL; @@ -578,7 +578,7 @@ void mac802154dev_conf_data(MACHANDLE mac, /* Get exclusive access to the driver structure. We don't care about any * signals so if we see one, just go back to trying to get access again */ - + while(mac802154dev_takesem(&dev->md_exclsem) != OK); /* Search to see if there is a dwait pending for this transaction */ @@ -586,37 +586,36 @@ void mac802154dev_conf_data(MACHANDLE mac, for (prev = NULL, curr = dev->md_dwait; curr && curr->mw_handle != conf->msdu_handle; prev = curr, curr = curr->mw_flink); - + /* If a dwait is found */ if (curr) - { - /* Unlink the structure from the list. The struct should be allocated on - * the calling write's stack, so we don't need to worry about deallocating - * here */ + { + /* Unlink the structure from the list. The struct should be allocated on + * the calling write's stack, so we don't need to worry about deallocating + * here */ - if (prev) - { - prev->mw_flink = curr->mw_flink; - } - else - { - dev->md_dwait = curr->mw_flink; - } - - /* Copy the transmission status into the dwait struct */ + if (prev) + { + prev->mw_flink = curr->mw_flink; + } + else + { + dev->md_dwait = curr->mw_flink; + } - curr->mw_status = conf->msdu_handle; + /* Copy the transmission status into the dwait struct */ - /* Wake the thread waiting for the data transmission */ + curr->mw_status = conf->msdu_handle; - sem_post(&curr->mw_sem); + /* Wake the thread waiting for the data transmission */ - /* Release the driver */ + sem_post(&curr->mw_sem); - mac802154dev_givesem(&dev->md_exclsem); - } + /* Release the driver */ + mac802154dev_givesem(&dev->md_exclsem); + } #ifndef CONFIG_DISABLE_SIGNALS /* Send a signal to the registered application */ @@ -631,7 +630,6 @@ void mac802154dev_conf_data(MACHANDLE mac, (void)sigqueue(dev->md_mcps_pid, dev->md_mcps_notify.mn_signo, value.sival_ptr); #endif - #endif } diff --git a/wireless/ieee802154/radio802154_device.c b/wireless/ieee802154/radio802154_device.c index ac76283c7d7..15f4d1d84e3 100644 --- a/wireless/ieee802154/radio802154_device.c +++ b/wireless/ieee802154/radio802154_device.c @@ -261,7 +261,7 @@ static ssize_t radio802154dev_read(FAR struct file *filep, FAR char *buffer, siz goto done; } #endif - + /* if no packet is received, this will produce -EAGAIN * The user is responsible for sleeping until sth arrives */ From bbeadc2274e4a2d6717b414e0d418ca14d888898 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 16 Apr 2017 07:50:11 -0600 Subject: [PATCH 081/183] 6loWPAN network driver: Still only a skeleton but has some added though experimentation. --- wireless/ieee802154/mac802154_netdev.c | 130 +++++++++++++++++++------ 1 file changed, 101 insertions(+), 29 deletions(-) diff --git a/wireless/ieee802154/mac802154_netdev.c b/wireless/ieee802154/mac802154_netdev.c index d27daf3ef33..8768c3ee74f 100644 --- a/wireless/ieee802154/mac802154_netdev.c +++ b/wireless/ieee802154/mac802154_netdev.c @@ -130,16 +130,26 @@ struct macnet_driver_s /* This holds the information visible to the NuttX network */ struct ieee802154_driver_s md_dev; /* Interface understood by the network */ - struct macnet_callback_s md_cb; /* Callback information */ - MACHANDLE md_mac; /* Contained MAC interface */ /* For internal use by this driver */ - bool md_bifup; /* true:ifup false:ifdown */ - WDOG_ID md_txpoll; /* TX poll timer */ - WDOG_ID md_txtimeout; /* TX timeout timer */ - struct work_s md_irqwork; /* For deferring interupt work to the work queue */ - struct work_s md_pollwork; /* For deferring poll work to the work queue */ + struct macnet_callback_s md_cb; /* Callback information */ + MACHANDLE md_mac; /* Contained MAC interface */ + bool md_bifup; /* true:ifup false:ifdown */ + WDOG_ID md_txpoll; /* TX poll timer */ + WDOG_ID md_txtimeout; /* TX timeout timer */ + struct work_s md_irqwork; /* Defer interupt work to the work queue */ + struct work_s md_pollwork; /* Defer poll work to the work queue */ + + /* This is queue of outgoing, ready-to-send frames that will be sent + * indirectly. This list should only be used by a MAC acting as a + * coordinator. These transactions will stay here until the data is + * extracted by the destination device sending a Data Request MAC + * command or if too much time passes. + */ + + FAR volatile struct iob_s *md_head; + FAR volatile struct iob_s *md_tail; }; /**************************************************************************** @@ -583,8 +593,9 @@ static void macnet_ind_syncloss(MACHANDLE mac, int reason) * Name: macnet_transmit * * Description: - * Start hardware transmission. Called either from the txdone interrupt - * handling or from watchdog based polling. + * This function is called from the lower MAC layer when thre radio device + * is ready to accept another outgoing frame. It removes one of the + * previously queued fram IOBs and provides that to the MAC layer. * * Parameters: * priv - Reference to the driver state structure @@ -593,31 +604,85 @@ static void macnet_ind_syncloss(MACHANDLE mac, int reason) * OK on success; a negated errno on failure * * Assumptions: + * May or may not be called from an interrupt handler. + * + ****************************************************************************/ + +static int macnet_transmit(FAR struct macnet_driver_s *priv) +{ + /* Cancel the TX timeout watchdog + * + * REVISIT: Is there not a race condition here? Might the TX timeout + * already be queued?. + */ + + wd_cancel(priv->md_txtimeout); + + /* Increment statistics */ + + NETDEV_TXPACKETS(priv->md_dev); + + /* Provide the pre-formatted packet to the radio device (via the lower MAC + * layer). + */ +#warning Missing logic + + /* Setup the TX timeout watchdog (perhaps restarting the timer) */ + + (void)wd_start(priv->md_txtimeout, skeleton_TXTIMEOUT, + macnet_txtimeout_expiry, 1, (wdparm_t)priv); + return OK; +} + +/**************************************************************************** + * Name: macnet_txqueue + * + * Description: + * Add new frames from the network to the list of outgoing frames. + * + * Parameters: + * dev - Reference to the NuttX driver state structure + * + * Returned Value: + * OK on success; a negated errno on failure + * + * Assumptions: * May or may not be called from an interrupt handler. In either case, * the network is locked. * ****************************************************************************/ -static int macnet_transmit(FAR struct macnet_driver_s *priv) +static void macnet_txqueue(FAR struct net_driver_s *dev) { - /* Verify that the hardware is ready to send another packet. If we get - * here, then we are committed to sending a packet; Higher level logic - * must have assured that there is no transmission in progress. - */ + /* Check if there is a new list of outgoing frames from the network. */ - /* Increment statistics */ + if (priv->lo_ieee.i_framelist != NULL) + { + /* Yes.. Remove the frame list from the driver structure */ - NETDEV_TXPACKETS(priv->md_dev); + iob = priv->lo_ieee.i_framelist; + priv->lo_ieee.i_framelist = NULL; - /* Send the packet: address=priv->md_dev.d_buf, length=priv->md_dev.d_len */ + /* Append the new list to the tail of the queue of outgoing frames. */ - /* Enable Tx interrupts */ + if (priv->md_tail == NULL) + { + priv->md_head = iob; + } + else + { + priv->md_tail->io_flink = iob; + } - /* Setup the TX timeout watchdog (perhaps restarting the timer) */ + /* Find the new tail of the outgoing frame queue */ - (void)wd_start(priv->md_txtimeout, skeleton_TXTIMEOUT, - macnet_txtimeout_expiry, 1, (wdparm_t)priv); - return OK; + for (priv->md_tail = iob, iob = iob->io_flink; + iob != NULL; + priv->md_tail = iob, iob = iob->io_flink); + + /* Notify the radio driver that there is data available */ +#warning Missing logic + } } /**************************************************************************** @@ -646,17 +711,21 @@ static int macnet_transmit(FAR struct macnet_driver_s *priv) static int macnet_txpoll(FAR struct net_driver_s *dev) { - FAR struct macnet_driver_s *priv = (FAR struct macnet_driver_s *)dev->d_private; + FAR struct macnet_driver_s *priv = + (FAR struct macnet_driver_s *)dev->d_private; + FAR struct iob_s *iob; /* If the polling resulted in data that should be sent out, the field * i_framelist will set to a new, outgoing list of frames. */ - if (priv->md_dev.i_framelist != NULL) + if (priv->lo_ieee.i_framelist != NULL) { - /* And send the packet */ + /* Remove the frame list from the driver structure and append it to + * the tail of the ist of outgoing frames. + */ - macnet_transmit(priv); + macnet_txqueue(priv); } /* If zero is returned, the polling will continue until all connections have @@ -711,14 +780,17 @@ static void macnet_receive(FAR struct macnet_driver_s *priv) sixlowpan_input(&priv->md_dev); /* If the above function invocation resulted in data that should be sent - * out, the field i_framelist will set to a new, outgoing list of frames. + * out, the field i_framelist will have been set to a new, outgoing list + * of frames. */ if (priv->md_dev.i_framelist != NULL) { - /* And send the packet */ + /* Remove the frame list from the driver structure and append it to + * the tail of the ist of outgoing frames. + */ - macnet_transmit(priv); + macnet_txqueue(priv); } } From 46d7a4bb0389db061579d2c6f554136d28c34a1d Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Mon, 17 Apr 2017 11:27:14 -0400 Subject: [PATCH 082/183] wireless/ieee802154: Continues development on transmit structure --- drivers/wireless/ieee802154/mrf24j40.c | 121 +++++++++++++----- .../wireless/ieee802154/ieee802154_radio.h | 28 +--- wireless/ieee802154/mac802154.c | 65 +++++----- 3 files changed, 130 insertions(+), 84 deletions(-) diff --git a/drivers/wireless/ieee802154/mrf24j40.c b/drivers/wireless/ieee802154/mrf24j40.c index 32da714bcad..3659fe1651e 100644 --- a/drivers/wireless/ieee802154/mrf24j40.c +++ b/drivers/wireless/ieee802154/mrf24j40.c @@ -125,12 +125,19 @@ struct mrf24j40_radio_s /* Buffer Allocations */ - struct ieee802154_txdesc_s csma_desc; - struct ieee802154_txdesc_s gts_desc[2]; + struct mrf24j40_txdesc_s csma_desc; + struct mrf24j40_txdesc_s gts_desc[2]; uint8_t tx_buf[CONFIG_IEEE802154_MTU]; }; +struct mrf24j40_txdesc_s +{ + struct ieee802154_txdesc_s ieee_desc; + + uint8_t busy : 1; /* Is this txdesc being used */ +}; + /**************************************************************************** * Private Function Prototypes ****************************************************************************/ @@ -218,7 +225,8 @@ static const struct ieee802154_radioops_s mrf24j40_devops = mrf24j40_bind, mrf24j40_ioctl, mrf24j40_rxenable, - mrf24j40_transmit + mrf24j40_txnotify_csma, + mrf24j40_txnotify_gts, }; /**************************************************************************** @@ -236,51 +244,104 @@ static void mrf24j40_bind(FAR struct ieee802154_radio_s *radio, } /**************************************************************************** - * Function: mrf24j40_txavail + * Function: mrf24j40_dopoll_csma * * Description: - * Called from the upper layer, this function is to notify the device that - * the upper layer has a pending transaction. This function checks to see - * if there is availability for the corresponding transaction type. If - * there is, the function will call to the MAC layer to get the transaction - * and then start the transmission + * This function is called in order to preform an out-of-sequence TX poll. + * This is done: + * + * 1. After completion of a CSMA transmission + * 2. When the upper layer calls txnotify_csma + * + * Parameters: + * radio - Reference to the radio driver state structure + * + * Returned Value: + * None + * + * Assumptions: * ****************************************************************************/ -static void mrf24j40_txavail(FAR struct ieee802154_radio_s *radio, bool gts) +static void mrf24j40_dopoll_csma(FAR struct ieee802154_radio_s *radio) { FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)radio; - uint8_t gts; - while (sem_wait(dev->exclsem) < 0) { } + /* Need to get exlusive access to the device so that we can use the copy + * buffer */ + + while (sem_wait(&dev->exclsem) < 0) { } /* If this a CSMA transaction and we have room in the CSMA fifo */ - if (!gts && !dev->csma_busy) + if (!dev->csma_txdesc.busy) { /* need to somehow allow for a handle to be passed */ ret = dev->phyif->poll_csma(dev->phyif, &radio->csma_txdesc, &dev->tx_buf[0]); + if (ret > 0) + { + /* Now the txdesc is in use */ + + dev->cmsa_desc.busy = 1; + + /* Setup the transaction on the device in the CSMA FIFO */ + + mrf24j40_csma_setup(radio, &dev->tx_buf[0], + dev->gts_desc[i].psdu_length); + } + /* Setup the transmit on the device */ + break; } - else - { - for(gts = 0; gts < MRF24J40_GTS_SLOTS, gts++) + + sem_post(&dev->exclsem); +} + +/**************************************************************************** + * Function: mrf24j40_txnotify_gts + * + * Description: + * Called from the upper layer, this function is to notify the device that + * the upper layer has a pending transaction for one of it's GTS'. This + * function checks to see if there is availability for the corresponding + * transaction type. If there is, the function will call to the MAC layer + * to get the transaction and then start the transmission + * + ****************************************************************************/ + +static void mrf24j40_txnotify_gts(FAR struct ieee802154_radio_s *radio) +{ + FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)radio; + + /* Need to get exclusive access to the device so that we can use the copy + * buffer */ + + while (sem_wait(dev->exclsem) < 0) { } + + for(gts = 0; gts < MRF24J40_GTS_SLOTS, gts++) + { + if(!dev->gts_txdesc[i].busy) { - if(!dev->gts_txdesc[i].busy) + ret = dev->phyif->poll_gts(dev->phyif, &radio->gts_txdesc[i], + &dev->tx_buf[0]); + + if (ret > 0) { - ret = dev->phyif->poll_gts(dev->phyif, &radio->gts_txdesc[i], - &dev->tx_buf[0]); + /* Now the txdesc is in use */ - /* Setup the transmit on the device */ + dev->gts_txdesc[i].busy = 1; - break; + /* Setup the transaction on the device in the open GTS FIFO */ + + mrf24j40_gts_setup(radio, i, &dev->tx_buf[0], + dev->gts_desc[i].psdu_length); } } - } + } } /**************************************************************************** @@ -1506,38 +1567,36 @@ FAR struct ieee802154_radio_s *mrf24j40_init(FAR struct spi_dev_s *spi, /* Initialize semaphores */ sem_init(&dev->radio.rxsem, 0, 0); - sem_init(&dev->radio.txsem, 0, 0); /* These semaphores are all used for signaling and, hence, should * not have priority inheritance enabled. */ sem_setprotocol(&dev->radio.rxsem, SEM_PRIO_NONE); - sem_setprotocol(&dev->radio.txsem, SEM_PRIO_NONE); dev->lower = lower; dev->spi = spi; mrf24j40_initialize(dev); - mrf24j40_setchannel(&dev->radio, 11); - mrf24j40_setpanid (&dev->radio, 0xFFFF); - mrf24j40_setsaddr (&dev->radio, 0xFFFF); - mrf24j40_seteaddr (&dev->radio, (uint8_t*)"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"); + mrf24j40_setchannel(dev, 11); + mrf24j40_setpanid (dev, 0xFFFF); + mrf24j40_setsaddr (dev, 0xFFFF); + mrf24j40_seteaddr (dev, (uint8_t*)"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"); /* Default device params */ cca.use_ed = 1; cca.use_cs = 0; cca.edth = 0x60; /* CCA mode ED, no carrier sense, recommenced ED threshold -69 dBm */ - mrf24j40_setcca(&dev->radio, &cca); + mrf24j40_setcca(dev, &cca); mrf24j40_setrxmode(dev, MRF24J40_RXMODE_NORMAL); - mrf24j40_settxpower(&dev->radio, 0); /*16. Set transmitter power .*/ + mrf24j40_settxpower(dev, 0); /*16. Set transmitter power .*/ mrf24j40_pacontrol(dev, MRF24J40_PA_AUTO); - dev->lower->enable(dev->radio, true); + dev->lower->enable(dev->lower, true); return &dev->radio; } diff --git a/include/nuttx/wireless/ieee802154/ieee802154_radio.h b/include/nuttx/wireless/ieee802154/ieee802154_radio.h index a26e3321d68..bd7c725b150 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_radio.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_radio.h @@ -157,22 +157,15 @@ struct ieee802154_netradio_s #endif /* IEEE802.15.4 Radio Interface Operations **********************************/ -struct ieee802154_trans_s +struct ieee802154_txdesc_s { - uint8_t retry_count; /* The number of retries remaining */ - uint8_t msdu_handle; /* The msdu handle identifying the transaction */ + uint8_t psdu_handle; /* The psdu handle identifying the transaction */ uint16_t psdu_length; /* The length of the PSDU */ - /* The PHY Service Data Unit (PSDU) buffer representing the frame to be - * transmitted. This must be at the end of the struct to allow the array - * to continue and make the struct "variable length". Users should allocate - * memory using the SIZEOF_MAC802154_TRANSACTION_S macro below */ - - uint8_t psdu[CONFIG_IEEE802154_MTU]; + /* TODO: Add slotting information for GTS transactions */ }; - struct ieee802154_phyif_s; /* Forward Reference */ struct ieee802154_phyifops_s @@ -208,8 +201,8 @@ struct ieee802154_radioops_s CODE int (*rxenable)(FAR struct ieee802154_radio_s *dev, bool state, FAR struct ieee802154_packet_s *packet); - CODE int (*transmit)(FAR struct ieee802154_radio_s *dev, - FAR struct ieee802154_packet_s *packet); + CODE int (*txnotify_csma)(FAR struct ieee802154_radio_s *dev); + CODE int (*txnotify_gts)(FAR struct ieee802154_radio_s *dev); }; struct ieee802154_radio_s @@ -222,17 +215,6 @@ struct ieee802154_radio_s * rx interrupt, NULL if rx not enabled */ sem_t rxsem; /* Semaphore posted after reception of * a packet */ - - /* Packet transmission management */ - - bool txok; /* Last transmission status, filled by - * tx interrupt */ - bool txbusy; /* Last transmission failed because - * channel busy */ - uint8_t txretries; /* Last transmission required this much - * retries */ - sem_t txsem; /* Semaphore posted after transmission - * of a packet */ }; #ifdef __cplusplus diff --git a/wireless/ieee802154/mac802154.c b/wireless/ieee802154/mac802154.c index c4f99480bfb..32e78dd9165 100644 --- a/wireless/ieee802154/mac802154.c +++ b/wireless/ieee802154/mac802154.c @@ -57,6 +57,32 @@ /**************************************************************************** * Private Types ****************************************************************************/ + +struct mac802154_trans_s +{ + /* Supports a singly linked list */ + + FAR struct mac802154_trans_s *flink; + + uint8_t msdu_handle; + + uint8_t *mhr_buf; + uint8_t mhr_len; + + uint8_t *d_buf; + uint8_t d_len; + + sem_t sem; +}; + +struct mac802154_unsec_mhr_s +{ + uint8_t length; + union { + uint16_t frame_control; + uint8_t data[IEEE802154_MAX_UNSEC_MHR_OVERHEAD]; + }; +}; /* The privmac structure holds the internal state of the MAC and is the * underlying represention of the opaque MACHANDLE. It contains storage for @@ -79,7 +105,6 @@ struct ieee802154_privmac_s FAR struct mac802154_trans_s *csma_head; FAR struct mac802154_trans_s *csma_tail; - struct mac802154_trans_s csma_buf[5]; /* Support a singly linked list of transactions that will be sent indirectly. * This list should only be used by a MAC acting as a coordinator. These @@ -91,7 +116,6 @@ struct ieee802154_privmac_s FAR struct mac802154_trans_s *indirect_head; FAR struct mac802154_trans_s *indirect_tail; - FAR struct mac802154_trans_s *active_trans; /* MAC PIB attributes, grouped to save memory */ @@ -203,32 +227,6 @@ struct ieee802154_privmac_s /* TODO: Add Security-related MAC PIB attributes */ }; -struct mac802154_trans_s -{ - /* Supports a singly linked list */ - - FAR struct mac802154_trans_s *flink; - - uint8_t msdu_handle; - - uint8_t *mhr_buf; - uint8_t mhr_len; - - uint8_t *d_buf; - uint8_t d_len; - - sem_t sem; -}; - -struct mac802154_unsec_mhr_s -{ - uint8_t length; - union - { - uint16_t frame_control; - uint8_t data[IEEE802154_MAX_UNSEC_MHR_OVERHEAD]; - }; -}; /**************************************************************************** * Private Data @@ -563,7 +561,7 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) } } - /* Set the source addr mode inside the frame contorl field */ + /* Set the source addr mode inside the frame control field */ mhr.frame_ctrl |= (req->src_addr_mode << IEEE802154_FRAMECTRL_SHIFT_SADDR); @@ -658,7 +656,7 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) /* Notify the radio driver that there is data available */ - priv->radio->tx_notify(priv->radio); + priv->radio->ops->tx_notify(priv->radio); sem_wait(&trans->sem); } @@ -712,6 +710,13 @@ static uint16_t mac802154_poll_csma(FAR struct ieee802154_phyif_s *phyif, return 0; } +static uint16_t mac802154_poll_gts(FAR struct ieee802154_phyif_s *phyif, + FAR struct ieee802154_txdesc_s *tx_desc, + uint8_t *buf) +{ + return 0; +} + /**************************************************************************** * Name: mac802154_req_purge * From 6d3ec6e4a43fbad9305ffb520c8977899c401387 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 17 Apr 2017 09:53:58 -0600 Subject: [PATCH 083/183] ieee802.15.4: Changes from review of last PR --- drivers/wireless/ieee802154/mrf24j40.c | 38 ++++++++++--------- .../wireless/ieee802154/ieee802154_radio.h | 15 +++----- wireless/ieee802154/mac802154.c | 11 +++--- 3 files changed, 31 insertions(+), 33 deletions(-) diff --git a/drivers/wireless/ieee802154/mrf24j40.c b/drivers/wireless/ieee802154/mrf24j40.c index 3659fe1651e..2cb3300e5a0 100644 --- a/drivers/wireless/ieee802154/mrf24j40.c +++ b/drivers/wireless/ieee802154/mrf24j40.c @@ -268,7 +268,8 @@ static void mrf24j40_dopoll_csma(FAR struct ieee802154_radio_s *radio) FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)radio; /* Need to get exlusive access to the device so that we can use the copy - * buffer */ + * buffer. + */ while (sem_wait(&dev->exclsem) < 0) { } @@ -318,30 +319,31 @@ static void mrf24j40_txnotify_gts(FAR struct ieee802154_radio_s *radio) FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)radio; /* Need to get exclusive access to the device so that we can use the copy - * buffer */ + * buffer. + */ while (sem_wait(dev->exclsem) < 0) { } - for(gts = 0; gts < MRF24J40_GTS_SLOTS, gts++) - { - if(!dev->gts_txdesc[i].busy) - { - ret = dev->phyif->poll_gts(dev->phyif, &radio->gts_txdesc[i], - &dev->tx_buf[0]); + for (gts = 0; gts < MRF24J40_GTS_SLOTS, gts++) + { + if (!dev->gts_txdesc[i].busy) + { + ret = dev->phyif->poll_gts(dev->phyif, &radio->gts_txdesc[i], + &dev->tx_buf[0]); - if (ret > 0) - { - /* Now the txdesc is in use */ + if (ret > 0) + { + /* Now the txdesc is in use */ - dev->gts_txdesc[i].busy = 1; + dev->gts_txdesc[i].busy = 1; - /* Setup the transaction on the device in the open GTS FIFO */ + /* Setup the transaction on the device in the open GTS FIFO */ - mrf24j40_gts_setup(radio, i, &dev->tx_buf[0], - dev->gts_desc[i].psdu_length); - } - } - } + mrf24j40_gts_setup(radio, i, &dev->tx_buf[0], + dev->gts_desc[i].psdu_length); + } + } + } } /**************************************************************************** diff --git a/include/nuttx/wireless/ieee802154/ieee802154_radio.h b/include/nuttx/wireless/ieee802154/ieee802154_radio.h index bd7c725b150..d48b0d4e121 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_radio.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_radio.h @@ -157,6 +157,7 @@ struct ieee802154_netradio_s #endif /* IEEE802.15.4 Radio Interface Operations **********************************/ + struct ieee802154_txdesc_s { uint8_t psdu_handle; /* The psdu handle identifying the transaction */ @@ -171,12 +172,9 @@ struct ieee802154_phyif_s; /* Forward Reference */ struct ieee802154_phyifops_s { CODE int (*poll_csma) (FAR struct ieee802154_phyif_s *phyif, - FAR struct ieee802154_txdesc_s *tx_desc, - uint8_t *buf); - + FAR struct ieee802154_txdesc_s *tx_desc, FAR uint8_t *buf); CODE int (*poll_gts) (FAR struct ieee802154_phyif_s *phyif, - FAR struct ieee802154_txdesc_s *tx_desc, - uint8_t *buf); + FAR struct ieee802154_txdesc_s *tx_desc, FAR uint8_t *buf); }; struct ieee802154_phyif_s @@ -185,7 +183,7 @@ struct ieee802154_phyif_s /* Driver-specific information */ - void * priv; + FAR void * priv; }; struct ieee802154_radio_s; /* Forward reference */ @@ -193,14 +191,11 @@ struct ieee802154_radio_s; /* Forward reference */ struct ieee802154_radioops_s { CODE int (*bind) (FAR struct ieee802154_radio_s *dev, - FAR const struct ieee802154_phyif_s *phyif); - + FAR const struct ieee802154_phyif_s *phyif); CODE int (*ioctl)(FAR struct ieee802154_radio_s *ieee, int cmd, unsigned long arg); - CODE int (*rxenable)(FAR struct ieee802154_radio_s *dev, bool state, FAR struct ieee802154_packet_s *packet); - CODE int (*txnotify_csma)(FAR struct ieee802154_radio_s *dev); CODE int (*txnotify_gts)(FAR struct ieee802154_radio_s *dev); }; diff --git a/wireless/ieee802154/mac802154.c b/wireless/ieee802154/mac802154.c index 32e78dd9165..8dc2e87b3fc 100644 --- a/wireless/ieee802154/mac802154.c +++ b/wireless/ieee802154/mac802154.c @@ -66,10 +66,10 @@ struct mac802154_trans_s uint8_t msdu_handle; - uint8_t *mhr_buf; + FAR uint8_t *mhr_buf; uint8_t mhr_len; - uint8_t *d_buf; + FAR uint8_t *d_buf; uint8_t d_len; sem_t sem; @@ -78,10 +78,11 @@ struct mac802154_trans_s struct mac802154_unsec_mhr_s { uint8_t length; - union { + union + { uint16_t frame_control; uint8_t data[IEEE802154_MAX_UNSEC_MHR_OVERHEAD]; - }; + } u; }; /* The privmac structure holds the internal state of the MAC and is the @@ -530,7 +531,7 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) * from the transmitted frame. [1] pg. 41. */ - if(req->dest_addr.panid == priv->addr.panid) + if (req->dest_addr.panid == priv->addr.panid) { mhr.frame_control |= IEEE802154_FRAMECTRL_PANIDCOMP; } From 1d1d633e6f02f836bfa36032c866231905283897 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 17 Apr 2017 11:47:33 -0600 Subject: [PATCH 084/183] ieee802.15.4: Fix some forbidden C11 syntax. --- include/nuttx/wireless/ieee802154/ieee802154_mac.h | 8 ++++---- wireless/ieee802154/mac802154.c | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/include/nuttx/wireless/ieee802154/ieee802154_mac.h b/include/nuttx/wireless/ieee802154/ieee802154_mac.h index 838f7fcafd5..76880ebf29c 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_mac.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_mac.h @@ -356,7 +356,7 @@ struct ieee802154_addr_s { uint16_t saddr; /* short address */ uint8_t eaddr[8]; /* extended address */ - }; + } u; }; #define IEEE802154_ADDRSTRLEN 22 /* (2*2+1+8*2, PPPP/EEEEEEEEEEEEEEEE) */ @@ -430,7 +430,7 @@ struct ieee802154_data_req_s uint8_t ack_tx : 1; /* Acknowledge TX? */ uint8_t gts_tx : 1; /* 1=GTS used for TX, 0=CAP used for TX */ uint8_t indirect_tx : 1; /* Should indirect transmission be used? */ - }; + } msdu_flags; #ifdef CONFIG_IEEE802154_SECURITY /* Security information if enabled */ @@ -566,8 +566,8 @@ struct ieee802154_pend_addr_s uint8_t reserved_3 : 1; /* Reserved bit */ uint8_t num_ext_addr : 3; /* Number of extended addresses pending */ uint8_t reserved_7 : 1; /* Reserved bit */ - }; - }; + } pa_addr; + } u; struct ieee802154_addr_s addr[7]; /* Array of at most 7 addresses */ }; diff --git a/wireless/ieee802154/mac802154.c b/wireless/ieee802154/mac802154.c index 8dc2e87b3fc..ee057dcec1b 100644 --- a/wireless/ieee802154/mac802154.c +++ b/wireless/ieee802154/mac802154.c @@ -482,7 +482,7 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) * 5.1.6.4 [1] pg. 118. */ - mhr.frame_ctrl |= (req->ack_tx << IEEE802154_FRAMECTRL_SHIFT_ACKREQ); + mhr.frame_ctrl |= (req->msdu_flags.ack_tx << IEEE802154_FRAMECTRL_SHIFT_ACKREQ); /* If the destination address is present, copy the PAN ID and one of the * addresses, depending on mode, into the MHR . @@ -603,7 +603,7 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) * [1] pg. 118. */ - if (req->gts_tx) + if (req->msdu_flags.gts_tx) { /* TODO: Support GTS transmission. This should just change where we link * the transaction. Instead of going in the CSMA transaction list, it @@ -622,7 +622,7 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) * described in 5.1.5 and 5.1.6.3. [1] */ - if (req->indirect_tx) + if (req->msdu_flags.indirect_tx) { /* If the TxOptions parameter specifies that an indirect transmission * is required and if the device receiving this primitive is not a @@ -642,13 +642,13 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) { /* Override the setting since it wasn't valid */ - req->indirect_tx = 0; + req->msgu_flags.indirect_tx = 0; } } /* If this is a direct transmission not during a GTS */ - if (!req->indirect_tx) + if (!req->msdu_flags.indirect_tx) { /* Link the transaction into the CSMA transaction list */ From 9ad3b375e59c673749d70dfc7cecc59802c9e4c7 Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Tue, 18 Apr 2017 15:34:13 -0400 Subject: [PATCH 085/183] wireless/ieee802154: Lots of small fixes to eliminate build issues. Generally cleans things up and fixes lots of small issues preventing a successful build. Does not completely build, but there are significantly less errors --- drivers/wireless/ieee802154/mrf24j40.c | 345 +++++++++++++----- .../wireless/ieee802154/ieee802154_mac.h | 27 +- .../wireless/ieee802154/ieee802154_radio.h | 12 +- wireless/ieee802154/mac802154.c | 129 ++++--- wireless/ieee802154/mac802154_device.c | 138 ++++--- 5 files changed, 418 insertions(+), 233 deletions(-) diff --git a/drivers/wireless/ieee802154/mrf24j40.c b/drivers/wireless/ieee802154/mrf24j40.c index 2cb3300e5a0..655871eb94f 100644 --- a/drivers/wireless/ieee802154/mrf24j40.c +++ b/drivers/wireless/ieee802154/mrf24j40.c @@ -94,10 +94,19 @@ #define MRF24J40_PA_ED 2 #define MRF24J40_PA_SLEEP 3 +#define MRF24J40_GTS_SLOTS 2 + /**************************************************************************** * Private Types ****************************************************************************/ +struct mrf24j40_txdesc_s +{ + struct ieee802154_txdesc_s pub; + + uint8_t busy : 1; /* Is this txdesc being used */ +}; + /* A MRF24J40 device instance */ struct mrf24j40_radio_s @@ -106,36 +115,33 @@ struct mrf24j40_radio_s /* Reference to the bound upper layer via the phyif interface */ - FAR const struct ieee802154_phyif_s *phyif; + FAR struct ieee802154_phyif_s *phyif; - FAR struct spi_dev_s *spi; /* Saved SPI interface instance */ - struct work_s irqwork; /* Interrupt continuation work queue support */ - FAR const struct mrf24j40_lower_s *lower; /* Low-level MCU-specific support */ - sem_t excl_sem; /* Exclusive access to this struct */ + /* Low-level MCU-specific support */ - uint16_t panid; /* PAN identifier, FFFF = not set */ - uint16_t saddr; /* short address, FFFF = not set */ - uint8_t eaddr[8]; /* extended address, FFFFFFFFFFFFFFFF = not set */ - uint8_t channel; /* 11 to 26 for the 2.4 GHz band */ - uint8_t devmode; /* device mode: device, coord, pancoord */ - uint8_t paenabled; /* enable usage of PA */ - uint8_t rxmode; /* Reception mode: Main, no CRC, promiscuous */ - int32_t txpower; /* TX power in mBm = dBm/100 */ - struct ieee802154_cca_s cca; /* Clear channel assessement method */ + FAR const struct mrf24j40_lower_s *lower; + FAR struct spi_dev_s *spi; /* Saved SPI interface instance */ + + struct work_s irqwork; /* For deferring interrupt work to work queue */ + struct work_s pollwork; /* For deferring poll work to the work queue */ + sem_t exclsem; /* Exclusive access to this struct */ + + uint16_t panid; /* PAN identifier, FFFF = not set */ + uint16_t saddr; /* short address, FFFF = not set */ + uint8_t eaddr[8]; /* extended address, FFFFFFFFFFFFFFFF = not set */ + uint8_t channel; /* 11 to 26 for the 2.4 GHz band */ + uint8_t devmode; /* device mode: device, coord, pancoord */ + uint8_t paenabled; /* enable usage of PA */ + uint8_t rxmode; /* Reception mode: Main, no CRC, promiscuous */ + int32_t txpower; /* TX power in mBm = dBm/100 */ + struct ieee802154_cca_s cca; /* Clear channel assessement method */ /* Buffer Allocations */ struct mrf24j40_txdesc_s csma_desc; - struct mrf24j40_txdesc_s gts_desc[2]; + struct mrf24j40_txdesc_s gts_desc[MRF24J40_GTS_SLOTS]; - uint8_t tx_buf[CONFIG_IEEE802154_MTU]; -}; - -struct mrf24j40_txdesc_s -{ - struct ieee802154_txdesc_s ieee_desc; - - uint8_t busy : 1; /* Is this txdesc being used */ + uint8_t tx_buf[IEEE802154_MAX_PHY_PACKET_SIZE]; }; /**************************************************************************** @@ -161,41 +167,49 @@ static void mrf24j40_irqwork_tx(FAR struct mrf24j40_radio_s *dev); static void mrf24j40_irqworker(FAR void *arg); static int mrf24j40_interrupt(int irq, FAR void *context, FAR void *arg); +static void mrf24j40_dopoll_csma(FAR void *arg); +static void mrf24j40_dopoll_gts(FAR void *arg); + +static int mrf24j40_csma_setup(FAR struct mrf24j40_radio_s *dev, + uint8_t *buf, uint16_t buf_len); +static int mrf24j40_gts_setup(FAR struct mrf24j40_radio_s *dev, uint8_t gts, + uint8_t *buf, uint16_t buf_len); + /* IOCTL helpers */ -static int mrf24j40_setchannel(FAR struct ieee802154_radio_s *radio, +static int mrf24j40_setchannel(FAR struct mrf24j40_radio_s *radio, uint8_t chan); -static int mrf24j40_getchannel(FAR struct ieee802154_radio_s *radio, +static int mrf24j40_getchannel(FAR struct mrf24j40_radio_s *radio, FAR uint8_t *chan); -static int mrf24j40_setpanid(FAR struct ieee802154_radio_s *radio, +static int mrf24j40_setpanid(FAR struct mrf24j40_radio_s *radio, uint16_t panid); -static int mrf24j40_getpanid(FAR struct ieee802154_radio_s *radio, +static int mrf24j40_getpanid(FAR struct mrf24j40_radio_s *radio, FAR uint16_t *panid); -static int mrf24j40_setsaddr(FAR struct ieee802154_radio_s *radio, +static int mrf24j40_setsaddr(FAR struct mrf24j40_radio_s *radio, uint16_t saddr); -static int mrf24j40_getsaddr(FAR struct ieee802154_radio_s *radio, +static int mrf24j40_getsaddr(FAR struct mrf24j40_radio_s *radio, FAR uint16_t *saddr); -static int mrf24j40_seteaddr(FAR struct ieee802154_radio_s *radio, +static int mrf24j40_seteaddr(FAR struct mrf24j40_radio_s *radio, FAR uint8_t *eaddr); -static int mrf24j40_geteaddr(FAR struct ieee802154_radio_s *radio, +static int mrf24j40_geteaddr(FAR struct mrf24j40_radio_s *radio, FAR uint8_t *eaddr); -static int mrf24j40_setpromisc(FAR struct ieee802154_radio_s *radio, +static int mrf24j40_setpromisc(FAR struct mrf24j40_radio_s *radio, bool promisc); -static int mrf24j40_getpromisc(FAR struct ieee802154_radio_s *radio, +static int mrf24j40_getpromisc(FAR struct mrf24j40_radio_s *radio, FAR bool *promisc); -static int mrf24j40_setdevmode(FAR struct ieee802154_radio_s *radio, +static int mrf24j40_setdevmode(FAR struct mrf24j40_radio_s *radio, uint8_t mode); -static int mrf24j40_getdevmode(FAR struct ieee802154_radio_s *radio, +static int mrf24j40_getdevmode(FAR struct mrf24j40_radio_s *radio, FAR uint8_t *mode); -static int mrf24j40_settxpower(FAR struct ieee802154_radio_s *radio, +static int mrf24j40_settxpower(FAR struct mrf24j40_radio_s *radio, int32_t txpwr); -static int mrf24j40_gettxpower(FAR struct ieee802154_radio_s *radio, +static int mrf24j40_gettxpower(FAR struct mrf24j40_radio_s *radio, FAR int32_t *txpwr); -static int mrf24j40_setcca(FAR struct ieee802154_radio_s *radio, +static int mrf24j40_setcca(FAR struct mrf24j40_radio_s *radio, FAR struct ieee802154_cca_s *cca); -static int mrf24j40_getcca(FAR struct ieee802154_radio_s *radio, +static int mrf24j40_getcca(FAR struct mrf24j40_radio_s *radio, FAR struct ieee802154_cca_s *cca); -static int mrf24j40_energydetect(FAR struct ieee802154_radio_s *radio, +static int mrf24j40_energydetect(FAR struct mrf24j40_radio_s *radio, FAR uint8_t *energy); /* Driver operations */ @@ -207,7 +221,9 @@ static int mrf24j40_ioctl(FAR struct ieee802154_radio_s *radio, int cmd, static int mrf24j40_rxenable(FAR struct ieee802154_radio_s *radio, bool state, FAR struct ieee802154_packet_s *packet); static int mrf24j40_transmit(FAR struct ieee802154_radio_s *radio, - FAR struct ieee802154_packet_s *packet); + uint8_t *buf, uint16_t buf_len); +static int mrf24j40_txnotify_csma(FAR struct ieee802154_radio_s *radio); +static int mrf24j40_txnotify_gts(FAR struct ieee802154_radio_s *radio); /**************************************************************************** * Private Data @@ -233,8 +249,8 @@ static const struct ieee802154_radioops_s mrf24j40_devops = * Private Functions ****************************************************************************/ -static void mrf24j40_bind(FAR struct ieee802154_radio_s *radio, - FAR struct ieee802154_phyif_s *phyif) +static int mrf24j40_bind(FAR struct ieee802154_radio_s *radio, + FAR struct ieee802154_phyif_s *phyif) { FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)radio; @@ -243,6 +259,43 @@ static void mrf24j40_bind(FAR struct ieee802154_radio_s *radio, return OK; } +/**************************************************************************** + * Function: mrf24j40_txnotify_csma + * + * Description: + * Driver callback invoked when new TX data is available. This is a + * stimulus perform an out-of-cycle poll and, thereby, reduce the TX + * latency. + * + * Parameters: + * radio - Reference to the radio driver state structure + * + * Returned Value: + * None + * + * Assumptions: + * + ****************************************************************************/ + +static int mrf24j40_txnotify_csma(FAR struct ieee802154_radio_s *radio) +{ + FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)radio; + + /* Is our single work structure available? It may not be if there are + * pending interrupt actions and we will have to ignore the Tx + * availability action. + */ + + if (work_available(&dev->pollwork)) + { + /* Schedule to serialize the poll on the worker thread. */ + + work_queue(HPWORK, &dev->pollwork, mrf24j40_dopoll_csma, dev, 0); + } + + return OK; +} + /**************************************************************************** * Function: mrf24j40_dopoll_csma * @@ -250,8 +303,10 @@ static void mrf24j40_bind(FAR struct ieee802154_radio_s *radio, * This function is called in order to preform an out-of-sequence TX poll. * This is done: * - * 1. After completion of a CSMA transmission - * 2. When the upper layer calls txnotify_csma + * 1. After completion of a transmission (mrf24j40_txdone_csma), + * 2. When new TX data is available (mrf24j40_txnotify_csma), and + * 3. After a TX timeout to restart the sending process + * (mrf24j40_txtimeout_csma). * * Parameters: * radio - Reference to the radio driver state structure @@ -263,40 +318,41 @@ static void mrf24j40_bind(FAR struct ieee802154_radio_s *radio, * ****************************************************************************/ -static void mrf24j40_dopoll_csma(FAR struct ieee802154_radio_s *radio) +static void mrf24j40_dopoll_csma(FAR void *arg) { - FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)radio; + FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)arg; + int ret = 0; /* Need to get exlusive access to the device so that we can use the copy * buffer. */ - while (sem_wait(&dev->exclsem) < 0) { } + while (sem_wait(&dev->exclsem) != 0) { } /* If this a CSMA transaction and we have room in the CSMA fifo */ - if (!dev->csma_txdesc.busy) + if (!dev->csma_desc.busy) { /* need to somehow allow for a handle to be passed */ - ret = dev->phyif->poll_csma(dev->phyif, &radio->csma_txdesc, - &dev->tx_buf[0]); + ret = dev->phyif->ops->poll_csma(dev->phyif, + &dev->csma_desc.pub, + &dev->tx_buf[0]); if (ret > 0) { /* Now the txdesc is in use */ - dev->cmsa_desc.busy = 1; + dev->csma_desc.busy = 1; /* Setup the transaction on the device in the CSMA FIFO */ - mrf24j40_csma_setup(radio, &dev->tx_buf[0], - dev->gts_desc[i].psdu_length); + mrf24j40_csma_setup(dev, &dev->tx_buf[0], + dev->csma_desc.pub.psdu_length); } /* Setup the transmit on the device */ - break; } sem_post(&dev->exclsem); @@ -306,44 +362,95 @@ static void mrf24j40_dopoll_csma(FAR struct ieee802154_radio_s *radio) * Function: mrf24j40_txnotify_gts * * Description: - * Called from the upper layer, this function is to notify the device that - * the upper layer has a pending transaction for one of it's GTS'. This - * function checks to see if there is availability for the corresponding - * transaction type. If there is, the function will call to the MAC layer - * to get the transaction and then start the transmission + * Driver callback invoked when new TX data is available. This is a + * stimulus perform an out-of-cycle poll and, thereby, reduce the TX + * latency. + * + * Parameters: + * radio - Reference to the radio driver state structure + * + * Returned Value: + * None + * + * Assumptions: * ****************************************************************************/ -static void mrf24j40_txnotify_gts(FAR struct ieee802154_radio_s *radio) +static int mrf24j40_txnotify_gts(FAR struct ieee802154_radio_s *radio) { FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)radio; + /* Is our single work structure available? It may not be if there are + * pending interrupt actions and we will have to ignore the Tx + * availability action. + */ + + if (work_available(&dev->pollwork)) + { + /* Schedule to serialize the poll on the worker thread. */ + + work_queue(HPWORK, &dev->pollwork, mrf24j40_dopoll_gts, dev, 0); + } + + return OK; +} + +/**************************************************************************** + * Function: mrf24j40_dopoll_gts + * + * Description: + * This function is called in order to preform an out-of-sequence TX poll. + * This is done: + * + * 1. After completion of a transmission (mrf24j40_txdone_gts), + * 2. When new TX data is available (mrf24j40_txnotify_gts), and + * 3. After a TX timeout to restart the sending process + * (mrf24j40_txtimeout_gts). + * + * Parameters: + * arg - Reference to the radio driver state structure + * + * Returned Value: + * None + * + * Assumptions: + * + ****************************************************************************/ + +static void mrf24j40_dopoll_gts(FAR void *arg) +{ + FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)arg; + int gts = 0; + int ret = 0; + /* Need to get exclusive access to the device so that we can use the copy * buffer. */ - while (sem_wait(dev->exclsem) < 0) { } + while (sem_wait(&dev->exclsem) != 0) { } - for (gts = 0; gts < MRF24J40_GTS_SLOTS, gts++) + for (gts = 0; gts < MRF24J40_GTS_SLOTS; gts++) { - if (!dev->gts_txdesc[i].busy) + if (!dev->gts_desc[gts].busy) { - ret = dev->phyif->poll_gts(dev->phyif, &radio->gts_txdesc[i], - &dev->tx_buf[0]); + ret = dev->phyif->ops->poll_gts(dev->phyif, &dev->gts_desc[gts].pub, + &dev->tx_buf[0]); if (ret > 0) { /* Now the txdesc is in use */ - dev->gts_txdesc[i].busy = 1; + dev->gts_desc[gts].busy = 1; /* Setup the transaction on the device in the open GTS FIFO */ - mrf24j40_gts_setup(radio, i, &dev->tx_buf[0], - dev->gts_desc[i].psdu_length); + mrf24j40_gts_setup(dev, gts, &dev->tx_buf[0], + dev->gts_desc[gts].pub.psdu_length); } } } + + sem_post(&dev->exclsem); } /**************************************************************************** @@ -409,11 +516,11 @@ static void mrf24j40_setreg(FAR struct spi_dev_s *spi, uint32_t addr, buf[len++] = val; - mrf24j40_lock(spi); + mrf24j40_spi_lock(spi); SPI_SELECT(spi, SPIDEV_IEEE802154, true); SPI_SNDBLOCK(spi, buf, len); SPI_SELECT(spi, SPIDEV_IEEE802154, false); - mrf24j40_unlock(spi); + mrf24j40_spi_unlock(spi); } /**************************************************************************** @@ -453,11 +560,11 @@ static uint8_t mrf24j40_getreg(FAR struct spi_dev_s *spi, uint32_t addr) buf[len++] = 0xFF; /* dummy */ - mrf24j40_lock (spi); + mrf24j40_spi_lock (spi); SPI_SELECT (spi, SPIDEV_IEEE802154, true); SPI_EXCHANGE (spi, buf, rx, len); SPI_SELECT (spi, SPIDEV_IEEE802154, false); - mrf24j40_unlock(spi); + mrf24j40_spi_unlock(spi); /* wlinfo("r[%04X]=%02X\n", addr, rx[len - 1]); */ return rx[len - 1]; @@ -644,10 +751,18 @@ static int mrf24j40_setchannel(FAR struct mrf24j40_radio_s *dev, uint8_t chan) return OK; } +/**************************************************************************** + * Name: mrf24j40_getchannel + * + * Description: + * Get the channel the device is operating on. + * + ****************************************************************************/ + static int mrf24j40_getchannel(FAR struct mrf24j40_radio_s *dev, FAR uint8_t *chan) { - chan = dev->channel; + *chan = dev->channel; return OK; } @@ -955,7 +1070,7 @@ static int mrf24j40_settxpower(FAR struct mrf24j40_radio_s *dev, * ****************************************************************************/ -static int mrf24j40_gettxpower(FAR struct mrf24j40_radio_s *radio, +static int mrf24j40_gettxpower(FAR struct mrf24j40_radio_s *dev, FAR int32_t *txpwr) { *txpwr = dev->txpower; @@ -1085,78 +1200,78 @@ static int mrf24j40_ioctl(FAR struct ieee802154_radio_s *radio, int cmd, unsigned long arg) { FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)radio; - - FAR union ieee802154_radioarg_u *u; = - (FAR union ieee802154_radioarg_u *)((uintptr_t)arg) + FAR union ieee802154_radioarg_u *u = + (FAR union ieee802154_radioarg_u *)((uintptr_t)arg); + int ret; switch(cmd) { case PHY802154IOC_SET_CHAN: - ret = mrf24j40_setchannel(dev, u.channel); + ret = mrf24j40_setchannel(dev, u->channel); break; case PHY802154IOC_GET_CHAN: - ret = mrf24j40_getchannel(dev, &u.channel); + ret = mrf24j40_getchannel(dev, &u->channel); break; case PHY802154IOC_SET_PANID: - ret = mrf24j40_setpanid(dev, u.panid); + ret = mrf24j40_setpanid(dev, u->panid); break; case PHY802154IOC_GET_PANID: - ret = mrf24j40_getpanid(dev, &u.panid); + ret = mrf24j40_getpanid(dev, &u->panid); break; case PHY802154IOC_SET_SADDR: - ret = mrf24j40_setsaddr(dev, u.saddr); + ret = mrf24j40_setsaddr(dev, u->saddr); break; case PHY802154IOC_GET_SADDR: - ret = mrf24j40_getsaddr(dev, &u.saddr); + ret = mrf24j40_getsaddr(dev, &u->saddr); break; case PHY802154IOC_SET_EADDR: - ret = mrf24j40_seteaddr(dev, u.eaddr); + ret = mrf24j40_seteaddr(dev, u->eaddr); break; case PHY802154IOC_GET_EADDR: - ret = mrf24j40_geteaddr(dev, u.eaddr); + ret = mrf24j40_geteaddr(dev, u->eaddr); break; case PHY802154IOC_SET_PROMISC: - ret = mrf24j40_setpromisc(dev, u.promisc); + ret = mrf24j40_setpromisc(dev, u->promisc); break; case PHY802154IOC_GET_PROMISC: - ret = mrf24j40_getpromisc(dev, &u.promisc); + ret = mrf24j40_getpromisc(dev, &u->promisc); break; case PHY802154IOC_SET_DEVMODE: - ret = mrf24j40_setdevmode(dev, u.devmode); + ret = mrf24j40_setdevmode(dev, u->devmode); break; case PHY802154IOC_GET_DEVMODE: - ret = mrf24j40_getdevmode(dev, &u.devmode); + ret = mrf24j40_getdevmode(dev, &u->devmode); break; case PHY802154IOC_SET_TXPWR: - ret = mrf24j40_settxpower(dev, u.txpwr); + ret = mrf24j40_settxpower(dev, u->txpwr); break; case PHY802154IOC_GET_TXPWR: - ret = mrf24j40_gettxpower(dev, &u.txpwr); + ret = mrf24j40_gettxpower(dev, &u->txpwr); break; case PHY802154IOC_SET_CCA: - ret = mrf24j40_setcca(dev, &u.cca); + ret = mrf24j40_setcca(dev, &u->cca); break; case PHY802154IOC_GET_CCA: - ret = mrf24j40_getcca(dev, &u.cca); + ret = mrf24j40_getcca(dev, &u->cca); break; case PHY802154IOC_ENERGYDETECT: - ret = mrf24j40_energydetect(dev, &u.energy); + ret = mrf24j40_energydetect(dev, &u->energy); break; case 1000: @@ -1169,6 +1284,8 @@ static int mrf24j40_ioctl(FAR struct ieee802154_radio_s *radio, int cmd, default: return -ENOTTY; } + + return ret; } /**************************************************************************** @@ -1282,13 +1399,13 @@ static int mrf24j40_transmit(FAR struct ieee802154_radio_s *radio, /* Frame length */ - mrf24j40_setreg(dev->spi, addr++, buflen); + mrf24j40_setreg(dev->spi, addr++, buf_len); /* Frame data */ - for (ret = 0; ret < buflen; ret++) /* this sets the correct val for ret */ + for (ret = 0; ret < buf_len; ret++) /* this sets the correct val for ret */ { - mrf24j40_setreg(dev->spi, addr++, packet->data[ret]); + mrf24j40_setreg(dev->spi, addr++, buf[ret]); } /* If the frame control field contains @@ -1309,6 +1426,34 @@ static int mrf24j40_transmit(FAR struct ieee802154_radio_s *radio, return ret; } +/**************************************************************************** + * Name: mrf24j40_csma_setup + * + * Description: + * Setup a CSMA transaction in the normal TX FIFO + * + ****************************************************************************/ + +static int mrf24j40_csma_setup(FAR struct mrf24j40_radio_s *dev, + uint8_t *buf, uint16_t buf_len) +{ + return -ENOTTY; +} + +/**************************************************************************** + * Name: mrf24j40_gts_setup + * + * Description: + * Setup a GTS transaction in one of the GTS FIFOs + * + ****************************************************************************/ + +static int mrf24j40_gts_setup(FAR struct mrf24j40_radio_s *dev, uint8_t fifo, + uint8_t *buf, uint16_t buf_len) +{ + return -ENOTTY; +} + /**************************************************************************** * Name: mrf24j40_irqwork_tx * @@ -1328,9 +1473,11 @@ static void mrf24j40_irqwork_tx(FAR struct mrf24j40_radio_s *dev) /* 1 means it failed, we want 1 to mean it worked. */ + /* dev->radio.txok = (reg & MRF24J40_TXSTAT_TXNSTAT) != MRF24J40_TXSTAT_TXNSTAT; dev->radio.txretries = (reg & MRF24J40_TXSTAT_X_MASK) >> MRF24J40_TXSTAT_X_SHIFT; dev->radio.txbusy = (reg & MRF24J40_TXSTAT_CCAFAIL) == MRF24J40_TXSTAT_CCAFAIL; + */ //wlinfo("TXSTAT%02X!\n", txstat); #warning TODO report errors @@ -1344,7 +1491,7 @@ static void mrf24j40_irqwork_tx(FAR struct mrf24j40_radio_s *dev) /* Wake up the thread that triggered the transmission */ - sem_post(&dev->radio.txsem); + /* sem_post(&dev->radio.txsem); */ } diff --git a/include/nuttx/wireless/ieee802154/ieee802154_mac.h b/include/nuttx/wireless/ieee802154/ieee802154_mac.h index 76880ebf29c..800436de78d 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_mac.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_mac.h @@ -85,7 +85,7 @@ #define MAC802154IOC_MCPS_REGISTER _MAC802154IOC(0x0001) -#define MAC802154IOC_MLME_REGISER _MAC802154IOC(0x0002); +#define MAC802154IOC_MLME_REGISTER _MAC802154IOC(0x0002) #define MAC802154IOC_MLME_ASSOC_REQUEST _MAC802154IOC(0x0003) #define MAC802154IOC_MLME_ASSOC_RESPONSE _MAC802154IOC(0x0004) #define MAC802154IOC_MLME_DISASSOC_REQUEST _MAC802154IOC(0x0005) @@ -103,8 +103,6 @@ #define MAC802154IOC_MLME_SOUNDING_REQUEST _MAC802154IOC(0x0011) #define MAC802154IOC_MLME_CALIBRATE_REQUEST _MAC802154IOC(0x0012) - - /* IEEE 802.15.4 MAC Interface **********************************************/ /* Frame Type */ @@ -351,12 +349,9 @@ struct ieee802154_addr_s enum ieee802154_addr_mode_e mode; - uint16_t panid; /* PAN identifier, can be IEEE802154_PAN_UNSPEC */ - union - { - uint16_t saddr; /* short address */ - uint8_t eaddr[8]; /* extended address */ - } u; + uint16_t panid; /* PAN identifier, can be IEEE802154_PAN_UNSPEC */ + uint16_t saddr; /* short address */ + uint8_t eaddr[8]; /* extended address */ }; #define IEEE802154_ADDRSTRLEN 22 /* (2*2+1+8*2, PPPP/EEEEEEEEEEEEEEEE) */ @@ -397,19 +392,6 @@ enum ieee802154_ranging_e IEEE802154_PHY_HEADER_ONLY }; -struct ieee802154_frame_s -{ - struct ieee802154_framecontrol_s frame_control; - uint8_t seq_num; - struct ieee802154_addr_s dest_addr; - struct ieee802154_addr_s src_addr; -#ifdef CONFIG_IEEE802154_SECURITY - struct ieee802154_auxsec_s aux_sec_hdr; -#endif - void *payload; - uint16_t fcs; -}; - struct ieee802154_data_req_s { enum ieee802154_addr_mode_e src_addr_mode; /* Source Address Mode */ @@ -464,7 +446,6 @@ struct ieee802154_data_req_s uint8_t msdu[1]; }; - #define SIZEOF_IEEE802154_DATA_REQ_S(n) \ (sizeof(struct ieee802154_data_req_s) + (n) - 1) diff --git a/include/nuttx/wireless/ieee802154/ieee802154_radio.h b/include/nuttx/wireless/ieee802154/ieee802154_radio.h index d48b0d4e121..638760f356b 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_radio.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_radio.h @@ -190,14 +190,14 @@ struct ieee802154_radio_s; /* Forward reference */ struct ieee802154_radioops_s { - CODE int (*bind) (FAR struct ieee802154_radio_s *dev, - FAR const struct ieee802154_phyif_s *phyif); - CODE int (*ioctl)(FAR struct ieee802154_radio_s *ieee, int cmd, + CODE int (*bind) (FAR struct ieee802154_radio_s *radio, + FAR struct ieee802154_phyif_s *phyif); + CODE int (*ioctl)(FAR struct ieee802154_radio_s *radio, int cmd, unsigned long arg); - CODE int (*rxenable)(FAR struct ieee802154_radio_s *dev, bool state, + CODE int (*rxenable)(FAR struct ieee802154_radio_s *radio, bool state, FAR struct ieee802154_packet_s *packet); - CODE int (*txnotify_csma)(FAR struct ieee802154_radio_s *dev); - CODE int (*txnotify_gts)(FAR struct ieee802154_radio_s *dev); + CODE int (*txnotify_csma)(FAR struct ieee802154_radio_s *radio); + CODE int (*txnotify_gts)(FAR struct ieee802154_radio_s *radio); }; struct ieee802154_radio_s diff --git a/wireless/ieee802154/mac802154.c b/wireless/ieee802154/mac802154.c index ee057dcec1b..671e67b6e22 100644 --- a/wireless/ieee802154/mac802154.c +++ b/wireless/ieee802154/mac802154.c @@ -43,6 +43,7 @@ #include #include #include +#include #include #include @@ -96,7 +97,7 @@ struct ieee802154_privmac_s FAR const struct ieee802154_maccb_s *cb; /* Contained MAC callbacks */ FAR struct ieee802154_phyif_s phyif; /* Interface to bind to radio */ - sem_t excl_sem; /* Support exclusive access */ + sem_t exclsem; /* Support exclusive access */ /* Support a singly linked list of transactions that will be sent using the * CSMA algorithm. On a non-beacon enabled PAN, these transactions will be @@ -207,14 +208,14 @@ struct ieee802154_privmac_s */ uint32_t sync_symb_offset : 12; - } + }; struct { uint32_t beacon_tx_time : 24; /* Time of last beacon transmit */ uint32_t min_be : 4; /* Min value of backoff exponent (BE) */ uint32_t max_be : 4; /* Max value of backoff exponent (BE) */ - } + }; struct { @@ -223,11 +224,33 @@ struct ieee802154_privmac_s uint32_t tx_ctrl_pause_dur : 1; /* Duration after tx before another tx is * permitted. 0=2000, 1= 10000 */ uint32_t timestamp_support : 1; /* Does MAC layer supports timestamping */ - } + uint32_t is_coord : 1; /* Is this device acting as coordinator */ + }; /* TODO: Add Security-related MAC PIB attributes */ }; +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static inline int mac802154_takesem(sem_t *sem); +#define mac802154_givesem(s) sem_post(s); + +/* Internal Functions */ + +static int mac802154_defaultmib(FAR struct ieee802154_privmac_s *priv); +static int mac802154_applymib(FAR struct ieee802154_privmac_s *priv); + +/* IEEE 802.15.4 PHY Interface OPs */ + +static int mac802154_poll_csma(FAR struct ieee802154_phyif_s *phyif, + FAR struct ieee802154_txdesc_s *tx_desc, + uint8_t *buf); + +static int mac802154_poll_gts(FAR struct ieee802154_phyif_s *phyif, + FAR struct ieee802154_txdesc_s *tx_desc, + uint8_t *buf); /**************************************************************************** * Private Data @@ -350,7 +373,7 @@ MACHANDLE mac802154_create(FAR struct ieee802154_radio_s *radiodev) /* Bind our PHY interface to the radio */ - radiodev->ops->bind(radiodev, mac->phyif); + radiodev->ops->bind(radiodev, &mac->phyif); return (MACHANDLE)mac; } @@ -444,7 +467,7 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) { FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; - FAR struct mac802154_trans_s *trans; + FAR struct mac802154_trans_s trans; struct mac802154_unsec_mhr_s mhr; int ret; @@ -462,11 +485,12 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) /* Ensure we start with a clear frame control field */ - mhr.frame_control = 0; + mhr.u.frame_control = 0; /* Set the frame type to Data */ - mhr.frame_control |= IEEE802154_FRAME_DATA << IEEE802154_FRAMECTRL_SHIFT_FTYPE; + mhr.u.frame_control |= IEEE802154_FRAME_DATA << + IEEE802154_FRAMECTRL_SHIFT_FTYPE; /* If the msduLength is greater than aMaxMACSafePayloadSize, the MAC sublayer * will set the Frame Version to one. [1] pg. 118. @@ -474,7 +498,7 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) if (req->msdu_length > IEEE802154_MAX_SAFE_MAC_PAYLOAD_SIZE) { - mhr.frame_ctrl |= IEEE802154_FRAMECTRL_VERSION; + mhr.u.frame_control |= IEEE802154_FRAMECTRL_VERSION; } /* If the TXOptions parameter specifies that an acknowledged transmission is @@ -482,7 +506,8 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) * 5.1.6.4 [1] pg. 118. */ - mhr.frame_ctrl |= (req->msdu_flags.ack_tx << IEEE802154_FRAMECTRL_SHIFT_ACKREQ); + mhr.u.frame_control |= (req->msdu_flags.ack_tx << + IEEE802154_FRAMECTRL_SHIFT_ACKREQ); /* If the destination address is present, copy the PAN ID and one of the * addresses, depending on mode, into the MHR . @@ -490,28 +515,29 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) if (req->dest_addr.mode != IEEE802154_ADDRMODE_NONE) { - memcpy(&mhr.data[mhr.length], req->dest_addr.panid, 2); + memcpy(&mhr.u.data[mhr.length], &req->dest_addr.panid, 2); mhr.length += 2; if (req->dest_addr.mode == IEEE802154_ADDRMODE_SHORT) { - memcpy(&mhr.data[mhr.length], req->dest_addr.saddr, 2); + memcpy(&mhr.u.data[mhr.length], &req->dest_addr.saddr, 2); mhr.length += 2; } else if (req->dest_addr.mode == IEEE802154_ADDRMODE_EXTENDED) { - memcpy(&mhr.data[mhr.length], req->dest_addr.eaddr, 8); + memcpy(&mhr.u.data[mhr.length], &req->dest_addr.eaddr, 8); mhr.length += 8; } } /* Set the destination addr mode inside the frame contorl field */ - mhr.frame_ctrl |= (req->dest_addr.mode << IEEE802154_FRAMECTRL_SHIFT_DADDR); + mhr.u.frame_control |= (req->dest_addr.mode << + IEEE802154_FRAMECTRL_SHIFT_DADDR); /* From this point on, we need exclusive access to the privmac struct */ - ret = mac802154dev_takesem(&dev->md_exclsem); + ret = mac802154_takesem(&priv->exclsem); if (ret < 0) { wlerr("ERROR: mac802154_takesem failed: %d\n", ret); @@ -533,7 +559,7 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) if (req->dest_addr.panid == priv->addr.panid) { - mhr.frame_control |= IEEE802154_FRAMECTRL_PANIDCOMP; + mhr.u.frame_control |= IEEE802154_FRAMECTRL_PANIDCOMP; } } @@ -543,35 +569,36 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) * is off, we need to include the Source PAN ID. */ - if (req->dest_addr.mode == IEEE802154_ADDRMODE_NONE || - (mhr.frame_control & IEEE802154_FRAMECTRL_PANIDCOMP) + if ((req->dest_addr.mode == IEEE802154_ADDRMODE_NONE) || + (mhr.u.frame_control & IEEE802154_FRAMECTRL_PANIDCOMP)) { - memcpy(&mhr.data[mhr.length], priv->addr.panid, 2); + memcpy(&mhr.u.data[mhr.length], &priv->addr.panid, 2); mhr.length += 2; } if (req->src_addr_mode == IEEE802154_ADDRMODE_SHORT) { - memcpy(&mhr.data[mhr.length], priv->addr.saddr, 2); + memcpy(&mhr.u.data[mhr.length], &priv->addr.saddr, 2); mhr.length += 2; } else if (req->src_addr_mode == IEEE802154_ADDRMODE_EXTENDED) { - memcpy(&mhr.data[mhr.length], priv->addr.eaddr, 8); + memcpy(&mhr.u.data[mhr.length], &priv->addr.eaddr, 8); mhr.length += 8; } } /* Set the source addr mode inside the frame control field */ - mhr.frame_ctrl |= (req->src_addr_mode << IEEE802154_FRAMECTRL_SHIFT_SADDR); + mhr.u.frame_control |= (req->src_addr_mode << + IEEE802154_FRAMECTRL_SHIFT_SADDR); /* Each time a data or a MAC command frame is generated, the MAC sublayer * shall copy the value of macDSN into the Sequence Number field of the MHR * of the outgoing frame and then increment it by one. [1] pg. 40. */ - mhr.data[mhr.length++] = priv.dsn++; + mhr.u.data[mhr.length++] = priv->dsn++; /* Now that we know which fields are included in the header, we can make * sure we actually have enough room in the PSDU. @@ -583,13 +610,13 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) return -E2BIG; } - trans->mhr_buf = &mhr.data[0]; - trans->mhr_len = mhr.length; + trans.mhr_buf = &mhr.u.data[0]; + trans.mhr_len = mhr.length; - trans->d_buf = &req->msdu[0]; - trans->d_len = req->msdu_length; + trans.d_buf = &req->msdu[0]; + trans.d_len = req->msdu_length; - trans->msdu_handle = req->msdu_handle; + trans.msdu_handle = req->msdu_handle; /* If the TxOptions parameter specifies that a GTS transmission is required, * the MAC sublayer will determine whether it has a valid GTS as described @@ -635,14 +662,14 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) { /* Link the transaction into the indirect_trans list */ - priv->indirect_tail->flink = trans; - priv->indirect_tail = trans; + priv->indirect_tail->flink = &trans; + priv->indirect_tail = &trans; } else { /* Override the setting since it wasn't valid */ - req->msgu_flags.indirect_tx = 0; + req->msdu_flags.indirect_tx = 0; } } @@ -652,40 +679,50 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) { /* Link the transaction into the CSMA transaction list */ - priv->csma_tail->flink = trans; - priv->csma_tail = trans; + priv->csma_tail->flink = &trans; + priv->csma_tail = &trans; + + /* We no longer need to have the MAC layer locked. */ + + mac802154_givesem(&priv->exclsem); /* Notify the radio driver that there is data available */ - priv->radio->ops->tx_notify(priv->radio); + priv->radio->ops->txnotify_csma(priv->radio); - sem_wait(&trans->sem); + sem_wait(&trans.sem); } } return OK; } - /* Called from interrupt level or worker thread with interrupts disabled */ -static uint16_t mac802154_poll_csma(FAR struct ieee802154_phyif_s *phyif, +static int mac802154_poll_csma(FAR struct ieee802154_phyif_s *phyif, FAR struct ieee802154_txdesc_s *tx_desc, uint8_t *buf) { FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)&phyif->priv; - FAR struct mac802154_trans_s *trans; + int ret = 0; + + DEBUGASSERT(priv != 0); + + /* Get exclusive access to the driver structure. We don't care about any + * signals so if we see one, just go back to trying to get access again */ + + while (mac802154_takesem(&priv->exclsem) != 0); /* Check to see if there are any CSMA transactions waiting */ - if (mac->csma_head) + if (priv->csma_head) { /* Pop a CSMA transaction off the list */ - trans = mac->csma_head; - mac->csma_head = mac->csma_head.flink; + trans = priv->csma_head; + priv->csma_head = priv->csma_head->flink; /* Setup the transmit descriptor */ @@ -703,15 +740,17 @@ static uint16_t mac802154_poll_csma(FAR struct ieee802154_phyif_s *phyif, * returns. */ - sem_post(trans->sem); + sem_post(&trans->sem); - return txdesc->psdu_length; + ret = tx_desc->psdu_length; } - return 0; + mac802154_givesem(&priv->exclsem); + + return ret; } -static uint16_t mac802154_poll_gts(FAR struct ieee802154_phyif_s *phyif, +static int mac802154_poll_gts(FAR struct ieee802154_phyif_s *phyif, FAR struct ieee802154_txdesc_s *tx_desc, uint8_t *buf) { diff --git a/wireless/ieee802154/mac802154_device.c b/wireless/ieee802154/mac802154_device.c index b35049e9ace..8e9250a2180 100644 --- a/wireless/ieee802154/mac802154_device.c +++ b/wireless/ieee802154/mac802154_device.c @@ -45,6 +45,7 @@ #include #include #include +#include #include #include @@ -66,31 +67,6 @@ * Private Types ****************************************************************************/ -struct mac802154_devwrapper_s -{ - MACHANDLE md_mac; /* Saved binding to the mac layer */ - sem_t md_exclsem; /* Exclusive device access */ - - /* The following is a singly linked list of open references to the - * MAC device. - */ - - FAR struct mac802154_open_s *md_open; - FAR struct mac802154dev_dwait_s *md_dwait; - -#ifndef CONFIG_DISABLE_SIGNALS - /* MCPS Service notification information */ - - struct mac802154dev_notify_s md_mcps_notify; - pid_t md_mcps_pid; - - /* MLME Service notification information */ - - struct mac802154dev_notify_s md_mlme_notify; - pid_t md_mlme_pid; -#endif -}; - struct mac802154dev_notify_s { uint8_t mn_signo; /* Signal number to use in the notification */ @@ -120,6 +96,31 @@ struct mac802154dev_dwait_s FAR struct mac802154dev_dwait_s *mw_flink; }; +struct mac802154_devwrapper_s +{ + MACHANDLE md_mac; /* Saved binding to the mac layer */ + sem_t md_exclsem; /* Exclusive device access */ + + /* The following is a singly linked list of open references to the + * MAC device. + */ + + FAR struct mac802154dev_open_s *md_open; + FAR struct mac802154dev_dwait_s *md_dwait; + +#ifndef CONFIG_DISABLE_SIGNALS + /* MCPS Service notification information */ + + struct mac802154dev_notify_s md_mcps_notify; + pid_t md_mcps_pid; + + /* MLME Service notification information */ + + struct mac802154dev_notify_s md_mlme_notify; + pid_t md_mlme_pid; +#endif +}; + /**************************************************************************** * Private Function Prototypes ****************************************************************************/ @@ -358,7 +359,8 @@ static ssize_t mac802154dev_read(FAR struct file *filep, FAR char *buffer, * packet. */ - if (len < sizeof(struct ieee802154_frame_s)) + if ((len >= SIZEOF_IEEE802154_DATA_REQ_S(1)) && + (len <= SIZEOF_IEEE802154_DATA_REQ_S(IEEE802154_MAX_MAC_PAYLOAD_SIZE))) { wlerr("ERROR: buffer too small: %lu\n", (unsigned long)len); return -EINVAL; @@ -394,7 +396,6 @@ static ssize_t mac802154dev_write(FAR struct file *filep, FAR struct inode *inode; FAR struct mac802154_devwrapper_s *dev; FAR struct ieee802154_data_req_s *req; - FAR struct ieee802154_frame_s *frame; struct mac802154dev_dwait_s dwait; int ret; @@ -404,64 +405,82 @@ static ssize_t mac802154dev_write(FAR struct file *filep, dev = (FAR struct mac802154_devwrapper_s *)inode->i_private; /* Check to make sure that the buffer is big enough to hold at least one - * packet. - */ + * packet. */ - if (len < sizeof(struct ieee802154_frame_s)) + if ((len >= SIZEOF_IEEE802154_DATA_REQ_S(1)) && + (len <= SIZEOF_IEEE802154_DATA_REQ_S(IEEE802154_MAX_MAC_PAYLOAD_SIZE))) { - wlerr("ERROR: buffer too small: %lu\n", (unsigned long)len); + wlerr("ERROR: buffer isn't an ieee802154_data_req_s: %lu\n", + (unsigned long)len); + return -EINVAL; } DEBUGASSERT(buffer != NULL); - frame = (FAR struct ieee802154_frame_s *)buffer; + req = (FAR struct ieee802154_data_req_s *)buffer; - /* Get exclusive access to the driver structure */ + /* If this is a blocking operation, we need to setup a wait struct so we + * can unblock when the packet transmission has finished. If this is a + * non-blocking write, we pass off the data and then move along. Technically + * we stil have to wait for the transaction to get put into the buffer, but we + * won't wait for the transaction to actually finish. */ - ret = mac802154dev_takesem(&dev->md_exclsem); - if (ret < 0) + if (!(filep->f_oflags & O_NONBLOCK)) { - wlerr("ERROR: mac802154dev_takesem failed: %d\n", ret); - return ret; - } + /* Get exclusive access to the driver structure */ - /* Setup the wait struct */ + ret = mac802154dev_takesem(&dev->md_exclsem); + if (ret < 0) + { + wlerr("ERROR: mac802154dev_takesem failed: %d\n", ret); + return ret; + } - dwait.mw_handle = req->msdu_handle; + /* Setup the wait struct */ - /* Link the wait struct */ + dwait.mw_handle = req->msdu_handle; - dwait.mw_flink = dev->md_dwait; - dev->md_dwait = &dwait; + /* Link the wait struct */ + dwait.mw_flink = dev->md_dwait; + dev->md_dwait = &dwait; + + mac802154dev_givesem(&dev->md_exclsem); + + } + /* Pass the request to the MAC layer */ ret = mac802154_req_data(dev->md_mac, req); - mac802154dev_givesem(&dev->md_exclsem); - if (ret < 0) { wlerr("ERROR: req_data failed %d\n", ret); return ret; } - /* Wait for the DATA.confirm callback to be called for our handle */ - if (sem_wait(dwait.mw_sem) < 0) + if (!(filep->f_oflags & O_NONBLOCK)) { - /* This should only happen if the wait was canceled by an signal */ + /* Wait for the DATA.confirm callback to be called for our handle */ - DEBUGASSERT(errno == EINTR); - return -EINTR; + if (sem_wait(&dwait.mw_sem) < 0) + { + /* This should only happen if the wait was canceled by an signal */ + + DEBUGASSERT(errno == EINTR); + return -EINTR; + } + + /* The unlinking of the wait struct happens inside the callback. This + * is more efficient since it will already have to find the struct in + * the list in order to perform the sem_post. + */ + + return dwait.mw_status; } - /* The unlinking of the wait struct happens inside the callback. This - * is more efficient since it will already have to find the struct in - * the list in order to perform the sem_post. - */ - - return dwait.status; + return OK; } /**************************************************************************** @@ -477,7 +496,6 @@ static int mac802154dev_ioctl(FAR struct file *filep, int cmd, { FAR struct inode *inode; FAR struct mac802154_devwrapper_s *dev; - MACHANDLE mac; int ret; DEBUGASSERT(filep != NULL && filep->f_priv != NULL && @@ -564,10 +582,10 @@ static int mac802154dev_ioctl(FAR struct file *filep, int cmd, void mac802154dev_conf_data(MACHANDLE mac, FAR struct ieee802154_data_conf_s *conf) { - FAR struct mac802154_devwrapper_s *dev; + FAR struct mac802154_devwrapper_s *dev = + (FAR struct mac802154_devwrapper_s *)mac; FAR struct mac802154dev_dwait_s *curr; FAR struct mac802154dev_dwait_s *prev; - int ret; /* Get the dev from the callback context. This should have been set when * the char driver was registered. @@ -579,7 +597,7 @@ void mac802154dev_conf_data(MACHANDLE mac, /* Get exclusive access to the driver structure. We don't care about any * signals so if we see one, just go back to trying to get access again */ - while(mac802154dev_takesem(&dev->md_exclsem) != OK); + while (mac802154dev_takesem(&dev->md_exclsem) != 0); /* Search to see if there is a dwait pending for this transaction */ From 35756d62950ee6d2e5f7b5e594ad3796e8dbeb7c Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 18 Apr 2017 14:25:23 -0600 Subject: [PATCH 086/183] ieee802.15.4: Cosmetic changes from review of last PR. --- drivers/wireless/ieee802154/mrf24j40.c | 38 ++++++++----------- .../wireless/ieee802154/ieee802154_mac.h | 6 ++- wireless/ieee802154/mac802154.c | 36 ++++++++++-------- 3 files changed, 40 insertions(+), 40 deletions(-) diff --git a/drivers/wireless/ieee802154/mrf24j40.c b/drivers/wireless/ieee802154/mrf24j40.c index 655871eb94f..1b00a67e155 100644 --- a/drivers/wireless/ieee802154/mrf24j40.c +++ b/drivers/wireless/ieee802154/mrf24j40.c @@ -90,9 +90,9 @@ /* Definitions for PA control on high power modules */ -#define MRF24J40_PA_AUTO 1 -#define MRF24J40_PA_ED 2 -#define MRF24J40_PA_SLEEP 3 +#define MRF24J40_PA_AUTO 1 +#define MRF24J40_PA_ED 2 +#define MRF24J40_PA_SLEEP 3 #define MRF24J40_GTS_SLOTS 2 @@ -111,7 +111,7 @@ struct mrf24j40_txdesc_s struct mrf24j40_radio_s { - struct ieee802154_radio_s radio; /* The public device instance */ + struct ieee802154_radio_s radio; /* The public device instance */ /* Reference to the bound upper layer via the phyif interface */ @@ -120,11 +120,11 @@ struct mrf24j40_radio_s /* Low-level MCU-specific support */ FAR const struct mrf24j40_lower_s *lower; - FAR struct spi_dev_s *spi; /* Saved SPI interface instance */ + FAR struct spi_dev_s *spi; /* Saved SPI interface instance */ struct work_s irqwork; /* For deferring interrupt work to work queue */ struct work_s pollwork; /* For deferring poll work to the work queue */ - sem_t exclsem; /* Exclusive access to this struct */ + sem_t exclsem; /* Exclusive access to this struct */ uint16_t panid; /* PAN identifier, FFFF = not set */ uint16_t saddr; /* short address, FFFF = not set */ @@ -134,7 +134,7 @@ struct mrf24j40_radio_s uint8_t paenabled; /* enable usage of PA */ uint8_t rxmode; /* Reception mode: Main, no CRC, promiscuous */ int32_t txpower; /* TX power in mBm = dBm/100 */ - struct ieee802154_cca_s cca; /* Clear channel assessement method */ + struct ieee802154_cca_s cca; /* Clear channel assessement method */ /* Buffer Allocations */ @@ -171,9 +171,9 @@ static void mrf24j40_dopoll_csma(FAR void *arg); static void mrf24j40_dopoll_gts(FAR void *arg); static int mrf24j40_csma_setup(FAR struct mrf24j40_radio_s *dev, - uint8_t *buf, uint16_t buf_len); + uint8_t *buf, uint16_t buf_len); static int mrf24j40_gts_setup(FAR struct mrf24j40_radio_s *dev, uint8_t gts, - uint8_t *buf, uint16_t buf_len); + uint8_t *buf, uint16_t buf_len); /* IOCTL helpers */ @@ -338,7 +338,6 @@ static void mrf24j40_dopoll_csma(FAR void *arg) ret = dev->phyif->ops->poll_csma(dev->phyif, &dev->csma_desc.pub, &dev->tx_buf[0]); - if (ret > 0) { /* Now the txdesc is in use */ @@ -352,7 +351,6 @@ static void mrf24j40_dopoll_csma(FAR void *arg) } /* Setup the transmit on the device */ - } sem_post(&dev->exclsem); @@ -435,7 +433,6 @@ static void mrf24j40_dopoll_gts(FAR void *arg) { ret = dev->phyif->ops->poll_gts(dev->phyif, &dev->gts_desc[gts].pub, &dev->tx_buf[0]); - if (ret > 0) { /* Now the txdesc is in use */ @@ -953,12 +950,11 @@ static int mrf24j40_setdevmode(FAR struct mrf24j40_radio_s *dev, } else { - return -EINVAL; + return -EINVAL; } mrf24j40_setreg(dev->spi, MRF24J40_RXMCR, reg); dev->devmode = mode; - return ret; } @@ -974,7 +970,6 @@ static int mrf24j40_getdevmode(FAR struct mrf24j40_radio_s *dev, FAR uint8_t *mode) { *mode = dev->devmode; - return OK; } @@ -1074,7 +1069,6 @@ static int mrf24j40_gettxpower(FAR struct mrf24j40_radio_s *dev, FAR int32_t *txpwr) { *txpwr = dev->txpower; - return OK; } @@ -1134,7 +1128,6 @@ static int mrf24j40_getcca(FAR struct mrf24j40_radio_s *dev, FAR struct ieee802154_cca_s *cca) { memcpy(cca, &dev->cca, sizeof(struct ieee802154_cca_s)); - return OK; } @@ -1285,7 +1278,7 @@ static int mrf24j40_ioctl(FAR struct ieee802154_radio_s *radio, int cmd, return -ENOTTY; } - return ret; + return ret; } /**************************************************************************** @@ -1422,7 +1415,6 @@ static int mrf24j40_transmit(FAR struct ieee802154_radio_s *radio, /* Trigger packet emission */ mrf24j40_setreg(dev->spi, MRF24J40_TXNCON, reg); - return ret; } @@ -1473,11 +1465,11 @@ static void mrf24j40_irqwork_tx(FAR struct mrf24j40_radio_s *dev) /* 1 means it failed, we want 1 to mean it worked. */ - /* +#if 0 dev->radio.txok = (reg & MRF24J40_TXSTAT_TXNSTAT) != MRF24J40_TXSTAT_TXNSTAT; dev->radio.txretries = (reg & MRF24J40_TXSTAT_X_MASK) >> MRF24J40_TXSTAT_X_SHIFT; dev->radio.txbusy = (reg & MRF24J40_TXSTAT_CCAFAIL) == MRF24J40_TXSTAT_CCAFAIL; - */ +#endif //wlinfo("TXSTAT%02X!\n", txstat); #warning TODO report errors @@ -1568,7 +1560,9 @@ static void mrf24j40_irqwork_rx(FAR struct mrf24j40_radio_s *dev) dev->radio.rxbuf->lqi = mrf24j40_getreg(dev->spi, addr++); dev->radio.rxbuf->rssi = mrf24j40_getreg(dev->spi, addr++); - /* Reduce len by 2, we only receive frames with correct crc, no check required */ + /* Reduce len by 2, we only receive frames with correct crc, no check + * required. + */ dev->radio.rxbuf->len -= 2; diff --git a/include/nuttx/wireless/ieee802154/ieee802154_mac.h b/include/nuttx/wireless/ieee802154/ieee802154_mac.h index 800436de78d..6486129d614 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_mac.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_mac.h @@ -401,7 +401,8 @@ struct ieee802154_data_req_s * to be transmitted by the MAC sublayer enitity * Note: This could be a uint8_t but if anyone ever wants to use * non-standard frame lengths, they may want a length larger than - * a uint8_t */ + * a uint8_t. + */ uint16_t msdu_length; @@ -611,7 +612,8 @@ struct ieee802154_assoc_rsp_s struct ieee802154_assoc_conf_s { /* Associated device address ALWAYS passed in short address mode. The - * address will be IEEE802154_SADDR_UNSPEC if association was unsuccessful. + * address will be IEEE802154_SADDR_UNSPEC if association was + * unsuccessful. */ struct ieee802154_addr_s dev_addr; diff --git a/wireless/ieee802154/mac802154.c b/wireless/ieee802154/mac802154.c index 671e67b6e22..a23128820d3 100644 --- a/wireless/ieee802154/mac802154.c +++ b/wireless/ieee802154/mac802154.c @@ -245,12 +245,12 @@ static int mac802154_applymib(FAR struct ieee802154_privmac_s *priv); /* IEEE 802.15.4 PHY Interface OPs */ static int mac802154_poll_csma(FAR struct ieee802154_phyif_s *phyif, - FAR struct ieee802154_txdesc_s *tx_desc, - uint8_t *buf); + FAR struct ieee802154_txdesc_s *tx_desc, + FAR uint8_t *buf); static int mac802154_poll_gts(FAR struct ieee802154_phyif_s *phyif, - FAR struct ieee802154_txdesc_s *tx_desc, - uint8_t *buf); + FAR struct ieee802154_txdesc_s *tx_desc, + FAR uint8_t *buf); /**************************************************************************** * Private Data @@ -301,6 +301,7 @@ static inline int mac802154_takesem(sem_t *sem) static int mac802154_defaultmib(FAR struct ieee802154_privmac_s *priv) { /* TODO: Set all MAC fields to default values */ + return OK; } @@ -475,8 +476,9 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) mhr.length = 2; - /* Do a preliminary check to make sure the MSDU isn't too long for even the - * best case */ + /* Do a preliminary check to make sure the MSDU isn't too long for even + * the best case. + */ if (req->msdu_length > IEEE802154_MAX_MAC_PAYLOAD_SIZE) { @@ -492,8 +494,8 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) mhr.u.frame_control |= IEEE802154_FRAME_DATA << IEEE802154_FRAMECTRL_SHIFT_FTYPE; - /* If the msduLength is greater than aMaxMACSafePayloadSize, the MAC sublayer - * will set the Frame Version to one. [1] pg. 118. + /* If the msduLength is greater than aMaxMACSafePayloadSize, the MAC + * sublayer will set the Frame Version to one. [1] pg. 118. */ if (req->msdu_length > IEEE802154_MAX_SAFE_MAC_PAYLOAD_SIZE) @@ -501,8 +503,8 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) mhr.u.frame_control |= IEEE802154_FRAMECTRL_VERSION; } - /* If the TXOptions parameter specifies that an acknowledged transmission is - * required, the AR field will be set appropriately, as described in + /* If the TXOptions parameter specifies that an acknowledged transmission + * is required, the AR field will be set appropriately, as described in * 5.1.6.4 [1] pg. 118. */ @@ -700,8 +702,8 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) /* Called from interrupt level or worker thread with interrupts disabled */ static int mac802154_poll_csma(FAR struct ieee802154_phyif_s *phyif, - FAR struct ieee802154_txdesc_s *tx_desc, - uint8_t *buf) + FAR struct ieee802154_txdesc_s *tx_desc, + FAR uint8_t *buf) { FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)&phyif->priv; @@ -711,7 +713,8 @@ static int mac802154_poll_csma(FAR struct ieee802154_phyif_s *phyif, DEBUGASSERT(priv != 0); /* Get exclusive access to the driver structure. We don't care about any - * signals so if we see one, just go back to trying to get access again */ + * signals so if we see one, just go back to trying to get access again. + */ while (mac802154_takesem(&priv->exclsem) != 0); @@ -751,8 +754,8 @@ static int mac802154_poll_csma(FAR struct ieee802154_phyif_s *phyif, } static int mac802154_poll_gts(FAR struct ieee802154_phyif_s *phyif, - FAR struct ieee802154_txdesc_s *tx_desc, - uint8_t *buf) + FAR struct ieee802154_txdesc_s *tx_desc, + FAR uint8_t *buf) { return 0; } @@ -797,7 +800,8 @@ int mac802154_req_associate(MACHANDLE mac, /* Set the macPANId */ /* Set either the macCoordExtendedAddress and macCoordShortAddress - * depending on the CoordAddrMode in the primitive */ + * depending on the CoordAddrMode in the primitive. + */ if (req->coord_addr.mode == IEEE802154_ADDRMODE_EXTENDED) { From de4e2d84c42fbacf48f614cc58e85b5688a5cfe8 Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Wed, 19 Apr 2017 11:30:39 -0400 Subject: [PATCH 087/183] wireless/ieee802154: Simplifies MAC callback interface. Adds missing data type definitions --- .../wireless/ieee802154/ieee802154_mac.h | 976 +++++++++++++----- wireless/ieee802154/mac802154_device.c | 98 +- wireless/ieee802154/mac802154_netdev.c | 323 +++--- wireless/ieee802154/radio802154_device.c | 3 + 4 files changed, 963 insertions(+), 437 deletions(-) diff --git a/include/nuttx/wireless/ieee802154/ieee802154_mac.h b/include/nuttx/wireless/ieee802154/ieee802154_mac.h index 6486129d614..4bdbdde8764 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_mac.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_mac.h @@ -115,7 +115,7 @@ /* MAC commands */ #define IEEE802154_CMD_ASSOC_REQ 0x01 -#define IEEE802154_CMD_ASSOC_RSP 0x02 +#define IEEE802154_CMD_ASSOC_RESP 0x02 #define IEEE802154_CMD_DISASSOC_NOT 0x03 #define IEEE802154_CMD_DATA_REQ 0x04 #define IEEE802154_CMD_PANID_CONF_NOT 0x05 @@ -392,107 +392,6 @@ enum ieee802154_ranging_e IEEE802154_PHY_HEADER_ONLY }; -struct ieee802154_data_req_s -{ - enum ieee802154_addr_mode_e src_addr_mode; /* Source Address Mode */ - struct ieee802154_addr_s dest_addr; /* Destination Address */ - - /* Number of bytes contained in the MAC Service Data Unit (MSDU) - * to be transmitted by the MAC sublayer enitity - * Note: This could be a uint8_t but if anyone ever wants to use - * non-standard frame lengths, they may want a length larger than - * a uint8_t. - */ - - uint16_t msdu_length; - - - uint8_t msdu_handle; /* Handle assoc. with MSDU */ - struct - { - uint8_t ack_tx : 1; /* Acknowledge TX? */ - uint8_t gts_tx : 1; /* 1=GTS used for TX, 0=CAP used for TX */ - uint8_t indirect_tx : 1; /* Should indirect transmission be used? */ - } msdu_flags; - -#ifdef CONFIG_IEEE802154_SECURITY - /* Security information if enabled */ - - struct ieee802154_security_s security; -#endif - -#ifdef CONFIG_IEEE802154_UWB - /* The UWB Pulse Repetion Frequency to be used for the transmission */ - - enum ieee802154_uwbprf_e uwb_prf; - - /* The UWB preamble symbol repititions - * Should be one of: - * 0, 16, 64, 1024, 4096 - */ - - uint16_t uwb_presym_rep; - - /* The UWB Data Rate to be used for the transmission */ - - enum ieee802154_uwb_datarate_e data_rate; -#endif - - enum ieee802154_ranging_e ranging; - - /* The MAC service data unit array that is to be transmitted - * This must be at the end of the struct to allow the array - * to continue and make the struct "variable length" - */ - - uint8_t msdu[1]; -}; -#define SIZEOF_IEEE802154_DATA_REQ_S(n) \ - (sizeof(struct ieee802154_data_req_s) + (n) - 1) - -struct ieee802154_data_conf_s -{ - uint8_t msdu_handle; /* Handle assoc. with MSDU */ - - /* The time, in symbols, at which the data were transmitted */ - - uint32_t timestamp; - - enum ieee802154_status_e status; /* The status of the MSDU transmission */ - -#ifdef CONFIG_IEEE802154_RANGING - bool rng_rcvd; /* Ranging indicated by MSDU */ - - /* A count of the time units corresponding to an RMARKER at the antenna at - * the beginning of the ranging exchange - */ - - uint32_t rng_counter_start; - - /* A count of the time units corresponding to an RMARKER at the antenna at - * end of the ranging exchange - */ - - uint32_t rng_counter_stop; - - /* A count of the time units in a message exchange over which the tracking - * offset was measured - */ - - uint34_t rng_tracking_interval; - - /* A count of the time units slipped or advanced by the radio tracking - * system over the course of the entire tracking interval - */ - - uint32_t rng_offset; - - /* The Figure of Merit (FoM) characterizing the ranging measurement */ - - uint8_t rng_fom; -#endif -}; - struct ieee802154_capability_info_s { uint8_t reserved_0 : 1; /* Reserved */ @@ -553,7 +452,234 @@ struct ieee802154_pend_addr_s struct ieee802154_addr_s addr[7]; /* Array of at most 7 addresses */ }; -/* Primitive Semantics */ +/* Primitive Support Types ***************************************************/ + +union ieee802154_attr_val_u +{ + /* TODO: Finish this */ +}; + +struct ieee802154_gts_info_s +{ + uint8_t length : 4; /* Number of SF slots for GTS */ + uint8_t direction : 1; /* 0=transmit-only, 1=receive-only */ + uint8_t type : 1; /* 0=GTS deallocation, 1= GTS allocation */ + uint8_t reserved : 2; +}; + +enum ieee802154_scantype_e +{ + IEEE802154_SCANTYPE_ED, + IEEE802154_SCANTYPE_ACTIVE, + IEEE802154_SCANTYPE_PASSIVE, + IEEE802154_SCANTYPE_ORPHAN +}; + +/* Primitive Semantics *******************************************************/ + +/***************************************************************************** + * Primitive: MCPS-DATA.request + * + * Description: + * Requests the transfer of data to another device. + * + *****************************************************************************/ + +struct ieee802154_data_req_s +{ + enum ieee802154_addr_mode_e src_addr_mode; /* Source Address Mode */ + struct ieee802154_addr_s dest_addr; /* Destination Address */ + + /* Number of bytes contained in the MAC Service Data Unit (MSDU) + * to be transmitted by the MAC sublayer enitity + * Note: This could be a uint8_t but if anyone ever wants to use + * non-standard frame lengths, they may want a length larger than + * a uint8_t. + */ + + uint16_t msdu_length; + + uint8_t msdu_handle; /* Handle assoc. with MSDU */ + struct + { + uint8_t ack_tx : 1; /* Acknowledge TX? */ + uint8_t gts_tx : 1; /* 1=GTS used for TX, 0=CAP used for TX */ + uint8_t indirect_tx : 1; /* Should indirect transmission be used? */ + } msdu_flags; + +#ifdef CONFIG_IEEE802154_SECURITY + /* Security information if enabled */ + + struct ieee802154_security_s security; +#endif + +#ifdef CONFIG_IEEE802154_UWB + /* The UWB Pulse Repetion Frequency to be used for the transmission */ + + enum ieee802154_uwbprf_e uwb_prf; + + /* The UWB preamble symbol repititions + * Should be one of: + * 0, 16, 64, 1024, 4096 + */ + + uint16_t uwb_presym_rep; + + /* The UWB Data Rate to be used for the transmission */ + + enum ieee802154_uwb_datarate_e data_rate; +#endif + + enum ieee802154_ranging_e ranging; + + /* The MAC service data unit array that is to be transmitted + * This must be at the end of the struct to allow the array + * to continue and make the struct "variable length" + */ + + uint8_t msdu[1]; +}; + +#define SIZEOF_IEEE802154_DATA_REQ_S(n) \ + (sizeof(struct ieee802154_data_req_s) + (n) - 1) + +/***************************************************************************** + * Primitive: MCPS-DATA.confirm + * + * Description: + * Reports the results of a request to transfer data to another device. + * + *****************************************************************************/ + +struct ieee802154_data_conf_s +{ + uint8_t msdu_handle; /* Handle assoc. with MSDU */ + + /* The time, in symbols, at which the data were transmitted */ + + uint32_t timestamp; + + enum ieee802154_status_e status; /* The status of the MSDU transmission */ + +#ifdef CONFIG_IEEE802154_RANGING + bool rng_rcvd; /* Ranging indicated by MSDU */ + + /* A count of the time units corresponding to an RMARKER at the antenna at + * the beginning of the ranging exchange + */ + + uint32_t rng_counter_start; + + /* A count of the time units corresponding to an RMARKER at the antenna at + * end of the ranging exchange + */ + + uint32_t rng_counter_stop; + + /* A count of the time units in a message exchange over which the tracking + * offset was measured + */ + + uint34_t rng_tracking_interval; + + /* A count of the time units slipped or advanced by the radio tracking + * system over the course of the entire tracking interval + */ + + uint32_t rng_offset; + + /* The Figure of Merit (FoM) characterizing the ranging measurement */ + + uint8_t rng_fom; +#endif +}; + +/***************************************************************************** + * Primitive: MCPS-DATA.indication + * + * Description: + * Indicates the reception of data from another device. + * + *****************************************************************************/ + +struct ieee802154_data_ind_s +{ + uint8_t msdu_handle; /* Handle assoc. with MSDU */ + + /* The time, in symbols, at which the data were transmitted */ + + uint32_t timestamp; + + enum ieee802154_status_e status; /* The status of the MSDU transmission */ + +#ifdef CONFIG_IEEE802154_RANGING + bool rng_rcvd; /* Ranging indicated by MSDU */ + + /* A count of the time units corresponding to an RMARKER at the antenna at + * the beginning of the ranging exchange + */ + + uint32_t rng_counter_start; + + /* A count of the time units corresponding to an RMARKER at the antenna at + * end of the ranging exchange + */ + + uint32_t rng_counter_stop; + + /* A count of the time units in a message exchange over which the tracking + * offset was measured + */ + + uint34_t rng_tracking_interval; + + /* A count of the time units slipped or advanced by the radio tracking + * system over the course of the entire tracking interval + */ + + uint32_t rng_offset; + + /* The Figure of Merit (FoM) characterizing the ranging measurement */ + + uint8_t rng_fom; +#endif +}; + +/***************************************************************************** + * Primitive: MCPS-PURGE.request + * + * Description: + * Allows the next higher layer to purge an MSDU from the transaction queue. + * + *****************************************************************************/ + +struct ieee802154_purge_req_s +{ + uint8_t msdu_handle; /* Handle assoc. with MSDU */ +}; + +/***************************************************************************** + * Primitive: MCPS-PURGE.confirm + * + * Description: + * Allows the MAC sublayer to notify the next higher layer of the success of + * its request to purge an MSDU from the transaction queue. + * + *****************************************************************************/ + +struct ieee802154_purge_conf_s +{ + uint8_t msdu_handle; /* Handle assoc. with MSDU */ + enum ieee802154_status_e status; /* The status of the MSDU transmission */ +}; + +/***************************************************************************** + * Primitive: MLME-ASSOCIATE.request + * + * Description: + * Used by a device to request an association with a coordinator. + * + *****************************************************************************/ struct ieee802154_assoc_req_s { @@ -575,6 +701,14 @@ struct ieee802154_assoc_req_s #endif }; +/***************************************************************************** + * Primitive: MLME-ASSOCIATE.indication + * + * Description: + * Used to indicate the reception of an association request command. + * + *****************************************************************************/ + struct ieee802154_assoc_ind_s { /* Address of device requesting association. Always in extended mode */ @@ -592,7 +726,15 @@ struct ieee802154_assoc_ind_s #endif }; -struct ieee802154_assoc_rsp_s +/***************************************************************************** + * Primitive: MLME-ASSOCIATE.response + * + * Description: + * Used to initiate a response to an MLME-ASSOCIATE.indication primitive. + * + *****************************************************************************/ + +struct ieee802154_assoc_resp_s { /* Address of device requesting association. Always in extended mode */ @@ -609,6 +751,15 @@ struct ieee802154_assoc_rsp_s #endif }; +/***************************************************************************** + * Primitive: MLME-ASSOCIATE.confirm + * + * Description: + * Used to inform the next higher layer of the initiating device whether its + * request to associate was successful or unsuccessful. + * + *****************************************************************************/ + struct ieee802154_assoc_conf_s { /* Associated device address ALWAYS passed in short address mode. The @@ -629,6 +780,16 @@ struct ieee802154_assoc_conf_s #endif }; +/***************************************************************************** + * Primitive: MLME-DISASSOCIATE.request + * + * Description: + * Used by an associated device to notify the coordinator of its intent to + * leave the PAN. It is also used by the coordinator to instruct an + * associated device to leave the PAN. + * + *****************************************************************************/ + struct ieee802154_disassoc_req_s { /* Address of device to send disassociation notification */ @@ -648,6 +809,14 @@ struct ieee802154_disassoc_req_s #endif }; +/***************************************************************************** + * Primitive: MLME-DISASSOCIATE.indication + * + * Description: + * Used to indicate the reception of a disassociation notification command. + * + *****************************************************************************/ + struct ieee802154_disassoc_ind_s { /* Address of device requesting disassociation. Always extended mode */ @@ -665,6 +834,14 @@ struct ieee802154_disassoc_ind_s #endif }; +/***************************************************************************** + * Primitive: MLME-DISASSOCIATE.confirm + * + * Description: + * Reports the results of an MLME-DISASSOCIATE.request primitive. + * + *****************************************************************************/ + struct ieee802154_disassoc_conf_s { /* Status of the disassociation attempt */ @@ -676,6 +853,18 @@ struct ieee802154_disassoc_conf_s struct ieee802154_addr_s dev_addr; }; +/***************************************************************************** + * Primitive: MLME-BEACONNOTIFY.indication + * + * Description: + * Used to send parameters contained within a beacon frame received by the + * MAC sublayer to the next higher layer when either macAutoRequest is set to + * FALSE or when the beacon frame contains one or more octets of payload. The + * primitive also sends a measure of the LQI and the time the beacon frame + * was received. + * + *****************************************************************************/ + struct ieee802154_beaconnotify_ind_s { uint8_t bsn; /* Beacon sequence number */ @@ -700,100 +889,402 @@ struct ieee802154_beaconnotify_ind_s (sizeof(struct ieee802154_beaconnotify_ind_s) \ - IEEE802154_MAX_BEACON_PAYLOAD_LENGTH + (n)) -/* IOCTL data arguments *****************************************************/ +/***************************************************************************** + * Primitive: MLME-COMM-STATUS.indication + * + * Description: + * Allows the MLME to indicate a communications status. + * + *****************************************************************************/ -/* Data returned with MAC802154IOC_MLME_ASSOC_RESPONSE */ - -struct ieee802154_assocresp_s +struct ieee802154_commstatus_ind_s { - uint8_t eadr; - uint16_t saddr; - int status; + struct ieee802154_addr_s src_addr; + struct ieee802154_addr_s dest_addr; + enum ieee802154_status_e status; +#ifdef CONFIG_IEEE802154_SECURITY + /* Security information if enabled */ + + struct ieee802154_security_s security; +#endif }; -/* Data provided to MAC802154IOC_MLME_GET_REQUEST */ +/***************************************************************************** + * Primitive: MLME-GET.request + * + * Description: + * Requests information about a given PIB attribute. + * + *****************************************************************************/ -struct ieee802154_getreq_s +struct ieee802154_get_req_s { - enum ieee802154_pib_attr_e attr; + enum ieee802154_pib_attr_e pib_attr; }; -/* Data provided to MAC802154IOC_MLME_GTS_REQUEST */ +/***************************************************************************** + * Primitive: MLME-GET.confirm + * + * Description: + * Reports the results of an information request from the PIB. + * + *****************************************************************************/ -struct ieee802154_gtsreq_s +struct ieee802154_get_conf_s { - uint8_t characteristics; + enum ieee802154_status_e status; + enum ieee802154_pib_attr_e pib_attr; + union ieee802154_attr_val_u attr_value; }; -/* Data returned with MAC802154IOC_MLME_ORPHAN_RESPONSE */ +/***************************************************************************** + * Primitive: MLME-GTS.request + * + * Description: + * Allows a device to send a request to the PAN coordinator to allocate a new + * GTS or to deallocate an existing GTS. This primitive is also used by the + * PAN coordinator to initiate a GTS deallocation. + * + *****************************************************************************/ -struct ieee802154_orphanresp_s +struct ieee802154_gts_req_s { - uint8_t orphanaddr[MAX_ORPHAN_ADDR]; - uint16_t saddr; - bool associated; + struct ieee802154_gts_info_s gts_info; + +#ifdef CONFIG_IEEE802154_SECURITY + /* Security information if enabled */ + + struct ieee802154_security_s security; +#endif }; -/* Data provided with MAC802154IOC_MLME_RESET_REQUEST */ +/***************************************************************************** + * Primitive: MLME-GTS.confirm + * + * Description: + * Reports the results of a request to allocate a new GTS or to deallocate an + * existing GTS. + * + *****************************************************************************/ -struct ieee802154_resetreq_s +struct ieee802154_gts_conf_s { - bool setdefaults; + struct ieee802154_gts_info_s gts_info; + enum ieee802154_status_e status; }; -/* Data provided with MAC802154IOC_MLME_RXENABLE_REQUEST */ +/***************************************************************************** + * Primitive: MLME-GTS.indication + * + * Description: + * Indicates that a GTS has been allocated or that a previously allocated + * GTS has been deallocated. + * + *****************************************************************************/ -struct ieee802154_rxenabreq_s +struct ieee802154_gts_ind_s { - bool deferrable; - int ontime; - int duration; + uint16_t dev_addr; + struct ieee802154_gts_info_s gts_info; +#ifdef CONFIG_IEEE802154_SECURITY + /* Security information if enabled */ + + struct ieee802154_security_s security; +#endif }; -/* Data provided with MAC802154IOC_MLME_SCAN_REQUEST */ +/***************************************************************************** + * Primitive: MLME-ORPHAN.indication + * + * Description: + * Generated by the MLME of a coordinator and issued to its next higher layer + * on receipt of an orphan notification command. + * + *****************************************************************************/ -struct ieee802154_scanreq_s +struct ieee802154_orphan_ind_s { - uint8_t type; - uint32_t channels; - int duration; + uint8_t orphan_addr[8]; +#ifdef CONFIG_IEEE802154_SECURITY + /* Security information if enabled */ + + struct ieee802154_security_s security; +#endif }; -/* Data provided with MAC802154IOC_MLME_SET_REQUEST */ +/***************************************************************************** + * Primitive: MLME-ORPHAN.response + * + * Description: + * Allows the next higher layer of a coordinator to respond to the + * MLME-ORPHAN.indication primitive. + * + *****************************************************************************/ -struct ieee802154_setreq_s +struct ieee802154_orphan_resp_s { - FAR uint8_t *value; - int valuelen; - int attribute; + uint8_t orphan_addr[8]; +#ifdef CONFIG_IEEE802154_SECURITY + /* Security information if enabled */ + + struct ieee802154_security_s security; +#endif }; -/* Data provided with MAC802154IOC_MLME_START_REQUEST */ +/***************************************************************************** + * Primitive: MLME-RESET.request + * + * Description: + * Used by the next higher layer to request that the MLME performs a reset + * operation. + * + *****************************************************************************/ -struct ieee802154_startreq_s +struct ieee802154_reset_req_s { - int channel; - uint16_t panid; - uint8_t bo; - uint8_t fo; - bool coord; - bool batext; - bool realign; + bool rst_pibattr; }; -/* Data provided with MAC802154IOC_MLME_SYNC_REQUEST */ +/***************************************************************************** + * Primitive: MLME-RESET.confirm + * + * Description: + * Reports the results of the reset operation. + * + *****************************************************************************/ -struct ieee802154_syncreq_s +struct ieee802154_reset_conf_s { - int channel; - bool track; + enum ieee802154_status_e status; }; -/* Data provided with MAC802154IOC_MLME_POLL_REQUEST */ +/***************************************************************************** + * Primitive: MLME-RXENABLE.request + * + * Description: + * Allows the next higher layer to request that the receiver is either + * enabled for a finite period of time or disabled. + * + *****************************************************************************/ -struct ieee802154_pollreq_s +struct ieee802154_rxenable_req_s { - FAR uint8_t *coordaddr; + /* Number of symbols measured from the start of the superframe before the + * receiver is to be enabled or disabled. */ + + uint32_t rxon_time; + + /* Number of symbols for which the receiver is to be enabled */ + + uint32_t rxon_dur; + + uint8_t defer_permit : 1; /* 0=Only attempt operation on current superframe + * 1=Operation can be deferred to next superframe */ + uint8_t rng_rxctrl : 1; /* 0=RANGING_OFF, 1=RANGING_OFF */ +}; + +/***************************************************************************** + * Primitive: MLME-RXENABLE.confirm + * + * Description: + * Reports the results of the attempt to enable or disable the receiver. + * + *****************************************************************************/ + +struct ieee802154_rxenable_conf_s +{ + enum ieee802154_status_e status; +}; + +/***************************************************************************** + * Primitive: MLME-SCAN.request + * + * Description: + * Used to initiate a channel scan over a given list of channels. + * + *****************************************************************************/ + +struct ieee802154_scan_req_s +{ + + enum ieee802154_scantype_e type; + uint8_t duration; + uint8_t ch_page; + +#ifdef CONFIG_IEEE802154_SECURITY + /* Security information if enabled */ + + struct ieee802154_security_s security; +#endif + + uint8_t channels[1]; +}; + +#define SIZEOF_IEEE802154_SCAN_REQ_S(n) \ + (sizeof(struct ieee802154_scan_req_s) + (n) - 1) + +/***************************************************************************** + * Primitive: MLME-SCAN.confirm + * + * Description: + * Reports the result of the channel scan request. + * + *****************************************************************************/ + +struct ieee802154_scan_conf_s +{ + enum ieee802154_status_e status; + enum ieee802154_scantype_e type; + uint8_t ch_page; + uint8_t num_channels; + +#warning Figure out how to handle missing primitive semantics. See standard. +}; + +/***************************************************************************** + * Primitive: MLME-SET.request + * + * Description: + * Attempts to write the given value to the indicated PIB attribute. + * + *****************************************************************************/ + +struct ieee802154_set_req_s +{ + enum ieee802154_pib_attr_e pib_attr; + union ieee802154_attr_val_u attr_value; +}; + +/***************************************************************************** + * Primitive: MLME-SET.confirm + * + * Description: + * Reports the results of an attempt to write a value to a PIB attribute. + * + *****************************************************************************/ + +struct ieee802154_set_conf_s +{ + enum ieee802154_status_e status; + enum ieee802154_pib_attr_e pib_attr; +}; + +/***************************************************************************** + * Primitive: MLME-START.request + * + * Description: + * Used by the PAN coordinator to initiate a new PAN or to begin using a new + * superframe configuration. This primitive is also used by a device already + * associated with an existing PAN to begin using a new superframe + * configuration. + * + *****************************************************************************/ + +struct ieee802154_start_req_s +{ + uint16_t pan_id; + uint8_t ch_num; + uint8_t ch_page; + + uint32_t start_time : 24; + uint32_t beacon_order : 8; + + uint8_t sf_order; + + uint8_t pan_coord : 1; + uint8_t batt_life_ext : 1; + uint8_t coord_realign : 1; + +#ifdef CONFIG_IEEE802154_SECURITY + /* Security information if enabled */ + + struct ieee802154_security_s coord_realign; + struct ieee802154_security_s beacon; +#endif +}; + +/***************************************************************************** + * Primitive: MLME-START.confirm + * + * Description: + * Reports the results of the attempt to start using a new superframe + * configuration. + * + *****************************************************************************/ + +struct ieee802154_start_conf_s +{ + enum ieee802154_status_e status; +}; + +/***************************************************************************** + * Primitive: MLME-SYNC.request + * + * Description: + * Requests to synchronize with the coordinator by acquiring and, if + * specified, tracking its beacons. + * + *****************************************************************************/ + +struct ieee802154_sync_req_s +{ + uint8_t ch_num; + uint8_t ch_page; + bool track_beacon; +}; + +/***************************************************************************** + * Primitive: MLME-SYNC-LOSS.indication + * + * Description: + * Indicates the loss of synchronization with a coordinator. + * + *****************************************************************************/ + +struct ieee802154_syncloss_ind_s +{ + enum ieee802154_status_e loss_reason; + uint16_t pan_id; + uint8_t ch_num; + uint8_t ch_page; + +#ifdef CONFIG_IEEE802154_SECURITY + /* Security information if enabled */ + + struct ieee802154_security_s security; +#endif +}; + +/***************************************************************************** + * Primitive: MLME-POLL.request + * + * Description: + * Prompts the device to request data from the coordinator. + * + *****************************************************************************/ + +struct ieee802154_poll_req_s +{ + struct ieee802154_addr_s coord_addr; + +#ifdef CONFIG_IEEE802154_SECURITY + /* Security information if enabled */ + + struct ieee802154_security_s security; +#endif +}; + +/***************************************************************************** + * Primitive: MLME-POLL.confirm + * + * Description: + * Reports the results of a request to poll the coordinator for data. + * + *****************************************************************************/ + +struct ieee802154_poll_conf_s +{ + enum ieee802154_status_e status; }; /* A pointer to this structure is passed as the argument of each IOCTL @@ -803,23 +1294,52 @@ struct ieee802154_pollreq_s union ieee802154_macarg_u { struct ieee802154_assoc_req_s assocreq; /* MAC802154IOC_MLME_ASSOC_REQUEST */ - struct ieee802154_assocresp_s assocresp; /* MAC802154IOC_MLME_ASSOC_RESPONSE */ + struct ieee802154_assoc_resp_s assocresp; /* MAC802154IOC_MLME_ASSOC_RESPONSE */ struct ieee802154_disassoc_req_s disassocreq; /* MAC802154IOC_MLME_DISASSOC_REQUEST */ - struct ieee802154_getreq_s getreq; /* MAC802154IOC_MLME_GET_REQUEST */ - struct ieee802154_gtsreq_s gtsreq; /* MAC802154IOC_MLME_GTS_REQUEST */ - struct ieee802154_orphanresp_s orphanresp; /* MAC802154IOC_MLME_ORPHAN_RESPONSE */ - struct ieee802154_resetreq_s resetreq; /* MAC802154IOC_MLME_RESET_REQUEST */ - struct ieee802154_rxenabreq_s rxenabreq; /* MAC802154IOC_MLME_RXENABLE_REQUEST */ - struct ieee802154_scanreq_s scanreq; /* MAC802154IOC_MLME_SCAN_REQUEST */ - struct ieee802154_setreq_s setreq; /* MAC802154IOC_MLME_SET_REQUEST */ - struct ieee802154_startreq_s startreq; /* MAC802154IOC_MLME_START_REQUEST */ - struct ieee802154_syncreq_s syncreq; /* MAC802154IOC_MLME_SYNC_REQUEST */ - struct ieee802154_pollreq_s pollreq; /* MAC802154IOC_MLME_POLL_REQUEST */ + struct ieee802154_get_req_s getreq; /* MAC802154IOC_MLME_GET_REQUEST */ + struct ieee802154_gts_req_s gtsreq; /* MAC802154IOC_MLME_GTS_REQUEST */ + struct ieee802154_orphan_resp_s orphanresp; /* MAC802154IOC_MLME_ORPHAN_RESPONSE */ + struct ieee802154_reset_req_s resetreq; /* MAC802154IOC_MLME_RESET_REQUEST */ + struct ieee802154_rxenable_req_s rxenabreq; /* MAC802154IOC_MLME_RXENABLE_REQUEST */ + struct ieee802154_scan_req_s scanreq; /* MAC802154IOC_MLME_SCAN_REQUEST */ + struct ieee802154_set_req_s setreq; /* MAC802154IOC_MLME_SET_REQUEST */ + struct ieee802154_start_req_s startreq; /* MAC802154IOC_MLME_START_REQUEST */ + struct ieee802154_sync_req_s syncreq; /* MAC802154IOC_MLME_SYNC_REQUEST */ + struct ieee802154_poll_req_s pollreq; /* MAC802154IOC_MLME_POLL_REQUEST */ /* To be determined */ /* MAC802154IOC_MLME_DPS_REQUEST */ /* To be determined */ /* MAC802154IOC_MLME_SOUNDING_REQUEST */ /* To be determined */ /* MAC802154IOC_MLME_CALIBRATE_REQUEST */ }; +union ieee802154_mlme_notify_u +{ + struct ieee802154_assoc_conf_s assocconf; + struct ieee802154_disassoc_conf_s disassocconf; + struct ieee802154_get_conf_s getconf; + struct ieee802154_gts_conf_s gtsconf; + struct ieee802154_reset_conf_s resetconf; + struct ieee802154_rxenable_conf_s rxenableconf; + struct ieee802154_scan_conf_s scanconf; + struct ieee802154_set_conf_s setconf; + struct ieee802154_start_conf_s startconf; + struct ieee802154_poll_conf_s pollconf; + + struct ieee802154_assoc_ind_s assocind; + struct ieee802154_disassoc_ind_s disassocind; + struct ieee802154_beaconnotify_ind_s beaconnotifyind; + struct ieee802154_gts_ind_s gtsind; + struct ieee802154_orphan_ind_s orphanind; + struct ieee802154_commstatus_ind_s commstatusind; + struct ieee802154_syncloss_ind_s synclossind; +}; + +union ieee802154_mcps_notify_u +{ + struct ieee802154_data_conf_s dataconf; + struct ieee802154_purge_conf_s purgeconf; + struct ieee802154_data_ind_s dataind; +}; + #ifdef CONFIG_NET_6LOWPAN /* For the case of network IOCTLs, the network IOCTL to the MAC network * driver will include a device name like "wpan0" as the destination of @@ -840,91 +1360,51 @@ struct ieee802154_netmac_s typedef FAR void *MACHANDLE; -/* Notifications */ +/* MAC Service Notifications */ + +enum ieee802154_macnotify_e +{ + /* MCPS Notifications */ + + IEEE802154_NOTIFY_CONF_DATA = 0x00, + IEEE802154_NOTIFY_CONF_PURGE, + IEEE802154_NOTIFY_IND_DATA, + + /* MLME Notifications */ + + IEEE802154_NOTIFY_CONF_ASSOC, + IEEE802154_NOTIFY_CONF_DISASSOC, + IEEE802154_NOTIFY_CONF_GET, + IEEE802154_NOTIFY_CONF_GTS, + IEEE802154_NOTIFY_CONF_RESET, + IEEE802154_NOTIFY_CONF_RXENABLE, + IEEE802154_NOTIFY_CONF_SCAN, + IEEE802154_NOTIFY_CONF_SET, + IEEE802154_NOTIFY_CONF_START, + IEEE802154_NOTIFY_CONF_POLL, + + IEEE802154_NOTIFY_IND_ASSOC, + IEEE802154_NOTIFY_IND_DISASSOC, + IEEE802154_NOTIFY_IND_BEACONNOTIFY, + IEEE802154_NOTIFY_IND_GTS, + IEEE802154_NOTIFY_IND_ORPHAN, + IEEE802154_NOTIFY_IND_COMMSTATUS, + IEEE802154_NOTIFY_IND_SYNCLOSS +}; + +/* Callback operations to notify the next highest layer of various asynchronous + * events, usually triggered by some previous request or response invoked by the + * upper layer */ struct ieee802154_maccb_s { - /* Asynchronous confirmations to requests */ + CODE void (*mlme_notify) (FAR struct ieee802154_maccb_s *maccb, + enum ieee802154_macnotify_e notif, + FAR union ieee802154_mlme_notify_u *arg); - /* Data frame was received by remote device */ - - CODE void (*conf_data)(MACHANDLE mac, - FAR struct ieee802154_data_conf_s *conf); - - /* Data frame was purged */ - - CODE void (*conf_purge)(MACHANDLE mac, uint8_t handle, int status); - - /* Association request completed */ - - CODE void (*conf_associate)(MACHANDLE mac, uint16_t saddr, int status); - - /* Disassociation request completed */ - - CODE void (*conf_disassociate)(MACHANDLE mac, int status); - - /* PIB data returned */ - - CODE void (*conf_get)(MACHANDLE mac, int status, int attribute, - FAR uint8_t *value, int valuelen); - - /* GTS management completed */ - - CODE void (*conf_gts)(MACHANDLE mac, FAR uint8_t *characteristics, - int status); - - /* MAC reset completed */ - - CODE void (*conf_reset)(MACHANDLE mac, int status); - - CODE void (*conf_rxenable)(MACHANDLE mac, int status); - - CODE void (*conf_scan)(MACHANDLE mac, int status, uint8_t type, - uint32_t unscanned, int rsltsize, - FAR uint8_t *edlist, FAR uint8_t *pandescs); - - CODE void (*conf_set)(MACHANDLE mac, int status, int attribute); - - CODE void (*conf_start)(MACHANDLE mac, int status); - - CODE void (*conf_poll)(MACHANDLE mac, int status); - - /* Asynchronous event indications, replied to synchronously with responses */ - - /* Data frame received */ - - CODE void (*ind_data)(MACHANDLE mac, FAR uint8_t *buf, int len); - - /* Association request received */ - - CODE void (*ind_associate)(MACHANDLE mac, uint16_t clipanid, - FAR uint8_t *clieaddr); - - /* Disassociation request received */ - - CODE void (*ind_disassociate)(MACHANDLE mac, FAR uint8_t *eadr, - uint8_t reason); - - /* Beacon notification */ - - CODE void (*ind_beaconnotify)(MACHANDLE mac, FAR uint8_t *bsn, - FAR struct ieee802154_pan_desc_s *pandesc, - FAR uint8_t *sdu, int sdulen); - - /* GTS management request received */ - - CODE void (*ind_gts)(MACHANDLE mac, FAR uint8_t *devaddr, - FAR uint8_t *characteristics); - - /* Orphan device detected */ - - CODE void (*ind_orphan)(MACHANDLE mac, FAR uint8_t *orphanaddr); - - CODE void (*ind_commstatus)(MACHANDLE mac, uint16_t panid, - FAR uint8_t *src, FAR uint8_t *dst, - int status); - - CODE void (*ind_syncloss)(MACHANDLE mac, int reason); + CODE void (*mcps_notify) (FAR struct ieee802154_maccb_s *maccb, + enum ieee802154_macnotify_e notif, + FAR union ieee802154_mcps_notify_u *arg); }; #ifdef __cplusplus diff --git a/wireless/ieee802154/mac802154_device.c b/wireless/ieee802154/mac802154_device.c index 8e9250a2180..52a3e5b4e35 100644 --- a/wireless/ieee802154/mac802154_device.c +++ b/wireless/ieee802154/mac802154_device.c @@ -96,10 +96,19 @@ struct mac802154dev_dwait_s FAR struct mac802154dev_dwait_s *mw_flink; }; +struct mac802154dev_callback_s +{ + /* This holds the information visible to the MAC layer */ + + struct ieee802154_maccb_s mc_cb; /* Interface understood by the MAC layer */ + FAR struct mac802154_devwrapper_s *mc_priv; /* Our priv data */ +}; + struct mac802154_devwrapper_s { - MACHANDLE md_mac; /* Saved binding to the mac layer */ - sem_t md_exclsem; /* Exclusive device access */ + MACHANDLE md_mac; /* Saved binding to the mac layer */ + struct mac802154dev_callback_s md_cb; /* Callback information */ + sem_t md_exclsem; /* Exclusive device access */ /* The following is a singly linked list of open references to the * MAC device. @@ -139,6 +148,11 @@ static ssize_t mac802154dev_write(FAR struct file *filep, static int mac802154dev_ioctl(FAR struct file *filep, int cmd, unsigned long arg); +/* MAC callback helpers */ + +static void mac802154dev_conf_data(FAR struct mac802154_devwrapper_s *dev, + FAR struct ieee802154_data_conf_s *conf); + /**************************************************************************** * Private Data ****************************************************************************/ @@ -579,21 +593,54 @@ static int mac802154dev_ioctl(FAR struct file *filep, int cmd, return ret; } -void mac802154dev_conf_data(MACHANDLE mac, - FAR struct ieee802154_data_conf_s *conf) +static void mac802154dev_mlme_notify(FAR struct ieee802154_maccb_s *maccb, + enum ieee802154_macnotify_e notif, + FAR union ieee802154_mlme_notify_u *arg) +{ + FAR struct mac802154dev_callback_s *cb = + (FAR struct mac802154dev_callback_s *)maccb; + FAR struct mac802154_devwrapper_s *dev; + + DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); + dev = cb->mc_priv; + + switch (notif) + { +#warning Handle MLME notifications + default: + break; + } +} + +static void mac802154dev_mcps_notify(FAR struct ieee802154_maccb_s *maccb, + enum ieee802154_macnotify_e notif, + FAR union ieee802154_mcps_notify_u *arg) +{ + FAR struct mac802154dev_callback_s *cb = + (FAR struct mac802154dev_callback_s *)maccb; + FAR struct mac802154_devwrapper_s *dev; + + DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); + dev = cb->mc_priv; + + switch (notif) + { + case IEEE802154_NOTIFY_CONF_DATA: + { + mac802154dev_conf_data(dev, &arg->dataconf); + } + break; + default: + break; + } +} + +static void mac802154dev_conf_data(FAR struct mac802154_devwrapper_s *dev, + FAR struct ieee802154_data_conf_s *conf) { - FAR struct mac802154_devwrapper_s *dev = - (FAR struct mac802154_devwrapper_s *)mac; FAR struct mac802154dev_dwait_s *curr; FAR struct mac802154dev_dwait_s *prev; - /* Get the dev from the callback context. This should have been set when - * the char driver was registered. - * - * REVISIT: See mac802154_netdev.c - */ -#warning Missing logic - /* Get exclusive access to the driver structure. We don't care about any * signals so if we see one, just go back to trying to get access again */ @@ -676,6 +723,7 @@ void mac802154dev_conf_data(MACHANDLE mac, int mac802154dev_register(MACHANDLE mac, int minor) { FAR struct mac802154_devwrapper_s *dev; + FAR struct ieee802154_maccb_s *maccb; char devname[DEVNAME_FMTLEN]; int ret; @@ -692,11 +740,25 @@ int mac802154dev_register(MACHANDLE mac, int minor) sem_init(&dev->md_exclsem, 0, 1); /* Allow the device to be opened once * before blocking */ - /* Initialize the callbacks and bind them to the radio - * - * REVISIT: See mac802154_netdev.c - */ -#warning Missing logic + /* Initialize the MAC callbacks */ + + dev->md_cb.mc_priv = dev; + + maccb = &dev->md_cb.mc_cb; + maccb->mlme_notify = mac802154dev_mlme_notify; + maccb->mcps_notify = mac802154dev_mcps_notify; + + /* Bind the callback structure */ + + ret = mac802154_bind(mac, maccb); + if (ret < 0) + { + nerr("ERROR: Failed to bind the MAC callbacks: %d\n", ret); + + /* Free memory and return the error */ + kmm_free(dev); + return ret; + } /* Create the character device name */ diff --git a/wireless/ieee802154/mac802154_netdev.c b/wireless/ieee802154/mac802154_netdev.c index 8768c3ee74f..7965578f385 100644 --- a/wireless/ieee802154/mac802154_netdev.c +++ b/wireless/ieee802154/mac802154_netdev.c @@ -157,42 +157,60 @@ struct macnet_driver_s ****************************************************************************/ /* IEE802.15.4 MAC callback functions ***************************************/ + +static void macnet_mlme_notify(FAR struct ieee802154_maccb_s *maccb, + enum ieee802154_macnotify_e notif, + FAR union ieee802154_mlme_notify_u *arg); + +static void macnet_mcps_notify(FAR struct ieee802154_maccb_s *maccb, + enum ieee802154_macnotify_e notif, + FAR union ieee802154_mcps_notify_u *arg); + /* Asynchronous confirmations to requests */ -static void macnet_conf_data(MACHANDLE mac, +static void macnet_conf_data(FAR struct macnet_driver_s *priv, FAR struct ieee802154_data_conf_s *conf); -static void macnet_conf_purge(MACHANDLE mac, uint8_t handle, int status); -static void macnet_conf_associate(MACHANDLE mac, uint16_t saddr, int status); -static void macnet_conf_disassociate(MACHANDLE mac, int status); -static void macnet_conf_get(MACHANDLE mac, int status, int attribute, - FAR uint8_t *value, int valuelen); -static void macnet_conf_gts(MACHANDLE mac, FAR uint8_t *characteristics, - int status); -static void macnet_conf_reset(MACHANDLE mac, int status); -static void macnet_conf_rxenable(MACHANDLE mac, int status); -static void macnet_conf_scan(MACHANDLE mac, int status, uint8_t type, - uint32_t unscanned, int rsltsize, FAR uint8_t *edlist, - FAR uint8_t *pandescs); -static void macnet_conf_set(MACHANDLE mac, int status, int attribute); -static void macnet_conf_start(MACHANDLE mac, int status); -static void macnet_conf_poll(MACHANDLE mac, int status); +static void macnet_conf_purge(FAR struct macnet_driver_s *priv, + FAR struct ieee802154_purge_conf_s *conf); +static void macnet_conf_associate(FAR struct macnet_driver_s *priv, + FAR struct ieee802154_assoc_conf_s *conf); +static void macnet_conf_disassociate(FAR struct macnet_driver_s *priv, + FAR struct ieee802154_disassoc_conf_s *conf); +static void macnet_conf_get(FAR struct macnet_driver_s *priv, + FAR struct ieee802154_get_conf_s *conf); +static void macnet_conf_gts(FAR struct macnet_driver_s *priv, + FAR struct ieee802154_gts_conf_s *conf); +static void macnet_conf_reset(FAR struct macnet_driver_s *priv, + FAR struct ieee802154_reset_conf_s *conf); +static void macnet_conf_rxenable(FAR struct macnet_driver_s *priv, + FAR struct ieee802154_rxenable_conf_s *conf); +static void macnet_conf_scan(FAR struct macnet_driver_s *priv, + FAR struct ieee802154_scan_conf_s *conf); +static void macnet_conf_set(FAR struct macnet_driver_s *priv, + FAR struct ieee802154_set_conf_s *conf); +static void macnet_conf_start(FAR struct macnet_driver_s *priv, + FAR struct ieee802154_start_conf_s *conf); +static void macnet_conf_poll(FAR struct macnet_driver_s *priv, + FAR struct ieee802154_poll_conf_s *conf); /* Asynchronous event indications, replied to synchronously with responses */ -static void macnet_ind_data(MACHANDLE mac, FAR uint8_t *buf, int len); -static void macnet_ind_associate(MACHANDLE mac, uint16_t clipanid, - FAR uint8_t *clieaddr); -static void macnet_ind_disassociate(MACHANDLE mac, FAR uint8_t *eadr, - uint8_t reason); -static void macnet_ind_beaconnotify(MACHANDLE mac, FAR uint8_t *bsn, - FAR struct ieee802154_pan_desc_s *pandesc, FAR uint8_t *sdu, - int sdulen); -static void macnet_ind_gts(MACHANDLE mac, FAR uint8_t *devaddr, - FAR uint8_t *characteristics); -static void macnet_ind_orphan(MACHANDLE mac, FAR uint8_t *orphanaddr); -static void macnet_ind_commstatus(MACHANDLE mac, uint16_t panid, - FAR uint8_t *src, FAR uint8_t *dst, int status); -static void macnet_ind_syncloss(MACHANDLE mac, int reason); +static void macnet_ind_data(FAR struct macnet_driver_s *priv, + FAR struct ieee802154_data_ind_s *conf); +static void macnet_ind_associate(FAR struct macnet_driver_s *priv, + FAR struct ieee802154_assoc_ind_s *conf); +static void macnet_ind_disassociate(FAR struct macnet_driver_s *priv, + FAR struct ieee802154_disassoc_ind_s *conf); +static void macnet_ind_beaconnotify(FAR struct macnet_driver_s *priv, + FAR struct ieee802154_beaconnotify_ind_s *conf); +static void macnet_ind_gts(FAR struct macnet_driver_s *priv, + FAR struct ieee802154_gts_ind_s *conf); +static void macnet_ind_orphan(FAR struct macnet_driver_s *priv, + FAR struct ieee802154_orphan_ind_s *conf); +static void macnet_ind_commstatus(FAR struct macnet_driver_s *priv, + FAR struct ieee802154_commstatus_ind_s *conf); +static void macnet_ind_syncloss(FAR struct macnet_driver_s *priv, + FAR struct ieee802154_syncloss_ind_s *conf); /* Network interface support ************************************************/ /* Common TX logic */ @@ -244,6 +262,58 @@ static int macnet_ioctl(FAR struct net_driver_s *dev, int cmd, * Private Functions ****************************************************************************/ +static void macnet_mlme_notify(FAR struct ieee802154_maccb_s *maccb, + enum ieee802154_macnotify_e notif, + FAR union ieee802154_mlme_notify_u *arg) +{ + FAR struct macdev_callback_s *cb = + (FAR struct macdev_callback_s *)maccb; + FAR struct macnet_driver_s *priv; + + DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); + priv = cb->mc_priv; + + switch (notif) + { + + default: + break; + } +} + +static void macnet_mcps_notify(FAR struct ieee802154_maccb_s *maccb, + enum ieee802154_macnotify_e notif, + FAR union ieee802154_mcps_notify_u *arg) +{ + FAR struct macdev_callback_s *cb = + (FAR struct macdev_callback_s *)maccb; + FAR struct macdev_driver_s *priv; + + DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); + priv = cb->mc_priv; + + switch (notif) + { + case IEEE802154_NOTIFY_CONF_DATA: + { + macnet_conf_data(priv, &arg->dataconf); + } + break; + case IEEE802154_NOTIFY_CONF_PURGE: + { + macnet_conf_purge(priv, &arg->purgeconf); + } + break; + case IEEE802154_NOTIFY_IND_DATA: + { + macnet_ind_data(priv, &arg->dataind); + } + break; + default: + break; + } +} + /**************************************************************************** * Name: macnet_conf_data * @@ -252,14 +322,10 @@ static int macnet_ioctl(FAR struct net_driver_s *dev, int cmd, * ****************************************************************************/ -static void macnet_conf_data(MACHANDLE mac, +static void macnet_conf_data(FAR struct macnet_driver_s *priv, FAR struct ieee802154_data_conf_s *conf) { - FAR struct macnet_callback_s *cb = (FAR struct macnet_callback_s *)mac; - FAR struct macnet_driver_s *priv; - DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); - priv = cb->mc_priv; } /**************************************************************************** @@ -270,13 +336,10 @@ static void macnet_conf_data(MACHANDLE mac, * ****************************************************************************/ -static void macnet_conf_purge(MACHANDLE mac, uint8_t handle, int status) +static void macnet_conf_purge(FAR struct macnet_driver_s *priv, + FAR struct ieee802154_purge_conf_s *conf) { - FAR struct macnet_callback_s *cb = (FAR struct macnet_callback_s *)mac; - FAR struct macnet_driver_s *priv; - DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); - priv = cb->mc_priv; } /**************************************************************************** @@ -287,13 +350,10 @@ static void macnet_conf_purge(MACHANDLE mac, uint8_t handle, int status) * ****************************************************************************/ -static void macnet_conf_associate(MACHANDLE mac, uint16_t saddr, int status) +static void macnet_conf_associate(FAR struct macnet_driver_s *priv, + FAR struct ieee802154_assoc_conf_s *conf) { - FAR struct macnet_callback_s *cb = (FAR struct macnet_callback_s *)mac; - FAR struct macnet_driver_s *priv; - DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); - priv = cb->mc_priv; } /**************************************************************************** @@ -304,66 +364,52 @@ static void macnet_conf_associate(MACHANDLE mac, uint16_t saddr, int status) * ****************************************************************************/ -static void macnet_conf_disassociate(MACHANDLE mac, int status) +static void macnet_conf_disassociate(FAR struct macnet_driver_s *priv, + FAR struct ieee802154_disassoc_conf_s *conf) { - FAR struct macnet_callback_s *cb = (FAR struct macnet_callback_s *)mac; - FAR struct macnet_driver_s *priv; - DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); - priv = cb->mc_priv; } /**************************************************************************** * Name: macnet_conf_get * * Description: - * PIvoata returned + * PIB data returned * ****************************************************************************/ -static void macnet_conf_get(MACHANDLE mac, int status, int attribute, - FAR uint8_t *value, int valuelen) +static void macnet_conf_get(FAR struct macnet_driver_s *priv, + FAR struct ieee802154_get_conf_s *conf) { - FAR struct macnet_callback_s *cb = (FAR struct macnet_callback_s *)mac; - FAR struct macnet_driver_s *priv; - DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); - priv = cb->mc_priv; } /**************************************************************************** * Name: macnet_conf_gts * * Description: - * GTvoanagement completed + * GTS management completed * ****************************************************************************/ -static void macnet_conf_gts(MACHANDLE mac, FAR uint8_t *characteristics, - int status) +static void macnet_conf_gts(FAR struct macnet_driver_s *priv, + FAR struct ieee802154_gts_conf_s *conf) { - FAR struct macnet_callback_s *cb = (FAR struct macnet_callback_s *)mac; - FAR struct macnet_driver_s *priv; - DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); - priv = cb->mc_priv; } /**************************************************************************** * Name: macnet_conf_reset * * Description: - * MAveset completed + * MAC reset completed * ****************************************************************************/ -static void macnet_conf_reset(MACHANDLE mac, int status) +static void macnet_conf_reset(FAR struct macnet_driver_s *priv, + FAR struct ieee802154_reset_conf_s *conf) { - FAR struct macnet_callback_s *cb = (FAR struct macnet_callback_s *)mac; - FAR struct macnet_driver_s *priv; - DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); - priv = cb->mc_priv; } /**************************************************************************** @@ -373,13 +419,10 @@ static void macnet_conf_reset(MACHANDLE mac, int status) * ****************************************************************************/ -static void macnet_conf_rxenable(MACHANDLE mac, int status) +static void macnet_conf_rxenable(FAR struct macnet_driver_s *priv, + FAR struct ieee802154_rxenable_conf_s *conf) { - FAR struct macnet_callback_s *cb = (FAR struct macnet_callback_s *)mac; - FAR struct macnet_driver_s *priv; - DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); - priv = cb->mc_priv; } /**************************************************************************** @@ -389,15 +432,10 @@ static void macnet_conf_rxenable(MACHANDLE mac, int status) * ****************************************************************************/ -static void macnet_conf_scan(MACHANDLE mac, int status, uint8_t type, - uint32_t unscanned, int rsltsize, - FAR uint8_t *edlist, FAR uint8_t *pandescs) +static void macnet_conf_scan(FAR struct macnet_driver_s *priv, + FAR struct ieee802154_scan_conf_s *conf) { - FAR struct macnet_callback_s *cb = (FAR struct macnet_callback_s *)mac; - FAR struct macnet_driver_s *priv; - DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); - priv = cb->mc_priv; } /**************************************************************************** @@ -407,13 +445,10 @@ static void macnet_conf_scan(MACHANDLE mac, int status, uint8_t type, * ****************************************************************************/ -static void macnet_conf_set(MACHANDLE mac, int status, int attribute) +static void macnet_conf_set(FAR struct macnet_driver_s *priv, + FAR struct ieee802154_set_conf_s *conf) { - FAR struct macnet_callback_s *cb = (FAR struct macnet_callback_s *)mac; - FAR struct macnet_driver_s *priv; - DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); - priv = cb->mc_priv; } /**************************************************************************** @@ -423,13 +458,10 @@ static void macnet_conf_set(MACHANDLE mac, int status, int attribute) * ****************************************************************************/ -static void macnet_conf_start(MACHANDLE mac, int status) +static void macnet_conf_start(FAR struct macnet_driver_s *priv, + FAR struct ieee802154_start_conf_s *conf) { - FAR struct macnet_callback_s *cb = (FAR struct macnet_callback_s *)mac; - FAR struct macnet_driver_s *priv; - DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); - priv = cb->mc_priv; } /**************************************************************************** @@ -439,13 +471,10 @@ static void macnet_conf_start(MACHANDLE mac, int status) * ****************************************************************************/ -static void macnet_conf_poll(MACHANDLE mac, int status) +static void macnet_conf_poll(FAR struct macnet_driver_s *priv, + FAR struct ieee802154_poll_conf_s *conf) { - FAR struct macnet_callback_s *cb = (FAR struct macnet_callback_s *)mac; - FAR struct macnet_driver_s *priv; - DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); - priv = cb->mc_priv; } /**************************************************************************** @@ -456,13 +485,10 @@ static void macnet_conf_poll(MACHANDLE mac, int status) * ****************************************************************************/ -static void macnet_ind_data(MACHANDLE mac, FAR uint8_t *buf, int len) +static void macnet_ind_data(FAR struct macnet_driver_s *priv, + FAR struct ieee802154_data_ind_s *ind) { - FAR struct macnet_callback_s *cb = (FAR struct macnet_callback_s *)mac; - FAR struct macnet_driver_s *priv; - DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); - priv = cb->mc_priv; } /**************************************************************************** @@ -473,14 +499,10 @@ static void macnet_ind_data(MACHANDLE mac, FAR uint8_t *buf, int len) * ****************************************************************************/ -static void macnet_ind_associate(MACHANDLE mac, uint16_t clipanid, - FAR uint8_t *clieaddr) +static void macnet_ind_associate(FAR struct macnet_driver_s *priv, + FAR struct ieee802154_assoc_ind_s *ind) { - FAR struct macnet_callback_s *cb = (FAR struct macnet_callback_s *)mac; - FAR struct macnet_driver_s *priv; - DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); - priv = cb->mc_priv; } /**************************************************************************** @@ -491,14 +513,10 @@ static void macnet_ind_associate(MACHANDLE mac, uint16_t clipanid, * ****************************************************************************/ -static void macnet_ind_disassociate(MACHANDLE mac, FAR uint8_t *eadr, - uint8_t reason) +static void macnet_ind_disassociate(FAR struct macnet_driver_s *priv, + FAR struct ieee802154_disassoc_ind_s *ind) { - FAR struct macnet_callback_s *cb = (FAR struct macnet_callback_s *)mac; - FAR struct macnet_driver_s *priv; - DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); - priv = cb->mc_priv; } /**************************************************************************** @@ -509,15 +527,10 @@ static void macnet_ind_disassociate(MACHANDLE mac, FAR uint8_t *eadr, * ****************************************************************************/ -static void macnet_ind_beaconnotify(MACHANDLE mac, FAR uint8_t *bsn, - FAR struct ieee802154_pan_desc_s *pandesc, - FAR uint8_t *sdu, int sdulen) +static void macnet_ind_beaconnotify(FAR struct macnet_driver_s *priv, + FAR struct ieee802154_beaconnotify_ind_s *ind) { - FAR struct macnet_callback_s *cb = (FAR struct macnet_callback_s *)mac; - FAR struct macnet_driver_s *priv; - DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); - priv = cb->mc_priv; } /**************************************************************************** @@ -528,14 +541,10 @@ static void macnet_ind_beaconnotify(MACHANDLE mac, FAR uint8_t *bsn, * ****************************************************************************/ -static void macnet_ind_gts(MACHANDLE mac, FAR uint8_t *devaddr, - FAR uint8_t *characteristics) +static void macnet_ind_gts(FAR struct macnet_driver_s *priv, + FAR struct ieee802154_gts_ind_s *ind) { - FAR struct macnet_callback_s *cb = (FAR struct macnet_callback_s *)mac; - FAR struct macnet_driver_s *priv; - DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); - priv = cb->mc_priv; } /**************************************************************************** @@ -546,13 +555,10 @@ static void macnet_ind_gts(MACHANDLE mac, FAR uint8_t *devaddr, * ****************************************************************************/ -static void macnet_ind_orphan(MACHANDLE mac, FAR uint8_t *orphanaddr) +static void macnet_ind_orphan(FAR struct macnet_driver_s *priv, + FAR struct ieee802154_orphan_ind_s *ind) { - FAR struct macnet_callback_s *cb = (FAR struct macnet_callback_s *)mac; - FAR struct macnet_driver_s *priv; - DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); - priv = cb->mc_priv; } /**************************************************************************** @@ -562,15 +568,10 @@ static void macnet_ind_orphan(MACHANDLE mac, FAR uint8_t *orphanaddr) * ****************************************************************************/ -static void macnet_ind_commstatus(MACHANDLE mac, uint16_t panid, - FAR uint8_t *src, FAR uint8_t *dst, - int status) +static void macnet_ind_commstatus(FAR struct macnet_driver_s *priv, + FAR struct ieee802154_commstatus_ind_s *ind) { - FAR struct macnet_callback_s *cb = (FAR struct macnet_callback_s *)mac; - FAR struct macnet_driver_s *priv; - DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); - priv = cb->mc_priv; } /**************************************************************************** @@ -580,13 +581,10 @@ static void macnet_ind_commstatus(MACHANDLE mac, uint16_t panid, * ****************************************************************************/ -static void macnet_ind_syncloss(MACHANDLE mac, int reason) +static void macnet_ind_syncloss(FAR struct macnet_driver_s *priv, + FAR struct ieee802154_syncloss_ind_s *ind) { - FAR struct macnet_callback_s *cb = (FAR struct macnet_callback_s *)mac; - FAR struct macnet_driver_s *priv; - DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); - priv = cb->mc_priv; } /**************************************************************************** @@ -1503,10 +1501,11 @@ int mac802154netdev_register(MACHANDLE mac) { FAR struct macnet_driver_s *priv; FAR struct net_driver_s *dev; + FAR struct ieee802154_maccb_s *maccb; FAR uint8_t *pktbuf; int ret; - DEBUGASSERT(radio != NULL); + DEBUGASSERT(mac != NULL); /* Get the interface structure associated with this interface number. */ @@ -1533,7 +1532,7 @@ int mac802154netdev_register(MACHANDLE mac) /* Initialize the driver structure */ - dev = &ieee->md_dev.i_dev; + dev = &priv->md_dev.i_dev; dev->d_buf = pktbuf; /* Single packet buffer */ dev->d_ifup = macnet_ifup; /* I/F up (new IP address) callback */ dev->d_ifdown = macnet_ifdown; /* I/F down callback */ @@ -1557,34 +1556,16 @@ int mac802154netdev_register(MACHANDLE mac) /* Initialize the MAC callbacks */ - priv->md_cb.mc_priv = priv; + priv->md_cb.mc_priv = priv; - maccb = &priv->md_cb.mc_cb; - maccb->conf_data = macnet_conf_data; - maccb->conf_purge = macnet_conf_purge; - maccb->conf_associate = macnet_conf_associate; - maccb->conf_disassociate = macnet_conf_disassociate; - maccb->conf_get = macnet_conf_get; - maccb->conf_gts = macnet_conf_gts; - maccb->conf_reset = macnet_conf_reset; - maccb->conf_rxenable = macnet_conf_rxenable; - maccb->conf_scan = macnet_conf_scan; - maccb->conf_set = macnet_conf_set; - maccb->conf_start = macnet_conf_start; - maccb->conf_poll = macnet_conf_poll; - maccb->ind_data = macnet_ind_data; - maccb->ind_associate = macnet_ind_associate; - maccb->ind_disassociate = macnet_ind_disassociate; - maccb->ind_beaconnotify = macnet_ind_beaconnotify; - maccb->ind_gts = macnet_ind_gts; - maccb->ind_orphan = macnet_ind_orphan; - maccb->ind_commstatus = macnet_ind_commstatus; - maccb->ind_syncloss = macnet_ind_syncloss; + maccb = &priv->md_cb.mc_cb; + maccb->mlme_notify = macdev_mlme_notify; + maccb->mcps_notify = macdev_mcps_notify; /* Bind the callback structure */ - ret = mac->ops->bind(mac, *priv->md_cb.mc_cb); - if (ret < 0) + ret = mac802154_bind(mac, maccb); + if (ret < 0 { nerr("ERROR: Failed to bind the MAC callbacks: %d\n", ret); @@ -1596,7 +1577,7 @@ int mac802154netdev_register(MACHANDLE mac) /* Free memory and return the error */ kmm_free(pktbuf); kmm_free(priv); - return ret + return ret; } /* Put the interface in the down state. */ diff --git a/wireless/ieee802154/radio802154_device.c b/wireless/ieee802154/radio802154_device.c index 15f4d1d84e3..247570de8ab 100644 --- a/wireless/ieee802154/radio802154_device.c +++ b/wireless/ieee802154/radio802154_device.c @@ -346,6 +346,8 @@ static ssize_t radio802154dev_write(FAR struct file *filep, * Beacons and GTS transmission will be handled via IOCTLs */ +#warning Fix this when transmit interface is complete + /* ret = dev->child->ops->transmit(dev->child, packet); if (ret != packet->len) { @@ -357,6 +359,7 @@ static ssize_t radio802154dev_write(FAR struct file *filep, { wlerr("Radio Device timedout on Tx\n"); } + */ done: From dbafc0fc492b9a2df7611a8eeb2e62534cc1ebd5 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 19 Apr 2017 09:53:32 -0600 Subject: [PATCH 088/183] ieee802154: Purely cosmetic changes from review of last PR. --- .../wireless/ieee802154/ieee802154_mac.h | 28 +++++++++++-------- wireless/ieee802154/mac802154_netdev.c | 17 +++++++++++ wireless/ieee802154/radio802154_device.c | 6 ++-- 3 files changed, 37 insertions(+), 14 deletions(-) diff --git a/include/nuttx/wireless/ieee802154/ieee802154_mac.h b/include/nuttx/wireless/ieee802154/ieee802154_mac.h index 4bdbdde8764..dfc5aa76968 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_mac.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_mac.h @@ -394,15 +394,15 @@ enum ieee802154_ranging_e struct ieee802154_capability_info_s { - uint8_t reserved_0 : 1; /* Reserved */ - uint8_t device_type : 1; /* 0=RFD, 1=FFD */ - uint8_t power_source : 1; /* 1=AC, 0=Other */ - uint8_t rx_on_idle : 1; /* 0=Receiver off when idle - * 1=Receiver on when idle */ - uint8_t reserved_45 : 2; /* Reserved */ - uint8_t security : 1; /* 0=disabled, 1=enabled */ - uint8_t allocate_addr : 1; /* 1=Coordinator allocates short address - * 0=otherwise */ + uint8_t reserved_0 : 1; /* Reserved */ + uint8_t device_type : 1; /* 0=RFD, 1=FFD */ + uint8_t power_source : 1; /* 1=AC, 0=Other */ + uint8_t rx_on_idle : 1; /* 0=Receiver off when idle + * 1=Receiver on when idle */ + uint8_t reserved_45 : 2; /* Reserved */ + uint8_t security : 1; /* 0=disabled, 1=enabled */ + uint8_t allocate_addr : 1; /* 1=Coordinator allocates short address + * 0=otherwise */ }; struct ieee802154_superframe_spec_s @@ -902,6 +902,7 @@ struct ieee802154_commstatus_ind_s struct ieee802154_addr_s src_addr; struct ieee802154_addr_s dest_addr; enum ieee802154_status_e status; + #ifdef CONFIG_IEEE802154_SECURITY /* Security information if enabled */ @@ -986,6 +987,7 @@ struct ieee802154_gts_ind_s { uint16_t dev_addr; struct ieee802154_gts_info_s gts_info; + #ifdef CONFIG_IEEE802154_SECURITY /* Security information if enabled */ @@ -1005,6 +1007,7 @@ struct ieee802154_gts_ind_s struct ieee802154_orphan_ind_s { uint8_t orphan_addr[8]; + #ifdef CONFIG_IEEE802154_SECURITY /* Security information if enabled */ @@ -1024,6 +1027,7 @@ struct ieee802154_orphan_ind_s struct ieee802154_orphan_resp_s { uint8_t orphan_addr[8]; + #ifdef CONFIG_IEEE802154_SECURITY /* Security information if enabled */ @@ -1070,7 +1074,8 @@ struct ieee802154_reset_conf_s struct ieee802154_rxenable_req_s { /* Number of symbols measured from the start of the superframe before the - * receiver is to be enabled or disabled. */ + * receiver is to be enabled or disabled. + */ uint32_t rxon_time; @@ -1394,7 +1399,8 @@ enum ieee802154_macnotify_e /* Callback operations to notify the next highest layer of various asynchronous * events, usually triggered by some previous request or response invoked by the - * upper layer */ + * upper layer. + */ struct ieee802154_maccb_s { diff --git a/wireless/ieee802154/mac802154_netdev.c b/wireless/ieee802154/mac802154_netdev.c index 7965578f385..adc433aa652 100644 --- a/wireless/ieee802154/mac802154_netdev.c +++ b/wireless/ieee802154/mac802154_netdev.c @@ -262,6 +262,13 @@ static int macnet_ioctl(FAR struct net_driver_s *dev, int cmd, * Private Functions ****************************************************************************/ +/**************************************************************************** + * Name: macnet_mlme_notify + * + * Description: + * + ****************************************************************************/ + static void macnet_mlme_notify(FAR struct ieee802154_maccb_s *maccb, enum ieee802154_macnotify_e notif, FAR union ieee802154_mlme_notify_u *arg) @@ -281,6 +288,13 @@ static void macnet_mlme_notify(FAR struct ieee802154_maccb_s *maccb, } } +/**************************************************************************** + * Name: macnet_mcps_notify + * + * Description: + * + ****************************************************************************/ + static void macnet_mcps_notify(FAR struct ieee802154_maccb_s *maccb, enum ieee802154_macnotify_e notif, FAR union ieee802154_mcps_notify_u *arg) @@ -299,16 +313,19 @@ static void macnet_mcps_notify(FAR struct ieee802154_maccb_s *maccb, macnet_conf_data(priv, &arg->dataconf); } break; + case IEEE802154_NOTIFY_CONF_PURGE: { macnet_conf_purge(priv, &arg->purgeconf); } break; + case IEEE802154_NOTIFY_IND_DATA: { macnet_ind_data(priv, &arg->dataind); } break; + default: break; } diff --git a/wireless/ieee802154/radio802154_device.c b/wireless/ieee802154/radio802154_device.c index 247570de8ab..a1fe8dc515e 100644 --- a/wireless/ieee802154/radio802154_device.c +++ b/wireless/ieee802154/radio802154_device.c @@ -298,7 +298,7 @@ done: ****************************************************************************/ static ssize_t radio802154dev_write(FAR struct file *filep, - FAR const char *buffer, size_t len) + FAR const char *buffer, size_t len) { FAR struct inode *inode; FAR struct radio802154_devwrapper_s *dev; @@ -347,7 +347,7 @@ static ssize_t radio802154dev_write(FAR struct file *filep, */ #warning Fix this when transmit interface is complete - /* +#if 0 ret = dev->child->ops->transmit(dev->child, packet); if (ret != packet->len) { @@ -359,7 +359,7 @@ static ssize_t radio802154dev_write(FAR struct file *filep, { wlerr("Radio Device timedout on Tx\n"); } - */ +#endif done: From 395054113680660c7d074c3fb95ed05ea79f93d9 Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Wed, 19 Apr 2017 12:56:43 -0400 Subject: [PATCH 089/183] wireless/ieee802154: Renames mac802154_devwrapper_s to mac802154_chardevice_s --- wireless/ieee802154/mac802154_device.c | 36 ++++++++++++-------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/wireless/ieee802154/mac802154_device.c b/wireless/ieee802154/mac802154_device.c index 52a3e5b4e35..3b7dc493092 100644 --- a/wireless/ieee802154/mac802154_device.c +++ b/wireless/ieee802154/mac802154_device.c @@ -101,10 +101,10 @@ struct mac802154dev_callback_s /* This holds the information visible to the MAC layer */ struct ieee802154_maccb_s mc_cb; /* Interface understood by the MAC layer */ - FAR struct mac802154_devwrapper_s *mc_priv; /* Our priv data */ + FAR struct mac802154_chardevice_s *mc_priv; /* Our priv data */ }; -struct mac802154_devwrapper_s +struct mac802154_chardevice_s { MACHANDLE md_mac; /* Saved binding to the mac layer */ struct mac802154dev_callback_s md_cb; /* Callback information */ @@ -150,7 +150,7 @@ static int mac802154dev_ioctl(FAR struct file *filep, int cmd, /* MAC callback helpers */ -static void mac802154dev_conf_data(FAR struct mac802154_devwrapper_s *dev, +static void mac802154dev_conf_data(FAR struct mac802154_chardevice_s *dev, FAR struct ieee802154_data_conf_s *conf); /**************************************************************************** @@ -212,7 +212,7 @@ static inline int mac802154dev_takesem(sem_t *sem) static int mac802154dev_open(FAR struct file *filep) { FAR struct inode *inode; - FAR struct mac802154_devwrapper_s *dev; + FAR struct mac802154_chardevice_s *dev; FAR struct mac802154dev_open_s *opriv; int ret; @@ -269,7 +269,7 @@ errout_with_sem: static int mac802154dev_close(FAR struct file *filep) { FAR struct inode *inode; - FAR struct mac802154_devwrapper_s *dev; + FAR struct mac802154_chardevice_s *dev; FAR struct mac802154dev_open_s *opriv; FAR struct mac802154dev_open_s *curr; FAR struct mac802154dev_open_s *prev; @@ -281,7 +281,7 @@ static int mac802154dev_close(FAR struct file *filep) opriv = filep->f_priv; inode = filep->f_inode; DEBUGASSERT(inode->i_private); - dev = (FAR struct mac802154_devwrapper_s *)inode->i_private; + dev = (FAR struct mac802154_chardevice_s *)inode->i_private; /* Handle an improbable race conditions with the following atomic test * and set. @@ -361,13 +361,13 @@ static ssize_t mac802154dev_read(FAR struct file *filep, FAR char *buffer, size_t len) { FAR struct inode *inode; - FAR struct mac802154_devwrapper_s *dev; + FAR struct mac802154_chardevice_s *dev; int ret; DEBUGASSERT(filep && filep->f_inode); inode = filep->f_inode; DEBUGASSERT(inode->i_private); - dev = (FAR struct mac802154_devwrapper_s *)inode->i_private; + dev = (FAR struct mac802154_chardevice_s *)inode->i_private; /* Check to make sure that the buffer is big enough to hold at least one * packet. @@ -408,7 +408,7 @@ static ssize_t mac802154dev_write(FAR struct file *filep, FAR const char *buffer, size_t len) { FAR struct inode *inode; - FAR struct mac802154_devwrapper_s *dev; + FAR struct mac802154_chardevice_s *dev; FAR struct ieee802154_data_req_s *req; struct mac802154dev_dwait_s dwait; int ret; @@ -416,7 +416,7 @@ static ssize_t mac802154dev_write(FAR struct file *filep, DEBUGASSERT(filep && filep->f_inode); inode = filep->f_inode; DEBUGASSERT(inode->i_private); - dev = (FAR struct mac802154_devwrapper_s *)inode->i_private; + dev = (FAR struct mac802154_chardevice_s *)inode->i_private; /* Check to make sure that the buffer is big enough to hold at least one * packet. */ @@ -460,7 +460,6 @@ static ssize_t mac802154dev_write(FAR struct file *filep, dev->md_dwait = &dwait; mac802154dev_givesem(&dev->md_exclsem); - } /* Pass the request to the MAC layer */ @@ -473,7 +472,6 @@ static ssize_t mac802154dev_write(FAR struct file *filep, return ret; } - if (!(filep->f_oflags & O_NONBLOCK)) { /* Wait for the DATA.confirm callback to be called for our handle */ @@ -509,14 +507,14 @@ static int mac802154dev_ioctl(FAR struct file *filep, int cmd, unsigned long arg) { FAR struct inode *inode; - FAR struct mac802154_devwrapper_s *dev; + FAR struct mac802154_chardevice_s *dev; int ret; DEBUGASSERT(filep != NULL && filep->f_priv != NULL && filep->f_inode != NULL); inode = filep->f_inode; DEBUGASSERT(inode->i_private); - dev = (FAR struct mac802154_devwrapper_s *)inode->i_private; + dev = (FAR struct mac802154_chardevice_s *)inode->i_private; /* Get exclusive access to the driver structure */ @@ -599,7 +597,7 @@ static void mac802154dev_mlme_notify(FAR struct ieee802154_maccb_s *maccb, { FAR struct mac802154dev_callback_s *cb = (FAR struct mac802154dev_callback_s *)maccb; - FAR struct mac802154_devwrapper_s *dev; + FAR struct mac802154_chardevice_s *dev; DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); dev = cb->mc_priv; @@ -618,7 +616,7 @@ static void mac802154dev_mcps_notify(FAR struct ieee802154_maccb_s *maccb, { FAR struct mac802154dev_callback_s *cb = (FAR struct mac802154dev_callback_s *)maccb; - FAR struct mac802154_devwrapper_s *dev; + FAR struct mac802154_chardevice_s *dev; DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); dev = cb->mc_priv; @@ -635,7 +633,7 @@ static void mac802154dev_mcps_notify(FAR struct ieee802154_maccb_s *maccb, } } -static void mac802154dev_conf_data(FAR struct mac802154_devwrapper_s *dev, +static void mac802154dev_conf_data(FAR struct mac802154_chardevice_s *dev, FAR struct ieee802154_data_conf_s *conf) { FAR struct mac802154dev_dwait_s *curr; @@ -722,12 +720,12 @@ static void mac802154dev_conf_data(FAR struct mac802154_devwrapper_s *dev, int mac802154dev_register(MACHANDLE mac, int minor) { - FAR struct mac802154_devwrapper_s *dev; + FAR struct mac802154_chardevice_s *dev; FAR struct ieee802154_maccb_s *maccb; char devname[DEVNAME_FMTLEN]; int ret; - dev = kmm_zalloc(sizeof(struct mac802154_devwrapper_s)); + dev = kmm_zalloc(sizeof(struct mac802154_chardevice_s)); if (!dev) { wlerr("ERROR: Failed to allocate device structure\n"); From 37e7c673733e7f2e3800320e708d07548bccf6e1 Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Wed, 19 Apr 2017 13:26:30 -0400 Subject: [PATCH 090/183] wireless/ieee802154: Changes radio interface to match MAC callback design --- drivers/wireless/ieee802154/mrf24j40.c | 20 +++--- .../wireless/ieee802154/ieee802154_radio.h | 19 ++---- wireless/ieee802154/mac802154.c | 62 ++++++++++++++----- 3 files changed, 57 insertions(+), 44 deletions(-) diff --git a/drivers/wireless/ieee802154/mrf24j40.c b/drivers/wireless/ieee802154/mrf24j40.c index 1b00a67e155..b1c0c67218d 100644 --- a/drivers/wireless/ieee802154/mrf24j40.c +++ b/drivers/wireless/ieee802154/mrf24j40.c @@ -112,10 +112,7 @@ struct mrf24j40_txdesc_s struct mrf24j40_radio_s { struct ieee802154_radio_s radio; /* The public device instance */ - - /* Reference to the bound upper layer via the phyif interface */ - - FAR struct ieee802154_phyif_s *phyif; + FAR struct ieee802154_radiocb_s *radiocb; /* Registered callbacks */ /* Low-level MCU-specific support */ @@ -215,7 +212,7 @@ static int mrf24j40_energydetect(FAR struct mrf24j40_radio_s *radio, /* Driver operations */ static int mrf24j40_bind(FAR struct ieee802154_radio_s *radio, - FAR struct ieee802154_phyif_s *phyif); + FAR struct ieee802154_radiocb_s *radiocb); static int mrf24j40_ioctl(FAR struct ieee802154_radio_s *radio, int cmd, unsigned long arg); static int mrf24j40_rxenable(FAR struct ieee802154_radio_s *radio, @@ -250,12 +247,12 @@ static const struct ieee802154_radioops_s mrf24j40_devops = ****************************************************************************/ static int mrf24j40_bind(FAR struct ieee802154_radio_s *radio, - FAR struct ieee802154_phyif_s *phyif) + FAR struct ieee802154_radiocb_s *radiocb) { FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)radio; DEBUGASSERT(dev != NULL); - dev->phyif = phyif; + dev->radiocb = radiocb; return OK; } @@ -335,9 +332,8 @@ static void mrf24j40_dopoll_csma(FAR void *arg) { /* need to somehow allow for a handle to be passed */ - ret = dev->phyif->ops->poll_csma(dev->phyif, - &dev->csma_desc.pub, - &dev->tx_buf[0]); + ret = dev->radiocb->poll_csma(dev->radiocb, &dev->csma_desc.pub, + &dev->tx_buf[0]); if (ret > 0) { /* Now the txdesc is in use */ @@ -431,8 +427,8 @@ static void mrf24j40_dopoll_gts(FAR void *arg) { if (!dev->gts_desc[gts].busy) { - ret = dev->phyif->ops->poll_gts(dev->phyif, &dev->gts_desc[gts].pub, - &dev->tx_buf[0]); + ret = dev->radiocb->poll_gts(dev->radiocb, &dev->gts_desc[gts].pub, + &dev->tx_buf[0]); if (ret > 0) { /* Now the txdesc is in use */ diff --git a/include/nuttx/wireless/ieee802154/ieee802154_radio.h b/include/nuttx/wireless/ieee802154/ieee802154_radio.h index 638760f356b..e1c0ff3aeac 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_radio.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_radio.h @@ -167,31 +167,20 @@ struct ieee802154_txdesc_s /* TODO: Add slotting information for GTS transactions */ }; -struct ieee802154_phyif_s; /* Forward Reference */ - -struct ieee802154_phyifops_s +struct ieee802154_radiocb_s { - CODE int (*poll_csma) (FAR struct ieee802154_phyif_s *phyif, + CODE int (*poll_csma) (FAR struct ieee802154_radiocb_s *radiocb, FAR struct ieee802154_txdesc_s *tx_desc, FAR uint8_t *buf); - CODE int (*poll_gts) (FAR struct ieee802154_phyif_s *phyif, + CODE int (*poll_gts) (FAR struct ieee802154_radiocb_s *radiocb, FAR struct ieee802154_txdesc_s *tx_desc, FAR uint8_t *buf); }; -struct ieee802154_phyif_s -{ - FAR const struct ieee802154_phyifops_s *ops; - - /* Driver-specific information */ - - FAR void * priv; -}; - struct ieee802154_radio_s; /* Forward reference */ struct ieee802154_radioops_s { CODE int (*bind) (FAR struct ieee802154_radio_s *radio, - FAR struct ieee802154_phyif_s *phyif); + FAR struct ieee802154_radiocb_s *radiocb); CODE int (*ioctl)(FAR struct ieee802154_radio_s *radio, int cmd, unsigned long arg); CODE int (*rxenable)(FAR struct ieee802154_radio_s *radio, bool state, diff --git a/wireless/ieee802154/mac802154.c b/wireless/ieee802154/mac802154.c index a23128820d3..beec54f711b 100644 --- a/wireless/ieee802154/mac802154.c +++ b/wireless/ieee802154/mac802154.c @@ -86,6 +86,12 @@ struct mac802154_unsec_mhr_s } u; }; +struct mac802154_radiocb_s +{ + struct ieee802154_radiocb_s cb; + FAR struct ieee802154_privmac_s *priv; +}; + /* The privmac structure holds the internal state of the MAC and is the * underlying represention of the opaque MACHANDLE. It contains storage for * the IEEE802.15.4 MIB attributes. @@ -95,7 +101,7 @@ struct ieee802154_privmac_s { FAR struct ieee802154_radio_s *radio; /* Contained IEEE802.15.4 radio dev */ FAR const struct ieee802154_maccb_s *cb; /* Contained MAC callbacks */ - FAR struct ieee802154_phyif_s phyif; /* Interface to bind to radio */ + FAR struct mac802154_radiocb_s radiocb; /* Interface to bind to radio */ sem_t exclsem; /* Support exclusive access */ @@ -244,11 +250,11 @@ static int mac802154_applymib(FAR struct ieee802154_privmac_s *priv); /* IEEE 802.15.4 PHY Interface OPs */ -static int mac802154_poll_csma(FAR struct ieee802154_phyif_s *phyif, +static int mac802154_poll_csma(FAR struct ieee802154_radiocb_s *radiocb, FAR struct ieee802154_txdesc_s *tx_desc, FAR uint8_t *buf); -static int mac802154_poll_gts(FAR struct ieee802154_phyif_s *phyif, +static int mac802154_poll_gts(FAR struct ieee802154_radiocb_s *radiocb, FAR struct ieee802154_txdesc_s *tx_desc, FAR uint8_t *buf); @@ -256,11 +262,6 @@ static int mac802154_poll_gts(FAR struct ieee802154_phyif_s *phyif, * Private Data ****************************************************************************/ -static const struct ieee802154_phyifops_s mac802154_phyifops = -{ - mac802154_poll_csma, - mac802154_poll_gts -}; /**************************************************************************** * Private Functions @@ -351,6 +352,7 @@ static int mac802154_applymib(FAR struct ieee802154_privmac_s *priv) MACHANDLE mac802154_create(FAR struct ieee802154_radio_s *radiodev) { FAR struct ieee802154_privmac_s *mac; + FAR struct ieee802154_radiocb_s *radiocb; /* Allocate object */ @@ -369,12 +371,17 @@ MACHANDLE mac802154_create(FAR struct ieee802154_radio_s *radiodev) mac802154_defaultmib(mac); mac802154_applymib(mac); - mac->phyif.ops = &mac802154_phyifops; - mac->phyif.priv = mac; + /* Initialize the Radio callbacks */ - /* Bind our PHY interface to the radio */ + mac->radiocb.priv = mac; - radiodev->ops->bind(radiodev, &mac->phyif); + radiocb = &mac->radiocb.cb; + radiocb->poll_cmsa = mac802154_poll_csma; + radiocb->poll_gts = mac802154_poll_gts; + + /* Bind our callback structure */ + + radiodev->ops->bind(radiodev, &mac->radiocb.cb); return (MACHANDLE)mac; } @@ -701,16 +708,18 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) /* Called from interrupt level or worker thread with interrupts disabled */ -static int mac802154_poll_csma(FAR struct ieee802154_phyif_s *phyif, +static int mac802154_poll_csma(FAR struct ieee802154_radiocb_s *radiocb, FAR struct ieee802154_txdesc_s *tx_desc, FAR uint8_t *buf) { - FAR struct ieee802154_privmac_s *priv = - (FAR struct ieee802154_privmac_s *)&phyif->priv; + FAR struct mac802154_radiocb_s *cb = + (FAR struct mac802154_radiocb_s *)radiocb; + FAR struct ieee802154_privmac_s *priv; FAR struct mac802154_trans_s *trans; int ret = 0; - DEBUGASSERT(priv != 0); + DEBUGASSERT(cb != NULL && cb->priv != NULL); + priv = cb->priv; /* Get exclusive access to the driver structure. We don't care about any * signals so if we see one, just go back to trying to get access again. @@ -753,10 +762,29 @@ static int mac802154_poll_csma(FAR struct ieee802154_phyif_s *phyif, return ret; } -static int mac802154_poll_gts(FAR struct ieee802154_phyif_s *phyif, +static int mac802154_poll_gts(FAR struct ieee802154_radiocb_s *radiocb, FAR struct ieee802154_txdesc_s *tx_desc, FAR uint8_t *buf) { + FAR struct mac802154_radiocb_s *cb = + (FAR struct mac802154_radiocb_s *)radiocb; + FAR struct ieee802154_privmac_s *priv; + FAR struct mac802154_trans_s *trans; + int ret = 0; + + DEBUGASSERT(cb != NULL && cb->priv != NULL); + priv = cb->priv; + + /* Get exclusive access to the driver structure. We don't care about any + * signals so if we see one, just go back to trying to get access again. + */ + + while (mac802154_takesem(&priv->exclsem) != 0); + +#warning Missing logic. + + mac802154_givesem(&priv->exclsem); + return 0; } From 3b5f350656aa658978eb0fcd8b6f73ed68d40ed1 Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Wed, 19 Apr 2017 14:47:35 -0400 Subject: [PATCH 091/183] wireless/ieee802154: Removes uneccessary structs surrounding bit-fields in mac802154.c --- wireless/ieee802154/mac802154.c | 72 +++++++++++++++++---------------- 1 file changed, 38 insertions(+), 34 deletions(-) diff --git a/wireless/ieee802154/mac802154.c b/wireless/ieee802154/mac802154.c index beec54f711b..ad702dc5358 100644 --- a/wireless/ieee802154/mac802154.c +++ b/wireless/ieee802154/mac802154.c @@ -185,27 +185,27 @@ struct ieee802154_privmac_s uint32_t tx_total_dur; - struct - { - uint32_t is_assoc : 1; /* Are we associated to the PAN */ - uint32_t assoc_permit : 1; /* Are we allowing assoc. as a coord. */ - uint32_t auto_req : 1; /* Automatically send data req. if addr - * addr is in the beacon frame */ + /* Start of 32-bit bitfield */ - uint32_t batt_life_ext : 1; /* Is BLE enabled */ - uint32_t gts_permit : 1; /* Is PAN Coord. accepting GTS reqs. */ - uint32_t promiscuous_mode : 1; /* Is promiscuous mode on? */ - uint32_t ranging_supported : 1; /* Does MAC sublayer support ranging */ - uint32_t rx_when_idle : 1; /* Recvr. on during idle periods */ - uint32_t sec_enabled : 1; /* Does MAC sublayer have security en. */ + uint32_t is_assoc : 1; /* Are we associated to the PAN */ + uint32_t assoc_permit : 1; /* Are we allowing assoc. as a coord. */ + uint32_t auto_req : 1; /* Automatically send data req. if addr + * addr is in the beacon frame */ - uint32_t max_csma_backoffs : 3; /* Max num backoffs for CSMA algorithm - * before declaring ch access failure */ + uint32_t batt_life_ext : 1; /* Is BLE enabled */ + uint32_t gts_permit : 1; /* Is PAN Coord. accepting GTS reqs. */ + uint32_t promiscuous_mode : 1; /* Is promiscuous mode on? */ + uint32_t ranging_supported : 1; /* Does MAC sublayer support ranging */ + uint32_t rx_when_idle : 1; /* Recvr. on during idle periods */ + uint32_t sec_enabled : 1; /* Does MAC sublayer have security en. */ - uint32_t beacon_order : 4; /* Freq. that beacon is transmitted */ + uint32_t max_csma_backoffs : 3; /* Max num backoffs for CSMA algorithm + * before declaring ch access failure */ - uint32_t superframe_order : 4; /* Length of active portion of outgoing - * superframe, including the beacon */ + uint32_t beacon_order : 4; /* Freq. that beacon is transmitted */ + + uint32_t superframe_order : 4; /* Length of active portion of outgoing + * superframe, including the beacon */ /* The offset, measured is symbols, between the symbol boundary at which the * MLME captures the timestamp of each transmitted and received frame, and @@ -213,25 +213,29 @@ struct ieee802154_privmac_s * the frames [1] pg. 129. */ - uint32_t sync_symb_offset : 12; - }; + uint32_t sync_symb_offset : 12; - struct - { - uint32_t beacon_tx_time : 24; /* Time of last beacon transmit */ - uint32_t min_be : 4; /* Min value of backoff exponent (BE) */ - uint32_t max_be : 4; /* Max value of backoff exponent (BE) */ - }; + /* End of 32-bit bitfield */ - struct - { - uint32_t tx_ctrl_active_dur : 17; /* Duration for which tx is permitted to - * be active */ - uint32_t tx_ctrl_pause_dur : 1; /* Duration after tx before another tx is - * permitted. 0=2000, 1= 10000 */ - uint32_t timestamp_support : 1; /* Does MAC layer supports timestamping */ - uint32_t is_coord : 1; /* Is this device acting as coordinator */ - }; + /* Start of 32-bit bitfield */ + + uint32_t beacon_tx_time : 24; /* Time of last beacon transmit */ + uint32_t min_be : 4; /* Min value of backoff exponent (BE) */ + uint32_t max_be : 4; /* Max value of backoff exponent (BE) */ + + /* End of 32-bit bitfield */ + + /* Start of 32-bit bitfield */ + + uint32_t tx_ctrl_active_dur : 17; /* Duration for which tx is permitted to + * be active */ + uint32_t tx_ctrl_pause_dur : 1; /* Duration after tx before another tx is + * permitted. 0=2000, 1= 10000 */ + uint32_t timestamp_support : 1; /* Does MAC layer supports timestamping */ + uint32_t is_coord : 1; /* Is this device acting as coordinator */ + /* 12-bits remaining */ + + /* End of 32-bit bitfield. /* TODO: Add Security-related MAC PIB attributes */ }; From ec5b0a0ef3d8caffb82cd1302fd78788a8ef6c81 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 19 Apr 2017 13:40:52 -0600 Subject: [PATCH 092/183] Minor changes to spacing only from review of last PR --- wireless/ieee802154/mac802154.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/wireless/ieee802154/mac802154.c b/wireless/ieee802154/mac802154.c index ad702dc5358..5ea09c2546d 100644 --- a/wireless/ieee802154/mac802154.c +++ b/wireless/ieee802154/mac802154.c @@ -163,14 +163,14 @@ struct ieee802154_privmac_s /* Contents of beacon payload */ uint8_t beacon_payload[IEEE802154_MAX_BEACON_PAYLOAD_LENGTH]; - uint8_t beacon_payload_len; /* Length of beacon payload */ + uint8_t beacon_payload_len; /* Length of beacon payload */ - uint8_t batt_life_ext_periods; /* # of backoff periods during which rx is - * enabled after the IFS following beacon */ + uint8_t batt_life_ext_periods; /* # of backoff periods during which rx is + * enabled after the IFS following beacon */ - uint8_t bsn; /* Seq. num added to tx beacon frame */ - uint8_t dsn; /* Seq. num added to tx data or MAC frame */ - uint8_t max_retries; /* Max # of retries alloed after tx failure */ + uint8_t bsn; /* Seq. num added to tx beacon frame */ + uint8_t dsn; /* Seq. num added to tx data or MAC frame */ + uint8_t max_retries; /* Max # of retries alloed after tx failure */ /* The maximum time, in multiples of aBaseSuperframeDuration, a device shall * wait for a response command frame to be available following a request @@ -207,11 +207,11 @@ struct ieee802154_privmac_s uint32_t superframe_order : 4; /* Length of active portion of outgoing * superframe, including the beacon */ - /* The offset, measured is symbols, between the symbol boundary at which the - * MLME captures the timestamp of each transmitted and received frame, and - * the onset of the first symbol past the SFD, namely the first symbol of - * the frames [1] pg. 129. - */ + /* The offset, measured is symbols, between the symbol boundary at which the + * MLME captures the timestamp of each transmitted and received frame, and + * the onset of the first symbol past the SFD, namely the first symbol of + * the frames [1] pg. 129. + */ uint32_t sync_symb_offset : 12; @@ -233,7 +233,7 @@ struct ieee802154_privmac_s * permitted. 0=2000, 1= 10000 */ uint32_t timestamp_support : 1; /* Does MAC layer supports timestamping */ uint32_t is_coord : 1; /* Is this device acting as coordinator */ - /* 12-bits remaining */ + /* 12-bits remaining */ /* End of 32-bit bitfield. From 1abe4ae4da7dbd6e8ef34291ff51c8173c5cf704 Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Wed, 19 Apr 2017 16:34:34 -0400 Subject: [PATCH 093/183] wireless/ieee802154: Starts structuring transmission completion handling --- drivers/wireless/ieee802154/mrf24j40.c | 256 ++++++++++++------ drivers/wireless/ieee802154/mrf24j40.h | 13 +- .../wireless/ieee802154/ieee802154_radio.h | 7 + wireless/ieee802154/mac802154.c | 4 +- 4 files changed, 196 insertions(+), 84 deletions(-) diff --git a/drivers/wireless/ieee802154/mrf24j40.c b/drivers/wireless/ieee802154/mrf24j40.c index b1c0c67218d..ffdd0689d47 100644 --- a/drivers/wireless/ieee802154/mrf24j40.c +++ b/drivers/wireless/ieee802154/mrf24j40.c @@ -159,8 +159,12 @@ static int mrf24j40_initialize(FAR struct mrf24j40_radio_s *dev); static int mrf24j40_setrxmode(FAR struct mrf24j40_radio_s *dev, int mode); static int mrf24j40_regdump(FAR struct mrf24j40_radio_s *dev); + static void mrf24j40_irqwork_rx(FAR struct mrf24j40_radio_s *dev); -static void mrf24j40_irqwork_tx(FAR struct mrf24j40_radio_s *dev); +static void mrf24j40_irqwork_txnorm(FAR struct mrf24j40_radio_s *dev); +static void mrf24j40_irqwork_txgts(FAR struct mrf24j40_radio_s *dev, + uint8_t gts_num); + static void mrf24j40_irqworker(FAR void *arg); static int mrf24j40_interrupt(int irq, FAR void *context, FAR void *arg); @@ -171,6 +175,9 @@ static int mrf24j40_csma_setup(FAR struct mrf24j40_radio_s *dev, uint8_t *buf, uint16_t buf_len); static int mrf24j40_gts_setup(FAR struct mrf24j40_radio_s *dev, uint8_t gts, uint8_t *buf, uint16_t buf_len); +static int mrf24j40_setup_fifo(FAR struct mrf24j40_radio_s *dev, + uint8_t *buf, uint16_t buf_len, + uint32_t fifo_addr); /* IOCTL helpers */ @@ -345,8 +352,6 @@ static void mrf24j40_dopoll_csma(FAR void *arg) mrf24j40_csma_setup(dev, &dev->tx_buf[0], dev->csma_desc.pub.psdu_length); } - - /* Setup the transmit on the device */ } sem_post(&dev->exclsem); @@ -1338,22 +1343,103 @@ static int mrf24j40_transmit(FAR struct ieee802154_radio_s *radio, uint8_t *buf, uint16_t buf_len) { FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)radio; - uint32_t addr; uint8_t reg; int ret; - int hlen = 3; /* Include frame control and seq number */ - uint16_t frame_ctrl; mrf24j40_pacontrol(dev, MRF24J40_PA_AUTO); - addr = MRF24J40_TXBUF_BASE; - /* Enable tx int */ reg = mrf24j40_getreg(dev->spi, MRF24J40_INTCON); reg &= ~MRF24J40_INTCON_TXNIE; mrf24j40_setreg(dev->spi, MRF24J40_INTCON, reg); + /* Setup the FIFO */ + + ret = mrf24j40_setup_fifo(dev, buf, buf_len, MRF24J40_TXNORM_FIFO); + + /* If the frame control field contains + * an acknowledgment request, set the TXNACKREQ bit. + * See IEEE 802.15.4/2003 7.2.1.1 page 112 for info. + */ + + reg = MRF24J40_TXNCON_TXNTRIG; + if (buf[0] & IEEE802154_FRAMECTRL_ACKREQ) + { + reg |= MRF24J40_TXNCON_TXNACKREQ; + } + + /* Trigger packet emission */ + + mrf24j40_setreg(dev->spi, MRF24J40_TXNCON, reg); + return ret; +} + +/**************************************************************************** + * Name: mrf24j40_csma_setup + * + * Description: + * Setup a CSMA transaction in the normal TX FIFO + * + ****************************************************************************/ + +static int mrf24j40_csma_setup(FAR struct mrf24j40_radio_s *dev, + uint8_t *buf, uint16_t buf_len) +{ + uint8_t reg; + int ret; + + mrf24j40_pacontrol(dev, MRF24J40_PA_AUTO); + + /* Enable tx int */ + + reg = mrf24j40_getreg(dev->spi, MRF24J40_INTCON); + reg &= ~MRF24J40_INTCON_TXNIE; + mrf24j40_setreg(dev->spi, MRF24J40_INTCON, reg); + + /* Setup the FIFO */ + + ret = mrf24j40_setup_fifo(dev, buf, buf_len, MRF24J40_TXNORM_FIFO); + + /* If the frame control field contains + * an acknowledgment request, set the TXNACKREQ bit. + * See IEEE 802.15.4/2003 7.2.1.1 page 112 for info. + */ + + reg = MRF24J40_TXNCON_TXNTRIG; + if (buf[0] & IEEE802154_FRAMECTRL_ACKREQ) + { + reg |= MRF24J40_TXNCON_TXNACKREQ; + } + + /* Trigger packet emission */ + + mrf24j40_setreg(dev->spi, MRF24J40_TXNCON, reg); + return ret; +} + +/**************************************************************************** + * Name: mrf24j40_gts_setup + * + * Description: + * Setup a GTS transaction in one of the GTS FIFOs + * + ****************************************************************************/ + +static int mrf24j40_gts_setup(FAR struct mrf24j40_radio_s *dev, uint8_t fifo, + uint8_t *buf, uint16_t buf_len) +{ + return -ENOTTY; +} + +static int mrf24j40_setup_fifo(FAR struct mrf24j40_radio_s *dev, + uint8_t *buf, uint16_t buf_len, + uint32_t fifo_addr) +{ + int ret; + int hlen = 3; /* Include frame control and seq number */ + uint16_t frame_ctrl; + /* Analyze frame control to compute header length */ frame_ctrl = buf[0]; @@ -1384,103 +1470,101 @@ static int mrf24j40_transmit(FAR struct ieee802154_radio_s *radio, /* Header len, 0, TODO for security modes */ - mrf24j40_setreg(dev->spi, addr++, hlen); + mrf24j40_setreg(dev->spi, fifo_addr++, hlen); /* Frame length */ - mrf24j40_setreg(dev->spi, addr++, buf_len); + mrf24j40_setreg(dev->spi, fifo_addr++, buf_len); /* Frame data */ for (ret = 0; ret < buf_len; ret++) /* this sets the correct val for ret */ { - mrf24j40_setreg(dev->spi, addr++, buf[ret]); + mrf24j40_setreg(dev->spi, fifo_addr++, buf[ret]); } - - /* If the frame control field contains - * an acknowledgment request, set the TXNACKREQ bit. - * See IEEE 802.15.4/2003 7.2.1.1 page 112 for info. - */ - - reg = MRF24J40_TXNCON_TXNTRIG; - if (frame_ctrl & IEEE802154_FRAMECTRL_ACKREQ) - { - reg |= MRF24J40_TXNCON_TXNACKREQ; - } - - /* Trigger packet emission */ - - mrf24j40_setreg(dev->spi, MRF24J40_TXNCON, reg); + return ret; } /**************************************************************************** - * Name: mrf24j40_csma_setup - * - * Description: - * Setup a CSMA transaction in the normal TX FIFO - * - ****************************************************************************/ - -static int mrf24j40_csma_setup(FAR struct mrf24j40_radio_s *dev, - uint8_t *buf, uint16_t buf_len) -{ - return -ENOTTY; -} - -/**************************************************************************** - * Name: mrf24j40_gts_setup - * - * Description: - * Setup a GTS transaction in one of the GTS FIFOs - * - ****************************************************************************/ - -static int mrf24j40_gts_setup(FAR struct mrf24j40_radio_s *dev, uint8_t fifo, - uint8_t *buf, uint16_t buf_len) -{ - return -ENOTTY; -} - -/**************************************************************************** - * Name: mrf24j40_irqwork_tx + * Name: mrf24j40_irqwork_txnorm * * Description: * Manage completion of packet transmission. * ****************************************************************************/ -static void mrf24j40_irqwork_tx(FAR struct mrf24j40_radio_s *dev) +static void mrf24j40_irqwork_txnorm(FAR struct mrf24j40_radio_s *dev) { uint8_t txstat; - uint8_t reg; - - txstat = mrf24j40_getreg(dev->spi, MRF24J40_TXSTAT); - - reg = mrf24j40_getreg(dev->spi, MRF24J40_TXSTAT); - - /* 1 means it failed, we want 1 to mean it worked. */ - -#if 0 - dev->radio.txok = (reg & MRF24J40_TXSTAT_TXNSTAT) != MRF24J40_TXSTAT_TXNSTAT; - dev->radio.txretries = (reg & MRF24J40_TXSTAT_X_MASK) >> MRF24J40_TXSTAT_X_SHIFT; - dev->radio.txbusy = (reg & MRF24J40_TXSTAT_CCAFAIL) == MRF24J40_TXSTAT_CCAFAIL; -#endif - - //wlinfo("TXSTAT%02X!\n", txstat); -#warning TODO report errors - UNUSED(txstat); /* Disable tx int */ - reg = mrf24j40_getreg(dev->spi, MRF24J40_INTCON); - reg |= MRF24J40_INTCON_TXNIE; - mrf24j40_setreg(dev->spi, MRF24J40_INTCON, reg); + txstat = mrf24j40_getreg(dev->spi, MRF24J40_INTCON); + txstat |= MRF24J40_INTCON_TXNIE; + mrf24j40_setreg(dev->spi, MRF24J40_INTCON, txstat); - /* Wake up the thread that triggered the transmission */ + /* Get the status from the device and copy the status into the tx desc. + * The status for the normal FIFO is represented with bit TXNSTAT where + * 0=success, 1= failure */ - /* sem_post(&dev->radio.txsem); */ + txstat = mrf24j40_getreg(dev->spi, MRF24J40_TXSTAT); + dev->csma_desc.pub.status = txstat & MRF24J40_TXSTAT_TXNSTAT; + /* Inform the next layer of the transmission success/failure */ + + dev->radiocb->txdone_csma(dev->radiocb, dev->csma_desc.pub); + + /* We are now done with the transaction */ + + dev->csma_desc.busy = 0; + + mrf24j40_dopoll_csma(dev); +} + +/**************************************************************************** + * Name: mrf24j40_irqwork_gts + * + * Description: + * Manage completion of packet transmission. + * + ****************************************************************************/ + +static void mrf24j40_irqwork_txgts(FAR struct mrf24j40_radio_s *dev, + uint8_t gts) +{ + uint8_t txstat; + + /* Disable tx int */ + + txstat = mrf24j40_getreg(dev->spi, MRF24J40_INTCON); + txstat |= MRF24J40_INTCON_TXNIE; + mrf24j40_setreg(dev->spi, MRF24J40_INTCON, txstat); + + /* Get the status from the device and copy the status into the tx desc. + * The status for the normal FIFO is represented with bit TXNSTAT where + * 0=success, 1= failure */ + + txstat = mrf24j40_getreg(dev->spi, MRF24J40_TXSTAT); + + if (gts == 0) + { + dev->csma_desc.pub.status = txstat & MRF24J40_TXSTAT_TXG1STAT; + } + else if (gts == 1) + { + dev->csma_desc.pub.status = txstat & MRF24J40_TXSTAT_TXG2STAT; + } + + /* Inform the next layer of the transmission success/failure */ + + dev->radiocb->txdone_gts(dev->radiocb, dev->gts_desc[gts].pub); + + /* We are now done with the transaction */ + + dev->gts_desc[gts].busy = 0; + + mrf24j40_dopoll_gts(dev); } /**************************************************************************** @@ -1618,7 +1702,21 @@ static void mrf24j40_irqworker(FAR void *arg) { /* A packet was transmitted or failed*/ - mrf24j40_irqwork_tx(dev); + mrf24j40_irqwork_txnorm(dev); + } + + if ((intstat & MRF24J40_INTSTAT_TXG1IF)) + { + /* A packet was transmitted or failed*/ + + mrf24j40_irqwork_txgts(dev, 0); + } + + if ((intstat & MRF24J40_INTSTAT_TXG1IF)) + { + /* A packet was transmitted or failed*/ + + mrf24j40_irqwork_txgts(dev, 1); } /* Re-enable GPIO interrupts */ diff --git a/drivers/wireless/ieee802154/mrf24j40.h b/drivers/wireless/ieee802154/mrf24j40.h index 62b2bee888c..96d00691d2b 100644 --- a/drivers/wireless/ieee802154/mrf24j40.h +++ b/drivers/wireless/ieee802154/mrf24j40.h @@ -97,9 +97,14 @@ #define MRF24J40_BBREG6 0x3E #define MRF24J40_CCAEDTH 0x3F -#define MRF24J40_TXBUF_BASE 0x80000000 -#define MRF24J40_LONGREG_BASE 0x80000200 -#define MRF24J40_RXBUF_BASE 0x80000300 +#define MRF24J40_FIFO_BASE 0x80000000 +#define MRF24J40_LONGREG_BASE 0x80000200 +#define MRF24J40_RXBUF_BASE 0x80000300 + +#define MRF24J40_TXNORM_FIFO (MRF24J40_FIFO_BASE + 0x000) +#define MRF24J40_BEACON_FIFO (MRF24J40_FIFO_BASE + 0x080) +#define MRF24J40_GTS1_FIFO (MRF24J40_FIFO_BASE + 0x100) +#define MRF24J40_GTS2_FIFO (MRF24J40_FIFO_BASE + 0x180) #define MRF24J40_RFCON0 (MRF24J40_LONGREG_BASE + 0x00) #define MRF24J40_RFCON1 (MRF24J40_LONGREG_BASE + 0x01) @@ -210,6 +215,8 @@ /* TXSTAT bits */ #define MRF24J40_TXSTAT_TXNSTAT (1 << 0) +#define MRF24J40_TXSTAT_TXG1STAT (1 << 1) +#define MRF24J40_TXSTAT_TXG2STAT (1 << 2) #define MRF24J40_TXSTAT_CCAFAIL (1 << 5) #define MRF24J40_TXSTAT_X_SHIFT 6 #define MRF24J40_TXSTAT_X_MASK (3 << MRF24J40_TXSTAT_X_SHIFT) diff --git a/include/nuttx/wireless/ieee802154/ieee802154_radio.h b/include/nuttx/wireless/ieee802154/ieee802154_radio.h index e1c0ff3aeac..ea22b6f1c1f 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_radio.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_radio.h @@ -164,6 +164,9 @@ struct ieee802154_txdesc_s uint16_t psdu_length; /* The length of the PSDU */ + uint8_t status; /* The status of the transaction. This is set by the + * radio layer prior to calling txdone_csma */ + /* TODO: Add slotting information for GTS transactions */ }; @@ -173,6 +176,10 @@ struct ieee802154_radiocb_s FAR struct ieee802154_txdesc_s *tx_desc, FAR uint8_t *buf); CODE int (*poll_gts) (FAR struct ieee802154_radiocb_s *radiocb, FAR struct ieee802154_txdesc_s *tx_desc, FAR uint8_t *buf); + CODE int (*txdone_csma) (FAR struct ieee802154_radiocb_s *radiocb, + FAR struct ieee802154_txdesc_s tx_desc); + CODE int (*txdone_gts) (FAR struct ieee802154_radiocb_s *radiocb, + FAR struct ieee802154_txdesc_s tx_desc); }; struct ieee802154_radio_s; /* Forward reference */ diff --git a/wireless/ieee802154/mac802154.c b/wireless/ieee802154/mac802154.c index 5ea09c2546d..0977c72b92c 100644 --- a/wireless/ieee802154/mac802154.c +++ b/wireless/ieee802154/mac802154.c @@ -235,7 +235,7 @@ struct ieee802154_privmac_s uint32_t is_coord : 1; /* Is this device acting as coordinator */ /* 12-bits remaining */ - /* End of 32-bit bitfield. + /* End of 32-bit bitfield. */ /* TODO: Add Security-related MAC PIB attributes */ }; @@ -380,7 +380,7 @@ MACHANDLE mac802154_create(FAR struct ieee802154_radio_s *radiodev) mac->radiocb.priv = mac; radiocb = &mac->radiocb.cb; - radiocb->poll_cmsa = mac802154_poll_csma; + radiocb->poll_csma = mac802154_poll_csma; radiocb->poll_gts = mac802154_poll_gts; /* Bind our callback structure */ From 9a1fe0b9719c756d11d74c0f57d17ae56b8d2bde Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 19 Apr 2017 14:52:45 -0600 Subject: [PATCH 094/183] ieee802154: Cosmetic changes from review of last PR. --- drivers/wireless/ieee802154/mrf24j40.c | 42 +++++++++++-------- drivers/wireless/ieee802154/mrf24j40.h | 8 ++-- .../wireless/ieee802154/ieee802154_radio.h | 2 - 3 files changed, 29 insertions(+), 23 deletions(-) diff --git a/drivers/wireless/ieee802154/mrf24j40.c b/drivers/wireless/ieee802154/mrf24j40.c index ffdd0689d47..bd773e8aaa0 100644 --- a/drivers/wireless/ieee802154/mrf24j40.c +++ b/drivers/wireless/ieee802154/mrf24j40.c @@ -163,7 +163,7 @@ static int mrf24j40_regdump(FAR struct mrf24j40_radio_s *dev); static void mrf24j40_irqwork_rx(FAR struct mrf24j40_radio_s *dev); static void mrf24j40_irqwork_txnorm(FAR struct mrf24j40_radio_s *dev); static void mrf24j40_irqwork_txgts(FAR struct mrf24j40_radio_s *dev, - uint8_t gts_num); + uint8_t gts_num); static void mrf24j40_irqworker(FAR void *arg); static int mrf24j40_interrupt(int irq, FAR void *context, FAR void *arg); @@ -171,13 +171,12 @@ static int mrf24j40_interrupt(int irq, FAR void *context, FAR void *arg); static void mrf24j40_dopoll_csma(FAR void *arg); static void mrf24j40_dopoll_gts(FAR void *arg); -static int mrf24j40_csma_setup(FAR struct mrf24j40_radio_s *dev, - uint8_t *buf, uint16_t buf_len); -static int mrf24j40_gts_setup(FAR struct mrf24j40_radio_s *dev, uint8_t gts, - uint8_t *buf, uint16_t buf_len); -static int mrf24j40_setup_fifo(FAR struct mrf24j40_radio_s *dev, - uint8_t *buf, uint16_t buf_len, - uint32_t fifo_addr); +static int mrf24j40_csma_setup(FAR struct mrf24j40_radio_s *dev, + FAR uint8_t *buf, uint16_t buf_len); +static int mrf24j40_gts_setup(FAR struct mrf24j40_radio_s *dev, uint8_t gts, + FAR uint8_t *buf, uint16_t buf_len); +static int mrf24j40_setup_fifo(FAR struct mrf24j40_radio_s *dev, + FAR uint8_t *buf, uint16_t buf_len, uint32_t fifo_addr); /* IOCTL helpers */ @@ -225,7 +224,7 @@ static int mrf24j40_ioctl(FAR struct ieee802154_radio_s *radio, int cmd, static int mrf24j40_rxenable(FAR struct ieee802154_radio_s *radio, bool state, FAR struct ieee802154_packet_s *packet); static int mrf24j40_transmit(FAR struct ieee802154_radio_s *radio, - uint8_t *buf, uint16_t buf_len); + FAR uint8_t *buf, uint16_t buf_len); static int mrf24j40_txnotify_csma(FAR struct ieee802154_radio_s *radio); static int mrf24j40_txnotify_gts(FAR struct ieee802154_radio_s *radio); @@ -1340,7 +1339,7 @@ static int mrf24j40_energydetect(FAR struct mrf24j40_radio_s *dev, ****************************************************************************/ static int mrf24j40_transmit(FAR struct ieee802154_radio_s *radio, - uint8_t *buf, uint16_t buf_len) + FAR uint8_t *buf, uint16_t buf_len) { FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)radio; uint8_t reg; @@ -1384,10 +1383,10 @@ static int mrf24j40_transmit(FAR struct ieee802154_radio_s *radio, ****************************************************************************/ static int mrf24j40_csma_setup(FAR struct mrf24j40_radio_s *dev, - uint8_t *buf, uint16_t buf_len) + FAR uint8_t *buf, uint16_t buf_len) { - uint8_t reg; - int ret; + uint8_t reg; + int ret; mrf24j40_pacontrol(dev, MRF24J40_PA_AUTO); @@ -1427,13 +1426,20 @@ static int mrf24j40_csma_setup(FAR struct mrf24j40_radio_s *dev, ****************************************************************************/ static int mrf24j40_gts_setup(FAR struct mrf24j40_radio_s *dev, uint8_t fifo, - uint8_t *buf, uint16_t buf_len) + FAR uint8_t *buf, uint16_t buf_len) { return -ENOTTY; } +/**************************************************************************** + * Name: mrf24j40_setup_fifo + * + * Description: + * + ****************************************************************************/ + static int mrf24j40_setup_fifo(FAR struct mrf24j40_radio_s *dev, - uint8_t *buf, uint16_t buf_len, + FAR uint8_t *buf, uint16_t buf_len, uint32_t fifo_addr) { int ret; @@ -1506,7 +1512,8 @@ static void mrf24j40_irqwork_txnorm(FAR struct mrf24j40_radio_s *dev) /* Get the status from the device and copy the status into the tx desc. * The status for the normal FIFO is represented with bit TXNSTAT where - * 0=success, 1= failure */ + * 0=success, 1= failure. + */ txstat = mrf24j40_getreg(dev->spi, MRF24J40_TXSTAT); dev->csma_desc.pub.status = txstat & MRF24J40_TXSTAT_TXNSTAT; @@ -1543,7 +1550,8 @@ static void mrf24j40_irqwork_txgts(FAR struct mrf24j40_radio_s *dev, /* Get the status from the device and copy the status into the tx desc. * The status for the normal FIFO is represented with bit TXNSTAT where - * 0=success, 1= failure */ + * 0=success, 1= failure. + */ txstat = mrf24j40_getreg(dev->spi, MRF24J40_TXSTAT); diff --git a/drivers/wireless/ieee802154/mrf24j40.h b/drivers/wireless/ieee802154/mrf24j40.h index 96d00691d2b..585fae513af 100644 --- a/drivers/wireless/ieee802154/mrf24j40.h +++ b/drivers/wireless/ieee802154/mrf24j40.h @@ -101,10 +101,10 @@ #define MRF24J40_LONGREG_BASE 0x80000200 #define MRF24J40_RXBUF_BASE 0x80000300 -#define MRF24J40_TXNORM_FIFO (MRF24J40_FIFO_BASE + 0x000) -#define MRF24J40_BEACON_FIFO (MRF24J40_FIFO_BASE + 0x080) -#define MRF24J40_GTS1_FIFO (MRF24J40_FIFO_BASE + 0x100) -#define MRF24J40_GTS2_FIFO (MRF24J40_FIFO_BASE + 0x180) +#define MRF24J40_TXNORM_FIFO (MRF24J40_FIFO_BASE + 0x000) +#define MRF24J40_BEACON_FIFO (MRF24J40_FIFO_BASE + 0x080) +#define MRF24J40_GTS1_FIFO (MRF24J40_FIFO_BASE + 0x100) +#define MRF24J40_GTS2_FIFO (MRF24J40_FIFO_BASE + 0x180) #define MRF24J40_RFCON0 (MRF24J40_LONGREG_BASE + 0x00) #define MRF24J40_RFCON1 (MRF24J40_LONGREG_BASE + 0x01) diff --git a/include/nuttx/wireless/ieee802154/ieee802154_radio.h b/include/nuttx/wireless/ieee802154/ieee802154_radio.h index ea22b6f1c1f..af1281e36a9 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_radio.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_radio.h @@ -161,9 +161,7 @@ struct ieee802154_netradio_s struct ieee802154_txdesc_s { uint8_t psdu_handle; /* The psdu handle identifying the transaction */ - uint16_t psdu_length; /* The length of the PSDU */ - uint8_t status; /* The status of the transaction. This is set by the * radio layer prior to calling txdone_csma */ From a5d73e42cdcc1ccb916bd728c15550a9dcb2f756 Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Wed, 19 Apr 2017 18:15:09 -0400 Subject: [PATCH 095/183] wireless/ieee802154: Fixes radio callback arguments --- drivers/wireless/ieee802154/mrf24j40.c | 4 ++-- include/nuttx/wireless/ieee802154/ieee802154_radio.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/wireless/ieee802154/mrf24j40.c b/drivers/wireless/ieee802154/mrf24j40.c index bd773e8aaa0..fe34ab1259d 100644 --- a/drivers/wireless/ieee802154/mrf24j40.c +++ b/drivers/wireless/ieee802154/mrf24j40.c @@ -1520,7 +1520,7 @@ static void mrf24j40_irqwork_txnorm(FAR struct mrf24j40_radio_s *dev) /* Inform the next layer of the transmission success/failure */ - dev->radiocb->txdone_csma(dev->radiocb, dev->csma_desc.pub); + dev->radiocb->txdone_csma(dev->radiocb, &dev->csma_desc.pub); /* We are now done with the transaction */ @@ -1566,7 +1566,7 @@ static void mrf24j40_irqwork_txgts(FAR struct mrf24j40_radio_s *dev, /* Inform the next layer of the transmission success/failure */ - dev->radiocb->txdone_gts(dev->radiocb, dev->gts_desc[gts].pub); + dev->radiocb->txdone_gts(dev->radiocb, &dev->gts_desc[gts].pub); /* We are now done with the transaction */ diff --git a/include/nuttx/wireless/ieee802154/ieee802154_radio.h b/include/nuttx/wireless/ieee802154/ieee802154_radio.h index af1281e36a9..3dcde47e832 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_radio.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_radio.h @@ -175,9 +175,9 @@ struct ieee802154_radiocb_s CODE int (*poll_gts) (FAR struct ieee802154_radiocb_s *radiocb, FAR struct ieee802154_txdesc_s *tx_desc, FAR uint8_t *buf); CODE int (*txdone_csma) (FAR struct ieee802154_radiocb_s *radiocb, - FAR struct ieee802154_txdesc_s tx_desc); + FAR const struct ieee802154_txdesc_s *tx_desc); CODE int (*txdone_gts) (FAR struct ieee802154_radiocb_s *radiocb, - FAR struct ieee802154_txdesc_s tx_desc); + FAR const struct ieee802154_txdesc_s *tx_desc); }; struct ieee802154_radio_s; /* Forward reference */ From 7ed8e4166b7af4a1c9474e165f59cb552bbf5504 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 21 Apr 2017 10:33:24 -0600 Subject: [PATCH 096/183] MAC header: Keep IOCTL-related structures together. --- .../wireless/ieee802154/ieee802154_mac.h | 48 +++++++++---------- .../wireless/ieee802154/ieee802154_radio.h | 2 +- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/include/nuttx/wireless/ieee802154/ieee802154_mac.h b/include/nuttx/wireless/ieee802154/ieee802154_mac.h index dfc5aa76968..f4fc2b7d181 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_mac.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_mac.h @@ -1292,30 +1292,6 @@ struct ieee802154_poll_conf_s enum ieee802154_status_e status; }; -/* A pointer to this structure is passed as the argument of each IOCTL - * command. - */ - -union ieee802154_macarg_u -{ - struct ieee802154_assoc_req_s assocreq; /* MAC802154IOC_MLME_ASSOC_REQUEST */ - struct ieee802154_assoc_resp_s assocresp; /* MAC802154IOC_MLME_ASSOC_RESPONSE */ - struct ieee802154_disassoc_req_s disassocreq; /* MAC802154IOC_MLME_DISASSOC_REQUEST */ - struct ieee802154_get_req_s getreq; /* MAC802154IOC_MLME_GET_REQUEST */ - struct ieee802154_gts_req_s gtsreq; /* MAC802154IOC_MLME_GTS_REQUEST */ - struct ieee802154_orphan_resp_s orphanresp; /* MAC802154IOC_MLME_ORPHAN_RESPONSE */ - struct ieee802154_reset_req_s resetreq; /* MAC802154IOC_MLME_RESET_REQUEST */ - struct ieee802154_rxenable_req_s rxenabreq; /* MAC802154IOC_MLME_RXENABLE_REQUEST */ - struct ieee802154_scan_req_s scanreq; /* MAC802154IOC_MLME_SCAN_REQUEST */ - struct ieee802154_set_req_s setreq; /* MAC802154IOC_MLME_SET_REQUEST */ - struct ieee802154_start_req_s startreq; /* MAC802154IOC_MLME_START_REQUEST */ - struct ieee802154_sync_req_s syncreq; /* MAC802154IOC_MLME_SYNC_REQUEST */ - struct ieee802154_poll_req_s pollreq; /* MAC802154IOC_MLME_POLL_REQUEST */ - /* To be determined */ /* MAC802154IOC_MLME_DPS_REQUEST */ - /* To be determined */ /* MAC802154IOC_MLME_SOUNDING_REQUEST */ - /* To be determined */ /* MAC802154IOC_MLME_CALIBRATE_REQUEST */ -}; - union ieee802154_mlme_notify_u { struct ieee802154_assoc_conf_s assocconf; @@ -1345,6 +1321,30 @@ union ieee802154_mcps_notify_u struct ieee802154_data_ind_s dataind; }; +/* A pointer to this structure is passed as the argument of each IOCTL + * command. + */ + +union ieee802154_macarg_u +{ + struct ieee802154_assoc_req_s assocreq; /* MAC802154IOC_MLME_ASSOC_REQUEST */ + struct ieee802154_assoc_resp_s assocresp; /* MAC802154IOC_MLME_ASSOC_RESPONSE */ + struct ieee802154_disassoc_req_s disassocreq; /* MAC802154IOC_MLME_DISASSOC_REQUEST */ + struct ieee802154_get_req_s getreq; /* MAC802154IOC_MLME_GET_REQUEST */ + struct ieee802154_gts_req_s gtsreq; /* MAC802154IOC_MLME_GTS_REQUEST */ + struct ieee802154_orphan_resp_s orphanresp; /* MAC802154IOC_MLME_ORPHAN_RESPONSE */ + struct ieee802154_reset_req_s resetreq; /* MAC802154IOC_MLME_RESET_REQUEST */ + struct ieee802154_rxenable_req_s rxenabreq; /* MAC802154IOC_MLME_RXENABLE_REQUEST */ + struct ieee802154_scan_req_s scanreq; /* MAC802154IOC_MLME_SCAN_REQUEST */ + struct ieee802154_set_req_s setreq; /* MAC802154IOC_MLME_SET_REQUEST */ + struct ieee802154_start_req_s startreq; /* MAC802154IOC_MLME_START_REQUEST */ + struct ieee802154_sync_req_s syncreq; /* MAC802154IOC_MLME_SYNC_REQUEST */ + struct ieee802154_poll_req_s pollreq; /* MAC802154IOC_MLME_POLL_REQUEST */ + /* To be determined */ /* MAC802154IOC_MLME_DPS_REQUEST */ + /* To be determined */ /* MAC802154IOC_MLME_SOUNDING_REQUEST */ + /* To be determined */ /* MAC802154IOC_MLME_CALIBRATE_REQUEST */ +}; + #ifdef CONFIG_NET_6LOWPAN /* For the case of network IOCTLs, the network IOCTL to the MAC network * driver will include a device name like "wpan0" as the destination of diff --git a/include/nuttx/wireless/ieee802154/ieee802154_radio.h b/include/nuttx/wireless/ieee802154/ieee802154_radio.h index 3dcde47e832..be2876468b5 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_radio.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_radio.h @@ -99,7 +99,7 @@ #define PHY802154IOC_ENERGYDETECT _PHY802154IOC(0x0011) -#define EADDR_SIZE 8 /* REVISIT */ +#define EADDR_SIZE 8 /* Extended address size */ /**************************************************************************** * Public Types From 795e70a9522231b1c1a5e8c0bbcbcef2b803f276 Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Fri, 21 Apr 2017 13:06:18 -0400 Subject: [PATCH 097/183] wireless/ieee802154: Work on packet reception at radio layer (MRF24J40) --- drivers/wireless/ieee802154/mrf24j40.c | 36 +++++++++++++++---- .../wireless/ieee802154/ieee802154_radio.h | 16 +++++---- net/sixlowpan/sixlowpan_framelist.c | 2 +- 3 files changed, 39 insertions(+), 15 deletions(-) diff --git a/drivers/wireless/ieee802154/mrf24j40.c b/drivers/wireless/ieee802154/mrf24j40.c index fe34ab1259d..b6e155bd936 100644 --- a/drivers/wireless/ieee802154/mrf24j40.c +++ b/drivers/wireless/ieee802154/mrf24j40.c @@ -1618,6 +1618,8 @@ static int mrf24j40_rxenable(FAR struct ieee802154_radio_s *radio, bool state, static void mrf24j40_irqwork_rx(FAR struct mrf24j40_radio_s *dev) { + FAR struct iob_s *iob; + struct ieee802154_txdesc_s rxdesc; uint32_t addr; uint32_t index; uint8_t reg; @@ -1634,25 +1636,46 @@ static void mrf24j40_irqwork_rx(FAR struct mrf24j40_radio_s *dev) mrf24j40_setreg(dev->spi, MRF24J40_BBREG1, MRF24J40_BBREG1_RXDECINV); + + /* Allocate an IOB to put the packet in */ + + iob = iob_alloc(true); + DEBUGASSERT(iob != NULL); + + iob->io_flink = NULL; + iob->io_len = 0; + iob->io_offset = 0; + iob->io_pktlen = 0; + /* Read packet */ addr = MRF24J40_RXBUF_BASE; - dev->radio.rxbuf->len = mrf24j40_getreg(dev->spi, addr++); + + iob->io_len= mrf24j40_getreg(dev->spi, addr++); /* wlinfo("len %3d\n", dev->radio.rxbuf->len); */ - for (index = 0; index < dev->radio.rxbuf->len; index++) + /* TODO: This needs to be changed. It is inefficient to do the SPI read byte + * by byte */ + + for (index = 0; index < iob->io_len; index++) { - dev->radio.rxbuf->data[index] = mrf24j40_getreg(dev->spi, addr++); + iob->io_data[index] = mrf24j40_getreg(dev->spi, addr++); } - dev->radio.rxbuf->lqi = mrf24j40_getreg(dev->spi, addr++); - dev->radio.rxbuf->rssi = mrf24j40_getreg(dev->spi, addr++); + /* Copy meta-data into RX descriptor */ + + rxdesc.lqi = mrf24j40_getreg(dev->spi, addr++); + rxdesc.rssi = mrf24j40_getreg(dev->spi, addr++); /* Reduce len by 2, we only receive frames with correct crc, no check * required. */ - dev->radio.rxbuf->len -= 2; + iob->io_len -= 2; + + /* Callback the receiver in the next highest layer */ + + dev->radiocb->rx_frame(dev->radiocb, &rxdesc, iob); /* Enable reception of next packet by flushing the fifo. * This is an MRF24J40 errata (no. 1). @@ -1664,7 +1687,6 @@ static void mrf24j40_irqwork_rx(FAR struct mrf24j40_radio_s *dev) mrf24j40_setreg(dev->spi, MRF24J40_BBREG1, 0); - sem_post(&dev->radio.rxsem); } /**************************************************************************** diff --git a/include/nuttx/wireless/ieee802154/ieee802154_radio.h b/include/nuttx/wireless/ieee802154/ieee802154_radio.h index be2876468b5..272d5fdf2c6 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_radio.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_radio.h @@ -168,6 +168,12 @@ struct ieee802154_txdesc_s /* TODO: Add slotting information for GTS transactions */ }; +struct ieee802154_rxdesc_s +{ + uint8_t lqi; + uint8_t rssi; +}; + struct ieee802154_radiocb_s { CODE int (*poll_csma) (FAR struct ieee802154_radiocb_s *radiocb, @@ -178,6 +184,9 @@ struct ieee802154_radiocb_s FAR const struct ieee802154_txdesc_s *tx_desc); CODE int (*txdone_gts) (FAR struct ieee802154_radiocb_s *radiocb, FAR const struct ieee802154_txdesc_s *tx_desc); + CODE int (*rx_frame) (FAR struct ieee802154_radiocb_s *radiocb, + FAR const struct ieee8021254_rxdesc_s *rx_desc, + FAR struct iob_s *frame); }; struct ieee802154_radio_s; /* Forward reference */ @@ -197,13 +206,6 @@ struct ieee802154_radioops_s struct ieee802154_radio_s { FAR const struct ieee802154_radioops_s *ops; - - /* Packet reception management */ - - struct ieee802154_packet_s *rxbuf; /* packet reception buffer, filled by - * rx interrupt, NULL if rx not enabled */ - sem_t rxsem; /* Semaphore posted after reception of - * a packet */ }; #ifdef __cplusplus diff --git a/net/sixlowpan/sixlowpan_framelist.c b/net/sixlowpan/sixlowpan_framelist.c index 79e653d10bd..ee9487a101d 100644 --- a/net/sixlowpan/sixlowpan_framelist.c +++ b/net/sixlowpan/sixlowpan_framelist.c @@ -77,7 +77,7 @@ */ #if CONFIG_NET_6LOWPAN_MTU > (CONFIG_IOB_BUFSIZE * CONFIG_IOB_NBUFFERS) -# error Not enough IOBs to hold one full IEEE802.14.5 packet +# error Not enough IOBs to hold one full 6LoWPAN packet #endif /**************************************************************************** From c071cde2204161963e06ab6cc495adbdb4885d63 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 21 Apr 2017 12:29:38 -0600 Subject: [PATCH 098/183] Cosmetic changes to some comments. --- include/nuttx/wireless/ieee802154/ieee802154_mac.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/nuttx/wireless/ieee802154/ieee802154_mac.h b/include/nuttx/wireless/ieee802154/ieee802154_mac.h index f4fc2b7d181..2f78ec443f1 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_mac.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_mac.h @@ -1327,6 +1327,8 @@ union ieee802154_mcps_notify_u union ieee802154_macarg_u { + /* To be determined */ /* MAC802154IOC_MCPS_REGISTER */ + /* To be determined */ /* MAC802154IOC_MLME_REGISTER */ struct ieee802154_assoc_req_s assocreq; /* MAC802154IOC_MLME_ASSOC_REQUEST */ struct ieee802154_assoc_resp_s assocresp; /* MAC802154IOC_MLME_ASSOC_RESPONSE */ struct ieee802154_disassoc_req_s disassocreq; /* MAC802154IOC_MLME_DISASSOC_REQUEST */ From b1c8f008d62c2c3f9a7502aefe8f98b7db6c2480 Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Fri, 21 Apr 2017 14:57:15 -0400 Subject: [PATCH 099/183] wireless/ieee802154: Simplifies TX completion interface. Documents and cleans up some functions --- drivers/wireless/ieee802154/mrf24j40.c | 4 +- .../wireless/ieee802154/ieee802154_radio.h | 4 +- wireless/ieee802154/mac802154.c | 350 +++++++++++++----- 3 files changed, 269 insertions(+), 89 deletions(-) diff --git a/drivers/wireless/ieee802154/mrf24j40.c b/drivers/wireless/ieee802154/mrf24j40.c index b6e155bd936..1e07d1126b7 100644 --- a/drivers/wireless/ieee802154/mrf24j40.c +++ b/drivers/wireless/ieee802154/mrf24j40.c @@ -1520,7 +1520,7 @@ static void mrf24j40_irqwork_txnorm(FAR struct mrf24j40_radio_s *dev) /* Inform the next layer of the transmission success/failure */ - dev->radiocb->txdone_csma(dev->radiocb, &dev->csma_desc.pub); + dev->radiocb->txdone(dev->radiocb, &dev->csma_desc.pub); /* We are now done with the transaction */ @@ -1566,7 +1566,7 @@ static void mrf24j40_irqwork_txgts(FAR struct mrf24j40_radio_s *dev, /* Inform the next layer of the transmission success/failure */ - dev->radiocb->txdone_gts(dev->radiocb, &dev->gts_desc[gts].pub); + dev->radiocb->txdone(dev->radiocb, &dev->gts_desc[gts].pub); /* We are now done with the transaction */ diff --git a/include/nuttx/wireless/ieee802154/ieee802154_radio.h b/include/nuttx/wireless/ieee802154/ieee802154_radio.h index 272d5fdf2c6..58748b267a2 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_radio.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_radio.h @@ -180,9 +180,7 @@ struct ieee802154_radiocb_s FAR struct ieee802154_txdesc_s *tx_desc, FAR uint8_t *buf); CODE int (*poll_gts) (FAR struct ieee802154_radiocb_s *radiocb, FAR struct ieee802154_txdesc_s *tx_desc, FAR uint8_t *buf); - CODE int (*txdone_csma) (FAR struct ieee802154_radiocb_s *radiocb, - FAR const struct ieee802154_txdesc_s *tx_desc); - CODE int (*txdone_gts) (FAR struct ieee802154_radiocb_s *radiocb, + CODE int (*txdone) (FAR struct ieee802154_radiocb_s *radiocb, FAR const struct ieee802154_txdesc_s *tx_desc); CODE int (*rx_frame) (FAR struct ieee802154_radiocb_s *radiocb, FAR const struct ieee8021254_rxdesc_s *rx_desc, diff --git a/wireless/ieee802154/mac802154.c b/wireless/ieee802154/mac802154.c index 0977c72b92c..51658893c00 100644 --- a/wireless/ieee802154/mac802154.c +++ b/wireless/ieee802154/mac802154.c @@ -105,6 +105,9 @@ struct ieee802154_privmac_s sem_t exclsem; /* Support exclusive access */ + struct work_s tx_work; + struct work_s rx_work; + /* Support a singly linked list of transactions that will be sent using the * CSMA algorithm. On a non-beacon enabled PAN, these transactions will be * sent whenever. On a beacon-enabled PAN, these transactions will be sent @@ -125,6 +128,10 @@ struct ieee802154_privmac_s FAR struct mac802154_trans_s *indirect_head; FAR struct mac802154_trans_s *indirect_tail; + FAR struct ieee802154_txdesc_s *txhead; /* Next TX descriptor to handle */ + FAR struct ieee802154_txdesc_s *txtail; /* Location to push TX descriptor */ + struct ieee802154_txdesc_s txtable[CONFIG_IEEE802154_NTXDESC]; + /* MAC PIB attributes, grouped to save memory */ /* Holds all address information (Extended, Short, and PAN ID) for the MAC. */ @@ -262,6 +269,9 @@ static int mac802154_poll_gts(FAR struct ieee802154_radiocb_s *radiocb, FAR struct ieee802154_txdesc_s *tx_desc, FAR uint8_t *buf); +static int mac802154_txdone(FAR struct ieee802154_radiocb_s *radiocb, + FAR struct ieee802154_txdesc_s *tx_desc); + /**************************************************************************** * Private Data ****************************************************************************/ @@ -325,6 +335,258 @@ static int mac802154_applymib(FAR struct ieee802154_privmac_s *priv) return OK; } +/**************************************************************************** + * Name: mac802154_poll_csma + * + * Description: + * Called from the radio driver through the callback struct. This function is + * called when the radio has room for another CSMA transaction. If the MAC + * layer has a CSMA transaction, it copies it into the supplied buffer and + * returns the length. A descriptor is also populated with the transaction. + * + ****************************************************************************/ + +static int mac802154_poll_csma(FAR struct ieee802154_radiocb_s *radiocb, + FAR struct ieee802154_txdesc_s *tx_desc, + FAR uint8_t *buf) +{ + FAR struct mac802154_radiocb_s *cb = + (FAR struct mac802154_radiocb_s *)radiocb; + FAR struct ieee802154_privmac_s *priv; + FAR struct mac802154_trans_s *trans; + + DEBUGASSERT(cb != NULL && cb->priv != NULL); + priv = cb->priv; + + /* Get exclusive access to the driver structure. We don't care about any + * signals so if we see one, just go back to trying to get access again. + */ + + while (mac802154_takesem(&priv->exclsem) != 0); + + /* Check to see if there are any CSMA transactions waiting */ + + if (priv->csma_head) + { + /* Pop a CSMA transaction off the list */ + + trans = priv->csma_head; + priv->csma_head = priv->csma_head->flink; + + mac802154_givesem(&priv->exclsem); + + /* Setup the transmit descriptor */ + + tx_desc->psdu_handle = trans->msdu_handle; + tx_desc->psdu_length = trans->mhr_len + trans->d_len; + + /* Copy the frame into the buffer */ + + memcpy(&buf[0], trans->mhr_buf, trans->mhr_len); + memcpy(&buf[trans->mhr_len], trans->d_buf, trans->d_len); + + /* Now that we've passed off the data, notify the waiting thread. + * NOTE: The transaction was allocated on the waiting thread's stack so + * it will be automatically deallocated when that thread awakens and + * returns. + */ + + sem_post(&trans->sem); + return tx_desc->psdu_length; + } + + mac802154_givesem(&priv->exclsem); + return 0; +} + +/**************************************************************************** + * Name: mac802154_poll_gts + * + * Description: + * Called from the radio driver through the callback struct. This function is + * called when the radio has room for another GTS transaction. If the MAC + * layer has a GTS transaction, it copies it into the supplied buffer and + * returns the length. A descriptor is also populated with the transaction. + * + ****************************************************************************/ + +static int mac802154_poll_gts(FAR struct ieee802154_radiocb_s *radiocb, + FAR struct ieee802154_txdesc_s *tx_desc, + FAR uint8_t *buf) +{ + FAR struct mac802154_radiocb_s *cb = + (FAR struct mac802154_radiocb_s *)radiocb; + FAR struct ieee802154_privmac_s *priv; + FAR struct mac802154_trans_s *trans; + int ret = 0; + + DEBUGASSERT(cb != NULL && cb->priv != NULL); + priv = cb->priv; + + /* Get exclusive access to the driver structure. We don't care about any + * signals so if we see one, just go back to trying to get access again. + */ + + while (mac802154_takesem(&priv->exclsem) != 0); + +#warning Missing logic. + + mac802154_givesem(&priv->exclsem); + + return 0; +} + +/**************************************************************************** + * Name: mac802154_txdone + * + * Description: + * Called from the radio driver through the callback struct. This function is + * called when the radio has completed a transaction. The txdesc passed gives + * provides information about the completed transaction including the original + * handle provided when the transaction was created and the status of the + * transaction. This function copies the descriptor and schedules work to + * handle the transaction without blocking the radio. + * + ****************************************************************************/ + +static int mac802154_txdone(FAR struct ieee802154_radiocb_s *radiocb, + FAR const struct ieee802154_txdesc_s *tx_desc) +{ + FAR struct mac802154_radiocb_s *cb = + (FAR struct mac802154_radiocb_s *)radiocb; + FAR struct ieee802154_privmac_s *priv; + FAR struct ieee802154_txdesc_s *desc; + int ret = 0; + + DEBUGASSERT(cb != NULL && cb->priv != NULL); + priv = cb->priv; + + /* Get exclusive access to the driver structure. We don't care about any + * signals so if we see one, just go back to trying to get access again. + */ + + while (mac802154_takesem(&priv->exclsem) != 0); + + /* Allocate a tx_desc */ + + desc = kmm_zalloc(sizeof(struct ieee802154_txdesc_s)); + if (desc == NULL) + { + mac802154_givesem(&priv->exclsem); + + return -ENOMEM; + } + + /* Copy the txdesc over and link it into our list */ + + memcpy(desc, tx_desc, sizeof(ieee802154_txdesc_s)); + + /* Link the descriptor */ + +#warning Missing Logic! + + mac802154_givesem(&priv->exclsem); + + /* Schedule work with the work queue to process the completion further */ + + if (work_available(&priv->tx_work)) + { + work_queue(MAC802154_WORK, &priv->tx_work, mac802154_txdone_worker, + (FAR void *)dev, 0); + } +} + +/**************************************************************************** + * Name: mac802154_txdone_worker + * + * Description: + * Worker function scheduled from mac802154_txdone. This function pops any + * TX descriptors off of the list and calls the next highest layers callback + * to inform the layer of the completed transaction and the status of it. + * + ****************************************************************************/ + +static void mac802154_txdone_worker(FAR void *arg) +{ + FAR struct ieee802154_privmanc_s *priv = + (FAR struct ieee802154_privmanc_s *)arg; + + +} + +/**************************************************************************** + * Name: mac802154_rxframe + * + * Description: + * Called from the radio driver through the callback struct. This function is + * called when the radio has received a frame. The frame is passed in an iob, + * so that we can free it when we are done processing. A pointer to the RX + * descriptor is passed along with the iob, but it must be copied here as it + * is allocated directly on the caller's stack. We simply link the frame, + * copy the RX descriptor, and schedule a worker to process the frame later so + * that we do not hold up the radio. + * + ****************************************************************************/ + +static void mac802154_rxframe(FAR struct ieee802154_radiocb_s *radiocb, + FAR struct ieee802154_rxdesc_s *rx_desc, + FAR struct iob_s *frame) +{ + FAR struct mac802154_radiocb_s *cb = + (FAR struct mac802154_radiocb_s *)radiocb; + FAR struct ieee802154_privmac_s *priv; + FAR struct ieee802154_txdesc_s *desc; + int ret = 0; + + DEBUGASSERT(cb != NULL && cb->priv != NULL); + priv = cb->priv; + + /* Get exclusive access to the driver structure. We don't care about any + * signals so if we see one, just go back to trying to get access again. + */ + + while (mac802154_takesem(&priv->exclsem) != 0); + + /* TODO: Copy the frame descriptor to some type of list */ + + /* Push the iob onto the tail of the frame list for processing */ + + priv->rxframes_tail->io_flink = iob; + priv->rxframes_tail = iob; + + mac802154_givesem(&priv->exclsem); + + /* Schedule work with the work queue to process the completion further */ + + if (work_available(&priv->rx_work)) + { + work_queue(MAC802154_WORK, &priv->rx_work, mac802154_rxframe_worker, + (FAR void *)priv, 0); + } +} + +/**************************************************************************** + * Name: mac802154_rxframe_worker + * + * Description: + * Worker function scheduled from mac802154_rxframe. This function processes + * any frames in the list. Frames intended to be consumed by the MAC layer + * will not produce any callbacks to the next highest layer. Frames intended + * for the application layer will be forwarded to them. + * + ****************************************************************************/ + +static void mac802154_rxframe_worker(FAR void *arg) +{ + FAR struct ieee802154_privmac_s *priv = + (FAR struct ieee802154_privmac_s *)arg; + + /* The radio layer is responsible for handling all ACKs and retries. If for + * some reason an ACK gets here, just throw it out */ + +} + + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -379,9 +641,10 @@ MACHANDLE mac802154_create(FAR struct ieee802154_radio_s *radiodev) mac->radiocb.priv = mac; - radiocb = &mac->radiocb.cb; - radiocb->poll_csma = mac802154_poll_csma; - radiocb->poll_gts = mac802154_poll_gts; + radiocb = &mac->radiocb.cb; + radiocb->poll_csma = mac802154_poll_csma; + radiocb->poll_gts = mac802154_poll_gts; + radiocb->txdone = mac802154_txdone; /* Bind our callback structure */ @@ -710,87 +973,6 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) return OK; } -/* Called from interrupt level or worker thread with interrupts disabled */ - -static int mac802154_poll_csma(FAR struct ieee802154_radiocb_s *radiocb, - FAR struct ieee802154_txdesc_s *tx_desc, - FAR uint8_t *buf) -{ - FAR struct mac802154_radiocb_s *cb = - (FAR struct mac802154_radiocb_s *)radiocb; - FAR struct ieee802154_privmac_s *priv; - FAR struct mac802154_trans_s *trans; - int ret = 0; - - DEBUGASSERT(cb != NULL && cb->priv != NULL); - priv = cb->priv; - - /* Get exclusive access to the driver structure. We don't care about any - * signals so if we see one, just go back to trying to get access again. - */ - - while (mac802154_takesem(&priv->exclsem) != 0); - - /* Check to see if there are any CSMA transactions waiting */ - - if (priv->csma_head) - { - /* Pop a CSMA transaction off the list */ - - trans = priv->csma_head; - priv->csma_head = priv->csma_head->flink; - - /* Setup the transmit descriptor */ - - tx_desc->psdu_handle = trans->msdu_handle; - tx_desc->psdu_length = trans->mhr_len + trans->d_len; - - /* Copy the frame into the buffer */ - - memcpy(&buf[0], trans->mhr_buf, trans->mhr_len); - memcpy(&buf[trans->mhr_len], trans->d_buf, trans->d_len); - - /* Now that we've passed off the data, notify the waiting thread. - * NOTE: The transaction was allocated on the waiting thread's stack so - * it will be automatically deallocated when that thread awakens and - * returns. - */ - - sem_post(&trans->sem); - - ret = tx_desc->psdu_length; - } - - mac802154_givesem(&priv->exclsem); - - return ret; -} - -static int mac802154_poll_gts(FAR struct ieee802154_radiocb_s *radiocb, - FAR struct ieee802154_txdesc_s *tx_desc, - FAR uint8_t *buf) -{ - FAR struct mac802154_radiocb_s *cb = - (FAR struct mac802154_radiocb_s *)radiocb; - FAR struct ieee802154_privmac_s *priv; - FAR struct mac802154_trans_s *trans; - int ret = 0; - - DEBUGASSERT(cb != NULL && cb->priv != NULL); - priv = cb->priv; - - /* Get exclusive access to the driver structure. We don't care about any - * signals so if we see one, just go back to trying to get access again. - */ - - while (mac802154_takesem(&priv->exclsem) != 0); - -#warning Missing logic. - - mac802154_givesem(&priv->exclsem); - - return 0; -} /**************************************************************************** * Name: mac802154_req_purge From b2292cd2cbef6af4693328e44f282b6ac027caf7 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 21 Apr 2017 13:21:43 -0600 Subject: [PATCH 100/183] Some trivial spacing changes from review of last PR; Remove some dangling whitespace at the end of lines. --- wireless/ieee802154/mac802154.c | 35 ++++++++++++-------------- wireless/ieee802154/mac802154_device.c | 2 +- wireless/ieee802154/mac802154_netdev.c | 32 +++++++++++------------ 3 files changed, 33 insertions(+), 36 deletions(-) diff --git a/wireless/ieee802154/mac802154.c b/wireless/ieee802154/mac802154.c index 51658893c00..ca877d5442f 100644 --- a/wireless/ieee802154/mac802154.c +++ b/wireless/ieee802154/mac802154.c @@ -58,7 +58,7 @@ /**************************************************************************** * Private Types ****************************************************************************/ - + struct mac802154_trans_s { /* Supports a singly linked list */ @@ -265,7 +265,7 @@ static int mac802154_poll_csma(FAR struct ieee802154_radiocb_s *radiocb, FAR struct ieee802154_txdesc_s *tx_desc, FAR uint8_t *buf); -static int mac802154_poll_gts(FAR struct ieee802154_radiocb_s *radiocb, +static int mac802154_poll_gts(FAR struct ieee802154_radiocb_s *radiocb, FAR struct ieee802154_txdesc_s *tx_desc, FAR uint8_t *buf); @@ -342,7 +342,7 @@ static int mac802154_applymib(FAR struct ieee802154_privmac_s *priv) * Called from the radio driver through the callback struct. This function is * called when the radio has room for another CSMA transaction. If the MAC * layer has a CSMA transaction, it copies it into the supplied buffer and - * returns the length. A descriptor is also populated with the transaction. + * returns the length. A descriptor is also populated with the transaction. * ****************************************************************************/ @@ -406,11 +406,11 @@ static int mac802154_poll_csma(FAR struct ieee802154_radiocb_s *radiocb, * Called from the radio driver through the callback struct. This function is * called when the radio has room for another GTS transaction. If the MAC * layer has a GTS transaction, it copies it into the supplied buffer and - * returns the length. A descriptor is also populated with the transaction. + * returns the length. A descriptor is also populated with the transaction. * ****************************************************************************/ -static int mac802154_poll_gts(FAR struct ieee802154_radiocb_s *radiocb, +static int mac802154_poll_gts(FAR struct ieee802154_radiocb_s *radiocb, FAR struct ieee802154_txdesc_s *tx_desc, FAR uint8_t *buf) { @@ -474,9 +474,9 @@ static int mac802154_txdone(FAR struct ieee802154_radiocb_s *radiocb, { mac802154_givesem(&priv->exclsem); - return -ENOMEM; + return -ENOMEM; } - + /* Copy the txdesc over and link it into our list */ memcpy(desc, tx_desc, sizeof(ieee802154_txdesc_s)); @@ -490,10 +490,10 @@ static int mac802154_txdone(FAR struct ieee802154_radiocb_s *radiocb, /* Schedule work with the work queue to process the completion further */ if (work_available(&priv->tx_work)) - { - work_queue(MAC802154_WORK, &priv->tx_work, mac802154_txdone_worker, - (FAR void *)dev, 0); - } + { + work_queue(MAC802154_WORK, &priv->tx_work, mac802154_txdone_worker, + (FAR void *)dev, 0); + } } /**************************************************************************** @@ -508,10 +508,8 @@ static int mac802154_txdone(FAR struct ieee802154_radiocb_s *radiocb, static void mac802154_txdone_worker(FAR void *arg) { - FAR struct ieee802154_privmanc_s *priv = + FAR struct ieee802154_privmanc_s *priv = (FAR struct ieee802154_privmanc_s *)arg; - - } /**************************************************************************** @@ -524,7 +522,7 @@ static void mac802154_txdone_worker(FAR void *arg) * descriptor is passed along with the iob, but it must be copied here as it * is allocated directly on the caller's stack. We simply link the frame, * copy the RX descriptor, and schedule a worker to process the frame later so - * that we do not hold up the radio. + * that we do not hold up the radio. * ****************************************************************************/ @@ -580,13 +578,12 @@ static void mac802154_rxframe_worker(FAR void *arg) { FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)arg; - + /* The radio layer is responsible for handling all ACKs and retries. If for - * some reason an ACK gets here, just throw it out */ - + * some reason an ACK gets here, just throw it out. + */ } - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/wireless/ieee802154/mac802154_device.c b/wireless/ieee802154/mac802154_device.c index 3b7dc493092..6370ff47623 100644 --- a/wireless/ieee802154/mac802154_device.c +++ b/wireless/ieee802154/mac802154_device.c @@ -461,7 +461,7 @@ static ssize_t mac802154dev_write(FAR struct file *filep, mac802154dev_givesem(&dev->md_exclsem); } - + /* Pass the request to the MAC layer */ ret = mac802154_req_data(dev->md_mac, req); diff --git a/wireless/ieee802154/mac802154_netdev.c b/wireless/ieee802154/mac802154_netdev.c index adc433aa652..18b2d6e1cd0 100644 --- a/wireless/ieee802154/mac802154_netdev.c +++ b/wireless/ieee802154/mac802154_netdev.c @@ -181,36 +181,36 @@ static void macnet_conf_get(FAR struct macnet_driver_s *priv, static void macnet_conf_gts(FAR struct macnet_driver_s *priv, FAR struct ieee802154_gts_conf_s *conf); static void macnet_conf_reset(FAR struct macnet_driver_s *priv, - FAR struct ieee802154_reset_conf_s *conf); + FAR struct ieee802154_reset_conf_s *conf); static void macnet_conf_rxenable(FAR struct macnet_driver_s *priv, - FAR struct ieee802154_rxenable_conf_s *conf); + FAR struct ieee802154_rxenable_conf_s *conf); static void macnet_conf_scan(FAR struct macnet_driver_s *priv, - FAR struct ieee802154_scan_conf_s *conf); + FAR struct ieee802154_scan_conf_s *conf); static void macnet_conf_set(FAR struct macnet_driver_s *priv, - FAR struct ieee802154_set_conf_s *conf); + FAR struct ieee802154_set_conf_s *conf); static void macnet_conf_start(FAR struct macnet_driver_s *priv, - FAR struct ieee802154_start_conf_s *conf); + FAR struct ieee802154_start_conf_s *conf); static void macnet_conf_poll(FAR struct macnet_driver_s *priv, - FAR struct ieee802154_poll_conf_s *conf); + FAR struct ieee802154_poll_conf_s *conf); /* Asynchronous event indications, replied to synchronously with responses */ static void macnet_ind_data(FAR struct macnet_driver_s *priv, - FAR struct ieee802154_data_ind_s *conf); + FAR struct ieee802154_data_ind_s *conf); static void macnet_ind_associate(FAR struct macnet_driver_s *priv, - FAR struct ieee802154_assoc_ind_s *conf); + FAR struct ieee802154_assoc_ind_s *conf); static void macnet_ind_disassociate(FAR struct macnet_driver_s *priv, - FAR struct ieee802154_disassoc_ind_s *conf); + FAR struct ieee802154_disassoc_ind_s *conf); static void macnet_ind_beaconnotify(FAR struct macnet_driver_s *priv, - FAR struct ieee802154_beaconnotify_ind_s *conf); + FAR struct ieee802154_beaconnotify_ind_s *conf); static void macnet_ind_gts(FAR struct macnet_driver_s *priv, - FAR struct ieee802154_gts_ind_s *conf); + FAR struct ieee802154_gts_ind_s *conf); static void macnet_ind_orphan(FAR struct macnet_driver_s *priv, - FAR struct ieee802154_orphan_ind_s *conf); + FAR struct ieee802154_orphan_ind_s *conf); static void macnet_ind_commstatus(FAR struct macnet_driver_s *priv, - FAR struct ieee802154_commstatus_ind_s *conf); + FAR struct ieee802154_commstatus_ind_s *conf); static void macnet_ind_syncloss(FAR struct macnet_driver_s *priv, - FAR struct ieee802154_syncloss_ind_s *conf); + FAR struct ieee802154_syncloss_ind_s *conf); /* Network interface support ************************************************/ /* Common TX logic */ @@ -1576,8 +1576,8 @@ int mac802154netdev_register(MACHANDLE mac) priv->md_cb.mc_priv = priv; maccb = &priv->md_cb.mc_cb; - maccb->mlme_notify = macdev_mlme_notify; - maccb->mcps_notify = macdev_mcps_notify; + maccb->mlme_notify = macdev_mlme_notify; + maccb->mcps_notify = macdev_mcps_notify; /* Bind the callback structure */ From 5d68eb60592518da7d7d1bee786edad669abc6cd Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 21 Apr 2017 16:23:40 -0600 Subject: [PATCH 101/183] 6loWPAN: Remove the PAN ID from the 6loWPAN data structure. This is owned by the radio driver. Rather, use an IOCTL to obtain the PAN ID from the downstream radio driver. --- include/nuttx/net/sixlowpan.h | 21 ++---- net/netdev/netdev_ioctl.c | 15 ----- net/sixlowpan/sixlowpan.h | 8 +-- net/sixlowpan/sixlowpan_framelist.c | 16 ++++- net/sixlowpan/sixlowpan_framer.c | 26 +++++--- net/sixlowpan/sixlowpan_input.c | 2 +- net/sixlowpan/sixlowpan_internal.h | 22 ++++++- net/sixlowpan/sixlowpan_send.c | 4 +- net/sixlowpan/sixlowpan_tcpsend.c | 4 +- net/sixlowpan/sixlowpan_udpsend.c | 4 +- net/sixlowpan/sixlowpan_utils.c | 37 +++++++++++ wireless/ieee802154/mac802154_loopback.c | 81 +++++++++++++++++++++++- 12 files changed, 180 insertions(+), 60 deletions(-) diff --git a/include/nuttx/net/sixlowpan.h b/include/nuttx/net/sixlowpan.h index 855948b4e8b..fd2301632d8 100644 --- a/include/nuttx/net/sixlowpan.h +++ b/include/nuttx/net/sixlowpan.h @@ -426,15 +426,12 @@ struct rimeaddr_s * this structure. In general, all fields must be set to NULL. In * addtion: * - * 1. i_panid must be set to identify the network. It may be set to 0xfff - * if the device is not associated. - * - * 2. i_dsn must be set to a random value. After that, it will be managed + * 1. i_dsn must be set to a random value. After that, it will be managed * by the network. * - * 3. i_nodeaddr must be set after the MAC is assigned an address. + * 2. i_nodeaddr must be set after the MAC is assigned an address. * - * 4. On a TX poll, the IEEE802.15.4 MAC driver should provide its driver + * 3. On a TX poll, the IEEE802.15.4 MAC driver should provide its driver * structure with i_framelist set to NULL. At the conclusion of the * poll, if there are frames to be sent, they will have been added to * the i_framelist. The non-empty frame list at the conclusion of the @@ -449,7 +446,7 @@ struct rimeaddr_s * After sending each frame, the driver must return the IOB to the pool * of free IOBs using the FROM_IOB_FREE() macro. * - * 5. When receiving data both buffers must be provided: + * 4. When receiving data both buffers must be provided: * * The IEEE802.15.4 MAC driver should receive the frame data directly * into the payload area of an IOB structure. That IOB structure may be @@ -500,16 +497,6 @@ struct ieee802154_driver_s FAR struct iob_s *i_framelist; /* Driver Configuration ***************************************************/ - /* i_panid. The PAN ID is 16-bit number that identifies the network. It - * must be unique to differentiate a network. All the nodes in the same - * network should have the same PAN ID. This value must be provided to - * the network from the IEEE802.15.4 MAC driver. - * - * If this value is 0xffff, the device is not associated. - */ - - uint16_t i_panid; - /* i_node_addr. The address assigned to this node. */ struct rimeaddr_s i_nodeaddr; diff --git a/net/netdev/netdev_ioctl.c b/net/netdev/netdev_ioctl.c index 96eff51998f..7f194d1c1a6 100644 --- a/net/netdev/netdev_ioctl.c +++ b/net/netdev/netdev_ioctl.c @@ -1301,21 +1301,6 @@ int psock_ioctl(FAR struct socket *psock, int cmd, unsigned long arg) { int ret; - /* Check if this is a valid command. In all cases, arg is a pointer that has - * been cast to unsigned long. Verify that the value of the to-be-pointer is - * non-NULL. - */ - -#ifdef CONFIG_DRIVERS_WIRELESS - if (!_SIOCVALID(cmd) && !_WLIOCVALID(cmd)) -#else - if (!_SIOCVALID(cmd)) -#endif - { - ret = -ENOTTY; - goto errout; - } - /* Verify that the psock corresponds to valid, allocated socket */ if (psock == NULL || psock->s_crefs <= 0) diff --git a/net/sixlowpan/sixlowpan.h b/net/sixlowpan/sixlowpan.h index 05ce9496c9c..fe4451c0939 100644 --- a/net/sixlowpan/sixlowpan.h +++ b/net/sixlowpan/sixlowpan.h @@ -79,7 +79,7 @@ struct sockaddr; /* Forward reference */ void sixlowpan_initialize(void); /**************************************************************************** - * Function: psock_6lowpan_tcp_send + * Name: psock_6lowpan_tcp_send * * Description: * psock_6lowpan_tcp_send() call may be used only when the TCP socket is in a @@ -107,7 +107,7 @@ ssize_t psock_6lowpan_tcp_send(FAR struct socket *psock, FAR const void *buf, #endif /**************************************************************************** - * Function: sixlowpan_tcp_send + * Name: sixlowpan_tcp_send * * Description: * TCP output comes through three different mechansims. Either from: @@ -139,7 +139,7 @@ ssize_t psock_6lowpan_tcp_send(FAR struct socket *psock, FAR const void *buf, void sixlowpan_tcp_send(FAR struct net_driver_s *dev); /**************************************************************************** - * Function: psock_6lowpan_udp_send + * Name: psock_6lowpan_udp_send * * Description: * psock_6lowpan_udp_send() call may be used with connectionlesss UDP @@ -167,7 +167,7 @@ ssize_t psock_6lowpan_udp_send(FAR struct socket *psock, FAR const void *buf, #endif /**************************************************************************** - * Function: psock_6lowpan_udp_sendto + * Name: psock_6lowpan_udp_sendto * * Description: * If sendto() is used on a connection-mode (SOCK_STREAM, SOCK_SEQPACKET) diff --git a/net/sixlowpan/sixlowpan_framelist.c b/net/sixlowpan/sixlowpan_framelist.c index ee9487a101d..e392c022988 100644 --- a/net/sixlowpan/sixlowpan_framelist.c +++ b/net/sixlowpan/sixlowpan_framelist.c @@ -217,6 +217,7 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, struct rimeaddr_s bcastmac; uint16_t pktlen; uint16_t paysize; + uint16_t dest_panid; #ifdef CONFIG_NET_6LOWPAN_FRAG uint16_t outlen = 0; #endif @@ -286,9 +287,18 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, rimeaddr_copy(&g_pktaddrs[PACKETBUF_ADDR_SENDER], &ieee->i_nodeaddr); rimeaddr_copy(&g_pktaddrs[PACKETBUF_ADDR_RECEIVER], destmac); + /* Get the destination PAN ID. + * + * REVISIT: For now I am assuming that the source and destination + * PAN IDs are the same. + */ + + dest_panid = 0xffff; + (void)sixlowpan_src_panid(ieee, &dest_panid); + /* Pre-calculate frame header length. */ - framer_hdrlen = sixlowpan_send_hdrlen(ieee, ieee->i_panid); + framer_hdrlen = sixlowpan_send_hdrlen(ieee, dest_panid); if (framer_hdrlen < 0) { /* Failed to determine the size of the header failed. */ @@ -349,7 +359,7 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, /* Create 1st Fragment */ /* Add the frame header using the pre-allocated IOB. */ - verify = sixlowpan_framecreate(ieee, iob, ieee->i_panid); + verify = sixlowpan_framecreate(ieee, iob, dest_panid); DEBUGASSERT(verify == framer_hdrlen); UNUSED(verify); @@ -513,7 +523,7 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, /* Add the frame header to the preallocated IOB. */ - verify = sixlowpan_framecreate(ieee, iob, ieee->i_panid); + verify = sixlowpan_framecreate(ieee, iob, dest_panid); DEBUGASSERT(verify == framer_hdrlen); UNUSED(verify); diff --git a/net/sixlowpan/sixlowpan_framer.c b/net/sixlowpan/sixlowpan_framer.c index 66f8a1c3fb6..4ec877d2d5c 100644 --- a/net/sixlowpan/sixlowpan_framer.c +++ b/net/sixlowpan/sixlowpan_framer.c @@ -82,7 +82,7 @@ struct field_length_s ****************************************************************************/ /**************************************************************************** - * Function: sixlowpan_addrlen + * Name: sixlowpan_addrlen * * Description: * Return the address length associated with a 2-bit address mode @@ -109,7 +109,7 @@ static inline uint8_t sixlowpan_addrlen(uint8_t addrmode) } /**************************************************************************** - * Function: sixlowpan_addrnull + * Name: sixlowpan_addrnull * * Description: * If the output address is NULL in the Rime buf, then it is broadcast @@ -140,7 +140,7 @@ static bool sixlowpan_addrnull(FAR uint8_t *addr) /**************************************************************************** - * Function: sixlowpan_fieldlengths + * Name: sixlowpan_fieldlengths * * Description: * Return the lengths associated fields of the IEEE802.15.4 header. @@ -228,7 +228,7 @@ static void sixlowpan_fieldlengths(FAR struct frame802154_s *finfo, } /**************************************************************************** - * Function: sixlowpan_fieldlengths + * Name: sixlowpan_fieldlengths * * Description: * Return the lengths associated fields of the IEEE802.15.4 header. @@ -249,7 +249,7 @@ static int sixlowpan_flen_hdrlen(FAR const struct field_length_s *flen) } /**************************************************************************** - * Function: sixlowpan_802154_hdrlen + * Name: sixlowpan_802154_hdrlen * * Description: * Calculates the length of the frame header. This function is meant to @@ -272,7 +272,7 @@ static int sixlowpan_802154_hdrlen(FAR struct frame802154_s *finfo) } /**************************************************************************** - * Function: sixlowpan_setup_params + * Name: sixlowpan_setup_params * * Description: * Configure frame parmeters structure. @@ -293,6 +293,7 @@ static void sixlowpan_setup_params(FAR struct ieee802154_driver_s *ieee, uint16_t dest_panid, FAR struct frame802154_s *params) { + uint16_t src_panid; bool rcvrnull; /* Initialize all prameters to all zero */ @@ -331,9 +332,14 @@ static void sixlowpan_setup_params(FAR struct ieee802154_driver_s *ieee, } /* Complete the addressing fields. */ + /* Get the source PAN ID from the IEEE802.15.4 radio driver */ + + src_panid = 0xffff; + (void)sixlowpan_src_panid(ieee, &src_panid); + /* Set the source and destination PAN ID. */ - params->src_pid = ieee->i_panid; + params->src_pid = src_panid; params->dest_pid = dest_panid; /* If the output address is NULL in the Rime buf, then it is broadcast @@ -382,7 +388,7 @@ static void sixlowpan_setup_params(FAR struct ieee802154_driver_s *ieee, ****************************************************************************/ /**************************************************************************** - * Function: sixlowpan_send_hdrlen + * Name: sixlowpan_send_hdrlen * * Description: * This function is before the first frame has been sent in order to @@ -415,7 +421,7 @@ int sixlowpan_send_hdrlen(FAR struct ieee802154_driver_s *ieee, } /**************************************************************************** - * Function: sixlowpan_802154_framecreate + * Name: sixlowpan_802154_framecreate * * Description: * Creates a frame for transmission over the air. This function is meant @@ -514,7 +520,7 @@ int sixlowpan_802154_framecreate(FAR struct frame802154_s *finfo, } /**************************************************************************** - * Function: sixlowpan_framecreate + * Name: sixlowpan_framecreate * * Description: * This function is called after eiether (1) the IEEE802.15.4 MAC driver diff --git a/net/sixlowpan/sixlowpan_input.c b/net/sixlowpan/sixlowpan_input.c index bfa74da13a4..bccd97677b7 100644 --- a/net/sixlowpan/sixlowpan_input.c +++ b/net/sixlowpan/sixlowpan_input.c @@ -680,7 +680,7 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, } /**************************************************************************** - * Function: sixlowpan_dispatch + * Name: sixlowpan_dispatch * * Description: * Inject the packet in d_buf into the network for normal packet processing. diff --git a/net/sixlowpan/sixlowpan_internal.h b/net/sixlowpan/sixlowpan_internal.h index 392bc376b78..08b2fc445cb 100644 --- a/net/sixlowpan/sixlowpan_internal.h +++ b/net/sixlowpan/sixlowpan_internal.h @@ -344,7 +344,7 @@ int sixlowpan_send(FAR struct net_driver_s *dev, uint16_t timeout); /**************************************************************************** - * Function: sixlowpan_send_hdrlen + * Name: sixlowpan_send_hdrlen * * Description: * This function is before the first frame has been sent in order to @@ -366,7 +366,7 @@ int sixlowpan_send_hdrlen(FAR struct ieee802154_driver_s *ieee, uint16_t dest_panid); /**************************************************************************** - * Function: sixlowpan_framecreate + * Name: sixlowpan_framecreate * * Description: * This function is called after the IEEE802.15.4 MAC driver polls for @@ -606,5 +606,23 @@ void sixlowpan_rimefromip(const net_ipv6addr_t ipaddr, bool sixlowpan_ismacbased(const net_ipv6addr_t ipaddr, FAR const struct rimeaddr_s *rime); +/**************************************************************************** + * Name: sixlowpan_src_panid + * + * Description: + * Get the source PAN ID from the IEEE802.15.4 radio. + * + * Input parameters: + * ieee - A reference IEEE802.15.4 MAC network device structure. + * panid - The location in which to return the PAN ID. 0xfff may be + * returned if the device is not associated. + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int sixlowpan_src_panid(FAR struct ieee802154_driver_s *ieee, + FAR uint16_t *panid); #endif /* CONFIG_NET_6LOWPAN */ #endif /* _NET_SIXLOWPAN_SIXLOWPAN_INTERNAL_H */ diff --git a/net/sixlowpan/sixlowpan_send.c b/net/sixlowpan/sixlowpan_send.c index 1dd8f86c667..3ad68554aec 100644 --- a/net/sixlowpan/sixlowpan_send.c +++ b/net/sixlowpan/sixlowpan_send.c @@ -93,7 +93,7 @@ struct sixlowpan_send_s ****************************************************************************/ /**************************************************************************** - * Function: send_timeout + * Name: send_timeout * * Description: * Check for send timeout. @@ -134,7 +134,7 @@ static inline bool send_timeout(FAR struct sixlowpan_send_s *sinfo) } /**************************************************************************** - * Function: send_interrupt + * Name: send_interrupt * * Description: * This function is called from the interrupt level to perform the actual diff --git a/net/sixlowpan/sixlowpan_tcpsend.c b/net/sixlowpan/sixlowpan_tcpsend.c index 3ee39e72ed6..2bb6c49130c 100644 --- a/net/sixlowpan/sixlowpan_tcpsend.c +++ b/net/sixlowpan/sixlowpan_tcpsend.c @@ -136,7 +136,7 @@ static uint16_t sixlowpan_tcp_chksum(FAR struct ipv6tcp_hdr_s *ipv6tcp, ****************************************************************************/ /**************************************************************************** - * Function: psock_6lowpan_tcp_send + * Name: psock_6lowpan_tcp_send * * Description: * psock_6lowpan_tcp_send() call may be used only when the TCP socket is in a @@ -348,7 +348,7 @@ ssize_t psock_6lowpan_tcp_send(FAR struct socket *psock, FAR const void *buf, } /**************************************************************************** - * Function: sixlowpan_tcp_send + * Name: sixlowpan_tcp_send * * Description: * TCP output comes through three different mechansims. Either from: diff --git a/net/sixlowpan/sixlowpan_udpsend.c b/net/sixlowpan/sixlowpan_udpsend.c index f8f62e528b1..a29197eec70 100644 --- a/net/sixlowpan/sixlowpan_udpsend.c +++ b/net/sixlowpan/sixlowpan_udpsend.c @@ -125,7 +125,7 @@ static uint16_t sixlowpan_udp_chksum(FAR struct ipv6udp_hdr_s *ipv6udp, ****************************************************************************/ /**************************************************************************** - * Function: psock_6lowpan_udp_sendto + * Name: psock_6lowpan_udp_sendto * * Description: * If sendto() is used on a connection-mode (SOCK_STREAM, SOCK_SEQPACKET) @@ -323,7 +323,7 @@ ssize_t psock_6lowpan_udp_sendto(FAR struct socket *psock, } /**************************************************************************** - * Function: psock_6lowpan_udp_send + * Name: psock_6lowpan_udp_send * * Description: * psock_6lowpan_udp_send() call may be used with connectionlesss UDP diff --git a/net/sixlowpan/sixlowpan_utils.c b/net/sixlowpan/sixlowpan_utils.c index dcda6be652d..7e1a6ac2eed 100644 --- a/net/sixlowpan/sixlowpan_utils.c +++ b/net/sixlowpan/sixlowpan_utils.c @@ -54,8 +54,10 @@ #include #include #include +#include #include +#include #include "sixlowpan/sixlowpan_internal.h" @@ -156,4 +158,39 @@ bool sixlowpan_ismacbased(const net_ipv6addr_t ipaddr, #endif } +/**************************************************************************** + * Name: sixlowpan_src_panid + * + * Description: + * Get the source PAN ID from the IEEE802.15.4 radio. + * + * Input parameters: + * ieee - A reference IEEE802.15.4 MAC network device structure. + * panid - The location in which to return the PAN ID. 0xfff may be + * returned if the device is not associated. + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int sixlowpan_src_panid(FAR struct ieee802154_driver_s *ieee, + FAR uint16_t *panid) +{ + FAR struct net_driver_s *dev = &ieee->i_dev; + struct ieee802154_netradio_s arg; + int ret; + + memcpy(arg.ifr_name, ieee->i_dev.d_ifname, IFNAMSIZ); + ret = dev->d_ioctl(dev, PHY802154IOC_GET_PANID, (unsigned long)((uintptr_t)&arg)); + if (ret < 0) + { + wlerr("ERROR: PHY802154IOC_GET_PANID failed: %d\n", ret); + return ret; + } + + *panid = arg.u.panid; + return OK; +} + #endif /* CONFIG_NET_6LOWPAN */ diff --git a/wireless/ieee802154/mac802154_loopback.c b/wireless/ieee802154/mac802154_loopback.c index b3c0c4cdf5b..13243baed07 100644 --- a/wireless/ieee802154/mac802154_loopback.c +++ b/wireless/ieee802154/mac802154_loopback.c @@ -54,6 +54,7 @@ #include #include #include +#include #include #include "mac802154.h" @@ -94,6 +95,7 @@ struct lo_driver_s { bool lo_bifup; /* true:ifup false:ifdown */ bool lo_txdone; /* One RX packet was looped back */ + uint16_t lo_panid; /* Fake PAN ID for testing */ WDOG_ID lo_polldog; /* TX poll timer */ struct work_s lo_work; /* For deferring poll work to the work queue */ @@ -131,6 +133,10 @@ static int lo_addmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac); static int lo_rmmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac); #endif #endif +#ifdef CONFIG_NETDEV_IOCTL +static int lo_ioctl(FAR struct net_driver_s *dev, int cmd, + unsigned long arg); +#endif /**************************************************************************** * Private Functions @@ -371,11 +377,11 @@ static int lo_ifup(FAR struct net_driver_s *dev) priv->lo_ieee.i_nodeaddr.u8[2], priv->lo_ieee.i_nodeaddr.u8[3], priv->lo_ieee.i_nodeaddr.u8[4], priv->lo_ieee.i_nodeaddr.u8[5], priv->lo_ieee.i_nodeaddr.u8[6], priv->lo_ieee.i_nodeaddr.u8[7], - priv->lo_ieee.i_panid); + priv->lo_panid); #else ninfo(" Node: %02x:%02x PANID=%04x\n", priv->lo_ieee.i_nodeaddr.u8[0], priv->lo_ieee.i_nodeaddr.u8[1], - priv->lo_ieee.i_panid); + priv->lo_panid); #endif /* Set and activate a timer process */ @@ -570,6 +576,74 @@ static int lo_rmmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac) } #endif +/**************************************************************************** + * Name: macnet_ioctl + * + * Description: + * Handle network IOCTL commands directed to this device. + * + * Parameters: + * dev - Reference to the NuttX driver state structure + * cmd - The IOCTL command + * arg - The argument for the IOCTL command + * + * Returned Value: + * OK on success; Negated errno on failure. + * + * Assumptions: + * + ****************************************************************************/ + +#ifdef CONFIG_NETDEV_IOCTL +static int lo_ioctl(FAR struct net_driver_s *dev, int cmd, + unsigned long arg) +{ + FAR struct lo_driver_s *priv = (FAR struct lo_driver_s *)dev->d_private; + int ret = -ENOTTY; + +#if 0 + /* Check for IOCTLs aimed at the IEEE802.15.4 MAC layer */ + + if (_MAC802154IOCVALID(cmd)) + { + FAR struct ieee802154_netmac_s *netmac = + (FAR struct ieee802154_netmac_s *)arg; + } + + /* No, check for IOCTLs aimed at the IEEE802.15.4 radio layer */ + + else +#endif + if (_PHY802154IOCVALID(cmd)) + { + FAR struct ieee802154_netradio_s *netradio = + (FAR struct ieee802154_netradio_s *)arg; + + /* Pick out radio settings of interest. There is, of course, no + * radio in this loopback. + */ + + switch (cmd) + { + case PHY802154IOC_SET_PANID: + priv->lo_panid = netradio->u.panid; + ret = OK; + break; + + case PHY802154IOC_GET_PANID: + netradio->u.panid = priv->lo_panid; + ret = OK; + break; + + default: + break; + } + } + + return ret; +} +#endif + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -612,6 +686,9 @@ int ieee8021514_loopback(void) #ifdef CONFIG_NET_IGMP dev->d_addmac = lo_addmac; /* Add multicast MAC address */ dev->d_rmmac = lo_rmmac; /* Remove multicast MAC address */ +#endif +#ifdef CONFIG_NETDEV_IOCTL + dev->d_ioctl = lo_ioctl; /* Handle network IOCTL commands */ #endif dev->d_buf = g_iobuffer; /* Attach the IO buffer */ dev->d_private = (FAR void *)priv; /* Used to recover private state from dev */ From a253e420f29a2f9a63e52e419dfd29b5042ef904 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 21 Apr 2017 17:38:34 -0600 Subject: [PATCH 102/183] MAC IOCTLs: Eliminate a couple 'To be determined.' --- include/nuttx/wireless/ieee802154/ieee802154_mac.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/nuttx/wireless/ieee802154/ieee802154_mac.h b/include/nuttx/wireless/ieee802154/ieee802154_mac.h index 2f78ec443f1..95ccf10ecd2 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_mac.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_mac.h @@ -1327,8 +1327,8 @@ union ieee802154_mcps_notify_u union ieee802154_macarg_u { - /* To be determined */ /* MAC802154IOC_MCPS_REGISTER */ - /* To be determined */ /* MAC802154IOC_MLME_REGISTER */ + union ieee802154_mcps_notify_u mcpsnotify; /* MAC802154IOC_MCPS_REGISTER */ + union ieee802154_mlme_notify_u mlmenotify; /* MAC802154IOC_MLME_REGISTER */ struct ieee802154_assoc_req_s assocreq; /* MAC802154IOC_MLME_ASSOC_REQUEST */ struct ieee802154_assoc_resp_s assocresp; /* MAC802154IOC_MLME_ASSOC_RESPONSE */ struct ieee802154_disassoc_req_s disassocreq; /* MAC802154IOC_MLME_DISASSOC_REQUEST */ From d884958a2ea9eb8f08ca9b0b7cb5d7ec7a215f8c Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 21 Apr 2017 18:37:07 -0600 Subject: [PATCH 103/183] Back out most of ebf05cb9f56278b03965f86ea8a1c33634cbfec5 --- include/nuttx/wireless/wireless.h | 44 ------------------------ net/netdev/netdev_ioctl.c | 57 ------------------------------- 2 files changed, 101 deletions(-) diff --git a/include/nuttx/wireless/wireless.h b/include/nuttx/wireless/wireless.h index a9abf706b60..cc5df1e309d 100644 --- a/include/nuttx/wireless/wireless.h +++ b/include/nuttx/wireless/wireless.h @@ -63,7 +63,6 @@ * interface. */ -/* IEEE802.11 */ /* Wireless identification */ #define SIOCSIWCOMMIT _WLIOC(0x0001) /* Commit pending changes to driver */ @@ -154,19 +153,6 @@ #define SIOCSIWPMKSA _WLIOC(0x0032) /* PMKSA cache operation */ -/* IEEE802.15.4 6loWPAN - * - * IEEE802.15.4 IOCTLs may be directed at one of three layers: - * - * 1. To the 6loWPAN network layer, as documented here, - * 2. To the IEEE802.15.4 MAC layer, as documented in, - * include/nuttx/wireless/ieee802154/ioeee802154_mac.h, or to - * 3. To the IEEE802.15.4 radio device layer, as documented in, - * include/nuttx/wireless/ieee802154/ioeee802154_radio.h. - * - * This is a placeholder; no 6LoWPAN IOCTL commands have been defined. - */ - #define WL_FIRSTCHAR 0x0033 #define WL_NNETCMDS 0x0032 @@ -369,35 +355,5 @@ struct iw_event union iwreq_data u; /* Fixed IOCTL payload */ }; -/* 6loWPAN */ -/* This structure is used with the SIOCSWPANID IOCTL command to select the - * PAN ID to join. - */ - -struct sixlowpan_panid_s -{ - uint16_t panid; /* The PAN ID to join */ -}; - -/* This union defines the data payload of an 6loWPAN or SIOCGWPANID ioctl - * command and is used in struct sixlowpan_req_s below. - */ - -union sixlowpan_data -{ - struct sixlowpan_panid_s panid; /* PAN ID to join */ -}; - -/* This is the structure used to exchange data in wireless IOCTLs. This - * structure is the same as 'struct ifreq', but defined for use with - * 6loWPAN IOCTLs. - */ - -struct sixlowpan_req_s -{ - char ifr_name[IFNAMSIZ]; /* Interface name, e.g. "wpan0" */ - union sixlowpan_data u; /* Data payload */ -}; - #endif /* CONFIG_DRIVERS_WIRELESS */ #endif /* __INCLUDE_NUTTX_WIRELESS_WIRELESS_H */ diff --git a/net/netdev/netdev_ioctl.c b/net/netdev/netdev_ioctl.c index 7f194d1c1a6..41014ce5efe 100644 --- a/net/netdev/netdev_ioctl.c +++ b/net/netdev/netdev_ioctl.c @@ -326,51 +326,6 @@ static void ioctl_set_ipv6addr(FAR net_ipv6addr_t outaddr, } #endif -/**************************************************************************** - * Name: netdev_sixlowpan_ioctl - * - * Description: - * Perform 6loWPAN network device specific operations. - * - * Parameters: - * psock Socket structure - * dev Ethernet driver device structure - * cmd The ioctl command - * req The argument of the ioctl cmd - * - * Return: - * >=0 on success (positive non-zero values are cmd-specific) - * Negated errno returned on failure. - * - ****************************************************************************/ - -#if defined(CONFIG_NETDEV_IOCTL) && defined(CONFIG_NET_6LOWPAN) -static int netdev_sixlowpan_ioctl(FAR struct socket *psock, int cmd, - FAR struct sixlowpan_req_s *req) -{ -#if 0 /* None yet defined */ - FAR struct ieee802154_driver_s *ieee; - int ret = -ENOTTY; - - /* Verify that this is a valid wireless network IOCTL command */ - - if (_WLIOCVALID(cmd) && (unsigned)_IOC_NR(cmd) <= WL_NNETCMDS) - { - switch (cmd) - { - - default: - return -ENOTTY; - } - } - - return ret; -#else - return -ENOTTY; -#endif -} -#endif - /**************************************************************************** * Name: netdev_iee802154_ioctl * @@ -1313,18 +1268,6 @@ int psock_ioctl(FAR struct socket *psock, int cmd, unsigned long arg) ret = netdev_ifr_ioctl(psock, cmd, (FAR struct ifreq *)((uintptr_t)arg)); -#if defined(CONFIG_NETDEV_IOCTL) && defined(CONFIG_NET_6LOWPAN) - /* Check for a 6loWPAN network command */ - - if (ret == -ENOTTY) - { - FAR struct sixlowpan_req_s *slpreq; - - slpreq = (FAR struct sixlowpan_req_s *)((uintptr_t)arg); - ret = netdev_sixlowpan_ioctl(psock, cmd, slpreq); - } -#endif - #if defined(CONFIG_NETDEV_IOCTL) && defined(CONFIG_NETDEV_WIRELESS_IOCTL) /* Check for a wireless network command */ From 9e760dcf6aed3ab2d1053e22d1116fcac8951e41 Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Wed, 26 Apr 2017 11:30:54 -0400 Subject: [PATCH 104/183] wireless/ieee802154: Lots of little fixes and changes to get everything to build --- configs/clicker2-stm32/src/stm32_mrf24j40.c | 4 - drivers/wireless/ieee802154/mrf24j40.c | 60 +- .../wireless/ieee802154/ieee802154_mac.h | 51 +- .../wireless/ieee802154/ieee802154_radio.h | 37 +- wireless/ieee802154/Kconfig | 35 +- wireless/ieee802154/mac802154.c | 2548 +++++++++-------- wireless/ieee802154/mac802154.h | 34 +- wireless/ieee802154/mac802154_device.c | 24 +- wireless/ieee802154/radio802154_device.c | 6 +- 9 files changed, 1418 insertions(+), 1381 deletions(-) diff --git a/configs/clicker2-stm32/src/stm32_mrf24j40.c b/configs/clicker2-stm32/src/stm32_mrf24j40.c index e1b664f28b1..18751e27dc7 100644 --- a/configs/clicker2-stm32/src/stm32_mrf24j40.c +++ b/configs/clicker2-stm32/src/stm32_mrf24j40.c @@ -67,10 +67,6 @@ # error Wireless support requires CONFIG_DRIVERS_WIRELESS #endif -#ifndef CONFIG_IEEE802154_DEV -# error IEEE802.15.4 radio character device required (CONFIG_IEEE802154_DEV) -#endif - #if !defined(CONFIG_CLICKER2_STM32_MB1_BEE) && \ !defined(CONFIG_CLICKER2_STM32_MB2_BEE) # error Only the Mikroe BEE board is supported diff --git a/drivers/wireless/ieee802154/mrf24j40.c b/drivers/wireless/ieee802154/mrf24j40.c index 1e07d1126b7..b819ed7d991 100644 --- a/drivers/wireless/ieee802154/mrf24j40.c +++ b/drivers/wireless/ieee802154/mrf24j40.c @@ -56,6 +56,8 @@ #include #include +#include + #include #include #include @@ -221,8 +223,7 @@ static int mrf24j40_bind(FAR struct ieee802154_radio_s *radio, FAR struct ieee802154_radiocb_s *radiocb); static int mrf24j40_ioctl(FAR struct ieee802154_radio_s *radio, int cmd, unsigned long arg); -static int mrf24j40_rxenable(FAR struct ieee802154_radio_s *radio, - bool state, FAR struct ieee802154_packet_s *packet); +static int mrf24j40_rxenable(FAR struct ieee802154_radio_s *radio); static int mrf24j40_transmit(FAR struct ieee802154_radio_s *radio, FAR uint8_t *buf, uint16_t buf_len); static int mrf24j40_txnotify_csma(FAR struct ieee802154_radio_s *radio); @@ -324,7 +325,7 @@ static int mrf24j40_txnotify_csma(FAR struct ieee802154_radio_s *radio) static void mrf24j40_dopoll_csma(FAR void *arg) { FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)arg; - int ret = 0; + int len = 0; /* Need to get exlusive access to the device so that we can use the copy * buffer. @@ -338,9 +339,9 @@ static void mrf24j40_dopoll_csma(FAR void *arg) { /* need to somehow allow for a handle to be passed */ - ret = dev->radiocb->poll_csma(dev->radiocb, &dev->csma_desc.pub, + len = dev->radiocb->poll_csma(dev->radiocb, &dev->csma_desc.pub, &dev->tx_buf[0]); - if (ret > 0) + if (len > 0) { /* Now the txdesc is in use */ @@ -348,8 +349,7 @@ static void mrf24j40_dopoll_csma(FAR void *arg) /* Setup the transaction on the device in the CSMA FIFO */ - mrf24j40_csma_setup(dev, &dev->tx_buf[0], - dev->csma_desc.pub.psdu_length); + mrf24j40_csma_setup(dev, &dev->tx_buf[0], len); } } @@ -419,7 +419,7 @@ static void mrf24j40_dopoll_gts(FAR void *arg) { FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)arg; int gts = 0; - int ret = 0; + int len = 0; /* Need to get exclusive access to the device so that we can use the copy * buffer. @@ -431,9 +431,9 @@ static void mrf24j40_dopoll_gts(FAR void *arg) { if (!dev->gts_desc[gts].busy) { - ret = dev->radiocb->poll_gts(dev->radiocb, &dev->gts_desc[gts].pub, + len = dev->radiocb->poll_gts(dev->radiocb, &dev->gts_desc[gts].pub, &dev->tx_buf[0]); - if (ret > 0) + if (len > 0) { /* Now the txdesc is in use */ @@ -441,8 +441,7 @@ static void mrf24j40_dopoll_gts(FAR void *arg) /* Setup the transaction on the device in the open GTS FIFO */ - mrf24j40_gts_setup(dev, gts, &dev->tx_buf[0], - dev->gts_desc[gts].pub.psdu_length); + mrf24j40_gts_setup(dev, gts, &dev->tx_buf[0], len); } } } @@ -1583,27 +1582,18 @@ static void mrf24j40_irqwork_txgts(FAR struct mrf24j40_radio_s *dev, * ****************************************************************************/ -static int mrf24j40_rxenable(FAR struct ieee802154_radio_s *radio, bool state, - FAR struct ieee802154_packet_s *packet) +static int mrf24j40_rxenable(FAR struct ieee802154_radio_s *radio) { FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)radio; uint8_t reg; - if (state) - { - mrf24j40_pacontrol(dev, MRF24J40_PA_AUTO); - radio->rxbuf = packet; + mrf24j40_pacontrol(dev, MRF24J40_PA_AUTO); - /* Enable rx int */ + /* Enable rx int */ - reg = mrf24j40_getreg(dev->spi, MRF24J40_INTCON); - reg &= ~MRF24J40_INTCON_RXIE; - mrf24j40_setreg(dev->spi, MRF24J40_INTCON, reg); - } - else - { - radio->rxbuf = NULL; - } + reg = mrf24j40_getreg(dev->spi, MRF24J40_INTCON); + reg &= ~MRF24J40_INTCON_RXIE; + mrf24j40_setreg(dev->spi, MRF24J40_INTCON, reg); return OK; } @@ -1619,7 +1609,7 @@ static int mrf24j40_rxenable(FAR struct ieee802154_radio_s *radio, bool state, static void mrf24j40_irqwork_rx(FAR struct mrf24j40_radio_s *dev) { FAR struct iob_s *iob; - struct ieee802154_txdesc_s rxdesc; + struct ieee802154_rxdesc_s rxdesc; uint32_t addr; uint32_t index; uint8_t reg; @@ -1636,7 +1626,6 @@ static void mrf24j40_irqwork_rx(FAR struct mrf24j40_radio_s *dev) mrf24j40_setreg(dev->spi, MRF24J40_BBREG1, MRF24J40_BBREG1_RXDECINV); - /* Allocate an IOB to put the packet in */ iob = iob_alloc(true); @@ -1675,7 +1664,8 @@ static void mrf24j40_irqwork_rx(FAR struct mrf24j40_radio_s *dev) /* Callback the receiver in the next highest layer */ - dev->radiocb->rx_frame(dev->radiocb, &rxdesc, iob); + dev->radiocb->rxframe(dev->radiocb, + (FAR const struct ieee802154_rxdesc_s *)&rxdesc, iob); /* Enable reception of next packet by flushing the fifo. * This is an MRF24J40 errata (no. 1). @@ -1831,16 +1821,6 @@ FAR struct ieee802154_radio_s *mrf24j40_init(FAR struct spi_dev_s *spi, dev->radio.ops = &mrf24j40_devops; - /* Initialize semaphores */ - - sem_init(&dev->radio.rxsem, 0, 0); - - /* These semaphores are all used for signaling and, hence, should - * not have priority inheritance enabled. - */ - - sem_setprotocol(&dev->radio.rxsem, SEM_PRIO_NONE); - dev->lower = lower; dev->spi = spi; diff --git a/include/nuttx/wireless/ieee802154/ieee802154_mac.h b/include/nuttx/wireless/ieee802154/ieee802154_mac.h index 95ccf10ecd2..e1aca5de757 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_mac.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_mac.h @@ -55,6 +55,8 @@ # include #endif +#include + #include /**************************************************************************** @@ -553,45 +555,7 @@ struct ieee802154_data_req_s struct ieee802154_data_conf_s { - uint8_t msdu_handle; /* Handle assoc. with MSDU */ - - /* The time, in symbols, at which the data were transmitted */ - - uint32_t timestamp; - - enum ieee802154_status_e status; /* The status of the MSDU transmission */ - -#ifdef CONFIG_IEEE802154_RANGING - bool rng_rcvd; /* Ranging indicated by MSDU */ - - /* A count of the time units corresponding to an RMARKER at the antenna at - * the beginning of the ranging exchange - */ - - uint32_t rng_counter_start; - - /* A count of the time units corresponding to an RMARKER at the antenna at - * end of the ranging exchange - */ - - uint32_t rng_counter_stop; - - /* A count of the time units in a message exchange over which the tracking - * offset was measured - */ - - uint34_t rng_tracking_interval; - - /* A count of the time units slipped or advanced by the radio tracking - * system over the course of the entire tracking interval - */ - - uint32_t rng_offset; - - /* The Figure of Merit (FoM) characterizing the ranging measurement */ - - uint8_t rng_fom; -#endif + IEEE802154_TXDESC_FIELDS }; /***************************************************************************** @@ -1111,7 +1075,6 @@ struct ieee802154_rxenable_conf_s struct ieee802154_scan_req_s { - enum ieee802154_scantype_e type; uint8_t duration; uint8_t ch_page; @@ -1406,13 +1369,13 @@ enum ieee802154_macnotify_e struct ieee802154_maccb_s { - CODE void (*mlme_notify) (FAR struct ieee802154_maccb_s *maccb, + CODE void (*mlme_notify) (FAR const struct ieee802154_maccb_s *maccb, enum ieee802154_macnotify_e notif, - FAR union ieee802154_mlme_notify_u *arg); + FAR const union ieee802154_mlme_notify_u *arg); - CODE void (*mcps_notify) (FAR struct ieee802154_maccb_s *maccb, + CODE void (*mcps_notify) (FAR const struct ieee802154_maccb_s *maccb, enum ieee802154_macnotify_e notif, - FAR union ieee802154_mcps_notify_u *arg); + FAR const union ieee802154_mcps_notify_u *arg); }; #ifdef __cplusplus diff --git a/include/nuttx/wireless/ieee802154/ieee802154_radio.h b/include/nuttx/wireless/ieee802154/ieee802154_radio.h index 58748b267a2..54e08969d9a 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_radio.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_radio.h @@ -158,12 +158,30 @@ struct ieee802154_netradio_s /* IEEE802.15.4 Radio Interface Operations **********************************/ +/* This is a work-around to allow the MAC upper layer have a struct with + * identical members but with a different name. */ + +#ifdef CONFIG_IEEE802154_RANGING +#define IEEE802154_TXDESC_FIELDS \ + uint8_t handle; \ + uint32_t timestamp; \ + uint8_t status; +#else +#define IEEE802154_TXDESC_FIELDS \ + uint8_t handle; \ + uint32_t timestamp; \ + uint8_t status; + bool rng_rcvd; \ + uint32_t rng_counter_start; \ + uint32_t rng_counter_stop; \ + uint32_t rng_tracking_interval; \ + uint32_t rng_offset;\ + uint8_t rng_fom; +#endif + struct ieee802154_txdesc_s { - uint8_t psdu_handle; /* The psdu handle identifying the transaction */ - uint16_t psdu_length; /* The length of the PSDU */ - uint8_t status; /* The status of the transaction. This is set by the - * radio layer prior to calling txdone_csma */ + IEEE802154_TXDESC_FIELDS /* TODO: Add slotting information for GTS transactions */ }; @@ -176,13 +194,13 @@ struct ieee802154_rxdesc_s struct ieee802154_radiocb_s { - CODE int (*poll_csma) (FAR struct ieee802154_radiocb_s *radiocb, + CODE int (*poll_csma) (FAR const struct ieee802154_radiocb_s *radiocb, FAR struct ieee802154_txdesc_s *tx_desc, FAR uint8_t *buf); - CODE int (*poll_gts) (FAR struct ieee802154_radiocb_s *radiocb, + CODE int (*poll_gts) (FAR const struct ieee802154_radiocb_s *radiocb, FAR struct ieee802154_txdesc_s *tx_desc, FAR uint8_t *buf); - CODE int (*txdone) (FAR struct ieee802154_radiocb_s *radiocb, + CODE void (*txdone) (FAR const struct ieee802154_radiocb_s *radiocb, FAR const struct ieee802154_txdesc_s *tx_desc); - CODE int (*rx_frame) (FAR struct ieee802154_radiocb_s *radiocb, + CODE void (*rxframe) (FAR const struct ieee802154_radiocb_s *radiocb, FAR const struct ieee8021254_rxdesc_s *rx_desc, FAR struct iob_s *frame); }; @@ -195,8 +213,7 @@ struct ieee802154_radioops_s FAR struct ieee802154_radiocb_s *radiocb); CODE int (*ioctl)(FAR struct ieee802154_radio_s *radio, int cmd, unsigned long arg); - CODE int (*rxenable)(FAR struct ieee802154_radio_s *radio, bool state, - FAR struct ieee802154_packet_s *packet); + CODE int (*rxenable)(FAR struct ieee802154_radio_s *radio); CODE int (*txnotify_csma)(FAR struct ieee802154_radio_s *radio); CODE int (*txnotify_gts)(FAR struct ieee802154_radio_s *radio); }; diff --git a/wireless/ieee802154/Kconfig b/wireless/ieee802154/Kconfig index 64b9e66e91a..c1f7f828fa8 100644 --- a/wireless/ieee802154/Kconfig +++ b/wireless/ieee802154/Kconfig @@ -6,13 +6,14 @@ config WIRELESS_IEEE802154 bool "IEEE 802.15.4 Wireless Support" default n + select DRIVERS_IOB ---help--- Enables support for the IEEE 802.14.5 Wireless library. if WIRELESS_IEEE802154 -config IEEE802154_MAC - bool "Generic Media Access Control layer for 802.15.4 radios" +menuconfig IEEE802154_MAC + bool "Generic Media Access Control (MAC) layer for 802.15.4 radios" default n depends on WIRELESS_IEEE802154 ---help--- @@ -21,6 +22,8 @@ config IEEE802154_MAC such as 6lowpan. It is not required to use 802.15.4 radios, but is strongly suggested to ensure exchange of valid frames. +if IEEE802154_MAC + config IEEE802154_MAC_DEV bool "Character driver for IEEE 802.15.4 MAC layer" default n @@ -29,6 +32,34 @@ config IEEE802154_MAC_DEV Enable the device driver to expose the IEEE 802.15.4 MAC layer access to user space as IOCTLs +choice + prompt "IEEE 802.15.4 work queue" + default MAC802154_LPWORK if SCHED_LPWORK + default MAC802154_HPWORK if !SCHED_LPWORK && SCHED_HPWORK + depends on SCHED_WORKQUEUE + ---help--- + Work queue support is required to use the IEEE 802.15.4 MAC layer. + If the low priority work queue is available, then it should be used by + the driver. + +config MAC802154_HPWORK + bool "High priority" + depends on SCHED_HPWORK + +config MAC802154_LPWORK + bool "Low priority" + depends on SCHED_LPWORK + +endchoice # Work queue + +config IEEE802154_NTXDESC + int "Number or TX descriptors" + default 3 + ---help--- + Configured number of Tx descriptors. Default: 3 + +endif # IEEE802154_MAC + config IEEE802154_DEV bool "Debug character driver for ieee802.15.4 radio interfaces" default n diff --git a/wireless/ieee802154/mac802154.c b/wireless/ieee802154/mac802154.c index ca877d5442f..54e5782b41b 100644 --- a/wireless/ieee802154/mac802154.c +++ b/wireless/ieee802154/mac802154.c @@ -1,1252 +1,1296 @@ -/**************************************************************************** - * wireless/ieee802154/mac802154.c - * - * Copyright (C) 2016 Sebastien Lorquet. All rights reserved. - * Author: Sebastien Lorquet - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "mac802154.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct mac802154_trans_s -{ - /* Supports a singly linked list */ - - FAR struct mac802154_trans_s *flink; - - uint8_t msdu_handle; - - FAR uint8_t *mhr_buf; - uint8_t mhr_len; - - FAR uint8_t *d_buf; - uint8_t d_len; - - sem_t sem; -}; - -struct mac802154_unsec_mhr_s -{ - uint8_t length; - union - { - uint16_t frame_control; - uint8_t data[IEEE802154_MAX_UNSEC_MHR_OVERHEAD]; - } u; -}; - -struct mac802154_radiocb_s -{ - struct ieee802154_radiocb_s cb; - FAR struct ieee802154_privmac_s *priv; -}; - -/* The privmac structure holds the internal state of the MAC and is the - * underlying represention of the opaque MACHANDLE. It contains storage for - * the IEEE802.15.4 MIB attributes. - */ - -struct ieee802154_privmac_s -{ - FAR struct ieee802154_radio_s *radio; /* Contained IEEE802.15.4 radio dev */ - FAR const struct ieee802154_maccb_s *cb; /* Contained MAC callbacks */ - FAR struct mac802154_radiocb_s radiocb; /* Interface to bind to radio */ - - sem_t exclsem; /* Support exclusive access */ - - struct work_s tx_work; - struct work_s rx_work; - - /* Support a singly linked list of transactions that will be sent using the - * CSMA algorithm. On a non-beacon enabled PAN, these transactions will be - * sent whenever. On a beacon-enabled PAN, these transactions will be sent - * during the CAP of the Coordinator's superframe. - */ - - FAR struct mac802154_trans_s *csma_head; - FAR struct mac802154_trans_s *csma_tail; - - /* Support a singly linked list of transactions that will be sent indirectly. - * This list should only be used by a MAC acting as a coordinator. These - * transactions will stay here until the data is extracted by the destination - * device sending a Data Request MAC command or if too much time passes. This - * list should also be used to populate the address list of the outgoing - * beacon frame. - */ - - FAR struct mac802154_trans_s *indirect_head; - FAR struct mac802154_trans_s *indirect_tail; - - FAR struct ieee802154_txdesc_s *txhead; /* Next TX descriptor to handle */ - FAR struct ieee802154_txdesc_s *txtail; /* Location to push TX descriptor */ - struct ieee802154_txdesc_s txtable[CONFIG_IEEE802154_NTXDESC]; - - /* MAC PIB attributes, grouped to save memory */ - - /* Holds all address information (Extended, Short, and PAN ID) for the MAC. */ - - struct ieee802154_addr_s addr; - - /* Holds all address information (Extended, Short) for Coordinator */ - - struct ieee802154_addr_s coord_addr; - - /* The maximum number of symbols to wait for an acknowledgement frame to - * arrive following a transmitted data frame. [1] pg. 126 - * - * NOTE: This may be able to be a 16-bit or even an 8-bit number. I wasn't - * sure at the time what the range of reasonable values was. - */ - - uint32_t ack_wait_dur; - - /* The maximum time to wait either for a frame intended as a response to a - * data request frame or for a broadcast frame following a beacon with the - * Frame Pending field set to one. [1] pg. 127 - * - * NOTE: This may be able to be a 16-bit or even an 8-bit number. I wasn't - * sure at the time what the range of reasonable values was. - */ - - uint32_t max_frame_wait_time; - - /* The maximum time (in unit periods) that a transaction is stored by a - * coordinator and indicated in its beacon. - */ - - uint16_t trans_persist_time; - - /* Contents of beacon payload */ - - uint8_t beacon_payload[IEEE802154_MAX_BEACON_PAYLOAD_LENGTH]; - uint8_t beacon_payload_len; /* Length of beacon payload */ - - uint8_t batt_life_ext_periods; /* # of backoff periods during which rx is - * enabled after the IFS following beacon */ - - uint8_t bsn; /* Seq. num added to tx beacon frame */ - uint8_t dsn; /* Seq. num added to tx data or MAC frame */ - uint8_t max_retries; /* Max # of retries alloed after tx failure */ - - /* The maximum time, in multiples of aBaseSuperframeDuration, a device shall - * wait for a response command frame to be available following a request - * command frame. [1] 128. - */ - - uint8_t resp_wait_time; - - /* The total transmit duration (including PHY header and FCS) specified in - * symbols. [1] pg. 129. - */ - - uint32_t tx_total_dur; - - /* Start of 32-bit bitfield */ - - uint32_t is_assoc : 1; /* Are we associated to the PAN */ - uint32_t assoc_permit : 1; /* Are we allowing assoc. as a coord. */ - uint32_t auto_req : 1; /* Automatically send data req. if addr - * addr is in the beacon frame */ - - uint32_t batt_life_ext : 1; /* Is BLE enabled */ - uint32_t gts_permit : 1; /* Is PAN Coord. accepting GTS reqs. */ - uint32_t promiscuous_mode : 1; /* Is promiscuous mode on? */ - uint32_t ranging_supported : 1; /* Does MAC sublayer support ranging */ - uint32_t rx_when_idle : 1; /* Recvr. on during idle periods */ - uint32_t sec_enabled : 1; /* Does MAC sublayer have security en. */ - - uint32_t max_csma_backoffs : 3; /* Max num backoffs for CSMA algorithm - * before declaring ch access failure */ - - uint32_t beacon_order : 4; /* Freq. that beacon is transmitted */ - - uint32_t superframe_order : 4; /* Length of active portion of outgoing - * superframe, including the beacon */ - - /* The offset, measured is symbols, between the symbol boundary at which the - * MLME captures the timestamp of each transmitted and received frame, and - * the onset of the first symbol past the SFD, namely the first symbol of - * the frames [1] pg. 129. - */ - - uint32_t sync_symb_offset : 12; - - /* End of 32-bit bitfield */ - - /* Start of 32-bit bitfield */ - - uint32_t beacon_tx_time : 24; /* Time of last beacon transmit */ - uint32_t min_be : 4; /* Min value of backoff exponent (BE) */ - uint32_t max_be : 4; /* Max value of backoff exponent (BE) */ - - /* End of 32-bit bitfield */ - - /* Start of 32-bit bitfield */ - - uint32_t tx_ctrl_active_dur : 17; /* Duration for which tx is permitted to - * be active */ - uint32_t tx_ctrl_pause_dur : 1; /* Duration after tx before another tx is - * permitted. 0=2000, 1= 10000 */ - uint32_t timestamp_support : 1; /* Does MAC layer supports timestamping */ - uint32_t is_coord : 1; /* Is this device acting as coordinator */ - /* 12-bits remaining */ - - /* End of 32-bit bitfield. */ - - /* TODO: Add Security-related MAC PIB attributes */ -}; - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static inline int mac802154_takesem(sem_t *sem); -#define mac802154_givesem(s) sem_post(s); - -/* Internal Functions */ - -static int mac802154_defaultmib(FAR struct ieee802154_privmac_s *priv); -static int mac802154_applymib(FAR struct ieee802154_privmac_s *priv); - -/* IEEE 802.15.4 PHY Interface OPs */ - -static int mac802154_poll_csma(FAR struct ieee802154_radiocb_s *radiocb, - FAR struct ieee802154_txdesc_s *tx_desc, - FAR uint8_t *buf); - -static int mac802154_poll_gts(FAR struct ieee802154_radiocb_s *radiocb, - FAR struct ieee802154_txdesc_s *tx_desc, - FAR uint8_t *buf); - -static int mac802154_txdone(FAR struct ieee802154_radiocb_s *radiocb, - FAR struct ieee802154_txdesc_s *tx_desc); - -/**************************************************************************** - * Private Data - ****************************************************************************/ - - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: mac802154_semtake - * - * Description: - * Acquire the semaphore used for access serialization. - * - ****************************************************************************/ - -static inline int mac802154_takesem(sem_t *sem) -{ - /* Take a count from the semaphore, possibly waiting */ - - if (sem_wait(sem) < 0) - { - /* EINTR is the only error that we expect */ - - int errcode = get_errno(); - DEBUGASSERT(errcode == EINTR); - return -errcode; - } - - return OK; -} - -/**************************************************************************** - * Name: mac802154_defaultmib - * - * Description: - * Set the MIB to its default values. - * - ****************************************************************************/ - -static int mac802154_defaultmib(FAR struct ieee802154_privmac_s *priv) -{ - /* TODO: Set all MAC fields to default values */ - - return OK; -} - -/**************************************************************************** - * Name: mac802154_applymib - * - * Description: - * Some parts of the MIB must be sent to the radio device. This routine - * calls the radio device routines to store the related parameters in the - * radio driver. It must be called each time a MIB parameter is changed. - * - ****************************************************************************/ - -static int mac802154_applymib(FAR struct ieee802154_privmac_s *priv) -{ - return OK; -} - -/**************************************************************************** - * Name: mac802154_poll_csma - * - * Description: - * Called from the radio driver through the callback struct. This function is - * called when the radio has room for another CSMA transaction. If the MAC - * layer has a CSMA transaction, it copies it into the supplied buffer and - * returns the length. A descriptor is also populated with the transaction. - * - ****************************************************************************/ - -static int mac802154_poll_csma(FAR struct ieee802154_radiocb_s *radiocb, - FAR struct ieee802154_txdesc_s *tx_desc, - FAR uint8_t *buf) -{ - FAR struct mac802154_radiocb_s *cb = - (FAR struct mac802154_radiocb_s *)radiocb; - FAR struct ieee802154_privmac_s *priv; - FAR struct mac802154_trans_s *trans; - - DEBUGASSERT(cb != NULL && cb->priv != NULL); - priv = cb->priv; - - /* Get exclusive access to the driver structure. We don't care about any - * signals so if we see one, just go back to trying to get access again. - */ - - while (mac802154_takesem(&priv->exclsem) != 0); - - /* Check to see if there are any CSMA transactions waiting */ - - if (priv->csma_head) - { - /* Pop a CSMA transaction off the list */ - - trans = priv->csma_head; - priv->csma_head = priv->csma_head->flink; - - mac802154_givesem(&priv->exclsem); - - /* Setup the transmit descriptor */ - - tx_desc->psdu_handle = trans->msdu_handle; - tx_desc->psdu_length = trans->mhr_len + trans->d_len; - - /* Copy the frame into the buffer */ - - memcpy(&buf[0], trans->mhr_buf, trans->mhr_len); - memcpy(&buf[trans->mhr_len], trans->d_buf, trans->d_len); - - /* Now that we've passed off the data, notify the waiting thread. - * NOTE: The transaction was allocated on the waiting thread's stack so - * it will be automatically deallocated when that thread awakens and - * returns. - */ - - sem_post(&trans->sem); - return tx_desc->psdu_length; - } - - mac802154_givesem(&priv->exclsem); - return 0; -} - -/**************************************************************************** - * Name: mac802154_poll_gts - * - * Description: - * Called from the radio driver through the callback struct. This function is - * called when the radio has room for another GTS transaction. If the MAC - * layer has a GTS transaction, it copies it into the supplied buffer and - * returns the length. A descriptor is also populated with the transaction. - * - ****************************************************************************/ - -static int mac802154_poll_gts(FAR struct ieee802154_radiocb_s *radiocb, - FAR struct ieee802154_txdesc_s *tx_desc, - FAR uint8_t *buf) -{ - FAR struct mac802154_radiocb_s *cb = - (FAR struct mac802154_radiocb_s *)radiocb; - FAR struct ieee802154_privmac_s *priv; - FAR struct mac802154_trans_s *trans; - int ret = 0; - - DEBUGASSERT(cb != NULL && cb->priv != NULL); - priv = cb->priv; - - /* Get exclusive access to the driver structure. We don't care about any - * signals so if we see one, just go back to trying to get access again. - */ - - while (mac802154_takesem(&priv->exclsem) != 0); - -#warning Missing logic. - - mac802154_givesem(&priv->exclsem); - - return 0; -} - -/**************************************************************************** - * Name: mac802154_txdone - * - * Description: - * Called from the radio driver through the callback struct. This function is - * called when the radio has completed a transaction. The txdesc passed gives - * provides information about the completed transaction including the original - * handle provided when the transaction was created and the status of the - * transaction. This function copies the descriptor and schedules work to - * handle the transaction without blocking the radio. - * - ****************************************************************************/ - -static int mac802154_txdone(FAR struct ieee802154_radiocb_s *radiocb, - FAR const struct ieee802154_txdesc_s *tx_desc) -{ - FAR struct mac802154_radiocb_s *cb = - (FAR struct mac802154_radiocb_s *)radiocb; - FAR struct ieee802154_privmac_s *priv; - FAR struct ieee802154_txdesc_s *desc; - int ret = 0; - - DEBUGASSERT(cb != NULL && cb->priv != NULL); - priv = cb->priv; - - /* Get exclusive access to the driver structure. We don't care about any - * signals so if we see one, just go back to trying to get access again. - */ - - while (mac802154_takesem(&priv->exclsem) != 0); - - /* Allocate a tx_desc */ - - desc = kmm_zalloc(sizeof(struct ieee802154_txdesc_s)); - if (desc == NULL) - { - mac802154_givesem(&priv->exclsem); - - return -ENOMEM; - } - - /* Copy the txdesc over and link it into our list */ - - memcpy(desc, tx_desc, sizeof(ieee802154_txdesc_s)); - - /* Link the descriptor */ - -#warning Missing Logic! - - mac802154_givesem(&priv->exclsem); - - /* Schedule work with the work queue to process the completion further */ - - if (work_available(&priv->tx_work)) - { - work_queue(MAC802154_WORK, &priv->tx_work, mac802154_txdone_worker, - (FAR void *)dev, 0); - } -} - -/**************************************************************************** - * Name: mac802154_txdone_worker - * - * Description: - * Worker function scheduled from mac802154_txdone. This function pops any - * TX descriptors off of the list and calls the next highest layers callback - * to inform the layer of the completed transaction and the status of it. - * - ****************************************************************************/ - -static void mac802154_txdone_worker(FAR void *arg) -{ - FAR struct ieee802154_privmanc_s *priv = - (FAR struct ieee802154_privmanc_s *)arg; -} - -/**************************************************************************** - * Name: mac802154_rxframe - * - * Description: - * Called from the radio driver through the callback struct. This function is - * called when the radio has received a frame. The frame is passed in an iob, - * so that we can free it when we are done processing. A pointer to the RX - * descriptor is passed along with the iob, but it must be copied here as it - * is allocated directly on the caller's stack. We simply link the frame, - * copy the RX descriptor, and schedule a worker to process the frame later so - * that we do not hold up the radio. - * - ****************************************************************************/ - -static void mac802154_rxframe(FAR struct ieee802154_radiocb_s *radiocb, - FAR struct ieee802154_rxdesc_s *rx_desc, - FAR struct iob_s *frame) -{ - FAR struct mac802154_radiocb_s *cb = - (FAR struct mac802154_radiocb_s *)radiocb; - FAR struct ieee802154_privmac_s *priv; - FAR struct ieee802154_txdesc_s *desc; - int ret = 0; - - DEBUGASSERT(cb != NULL && cb->priv != NULL); - priv = cb->priv; - - /* Get exclusive access to the driver structure. We don't care about any - * signals so if we see one, just go back to trying to get access again. - */ - - while (mac802154_takesem(&priv->exclsem) != 0); - - /* TODO: Copy the frame descriptor to some type of list */ - - /* Push the iob onto the tail of the frame list for processing */ - - priv->rxframes_tail->io_flink = iob; - priv->rxframes_tail = iob; - - mac802154_givesem(&priv->exclsem); - - /* Schedule work with the work queue to process the completion further */ - - if (work_available(&priv->rx_work)) - { - work_queue(MAC802154_WORK, &priv->rx_work, mac802154_rxframe_worker, - (FAR void *)priv, 0); - } -} - -/**************************************************************************** - * Name: mac802154_rxframe_worker - * - * Description: - * Worker function scheduled from mac802154_rxframe. This function processes - * any frames in the list. Frames intended to be consumed by the MAC layer - * will not produce any callbacks to the next highest layer. Frames intended - * for the application layer will be forwarded to them. - * - ****************************************************************************/ - -static void mac802154_rxframe_worker(FAR void *arg) -{ - FAR struct ieee802154_privmac_s *priv = - (FAR struct ieee802154_privmac_s *)arg; - - /* The radio layer is responsible for handling all ACKs and retries. If for - * some reason an ACK gets here, just throw it out. - */ -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: mac802154_create - * - * Description: - * Create a 802.15.4 MAC device from a 802.15.4 compatible radio device. - * - * The returned MAC structure should be passed to either the next highest - * layer in the network stack, or registered with a mac802154dev character - * or network drivers. In any of these scenarios, the next highest layer - * should register a set of callbacks with the MAC layer by setting the - * mac->cbs member. - * - * NOTE: 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. - * - * Input Parameters: - * radiodev - an instance of an IEEE 802.15.4 radio - * - * Returned Value: - * An opaque reference to the MAC state data. - * - ****************************************************************************/ - -MACHANDLE mac802154_create(FAR struct ieee802154_radio_s *radiodev) -{ - FAR struct ieee802154_privmac_s *mac; - FAR struct ieee802154_radiocb_s *radiocb; - - /* Allocate object */ - - mac = (FAR struct ieee802154_privmac_s *) - kmm_zalloc(sizeof(struct ieee802154_privmac_s)); - - if (mac == NULL) - { - return NULL; - } - - /* Initialize fields */ - - mac->radio = radiodev; - - mac802154_defaultmib(mac); - mac802154_applymib(mac); - - /* Initialize the Radio callbacks */ - - mac->radiocb.priv = mac; - - radiocb = &mac->radiocb.cb; - radiocb->poll_csma = mac802154_poll_csma; - radiocb->poll_gts = mac802154_poll_gts; - radiocb->txdone = mac802154_txdone; - - /* Bind our callback structure */ - - radiodev->ops->bind(radiodev, &mac->radiocb.cb); - - return (MACHANDLE)mac; -} - -/**************************************************************************** - * Name: mac802154_bind - * - * Description: - * Bind the MAC callback table to the MAC state. - * - * Parameters: - * mac - Reference to the MAC driver state structure - * cb - MAC callback operations - * - * Returned Value: - * OK on success; Negated errno on failure. - * - ****************************************************************************/ - -int mac802154_bind(MACHANDLE mac, FAR const struct ieee802154_maccb_s *cb) -{ - FAR struct ieee802154_privmac_s *priv = - (FAR struct ieee802154_privmac_s *)mac; - - priv->cb = cb; - return OK; -} - -/**************************************************************************** - * Name: mac802154_ioctl - * - * Description: - * Handle MAC and radio IOCTL commands directed to the MAC. - * - * Parameters: - * mac - Reference to the MAC driver state structure - * cmd - The IOCTL command - * arg - The argument for the IOCTL command - * - * Returned Value: - * OK on success; Negated errno on failure. - * - ****************************************************************************/ - -int mac802154_ioctl(MACHANDLE mac, int cmd, unsigned long arg) -{ - FAR struct ieee802154_privmac_s *priv = - (FAR struct ieee802154_privmac_s *)mac; - int ret = -EINVAL; - - DEBUGASSERT(priv != NULL); - - /* Check for IOCTLs aimed at the IEEE802.15.4 MAC layer */ - - if (_MAC802154IOCVALID(cmd)) - { - /* Handle the MAC IOCTL command */ -#warning Missing logic - } - - /* No, other IOCTLs must be aimed at the IEEE802.15.4 radio layer */ - - else - { - DEBUGASSERT(priv->radio != NULL && - priv->radio->ops != NULL && - priv->radio->ops->ioctl != NULL); - - ret = priv->radio->ops->ioctl(priv->radio, cmd, arg); - } - - return ret; -} - -/**************************************************************************** - * MAC Interface Operations - ****************************************************************************/ - -/**************************************************************************** - * Name: mac802154_req_data - * - * Description: - * The MCPS-DATA.request primitive requests the transfer of a data SPDU - * (i.e., MSDU) from a local SSCS entity to a single peer SSCS entity. - * Confirmation is returned via the - * struct ieee802154_maccb_s->conf_data callback. - * - ****************************************************************************/ - -int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) -{ - FAR struct ieee802154_privmac_s *priv = - (FAR struct ieee802154_privmac_s *)mac; - FAR struct mac802154_trans_s trans; - struct mac802154_unsec_mhr_s mhr; - int ret; - - /* Start off assuming there is only the frame_control field in the MHR */ - - mhr.length = 2; - - /* Do a preliminary check to make sure the MSDU isn't too long for even - * the best case. - */ - - if (req->msdu_length > IEEE802154_MAX_MAC_PAYLOAD_SIZE) - { - return -EINVAL; - } - - /* Ensure we start with a clear frame control field */ - - mhr.u.frame_control = 0; - - /* Set the frame type to Data */ - - mhr.u.frame_control |= IEEE802154_FRAME_DATA << - IEEE802154_FRAMECTRL_SHIFT_FTYPE; - - /* If the msduLength is greater than aMaxMACSafePayloadSize, the MAC - * sublayer will set the Frame Version to one. [1] pg. 118. - */ - - if (req->msdu_length > IEEE802154_MAX_SAFE_MAC_PAYLOAD_SIZE) - { - mhr.u.frame_control |= IEEE802154_FRAMECTRL_VERSION; - } - - /* If the TXOptions parameter specifies that an acknowledged transmission - * is required, the AR field will be set appropriately, as described in - * 5.1.6.4 [1] pg. 118. - */ - - mhr.u.frame_control |= (req->msdu_flags.ack_tx << - IEEE802154_FRAMECTRL_SHIFT_ACKREQ); - - /* If the destination address is present, copy the PAN ID and one of the - * addresses, depending on mode, into the MHR . - */ - - if (req->dest_addr.mode != IEEE802154_ADDRMODE_NONE) - { - memcpy(&mhr.u.data[mhr.length], &req->dest_addr.panid, 2); - mhr.length += 2; - - if (req->dest_addr.mode == IEEE802154_ADDRMODE_SHORT) - { - memcpy(&mhr.u.data[mhr.length], &req->dest_addr.saddr, 2); - mhr.length += 2; - } - else if (req->dest_addr.mode == IEEE802154_ADDRMODE_EXTENDED) - { - memcpy(&mhr.u.data[mhr.length], &req->dest_addr.eaddr, 8); - mhr.length += 8; - } - } - - /* Set the destination addr mode inside the frame contorl field */ - - mhr.u.frame_control |= (req->dest_addr.mode << - IEEE802154_FRAMECTRL_SHIFT_DADDR); - - /* From this point on, we need exclusive access to the privmac struct */ - - ret = mac802154_takesem(&priv->exclsem); - if (ret < 0) - { - wlerr("ERROR: mac802154_takesem failed: %d\n", ret); - return ret; - } - - /* If both destination and source addressing information is present, the MAC - * sublayer shall compare the destination and source PAN identifiers. - * [1] pg. 41. - */ - - if (req->src_addr_mode != IEEE802154_ADDRMODE_NONE && - req->dest_addr.mode != IEEE802154_ADDRMODE_NONE) - { - /* If the PAN identifiers are identical, the PAN ID Compression field - * shall be set to one, and the source PAN identifier shall be omitted - * from the transmitted frame. [1] pg. 41. - */ - - if (req->dest_addr.panid == priv->addr.panid) - { - mhr.u.frame_control |= IEEE802154_FRAMECTRL_PANIDCOMP; - } - } - - if (req->src_addr_mode != IEEE802154_ADDRMODE_NONE) - { - /* If the destination address is not included, or if PAN ID Compression - * is off, we need to include the Source PAN ID. - */ - - if ((req->dest_addr.mode == IEEE802154_ADDRMODE_NONE) || - (mhr.u.frame_control & IEEE802154_FRAMECTRL_PANIDCOMP)) - { - memcpy(&mhr.u.data[mhr.length], &priv->addr.panid, 2); - mhr.length += 2; - } - - if (req->src_addr_mode == IEEE802154_ADDRMODE_SHORT) - { - memcpy(&mhr.u.data[mhr.length], &priv->addr.saddr, 2); - mhr.length += 2; - } - else if (req->src_addr_mode == IEEE802154_ADDRMODE_EXTENDED) - { - memcpy(&mhr.u.data[mhr.length], &priv->addr.eaddr, 8); - mhr.length += 8; - } - } - - /* Set the source addr mode inside the frame control field */ - - mhr.u.frame_control |= (req->src_addr_mode << - IEEE802154_FRAMECTRL_SHIFT_SADDR); - - /* Each time a data or a MAC command frame is generated, the MAC sublayer - * shall copy the value of macDSN into the Sequence Number field of the MHR - * of the outgoing frame and then increment it by one. [1] pg. 40. - */ - - mhr.u.data[mhr.length++] = priv->dsn++; - - /* Now that we know which fields are included in the header, we can make - * sure we actually have enough room in the PSDU. - */ - - if (mhr.length + req->msdu_length + IEEE802154_MFR_LENGTH > - IEEE802154_MAX_PHY_PACKET_SIZE) - { - return -E2BIG; - } - - trans.mhr_buf = &mhr.u.data[0]; - trans.mhr_len = mhr.length; - - trans.d_buf = &req->msdu[0]; - trans.d_len = req->msdu_length; - - trans.msdu_handle = req->msdu_handle; - - /* If the TxOptions parameter specifies that a GTS transmission is required, - * the MAC sublayer will determine whether it has a valid GTS as described - * 5.1.7.3. If a valid GTS could not be found, the MAC sublayer will discard - * the MSDU. If a valid GTS was found, the MAC sublayer will defer, if - * necessary, until the GTS. If the TxOptions parameter specifies that a GTS - * transmission is not required, the MAC sublayer will transmit the MSDU using - * either slotted CSMA-CA in the CAP for a beacon-enabled PAN or unslotted - * CSMA-CA for a nonbeacon-enabled PAN. Specifying a GTS transmission in the - * TxOptions parameter overrides an indirect transmission request. - * [1] pg. 118. - */ - - if (req->msdu_flags.gts_tx) - { - /* TODO: Support GTS transmission. This should just change where we link - * the transaction. Instead of going in the CSMA transaction list, it - * should be linked to the GTS' transaction list. We'll need to check if - * the GTS is valid, and then find the GTS, before linking. Note, we also - * don't have to try and kick-off any transmission here. - */ - - return -ENOTSUP; - } - else - { - /* If the TxOptions parameter specifies that an indirect transmission is - * required and this primitive is received by the MAC sublayer of a - * coordinator, the data frame is sent using indirect transmission, as - * described in 5.1.5 and 5.1.6.3. [1] - */ - - if (req->msdu_flags.indirect_tx) - { - /* If the TxOptions parameter specifies that an indirect transmission - * is required and if the device receiving this primitive is not a - * coordinator, the destination address is not present, or the - * TxOptions parameter also specifies a GTS transmission, the indirect - * transmission option will be ignored. [1] - */ - - if (priv->is_coord && req->dest_addr.mode != IEEE802154_ADDRMODE_NONE) - { - /* Link the transaction into the indirect_trans list */ - - priv->indirect_tail->flink = &trans; - priv->indirect_tail = &trans; - } - else - { - /* Override the setting since it wasn't valid */ - - req->msdu_flags.indirect_tx = 0; - } - } - - /* If this is a direct transmission not during a GTS */ - - if (!req->msdu_flags.indirect_tx) - { - /* Link the transaction into the CSMA transaction list */ - - priv->csma_tail->flink = &trans; - priv->csma_tail = &trans; - - /* We no longer need to have the MAC layer locked. */ - - mac802154_givesem(&priv->exclsem); - - /* Notify the radio driver that there is data available */ - - priv->radio->ops->txnotify_csma(priv->radio); - - sem_wait(&trans.sem); - } - } - - return OK; -} - - -/**************************************************************************** - * Name: mac802154_req_purge - * - * Description: - * The MCPS-PURGE.request primitive allows the next higher layer to purge - * an MSDU from the transaction queue. Confirmation is returned via - * the struct ieee802154_maccb_s->conf_purge callback. - * - ****************************************************************************/ - -int mac802154_req_purge(MACHANDLE mac, uint8_t handle) -{ - FAR struct ieee802154_privmac_s *priv = - (FAR struct ieee802154_privmac_s *)mac; - return -ENOTTY; -} - -/**************************************************************************** - * Name: mac802154_req_associate - * - * Description: - * The MLME-ASSOCIATE.request primitive allows a device to request an - * association with a coordinator. Confirmation is returned via the - * struct ieee802154_maccb_s->conf_associate callback. - * - ****************************************************************************/ - -int mac802154_req_associate(MACHANDLE mac, - FAR struct ieee802154_assoc_req_s *req) -{ - FAR struct ieee802154_privmac_s *priv = - (FAR struct ieee802154_privmac_s *)mac; - - /* Set the channel of the PHY layer */ - - /* Set the channel page of the PHY layer */ - - /* Set the macPANId */ - - /* Set either the macCoordExtendedAddress and macCoordShortAddress - * depending on the CoordAddrMode in the primitive. - */ - - if (req->coord_addr.mode == IEEE802154_ADDRMODE_EXTENDED) - { - - } - else if (req->coord_addr.mode == IEEE802154_ADDRMODE_EXTENDED) - { - - } - else - { - return -EINVAL; - } - - return -ENOTTY; -} - -/**************************************************************************** - * Name: mac802154_req_disassociate - * - * Description: - * The MLME-DISASSOCIATE.request primitive is used by an associated device to - * notify the coordinator of its intent to leave the PAN. It is also used by - * the coordinator to instruct an associated device to leave the PAN. - * Confirmation is returned via the - * struct ieee802154_maccb_s->conf_disassociate callback. - * - ****************************************************************************/ - -int mac802154_req_disassociate(MACHANDLE mac, - FAR struct ieee802154_disassoc_req_s *req) -{ - FAR struct ieee802154_privmac_s *priv = - (FAR struct ieee802154_privmac_s *)mac; - return -ENOTTY; -} - -/**************************************************************************** - * Name: mac802154_req_get - * - * Description: - * The MLME-GET.request primitive requests information about a given PIB - * attribute. Actual data is returned via the - * struct ieee802154_maccb_s->conf_get callback. - * - ****************************************************************************/ - -int mac802154_req_get(MACHANDLE mac, enum ieee802154_pib_attr_e attr) -{ - FAR struct ieee802154_privmac_s *priv = - (FAR struct ieee802154_privmac_s *)mac; - return -ENOTTY; -} - -/**************************************************************************** - * Name: mac802154_req_gts - * - * Description: - * The MLME-GTS.request primitive allows a device to send a request to the PAN - * coordinator to allocate a new GTS or to deallocate an existing GTS. - * Confirmation is returned via the - * struct ieee802154_maccb_s->conf_gts callback. - * - ****************************************************************************/ - -int mac802154_req_gts(MACHANDLE mac, FAR uint8_t *characteristics) -{ - FAR struct ieee802154_privmac_s *priv = - (FAR struct ieee802154_privmac_s *)mac; - return -ENOTTY; -} - -/**************************************************************************** - * Name: mac802154_req_reset - * - * Description: - * The MLME-RESET.request primitive allows the next higher layer to request - * that the MLME performs a reset operation. Confirmation is returned via - * the struct ieee802154_maccb_s->conf_reset callback. - * - ****************************************************************************/ - -int mac802154_req_reset(MACHANDLE mac, bool setdefaults) -{ - FAR struct ieee802154_privmac_s * priv = - (FAR struct ieee802154_privmac_s *) mac; - return -ENOTTY; -} - -/**************************************************************************** - * Name: mac802154_req_rxenable - * - * Description: - * The MLME-RX-ENABLE.request primitive allows the next higher layer to - * request that the receiver is enable for a finite period of time. - * Confirmation is returned via the - * struct ieee802154_maccb_s->conf_rxenable callback. - * - ****************************************************************************/ - -int mac802154_req_rxenable(MACHANDLE mac, bool deferrable, int ontime, - int duration) -{ - FAR struct ieee802154_privmac_s * priv = - (FAR struct ieee802154_privmac_s *)mac; - return -ENOTTY; -} - -/**************************************************************************** - * Name: mac802154_req_scan - * - * Description: - * The MLME-SCAN.request primitive is used to initiate a channel scan over a - * given list of channels. A device can use a channel scan to measure the - * energy on the channel, search for the coordinator with which it associated, - * or search for all coordinators transmitting beacon frames within the POS of - * the scanning device. Scan results are returned - * via MULTIPLE calls to the struct ieee802154_maccb_s->conf_scan callback. - * This is a difference with the official 802.15.4 specification, implemented - * here to save memory. - * - ****************************************************************************/ - -int mac802154_req_scan(MACHANDLE mac, uint8_t type, uint32_t channels, - int duration) -{ - FAR struct ieee802154_privmac_s *priv = - (FAR struct ieee802154_privmac_s *)mac; - return -ENOTTY; -} - -/**************************************************************************** - * Name: mac802154_req_set - * - * Description: - * The MLME-SET.request primitive attempts to write the given value to the - * indicated MAC PIB attribute. Confirmation is returned via the - * struct ieee802154_maccb_s->conf_set callback. - * - ****************************************************************************/ - -int mac802154_req_set(MACHANDLE mac, int attribute, FAR uint8_t *value, - int valuelen) -{ - FAR struct ieee802154_privmac_s *priv = - (FAR struct ieee802154_privmac_s *)mac; - return -ENOTTY; -} - -/**************************************************************************** - * Name: mac802154_req_start - * - * Description: - * The MLME-START.request primitive makes a request for the device to start - * using a new superframe configuration. Confirmation is returned - * via the struct ieee802154_maccb_s->conf_start callback. - * - ****************************************************************************/ - -int mac802154_req_start(MACHANDLE mac, uint16_t panid, int channel, - uint8_t bo, uint8_t fo, bool coord, bool batext, - bool realign) -{ - FAR struct ieee802154_privmac_s *priv = - (FAR struct ieee802154_privmac_s *)mac; - return -ENOTTY; -} - -/**************************************************************************** - * Name: mac802154_req_sync - * - * Description: - * The MLME-SYNC.request primitive requests to synchronize with the - * coordinator by acquiring and, if specified, tracking its beacons. - * Confirmation is returned via the - * struct ieee802154_maccb_s->int_commstatus callback. TOCHECK. - * - ****************************************************************************/ - -int mac802154_req_sync(MACHANDLE mac, int channel, bool track) -{ - FAR struct ieee802154_privmac_s *priv = - (FAR struct ieee802154_privmac_s *)mac; - return -ENOTTY; -} - -/**************************************************************************** - * Name: mac802154_req_poll - * - * Description: - * The MLME-POLL.request primitive prompts the device to request data from - * the coordinator. Confirmation is returned via the - * struct ieee802154_maccb_s->conf_poll callback, followed by a - * struct ieee802154_maccb_s->ind_data callback. - * - ****************************************************************************/ - -int mac802154_req_poll(MACHANDLE mac, FAR uint8_t *coordaddr) -{ - FAR struct ieee802154_privmac_s *priv = - (FAR struct ieee802154_privmac_s *)mac; - return -ENOTTY; -} - -/**************************************************************************** - * Name: mac802154_rsp_associate - * - * Description: - * The MLME-ASSOCIATE.response primitive is used to initiate a response to - * an MLME-ASSOCIATE.indication primitive. - * - ****************************************************************************/ - -int mac802154_rsp_associate(MACHANDLE mac, uint8_t eadr, uint16_t saddr, - int status) -{ - FAR struct ieee802154_privmac_s *priv = - (FAR struct ieee802154_privmac_s *)mac; - return -ENOTTY; -} - -/**************************************************************************** - * Name: mac802154_rsp_orphan - * - * Description: - * The MLME-ORPHAN.response primitive allows the next higher layer of a - * coordinator to respond to the MLME-ORPHAN.indication primitive. - * - ****************************************************************************/ - -int mac802154_rsp_orphan(MACHANDLE mac, FAR uint8_t *orphanaddr, - uint16_t saddr, bool associated) -{ - FAR struct ieee802154_privmac_s *priv = - (FAR struct ieee802154_privmac_s *)mac; - return -ENOTTY; -} +/**************************************************************************** + * wireless/ieee802154/mac802154.c + * + * Copyright (C) 2016 Sebastien Lorquet. All rights reserved. + * Author: Sebastien Lorquet + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include + +#include +#include + +#include + +#include + +#include "mac802154.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ +/* Configuration ************************************************************/ +/* If processing is not done at the interrupt level, then work queue support + * is required. + */ + +#if !defined(CONFIG_SCHED_WORKQUEUE) +# error Work queue support is required in this configuration (CONFIG_SCHED_WORKQUEUE) +#else + + /* Use the low priority work queue if possible */ + +# if defined(CONFIG_MAC802154_HPWORK) +# define MAC802154_WORK HPWORK +# elif defined(CONFIG_MAC802154_LPWORK) +# define MAC802154_WORK LPWORK +# else +# error Neither CONFIG_MAC802154_HPWORK nor CONFIG_MAC802154_LPWORK defined +# endif +#endif + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +struct mac802154_trans_s +{ + /* Supports a singly linked list */ + + FAR struct mac802154_trans_s *flink; + + uint8_t msdu_handle; + + FAR uint8_t *mhr_buf; + uint8_t mhr_len; + + FAR uint8_t *d_buf; + uint8_t d_len; + + sem_t sem; +}; + +struct mac802154_unsec_mhr_s +{ + uint8_t length; + union + { + uint16_t frame_control; + uint8_t data[IEEE802154_MAX_UNSEC_MHR_OVERHEAD]; + } u; +}; + +struct mac802154_radiocb_s +{ + struct ieee802154_radiocb_s cb; + FAR struct ieee802154_privmac_s *priv; +}; + +/* The privmac structure holds the internal state of the MAC and is the + * underlying represention of the opaque MACHANDLE. It contains storage for + * the IEEE802.15.4 MIB attributes. + */ + +struct ieee802154_privmac_s +{ + FAR struct ieee802154_radio_s *radio; /* Contained IEEE802.15.4 radio dev */ + FAR const struct ieee802154_maccb_s *cb; /* Contained MAC callbacks */ + FAR struct mac802154_radiocb_s radiocb; /* Interface to bind to radio */ + + sem_t exclsem; /* Support exclusive access */ + + struct work_s tx_work; + struct work_s rx_work; + + /* Support a singly linked list of transactions that will be sent using the + * CSMA algorithm. On a non-beacon enabled PAN, these transactions will be + * sent whenever. On a beacon-enabled PAN, these transactions will be sent + * during the CAP of the Coordinator's superframe. + */ + + FAR struct mac802154_trans_s *csma_head; + FAR struct mac802154_trans_s *csma_tail; + + /* Support a singly linked list of transactions that will be sent indirectly. + * This list should only be used by a MAC acting as a coordinator. These + * transactions will stay here until the data is extracted by the destination + * device sending a Data Request MAC command or if too much time passes. This + * list should also be used to populate the address list of the outgoing + * beacon frame. + */ + + FAR struct mac802154_trans_s *indirect_head; + FAR struct mac802154_trans_s *indirect_tail; + + uint8_t txdesc_count; + struct ieee802154_txdesc_s txdesc[CONFIG_IEEE802154_NTXDESC]; + + /* Support a singly linked list of frames received */ + FAR struct iob_s *rxframes_head; + FAR struct iob_s *rxframes_tail; + + /* MAC PIB attributes, grouped to save memory */ + + /* Holds all address information (Extended, Short, and PAN ID) for the MAC. */ + + struct ieee802154_addr_s addr; + + /* Holds all address information (Extended, Short) for Coordinator */ + + struct ieee802154_addr_s coord_addr; + + /* The maximum number of symbols to wait for an acknowledgement frame to + * arrive following a transmitted data frame. [1] pg. 126 + * + * NOTE: This may be able to be a 16-bit or even an 8-bit number. I wasn't + * sure at the time what the range of reasonable values was. + */ + + uint32_t ack_wait_dur; + + /* The maximum time to wait either for a frame intended as a response to a + * data request frame or for a broadcast frame following a beacon with the + * Frame Pending field set to one. [1] pg. 127 + * + * NOTE: This may be able to be a 16-bit or even an 8-bit number. I wasn't + * sure at the time what the range of reasonable values was. + */ + + uint32_t max_frame_wait_time; + + /* The maximum time (in unit periods) that a transaction is stored by a + * coordinator and indicated in its beacon. + */ + + uint16_t trans_persist_time; + + /* Contents of beacon payload */ + + uint8_t beacon_payload[IEEE802154_MAX_BEACON_PAYLOAD_LENGTH]; + uint8_t beacon_payload_len; /* Length of beacon payload */ + + uint8_t batt_life_ext_periods; /* # of backoff periods during which rx is + * enabled after the IFS following beacon */ + + uint8_t bsn; /* Seq. num added to tx beacon frame */ + uint8_t dsn; /* Seq. num added to tx data or MAC frame */ + uint8_t max_retries; /* Max # of retries alloed after tx failure */ + + /* The maximum time, in multiples of aBaseSuperframeDuration, a device shall + * wait for a response command frame to be available following a request + * command frame. [1] 128. + */ + + uint8_t resp_wait_time; + + /* The total transmit duration (including PHY header and FCS) specified in + * symbols. [1] pg. 129. + */ + + uint32_t tx_total_dur; + + /* Start of 32-bit bitfield */ + + uint32_t is_assoc : 1; /* Are we associated to the PAN */ + uint32_t assoc_permit : 1; /* Are we allowing assoc. as a coord. */ + uint32_t auto_req : 1; /* Automatically send data req. if addr + * addr is in the beacon frame */ + + uint32_t batt_life_ext : 1; /* Is BLE enabled */ + uint32_t gts_permit : 1; /* Is PAN Coord. accepting GTS reqs. */ + uint32_t promiscuous_mode : 1; /* Is promiscuous mode on? */ + uint32_t ranging_supported : 1; /* Does MAC sublayer support ranging */ + uint32_t rx_when_idle : 1; /* Recvr. on during idle periods */ + uint32_t sec_enabled : 1; /* Does MAC sublayer have security en. */ + + uint32_t max_csma_backoffs : 3; /* Max num backoffs for CSMA algorithm + * before declaring ch access failure */ + + uint32_t beacon_order : 4; /* Freq. that beacon is transmitted */ + + uint32_t superframe_order : 4; /* Length of active portion of outgoing + * superframe, including the beacon */ + + /* The offset, measured is symbols, between the symbol boundary at which the + * MLME captures the timestamp of each transmitted and received frame, and + * the onset of the first symbol past the SFD, namely the first symbol of + * the frames [1] pg. 129. + */ + + uint32_t sync_symb_offset : 12; + + /* End of 32-bit bitfield */ + + /* Start of 32-bit bitfield */ + + uint32_t beacon_tx_time : 24; /* Time of last beacon transmit */ + uint32_t min_be : 4; /* Min value of backoff exponent (BE) */ + uint32_t max_be : 4; /* Max value of backoff exponent (BE) */ + + /* End of 32-bit bitfield */ + + /* Start of 32-bit bitfield */ + + uint32_t tx_ctrl_active_dur : 17; /* Duration for which tx is permitted to + * be active */ + uint32_t tx_ctrl_pause_dur : 1; /* Duration after tx before another tx is + * permitted. 0=2000, 1= 10000 */ + uint32_t timestamp_support : 1; /* Does MAC layer supports timestamping */ + uint32_t is_coord : 1; /* Is this device acting as coordinator */ + /* 12-bits remaining */ + + /* End of 32-bit bitfield. */ + + /* TODO: Add Security-related MAC PIB attributes */ +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static inline int mac802154_takesem(sem_t *sem); +#define mac802154_givesem(s) sem_post(s); + +static void mac802154_txdone_worker(FAR void *arg); +static void mac802154_rxframe_worker(FAR void *arg); + +/* Internal Functions */ + +static int mac802154_defaultmib(FAR struct ieee802154_privmac_s *priv); +static int mac802154_applymib(FAR struct ieee802154_privmac_s *priv); + +/* IEEE 802.15.4 PHY Interface OPs */ + +static int mac802154_poll_csma(FAR const struct ieee802154_radiocb_s *radiocb, + FAR struct ieee802154_txdesc_s *tx_desc, + FAR uint8_t *buf); + +static int mac802154_poll_gts(FAR const struct ieee802154_radiocb_s *radiocb, + FAR struct ieee802154_txdesc_s *tx_desc, + FAR uint8_t *buf); + +static void mac802154_txdone(FAR const struct ieee802154_radiocb_s *radiocb, + FAR const struct ieee802154_txdesc_s *tx_desc); + +static void mac802154_rxframe(FAR const struct ieee802154_radiocb_s *radiocb, + FAR struct ieee802154_rxdesc_s *rx_desc, + FAR struct iob_s *frame); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: mac802154_semtake + * + * Description: + * Acquire the semaphore used for access serialization. + * + ****************************************************************************/ + +static inline int mac802154_takesem(sem_t *sem) +{ + /* Take a count from the semaphore, possibly waiting */ + + if (sem_wait(sem) < 0) + { + /* EINTR is the only error that we expect */ + + int errcode = get_errno(); + DEBUGASSERT(errcode == EINTR); + return -errcode; + } + + return OK; +} + +/**************************************************************************** + * Name: mac802154_defaultmib + * + * Description: + * Set the MIB to its default values. + * + ****************************************************************************/ + +static int mac802154_defaultmib(FAR struct ieee802154_privmac_s *priv) +{ + /* TODO: Set all MAC fields to default values */ + + return OK; +} + +/**************************************************************************** + * Name: mac802154_applymib + * + * Description: + * Some parts of the MIB must be sent to the radio device. This routine + * calls the radio device routines to store the related parameters in the + * radio driver. It must be called each time a MIB parameter is changed. + * + ****************************************************************************/ + +static int mac802154_applymib(FAR struct ieee802154_privmac_s *priv) +{ + return OK; +} + +/**************************************************************************** + * Name: mac802154_poll_csma + * + * Description: + * Called from the radio driver through the callback struct. This function is + * called when the radio has room for another CSMA transaction. If the MAC + * layer has a CSMA transaction, it copies it into the supplied buffer and + * returns the length. A descriptor is also populated with the transaction. + * + ****************************************************************************/ + +static int mac802154_poll_csma(FAR const struct ieee802154_radiocb_s *radiocb, + FAR struct ieee802154_txdesc_s *tx_desc, + FAR uint8_t *buf) +{ + FAR struct mac802154_radiocb_s *cb = + (FAR struct mac802154_radiocb_s *)radiocb; + FAR struct ieee802154_privmac_s *priv; + FAR struct mac802154_trans_s *trans; + + DEBUGASSERT(cb != NULL && cb->priv != NULL); + priv = cb->priv; + + /* Get exclusive access to the driver structure. We don't care about any + * signals so if we see one, just go back to trying to get access again. + */ + + while (mac802154_takesem(&priv->exclsem) != 0); + + /* Check to see if there are any CSMA transactions waiting */ + + if (priv->csma_head) + { + /* Pop a CSMA transaction off the list */ + + trans = priv->csma_head; + priv->csma_head = priv->csma_head->flink; + + mac802154_givesem(&priv->exclsem); + + /* Setup the transmit descriptor */ + + tx_desc->handle = trans->msdu_handle; + + /* Copy the frame into the buffer */ + + memcpy(&buf[0], trans->mhr_buf, trans->mhr_len); + memcpy(&buf[trans->mhr_len], trans->d_buf, trans->d_len); + + /* Now that we've passed off the data, notify the waiting thread. + * NOTE: The transaction was allocated on the waiting thread's stack so + * it will be automatically deallocated when that thread awakens and + * returns. + */ + + sem_post(&trans->sem); + return (trans->mhr_len + trans->d_len); + } + + mac802154_givesem(&priv->exclsem); + return 0; +} + +/**************************************************************************** + * Name: mac802154_poll_gts + * + * Description: + * Called from the radio driver through the callback struct. This function is + * called when the radio has room for another GTS transaction. If the MAC + * layer has a GTS transaction, it copies it into the supplied buffer and + * returns the length. A descriptor is also populated with the transaction. + * + ****************************************************************************/ + +static int mac802154_poll_gts(FAR const struct ieee802154_radiocb_s *radiocb, + FAR struct ieee802154_txdesc_s *tx_desc, + FAR uint8_t *buf) +{ + FAR struct mac802154_radiocb_s *cb = + (FAR struct mac802154_radiocb_s *)radiocb; + FAR struct ieee802154_privmac_s *priv; + FAR struct mac802154_trans_s *trans; + int ret = 0; + + DEBUGASSERT(cb != NULL && cb->priv != NULL); + priv = cb->priv; + + /* Get exclusive access to the driver structure. We don't care about any + * signals so if we see one, just go back to trying to get access again. + */ + + while (mac802154_takesem(&priv->exclsem) != 0); + +#warning Missing logic. + + mac802154_givesem(&priv->exclsem); + + return 0; +} + +/**************************************************************************** + * Name: mac802154_txdone + * + * Description: + * Called from the radio driver through the callback struct. This function is + * called when the radio has completed a transaction. The txdesc passed gives + * provides information about the completed transaction including the original + * handle provided when the transaction was created and the status of the + * transaction. This function copies the descriptor and schedules work to + * handle the transaction without blocking the radio. + * + ****************************************************************************/ + +static void mac802154_txdone(FAR const struct ieee802154_radiocb_s *radiocb, + FAR const struct ieee802154_txdesc_s *tx_desc) +{ + FAR struct mac802154_radiocb_s *cb = + (FAR struct mac802154_radiocb_s *)radiocb; + FAR struct ieee802154_privmac_s *priv; + + DEBUGASSERT(cb != NULL && cb->priv != NULL); + priv = cb->priv; + + /* Get exclusive access to the driver structure. We don't care about any + * signals so if we see one, just go back to trying to get access again. + */ + + while (mac802154_takesem(&priv->exclsem) != 0); + + /* Check to see if there is an available tx descriptor slot. If there is + * not we simply drop the notification */ + + if (priv->txdesc_count < CONFIG_IEEE802154_NTXDESC) + { + /* Copy the txdesc over and link it into our list */ + + memcpy(&priv->txdesc[priv->txdesc_count++], tx_desc, + sizeof(struct ieee802154_txdesc_s)); + } + else + { + wlinfo("MAC802154: No room for TX Desc.\n"); + } + + mac802154_givesem(&priv->exclsem); + + /* Schedule work with the work queue to process the completion further */ + + if (work_available(&priv->tx_work)) + { + work_queue(MAC802154_WORK, &priv->tx_work, mac802154_txdone_worker, + (FAR void *)priv, 0); + } +} + +/**************************************************************************** + * Name: mac802154_txdone_worker + * + * Description: + * Worker function scheduled from mac802154_txdone. This function pops any + * TX descriptors off of the list and calls the next highest layers callback + * to inform the layer of the completed transaction and the status of it. + * + ****************************************************************************/ + +static void mac802154_txdone_worker(FAR void *arg) +{ + FAR struct ieee802154_privmac_s *priv = + (FAR struct ieee802154_privmac_s *)arg; + int i = 0; + + /* Get exclusive access to the driver structure. We don't care about any + * signals so if we see one, just go back to trying to get access again. + */ + + while (mac802154_takesem(&priv->exclsem) != 0); + + /* For each pending TX descriptor, send an application callback */ + + for (i = 0; i < priv->txdesc_count; i++) + { + priv->cb->mcps_notify(priv->cb, IEEE802154_NOTIFY_CONF_DATA, + (FAR const union ieee802154_mcps_notify_u *) &priv->txdesc[i]); + } + + /* We've handled all the descriptors and no further desc could have been added + * since we have the struct locked */ + + priv->txdesc_count = 0; + + mac802154_givesem(&priv->exclsem); +} + +/**************************************************************************** + * Name: mac802154_rxframe + * + * Description: + * Called from the radio driver through the callback struct. This function is + * called when the radio has received a frame. The frame is passed in an iob, + * so that we can free it when we are done processing. A pointer to the RX + * descriptor is passed along with the iob, but it must be copied here as it + * is allocated directly on the caller's stack. We simply link the frame, + * copy the RX descriptor, and schedule a worker to process the frame later so + * that we do not hold up the radio. + * + ****************************************************************************/ + +static void mac802154_rxframe(FAR const struct ieee802154_radiocb_s *radiocb, + FAR struct ieee802154_rxdesc_s *rx_desc, + FAR struct iob_s *frame) +{ + FAR struct mac802154_radiocb_s *cb = + (FAR struct mac802154_radiocb_s *)radiocb; + FAR struct ieee802154_privmac_s *priv; + FAR struct ieee802154_rxdesc_s *desc; + + DEBUGASSERT(cb != NULL && cb->priv != NULL); + priv = cb->priv; + + /* Get exclusive access to the driver structure. We don't care about any + * signals so if we see one, just go back to trying to get access again. + */ + + while (mac802154_takesem(&priv->exclsem) != 0); + + /* TODO: Copy the frame descriptor to some type of list */ + + /* Push the iob onto the tail of the frame list for processing */ + + priv->rxframes_tail->io_flink = frame; + priv->rxframes_tail = frame; + + mac802154_givesem(&priv->exclsem); + + /* Schedule work with the work queue to process the completion further */ + + if (work_available(&priv->rx_work)) + { + work_queue(MAC802154_WORK, &priv->rx_work, mac802154_rxframe_worker, + (FAR void *)priv, 0); + } +} + +/**************************************************************************** + * Name: mac802154_rxframe_worker + * + * Description: + * Worker function scheduled from mac802154_rxframe. This function processes + * any frames in the list. Frames intended to be consumed by the MAC layer + * will not produce any callbacks to the next highest layer. Frames intended + * for the application layer will be forwarded to them. + * + ****************************************************************************/ + +static void mac802154_rxframe_worker(FAR void *arg) +{ + FAR struct ieee802154_privmac_s *priv = + (FAR struct ieee802154_privmac_s *)arg; + + /* The radio layer is responsible for handling all ACKs and retries. If for + * some reason an ACK gets here, just throw it out. + */ +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: mac802154_create + * + * Description: + * Create a 802.15.4 MAC device from a 802.15.4 compatible radio device. + * + * The returned MAC structure should be passed to either the next highest + * layer in the network stack, or registered with a mac802154dev character + * or network drivers. In any of these scenarios, the next highest layer + * should register a set of callbacks with the MAC layer by setting the + * mac->cbs member. + * + * NOTE: 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. + * + * Input Parameters: + * radiodev - an instance of an IEEE 802.15.4 radio + * + * Returned Value: + * An opaque reference to the MAC state data. + * + ****************************************************************************/ + +MACHANDLE mac802154_create(FAR struct ieee802154_radio_s *radiodev) +{ + FAR struct ieee802154_privmac_s *mac; + FAR struct ieee802154_radiocb_s *radiocb; + + /* Allocate object */ + + mac = (FAR struct ieee802154_privmac_s *) + kmm_zalloc(sizeof(struct ieee802154_privmac_s)); + + if (mac == NULL) + { + return NULL; + } + + /* Initialize fields */ + + mac->radio = radiodev; + + mac802154_defaultmib(mac); + mac802154_applymib(mac); + + /* Initialize the Radio callbacks */ + + mac->radiocb.priv = mac; + + radiocb = &mac->radiocb.cb; + radiocb->poll_csma = mac802154_poll_csma; + radiocb->poll_gts = mac802154_poll_gts; + radiocb->txdone = mac802154_txdone; + radiocb->rxframe = mac802154_rxframe; + + /* Bind our callback structure */ + + radiodev->ops->bind(radiodev, &mac->radiocb.cb); + + return (MACHANDLE)mac; +} + +/**************************************************************************** + * Name: mac802154_bind + * + * Description: + * Bind the MAC callback table to the MAC state. + * + * Parameters: + * mac - Reference to the MAC driver state structure + * cb - MAC callback operations + * + * Returned Value: + * OK on success; Negated errno on failure. + * + ****************************************************************************/ + +int mac802154_bind(MACHANDLE mac, FAR const struct ieee802154_maccb_s *cb) +{ + FAR struct ieee802154_privmac_s *priv = + (FAR struct ieee802154_privmac_s *)mac; + + priv->cb = cb; + return OK; +} + +/**************************************************************************** + * Name: mac802154_ioctl + * + * Description: + * Handle MAC and radio IOCTL commands directed to the MAC. + * + * Parameters: + * mac - Reference to the MAC driver state structure + * cmd - The IOCTL command + * arg - The argument for the IOCTL command + * + * Returned Value: + * OK on success; Negated errno on failure. + * + ****************************************************************************/ + +int mac802154_ioctl(MACHANDLE mac, int cmd, unsigned long arg) +{ + FAR struct ieee802154_privmac_s *priv = + (FAR struct ieee802154_privmac_s *)mac; + int ret = -EINVAL; + + DEBUGASSERT(priv != NULL); + + /* Check for IOCTLs aimed at the IEEE802.15.4 MAC layer */ + + if (_MAC802154IOCVALID(cmd)) + { + /* Handle the MAC IOCTL command */ +#warning Missing logic + } + + /* No, other IOCTLs must be aimed at the IEEE802.15.4 radio layer */ + + else + { + DEBUGASSERT(priv->radio != NULL && + priv->radio->ops != NULL && + priv->radio->ops->ioctl != NULL); + + ret = priv->radio->ops->ioctl(priv->radio, cmd, arg); + } + + return ret; +} + +/**************************************************************************** + * MAC Interface Operations + ****************************************************************************/ + +/**************************************************************************** + * Name: mac802154_req_data + * + * Description: + * The MCPS-DATA.request primitive requests the transfer of a data SPDU + * (i.e., MSDU) from a local SSCS entity to a single peer SSCS entity. + * Confirmation is returned via the + * struct ieee802154_maccb_s->conf_data callback. + * + ****************************************************************************/ + +int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) +{ + FAR struct ieee802154_privmac_s *priv = + (FAR struct ieee802154_privmac_s *)mac; + FAR struct mac802154_trans_s trans; + struct mac802154_unsec_mhr_s mhr; + int ret; + + /* Start off assuming there is only the frame_control field in the MHR */ + + mhr.length = 2; + + /* Do a preliminary check to make sure the MSDU isn't too long for even + * the best case. + */ + + if (req->msdu_length > IEEE802154_MAX_MAC_PAYLOAD_SIZE) + { + return -EINVAL; + } + + /* Ensure we start with a clear frame control field */ + + mhr.u.frame_control = 0; + + /* Set the frame type to Data */ + + mhr.u.frame_control |= IEEE802154_FRAME_DATA << + IEEE802154_FRAMECTRL_SHIFT_FTYPE; + + /* If the msduLength is greater than aMaxMACSafePayloadSize, the MAC + * sublayer will set the Frame Version to one. [1] pg. 118. + */ + + if (req->msdu_length > IEEE802154_MAX_SAFE_MAC_PAYLOAD_SIZE) + { + mhr.u.frame_control |= IEEE802154_FRAMECTRL_VERSION; + } + + /* If the TXOptions parameter specifies that an acknowledged transmission + * is required, the AR field will be set appropriately, as described in + * 5.1.6.4 [1] pg. 118. + */ + + mhr.u.frame_control |= (req->msdu_flags.ack_tx << + IEEE802154_FRAMECTRL_SHIFT_ACKREQ); + + /* If the destination address is present, copy the PAN ID and one of the + * addresses, depending on mode, into the MHR . + */ + + if (req->dest_addr.mode != IEEE802154_ADDRMODE_NONE) + { + memcpy(&mhr.u.data[mhr.length], &req->dest_addr.panid, 2); + mhr.length += 2; + + if (req->dest_addr.mode == IEEE802154_ADDRMODE_SHORT) + { + memcpy(&mhr.u.data[mhr.length], &req->dest_addr.saddr, 2); + mhr.length += 2; + } + else if (req->dest_addr.mode == IEEE802154_ADDRMODE_EXTENDED) + { + memcpy(&mhr.u.data[mhr.length], &req->dest_addr.eaddr, 8); + mhr.length += 8; + } + } + + /* Set the destination addr mode inside the frame contorl field */ + + mhr.u.frame_control |= (req->dest_addr.mode << + IEEE802154_FRAMECTRL_SHIFT_DADDR); + + /* From this point on, we need exclusive access to the privmac struct */ + + ret = mac802154_takesem(&priv->exclsem); + if (ret < 0) + { + wlerr("ERROR: mac802154_takesem failed: %d\n", ret); + return ret; + } + + /* If both destination and source addressing information is present, the MAC + * sublayer shall compare the destination and source PAN identifiers. + * [1] pg. 41. + */ + + if (req->src_addr_mode != IEEE802154_ADDRMODE_NONE && + req->dest_addr.mode != IEEE802154_ADDRMODE_NONE) + { + /* If the PAN identifiers are identical, the PAN ID Compression field + * shall be set to one, and the source PAN identifier shall be omitted + * from the transmitted frame. [1] pg. 41. + */ + + if (req->dest_addr.panid == priv->addr.panid) + { + mhr.u.frame_control |= IEEE802154_FRAMECTRL_PANIDCOMP; + } + } + + if (req->src_addr_mode != IEEE802154_ADDRMODE_NONE) + { + /* If the destination address is not included, or if PAN ID Compression + * is off, we need to include the Source PAN ID. + */ + + if ((req->dest_addr.mode == IEEE802154_ADDRMODE_NONE) || + (mhr.u.frame_control & IEEE802154_FRAMECTRL_PANIDCOMP)) + { + memcpy(&mhr.u.data[mhr.length], &priv->addr.panid, 2); + mhr.length += 2; + } + + if (req->src_addr_mode == IEEE802154_ADDRMODE_SHORT) + { + memcpy(&mhr.u.data[mhr.length], &priv->addr.saddr, 2); + mhr.length += 2; + } + else if (req->src_addr_mode == IEEE802154_ADDRMODE_EXTENDED) + { + memcpy(&mhr.u.data[mhr.length], &priv->addr.eaddr, 8); + mhr.length += 8; + } + } + + /* Set the source addr mode inside the frame control field */ + + mhr.u.frame_control |= (req->src_addr_mode << + IEEE802154_FRAMECTRL_SHIFT_SADDR); + + /* Each time a data or a MAC command frame is generated, the MAC sublayer + * shall copy the value of macDSN into the Sequence Number field of the MHR + * of the outgoing frame and then increment it by one. [1] pg. 40. + */ + + mhr.u.data[mhr.length++] = priv->dsn++; + + /* Now that we know which fields are included in the header, we can make + * sure we actually have enough room in the PSDU. + */ + + if (mhr.length + req->msdu_length + IEEE802154_MFR_LENGTH > + IEEE802154_MAX_PHY_PACKET_SIZE) + { + return -E2BIG; + } + + trans.mhr_buf = &mhr.u.data[0]; + trans.mhr_len = mhr.length; + + trans.d_buf = &req->msdu[0]; + trans.d_len = req->msdu_length; + + trans.msdu_handle = req->msdu_handle; + + /* If the TxOptions parameter specifies that a GTS transmission is required, + * the MAC sublayer will determine whether it has a valid GTS as described + * 5.1.7.3. If a valid GTS could not be found, the MAC sublayer will discard + * the MSDU. If a valid GTS was found, the MAC sublayer will defer, if + * necessary, until the GTS. If the TxOptions parameter specifies that a GTS + * transmission is not required, the MAC sublayer will transmit the MSDU using + * either slotted CSMA-CA in the CAP for a beacon-enabled PAN or unslotted + * CSMA-CA for a nonbeacon-enabled PAN. Specifying a GTS transmission in the + * TxOptions parameter overrides an indirect transmission request. + * [1] pg. 118. + */ + + if (req->msdu_flags.gts_tx) + { + /* TODO: Support GTS transmission. This should just change where we link + * the transaction. Instead of going in the CSMA transaction list, it + * should be linked to the GTS' transaction list. We'll need to check if + * the GTS is valid, and then find the GTS, before linking. Note, we also + * don't have to try and kick-off any transmission here. + */ + + return -ENOTSUP; + } + else + { + /* If the TxOptions parameter specifies that an indirect transmission is + * required and this primitive is received by the MAC sublayer of a + * coordinator, the data frame is sent using indirect transmission, as + * described in 5.1.5 and 5.1.6.3. [1] + */ + + if (req->msdu_flags.indirect_tx) + { + /* If the TxOptions parameter specifies that an indirect transmission + * is required and if the device receiving this primitive is not a + * coordinator, the destination address is not present, or the + * TxOptions parameter also specifies a GTS transmission, the indirect + * transmission option will be ignored. [1] + */ + + if (priv->is_coord && req->dest_addr.mode != IEEE802154_ADDRMODE_NONE) + { + /* Link the transaction into the indirect_trans list */ + + priv->indirect_tail->flink = &trans; + priv->indirect_tail = &trans; + } + else + { + /* Override the setting since it wasn't valid */ + + req->msdu_flags.indirect_tx = 0; + } + } + + /* If this is a direct transmission not during a GTS */ + + if (!req->msdu_flags.indirect_tx) + { + /* Link the transaction into the CSMA transaction list */ + + priv->csma_tail->flink = &trans; + priv->csma_tail = &trans; + + /* We no longer need to have the MAC layer locked. */ + + mac802154_givesem(&priv->exclsem); + + /* Notify the radio driver that there is data available */ + + priv->radio->ops->txnotify_csma(priv->radio); + + sem_wait(&trans.sem); + } + } + + return OK; +} + + +/**************************************************************************** + * Name: mac802154_req_purge + * + * Description: + * The MCPS-PURGE.request primitive allows the next higher layer to purge + * an MSDU from the transaction queue. Confirmation is returned via + * the struct ieee802154_maccb_s->conf_purge callback. + * + ****************************************************************************/ + +int mac802154_req_purge(MACHANDLE mac, FAR struct ieee802154_purge_req_s *req) +{ + FAR struct ieee802154_privmac_s *priv = + (FAR struct ieee802154_privmac_s *)mac; + return -ENOTTY; +} + +/**************************************************************************** + * Name: mac802154_req_associate + * + * Description: + * The MLME-ASSOCIATE.request primitive allows a device to request an + * association with a coordinator. Confirmation is returned via the + * struct ieee802154_maccb_s->conf_associate callback. + * + ****************************************************************************/ + +int mac802154_req_associate(MACHANDLE mac, + FAR struct ieee802154_assoc_req_s *req) +{ + FAR struct ieee802154_privmac_s *priv = + (FAR struct ieee802154_privmac_s *)mac; + + /* Set the channel of the PHY layer */ + + /* Set the channel page of the PHY layer */ + + /* Set the macPANId */ + + /* Set either the macCoordExtendedAddress and macCoordShortAddress + * depending on the CoordAddrMode in the primitive. + */ + + if (req->coord_addr.mode == IEEE802154_ADDRMODE_EXTENDED) + { + + } + else if (req->coord_addr.mode == IEEE802154_ADDRMODE_EXTENDED) + { + + } + else + { + return -EINVAL; + } + + return -ENOTTY; +} + +/**************************************************************************** + * Name: mac802154_req_disassociate + * + * Description: + * The MLME-DISASSOCIATE.request primitive is used by an associated device to + * notify the coordinator of its intent to leave the PAN. It is also used by + * the coordinator to instruct an associated device to leave the PAN. + * Confirmation is returned via the + * struct ieee802154_maccb_s->conf_disassociate callback. + * + ****************************************************************************/ + +int mac802154_req_disassociate(MACHANDLE mac, + FAR struct ieee802154_disassoc_req_s *req) +{ + FAR struct ieee802154_privmac_s *priv = + (FAR struct ieee802154_privmac_s *)mac; + return -ENOTTY; +} + +/**************************************************************************** + * Name: mac802154_req_get + * + * Description: + * The MLME-GET.request primitive requests information about a given PIB + * attribute. Actual data is returned via the + * struct ieee802154_maccb_s->conf_get callback. + * + ****************************************************************************/ + +int mac802154_req_get(MACHANDLE mac, FAR struct ieee802154_get_req_s *req) +{ + FAR struct ieee802154_privmac_s *priv = + (FAR struct ieee802154_privmac_s *)mac; + return -ENOTTY; +} + +/**************************************************************************** + * Name: mac802154_req_gts + * + * Description: + * The MLME-GTS.request primitive allows a device to send a request to the PAN + * coordinator to allocate a new GTS or to deallocate an existing GTS. + * Confirmation is returned via the + * struct ieee802154_maccb_s->conf_gts callback. + * + ****************************************************************************/ + +int mac802154_req_gts(MACHANDLE mac, FAR struct ieee802154_gts_req_s *req) +{ + FAR struct ieee802154_privmac_s *priv = + (FAR struct ieee802154_privmac_s *)mac; + return -ENOTTY; +} + +/**************************************************************************** + * Name: mac802154_req_reset + * + * Description: + * The MLME-RESET.request primitive allows the next higher layer to request + * that the MLME performs a reset operation. Confirmation is returned via + * the struct ieee802154_maccb_s->conf_reset callback. + * + ****************************************************************************/ + +int mac802154_req_reset(MACHANDLE mac, FAR struct ieee802154_reset_req_s *req) +{ + FAR struct ieee802154_privmac_s * priv = + (FAR struct ieee802154_privmac_s *) mac; + return -ENOTTY; +} + +/**************************************************************************** + * Name: mac802154_req_rxenable + * + * Description: + * The MLME-RX-ENABLE.request primitive allows the next higher layer to + * request that the receiver is enable for a finite period of time. + * Confirmation is returned via the + * struct ieee802154_maccb_s->conf_rxenable callback. + * + ****************************************************************************/ + +int mac802154_req_rxenable(MACHANDLE mac, + FAR struct ieee802154_rxenable_req_s *req) +{ + FAR struct ieee802154_privmac_s * priv = + (FAR struct ieee802154_privmac_s *)mac; + return -ENOTTY; +} + +/**************************************************************************** + * Name: mac802154_req_scan + * + * Description: + * The MLME-SCAN.request primitive is used to initiate a channel scan over a + * given list of channels. A device can use a channel scan to measure the + * energy on the channel, search for the coordinator with which it associated, + * or search for all coordinators transmitting beacon frames within the POS of + * the scanning device. Scan results are returned + * via MULTIPLE calls to the struct ieee802154_maccb_s->conf_scan callback. + * This is a difference with the official 802.15.4 specification, implemented + * here to save memory. + * + ****************************************************************************/ + +int mac802154_req_scan(MACHANDLE mac, FAR struct ieee802154_scan_req_s *req) +{ + FAR struct ieee802154_privmac_s *priv = + (FAR struct ieee802154_privmac_s *)mac; + return -ENOTTY; +} + +/**************************************************************************** + * Name: mac802154_req_set + * + * Description: + * The MLME-SET.request primitive attempts to write the given value to the + * indicated MAC PIB attribute. Confirmation is returned via the + * struct ieee802154_maccb_s->conf_set callback. + * + ****************************************************************************/ + +int mac802154_req_set(MACHANDLE mac, FAR struct ieee802154_set_req_s *req) +{ + FAR struct ieee802154_privmac_s *priv = + (FAR struct ieee802154_privmac_s *)mac; + return -ENOTTY; +} + +/**************************************************************************** + * Name: mac802154_req_start + * + * Description: + * The MLME-START.request primitive makes a request for the device to start + * using a new superframe configuration. Confirmation is returned + * via the struct ieee802154_maccb_s->conf_start callback. + * + ****************************************************************************/ + +int mac802154_req_start(MACHANDLE mac, FAR struct ieee802154_start_req_s *req) +{ + FAR struct ieee802154_privmac_s *priv = + (FAR struct ieee802154_privmac_s *)mac; + return -ENOTTY; +} + +/**************************************************************************** + * Name: mac802154_req_sync + * + * Description: + * The MLME-SYNC.request primitive requests to synchronize with the + * coordinator by acquiring and, if specified, tracking its beacons. + * Confirmation is returned via the + * struct ieee802154_maccb_s->int_commstatus callback. TOCHECK. + * + ****************************************************************************/ + +int mac802154_req_sync(MACHANDLE mac, FAR struct ieee802154_sync_req_s *req) +{ + FAR struct ieee802154_privmac_s *priv = + (FAR struct ieee802154_privmac_s *)mac; + return -ENOTTY; +} + +/**************************************************************************** + * Name: mac802154_req_poll + * + * Description: + * The MLME-POLL.request primitive prompts the device to request data from + * the coordinator. Confirmation is returned via the + * struct ieee802154_maccb_s->conf_poll callback, followed by a + * struct ieee802154_maccb_s->ind_data callback. + * + ****************************************************************************/ + +int mac802154_req_poll(MACHANDLE mac, FAR struct ieee802154_poll_req_s *req) +{ + FAR struct ieee802154_privmac_s *priv = + (FAR struct ieee802154_privmac_s *)mac; + return -ENOTTY; +} + +/**************************************************************************** + * Name: mac802154_rsp_associate + * + * Description: + * The MLME-ASSOCIATE.response primitive is used to initiate a response to + * an MLME-ASSOCIATE.indication primitive. + * + ****************************************************************************/ + +int mac802154_rsp_associate(MACHANDLE mac, + FAR struct ieee802154_assoc_resp_s *resp) +{ + FAR struct ieee802154_privmac_s *priv = + (FAR struct ieee802154_privmac_s *)mac; + return -ENOTTY; +} + +/**************************************************************************** + * Name: mac802154_rsp_orphan + * + * Description: + * The MLME-ORPHAN.response primitive allows the next higher layer of a + * coordinator to respond to the MLME-ORPHAN.indication primitive. + * + ****************************************************************************/ + +int mac802154_rsp_orphan(MACHANDLE mac, + FAR struct ieee802154_orphan_resp_s *resp) +{ + FAR struct ieee802154_privmac_s *priv = + (FAR struct ieee802154_privmac_s *)mac; + return -ENOTTY; +} diff --git a/wireless/ieee802154/mac802154.h b/wireless/ieee802154/mac802154.h index 3b2cd1de5a8..00235d025b2 100644 --- a/wireless/ieee802154/mac802154.h +++ b/wireless/ieee802154/mac802154.h @@ -120,7 +120,7 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req); * ****************************************************************************/ -int mac802154_req_purge(MACHANDLE mac, uint8_t handle); +int mac802154_req_purge(MACHANDLE mac, FAR struct ieee802154_purge_req_s *req); /**************************************************************************** * Name: mac802154_req_associate @@ -162,7 +162,7 @@ int mac802154_req_disassociate(MACHANDLE mac, * ****************************************************************************/ -int mac802154_req_get(MACHANDLE mac, enum ieee802154_pib_attr_e attr); +int mac802154_req_get(MACHANDLE mac, FAR struct ieee802154_get_req_s *req); /**************************************************************************** * Name: mac802154_req_gts @@ -175,7 +175,7 @@ int mac802154_req_get(MACHANDLE mac, enum ieee802154_pib_attr_e attr); * ****************************************************************************/ -int mac802154_req_gts(MACHANDLE mac, FAR uint8_t *characteristics); +int mac802154_req_gts(MACHANDLE mac, FAR struct ieee802154_gts_req_s *req); /**************************************************************************** * Name: mac802154_req_reset @@ -187,7 +187,7 @@ int mac802154_req_gts(MACHANDLE mac, FAR uint8_t *characteristics); * ****************************************************************************/ -int mac802154_req_reset(MACHANDLE mac, bool setdefaults); +int mac802154_req_reset(MACHANDLE mac, FAR struct ieee802154_reset_req_s *req); /**************************************************************************** * Name: mac802154_req_rxenable @@ -200,8 +200,8 @@ int mac802154_req_reset(MACHANDLE mac, bool setdefaults); * ****************************************************************************/ -int mac802154_req_rxenable(MACHANDLE mac, bool deferrable, int ontime, - int duration); +int mac802154_req_rxenable(MACHANDLE mac, + FAR struct ieee802154_rxenable_req_s *req); /**************************************************************************** * Name: mac802154_req_scan @@ -218,8 +218,7 @@ int mac802154_req_rxenable(MACHANDLE mac, bool deferrable, int ontime, * ****************************************************************************/ -int mac802154_req_scan(MACHANDLE mac, uint8_t type, uint32_t channels, - int duration); +int mac802154_req_scan(MACHANDLE mac, FAR struct ieee802154_scan_req_s *req); /**************************************************************************** * Name: mac802154_req_set @@ -231,8 +230,7 @@ int mac802154_req_scan(MACHANDLE mac, uint8_t type, uint32_t channels, * ****************************************************************************/ -int mac802154_req_set(MACHANDLE mac, int attribute, FAR uint8_t *value, - int valuelen); +int mac802154_req_set(MACHANDLE mac, FAR struct ieee802154_set_req_s *req); /**************************************************************************** * Name: mac802154_req_start @@ -244,9 +242,7 @@ int mac802154_req_set(MACHANDLE mac, int attribute, FAR uint8_t *value, * ****************************************************************************/ -int mac802154_req_start(MACHANDLE mac, uint16_t panid, int channel, - uint8_t bo, uint8_t fo, bool coord, bool batext, - bool realign); +int mac802154_req_start(MACHANDLE mac, FAR struct ieee802154_start_req_s *req); /**************************************************************************** * Name: mac802154_req_sync @@ -259,7 +255,7 @@ int mac802154_req_start(MACHANDLE mac, uint16_t panid, int channel, * ****************************************************************************/ -int mac802154_req_sync(MACHANDLE mac, int channel, bool track); +int mac802154_req_sync(MACHANDLE mac, FAR struct ieee802154_sync_req_s *req); /**************************************************************************** * Name: mac802154_req_poll @@ -272,7 +268,7 @@ int mac802154_req_sync(MACHANDLE mac, int channel, bool track); * ****************************************************************************/ -int mac802154_req_poll(MACHANDLE mac, FAR uint8_t *coordaddr); +int mac802154_req_poll(MACHANDLE mac, FAR struct ieee802154_poll_req_s *req); /**************************************************************************** * Name: mac802154_rsp_associate @@ -283,8 +279,8 @@ int mac802154_req_poll(MACHANDLE mac, FAR uint8_t *coordaddr); * ****************************************************************************/ -int mac802154_rsp_associate(MACHANDLE mac, uint8_t eadr, uint16_t saddr, - int status); +int mac802154_rsp_associate(MACHANDLE mac, + FAR struct ieee802154_assoc_resp_s *resp); /**************************************************************************** * Name: mac802154_rsp_orphan @@ -295,8 +291,8 @@ int mac802154_rsp_associate(MACHANDLE mac, uint8_t eadr, uint16_t saddr, * ****************************************************************************/ -int mac802154_rsp_orphan(MACHANDLE mac, FAR uint8_t *orphanaddr, - uint16_t saddr, bool associated); +int mac802154_rsp_orphan(MACHANDLE mac, + FAR struct ieee802154_orphan_resp_s *resp); #undef EXTERN #ifdef __cplusplus diff --git a/wireless/ieee802154/mac802154_device.c b/wireless/ieee802154/mac802154_device.c index 6370ff47623..19d3a5bc410 100644 --- a/wireless/ieee802154/mac802154_device.c +++ b/wireless/ieee802154/mac802154_device.c @@ -139,6 +139,14 @@ struct mac802154_chardevice_s static inline int mac802154dev_takesem(sem_t *sem); #define mac802154dev_givesem(s) sem_post(s); +static void mac802154dev_mlme_notify(FAR const struct ieee802154_maccb_s *maccb, + enum ieee802154_macnotify_e notif, + FAR const union ieee802154_mlme_notify_u *arg); + +static void mac802154dev_mcps_notify(FAR const struct ieee802154_maccb_s *maccb, + enum ieee802154_macnotify_e notif, + FAR const union ieee802154_mcps_notify_u *arg); + static int mac802154dev_open(FAR struct file *filep); static int mac802154dev_close(FAR struct file *filep); static ssize_t mac802154dev_read(FAR struct file *filep, FAR char *buffer, @@ -151,7 +159,7 @@ static int mac802154dev_ioctl(FAR struct file *filep, int cmd, /* MAC callback helpers */ static void mac802154dev_conf_data(FAR struct mac802154_chardevice_s *dev, - FAR struct ieee802154_data_conf_s *conf); + FAR const struct ieee802154_data_conf_s *conf); /**************************************************************************** * Private Data @@ -591,9 +599,9 @@ static int mac802154dev_ioctl(FAR struct file *filep, int cmd, return ret; } -static void mac802154dev_mlme_notify(FAR struct ieee802154_maccb_s *maccb, +static void mac802154dev_mlme_notify(FAR const struct ieee802154_maccb_s *maccb, enum ieee802154_macnotify_e notif, - FAR union ieee802154_mlme_notify_u *arg) + FAR const union ieee802154_mlme_notify_u *arg) { FAR struct mac802154dev_callback_s *cb = (FAR struct mac802154dev_callback_s *)maccb; @@ -610,9 +618,9 @@ static void mac802154dev_mlme_notify(FAR struct ieee802154_maccb_s *maccb, } } -static void mac802154dev_mcps_notify(FAR struct ieee802154_maccb_s *maccb, +static void mac802154dev_mcps_notify(FAR const struct ieee802154_maccb_s *maccb, enum ieee802154_macnotify_e notif, - FAR union ieee802154_mcps_notify_u *arg) + FAR const union ieee802154_mcps_notify_u *arg) { FAR struct mac802154dev_callback_s *cb = (FAR struct mac802154dev_callback_s *)maccb; @@ -634,7 +642,7 @@ static void mac802154dev_mcps_notify(FAR struct ieee802154_maccb_s *maccb, } static void mac802154dev_conf_data(FAR struct mac802154_chardevice_s *dev, - FAR struct ieee802154_data_conf_s *conf) + FAR const struct ieee802154_data_conf_s *conf) { FAR struct mac802154dev_dwait_s *curr; FAR struct mac802154dev_dwait_s *prev; @@ -647,7 +655,7 @@ static void mac802154dev_conf_data(FAR struct mac802154_chardevice_s *dev, /* Search to see if there is a dwait pending for this transaction */ for (prev = NULL, curr = dev->md_dwait; - curr && curr->mw_handle != conf->msdu_handle; + curr && curr->mw_handle != conf->handle; prev = curr, curr = curr->mw_flink); /* If a dwait is found */ @@ -669,7 +677,7 @@ static void mac802154dev_conf_data(FAR struct mac802154_chardevice_s *dev, /* Copy the transmission status into the dwait struct */ - curr->mw_status = conf->msdu_handle; + curr->mw_status = conf->status; /* Wake the thread waiting for the data transmission */ diff --git a/wireless/ieee802154/radio802154_device.c b/wireless/ieee802154/radio802154_device.c index a1fe8dc515e..2c48e107d0b 100644 --- a/wireless/ieee802154/radio802154_device.c +++ b/wireless/ieee802154/radio802154_device.c @@ -254,13 +254,13 @@ static ssize_t radio802154dev_read(FAR struct file *filep, FAR char *buffer, siz goto done; } - ret = dev->child->ops->rxenable(dev->child, 1, buf); +#warning Receive needs to be redone! #if 0 + ret = dev->child->ops->rxenable(dev->child, 1, buf); if (ret < 0) { goto done; } -#endif /* if no packet is received, this will produce -EAGAIN * The user is responsible for sleeping until sth arrives @@ -282,6 +282,8 @@ static ssize_t radio802154dev_read(FAR struct file *filep, FAR char *buffer, siz dev->child->ops->rxenable(dev->child, 0, NULL); ret = buf->len; +#endif + done: return ret; } From 804395e2c69bf711167ba2f42c52aa329ebaa024 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 26 Apr 2017 10:40:39 -0600 Subject: [PATCH 105/183] Remove /configs/clicker2-stm32/mrf24j40-radio/setenv.sh --- .../clicker2-stm32/mrf24j40-radio/setenv.sh | 80 ------------------- 1 file changed, 80 deletions(-) delete mode 100644 configs/clicker2-stm32/mrf24j40-radio/setenv.sh diff --git a/configs/clicker2-stm32/mrf24j40-radio/setenv.sh b/configs/clicker2-stm32/mrf24j40-radio/setenv.sh deleted file mode 100644 index a235db68fb3..00000000000 --- a/configs/clicker2-stm32/mrf24j40-radio/setenv.sh +++ /dev/null @@ -1,80 +0,0 @@ -#!/bin/bash -# configs/clicker2-stm32/mrf24j40-radio/setenv.sh -# -# Copyright (C) 2017 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# - -if [ "$_" = "$0" ] ; then - echo "You must source this script, not run it!" 1>&2 - exit 1 -fi - -WD=`pwd` -if [ ! -x "setenv.sh" ]; then - echo "This script must be executed from the top-level NuttX build directory" - exit 1 -fi - -if [ -z "${PATH_ORIG}" ]; then - export PATH_ORIG="${PATH}" -fi - -# This is the Cygwin path to the location where I installed the CodeSourcery -# toolchain under windows. You will also have to edit this if you install -# the CodeSourcery toolchain in any other location -#export TOOLCHAIN_BIN="/cygdrive/c/Program Files (x86)/CodeSourcery/Sourcery G++ Lite/bin" -#export TOOLCHAIN_BIN="/cygdrive/c/Program Files (x86)/CodeSourcery/Sourcery_CodeBench_Lite_for_ARM_EABI/bin" -# export TOOLCHAIN_BIN="/cygdrive/c/Users/MyName/MentorGraphics/Sourcery_CodeBench_Lite_for_ARM_EABI/bin" - -# This is the location where I installed the ARM "GNU Tools for ARM Embedded Processors" -# You can this free toolchain here https://launchpad.net/gcc-arm-embedded -export TOOLCHAIN_BIN="/cygdrive/c/Program Files (x86)/GNU Tools ARM Embedded/4.9 2015q2/bin" - -# This is the path to the location where I installed the devkitARM toolchain -# You can get this free toolchain from http://devkitpro.org/ or http://sourceforge.net/projects/devkitpro/ -#export TOOLCHAIN_BIN="/cygdrive/c/Program Files (x86)/devkitARM/bin" - -# These are the Cygwin paths to the locations where I installed the Atollic -# toolchain under windows. You will also have to edit this if you install -# the Atollic toolchain in any other location. /usr/bin is added before -# the Atollic bin path because there is are binaries named gcc.exe and g++.exe -# at those locations as well. -#export TOOLCHAIN_BIN="/usr/bin:/cygdrive/c/Program Files (x86)/Atollic/TrueSTUDIO for ARM Pro 2.3.0/ARMTools/bin" -#export TOOLCHAIN_BIN="/usr/bin:/cygdrive/c/Program Files (x86)/Atollic/TrueSTUDIO for STMicroelectronics STM32 Lite 2.3.0/ARMTools/bin" - -# This is the Cygwin path to the location where I build the buildroot -# toolchain. -# export TOOLCHAIN_BIN="${WD}/../buildroot/build_arm_nofpu/staging_dir/bin" - -# Add the path to the toolchain to the PATH varialble -export PATH="${TOOLCHAIN_BIN}:/sbin:/usr/sbin:${PATH_ORIG}" - -echo "PATH : ${PATH}" From 414516be20936d766d135f767bec42925d70c40c Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 27 Apr 2017 17:11:07 -0600 Subject: [PATCH 106/183] IEEE 802.15.4: Move MAC character driver IOCTL commands from ieee802154_mac.h to ieee802154_ioctl.h --- .../wireless/ieee802154/ieee802154_ioctl.h | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 include/nuttx/wireless/ieee802154/ieee802154_ioctl.h diff --git a/include/nuttx/wireless/ieee802154/ieee802154_ioctl.h b/include/nuttx/wireless/ieee802154/ieee802154_ioctl.h new file mode 100644 index 00000000000..24ac37369f7 --- /dev/null +++ b/include/nuttx/wireless/ieee802154/ieee802154_ioctl.h @@ -0,0 +1,73 @@ +/************************************************************************************ + * include/nuttx/wireless/ieee802154/ieee802154_ioctl.h + * IEEE802.15.4 character driver IOCTL commands + * + * Copyright (C) 2017 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ************************************************************************************/ + +/* This file includes common definitions to be used in all wireless character drivers + * (when applicable). + */ + +#ifndef __INCLUDE_NUTTX_WIRELESS_IEEE802154_IEEE802154_IOCTL_H +#define __INCLUDE_NUTTX_WIRELESS_IEEE802154_IEEE802154_IOCTL_H + +/************************************************************************************ + * Included Files + ************************************************************************************/ + +#include +#include + +#ifdef CONFIG_WIRELESS_IEEE802154 + +/************************************************************************************ + * Pre-processor Definitions + ************************************************************************************/ + +/* IEEE 802.15.4 Radio Character Driver IOCTL commands ******************************/ +/* None defined */ + +/* IEEE 802.15.4 MAC Character Driver IOCTL commands ********************************/ + + +#define MAC802154IOC_MCPS_REGISTER _WLCIOC(IEEE802154_FIRST) +#define MAC802154IOC_MLME_REGISTER _WLCIOC(IEEE802154_FIRST+1) + +/************************************************************************************ + * Public Types + ************************************************************************************/ + +/* To be provided */ + +#endif /* CONFIG_WIRELESS_IEEE802154 */ +#endif /* __INCLUDE_NUTTX_WIRELESS_IEEE802154_IEEE802154_IOCTL_H */ From 84a79502a2cdea1fac16a43e15f6b2af519e77f6 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 27 Apr 2017 17:11:36 -0600 Subject: [PATCH 107/183] IEEE 802.15.4: Move MAC character driver IOCTL commands from ieee802154_mac.h to ieee802154_ioctl.h --- include/nuttx/wireless/ieee802154/ieee802154_mac.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/include/nuttx/wireless/ieee802154/ieee802154_mac.h b/include/nuttx/wireless/ieee802154/ieee802154_mac.h index e1aca5de757..fc2b57c8f74 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_mac.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_mac.h @@ -85,9 +85,6 @@ * Request and Response primitives. */ -#define MAC802154IOC_MCPS_REGISTER _MAC802154IOC(0x0001) - -#define MAC802154IOC_MLME_REGISTER _MAC802154IOC(0x0002) #define MAC802154IOC_MLME_ASSOC_REQUEST _MAC802154IOC(0x0003) #define MAC802154IOC_MLME_ASSOC_RESPONSE _MAC802154IOC(0x0004) #define MAC802154IOC_MLME_DISASSOC_REQUEST _MAC802154IOC(0x0005) @@ -1290,8 +1287,6 @@ union ieee802154_mcps_notify_u union ieee802154_macarg_u { - union ieee802154_mcps_notify_u mcpsnotify; /* MAC802154IOC_MCPS_REGISTER */ - union ieee802154_mlme_notify_u mlmenotify; /* MAC802154IOC_MLME_REGISTER */ struct ieee802154_assoc_req_s assocreq; /* MAC802154IOC_MLME_ASSOC_REQUEST */ struct ieee802154_assoc_resp_s assocresp; /* MAC802154IOC_MLME_ASSOC_RESPONSE */ struct ieee802154_disassoc_req_s disassocreq; /* MAC802154IOC_MLME_DISASSOC_REQUEST */ From 1b3ab950a4f4e463b2e6f8d041da301537caebf1 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 27 Apr 2017 17:44:07 -0600 Subject: [PATCH 108/183] STM32F103-Mininum: Rename an incorrectly named file. --- configs/stm32f103-minimum/src/Makefile | 2 +- .../src/{stm32_cc3000.c => stm32_nrf24l01.c} | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) rename configs/stm32f103-minimum/src/{stm32_cc3000.c => stm32_nrf24l01.c} (95%) diff --git a/configs/stm32f103-minimum/src/Makefile b/configs/stm32f103-minimum/src/Makefile index 75b6cb29532..8402e553eab 100644 --- a/configs/stm32f103-minimum/src/Makefile +++ b/configs/stm32f103-minimum/src/Makefile @@ -86,7 +86,7 @@ CSRCS += stm32_veml6070.c endif ifeq ($(CONFIG_WL_NRF24L01),y) -CSRCS += stm32_cc3000.c +CSRCS += stm32_nrf24l01.c endif ifeq ($(CONFIG_USBDEV),y) diff --git a/configs/stm32f103-minimum/src/stm32_cc3000.c b/configs/stm32f103-minimum/src/stm32_nrf24l01.c similarity index 95% rename from configs/stm32f103-minimum/src/stm32_cc3000.c rename to configs/stm32f103-minimum/src/stm32_nrf24l01.c index 23b1144ef51..6edecba0e01 100644 --- a/configs/stm32f103-minimum/src/stm32_cc3000.c +++ b/configs/stm32f103-minimum/src/stm32_nrf24l01.c @@ -1,5 +1,5 @@ /************************************************************************************ - * configs/stm32f103-minimum//src/stm32_cc3000.c + * configs/stm32f103-minimum//src/stm32_nrf24l01.c * * Copyright (C) 2017 Gregory Nutt. All rights reserved. * Author: Laurent Latil @@ -82,7 +82,7 @@ static FAR void *g_arg; static int stm32tiny_wl_irq_attach(xcpt_t isr, FAR void *arg) { - winfo("Attach IRQ\n"); + wlinfo("Attach IRQ\n"); g_isr = isr; g_arg = arg; (void)stm32_gpiosetevent(GPIO_NRF24L01_IRQ, false, true, false, g_isr, g_arg); @@ -91,7 +91,7 @@ static int stm32tiny_wl_irq_attach(xcpt_t isr, FAR void *arg) static void stm32tiny_wl_chip_enable(bool enable) { - winfo("CE:%d\n", enable); + wlinfo("CE:%d\n", enable); stm32_gpiowrite(GPIO_NRF24L01_CE, enable); } @@ -132,14 +132,14 @@ void stm32_wlinitialize(void) spidev = stm32_spibus_initialize(1); if (!spidev) { - werr("ERROR: Failed to initialize SPI bus\n"); + wlerr("ERROR: Failed to initialize SPI bus\n"); return; } result = nrf24l01_register(spidev, &nrf_cfg); if (result != OK) { - werr("ERROR: Failed to register initialize SPI bus\n"); + wlerr("ERROR: Failed to register initialize SPI bus\n"); return; } } From 1c3d0cbbdd33165a7a1292612fe519a358874fae Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 28 Apr 2017 12:41:51 -0600 Subject: [PATCH 109/183] Add all ieee802.15.4 IOCTLs to include/sys/ioctl.h --- include/sys/ioctl.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/include/sys/ioctl.h b/include/sys/ioctl.h index acbcc1d3e66..e993a8d6b94 100644 --- a/include/sys/ioctl.h +++ b/include/sys/ioctl.h @@ -63,6 +63,27 @@ # include #endif + +#ifdef CONFIG_WIRELESS_IEEE802154 +#ifdef CONFIG_IEEE802154_DEV +/* Include ieee802.15.4 radio IOCTL definitions */ + +# include +#endif + +#ifdef CONFIG_IEEE802154_MAC +/* Include ieee802.15.4 MAC IOCTL definitions */ + +# include +#endif + +#ifdef CONFIG_IEEE802154_MAC_DEV +/* Include ieee802.15.4 character driver IOCTL definitions */ + +# include +#endif + +#endif /* CONFIG_WIRELESS_IEEE802154 */ #endif /* CONFIG_NSOCKET_DESCRIPTORS > 0 */ /**************************************************************************** From 80bca0736dedd9c2f3ee3b9a04eb45364d1d9fa4 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 29 Apr 2017 10:26:02 -0600 Subject: [PATCH 110/183] Update some changes from last merge that are needed on this branch. --- net/sixlowpan/sixlowpan_framelist.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/sixlowpan/sixlowpan_framelist.c b/net/sixlowpan/sixlowpan_framelist.c index ed7cb345a2a..91e3369b819 100644 --- a/net/sixlowpan/sixlowpan_framelist.c +++ b/net/sixlowpan/sixlowpan_framelist.c @@ -452,7 +452,7 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, g_pktattrs[PACKETBUF_ATTR_MAC_SEQNO] = 0; - verify = sixlowpan_framecreate(ieee, iob, ieee->i_panid); + verify = sixlowpan_framecreate(ieee, iob, dest_panid); DEBUGASSERT(verify == framer_hdrlen); UNUSED(verify); From c7264eb5507cee8203d16641902c5f6329c3ad64 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 29 Apr 2017 12:28:19 -0600 Subject: [PATCH 111/183] Add an instance argument to the SPIDEV definitions. --- drivers/wireless/ieee802154/at86rf23x.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/wireless/ieee802154/at86rf23x.c b/drivers/wireless/ieee802154/at86rf23x.c index e3429c4d1fa..8037c4005a7 100644 --- a/drivers/wireless/ieee802154/at86rf23x.c +++ b/drivers/wireless/ieee802154/at86rf23x.c @@ -265,9 +265,9 @@ static void at86rf23x_setreg(FAR struct spi_dev_s *spi, uint32_t addr, reg[1] = val; at86rf23x_lock(spi); - SPI_SELECT(spi, SPIDEV_IEEE802154, true); + SPI_SELECT(spi, SPIDEV_IEEE802154(0), true); SPI_SNDBLOCK(spi, reg, 2); - SPI_SELECT(spi, SPIDEV_IEEE802154, false); + SPI_SELECT(spi, SPIDEV_IEEE802154(0), false); at86rf23x_unlock(spi); wlinfo("0x%02X->r[0x%02X]\n", val, addr); @@ -292,9 +292,9 @@ static uint8_t at86rf23x_getreg(FAR struct spi_dev_s *spi, uint32_t addr) at86rf23x_lock (spi); - SPI_SELECT(spi, SPIDEV_IEEE802154, true); + SPI_SELECT(spi, SPIDEV_IEEE802154(0), true); SPI_EXCHANGE(spi, reg, val, 2); - SPI_SELECT(spi, SPIDEV_IEEE802154, false); + SPI_SELECT(spi, SPIDEV_IEEE802154(0), false); at86rf23x_unlock(spi); @@ -359,12 +359,12 @@ static int at86rf23x_writeframe(FAR struct spi_dev_s *spi, FAR uint8_t *frame, at86rf23x_lock(spi); - SPI_SELECT(spi, SPIDEV_IEEE802154, true); + SPI_SELECT(spi, SPIDEV_IEEE802154(0), true); SPI_SNDBLOCK(spi, ®, 1); SPI_SNDBLOCK(spi, &frame, len); - SPI_SELECT(spi, SPIDEV_IEEE802154, false); + SPI_SELECT(spi, SPIDEV_IEEE802154(0), false); at86rf23x_unlock(spi); @@ -388,13 +388,13 @@ static uint8_t at86rf23x_readframe(FAR struct spi_dev_s *spi, reg = RF23X_SPI_FRAME_READ; at86rf23x_lock(spi); - SPI_SELECT(spi, SPIDEV_IEEE802154, true); + SPI_SELECT(spi, SPIDEV_IEEE802154(0), true); SPI_SNDBLOCK(spi, ®, 1); SPI_RECVBLOCK(spi, &len, 1); SPI_RECVBLOCK(spi, frame_rx, len+3); - SPI_SELECT(spi, SPIDEV_IEEE802154, false); + SPI_SELECT(spi, SPIDEV_IEEE802154(0), false); at86rf23x_unlock(spi); return len; From b1ff257215280007303b7d5a173246e7333feb47 Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Mon, 1 May 2017 09:27:06 -0400 Subject: [PATCH 112/183] wireless/ieee802154: Minor fixes to account for moved IOCTL definitions --- include/nuttx/wireless/ieee802154/ieee802154_ioctl.h | 6 +++++- wireless/ieee802154/mac802154_device.c | 6 +----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/nuttx/wireless/ieee802154/ieee802154_ioctl.h b/include/nuttx/wireless/ieee802154/ieee802154_ioctl.h index 24ac37369f7..533e2f38535 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_ioctl.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_ioctl.h @@ -67,7 +67,11 @@ * Public Types ************************************************************************************/ -/* To be provided */ +struct mac802154dev_notify_s +{ + uint8_t mn_signo; /* Signal number to use in the notification */ +}; + #endif /* CONFIG_WIRELESS_IEEE802154 */ #endif /* __INCLUDE_NUTTX_WIRELESS_IEEE802154_IEEE802154_IOCTL_H */ diff --git a/wireless/ieee802154/mac802154_device.c b/wireless/ieee802154/mac802154_device.c index 19d3a5bc410..9721a5a7fe8 100644 --- a/wireless/ieee802154/mac802154_device.c +++ b/wireless/ieee802154/mac802154_device.c @@ -50,6 +50,7 @@ #include #include +#include #include #include "mac802154.h" @@ -67,11 +68,6 @@ * Private Types ****************************************************************************/ -struct mac802154dev_notify_s -{ - uint8_t mn_signo; /* Signal number to use in the notification */ -}; - /* This structure describes the state of one open mac driver instance */ struct mac802154dev_open_s From c4007a111c2d22abd25320386d8999c3599a23ae Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Mon, 1 May 2017 09:27:40 -0400 Subject: [PATCH 113/183] wireless/ieee802154: Fixes semaphore logic and list logic --- drivers/wireless/ieee802154/mrf24j40.c | 4 + .../wireless/ieee802154/ieee802154_mac.h | 5 +- wireless/ieee802154/mac802154.c | 94 +++++++++++++++++-- wireless/ieee802154/mac802154_device.c | 8 +- 4 files changed, 97 insertions(+), 14 deletions(-) diff --git a/drivers/wireless/ieee802154/mrf24j40.c b/drivers/wireless/ieee802154/mrf24j40.c index e65e48c108a..6b602b739d2 100644 --- a/drivers/wireless/ieee802154/mrf24j40.c +++ b/drivers/wireless/ieee802154/mrf24j40.c @@ -1819,6 +1819,10 @@ FAR struct ieee802154_radio_s *mrf24j40_init(FAR struct spi_dev_s *spi, return NULL; } + /* Allow exclusive access to the privmac struct */ + + sem_init(&dev->exclsem, 0, 1); + dev->radio.ops = &mrf24j40_devops; dev->lower = lower; diff --git a/include/nuttx/wireless/ieee802154/ieee802154_mac.h b/include/nuttx/wireless/ieee802154/ieee802154_mac.h index fc2b57c8f74..1a8e324ce21 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_mac.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_mac.h @@ -536,11 +536,12 @@ struct ieee802154_data_req_s * to continue and make the struct "variable length" */ - uint8_t msdu[1]; + uint8_t msdu[IEEE802154_MAX_MAC_PAYLOAD_SIZE]; }; #define SIZEOF_IEEE802154_DATA_REQ_S(n) \ - (sizeof(struct ieee802154_data_req_s) + (n) - 1) + (sizeof(struct ieee802154_data_req_s) \ + - IEEE802154_MAX_MAC_PAYLOAD_SIZE + (n)) /***************************************************************************** * Primitive: MCPS-DATA.confirm diff --git a/wireless/ieee802154/mac802154.c b/wireless/ieee802154/mac802154.c index 54e5782b41b..f6b5f5f455d 100644 --- a/wireless/ieee802154/mac802154.c +++ b/wireless/ieee802154/mac802154.c @@ -337,6 +337,78 @@ static inline int mac802154_takesem(sem_t *sem) return OK; } +/**************************************************************************** + * Name: mac802154_push_csma + * + * Description: + * Push a CSMA transaction onto the list + * + ****************************************************************************/ + +static void mac802154_push_csma(FAR struct ieee802154_privmac_s *priv, + FAR struct mac802154_trans_s *trans) +{ + /* Ensure the transactions forward link is NULL */ + + trans->flink = NULL; + + /* If the tail is not empty, make the transaction pointed to by the tail, + * point to the new transaction */ + + if (priv->csma_tail != NULL) + { + priv->csma_tail->flink = trans; + } + + /* Point the tail at the new transaction */ + + priv->csma_tail = trans; + + /* If the head is NULL, we need to point it at the transaction since there + * is only one transaction in the list at this point */ + + if (priv->csma_head == NULL) + { + priv->csma_head = trans; + } +} + +/**************************************************************************** + * Name: mac802154_pop_csma + * + * Description: + * Pop a CSMA transaction from the list + * + ****************************************************************************/ + +static FAR struct mac802154_trans_s * + mac802154_pop_csma(FAR struct ieee802154_privmac_s *priv) +{ + FAR struct mac802154_trans_s *trans; + + if (priv->csma_head == NULL) + { + return NULL; + } + + /* Get the transaction from the head of the list */ + + trans = priv->csma_head; + + /* Move the head pointer to the next transaction */ + + priv->csma_head = trans->flink; + + /* If the head is now NULL, the list is empty, so clear the tail too */ + + if (priv->csma_head == NULL) + { + priv->csma_tail = NULL; + } + + return trans; +} + /**************************************************************************** * Name: mac802154_defaultmib * @@ -398,14 +470,11 @@ static int mac802154_poll_csma(FAR const struct ieee802154_radiocb_s *radiocb, /* Check to see if there are any CSMA transactions waiting */ - if (priv->csma_head) + trans = mac802154_pop_csma(priv); + mac802154_givesem(&priv->exclsem); + + if (trans != NULL) { - /* Pop a CSMA transaction off the list */ - - trans = priv->csma_head; - priv->csma_head = priv->csma_head->flink; - - mac802154_givesem(&priv->exclsem); /* Setup the transmit descriptor */ @@ -426,7 +495,6 @@ static int mac802154_poll_csma(FAR const struct ieee802154_radiocb_s *radiocb, return (trans->mhr_len + trans->d_len); } - mac802154_givesem(&priv->exclsem); return 0; } @@ -673,6 +741,10 @@ MACHANDLE mac802154_create(FAR struct ieee802154_radio_s *radiodev) { return NULL; } + + /* Allow exclusive access to the privmac struct */ + + sem_init(&mac->exclsem, 0, 1); /* Initialize fields */ @@ -939,6 +1011,8 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) trans.msdu_handle = req->msdu_handle; + sem_init(&trans.sem, 0, 1); + /* If the TxOptions parameter specifies that a GTS transmission is required, * the MAC sublayer will determine whether it has a valid GTS as described * 5.1.7.3. If a valid GTS could not be found, the MAC sublayer will discard @@ -1000,8 +1074,7 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) { /* Link the transaction into the CSMA transaction list */ - priv->csma_tail->flink = &trans; - priv->csma_tail = &trans; + mac802154_push_csma(priv, &trans); /* We no longer need to have the MAC layer locked. */ @@ -1015,6 +1088,7 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) } } + sem_destroy(&trans.sem); return OK; } diff --git a/wireless/ieee802154/mac802154_device.c b/wireless/ieee802154/mac802154_device.c index 9721a5a7fe8..5c31cdf1402 100644 --- a/wireless/ieee802154/mac802154_device.c +++ b/wireless/ieee802154/mac802154_device.c @@ -425,8 +425,8 @@ static ssize_t mac802154dev_write(FAR struct file *filep, /* Check to make sure that the buffer is big enough to hold at least one * packet. */ - if ((len >= SIZEOF_IEEE802154_DATA_REQ_S(1)) && - (len <= SIZEOF_IEEE802154_DATA_REQ_S(IEEE802154_MAX_MAC_PAYLOAD_SIZE))) + if ((len < SIZEOF_IEEE802154_DATA_REQ_S(1)) || + (len > SIZEOF_IEEE802154_DATA_REQ_S(IEEE802154_MAX_MAC_PAYLOAD_SIZE))) { wlerr("ERROR: buffer isn't an ieee802154_data_req_s: %lu\n", (unsigned long)len); @@ -463,6 +463,8 @@ static ssize_t mac802154dev_write(FAR struct file *filep, dwait.mw_flink = dev->md_dwait; dev->md_dwait = &dwait; + sem_init(&dwait.mw_sem, 0, 1); + mac802154dev_givesem(&dev->md_exclsem); } @@ -484,6 +486,7 @@ static ssize_t mac802154dev_write(FAR struct file *filep, { /* This should only happen if the wait was canceled by an signal */ + sem_destroy(&dwait.mw_sem); DEBUGASSERT(errno == EINTR); return -EINTR; } @@ -493,6 +496,7 @@ static ssize_t mac802154dev_write(FAR struct file *filep, * the list in order to perform the sem_post. */ + sem_destroy(&dwait.mw_sem); return dwait.mw_status; } From f02d98d15e27f5c28dfd48ffbc88623f6129433c Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Tue, 2 May 2017 09:12:56 -0400 Subject: [PATCH 114/183] wireless/ieee802154: Changes transmit data path to use IOBs and exposes function for getting size of MAC header --- drivers/wireless/ieee802154/mrf24j40.c | 108 +++----- .../wireless/ieee802154/ieee802154_ioctl.h | 5 + .../wireless/ieee802154/ieee802154_mac.h | 40 ++- .../wireless/ieee802154/ieee802154_radio.h | 8 +- wireless/ieee802154/mac802154.c | 242 +++++++++++------- wireless/ieee802154/mac802154.h | 11 + wireless/ieee802154/mac802154_device.c | 63 +++-- 7 files changed, 262 insertions(+), 215 deletions(-) diff --git a/drivers/wireless/ieee802154/mrf24j40.c b/drivers/wireless/ieee802154/mrf24j40.c index 6b602b739d2..f883b55054a 100644 --- a/drivers/wireless/ieee802154/mrf24j40.c +++ b/drivers/wireless/ieee802154/mrf24j40.c @@ -138,9 +138,10 @@ struct mrf24j40_radio_s /* Buffer Allocations */ struct mrf24j40_txdesc_s csma_desc; - struct mrf24j40_txdesc_s gts_desc[MRF24J40_GTS_SLOTS]; + FAR struct iob_s *csma_frame; - uint8_t tx_buf[IEEE802154_MAX_PHY_PACKET_SIZE]; + struct mrf24j40_txdesc_s gts_desc[MRF24J40_GTS_SLOTS]; + FAR struct iob_s *gts_frame[MRF24J40_GTS_SLOTS]; }; /**************************************************************************** @@ -174,11 +175,11 @@ static void mrf24j40_dopoll_csma(FAR void *arg); static void mrf24j40_dopoll_gts(FAR void *arg); static int mrf24j40_csma_setup(FAR struct mrf24j40_radio_s *dev, - FAR uint8_t *buf, uint16_t buf_len); + FAR struct iob_s *frame); static int mrf24j40_gts_setup(FAR struct mrf24j40_radio_s *dev, uint8_t gts, - FAR uint8_t *buf, uint16_t buf_len); + FAR struct iob_s *frame); static int mrf24j40_setup_fifo(FAR struct mrf24j40_radio_s *dev, - FAR uint8_t *buf, uint16_t buf_len, uint32_t fifo_addr); + FAR struct iob_s *frame, uint32_t fifo_addr); /* IOCTL helpers */ @@ -224,10 +225,8 @@ static int mrf24j40_bind(FAR struct ieee802154_radio_s *radio, static int mrf24j40_ioctl(FAR struct ieee802154_radio_s *radio, int cmd, unsigned long arg); static int mrf24j40_rxenable(FAR struct ieee802154_radio_s *radio); -static int mrf24j40_transmit(FAR struct ieee802154_radio_s *radio, - FAR uint8_t *buf, uint16_t buf_len); -static int mrf24j40_txnotify_csma(FAR struct ieee802154_radio_s *radio); -static int mrf24j40_txnotify_gts(FAR struct ieee802154_radio_s *radio); +static int mrf24j40_txnotify_csma(FAR struct ieee802154_radio_s *radio); +static int mrf24j40_txnotify_gts(FAR struct ieee802154_radio_s *radio); /**************************************************************************** * Private Data @@ -327,9 +326,7 @@ static void mrf24j40_dopoll_csma(FAR void *arg) FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)arg; int len = 0; - /* Need to get exlusive access to the device so that we can use the copy - * buffer. - */ + /* Get exclusive access to the driver */ while (sem_wait(&dev->exclsem) != 0) { } @@ -340,7 +337,7 @@ static void mrf24j40_dopoll_csma(FAR void *arg) /* need to somehow allow for a handle to be passed */ len = dev->radiocb->poll_csma(dev->radiocb, &dev->csma_desc.pub, - &dev->tx_buf[0]); + &dev->csma_frame); if (len > 0) { /* Now the txdesc is in use */ @@ -349,7 +346,7 @@ static void mrf24j40_dopoll_csma(FAR void *arg) /* Setup the transaction on the device in the CSMA FIFO */ - mrf24j40_csma_setup(dev, &dev->tx_buf[0], len); + mrf24j40_csma_setup(dev, dev->csma_frame); } } @@ -421,9 +418,7 @@ static void mrf24j40_dopoll_gts(FAR void *arg) int gts = 0; int len = 0; - /* Need to get exclusive access to the device so that we can use the copy - * buffer. - */ + /* Get exclusive access to the driver */ while (sem_wait(&dev->exclsem) != 0) { } @@ -432,7 +427,7 @@ static void mrf24j40_dopoll_gts(FAR void *arg) if (!dev->gts_desc[gts].busy) { len = dev->radiocb->poll_gts(dev->radiocb, &dev->gts_desc[gts].pub, - &dev->tx_buf[0]); + &dev->gts_frame[0]); if (len > 0) { /* Now the txdesc is in use */ @@ -441,7 +436,7 @@ static void mrf24j40_dopoll_gts(FAR void *arg) /* Setup the transaction on the device in the open GTS FIFO */ - mrf24j40_gts_setup(dev, gts, &dev->tx_buf[0], len); + mrf24j40_gts_setup(dev, gts, dev->gts_frame[0]); } } } @@ -1327,52 +1322,6 @@ static int mrf24j40_energydetect(FAR struct mrf24j40_radio_s *dev, return OK; } -/* Packet exchange */ - -/**************************************************************************** - * Name: mrf24j40_transmit - * - * Description: - * Send a regular packet over the air. - * - ****************************************************************************/ - -static int mrf24j40_transmit(FAR struct ieee802154_radio_s *radio, - FAR uint8_t *buf, uint16_t buf_len) -{ - FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)radio; - uint8_t reg; - int ret; - - mrf24j40_pacontrol(dev, MRF24J40_PA_AUTO); - - /* Enable tx int */ - - reg = mrf24j40_getreg(dev->spi, MRF24J40_INTCON); - reg &= ~MRF24J40_INTCON_TXNIE; - mrf24j40_setreg(dev->spi, MRF24J40_INTCON, reg); - - /* Setup the FIFO */ - - ret = mrf24j40_setup_fifo(dev, buf, buf_len, MRF24J40_TXNORM_FIFO); - - /* If the frame control field contains - * an acknowledgment request, set the TXNACKREQ bit. - * See IEEE 802.15.4/2003 7.2.1.1 page 112 for info. - */ - - reg = MRF24J40_TXNCON_TXNTRIG; - if (buf[0] & IEEE802154_FRAMECTRL_ACKREQ) - { - reg |= MRF24J40_TXNCON_TXNACKREQ; - } - - /* Trigger packet emission */ - - mrf24j40_setreg(dev->spi, MRF24J40_TXNCON, reg); - return ret; -} - /**************************************************************************** * Name: mrf24j40_csma_setup * @@ -1382,7 +1331,7 @@ static int mrf24j40_transmit(FAR struct ieee802154_radio_s *radio, ****************************************************************************/ static int mrf24j40_csma_setup(FAR struct mrf24j40_radio_s *dev, - FAR uint8_t *buf, uint16_t buf_len) + FAR struct iob_s *frame) { uint8_t reg; int ret; @@ -1397,7 +1346,7 @@ static int mrf24j40_csma_setup(FAR struct mrf24j40_radio_s *dev, /* Setup the FIFO */ - ret = mrf24j40_setup_fifo(dev, buf, buf_len, MRF24J40_TXNORM_FIFO); + ret = mrf24j40_setup_fifo(dev, frame, MRF24J40_TXNORM_FIFO); /* If the frame control field contains * an acknowledgment request, set the TXNACKREQ bit. @@ -1405,7 +1354,7 @@ static int mrf24j40_csma_setup(FAR struct mrf24j40_radio_s *dev, */ reg = MRF24J40_TXNCON_TXNTRIG; - if (buf[0] & IEEE802154_FRAMECTRL_ACKREQ) + if (frame->io_data[0] & IEEE802154_FRAMECTRL_ACKREQ) { reg |= MRF24J40_TXNCON_TXNACKREQ; } @@ -1425,7 +1374,7 @@ static int mrf24j40_csma_setup(FAR struct mrf24j40_radio_s *dev, ****************************************************************************/ static int mrf24j40_gts_setup(FAR struct mrf24j40_radio_s *dev, uint8_t fifo, - FAR uint8_t *buf, uint16_t buf_len) + FAR struct iob_s *frame) { return -ENOTTY; } @@ -1438,8 +1387,7 @@ static int mrf24j40_gts_setup(FAR struct mrf24j40_radio_s *dev, uint8_t fifo, ****************************************************************************/ static int mrf24j40_setup_fifo(FAR struct mrf24j40_radio_s *dev, - FAR uint8_t *buf, uint16_t buf_len, - uint32_t fifo_addr) + FAR struct iob_s *frame, uint32_t fifo_addr) { int ret; int hlen = 3; /* Include frame control and seq number */ @@ -1447,8 +1395,8 @@ static int mrf24j40_setup_fifo(FAR struct mrf24j40_radio_s *dev, /* Analyze frame control to compute header length */ - frame_ctrl = buf[0]; - frame_ctrl |= (buf[1] << 8); + frame_ctrl = frame->io_data[0]; + frame_ctrl |= (frame->io_data[1] << 8); if ((frame_ctrl & IEEE802154_FRAMECTRL_DADDR)== IEEE802154_ADDRMODE_SHORT) { @@ -1479,13 +1427,13 @@ static int mrf24j40_setup_fifo(FAR struct mrf24j40_radio_s *dev, /* Frame length */ - mrf24j40_setreg(dev->spi, fifo_addr++, buf_len); + mrf24j40_setreg(dev->spi, fifo_addr++, frame->io_len); /* Frame data */ - for (ret = 0; ret < buf_len; ret++) /* this sets the correct val for ret */ + for (ret = 0; ret < frame->io_len; ret++) /* this sets the correct val for ret */ { - mrf24j40_setreg(dev->spi, fifo_addr++, buf[ret]); + mrf24j40_setreg(dev->spi, fifo_addr++, frame->io_data[ret]); } return ret; @@ -1525,6 +1473,10 @@ static void mrf24j40_irqwork_txnorm(FAR struct mrf24j40_radio_s *dev) dev->csma_desc.busy = 0; + /* Free the IOB */ + + iob_free(dev->csma_frame); + mrf24j40_dopoll_csma(dev); } @@ -1571,6 +1523,10 @@ static void mrf24j40_irqwork_txgts(FAR struct mrf24j40_radio_s *dev, dev->gts_desc[gts].busy = 0; + /* Free the IOB */ + + iob_free(dev->gts_frame[gts]); + mrf24j40_dopoll_gts(dev); } diff --git a/include/nuttx/wireless/ieee802154/ieee802154_ioctl.h b/include/nuttx/wireless/ieee802154/ieee802154_ioctl.h index 533e2f38535..019fedd55a7 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_ioctl.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_ioctl.h @@ -72,6 +72,11 @@ struct mac802154dev_notify_s uint8_t mn_signo; /* Signal number to use in the notification */ }; +struct mac802154dev_txframe_s +{ + FAR struct ieee802154_frame_meta_s *meta; + FAR uint8_t *payload; +}; #endif /* CONFIG_WIRELESS_IEEE802154 */ #endif /* __INCLUDE_NUTTX_WIRELESS_IEEE802154_IEEE802154_IOCTL_H */ diff --git a/include/nuttx/wireless/ieee802154/ieee802154_mac.h b/include/nuttx/wireless/ieee802154/ieee802154_mac.h index 1a8e324ce21..422e4d88fb3 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_mac.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_mac.h @@ -474,20 +474,12 @@ enum ieee802154_scantype_e IEEE802154_SCANTYPE_ORPHAN }; -/* Primitive Semantics *******************************************************/ - -/***************************************************************************** - * Primitive: MCPS-DATA.request - * - * Description: - * Requests the transfer of data to another device. - * - *****************************************************************************/ - -struct ieee802154_data_req_s +struct ieee802154_frame_meta_s { enum ieee802154_addr_mode_e src_addr_mode; /* Source Address Mode */ struct ieee802154_addr_s dest_addr; /* Destination Address */ + + uint8_t msdu_handle; /* Handle assoc. with MSDU */ /* Number of bytes contained in the MAC Service Data Unit (MSDU) * to be transmitted by the MAC sublayer enitity @@ -498,7 +490,6 @@ struct ieee802154_data_req_s uint16_t msdu_length; - uint8_t msdu_handle; /* Handle assoc. with MSDU */ struct { uint8_t ack_tx : 1; /* Acknowledge TX? */ @@ -530,18 +521,23 @@ struct ieee802154_data_req_s #endif enum ieee802154_ranging_e ranging; - - /* The MAC service data unit array that is to be transmitted - * This must be at the end of the struct to allow the array - * to continue and make the struct "variable length" - */ - - uint8_t msdu[IEEE802154_MAX_MAC_PAYLOAD_SIZE]; }; -#define SIZEOF_IEEE802154_DATA_REQ_S(n) \ - (sizeof(struct ieee802154_data_req_s) \ - - IEEE802154_MAX_MAC_PAYLOAD_SIZE + (n)) +/* Primitive Semantics *******************************************************/ + +/***************************************************************************** + * Primitive: MCPS-DATA.request + * + * Description: + * Requests the transfer of data to another device. + * + *****************************************************************************/ + +struct ieee802154_data_req_s +{ + FAR struct ieee802154_frame_meta_s *meta; /* Metadata describing the req */ + FAR struct iob_s *frame; /* Frame IOB with payload */ +}; /***************************************************************************** * Primitive: MCPS-DATA.confirm diff --git a/include/nuttx/wireless/ieee802154/ieee802154_radio.h b/include/nuttx/wireless/ieee802154/ieee802154_radio.h index 54e08969d9a..e976ec20753 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_radio.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_radio.h @@ -195,13 +195,15 @@ struct ieee802154_rxdesc_s struct ieee802154_radiocb_s { CODE int (*poll_csma) (FAR const struct ieee802154_radiocb_s *radiocb, - FAR struct ieee802154_txdesc_s *tx_desc, FAR uint8_t *buf); + FAR struct ieee802154_txdesc_s *tx_desc, + FAR struct iob_s **frame); CODE int (*poll_gts) (FAR const struct ieee802154_radiocb_s *radiocb, - FAR struct ieee802154_txdesc_s *tx_desc, FAR uint8_t *buf); + FAR struct ieee802154_txdesc_s *tx_desc, + FAR struct iob_s **frame); CODE void (*txdone) (FAR const struct ieee802154_radiocb_s *radiocb, FAR const struct ieee802154_txdesc_s *tx_desc); CODE void (*rxframe) (FAR const struct ieee802154_radiocb_s *radiocb, - FAR const struct ieee8021254_rxdesc_s *rx_desc, + FAR const struct ieee802154_rxdesc_s *rx_desc, FAR struct iob_s *frame); }; diff --git a/wireless/ieee802154/mac802154.c b/wireless/ieee802154/mac802154.c index f6b5f5f455d..1dbd3a65c2a 100644 --- a/wireless/ieee802154/mac802154.c +++ b/wireless/ieee802154/mac802154.c @@ -86,15 +86,8 @@ struct mac802154_trans_s /* Supports a singly linked list */ FAR struct mac802154_trans_s *flink; - + FAR struct iob_s *frame; uint8_t msdu_handle; - - FAR uint8_t *mhr_buf; - uint8_t mhr_len; - - FAR uint8_t *d_buf; - uint8_t d_len; - sem_t sem; }; @@ -291,23 +284,26 @@ static int mac802154_applymib(FAR struct ieee802154_privmac_s *priv); static int mac802154_poll_csma(FAR const struct ieee802154_radiocb_s *radiocb, FAR struct ieee802154_txdesc_s *tx_desc, - FAR uint8_t *buf); + FAR struct iob_s **frame); static int mac802154_poll_gts(FAR const struct ieee802154_radiocb_s *radiocb, FAR struct ieee802154_txdesc_s *tx_desc, - FAR uint8_t *buf); + FAR struct iob_s **frame); static void mac802154_txdone(FAR const struct ieee802154_radiocb_s *radiocb, FAR const struct ieee802154_txdesc_s *tx_desc); static void mac802154_rxframe(FAR const struct ieee802154_radiocb_s *radiocb, - FAR struct ieee802154_rxdesc_s *rx_desc, + FAR const struct ieee802154_rxdesc_s *rx_desc, FAR struct iob_s *frame); /**************************************************************************** * Private Data ****************************************************************************/ +/* Map between ieee802154_addr_mode_e enum and actual address length */ + +static const uint8_t mac802154_addr_length[4] = {0, 0, 2, 8}; /**************************************************************************** * Private Functions @@ -452,7 +448,7 @@ static int mac802154_applymib(FAR struct ieee802154_privmac_s *priv) static int mac802154_poll_csma(FAR const struct ieee802154_radiocb_s *radiocb, FAR struct ieee802154_txdesc_s *tx_desc, - FAR uint8_t *buf) + FAR struct iob_s **frame) { FAR struct mac802154_radiocb_s *cb = (FAR struct mac802154_radiocb_s *)radiocb; @@ -475,24 +471,19 @@ static int mac802154_poll_csma(FAR const struct ieee802154_radiocb_s *radiocb, if (trans != NULL) { - /* Setup the transmit descriptor */ tx_desc->handle = trans->msdu_handle; - /* Copy the frame into the buffer */ - - memcpy(&buf[0], trans->mhr_buf, trans->mhr_len); - memcpy(&buf[trans->mhr_len], trans->d_buf, trans->d_len); + *frame = trans->frame; /* Now that we've passed off the data, notify the waiting thread. * NOTE: The transaction was allocated on the waiting thread's stack so * it will be automatically deallocated when that thread awakens and - * returns. - */ + * returns. */ sem_post(&trans->sem); - return (trans->mhr_len + trans->d_len); + return (trans->frame->io_len); } return 0; @@ -511,7 +502,7 @@ static int mac802154_poll_csma(FAR const struct ieee802154_radiocb_s *radiocb, static int mac802154_poll_gts(FAR const struct ieee802154_radiocb_s *radiocb, FAR struct ieee802154_txdesc_s *tx_desc, - FAR uint8_t *buf) + FAR struct iob_s **frame) { FAR struct mac802154_radiocb_s *cb = (FAR struct mac802154_radiocb_s *)radiocb; @@ -643,7 +634,7 @@ static void mac802154_txdone_worker(FAR void *arg) ****************************************************************************/ static void mac802154_rxframe(FAR const struct ieee802154_radiocb_s *radiocb, - FAR struct ieee802154_rxdesc_s *rx_desc, + FAR const struct ieee802154_rxdesc_s *rx_desc, FAR struct iob_s *frame) { FAR struct mac802154_radiocb_s *cb = @@ -844,6 +835,82 @@ int mac802154_ioctl(MACHANDLE mac, int cmd, unsigned long arg) * MAC Interface Operations ****************************************************************************/ +/**************************************************************************** + * Name: mac802154_get_mhrlen + * + * Description: + * Calculate the MAC header length given the frame meta-data. + * + ****************************************************************************/ + +int mac802154_get_mhrlen(MACHANDLE mac, + FAR struct ieee802154_frame_meta_s *meta) +{ + FAR struct ieee802154_privmac_s *priv = + (FAR struct ieee802154_privmac_s *)mac; + int ret = 3; /* Always frame control (2 bytes) and seq. num (1 byte) */ + + /* Check to make sure both the dest address and the source address are not set + * to NONE */ + + if (meta->dest_addr.mode == IEEE802154_ADDRMODE_NONE && + meta->src_addr_mode == IEEE802154_ADDRMODE_NONE) + { + return -EINVAL; + } + + /* The source address can only be set to NONE if the device is the PAN coord */ + + if (meta->src_addr_mode == IEEE802154_ADDRMODE_NONE && !priv->is_coord) + { + return -EINVAL; + } + + /* Add the destination address length */ + + ret += mac802154_addr_length[meta->dest_addr.mode]; + + /* Add the source address length */ + + ret += mac802154_addr_length[ meta->src_addr_mode]; + + /* If both destination and source addressing information is present, the MAC + * sublayer shall compare the destination and source PAN identifiers. + * [1] pg. 41. + */ + + if (meta->src_addr_mode != IEEE802154_ADDRMODE_NONE && + meta->dest_addr.mode != IEEE802154_ADDRMODE_NONE) + { + /* If the PAN identifiers are identical, the PAN ID Compression field + * shall be set to one, and the source PAN identifier shall be omitted + * from the transmitted frame. [1] pg. 41. + */ + + if (meta->dest_addr.panid == priv->addr.panid) + { + ret += 2; /* 2 bytes for destination PAN ID */ + return ret; + } + } + + /* If we are here, PAN ID compression is off, so include the dest and source + * PAN ID if the respective address is included + */ + + if (meta->src_addr_mode != IEEE802154_ADDRMODE_NONE) + { + ret += 2; /* 2 bytes for source PAN ID */ + } + + if (meta->dest_addr.mode != IEEE802154_ADDRMODE_NONE) + { + ret += 2; /* 2 bytes for destination PAN ID */ + } + + return ret; +} + /**************************************************************************** * Name: mac802154_req_data * @@ -860,73 +927,70 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; FAR struct mac802154_trans_s trans; - struct mac802154_unsec_mhr_s mhr; + FAR struct ieee802154_frame_meta_s *meta = req->meta; + uint16_t *frame_ctrl; + uint8_t mhr_len = 3; /* Start assuming frame control and seq. num */ int ret; + + /* Check the required frame size */ - /* Start off assuming there is only the frame_control field in the MHR */ + if (req->frame->io_len > IEEE802154_MAX_PHY_PACKET_SIZE) + { + return -E2BIG; + } - mhr.length = 2; + /* Cast the first two bytes of the IOB to a uint16_t frame control field */ - /* Do a preliminary check to make sure the MSDU isn't too long for even - * the best case. - */ - - if (req->msdu_length > IEEE802154_MAX_MAC_PAYLOAD_SIZE) - { - return -EINVAL; - } + frame_ctrl = (uint16_t *)&req->frame->io_data[0]; /* Ensure we start with a clear frame control field */ - mhr.u.frame_control = 0; + *frame_ctrl = 0; /* Set the frame type to Data */ - mhr.u.frame_control |= IEEE802154_FRAME_DATA << - IEEE802154_FRAMECTRL_SHIFT_FTYPE; + *frame_ctrl |= IEEE802154_FRAME_DATA << IEEE802154_FRAMECTRL_SHIFT_FTYPE; /* If the msduLength is greater than aMaxMACSafePayloadSize, the MAC * sublayer will set the Frame Version to one. [1] pg. 118. */ - if (req->msdu_length > IEEE802154_MAX_SAFE_MAC_PAYLOAD_SIZE) + if (meta->msdu_length > IEEE802154_MAX_SAFE_MAC_PAYLOAD_SIZE) { - mhr.u.frame_control |= IEEE802154_FRAMECTRL_VERSION; + *frame_ctrl |= IEEE802154_FRAMECTRL_VERSION; } /* If the TXOptions parameter specifies that an acknowledged transmission * is required, the AR field will be set appropriately, as described in * 5.1.6.4 [1] pg. 118. */ - - mhr.u.frame_control |= (req->msdu_flags.ack_tx << - IEEE802154_FRAMECTRL_SHIFT_ACKREQ); + + *frame_ctrl |= (meta->msdu_flags.ack_tx << IEEE802154_FRAMECTRL_SHIFT_ACKREQ); /* If the destination address is present, copy the PAN ID and one of the - * addresses, depending on mode, into the MHR . + * addresses, depending on mode, into the MHR. */ - if (req->dest_addr.mode != IEEE802154_ADDRMODE_NONE) + if (meta->dest_addr.mode != IEEE802154_ADDRMODE_NONE) { - memcpy(&mhr.u.data[mhr.length], &req->dest_addr.panid, 2); - mhr.length += 2; + memcpy(&req->frame->io_data[mhr_len], &meta->dest_addr.panid, 2); + mhr_len += 2; - if (req->dest_addr.mode == IEEE802154_ADDRMODE_SHORT) + if (meta->dest_addr.mode == IEEE802154_ADDRMODE_SHORT) { - memcpy(&mhr.u.data[mhr.length], &req->dest_addr.saddr, 2); - mhr.length += 2; + memcpy(&req->frame->io_data[mhr_len], &meta->dest_addr.saddr, 2); + mhr_len += 2; } - else if (req->dest_addr.mode == IEEE802154_ADDRMODE_EXTENDED) + else if (meta->dest_addr.mode == IEEE802154_ADDRMODE_EXTENDED) { - memcpy(&mhr.u.data[mhr.length], &req->dest_addr.eaddr, 8); - mhr.length += 8; + memcpy(&req->frame->io_data[mhr_len], &meta->dest_addr.eaddr, 8); + mhr_len += 8; } } - /* Set the destination addr mode inside the frame contorl field */ + /* Set the destination addr mode inside the frame control field */ - mhr.u.frame_control |= (req->dest_addr.mode << - IEEE802154_FRAMECTRL_SHIFT_DADDR); + *frame_ctrl |= (meta->dest_addr.mode << IEEE802154_FRAMECTRL_SHIFT_DADDR); /* From this point on, we need exclusive access to the privmac struct */ @@ -942,75 +1006,70 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) * [1] pg. 41. */ - if (req->src_addr_mode != IEEE802154_ADDRMODE_NONE && - req->dest_addr.mode != IEEE802154_ADDRMODE_NONE) + if (meta->src_addr_mode != IEEE802154_ADDRMODE_NONE && + meta->dest_addr.mode != IEEE802154_ADDRMODE_NONE) { /* If the PAN identifiers are identical, the PAN ID Compression field * shall be set to one, and the source PAN identifier shall be omitted * from the transmitted frame. [1] pg. 41. */ - if (req->dest_addr.panid == priv->addr.panid) + if (meta->dest_addr.panid == priv->addr.panid) { - mhr.u.frame_control |= IEEE802154_FRAMECTRL_PANIDCOMP; + *frame_ctrl |= IEEE802154_FRAMECTRL_PANIDCOMP; } } - if (req->src_addr_mode != IEEE802154_ADDRMODE_NONE) + if (meta->src_addr_mode != IEEE802154_ADDRMODE_NONE) { /* If the destination address is not included, or if PAN ID Compression * is off, we need to include the Source PAN ID. */ - if ((req->dest_addr.mode == IEEE802154_ADDRMODE_NONE) || - (mhr.u.frame_control & IEEE802154_FRAMECTRL_PANIDCOMP)) + if ((meta->dest_addr.mode == IEEE802154_ADDRMODE_NONE) || + (*frame_ctrl & IEEE802154_FRAMECTRL_PANIDCOMP)) { - memcpy(&mhr.u.data[mhr.length], &priv->addr.panid, 2); - mhr.length += 2; + memcpy(&req->frame->io_data[mhr_len], &priv->addr.panid, 2); + mhr_len += 2; } - if (req->src_addr_mode == IEEE802154_ADDRMODE_SHORT) + if (meta->src_addr_mode == IEEE802154_ADDRMODE_SHORT) { - memcpy(&mhr.u.data[mhr.length], &priv->addr.saddr, 2); - mhr.length += 2; + memcpy(&req->frame->io_data[mhr_len], &priv->addr.saddr, 2); + mhr_len += 2; } - else if (req->src_addr_mode == IEEE802154_ADDRMODE_EXTENDED) + else if (meta->src_addr_mode == IEEE802154_ADDRMODE_EXTENDED) { - memcpy(&mhr.u.data[mhr.length], &priv->addr.eaddr, 8); - mhr.length += 8; + memcpy(&req->frame->io_data[mhr_len], &priv->addr.eaddr, 8); + mhr_len += 8; } } /* Set the source addr mode inside the frame control field */ - mhr.u.frame_control |= (req->src_addr_mode << - IEEE802154_FRAMECTRL_SHIFT_SADDR); + *frame_ctrl |= (meta->src_addr_mode << IEEE802154_FRAMECTRL_SHIFT_SADDR); /* Each time a data or a MAC command frame is generated, the MAC sublayer * shall copy the value of macDSN into the Sequence Number field of the MHR * of the outgoing frame and then increment it by one. [1] pg. 40. */ - mhr.u.data[mhr.length++] = priv->dsn++; + req->frame->io_data[2] = priv->dsn++; - /* Now that we know which fields are included in the header, we can make - * sure we actually have enough room in the PSDU. + /* The MAC header we just created must never have exceeded where the app + * data starts. This should never happen since the offset should have + * been set via the same logic to calculate the header length as the logic + * here that created the header */ - if (mhr.length + req->msdu_length + IEEE802154_MFR_LENGTH > - IEEE802154_MAX_PHY_PACKET_SIZE) - { - return -E2BIG; - } + DEBUGASSERT(mhr_len == req->frame->io_offset); - trans.mhr_buf = &mhr.u.data[0]; - trans.mhr_len = mhr.length; + req->frame->io_offset = 0; /* Set the offset to 0 to include the header */ - trans.d_buf = &req->msdu[0]; - trans.d_len = req->msdu_length; - - trans.msdu_handle = req->msdu_handle; + /* Setup our transaction */ + trans.msdu_handle = meta->msdu_handle; + trans.frame = req->frame; sem_init(&trans.sem, 0, 1); /* If the TxOptions parameter specifies that a GTS transmission is required, @@ -1025,7 +1084,7 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) * [1] pg. 118. */ - if (req->msdu_flags.gts_tx) + if (meta->msdu_flags.gts_tx) { /* TODO: Support GTS transmission. This should just change where we link * the transaction. Instead of going in the CSMA transaction list, it @@ -1044,7 +1103,7 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) * described in 5.1.5 and 5.1.6.3. [1] */ - if (req->msdu_flags.indirect_tx) + if (meta->msdu_flags.indirect_tx) { /* If the TxOptions parameter specifies that an indirect transmission * is required and if the device receiving this primitive is not a @@ -1053,24 +1112,22 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) * transmission option will be ignored. [1] */ - if (priv->is_coord && req->dest_addr.mode != IEEE802154_ADDRMODE_NONE) + if (priv->is_coord && meta->dest_addr.mode != IEEE802154_ADDRMODE_NONE) { /* Link the transaction into the indirect_trans list */ - priv->indirect_tail->flink = &trans; - priv->indirect_tail = &trans; } else { /* Override the setting since it wasn't valid */ - req->msdu_flags.indirect_tx = 0; + meta->msdu_flags.indirect_tx = 0; } } /* If this is a direct transmission not during a GTS */ - if (!req->msdu_flags.indirect_tx) + if (!meta->msdu_flags.indirect_tx) { /* Link the transaction into the CSMA transaction list */ @@ -1092,7 +1149,6 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) return OK; } - /**************************************************************************** * Name: mac802154_req_purge * diff --git a/wireless/ieee802154/mac802154.h b/wireless/ieee802154/mac802154.h index 00235d025b2..ea582e4e7a4 100644 --- a/wireless/ieee802154/mac802154.h +++ b/wireless/ieee802154/mac802154.h @@ -97,6 +97,17 @@ int mac802154_ioctl(MACHANDLE mac, int cmd, unsigned long arg); * MAC Interface Operations ****************************************************************************/ +/**************************************************************************** + * Name: mac802154_get_mhrlen + * + * Description: + * Calculate the MAC header length given the frame meta-data. + * + ****************************************************************************/ + +int mac802154_get_mhrlen(MACHANDLE mac, + FAR struct ieee802154_frame_meta_s *meta); + /**************************************************************************** * Name: mac802154_req_data * diff --git a/wireless/ieee802154/mac802154_device.c b/wireless/ieee802154/mac802154_device.c index 5c31cdf1402..998cca074f7 100644 --- a/wireless/ieee802154/mac802154_device.c +++ b/wireless/ieee802154/mac802154_device.c @@ -50,6 +50,8 @@ #include #include +#include + #include #include @@ -373,17 +375,6 @@ static ssize_t mac802154dev_read(FAR struct file *filep, FAR char *buffer, DEBUGASSERT(inode->i_private); dev = (FAR struct mac802154_chardevice_s *)inode->i_private; - /* Check to make sure that the buffer is big enough to hold at least one - * packet. - */ - - if ((len >= SIZEOF_IEEE802154_DATA_REQ_S(1)) && - (len <= SIZEOF_IEEE802154_DATA_REQ_S(IEEE802154_MAX_MAC_PAYLOAD_SIZE))) - { - wlerr("ERROR: buffer too small: %lu\n", (unsigned long)len); - return -EINVAL; - } - /* Get exclusive access to the driver structure */ ret = mac802154dev_takesem(&dev->md_exclsem); @@ -413,7 +404,9 @@ static ssize_t mac802154dev_write(FAR struct file *filep, { FAR struct inode *inode; FAR struct mac802154_chardevice_s *dev; - FAR struct ieee802154_data_req_s *req; + FAR struct mac802154dev_txframe_s *tx; + FAR struct iob_s *iob; + struct ieee802154_data_req_s req; struct mac802154dev_dwait_s dwait; int ret; @@ -422,20 +415,44 @@ static ssize_t mac802154dev_write(FAR struct file *filep, DEBUGASSERT(inode->i_private); dev = (FAR struct mac802154_chardevice_s *)inode->i_private; - /* Check to make sure that the buffer is big enough to hold at least one - * packet. */ + /* Check if the struct is write */ - if ((len < SIZEOF_IEEE802154_DATA_REQ_S(1)) || - (len > SIZEOF_IEEE802154_DATA_REQ_S(IEEE802154_MAX_MAC_PAYLOAD_SIZE))) + if (len != sizeof(struct mac802154dev_txframe_s)) { - wlerr("ERROR: buffer isn't an ieee802154_data_req_s: %lu\n", + wlerr("ERROR: buffer isn't a mac802154dev_txframe_s: %lu\n", (unsigned long)len); return -EINVAL; } DEBUGASSERT(buffer != NULL); - req = (FAR struct ieee802154_data_req_s *)buffer; + tx = (FAR struct mac802154dev_txframe_s *)buffer; + + /* Allocate an IOB to put the frame in */ + + iob = iob_alloc(false); + DEBUGASSERT(iob != NULL); + + iob->io_flink = NULL; + iob->io_len = 0; + iob->io_offset = 0; + iob->io_pktlen = 0; + + /* Get the MAC header length */ + + ret = mac802154_get_mhrlen(dev->md_mac, tx->meta); + if (ret < 0) + { + wlerr("ERROR: TX meta-data is invalid"); + return ret; + } + + iob->io_offset = ret; + iob->io_len = iob->io_offset; + + memcpy(&iob->io_data[iob->io_offset], tx->payload, tx->meta->msdu_length); + + iob->io_len += tx->meta->msdu_length; /* If this is a blocking operation, we need to setup a wait struct so we * can unblock when the packet transmission has finished. If this is a @@ -456,21 +473,25 @@ static ssize_t mac802154dev_write(FAR struct file *filep, /* Setup the wait struct */ - dwait.mw_handle = req->msdu_handle; + dwait.mw_handle = tx->meta->msdu_handle; /* Link the wait struct */ dwait.mw_flink = dev->md_dwait; dev->md_dwait = &dwait; - sem_init(&dwait.mw_sem, 0, 1); + sem_init(&dwait.mw_sem, 0, 0); + sem_setprotocol(&dwait.mw_sem, SEM_PRIO_NONE); mac802154dev_givesem(&dev->md_exclsem); } + req.meta = tx->meta; + req.frame = iob; + /* Pass the request to the MAC layer */ - ret = mac802154_req_data(dev->md_mac, req); + ret = mac802154_req_data(dev->md_mac, &req); if (ret < 0) { From 2ece0c57dd6d7d77f44faa0c47d1c6bf0b3ad2ac Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 2 May 2017 14:42:40 -0600 Subject: [PATCH 115/183] Remove dangling whitespace at the end of lines --- drivers/wireless/ieee802154/at86rf23x.c | 2 +- drivers/wireless/ieee802154/mrf24j40.c | 18 +- drivers/wireless/ieee802154/mrf24j40.h | 6 +- .../wireless/ieee802154/ieee802154_mac.h | 146 +- .../wireless/ieee802154/ieee802154_radio.h | 8 +- wireless/ieee802154/mac802154.c | 2852 ++++++++--------- wireless/ieee802154/mac802154.h | 2 +- wireless/ieee802154/mac802154_device.c | 2 +- 8 files changed, 1518 insertions(+), 1518 deletions(-) diff --git a/drivers/wireless/ieee802154/at86rf23x.c b/drivers/wireless/ieee802154/at86rf23x.c index 8037c4005a7..24a4d5ca391 100644 --- a/drivers/wireless/ieee802154/at86rf23x.c +++ b/drivers/wireless/ieee802154/at86rf23x.c @@ -217,7 +217,7 @@ static const struct ieee802154_radioops_s at86rf23x_devops = /**************************************************************************** * Private Functions ****************************************************************************/ - + /**************************************************************************** * Name: at86rf23x_lock * diff --git a/drivers/wireless/ieee802154/mrf24j40.c b/drivers/wireless/ieee802154/mrf24j40.c index f883b55054a..c703933acc2 100644 --- a/drivers/wireless/ieee802154/mrf24j40.c +++ b/drivers/wireless/ieee802154/mrf24j40.c @@ -114,7 +114,7 @@ struct mrf24j40_txdesc_s struct mrf24j40_radio_s { struct ieee802154_radio_s radio; /* The public device instance */ - FAR struct ieee802154_radiocb_s *radiocb; /* Registered callbacks */ + FAR struct ieee802154_radiocb_s *radiocb; /* Registered callbacks */ /* Low-level MCU-specific support */ @@ -310,7 +310,7 @@ static int mrf24j40_txnotify_csma(FAR struct ieee802154_radio_s *radio) * 2. When new TX data is available (mrf24j40_txnotify_csma), and * 3. After a TX timeout to restart the sending process * (mrf24j40_txtimeout_csma). - * + * * Parameters: * radio - Reference to the radio driver state structure * @@ -329,7 +329,7 @@ static void mrf24j40_dopoll_csma(FAR void *arg) /* Get exclusive access to the driver */ while (sem_wait(&dev->exclsem) != 0) { } - + /* If this a CSMA transaction and we have room in the CSMA fifo */ if (!dev->csma_desc.busy) @@ -401,7 +401,7 @@ static int mrf24j40_txnotify_gts(FAR struct ieee802154_radio_s *radio) * 2. When new TX data is available (mrf24j40_txnotify_gts), and * 3. After a TX timeout to restart the sending process * (mrf24j40_txtimeout_gts). - * + * * Parameters: * arg - Reference to the radio driver state structure * @@ -440,7 +440,7 @@ static void mrf24j40_dopoll_gts(FAR void *arg) } } } - + sem_post(&dev->exclsem); } @@ -754,7 +754,7 @@ static int mrf24j40_getchannel(FAR struct mrf24j40_radio_s *dev, FAR uint8_t *chan) { *chan = dev->channel; - + return OK; } @@ -1369,7 +1369,7 @@ static int mrf24j40_csma_setup(FAR struct mrf24j40_radio_s *dev, * Name: mrf24j40_gts_setup * * Description: - * Setup a GTS transaction in one of the GTS FIFOs + * Setup a GTS transaction in one of the GTS FIFOs * ****************************************************************************/ @@ -1435,7 +1435,7 @@ static int mrf24j40_setup_fifo(FAR struct mrf24j40_radio_s *dev, { mrf24j40_setreg(dev->spi, fifo_addr++, frame->io_data[ret]); } - + return ret; } @@ -1764,7 +1764,7 @@ FAR struct ieee802154_radio_s *mrf24j40_init(FAR struct spi_dev_s *spi, { return NULL; } - + /* Attach irq */ if (lower->attach(lower, mrf24j40_interrupt, dev) != OK) diff --git a/drivers/wireless/ieee802154/mrf24j40.h b/drivers/wireless/ieee802154/mrf24j40.h index 585fae513af..f9a8a35a5d0 100644 --- a/drivers/wireless/ieee802154/mrf24j40.h +++ b/drivers/wireless/ieee802154/mrf24j40.h @@ -167,10 +167,10 @@ /* RXMCR bits */ -#define MRF24J40_RXMCR_PROMI (1 << 0) /* Enable promisc mode (rx all valid packets) */ -#define MRF24J40_RXMCR_ERRPKT 0x02 /* Do not check CRC */ +#define MRF24J40_RXMCR_PROMI (1 << 0) /* Enable promisc mode (rx all valid packets) */ +#define MRF24J40_RXMCR_ERRPKT 0x02 /* Do not check CRC */ #define MRF24J40_RXMCR_COORD 0x04 /* Enable coordinator mode ??? DIFFERENCE ??? - not used in datasheet! */ -#define MRF24J40_RXMCR_PANCOORD 0x08 /* Enable PAN coordinator mode ??? DIFFERENCE ??? */ +#define MRF24J40_RXMCR_PANCOORD 0x08 /* Enable PAN coordinator mode ??? DIFFERENCE ??? */ #define MRF24J40_RXMCR_NOACKRSP 0x20 /* Enable auto ACK when a packet is rxed */ /* TXMCR bits */ diff --git a/include/nuttx/wireless/ieee802154/ieee802154_mac.h b/include/nuttx/wireless/ieee802154/ieee802154_mac.h index 422e4d88fb3..a51e8852871 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_mac.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_mac.h @@ -68,7 +68,7 @@ /* IEEE 802.15.4 MAC Character Driver IOCTL Commands ************************/ -/* The IEEE 802.15.4 standard specifies a MLME Service Access Point (SAP) +/* The IEEE 802.15.4 standard specifies a MLME Service Access Point (SAP) * including a series of primitives that are used as an interface between * the MLME and the next highest layer. There are 4 types of primitives: * @@ -76,7 +76,7 @@ * - Indication * - Response * - Confirm - * + * * Of these, Request and Response primitives are sent from the next highest layer * to the MLME. Indication and Confirm primitives are used to notify the next * highest layer of changes or actions that have taken place. @@ -130,7 +130,7 @@ #define IEEE802154_SADDR_BCAST (uint16_t)0xFFFE #define IEEE802154_EADDR_UNSPEC (uint8_t*)"\xff\xff\xff\xff\xff\xff\xff\xff" -/* Frame control field masks, 2 bytes +/* Frame control field masks, 2 bytes * Seee IEEE 802.15.4/2011 5.2.1.1 page 57 */ @@ -178,11 +178,11 @@ #define IEEE802154_MAX_MPDU_UNSEC_OVERHEAD \ (IEEE802154_MAX_UNSEC_MHR_OVERHEAD + IEEE802154_MFR_LENGTH) - + #define IEEE802154_MAX_SAFE_MAC_PAYLOAD_SIZE \ (IEEE802154_MAX_PHY_PACKET_SIZE - IEEE802154_MAX_MPDU_UNSEC_OVERHEAD) - + #define IEEE802154_MAX_MAC_PAYLOAD_SIZE \ (IEEE802154_MAX_PHY_PACKET_SIZE - IEEE802154_MIN_MPDU_OVERHEAD) @@ -346,7 +346,7 @@ struct ieee802154_addr_s { /* Address mode. Short or Extended */ - enum ieee802154_addr_mode_e mode; + enum ieee802154_addr_mode_e mode; uint16_t panid; /* PAN identifier, can be IEEE802154_PAN_UNSPEC */ uint16_t saddr; /* short address */ @@ -444,7 +444,7 @@ struct ieee802154_pend_addr_s { uint8_t num_short_addr : 3; /* Number of short addresses pending */ uint8_t reserved_3 : 1; /* Reserved bit */ - uint8_t num_ext_addr : 3; /* Number of extended addresses pending */ + uint8_t num_ext_addr : 3; /* Number of extended addresses pending */ uint8_t reserved_7 : 1; /* Reserved bit */ } pa_addr; } u; @@ -480,9 +480,9 @@ struct ieee802154_frame_meta_s struct ieee802154_addr_s dest_addr; /* Destination Address */ uint8_t msdu_handle; /* Handle assoc. with MSDU */ - - /* Number of bytes contained in the MAC Service Data Unit (MSDU) - * to be transmitted by the MAC sublayer enitity + + /* Number of bytes contained in the MAC Service Data Unit (MSDU) + * to be transmitted by the MAC sublayer enitity * Note: This could be a uint8_t but if anyone ever wants to use * non-standard frame lengths, they may want a length larger than * a uint8_t. @@ -492,7 +492,7 @@ struct ieee802154_frame_meta_s struct { - uint8_t ack_tx : 1; /* Acknowledge TX? */ + uint8_t ack_tx : 1; /* Acknowledge TX? */ uint8_t gts_tx : 1; /* 1=GTS used for TX, 0=CAP used for TX */ uint8_t indirect_tx : 1; /* Should indirect transmission be used? */ } msdu_flags; @@ -513,7 +513,7 @@ struct ieee802154_frame_meta_s * 0, 16, 64, 1024, 4096 */ - uint16_t uwb_presym_rep; + uint16_t uwb_presym_rep; /* The UWB Data Rate to be used for the transmission */ @@ -526,11 +526,11 @@ struct ieee802154_frame_meta_s /* Primitive Semantics *******************************************************/ /***************************************************************************** - * Primitive: MCPS-DATA.request + * Primitive: MCPS-DATA.request * * Description: - * Requests the transfer of data to another device. - * + * Requests the transfer of data to another device. + * *****************************************************************************/ struct ieee802154_data_req_s @@ -540,11 +540,11 @@ struct ieee802154_data_req_s }; /***************************************************************************** - * Primitive: MCPS-DATA.confirm + * Primitive: MCPS-DATA.confirm * * Description: * Reports the results of a request to transfer data to another device. - * + * *****************************************************************************/ struct ieee802154_data_conf_s @@ -553,11 +553,11 @@ struct ieee802154_data_conf_s }; /***************************************************************************** - * Primitive: MCPS-DATA.indication + * Primitive: MCPS-DATA.indication * * Description: * Indicates the reception of data from another device. - * + * *****************************************************************************/ struct ieee802154_data_ind_s @@ -577,13 +577,13 @@ struct ieee802154_data_ind_s * the beginning of the ranging exchange */ - uint32_t rng_counter_start; + uint32_t rng_counter_start; /* A count of the time units corresponding to an RMARKER at the antenna at * end of the ranging exchange */ - uint32_t rng_counter_stop; + uint32_t rng_counter_stop; /* A count of the time units in a message exchange over which the tracking * offset was measured @@ -597,18 +597,18 @@ struct ieee802154_data_ind_s uint32_t rng_offset; - /* The Figure of Merit (FoM) characterizing the ranging measurement */ + /* The Figure of Merit (FoM) characterizing the ranging measurement */ - uint8_t rng_fom; + uint8_t rng_fom; #endif }; /***************************************************************************** - * Primitive: MCPS-PURGE.request + * Primitive: MCPS-PURGE.request * * Description: * Allows the next higher layer to purge an MSDU from the transaction queue. - * + * *****************************************************************************/ struct ieee802154_purge_req_s @@ -617,12 +617,12 @@ struct ieee802154_purge_req_s }; /***************************************************************************** - * Primitive: MCPS-PURGE.confirm + * Primitive: MCPS-PURGE.confirm * * Description: * Allows the MAC sublayer to notify the next higher layer of the success of * its request to purge an MSDU from the transaction queue. - * + * *****************************************************************************/ struct ieee802154_purge_conf_s @@ -632,11 +632,11 @@ struct ieee802154_purge_conf_s }; /***************************************************************************** - * Primitive: MLME-ASSOCIATE.request + * Primitive: MLME-ASSOCIATE.request * * Description: * Used by a device to request an association with a coordinator. - * + * *****************************************************************************/ struct ieee802154_assoc_req_s @@ -660,11 +660,11 @@ struct ieee802154_assoc_req_s }; /***************************************************************************** - * Primitive: MLME-ASSOCIATE.indication + * Primitive: MLME-ASSOCIATE.indication * * Description: * Used to indicate the reception of an association request command. - * + * *****************************************************************************/ struct ieee802154_assoc_ind_s @@ -685,11 +685,11 @@ struct ieee802154_assoc_ind_s }; /***************************************************************************** - * Primitive: MLME-ASSOCIATE.response + * Primitive: MLME-ASSOCIATE.response * * Description: * Used to initiate a response to an MLME-ASSOCIATE.indication primitive. - * + * *****************************************************************************/ struct ieee802154_assoc_resp_s @@ -700,7 +700,7 @@ struct ieee802154_assoc_resp_s /* Status of association attempt */ - enum ieee802154_status_e status; + enum ieee802154_status_e status; #ifdef CONFIG_IEEE802154_SECURITY /* Security information if enabled */ @@ -710,12 +710,12 @@ struct ieee802154_assoc_resp_s }; /***************************************************************************** - * Primitive: MLME-ASSOCIATE.confirm + * Primitive: MLME-ASSOCIATE.confirm * * Description: * Used to inform the next higher layer of the initiating device whether its * request to associate was successful or unsuccessful. - * + * *****************************************************************************/ struct ieee802154_assoc_conf_s @@ -739,13 +739,13 @@ struct ieee802154_assoc_conf_s }; /***************************************************************************** - * Primitive: MLME-DISASSOCIATE.request + * Primitive: MLME-DISASSOCIATE.request * * Description: * Used by an associated device to notify the coordinator of its intent to * leave the PAN. It is also used by the coordinator to instruct an * associated device to leave the PAN. - * + * *****************************************************************************/ struct ieee802154_disassoc_req_s @@ -768,11 +768,11 @@ struct ieee802154_disassoc_req_s }; /***************************************************************************** - * Primitive: MLME-DISASSOCIATE.indication + * Primitive: MLME-DISASSOCIATE.indication * * Description: * Used to indicate the reception of a disassociation notification command. - * + * *****************************************************************************/ struct ieee802154_disassoc_ind_s @@ -793,11 +793,11 @@ struct ieee802154_disassoc_ind_s }; /***************************************************************************** - * Primitive: MLME-DISASSOCIATE.confirm + * Primitive: MLME-DISASSOCIATE.confirm * * Description: * Reports the results of an MLME-DISASSOCIATE.request primitive. - * + * *****************************************************************************/ struct ieee802154_disassoc_conf_s @@ -812,7 +812,7 @@ struct ieee802154_disassoc_conf_s }; /***************************************************************************** - * Primitive: MLME-BEACONNOTIFY.indication + * Primitive: MLME-BEACONNOTIFY.indication * * Description: * Used to send parameters contained within a beacon frame received by the @@ -820,7 +820,7 @@ struct ieee802154_disassoc_conf_s * FALSE or when the beacon frame contains one or more octets of payload. The * primitive also sends a measure of the LQI and the time the beacon frame * was received. - * + * *****************************************************************************/ struct ieee802154_beaconnotify_ind_s @@ -837,7 +837,7 @@ struct ieee802154_beaconnotify_ind_s uint8_t sdu_length; /* Number of octets contained in the beacon * payload of the received beacond frame */ - + /* Beacon payload */ uint8_t sdu[IEEE802154_MAX_BEACON_PAYLOAD_LENGTH]; @@ -848,11 +848,11 @@ struct ieee802154_beaconnotify_ind_s - IEEE802154_MAX_BEACON_PAYLOAD_LENGTH + (n)) /***************************************************************************** - * Primitive: MLME-COMM-STATUS.indication + * Primitive: MLME-COMM-STATUS.indication * * Description: * Allows the MLME to indicate a communications status. - * + * *****************************************************************************/ struct ieee802154_commstatus_ind_s @@ -869,11 +869,11 @@ struct ieee802154_commstatus_ind_s }; /***************************************************************************** - * Primitive: MLME-GET.request + * Primitive: MLME-GET.request * * Description: * Requests information about a given PIB attribute. - * + * *****************************************************************************/ struct ieee802154_get_req_s @@ -882,11 +882,11 @@ struct ieee802154_get_req_s }; /***************************************************************************** - * Primitive: MLME-GET.confirm + * Primitive: MLME-GET.confirm * * Description: * Reports the results of an information request from the PIB. - * + * *****************************************************************************/ struct ieee802154_get_conf_s @@ -903,7 +903,7 @@ struct ieee802154_get_conf_s * Allows a device to send a request to the PAN coordinator to allocate a new * GTS or to deallocate an existing GTS. This primitive is also used by the * PAN coordinator to initiate a GTS deallocation. - * + * *****************************************************************************/ struct ieee802154_gts_req_s @@ -923,7 +923,7 @@ struct ieee802154_gts_req_s * Description: * Reports the results of a request to allocate a new GTS or to deallocate an * existing GTS. - * + * *****************************************************************************/ struct ieee802154_gts_conf_s @@ -938,7 +938,7 @@ struct ieee802154_gts_conf_s * Description: * Indicates that a GTS has been allocated or that a previously allocated * GTS has been deallocated. - * + * *****************************************************************************/ struct ieee802154_gts_ind_s @@ -959,7 +959,7 @@ struct ieee802154_gts_ind_s * Description: * Generated by the MLME of a coordinator and issued to its next higher layer * on receipt of an orphan notification command. - * + * *****************************************************************************/ struct ieee802154_orphan_ind_s @@ -979,7 +979,7 @@ struct ieee802154_orphan_ind_s * Description: * Allows the next higher layer of a coordinator to respond to the * MLME-ORPHAN.indication primitive. - * + * *****************************************************************************/ struct ieee802154_orphan_resp_s @@ -999,7 +999,7 @@ struct ieee802154_orphan_resp_s * Description: * Used by the next higher layer to request that the MLME performs a reset * operation. - * + * *****************************************************************************/ struct ieee802154_reset_req_s @@ -1012,7 +1012,7 @@ struct ieee802154_reset_req_s * * Description: * Reports the results of the reset operation. - * + * *****************************************************************************/ struct ieee802154_reset_conf_s @@ -1026,7 +1026,7 @@ struct ieee802154_reset_conf_s * Description: * Allows the next higher layer to request that the receiver is either * enabled for a finite period of time or disabled. - * + * *****************************************************************************/ struct ieee802154_rxenable_req_s @@ -1035,7 +1035,7 @@ struct ieee802154_rxenable_req_s * receiver is to be enabled or disabled. */ - uint32_t rxon_time; + uint32_t rxon_time; /* Number of symbols for which the receiver is to be enabled */ @@ -1051,7 +1051,7 @@ struct ieee802154_rxenable_req_s * * Description: * Reports the results of the attempt to enable or disable the receiver. - * + * *****************************************************************************/ struct ieee802154_rxenable_conf_s @@ -1064,7 +1064,7 @@ struct ieee802154_rxenable_conf_s * * Description: * Used to initiate a channel scan over a given list of channels. - * + * *****************************************************************************/ struct ieee802154_scan_req_s @@ -1090,7 +1090,7 @@ struct ieee802154_scan_req_s * * Description: * Reports the result of the channel scan request. - * + * *****************************************************************************/ struct ieee802154_scan_conf_s @@ -1108,7 +1108,7 @@ struct ieee802154_scan_conf_s * * Description: * Attempts to write the given value to the indicated PIB attribute. - * + * *****************************************************************************/ struct ieee802154_set_req_s @@ -1122,7 +1122,7 @@ struct ieee802154_set_req_s * * Description: * Reports the results of an attempt to write a value to a PIB attribute. - * + * *****************************************************************************/ struct ieee802154_set_conf_s @@ -1139,7 +1139,7 @@ struct ieee802154_set_conf_s * superframe configuration. This primitive is also used by a device already * associated with an existing PAN to begin using a new superframe * configuration. - * + * *****************************************************************************/ struct ieee802154_start_req_s @@ -1148,7 +1148,7 @@ struct ieee802154_start_req_s uint8_t ch_num; uint8_t ch_page; - uint32_t start_time : 24; + uint32_t start_time : 24; uint32_t beacon_order : 8; uint8_t sf_order; @@ -1171,7 +1171,7 @@ struct ieee802154_start_req_s * Description: * Reports the results of the attempt to start using a new superframe * configuration. - * + * *****************************************************************************/ struct ieee802154_start_conf_s @@ -1185,7 +1185,7 @@ struct ieee802154_start_conf_s * Description: * Requests to synchronize with the coordinator by acquiring and, if * specified, tracking its beacons. - * + * *****************************************************************************/ struct ieee802154_sync_req_s @@ -1200,7 +1200,7 @@ struct ieee802154_sync_req_s * * Description: * Indicates the loss of synchronization with a coordinator. - * + * *****************************************************************************/ struct ieee802154_syncloss_ind_s @@ -1221,8 +1221,8 @@ struct ieee802154_syncloss_ind_s * Primitive: MLME-POLL.request * * Description: - * Prompts the device to request data from the coordinator. - * + * Prompts the device to request data from the coordinator. + * *****************************************************************************/ struct ieee802154_poll_req_s @@ -1241,7 +1241,7 @@ struct ieee802154_poll_req_s * * Description: * Reports the results of a request to poll the coordinator for data. - * + * *****************************************************************************/ struct ieee802154_poll_conf_s diff --git a/include/nuttx/wireless/ieee802154/ieee802154_radio.h b/include/nuttx/wireless/ieee802154/ieee802154_radio.h index e976ec20753..9a80658664c 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_radio.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_radio.h @@ -162,18 +162,18 @@ struct ieee802154_netradio_s * identical members but with a different name. */ #ifdef CONFIG_IEEE802154_RANGING -#define IEEE802154_TXDESC_FIELDS \ +#define IEEE802154_TXDESC_FIELDS \ uint8_t handle; \ uint32_t timestamp; \ uint8_t status; #else -#define IEEE802154_TXDESC_FIELDS \ +#define IEEE802154_TXDESC_FIELDS \ uint8_t handle; \ uint32_t timestamp; \ uint8_t status; bool rng_rcvd; \ - uint32_t rng_counter_start; \ - uint32_t rng_counter_stop; \ + uint32_t rng_counter_start; \ + uint32_t rng_counter_stop; \ uint32_t rng_tracking_interval; \ uint32_t rng_offset;\ uint8_t rng_fom; diff --git a/wireless/ieee802154/mac802154.c b/wireless/ieee802154/mac802154.c index 1dbd3a65c2a..39bdb2ec2aa 100644 --- a/wireless/ieee802154/mac802154.c +++ b/wireless/ieee802154/mac802154.c @@ -1,1426 +1,1426 @@ -/**************************************************************************** - * wireless/ieee802154/mac802154.c - * - * Copyright (C) 2016 Sebastien Lorquet. All rights reserved. - * Author: Sebastien Lorquet - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include -#include - -#include -#include - -#include - -#include - -#include "mac802154.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ -/* Configuration ************************************************************/ -/* If processing is not done at the interrupt level, then work queue support - * is required. - */ - -#if !defined(CONFIG_SCHED_WORKQUEUE) -# error Work queue support is required in this configuration (CONFIG_SCHED_WORKQUEUE) -#else - - /* Use the low priority work queue if possible */ - -# if defined(CONFIG_MAC802154_HPWORK) -# define MAC802154_WORK HPWORK -# elif defined(CONFIG_MAC802154_LPWORK) -# define MAC802154_WORK LPWORK -# else -# error Neither CONFIG_MAC802154_HPWORK nor CONFIG_MAC802154_LPWORK defined -# endif -#endif - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct mac802154_trans_s -{ - /* Supports a singly linked list */ - - FAR struct mac802154_trans_s *flink; - FAR struct iob_s *frame; - uint8_t msdu_handle; - sem_t sem; -}; - -struct mac802154_unsec_mhr_s -{ - uint8_t length; - union - { - uint16_t frame_control; - uint8_t data[IEEE802154_MAX_UNSEC_MHR_OVERHEAD]; - } u; -}; - -struct mac802154_radiocb_s -{ - struct ieee802154_radiocb_s cb; - FAR struct ieee802154_privmac_s *priv; -}; - -/* The privmac structure holds the internal state of the MAC and is the - * underlying represention of the opaque MACHANDLE. It contains storage for - * the IEEE802.15.4 MIB attributes. - */ - -struct ieee802154_privmac_s -{ - FAR struct ieee802154_radio_s *radio; /* Contained IEEE802.15.4 radio dev */ - FAR const struct ieee802154_maccb_s *cb; /* Contained MAC callbacks */ - FAR struct mac802154_radiocb_s radiocb; /* Interface to bind to radio */ - - sem_t exclsem; /* Support exclusive access */ - - struct work_s tx_work; - struct work_s rx_work; - - /* Support a singly linked list of transactions that will be sent using the - * CSMA algorithm. On a non-beacon enabled PAN, these transactions will be - * sent whenever. On a beacon-enabled PAN, these transactions will be sent - * during the CAP of the Coordinator's superframe. - */ - - FAR struct mac802154_trans_s *csma_head; - FAR struct mac802154_trans_s *csma_tail; - - /* Support a singly linked list of transactions that will be sent indirectly. - * This list should only be used by a MAC acting as a coordinator. These - * transactions will stay here until the data is extracted by the destination - * device sending a Data Request MAC command or if too much time passes. This - * list should also be used to populate the address list of the outgoing - * beacon frame. - */ - - FAR struct mac802154_trans_s *indirect_head; - FAR struct mac802154_trans_s *indirect_tail; - - uint8_t txdesc_count; - struct ieee802154_txdesc_s txdesc[CONFIG_IEEE802154_NTXDESC]; - - /* Support a singly linked list of frames received */ - FAR struct iob_s *rxframes_head; - FAR struct iob_s *rxframes_tail; - - /* MAC PIB attributes, grouped to save memory */ - - /* Holds all address information (Extended, Short, and PAN ID) for the MAC. */ - - struct ieee802154_addr_s addr; - - /* Holds all address information (Extended, Short) for Coordinator */ - - struct ieee802154_addr_s coord_addr; - - /* The maximum number of symbols to wait for an acknowledgement frame to - * arrive following a transmitted data frame. [1] pg. 126 - * - * NOTE: This may be able to be a 16-bit or even an 8-bit number. I wasn't - * sure at the time what the range of reasonable values was. - */ - - uint32_t ack_wait_dur; - - /* The maximum time to wait either for a frame intended as a response to a - * data request frame or for a broadcast frame following a beacon with the - * Frame Pending field set to one. [1] pg. 127 - * - * NOTE: This may be able to be a 16-bit or even an 8-bit number. I wasn't - * sure at the time what the range of reasonable values was. - */ - - uint32_t max_frame_wait_time; - - /* The maximum time (in unit periods) that a transaction is stored by a - * coordinator and indicated in its beacon. - */ - - uint16_t trans_persist_time; - - /* Contents of beacon payload */ - - uint8_t beacon_payload[IEEE802154_MAX_BEACON_PAYLOAD_LENGTH]; - uint8_t beacon_payload_len; /* Length of beacon payload */ - - uint8_t batt_life_ext_periods; /* # of backoff periods during which rx is - * enabled after the IFS following beacon */ - - uint8_t bsn; /* Seq. num added to tx beacon frame */ - uint8_t dsn; /* Seq. num added to tx data or MAC frame */ - uint8_t max_retries; /* Max # of retries alloed after tx failure */ - - /* The maximum time, in multiples of aBaseSuperframeDuration, a device shall - * wait for a response command frame to be available following a request - * command frame. [1] 128. - */ - - uint8_t resp_wait_time; - - /* The total transmit duration (including PHY header and FCS) specified in - * symbols. [1] pg. 129. - */ - - uint32_t tx_total_dur; - - /* Start of 32-bit bitfield */ - - uint32_t is_assoc : 1; /* Are we associated to the PAN */ - uint32_t assoc_permit : 1; /* Are we allowing assoc. as a coord. */ - uint32_t auto_req : 1; /* Automatically send data req. if addr - * addr is in the beacon frame */ - - uint32_t batt_life_ext : 1; /* Is BLE enabled */ - uint32_t gts_permit : 1; /* Is PAN Coord. accepting GTS reqs. */ - uint32_t promiscuous_mode : 1; /* Is promiscuous mode on? */ - uint32_t ranging_supported : 1; /* Does MAC sublayer support ranging */ - uint32_t rx_when_idle : 1; /* Recvr. on during idle periods */ - uint32_t sec_enabled : 1; /* Does MAC sublayer have security en. */ - - uint32_t max_csma_backoffs : 3; /* Max num backoffs for CSMA algorithm - * before declaring ch access failure */ - - uint32_t beacon_order : 4; /* Freq. that beacon is transmitted */ - - uint32_t superframe_order : 4; /* Length of active portion of outgoing - * superframe, including the beacon */ - - /* The offset, measured is symbols, between the symbol boundary at which the - * MLME captures the timestamp of each transmitted and received frame, and - * the onset of the first symbol past the SFD, namely the first symbol of - * the frames [1] pg. 129. - */ - - uint32_t sync_symb_offset : 12; - - /* End of 32-bit bitfield */ - - /* Start of 32-bit bitfield */ - - uint32_t beacon_tx_time : 24; /* Time of last beacon transmit */ - uint32_t min_be : 4; /* Min value of backoff exponent (BE) */ - uint32_t max_be : 4; /* Max value of backoff exponent (BE) */ - - /* End of 32-bit bitfield */ - - /* Start of 32-bit bitfield */ - - uint32_t tx_ctrl_active_dur : 17; /* Duration for which tx is permitted to - * be active */ - uint32_t tx_ctrl_pause_dur : 1; /* Duration after tx before another tx is - * permitted. 0=2000, 1= 10000 */ - uint32_t timestamp_support : 1; /* Does MAC layer supports timestamping */ - uint32_t is_coord : 1; /* Is this device acting as coordinator */ - /* 12-bits remaining */ - - /* End of 32-bit bitfield. */ - - /* TODO: Add Security-related MAC PIB attributes */ -}; - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static inline int mac802154_takesem(sem_t *sem); -#define mac802154_givesem(s) sem_post(s); - -static void mac802154_txdone_worker(FAR void *arg); -static void mac802154_rxframe_worker(FAR void *arg); - -/* Internal Functions */ - -static int mac802154_defaultmib(FAR struct ieee802154_privmac_s *priv); -static int mac802154_applymib(FAR struct ieee802154_privmac_s *priv); - -/* IEEE 802.15.4 PHY Interface OPs */ - -static int mac802154_poll_csma(FAR const struct ieee802154_radiocb_s *radiocb, - FAR struct ieee802154_txdesc_s *tx_desc, - FAR struct iob_s **frame); - -static int mac802154_poll_gts(FAR const struct ieee802154_radiocb_s *radiocb, - FAR struct ieee802154_txdesc_s *tx_desc, - FAR struct iob_s **frame); - -static void mac802154_txdone(FAR const struct ieee802154_radiocb_s *radiocb, - FAR const struct ieee802154_txdesc_s *tx_desc); - -static void mac802154_rxframe(FAR const struct ieee802154_radiocb_s *radiocb, - FAR const struct ieee802154_rxdesc_s *rx_desc, - FAR struct iob_s *frame); - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* Map between ieee802154_addr_mode_e enum and actual address length */ - -static const uint8_t mac802154_addr_length[4] = {0, 0, 2, 8}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: mac802154_semtake - * - * Description: - * Acquire the semaphore used for access serialization. - * - ****************************************************************************/ - -static inline int mac802154_takesem(sem_t *sem) -{ - /* Take a count from the semaphore, possibly waiting */ - - if (sem_wait(sem) < 0) - { - /* EINTR is the only error that we expect */ - - int errcode = get_errno(); - DEBUGASSERT(errcode == EINTR); - return -errcode; - } - - return OK; -} - -/**************************************************************************** - * Name: mac802154_push_csma - * - * Description: - * Push a CSMA transaction onto the list - * - ****************************************************************************/ - -static void mac802154_push_csma(FAR struct ieee802154_privmac_s *priv, - FAR struct mac802154_trans_s *trans) -{ - /* Ensure the transactions forward link is NULL */ - - trans->flink = NULL; - - /* If the tail is not empty, make the transaction pointed to by the tail, - * point to the new transaction */ - - if (priv->csma_tail != NULL) - { - priv->csma_tail->flink = trans; - } - - /* Point the tail at the new transaction */ - - priv->csma_tail = trans; - - /* If the head is NULL, we need to point it at the transaction since there - * is only one transaction in the list at this point */ - - if (priv->csma_head == NULL) - { - priv->csma_head = trans; - } -} - -/**************************************************************************** - * Name: mac802154_pop_csma - * - * Description: - * Pop a CSMA transaction from the list - * - ****************************************************************************/ - -static FAR struct mac802154_trans_s * - mac802154_pop_csma(FAR struct ieee802154_privmac_s *priv) -{ - FAR struct mac802154_trans_s *trans; - - if (priv->csma_head == NULL) - { - return NULL; - } - - /* Get the transaction from the head of the list */ - - trans = priv->csma_head; - - /* Move the head pointer to the next transaction */ - - priv->csma_head = trans->flink; - - /* If the head is now NULL, the list is empty, so clear the tail too */ - - if (priv->csma_head == NULL) - { - priv->csma_tail = NULL; - } - - return trans; -} - -/**************************************************************************** - * Name: mac802154_defaultmib - * - * Description: - * Set the MIB to its default values. - * - ****************************************************************************/ - -static int mac802154_defaultmib(FAR struct ieee802154_privmac_s *priv) -{ - /* TODO: Set all MAC fields to default values */ - - return OK; -} - -/**************************************************************************** - * Name: mac802154_applymib - * - * Description: - * Some parts of the MIB must be sent to the radio device. This routine - * calls the radio device routines to store the related parameters in the - * radio driver. It must be called each time a MIB parameter is changed. - * - ****************************************************************************/ - -static int mac802154_applymib(FAR struct ieee802154_privmac_s *priv) -{ - return OK; -} - -/**************************************************************************** - * Name: mac802154_poll_csma - * - * Description: - * Called from the radio driver through the callback struct. This function is - * called when the radio has room for another CSMA transaction. If the MAC - * layer has a CSMA transaction, it copies it into the supplied buffer and - * returns the length. A descriptor is also populated with the transaction. - * - ****************************************************************************/ - -static int mac802154_poll_csma(FAR const struct ieee802154_radiocb_s *radiocb, - FAR struct ieee802154_txdesc_s *tx_desc, - FAR struct iob_s **frame) -{ - FAR struct mac802154_radiocb_s *cb = - (FAR struct mac802154_radiocb_s *)radiocb; - FAR struct ieee802154_privmac_s *priv; - FAR struct mac802154_trans_s *trans; - - DEBUGASSERT(cb != NULL && cb->priv != NULL); - priv = cb->priv; - - /* Get exclusive access to the driver structure. We don't care about any - * signals so if we see one, just go back to trying to get access again. - */ - - while (mac802154_takesem(&priv->exclsem) != 0); - - /* Check to see if there are any CSMA transactions waiting */ - - trans = mac802154_pop_csma(priv); - mac802154_givesem(&priv->exclsem); - - if (trans != NULL) - { - /* Setup the transmit descriptor */ - - tx_desc->handle = trans->msdu_handle; - - *frame = trans->frame; - - /* Now that we've passed off the data, notify the waiting thread. - * NOTE: The transaction was allocated on the waiting thread's stack so - * it will be automatically deallocated when that thread awakens and - * returns. */ - - sem_post(&trans->sem); - return (trans->frame->io_len); - } - - return 0; -} - -/**************************************************************************** - * Name: mac802154_poll_gts - * - * Description: - * Called from the radio driver through the callback struct. This function is - * called when the radio has room for another GTS transaction. If the MAC - * layer has a GTS transaction, it copies it into the supplied buffer and - * returns the length. A descriptor is also populated with the transaction. - * - ****************************************************************************/ - -static int mac802154_poll_gts(FAR const struct ieee802154_radiocb_s *radiocb, - FAR struct ieee802154_txdesc_s *tx_desc, - FAR struct iob_s **frame) -{ - FAR struct mac802154_radiocb_s *cb = - (FAR struct mac802154_radiocb_s *)radiocb; - FAR struct ieee802154_privmac_s *priv; - FAR struct mac802154_trans_s *trans; - int ret = 0; - - DEBUGASSERT(cb != NULL && cb->priv != NULL); - priv = cb->priv; - - /* Get exclusive access to the driver structure. We don't care about any - * signals so if we see one, just go back to trying to get access again. - */ - - while (mac802154_takesem(&priv->exclsem) != 0); - -#warning Missing logic. - - mac802154_givesem(&priv->exclsem); - - return 0; -} - -/**************************************************************************** - * Name: mac802154_txdone - * - * Description: - * Called from the radio driver through the callback struct. This function is - * called when the radio has completed a transaction. The txdesc passed gives - * provides information about the completed transaction including the original - * handle provided when the transaction was created and the status of the - * transaction. This function copies the descriptor and schedules work to - * handle the transaction without blocking the radio. - * - ****************************************************************************/ - -static void mac802154_txdone(FAR const struct ieee802154_radiocb_s *radiocb, - FAR const struct ieee802154_txdesc_s *tx_desc) -{ - FAR struct mac802154_radiocb_s *cb = - (FAR struct mac802154_radiocb_s *)radiocb; - FAR struct ieee802154_privmac_s *priv; - - DEBUGASSERT(cb != NULL && cb->priv != NULL); - priv = cb->priv; - - /* Get exclusive access to the driver structure. We don't care about any - * signals so if we see one, just go back to trying to get access again. - */ - - while (mac802154_takesem(&priv->exclsem) != 0); - - /* Check to see if there is an available tx descriptor slot. If there is - * not we simply drop the notification */ - - if (priv->txdesc_count < CONFIG_IEEE802154_NTXDESC) - { - /* Copy the txdesc over and link it into our list */ - - memcpy(&priv->txdesc[priv->txdesc_count++], tx_desc, - sizeof(struct ieee802154_txdesc_s)); - } - else - { - wlinfo("MAC802154: No room for TX Desc.\n"); - } - - mac802154_givesem(&priv->exclsem); - - /* Schedule work with the work queue to process the completion further */ - - if (work_available(&priv->tx_work)) - { - work_queue(MAC802154_WORK, &priv->tx_work, mac802154_txdone_worker, - (FAR void *)priv, 0); - } -} - -/**************************************************************************** - * Name: mac802154_txdone_worker - * - * Description: - * Worker function scheduled from mac802154_txdone. This function pops any - * TX descriptors off of the list and calls the next highest layers callback - * to inform the layer of the completed transaction and the status of it. - * - ****************************************************************************/ - -static void mac802154_txdone_worker(FAR void *arg) -{ - FAR struct ieee802154_privmac_s *priv = - (FAR struct ieee802154_privmac_s *)arg; - int i = 0; - - /* Get exclusive access to the driver structure. We don't care about any - * signals so if we see one, just go back to trying to get access again. - */ - - while (mac802154_takesem(&priv->exclsem) != 0); - - /* For each pending TX descriptor, send an application callback */ - - for (i = 0; i < priv->txdesc_count; i++) - { - priv->cb->mcps_notify(priv->cb, IEEE802154_NOTIFY_CONF_DATA, - (FAR const union ieee802154_mcps_notify_u *) &priv->txdesc[i]); - } - - /* We've handled all the descriptors and no further desc could have been added - * since we have the struct locked */ - - priv->txdesc_count = 0; - - mac802154_givesem(&priv->exclsem); -} - -/**************************************************************************** - * Name: mac802154_rxframe - * - * Description: - * Called from the radio driver through the callback struct. This function is - * called when the radio has received a frame. The frame is passed in an iob, - * so that we can free it when we are done processing. A pointer to the RX - * descriptor is passed along with the iob, but it must be copied here as it - * is allocated directly on the caller's stack. We simply link the frame, - * copy the RX descriptor, and schedule a worker to process the frame later so - * that we do not hold up the radio. - * - ****************************************************************************/ - -static void mac802154_rxframe(FAR const struct ieee802154_radiocb_s *radiocb, - FAR const struct ieee802154_rxdesc_s *rx_desc, - FAR struct iob_s *frame) -{ - FAR struct mac802154_radiocb_s *cb = - (FAR struct mac802154_radiocb_s *)radiocb; - FAR struct ieee802154_privmac_s *priv; - FAR struct ieee802154_rxdesc_s *desc; - - DEBUGASSERT(cb != NULL && cb->priv != NULL); - priv = cb->priv; - - /* Get exclusive access to the driver structure. We don't care about any - * signals so if we see one, just go back to trying to get access again. - */ - - while (mac802154_takesem(&priv->exclsem) != 0); - - /* TODO: Copy the frame descriptor to some type of list */ - - /* Push the iob onto the tail of the frame list for processing */ - - priv->rxframes_tail->io_flink = frame; - priv->rxframes_tail = frame; - - mac802154_givesem(&priv->exclsem); - - /* Schedule work with the work queue to process the completion further */ - - if (work_available(&priv->rx_work)) - { - work_queue(MAC802154_WORK, &priv->rx_work, mac802154_rxframe_worker, - (FAR void *)priv, 0); - } -} - -/**************************************************************************** - * Name: mac802154_rxframe_worker - * - * Description: - * Worker function scheduled from mac802154_rxframe. This function processes - * any frames in the list. Frames intended to be consumed by the MAC layer - * will not produce any callbacks to the next highest layer. Frames intended - * for the application layer will be forwarded to them. - * - ****************************************************************************/ - -static void mac802154_rxframe_worker(FAR void *arg) -{ - FAR struct ieee802154_privmac_s *priv = - (FAR struct ieee802154_privmac_s *)arg; - - /* The radio layer is responsible for handling all ACKs and retries. If for - * some reason an ACK gets here, just throw it out. - */ -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: mac802154_create - * - * Description: - * Create a 802.15.4 MAC device from a 802.15.4 compatible radio device. - * - * The returned MAC structure should be passed to either the next highest - * layer in the network stack, or registered with a mac802154dev character - * or network drivers. In any of these scenarios, the next highest layer - * should register a set of callbacks with the MAC layer by setting the - * mac->cbs member. - * - * NOTE: 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. - * - * Input Parameters: - * radiodev - an instance of an IEEE 802.15.4 radio - * - * Returned Value: - * An opaque reference to the MAC state data. - * - ****************************************************************************/ - -MACHANDLE mac802154_create(FAR struct ieee802154_radio_s *radiodev) -{ - FAR struct ieee802154_privmac_s *mac; - FAR struct ieee802154_radiocb_s *radiocb; - - /* Allocate object */ - - mac = (FAR struct ieee802154_privmac_s *) - kmm_zalloc(sizeof(struct ieee802154_privmac_s)); - - if (mac == NULL) - { - return NULL; - } - - /* Allow exclusive access to the privmac struct */ - - sem_init(&mac->exclsem, 0, 1); - - /* Initialize fields */ - - mac->radio = radiodev; - - mac802154_defaultmib(mac); - mac802154_applymib(mac); - - /* Initialize the Radio callbacks */ - - mac->radiocb.priv = mac; - - radiocb = &mac->radiocb.cb; - radiocb->poll_csma = mac802154_poll_csma; - radiocb->poll_gts = mac802154_poll_gts; - radiocb->txdone = mac802154_txdone; - radiocb->rxframe = mac802154_rxframe; - - /* Bind our callback structure */ - - radiodev->ops->bind(radiodev, &mac->radiocb.cb); - - return (MACHANDLE)mac; -} - -/**************************************************************************** - * Name: mac802154_bind - * - * Description: - * Bind the MAC callback table to the MAC state. - * - * Parameters: - * mac - Reference to the MAC driver state structure - * cb - MAC callback operations - * - * Returned Value: - * OK on success; Negated errno on failure. - * - ****************************************************************************/ - -int mac802154_bind(MACHANDLE mac, FAR const struct ieee802154_maccb_s *cb) -{ - FAR struct ieee802154_privmac_s *priv = - (FAR struct ieee802154_privmac_s *)mac; - - priv->cb = cb; - return OK; -} - -/**************************************************************************** - * Name: mac802154_ioctl - * - * Description: - * Handle MAC and radio IOCTL commands directed to the MAC. - * - * Parameters: - * mac - Reference to the MAC driver state structure - * cmd - The IOCTL command - * arg - The argument for the IOCTL command - * - * Returned Value: - * OK on success; Negated errno on failure. - * - ****************************************************************************/ - -int mac802154_ioctl(MACHANDLE mac, int cmd, unsigned long arg) -{ - FAR struct ieee802154_privmac_s *priv = - (FAR struct ieee802154_privmac_s *)mac; - int ret = -EINVAL; - - DEBUGASSERT(priv != NULL); - - /* Check for IOCTLs aimed at the IEEE802.15.4 MAC layer */ - - if (_MAC802154IOCVALID(cmd)) - { - /* Handle the MAC IOCTL command */ -#warning Missing logic - } - - /* No, other IOCTLs must be aimed at the IEEE802.15.4 radio layer */ - - else - { - DEBUGASSERT(priv->radio != NULL && - priv->radio->ops != NULL && - priv->radio->ops->ioctl != NULL); - - ret = priv->radio->ops->ioctl(priv->radio, cmd, arg); - } - - return ret; -} - -/**************************************************************************** - * MAC Interface Operations - ****************************************************************************/ - -/**************************************************************************** - * Name: mac802154_get_mhrlen - * - * Description: - * Calculate the MAC header length given the frame meta-data. - * - ****************************************************************************/ - -int mac802154_get_mhrlen(MACHANDLE mac, - FAR struct ieee802154_frame_meta_s *meta) -{ - FAR struct ieee802154_privmac_s *priv = - (FAR struct ieee802154_privmac_s *)mac; - int ret = 3; /* Always frame control (2 bytes) and seq. num (1 byte) */ - - /* Check to make sure both the dest address and the source address are not set - * to NONE */ - - if (meta->dest_addr.mode == IEEE802154_ADDRMODE_NONE && - meta->src_addr_mode == IEEE802154_ADDRMODE_NONE) - { - return -EINVAL; - } - - /* The source address can only be set to NONE if the device is the PAN coord */ - - if (meta->src_addr_mode == IEEE802154_ADDRMODE_NONE && !priv->is_coord) - { - return -EINVAL; - } - - /* Add the destination address length */ - - ret += mac802154_addr_length[meta->dest_addr.mode]; - - /* Add the source address length */ - - ret += mac802154_addr_length[ meta->src_addr_mode]; - - /* If both destination and source addressing information is present, the MAC - * sublayer shall compare the destination and source PAN identifiers. - * [1] pg. 41. - */ - - if (meta->src_addr_mode != IEEE802154_ADDRMODE_NONE && - meta->dest_addr.mode != IEEE802154_ADDRMODE_NONE) - { - /* If the PAN identifiers are identical, the PAN ID Compression field - * shall be set to one, and the source PAN identifier shall be omitted - * from the transmitted frame. [1] pg. 41. - */ - - if (meta->dest_addr.panid == priv->addr.panid) - { - ret += 2; /* 2 bytes for destination PAN ID */ - return ret; - } - } - - /* If we are here, PAN ID compression is off, so include the dest and source - * PAN ID if the respective address is included - */ - - if (meta->src_addr_mode != IEEE802154_ADDRMODE_NONE) - { - ret += 2; /* 2 bytes for source PAN ID */ - } - - if (meta->dest_addr.mode != IEEE802154_ADDRMODE_NONE) - { - ret += 2; /* 2 bytes for destination PAN ID */ - } - - return ret; -} - -/**************************************************************************** - * Name: mac802154_req_data - * - * Description: - * The MCPS-DATA.request primitive requests the transfer of a data SPDU - * (i.e., MSDU) from a local SSCS entity to a single peer SSCS entity. - * Confirmation is returned via the - * struct ieee802154_maccb_s->conf_data callback. - * - ****************************************************************************/ - -int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) -{ - FAR struct ieee802154_privmac_s *priv = - (FAR struct ieee802154_privmac_s *)mac; - FAR struct mac802154_trans_s trans; - FAR struct ieee802154_frame_meta_s *meta = req->meta; - uint16_t *frame_ctrl; - uint8_t mhr_len = 3; /* Start assuming frame control and seq. num */ - int ret; - - /* Check the required frame size */ - - if (req->frame->io_len > IEEE802154_MAX_PHY_PACKET_SIZE) - { - return -E2BIG; - } - - /* Cast the first two bytes of the IOB to a uint16_t frame control field */ - - frame_ctrl = (uint16_t *)&req->frame->io_data[0]; - - /* Ensure we start with a clear frame control field */ - - *frame_ctrl = 0; - - /* Set the frame type to Data */ - - *frame_ctrl |= IEEE802154_FRAME_DATA << IEEE802154_FRAMECTRL_SHIFT_FTYPE; - - /* If the msduLength is greater than aMaxMACSafePayloadSize, the MAC - * sublayer will set the Frame Version to one. [1] pg. 118. - */ - - if (meta->msdu_length > IEEE802154_MAX_SAFE_MAC_PAYLOAD_SIZE) - { - *frame_ctrl |= IEEE802154_FRAMECTRL_VERSION; - } - - /* If the TXOptions parameter specifies that an acknowledged transmission - * is required, the AR field will be set appropriately, as described in - * 5.1.6.4 [1] pg. 118. - */ - - *frame_ctrl |= (meta->msdu_flags.ack_tx << IEEE802154_FRAMECTRL_SHIFT_ACKREQ); - - /* If the destination address is present, copy the PAN ID and one of the - * addresses, depending on mode, into the MHR. - */ - - if (meta->dest_addr.mode != IEEE802154_ADDRMODE_NONE) - { - memcpy(&req->frame->io_data[mhr_len], &meta->dest_addr.panid, 2); - mhr_len += 2; - - if (meta->dest_addr.mode == IEEE802154_ADDRMODE_SHORT) - { - memcpy(&req->frame->io_data[mhr_len], &meta->dest_addr.saddr, 2); - mhr_len += 2; - } - else if (meta->dest_addr.mode == IEEE802154_ADDRMODE_EXTENDED) - { - memcpy(&req->frame->io_data[mhr_len], &meta->dest_addr.eaddr, 8); - mhr_len += 8; - } - } - - /* Set the destination addr mode inside the frame control field */ - - *frame_ctrl |= (meta->dest_addr.mode << IEEE802154_FRAMECTRL_SHIFT_DADDR); - - /* From this point on, we need exclusive access to the privmac struct */ - - ret = mac802154_takesem(&priv->exclsem); - if (ret < 0) - { - wlerr("ERROR: mac802154_takesem failed: %d\n", ret); - return ret; - } - - /* If both destination and source addressing information is present, the MAC - * sublayer shall compare the destination and source PAN identifiers. - * [1] pg. 41. - */ - - if (meta->src_addr_mode != IEEE802154_ADDRMODE_NONE && - meta->dest_addr.mode != IEEE802154_ADDRMODE_NONE) - { - /* If the PAN identifiers are identical, the PAN ID Compression field - * shall be set to one, and the source PAN identifier shall be omitted - * from the transmitted frame. [1] pg. 41. - */ - - if (meta->dest_addr.panid == priv->addr.panid) - { - *frame_ctrl |= IEEE802154_FRAMECTRL_PANIDCOMP; - } - } - - if (meta->src_addr_mode != IEEE802154_ADDRMODE_NONE) - { - /* If the destination address is not included, or if PAN ID Compression - * is off, we need to include the Source PAN ID. - */ - - if ((meta->dest_addr.mode == IEEE802154_ADDRMODE_NONE) || - (*frame_ctrl & IEEE802154_FRAMECTRL_PANIDCOMP)) - { - memcpy(&req->frame->io_data[mhr_len], &priv->addr.panid, 2); - mhr_len += 2; - } - - if (meta->src_addr_mode == IEEE802154_ADDRMODE_SHORT) - { - memcpy(&req->frame->io_data[mhr_len], &priv->addr.saddr, 2); - mhr_len += 2; - } - else if (meta->src_addr_mode == IEEE802154_ADDRMODE_EXTENDED) - { - memcpy(&req->frame->io_data[mhr_len], &priv->addr.eaddr, 8); - mhr_len += 8; - } - } - - /* Set the source addr mode inside the frame control field */ - - *frame_ctrl |= (meta->src_addr_mode << IEEE802154_FRAMECTRL_SHIFT_SADDR); - - /* Each time a data or a MAC command frame is generated, the MAC sublayer - * shall copy the value of macDSN into the Sequence Number field of the MHR - * of the outgoing frame and then increment it by one. [1] pg. 40. - */ - - req->frame->io_data[2] = priv->dsn++; - - /* The MAC header we just created must never have exceeded where the app - * data starts. This should never happen since the offset should have - * been set via the same logic to calculate the header length as the logic - * here that created the header - */ - - DEBUGASSERT(mhr_len == req->frame->io_offset); - - req->frame->io_offset = 0; /* Set the offset to 0 to include the header */ - - /* Setup our transaction */ - - trans.msdu_handle = meta->msdu_handle; - trans.frame = req->frame; - sem_init(&trans.sem, 0, 1); - - /* If the TxOptions parameter specifies that a GTS transmission is required, - * the MAC sublayer will determine whether it has a valid GTS as described - * 5.1.7.3. If a valid GTS could not be found, the MAC sublayer will discard - * the MSDU. If a valid GTS was found, the MAC sublayer will defer, if - * necessary, until the GTS. If the TxOptions parameter specifies that a GTS - * transmission is not required, the MAC sublayer will transmit the MSDU using - * either slotted CSMA-CA in the CAP for a beacon-enabled PAN or unslotted - * CSMA-CA for a nonbeacon-enabled PAN. Specifying a GTS transmission in the - * TxOptions parameter overrides an indirect transmission request. - * [1] pg. 118. - */ - - if (meta->msdu_flags.gts_tx) - { - /* TODO: Support GTS transmission. This should just change where we link - * the transaction. Instead of going in the CSMA transaction list, it - * should be linked to the GTS' transaction list. We'll need to check if - * the GTS is valid, and then find the GTS, before linking. Note, we also - * don't have to try and kick-off any transmission here. - */ - - return -ENOTSUP; - } - else - { - /* If the TxOptions parameter specifies that an indirect transmission is - * required and this primitive is received by the MAC sublayer of a - * coordinator, the data frame is sent using indirect transmission, as - * described in 5.1.5 and 5.1.6.3. [1] - */ - - if (meta->msdu_flags.indirect_tx) - { - /* If the TxOptions parameter specifies that an indirect transmission - * is required and if the device receiving this primitive is not a - * coordinator, the destination address is not present, or the - * TxOptions parameter also specifies a GTS transmission, the indirect - * transmission option will be ignored. [1] - */ - - if (priv->is_coord && meta->dest_addr.mode != IEEE802154_ADDRMODE_NONE) - { - /* Link the transaction into the indirect_trans list */ - - } - else - { - /* Override the setting since it wasn't valid */ - - meta->msdu_flags.indirect_tx = 0; - } - } - - /* If this is a direct transmission not during a GTS */ - - if (!meta->msdu_flags.indirect_tx) - { - /* Link the transaction into the CSMA transaction list */ - - mac802154_push_csma(priv, &trans); - - /* We no longer need to have the MAC layer locked. */ - - mac802154_givesem(&priv->exclsem); - - /* Notify the radio driver that there is data available */ - - priv->radio->ops->txnotify_csma(priv->radio); - - sem_wait(&trans.sem); - } - } - - sem_destroy(&trans.sem); - return OK; -} - -/**************************************************************************** - * Name: mac802154_req_purge - * - * Description: - * The MCPS-PURGE.request primitive allows the next higher layer to purge - * an MSDU from the transaction queue. Confirmation is returned via - * the struct ieee802154_maccb_s->conf_purge callback. - * - ****************************************************************************/ - -int mac802154_req_purge(MACHANDLE mac, FAR struct ieee802154_purge_req_s *req) -{ - FAR struct ieee802154_privmac_s *priv = - (FAR struct ieee802154_privmac_s *)mac; - return -ENOTTY; -} - -/**************************************************************************** - * Name: mac802154_req_associate - * - * Description: - * The MLME-ASSOCIATE.request primitive allows a device to request an - * association with a coordinator. Confirmation is returned via the - * struct ieee802154_maccb_s->conf_associate callback. - * - ****************************************************************************/ - -int mac802154_req_associate(MACHANDLE mac, - FAR struct ieee802154_assoc_req_s *req) -{ - FAR struct ieee802154_privmac_s *priv = - (FAR struct ieee802154_privmac_s *)mac; - - /* Set the channel of the PHY layer */ - - /* Set the channel page of the PHY layer */ - - /* Set the macPANId */ - - /* Set either the macCoordExtendedAddress and macCoordShortAddress - * depending on the CoordAddrMode in the primitive. - */ - - if (req->coord_addr.mode == IEEE802154_ADDRMODE_EXTENDED) - { - - } - else if (req->coord_addr.mode == IEEE802154_ADDRMODE_EXTENDED) - { - - } - else - { - return -EINVAL; - } - - return -ENOTTY; -} - -/**************************************************************************** - * Name: mac802154_req_disassociate - * - * Description: - * The MLME-DISASSOCIATE.request primitive is used by an associated device to - * notify the coordinator of its intent to leave the PAN. It is also used by - * the coordinator to instruct an associated device to leave the PAN. - * Confirmation is returned via the - * struct ieee802154_maccb_s->conf_disassociate callback. - * - ****************************************************************************/ - -int mac802154_req_disassociate(MACHANDLE mac, - FAR struct ieee802154_disassoc_req_s *req) -{ - FAR struct ieee802154_privmac_s *priv = - (FAR struct ieee802154_privmac_s *)mac; - return -ENOTTY; -} - -/**************************************************************************** - * Name: mac802154_req_get - * - * Description: - * The MLME-GET.request primitive requests information about a given PIB - * attribute. Actual data is returned via the - * struct ieee802154_maccb_s->conf_get callback. - * - ****************************************************************************/ - -int mac802154_req_get(MACHANDLE mac, FAR struct ieee802154_get_req_s *req) -{ - FAR struct ieee802154_privmac_s *priv = - (FAR struct ieee802154_privmac_s *)mac; - return -ENOTTY; -} - -/**************************************************************************** - * Name: mac802154_req_gts - * - * Description: - * The MLME-GTS.request primitive allows a device to send a request to the PAN - * coordinator to allocate a new GTS or to deallocate an existing GTS. - * Confirmation is returned via the - * struct ieee802154_maccb_s->conf_gts callback. - * - ****************************************************************************/ - -int mac802154_req_gts(MACHANDLE mac, FAR struct ieee802154_gts_req_s *req) -{ - FAR struct ieee802154_privmac_s *priv = - (FAR struct ieee802154_privmac_s *)mac; - return -ENOTTY; -} - -/**************************************************************************** - * Name: mac802154_req_reset - * - * Description: - * The MLME-RESET.request primitive allows the next higher layer to request - * that the MLME performs a reset operation. Confirmation is returned via - * the struct ieee802154_maccb_s->conf_reset callback. - * - ****************************************************************************/ - -int mac802154_req_reset(MACHANDLE mac, FAR struct ieee802154_reset_req_s *req) -{ - FAR struct ieee802154_privmac_s * priv = - (FAR struct ieee802154_privmac_s *) mac; - return -ENOTTY; -} - -/**************************************************************************** - * Name: mac802154_req_rxenable - * - * Description: - * The MLME-RX-ENABLE.request primitive allows the next higher layer to - * request that the receiver is enable for a finite period of time. - * Confirmation is returned via the - * struct ieee802154_maccb_s->conf_rxenable callback. - * - ****************************************************************************/ - -int mac802154_req_rxenable(MACHANDLE mac, - FAR struct ieee802154_rxenable_req_s *req) -{ - FAR struct ieee802154_privmac_s * priv = - (FAR struct ieee802154_privmac_s *)mac; - return -ENOTTY; -} - -/**************************************************************************** - * Name: mac802154_req_scan - * - * Description: - * The MLME-SCAN.request primitive is used to initiate a channel scan over a - * given list of channels. A device can use a channel scan to measure the - * energy on the channel, search for the coordinator with which it associated, - * or search for all coordinators transmitting beacon frames within the POS of - * the scanning device. Scan results are returned - * via MULTIPLE calls to the struct ieee802154_maccb_s->conf_scan callback. - * This is a difference with the official 802.15.4 specification, implemented - * here to save memory. - * - ****************************************************************************/ - -int mac802154_req_scan(MACHANDLE mac, FAR struct ieee802154_scan_req_s *req) -{ - FAR struct ieee802154_privmac_s *priv = - (FAR struct ieee802154_privmac_s *)mac; - return -ENOTTY; -} - -/**************************************************************************** - * Name: mac802154_req_set - * - * Description: - * The MLME-SET.request primitive attempts to write the given value to the - * indicated MAC PIB attribute. Confirmation is returned via the - * struct ieee802154_maccb_s->conf_set callback. - * - ****************************************************************************/ - -int mac802154_req_set(MACHANDLE mac, FAR struct ieee802154_set_req_s *req) -{ - FAR struct ieee802154_privmac_s *priv = - (FAR struct ieee802154_privmac_s *)mac; - return -ENOTTY; -} - -/**************************************************************************** - * Name: mac802154_req_start - * - * Description: - * The MLME-START.request primitive makes a request for the device to start - * using a new superframe configuration. Confirmation is returned - * via the struct ieee802154_maccb_s->conf_start callback. - * - ****************************************************************************/ - -int mac802154_req_start(MACHANDLE mac, FAR struct ieee802154_start_req_s *req) -{ - FAR struct ieee802154_privmac_s *priv = - (FAR struct ieee802154_privmac_s *)mac; - return -ENOTTY; -} - -/**************************************************************************** - * Name: mac802154_req_sync - * - * Description: - * The MLME-SYNC.request primitive requests to synchronize with the - * coordinator by acquiring and, if specified, tracking its beacons. - * Confirmation is returned via the - * struct ieee802154_maccb_s->int_commstatus callback. TOCHECK. - * - ****************************************************************************/ - -int mac802154_req_sync(MACHANDLE mac, FAR struct ieee802154_sync_req_s *req) -{ - FAR struct ieee802154_privmac_s *priv = - (FAR struct ieee802154_privmac_s *)mac; - return -ENOTTY; -} - -/**************************************************************************** - * Name: mac802154_req_poll - * - * Description: - * The MLME-POLL.request primitive prompts the device to request data from - * the coordinator. Confirmation is returned via the - * struct ieee802154_maccb_s->conf_poll callback, followed by a - * struct ieee802154_maccb_s->ind_data callback. - * - ****************************************************************************/ - -int mac802154_req_poll(MACHANDLE mac, FAR struct ieee802154_poll_req_s *req) -{ - FAR struct ieee802154_privmac_s *priv = - (FAR struct ieee802154_privmac_s *)mac; - return -ENOTTY; -} - -/**************************************************************************** - * Name: mac802154_rsp_associate - * - * Description: - * The MLME-ASSOCIATE.response primitive is used to initiate a response to - * an MLME-ASSOCIATE.indication primitive. - * - ****************************************************************************/ - -int mac802154_rsp_associate(MACHANDLE mac, - FAR struct ieee802154_assoc_resp_s *resp) -{ - FAR struct ieee802154_privmac_s *priv = - (FAR struct ieee802154_privmac_s *)mac; - return -ENOTTY; -} - -/**************************************************************************** - * Name: mac802154_rsp_orphan - * - * Description: - * The MLME-ORPHAN.response primitive allows the next higher layer of a - * coordinator to respond to the MLME-ORPHAN.indication primitive. - * - ****************************************************************************/ - -int mac802154_rsp_orphan(MACHANDLE mac, - FAR struct ieee802154_orphan_resp_s *resp) -{ - FAR struct ieee802154_privmac_s *priv = - (FAR struct ieee802154_privmac_s *)mac; - return -ENOTTY; -} +/**************************************************************************** + * wireless/ieee802154/mac802154.c + * + * Copyright (C) 2016 Sebastien Lorquet. All rights reserved. + * Author: Sebastien Lorquet + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include + +#include +#include + +#include + +#include + +#include "mac802154.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ +/* Configuration ************************************************************/ +/* If processing is not done at the interrupt level, then work queue support + * is required. + */ + +#if !defined(CONFIG_SCHED_WORKQUEUE) +# error Work queue support is required in this configuration (CONFIG_SCHED_WORKQUEUE) +#else + + /* Use the low priority work queue if possible */ + +# if defined(CONFIG_MAC802154_HPWORK) +# define MAC802154_WORK HPWORK +# elif defined(CONFIG_MAC802154_LPWORK) +# define MAC802154_WORK LPWORK +# else +# error Neither CONFIG_MAC802154_HPWORK nor CONFIG_MAC802154_LPWORK defined +# endif +#endif + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +struct mac802154_trans_s +{ + /* Supports a singly linked list */ + + FAR struct mac802154_trans_s *flink; + FAR struct iob_s *frame; + uint8_t msdu_handle; + sem_t sem; +}; + +struct mac802154_unsec_mhr_s +{ + uint8_t length; + union + { + uint16_t frame_control; + uint8_t data[IEEE802154_MAX_UNSEC_MHR_OVERHEAD]; + } u; +}; + +struct mac802154_radiocb_s +{ + struct ieee802154_radiocb_s cb; + FAR struct ieee802154_privmac_s *priv; +}; + +/* The privmac structure holds the internal state of the MAC and is the + * underlying represention of the opaque MACHANDLE. It contains storage for + * the IEEE802.15.4 MIB attributes. + */ + +struct ieee802154_privmac_s +{ + FAR struct ieee802154_radio_s *radio; /* Contained IEEE802.15.4 radio dev */ + FAR const struct ieee802154_maccb_s *cb; /* Contained MAC callbacks */ + FAR struct mac802154_radiocb_s radiocb; /* Interface to bind to radio */ + + sem_t exclsem; /* Support exclusive access */ + + struct work_s tx_work; + struct work_s rx_work; + + /* Support a singly linked list of transactions that will be sent using the + * CSMA algorithm. On a non-beacon enabled PAN, these transactions will be + * sent whenever. On a beacon-enabled PAN, these transactions will be sent + * during the CAP of the Coordinator's superframe. + */ + + FAR struct mac802154_trans_s *csma_head; + FAR struct mac802154_trans_s *csma_tail; + + /* Support a singly linked list of transactions that will be sent indirectly. + * This list should only be used by a MAC acting as a coordinator. These + * transactions will stay here until the data is extracted by the destination + * device sending a Data Request MAC command or if too much time passes. This + * list should also be used to populate the address list of the outgoing + * beacon frame. + */ + + FAR struct mac802154_trans_s *indirect_head; + FAR struct mac802154_trans_s *indirect_tail; + + uint8_t txdesc_count; + struct ieee802154_txdesc_s txdesc[CONFIG_IEEE802154_NTXDESC]; + + /* Support a singly linked list of frames received */ + FAR struct iob_s *rxframes_head; + FAR struct iob_s *rxframes_tail; + + /* MAC PIB attributes, grouped to save memory */ + + /* Holds all address information (Extended, Short, and PAN ID) for the MAC. */ + + struct ieee802154_addr_s addr; + + /* Holds all address information (Extended, Short) for Coordinator */ + + struct ieee802154_addr_s coord_addr; + + /* The maximum number of symbols to wait for an acknowledgement frame to + * arrive following a transmitted data frame. [1] pg. 126 + * + * NOTE: This may be able to be a 16-bit or even an 8-bit number. I wasn't + * sure at the time what the range of reasonable values was. + */ + + uint32_t ack_wait_dur; + + /* The maximum time to wait either for a frame intended as a response to a + * data request frame or for a broadcast frame following a beacon with the + * Frame Pending field set to one. [1] pg. 127 + * + * NOTE: This may be able to be a 16-bit or even an 8-bit number. I wasn't + * sure at the time what the range of reasonable values was. + */ + + uint32_t max_frame_wait_time; + + /* The maximum time (in unit periods) that a transaction is stored by a + * coordinator and indicated in its beacon. + */ + + uint16_t trans_persist_time; + + /* Contents of beacon payload */ + + uint8_t beacon_payload[IEEE802154_MAX_BEACON_PAYLOAD_LENGTH]; + uint8_t beacon_payload_len; /* Length of beacon payload */ + + uint8_t batt_life_ext_periods; /* # of backoff periods during which rx is + * enabled after the IFS following beacon */ + + uint8_t bsn; /* Seq. num added to tx beacon frame */ + uint8_t dsn; /* Seq. num added to tx data or MAC frame */ + uint8_t max_retries; /* Max # of retries alloed after tx failure */ + + /* The maximum time, in multiples of aBaseSuperframeDuration, a device shall + * wait for a response command frame to be available following a request + * command frame. [1] 128. + */ + + uint8_t resp_wait_time; + + /* The total transmit duration (including PHY header and FCS) specified in + * symbols. [1] pg. 129. + */ + + uint32_t tx_total_dur; + + /* Start of 32-bit bitfield */ + + uint32_t is_assoc : 1; /* Are we associated to the PAN */ + uint32_t assoc_permit : 1; /* Are we allowing assoc. as a coord. */ + uint32_t auto_req : 1; /* Automatically send data req. if addr + * addr is in the beacon frame */ + + uint32_t batt_life_ext : 1; /* Is BLE enabled */ + uint32_t gts_permit : 1; /* Is PAN Coord. accepting GTS reqs. */ + uint32_t promiscuous_mode : 1; /* Is promiscuous mode on? */ + uint32_t ranging_supported : 1; /* Does MAC sublayer support ranging */ + uint32_t rx_when_idle : 1; /* Recvr. on during idle periods */ + uint32_t sec_enabled : 1; /* Does MAC sublayer have security en. */ + + uint32_t max_csma_backoffs : 3; /* Max num backoffs for CSMA algorithm + * before declaring ch access failure */ + + uint32_t beacon_order : 4; /* Freq. that beacon is transmitted */ + + uint32_t superframe_order : 4; /* Length of active portion of outgoing + * superframe, including the beacon */ + + /* The offset, measured is symbols, between the symbol boundary at which the + * MLME captures the timestamp of each transmitted and received frame, and + * the onset of the first symbol past the SFD, namely the first symbol of + * the frames [1] pg. 129. + */ + + uint32_t sync_symb_offset : 12; + + /* End of 32-bit bitfield */ + + /* Start of 32-bit bitfield */ + + uint32_t beacon_tx_time : 24; /* Time of last beacon transmit */ + uint32_t min_be : 4; /* Min value of backoff exponent (BE) */ + uint32_t max_be : 4; /* Max value of backoff exponent (BE) */ + + /* End of 32-bit bitfield */ + + /* Start of 32-bit bitfield */ + + uint32_t tx_ctrl_active_dur : 17; /* Duration for which tx is permitted to + * be active */ + uint32_t tx_ctrl_pause_dur : 1; /* Duration after tx before another tx is + * permitted. 0=2000, 1= 10000 */ + uint32_t timestamp_support : 1; /* Does MAC layer supports timestamping */ + uint32_t is_coord : 1; /* Is this device acting as coordinator */ + /* 12-bits remaining */ + + /* End of 32-bit bitfield. */ + + /* TODO: Add Security-related MAC PIB attributes */ +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static inline int mac802154_takesem(sem_t *sem); +#define mac802154_givesem(s) sem_post(s); + +static void mac802154_txdone_worker(FAR void *arg); +static void mac802154_rxframe_worker(FAR void *arg); + +/* Internal Functions */ + +static int mac802154_defaultmib(FAR struct ieee802154_privmac_s *priv); +static int mac802154_applymib(FAR struct ieee802154_privmac_s *priv); + +/* IEEE 802.15.4 PHY Interface OPs */ + +static int mac802154_poll_csma(FAR const struct ieee802154_radiocb_s *radiocb, + FAR struct ieee802154_txdesc_s *tx_desc, + FAR struct iob_s **frame); + +static int mac802154_poll_gts(FAR const struct ieee802154_radiocb_s *radiocb, + FAR struct ieee802154_txdesc_s *tx_desc, + FAR struct iob_s **frame); + +static void mac802154_txdone(FAR const struct ieee802154_radiocb_s *radiocb, + FAR const struct ieee802154_txdesc_s *tx_desc); + +static void mac802154_rxframe(FAR const struct ieee802154_radiocb_s *radiocb, + FAR const struct ieee802154_rxdesc_s *rx_desc, + FAR struct iob_s *frame); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/* Map between ieee802154_addr_mode_e enum and actual address length */ + +static const uint8_t mac802154_addr_length[4] = {0, 0, 2, 8}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: mac802154_semtake + * + * Description: + * Acquire the semaphore used for access serialization. + * + ****************************************************************************/ + +static inline int mac802154_takesem(sem_t *sem) +{ + /* Take a count from the semaphore, possibly waiting */ + + if (sem_wait(sem) < 0) + { + /* EINTR is the only error that we expect */ + + int errcode = get_errno(); + DEBUGASSERT(errcode == EINTR); + return -errcode; + } + + return OK; +} + +/**************************************************************************** + * Name: mac802154_push_csma + * + * Description: + * Push a CSMA transaction onto the list + * + ****************************************************************************/ + +static void mac802154_push_csma(FAR struct ieee802154_privmac_s *priv, + FAR struct mac802154_trans_s *trans) +{ + /* Ensure the transactions forward link is NULL */ + + trans->flink = NULL; + + /* If the tail is not empty, make the transaction pointed to by the tail, + * point to the new transaction */ + + if (priv->csma_tail != NULL) + { + priv->csma_tail->flink = trans; + } + + /* Point the tail at the new transaction */ + + priv->csma_tail = trans; + + /* If the head is NULL, we need to point it at the transaction since there + * is only one transaction in the list at this point */ + + if (priv->csma_head == NULL) + { + priv->csma_head = trans; + } +} + +/**************************************************************************** + * Name: mac802154_pop_csma + * + * Description: + * Pop a CSMA transaction from the list + * + ****************************************************************************/ + +static FAR struct mac802154_trans_s * + mac802154_pop_csma(FAR struct ieee802154_privmac_s *priv) +{ + FAR struct mac802154_trans_s *trans; + + if (priv->csma_head == NULL) + { + return NULL; + } + + /* Get the transaction from the head of the list */ + + trans = priv->csma_head; + + /* Move the head pointer to the next transaction */ + + priv->csma_head = trans->flink; + + /* If the head is now NULL, the list is empty, so clear the tail too */ + + if (priv->csma_head == NULL) + { + priv->csma_tail = NULL; + } + + return trans; +} + +/**************************************************************************** + * Name: mac802154_defaultmib + * + * Description: + * Set the MIB to its default values. + * + ****************************************************************************/ + +static int mac802154_defaultmib(FAR struct ieee802154_privmac_s *priv) +{ + /* TODO: Set all MAC fields to default values */ + + return OK; +} + +/**************************************************************************** + * Name: mac802154_applymib + * + * Description: + * Some parts of the MIB must be sent to the radio device. This routine + * calls the radio device routines to store the related parameters in the + * radio driver. It must be called each time a MIB parameter is changed. + * + ****************************************************************************/ + +static int mac802154_applymib(FAR struct ieee802154_privmac_s *priv) +{ + return OK; +} + +/**************************************************************************** + * Name: mac802154_poll_csma + * + * Description: + * Called from the radio driver through the callback struct. This function is + * called when the radio has room for another CSMA transaction. If the MAC + * layer has a CSMA transaction, it copies it into the supplied buffer and + * returns the length. A descriptor is also populated with the transaction. + * + ****************************************************************************/ + +static int mac802154_poll_csma(FAR const struct ieee802154_radiocb_s *radiocb, + FAR struct ieee802154_txdesc_s *tx_desc, + FAR struct iob_s **frame) +{ + FAR struct mac802154_radiocb_s *cb = + (FAR struct mac802154_radiocb_s *)radiocb; + FAR struct ieee802154_privmac_s *priv; + FAR struct mac802154_trans_s *trans; + + DEBUGASSERT(cb != NULL && cb->priv != NULL); + priv = cb->priv; + + /* Get exclusive access to the driver structure. We don't care about any + * signals so if we see one, just go back to trying to get access again. + */ + + while (mac802154_takesem(&priv->exclsem) != 0); + + /* Check to see if there are any CSMA transactions waiting */ + + trans = mac802154_pop_csma(priv); + mac802154_givesem(&priv->exclsem); + + if (trans != NULL) + { + /* Setup the transmit descriptor */ + + tx_desc->handle = trans->msdu_handle; + + *frame = trans->frame; + + /* Now that we've passed off the data, notify the waiting thread. + * NOTE: The transaction was allocated on the waiting thread's stack so + * it will be automatically deallocated when that thread awakens and + * returns. */ + + sem_post(&trans->sem); + return (trans->frame->io_len); + } + + return 0; +} + +/**************************************************************************** + * Name: mac802154_poll_gts + * + * Description: + * Called from the radio driver through the callback struct. This function is + * called when the radio has room for another GTS transaction. If the MAC + * layer has a GTS transaction, it copies it into the supplied buffer and + * returns the length. A descriptor is also populated with the transaction. + * + ****************************************************************************/ + +static int mac802154_poll_gts(FAR const struct ieee802154_radiocb_s *radiocb, + FAR struct ieee802154_txdesc_s *tx_desc, + FAR struct iob_s **frame) +{ + FAR struct mac802154_radiocb_s *cb = + (FAR struct mac802154_radiocb_s *)radiocb; + FAR struct ieee802154_privmac_s *priv; + FAR struct mac802154_trans_s *trans; + int ret = 0; + + DEBUGASSERT(cb != NULL && cb->priv != NULL); + priv = cb->priv; + + /* Get exclusive access to the driver structure. We don't care about any + * signals so if we see one, just go back to trying to get access again. + */ + + while (mac802154_takesem(&priv->exclsem) != 0); + +#warning Missing logic. + + mac802154_givesem(&priv->exclsem); + + return 0; +} + +/**************************************************************************** + * Name: mac802154_txdone + * + * Description: + * Called from the radio driver through the callback struct. This function is + * called when the radio has completed a transaction. The txdesc passed gives + * provides information about the completed transaction including the original + * handle provided when the transaction was created and the status of the + * transaction. This function copies the descriptor and schedules work to + * handle the transaction without blocking the radio. + * + ****************************************************************************/ + +static void mac802154_txdone(FAR const struct ieee802154_radiocb_s *radiocb, + FAR const struct ieee802154_txdesc_s *tx_desc) +{ + FAR struct mac802154_radiocb_s *cb = + (FAR struct mac802154_radiocb_s *)radiocb; + FAR struct ieee802154_privmac_s *priv; + + DEBUGASSERT(cb != NULL && cb->priv != NULL); + priv = cb->priv; + + /* Get exclusive access to the driver structure. We don't care about any + * signals so if we see one, just go back to trying to get access again. + */ + + while (mac802154_takesem(&priv->exclsem) != 0); + + /* Check to see if there is an available tx descriptor slot. If there is + * not we simply drop the notification */ + + if (priv->txdesc_count < CONFIG_IEEE802154_NTXDESC) + { + /* Copy the txdesc over and link it into our list */ + + memcpy(&priv->txdesc[priv->txdesc_count++], tx_desc, + sizeof(struct ieee802154_txdesc_s)); + } + else + { + wlinfo("MAC802154: No room for TX Desc.\n"); + } + + mac802154_givesem(&priv->exclsem); + + /* Schedule work with the work queue to process the completion further */ + + if (work_available(&priv->tx_work)) + { + work_queue(MAC802154_WORK, &priv->tx_work, mac802154_txdone_worker, + (FAR void *)priv, 0); + } +} + +/**************************************************************************** + * Name: mac802154_txdone_worker + * + * Description: + * Worker function scheduled from mac802154_txdone. This function pops any + * TX descriptors off of the list and calls the next highest layers callback + * to inform the layer of the completed transaction and the status of it. + * + ****************************************************************************/ + +static void mac802154_txdone_worker(FAR void *arg) +{ + FAR struct ieee802154_privmac_s *priv = + (FAR struct ieee802154_privmac_s *)arg; + int i = 0; + + /* Get exclusive access to the driver structure. We don't care about any + * signals so if we see one, just go back to trying to get access again. + */ + + while (mac802154_takesem(&priv->exclsem) != 0); + + /* For each pending TX descriptor, send an application callback */ + + for (i = 0; i < priv->txdesc_count; i++) + { + priv->cb->mcps_notify(priv->cb, IEEE802154_NOTIFY_CONF_DATA, + (FAR const union ieee802154_mcps_notify_u *) &priv->txdesc[i]); + } + + /* We've handled all the descriptors and no further desc could have been added + * since we have the struct locked */ + + priv->txdesc_count = 0; + + mac802154_givesem(&priv->exclsem); +} + +/**************************************************************************** + * Name: mac802154_rxframe + * + * Description: + * Called from the radio driver through the callback struct. This function is + * called when the radio has received a frame. The frame is passed in an iob, + * so that we can free it when we are done processing. A pointer to the RX + * descriptor is passed along with the iob, but it must be copied here as it + * is allocated directly on the caller's stack. We simply link the frame, + * copy the RX descriptor, and schedule a worker to process the frame later so + * that we do not hold up the radio. + * + ****************************************************************************/ + +static void mac802154_rxframe(FAR const struct ieee802154_radiocb_s *radiocb, + FAR const struct ieee802154_rxdesc_s *rx_desc, + FAR struct iob_s *frame) +{ + FAR struct mac802154_radiocb_s *cb = + (FAR struct mac802154_radiocb_s *)radiocb; + FAR struct ieee802154_privmac_s *priv; + FAR struct ieee802154_rxdesc_s *desc; + + DEBUGASSERT(cb != NULL && cb->priv != NULL); + priv = cb->priv; + + /* Get exclusive access to the driver structure. We don't care about any + * signals so if we see one, just go back to trying to get access again. + */ + + while (mac802154_takesem(&priv->exclsem) != 0); + + /* TODO: Copy the frame descriptor to some type of list */ + + /* Push the iob onto the tail of the frame list for processing */ + + priv->rxframes_tail->io_flink = frame; + priv->rxframes_tail = frame; + + mac802154_givesem(&priv->exclsem); + + /* Schedule work with the work queue to process the completion further */ + + if (work_available(&priv->rx_work)) + { + work_queue(MAC802154_WORK, &priv->rx_work, mac802154_rxframe_worker, + (FAR void *)priv, 0); + } +} + +/**************************************************************************** + * Name: mac802154_rxframe_worker + * + * Description: + * Worker function scheduled from mac802154_rxframe. This function processes + * any frames in the list. Frames intended to be consumed by the MAC layer + * will not produce any callbacks to the next highest layer. Frames intended + * for the application layer will be forwarded to them. + * + ****************************************************************************/ + +static void mac802154_rxframe_worker(FAR void *arg) +{ + FAR struct ieee802154_privmac_s *priv = + (FAR struct ieee802154_privmac_s *)arg; + + /* The radio layer is responsible for handling all ACKs and retries. If for + * some reason an ACK gets here, just throw it out. + */ +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: mac802154_create + * + * Description: + * Create a 802.15.4 MAC device from a 802.15.4 compatible radio device. + * + * The returned MAC structure should be passed to either the next highest + * layer in the network stack, or registered with a mac802154dev character + * or network drivers. In any of these scenarios, the next highest layer + * should register a set of callbacks with the MAC layer by setting the + * mac->cbs member. + * + * NOTE: 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. + * + * Input Parameters: + * radiodev - an instance of an IEEE 802.15.4 radio + * + * Returned Value: + * An opaque reference to the MAC state data. + * + ****************************************************************************/ + +MACHANDLE mac802154_create(FAR struct ieee802154_radio_s *radiodev) +{ + FAR struct ieee802154_privmac_s *mac; + FAR struct ieee802154_radiocb_s *radiocb; + + /* Allocate object */ + + mac = (FAR struct ieee802154_privmac_s *) + kmm_zalloc(sizeof(struct ieee802154_privmac_s)); + + if (mac == NULL) + { + return NULL; + } + + /* Allow exclusive access to the privmac struct */ + + sem_init(&mac->exclsem, 0, 1); + + /* Initialize fields */ + + mac->radio = radiodev; + + mac802154_defaultmib(mac); + mac802154_applymib(mac); + + /* Initialize the Radio callbacks */ + + mac->radiocb.priv = mac; + + radiocb = &mac->radiocb.cb; + radiocb->poll_csma = mac802154_poll_csma; + radiocb->poll_gts = mac802154_poll_gts; + radiocb->txdone = mac802154_txdone; + radiocb->rxframe = mac802154_rxframe; + + /* Bind our callback structure */ + + radiodev->ops->bind(radiodev, &mac->radiocb.cb); + + return (MACHANDLE)mac; +} + +/**************************************************************************** + * Name: mac802154_bind + * + * Description: + * Bind the MAC callback table to the MAC state. + * + * Parameters: + * mac - Reference to the MAC driver state structure + * cb - MAC callback operations + * + * Returned Value: + * OK on success; Negated errno on failure. + * + ****************************************************************************/ + +int mac802154_bind(MACHANDLE mac, FAR const struct ieee802154_maccb_s *cb) +{ + FAR struct ieee802154_privmac_s *priv = + (FAR struct ieee802154_privmac_s *)mac; + + priv->cb = cb; + return OK; +} + +/**************************************************************************** + * Name: mac802154_ioctl + * + * Description: + * Handle MAC and radio IOCTL commands directed to the MAC. + * + * Parameters: + * mac - Reference to the MAC driver state structure + * cmd - The IOCTL command + * arg - The argument for the IOCTL command + * + * Returned Value: + * OK on success; Negated errno on failure. + * + ****************************************************************************/ + +int mac802154_ioctl(MACHANDLE mac, int cmd, unsigned long arg) +{ + FAR struct ieee802154_privmac_s *priv = + (FAR struct ieee802154_privmac_s *)mac; + int ret = -EINVAL; + + DEBUGASSERT(priv != NULL); + + /* Check for IOCTLs aimed at the IEEE802.15.4 MAC layer */ + + if (_MAC802154IOCVALID(cmd)) + { + /* Handle the MAC IOCTL command */ +#warning Missing logic + } + + /* No, other IOCTLs must be aimed at the IEEE802.15.4 radio layer */ + + else + { + DEBUGASSERT(priv->radio != NULL && + priv->radio->ops != NULL && + priv->radio->ops->ioctl != NULL); + + ret = priv->radio->ops->ioctl(priv->radio, cmd, arg); + } + + return ret; +} + +/**************************************************************************** + * MAC Interface Operations + ****************************************************************************/ + +/**************************************************************************** + * Name: mac802154_get_mhrlen + * + * Description: + * Calculate the MAC header length given the frame meta-data. + * + ****************************************************************************/ + +int mac802154_get_mhrlen(MACHANDLE mac, + FAR struct ieee802154_frame_meta_s *meta) +{ + FAR struct ieee802154_privmac_s *priv = + (FAR struct ieee802154_privmac_s *)mac; + int ret = 3; /* Always frame control (2 bytes) and seq. num (1 byte) */ + + /* Check to make sure both the dest address and the source address are not set + * to NONE */ + + if (meta->dest_addr.mode == IEEE802154_ADDRMODE_NONE && + meta->src_addr_mode == IEEE802154_ADDRMODE_NONE) + { + return -EINVAL; + } + + /* The source address can only be set to NONE if the device is the PAN coord */ + + if (meta->src_addr_mode == IEEE802154_ADDRMODE_NONE && !priv->is_coord) + { + return -EINVAL; + } + + /* Add the destination address length */ + + ret += mac802154_addr_length[meta->dest_addr.mode]; + + /* Add the source address length */ + + ret += mac802154_addr_length[ meta->src_addr_mode]; + + /* If both destination and source addressing information is present, the MAC + * sublayer shall compare the destination and source PAN identifiers. + * [1] pg. 41. + */ + + if (meta->src_addr_mode != IEEE802154_ADDRMODE_NONE && + meta->dest_addr.mode != IEEE802154_ADDRMODE_NONE) + { + /* If the PAN identifiers are identical, the PAN ID Compression field + * shall be set to one, and the source PAN identifier shall be omitted + * from the transmitted frame. [1] pg. 41. + */ + + if (meta->dest_addr.panid == priv->addr.panid) + { + ret += 2; /* 2 bytes for destination PAN ID */ + return ret; + } + } + + /* If we are here, PAN ID compression is off, so include the dest and source + * PAN ID if the respective address is included + */ + + if (meta->src_addr_mode != IEEE802154_ADDRMODE_NONE) + { + ret += 2; /* 2 bytes for source PAN ID */ + } + + if (meta->dest_addr.mode != IEEE802154_ADDRMODE_NONE) + { + ret += 2; /* 2 bytes for destination PAN ID */ + } + + return ret; +} + +/**************************************************************************** + * Name: mac802154_req_data + * + * Description: + * The MCPS-DATA.request primitive requests the transfer of a data SPDU + * (i.e., MSDU) from a local SSCS entity to a single peer SSCS entity. + * Confirmation is returned via the + * struct ieee802154_maccb_s->conf_data callback. + * + ****************************************************************************/ + +int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) +{ + FAR struct ieee802154_privmac_s *priv = + (FAR struct ieee802154_privmac_s *)mac; + FAR struct mac802154_trans_s trans; + FAR struct ieee802154_frame_meta_s *meta = req->meta; + uint16_t *frame_ctrl; + uint8_t mhr_len = 3; /* Start assuming frame control and seq. num */ + int ret; + + /* Check the required frame size */ + + if (req->frame->io_len > IEEE802154_MAX_PHY_PACKET_SIZE) + { + return -E2BIG; + } + + /* Cast the first two bytes of the IOB to a uint16_t frame control field */ + + frame_ctrl = (uint16_t *)&req->frame->io_data[0]; + + /* Ensure we start with a clear frame control field */ + + *frame_ctrl = 0; + + /* Set the frame type to Data */ + + *frame_ctrl |= IEEE802154_FRAME_DATA << IEEE802154_FRAMECTRL_SHIFT_FTYPE; + + /* If the msduLength is greater than aMaxMACSafePayloadSize, the MAC + * sublayer will set the Frame Version to one. [1] pg. 118. + */ + + if (meta->msdu_length > IEEE802154_MAX_SAFE_MAC_PAYLOAD_SIZE) + { + *frame_ctrl |= IEEE802154_FRAMECTRL_VERSION; + } + + /* If the TXOptions parameter specifies that an acknowledged transmission + * is required, the AR field will be set appropriately, as described in + * 5.1.6.4 [1] pg. 118. + */ + + *frame_ctrl |= (meta->msdu_flags.ack_tx << IEEE802154_FRAMECTRL_SHIFT_ACKREQ); + + /* If the destination address is present, copy the PAN ID and one of the + * addresses, depending on mode, into the MHR. + */ + + if (meta->dest_addr.mode != IEEE802154_ADDRMODE_NONE) + { + memcpy(&req->frame->io_data[mhr_len], &meta->dest_addr.panid, 2); + mhr_len += 2; + + if (meta->dest_addr.mode == IEEE802154_ADDRMODE_SHORT) + { + memcpy(&req->frame->io_data[mhr_len], &meta->dest_addr.saddr, 2); + mhr_len += 2; + } + else if (meta->dest_addr.mode == IEEE802154_ADDRMODE_EXTENDED) + { + memcpy(&req->frame->io_data[mhr_len], &meta->dest_addr.eaddr, 8); + mhr_len += 8; + } + } + + /* Set the destination addr mode inside the frame control field */ + + *frame_ctrl |= (meta->dest_addr.mode << IEEE802154_FRAMECTRL_SHIFT_DADDR); + + /* From this point on, we need exclusive access to the privmac struct */ + + ret = mac802154_takesem(&priv->exclsem); + if (ret < 0) + { + wlerr("ERROR: mac802154_takesem failed: %d\n", ret); + return ret; + } + + /* If both destination and source addressing information is present, the MAC + * sublayer shall compare the destination and source PAN identifiers. + * [1] pg. 41. + */ + + if (meta->src_addr_mode != IEEE802154_ADDRMODE_NONE && + meta->dest_addr.mode != IEEE802154_ADDRMODE_NONE) + { + /* If the PAN identifiers are identical, the PAN ID Compression field + * shall be set to one, and the source PAN identifier shall be omitted + * from the transmitted frame. [1] pg. 41. + */ + + if (meta->dest_addr.panid == priv->addr.panid) + { + *frame_ctrl |= IEEE802154_FRAMECTRL_PANIDCOMP; + } + } + + if (meta->src_addr_mode != IEEE802154_ADDRMODE_NONE) + { + /* If the destination address is not included, or if PAN ID Compression + * is off, we need to include the Source PAN ID. + */ + + if ((meta->dest_addr.mode == IEEE802154_ADDRMODE_NONE) || + (*frame_ctrl & IEEE802154_FRAMECTRL_PANIDCOMP)) + { + memcpy(&req->frame->io_data[mhr_len], &priv->addr.panid, 2); + mhr_len += 2; + } + + if (meta->src_addr_mode == IEEE802154_ADDRMODE_SHORT) + { + memcpy(&req->frame->io_data[mhr_len], &priv->addr.saddr, 2); + mhr_len += 2; + } + else if (meta->src_addr_mode == IEEE802154_ADDRMODE_EXTENDED) + { + memcpy(&req->frame->io_data[mhr_len], &priv->addr.eaddr, 8); + mhr_len += 8; + } + } + + /* Set the source addr mode inside the frame control field */ + + *frame_ctrl |= (meta->src_addr_mode << IEEE802154_FRAMECTRL_SHIFT_SADDR); + + /* Each time a data or a MAC command frame is generated, the MAC sublayer + * shall copy the value of macDSN into the Sequence Number field of the MHR + * of the outgoing frame and then increment it by one. [1] pg. 40. + */ + + req->frame->io_data[2] = priv->dsn++; + + /* The MAC header we just created must never have exceeded where the app + * data starts. This should never happen since the offset should have + * been set via the same logic to calculate the header length as the logic + * here that created the header + */ + + DEBUGASSERT(mhr_len == req->frame->io_offset); + + req->frame->io_offset = 0; /* Set the offset to 0 to include the header */ + + /* Setup our transaction */ + + trans.msdu_handle = meta->msdu_handle; + trans.frame = req->frame; + sem_init(&trans.sem, 0, 1); + + /* If the TxOptions parameter specifies that a GTS transmission is required, + * the MAC sublayer will determine whether it has a valid GTS as described + * 5.1.7.3. If a valid GTS could not be found, the MAC sublayer will discard + * the MSDU. If a valid GTS was found, the MAC sublayer will defer, if + * necessary, until the GTS. If the TxOptions parameter specifies that a GTS + * transmission is not required, the MAC sublayer will transmit the MSDU using + * either slotted CSMA-CA in the CAP for a beacon-enabled PAN or unslotted + * CSMA-CA for a nonbeacon-enabled PAN. Specifying a GTS transmission in the + * TxOptions parameter overrides an indirect transmission request. + * [1] pg. 118. + */ + + if (meta->msdu_flags.gts_tx) + { + /* TODO: Support GTS transmission. This should just change where we link + * the transaction. Instead of going in the CSMA transaction list, it + * should be linked to the GTS' transaction list. We'll need to check if + * the GTS is valid, and then find the GTS, before linking. Note, we also + * don't have to try and kick-off any transmission here. + */ + + return -ENOTSUP; + } + else + { + /* If the TxOptions parameter specifies that an indirect transmission is + * required and this primitive is received by the MAC sublayer of a + * coordinator, the data frame is sent using indirect transmission, as + * described in 5.1.5 and 5.1.6.3. [1] + */ + + if (meta->msdu_flags.indirect_tx) + { + /* If the TxOptions parameter specifies that an indirect transmission + * is required and if the device receiving this primitive is not a + * coordinator, the destination address is not present, or the + * TxOptions parameter also specifies a GTS transmission, the indirect + * transmission option will be ignored. [1] + */ + + if (priv->is_coord && meta->dest_addr.mode != IEEE802154_ADDRMODE_NONE) + { + /* Link the transaction into the indirect_trans list */ + + } + else + { + /* Override the setting since it wasn't valid */ + + meta->msdu_flags.indirect_tx = 0; + } + } + + /* If this is a direct transmission not during a GTS */ + + if (!meta->msdu_flags.indirect_tx) + { + /* Link the transaction into the CSMA transaction list */ + + mac802154_push_csma(priv, &trans); + + /* We no longer need to have the MAC layer locked. */ + + mac802154_givesem(&priv->exclsem); + + /* Notify the radio driver that there is data available */ + + priv->radio->ops->txnotify_csma(priv->radio); + + sem_wait(&trans.sem); + } + } + + sem_destroy(&trans.sem); + return OK; +} + +/**************************************************************************** + * Name: mac802154_req_purge + * + * Description: + * The MCPS-PURGE.request primitive allows the next higher layer to purge + * an MSDU from the transaction queue. Confirmation is returned via + * the struct ieee802154_maccb_s->conf_purge callback. + * + ****************************************************************************/ + +int mac802154_req_purge(MACHANDLE mac, FAR struct ieee802154_purge_req_s *req) +{ + FAR struct ieee802154_privmac_s *priv = + (FAR struct ieee802154_privmac_s *)mac; + return -ENOTTY; +} + +/**************************************************************************** + * Name: mac802154_req_associate + * + * Description: + * The MLME-ASSOCIATE.request primitive allows a device to request an + * association with a coordinator. Confirmation is returned via the + * struct ieee802154_maccb_s->conf_associate callback. + * + ****************************************************************************/ + +int mac802154_req_associate(MACHANDLE mac, + FAR struct ieee802154_assoc_req_s *req) +{ + FAR struct ieee802154_privmac_s *priv = + (FAR struct ieee802154_privmac_s *)mac; + + /* Set the channel of the PHY layer */ + + /* Set the channel page of the PHY layer */ + + /* Set the macPANId */ + + /* Set either the macCoordExtendedAddress and macCoordShortAddress + * depending on the CoordAddrMode in the primitive. + */ + + if (req->coord_addr.mode == IEEE802154_ADDRMODE_EXTENDED) + { + + } + else if (req->coord_addr.mode == IEEE802154_ADDRMODE_EXTENDED) + { + + } + else + { + return -EINVAL; + } + + return -ENOTTY; +} + +/**************************************************************************** + * Name: mac802154_req_disassociate + * + * Description: + * The MLME-DISASSOCIATE.request primitive is used by an associated device to + * notify the coordinator of its intent to leave the PAN. It is also used by + * the coordinator to instruct an associated device to leave the PAN. + * Confirmation is returned via the + * struct ieee802154_maccb_s->conf_disassociate callback. + * + ****************************************************************************/ + +int mac802154_req_disassociate(MACHANDLE mac, + FAR struct ieee802154_disassoc_req_s *req) +{ + FAR struct ieee802154_privmac_s *priv = + (FAR struct ieee802154_privmac_s *)mac; + return -ENOTTY; +} + +/**************************************************************************** + * Name: mac802154_req_get + * + * Description: + * The MLME-GET.request primitive requests information about a given PIB + * attribute. Actual data is returned via the + * struct ieee802154_maccb_s->conf_get callback. + * + ****************************************************************************/ + +int mac802154_req_get(MACHANDLE mac, FAR struct ieee802154_get_req_s *req) +{ + FAR struct ieee802154_privmac_s *priv = + (FAR struct ieee802154_privmac_s *)mac; + return -ENOTTY; +} + +/**************************************************************************** + * Name: mac802154_req_gts + * + * Description: + * The MLME-GTS.request primitive allows a device to send a request to the PAN + * coordinator to allocate a new GTS or to deallocate an existing GTS. + * Confirmation is returned via the + * struct ieee802154_maccb_s->conf_gts callback. + * + ****************************************************************************/ + +int mac802154_req_gts(MACHANDLE mac, FAR struct ieee802154_gts_req_s *req) +{ + FAR struct ieee802154_privmac_s *priv = + (FAR struct ieee802154_privmac_s *)mac; + return -ENOTTY; +} + +/**************************************************************************** + * Name: mac802154_req_reset + * + * Description: + * The MLME-RESET.request primitive allows the next higher layer to request + * that the MLME performs a reset operation. Confirmation is returned via + * the struct ieee802154_maccb_s->conf_reset callback. + * + ****************************************************************************/ + +int mac802154_req_reset(MACHANDLE mac, FAR struct ieee802154_reset_req_s *req) +{ + FAR struct ieee802154_privmac_s * priv = + (FAR struct ieee802154_privmac_s *) mac; + return -ENOTTY; +} + +/**************************************************************************** + * Name: mac802154_req_rxenable + * + * Description: + * The MLME-RX-ENABLE.request primitive allows the next higher layer to + * request that the receiver is enable for a finite period of time. + * Confirmation is returned via the + * struct ieee802154_maccb_s->conf_rxenable callback. + * + ****************************************************************************/ + +int mac802154_req_rxenable(MACHANDLE mac, + FAR struct ieee802154_rxenable_req_s *req) +{ + FAR struct ieee802154_privmac_s * priv = + (FAR struct ieee802154_privmac_s *)mac; + return -ENOTTY; +} + +/**************************************************************************** + * Name: mac802154_req_scan + * + * Description: + * The MLME-SCAN.request primitive is used to initiate a channel scan over a + * given list of channels. A device can use a channel scan to measure the + * energy on the channel, search for the coordinator with which it associated, + * or search for all coordinators transmitting beacon frames within the POS of + * the scanning device. Scan results are returned + * via MULTIPLE calls to the struct ieee802154_maccb_s->conf_scan callback. + * This is a difference with the official 802.15.4 specification, implemented + * here to save memory. + * + ****************************************************************************/ + +int mac802154_req_scan(MACHANDLE mac, FAR struct ieee802154_scan_req_s *req) +{ + FAR struct ieee802154_privmac_s *priv = + (FAR struct ieee802154_privmac_s *)mac; + return -ENOTTY; +} + +/**************************************************************************** + * Name: mac802154_req_set + * + * Description: + * The MLME-SET.request primitive attempts to write the given value to the + * indicated MAC PIB attribute. Confirmation is returned via the + * struct ieee802154_maccb_s->conf_set callback. + * + ****************************************************************************/ + +int mac802154_req_set(MACHANDLE mac, FAR struct ieee802154_set_req_s *req) +{ + FAR struct ieee802154_privmac_s *priv = + (FAR struct ieee802154_privmac_s *)mac; + return -ENOTTY; +} + +/**************************************************************************** + * Name: mac802154_req_start + * + * Description: + * The MLME-START.request primitive makes a request for the device to start + * using a new superframe configuration. Confirmation is returned + * via the struct ieee802154_maccb_s->conf_start callback. + * + ****************************************************************************/ + +int mac802154_req_start(MACHANDLE mac, FAR struct ieee802154_start_req_s *req) +{ + FAR struct ieee802154_privmac_s *priv = + (FAR struct ieee802154_privmac_s *)mac; + return -ENOTTY; +} + +/**************************************************************************** + * Name: mac802154_req_sync + * + * Description: + * The MLME-SYNC.request primitive requests to synchronize with the + * coordinator by acquiring and, if specified, tracking its beacons. + * Confirmation is returned via the + * struct ieee802154_maccb_s->int_commstatus callback. TOCHECK. + * + ****************************************************************************/ + +int mac802154_req_sync(MACHANDLE mac, FAR struct ieee802154_sync_req_s *req) +{ + FAR struct ieee802154_privmac_s *priv = + (FAR struct ieee802154_privmac_s *)mac; + return -ENOTTY; +} + +/**************************************************************************** + * Name: mac802154_req_poll + * + * Description: + * The MLME-POLL.request primitive prompts the device to request data from + * the coordinator. Confirmation is returned via the + * struct ieee802154_maccb_s->conf_poll callback, followed by a + * struct ieee802154_maccb_s->ind_data callback. + * + ****************************************************************************/ + +int mac802154_req_poll(MACHANDLE mac, FAR struct ieee802154_poll_req_s *req) +{ + FAR struct ieee802154_privmac_s *priv = + (FAR struct ieee802154_privmac_s *)mac; + return -ENOTTY; +} + +/**************************************************************************** + * Name: mac802154_rsp_associate + * + * Description: + * The MLME-ASSOCIATE.response primitive is used to initiate a response to + * an MLME-ASSOCIATE.indication primitive. + * + ****************************************************************************/ + +int mac802154_rsp_associate(MACHANDLE mac, + FAR struct ieee802154_assoc_resp_s *resp) +{ + FAR struct ieee802154_privmac_s *priv = + (FAR struct ieee802154_privmac_s *)mac; + return -ENOTTY; +} + +/**************************************************************************** + * Name: mac802154_rsp_orphan + * + * Description: + * The MLME-ORPHAN.response primitive allows the next higher layer of a + * coordinator to respond to the MLME-ORPHAN.indication primitive. + * + ****************************************************************************/ + +int mac802154_rsp_orphan(MACHANDLE mac, + FAR struct ieee802154_orphan_resp_s *resp) +{ + FAR struct ieee802154_privmac_s *priv = + (FAR struct ieee802154_privmac_s *)mac; + return -ENOTTY; +} diff --git a/wireless/ieee802154/mac802154.h b/wireless/ieee802154/mac802154.h index ea582e4e7a4..d0d7e82ce23 100644 --- a/wireless/ieee802154/mac802154.h +++ b/wireless/ieee802154/mac802154.h @@ -105,7 +105,7 @@ int mac802154_ioctl(MACHANDLE mac, int cmd, unsigned long arg); * ****************************************************************************/ -int mac802154_get_mhrlen(MACHANDLE mac, +int mac802154_get_mhrlen(MACHANDLE mac, FAR struct ieee802154_frame_meta_s *meta); /**************************************************************************** diff --git a/wireless/ieee802154/mac802154_device.c b/wireless/ieee802154/mac802154_device.c index 998cca074f7..83798b47346 100644 --- a/wireless/ieee802154/mac802154_device.c +++ b/wireless/ieee802154/mac802154_device.c @@ -446,7 +446,7 @@ static ssize_t mac802154dev_write(FAR struct file *filep, wlerr("ERROR: TX meta-data is invalid"); return ret; } - + iob->io_offset = ret; iob->io_len = iob->io_offset; From 4ec14bb2e4cfe36d73accf9f59f940d71b9f80f7 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 2 May 2017 16:03:26 -0600 Subject: [PATCH 116/183] 6loWPAN: Add basic call path to interface with the MAC layer through the MAC network driver. Logic has not yet been implemented. This is just a structural change in preparation for additional changes. --- include/nuttx/net/sixlowpan.h | 29 +++ .../wireless/ieee802154/ieee802154_mac.h | 2 +- wireless/ieee802154/mac802154_loopback.c | 189 +++++++++++++++--- wireless/ieee802154/mac802154_netdev.c | 118 +++++++++-- 4 files changed, 296 insertions(+), 42 deletions(-) diff --git a/include/nuttx/net/sixlowpan.h b/include/nuttx/net/sixlowpan.h index f67ac0d98e3..2e65199513f 100644 --- a/include/nuttx/net/sixlowpan.h +++ b/include/nuttx/net/sixlowpan.h @@ -402,6 +402,8 @@ * frame list. */ +struct ieee802154_frame_meta_s; /* Forward reference */ + struct ieee802154_driver_s { /* This definitiona must appear first in the structure definition to @@ -498,6 +500,33 @@ struct ieee802154_driver_s systime_t i_time; #endif /* CONFIG_NET_6LOWPAN_FRAG */ + + /* MAC network driver callback functions **********************************/ + /************************************************************************** + * Name: mac802154_get_mhrlen + * + * Description: + * Calculate the MAC header length given the frame meta-data. + * + **************************************************************************/ + + CODE int (*i_get_mhrlen)(FAR struct ieee802154_driver_s *netdev, + FAR struct ieee802154_frame_meta_s *meta); + + /************************************************************************** + * Name: mac802154_req_data + * + * Description: + * The MCPS-DATA.request primitive requests the transfer of a data SPDU + * (i.e., MSDU) from a local SSCS entity to a single peer SSCS entity. + * Confirmation is returned via the + * struct ieee802154_maccb_s->conf_data callback. + * + **************************************************************************/ + + CODE int (*i_req_data)(FAR struct ieee802154_driver_s *netdev, + FAR struct ieee802154_frame_meta_s *meta, + FAR struct iob_s *frames); }; /**************************************************************************** diff --git a/include/nuttx/wireless/ieee802154/ieee802154_mac.h b/include/nuttx/wireless/ieee802154/ieee802154_mac.h index a51e8852871..4231374371b 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_mac.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_mac.h @@ -479,7 +479,7 @@ struct ieee802154_frame_meta_s enum ieee802154_addr_mode_e src_addr_mode; /* Source Address Mode */ struct ieee802154_addr_s dest_addr; /* Destination Address */ - uint8_t msdu_handle; /* Handle assoc. with MSDU */ + uint8_t msdu_handle; /* Handle assoc. with MSDU */ /* Number of bytes contained in the MAC Service Data Unit (MSDU) * to be transmitted by the MAC sublayer enitity diff --git a/wireless/ieee802154/mac802154_loopback.c b/wireless/ieee802154/mac802154_loopback.c index 9733065f46d..92a30d35194 100644 --- a/wireless/ieee802154/mac802154_loopback.c +++ b/wireless/ieee802154/mac802154_loopback.c @@ -83,6 +83,10 @@ #define LO_WDDELAY (1*CLK_TCK) +/* Fake value for MAC header length */ + +#define MAC_HDRLEN 9 + /**************************************************************************** * Private Types ****************************************************************************/ @@ -98,6 +102,8 @@ struct lo_driver_s uint16_t lo_panid; /* Fake PAN ID for testing */ WDOG_ID lo_polldog; /* TX poll timer */ struct work_s lo_work; /* For deferring poll work to the work queue */ + FAR struct iob_s *head; /* Head of IOBs queued for loopback */ + FAR struct iob_s *tail; /* Tail of IOBs queued for loopback */ /* This holds the information visible to the NuttX network */ @@ -117,33 +123,39 @@ static uint8_t g_iobuffer[CONFIG_NET_6LOWPAN_MTU + CONFIG_NET_GUARDSIZE]; /* Polling logic */ -static int lo_txpoll(FAR struct net_driver_s *dev); +static int lo_loopback(FAR struct net_driver_s *dev); +static void lo_loopback_work(FAR void *arg); static void lo_poll_work(FAR void *arg); static void lo_poll_expiry(int argc, wdparm_t arg, ...); /* NuttX callback functions */ -static int lo_ifup(FAR struct net_driver_s *dev); -static int lo_ifdown(FAR struct net_driver_s *dev); +static int lo_ifup(FAR struct net_driver_s *dev); +static int lo_ifdown(FAR struct net_driver_s *dev); static void lo_txavail_work(FAR void *arg); -static int lo_txavail(FAR struct net_driver_s *dev); +static int lo_txavail(FAR struct net_driver_s *dev); #if defined(CONFIG_NET_IGMP) || defined(CONFIG_NET_ICMPv6) -static int lo_addmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac); +static int lo_addmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac); #ifdef CONFIG_NET_IGMP -static int lo_rmmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac); +static int lo_rmmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac); #endif #endif #ifdef CONFIG_NETDEV_IOCTL static int lo_ioctl(FAR struct net_driver_s *dev, int cmd, unsigned long arg); #endif +static int lo_get_mhrlen(FAR struct ieee802154_driver_s *netdev, + FAR struct ieee802154_frame_meta_s *meta); +static int lo_req_data(FAR struct ieee802154_driver_s *netdev, + FAR struct ieee802154_frame_meta_s *meta, + FAR struct iob_s *frames); /**************************************************************************** * Private Functions ****************************************************************************/ /**************************************************************************** - * Name: lo_txpoll + * Name: lo_loopback * * Description: * Check if the network has any outgoing packets ready to send. This is @@ -162,7 +174,7 @@ static int lo_ioctl(FAR struct net_driver_s *dev, int cmd, * ****************************************************************************/ -static int lo_txpoll(FAR struct net_driver_s *dev) +static int lo_loopback(FAR struct net_driver_s *dev) { FAR struct lo_driver_s *priv = (FAR struct lo_driver_s *)dev->d_private; FAR struct iob_s *head; @@ -270,6 +282,34 @@ static int lo_txpoll(FAR struct net_driver_s *dev) return 0; } +/**************************************************************************** + * Name: lo_loopback_work + * + * Description: + * Perform loopback of received frames. + * + * Parameters: + * arg - The argument passed when work_queue() as called. + * + * Returned Value: + * OK on success + * + * Assumptions: + * The network is locked + * + ****************************************************************************/ + +static void lo_loopback_work(FAR void *arg) +{ + FAR struct lo_driver_s *priv = (FAR struct lo_driver_s *)arg; + + /* Perform the loopback */ + + net_lock(); + (void)lo_loopback(&priv->lo_ieee.i_dev); + net_unlock(); +} + /**************************************************************************** * Name: lo_poll_work * @@ -295,7 +335,7 @@ static void lo_poll_work(FAR void *arg) net_lock(); priv->lo_txdone = false; - (void)devif_timer(&priv->lo_ieee.i_dev, lo_txpoll); + (void)devif_timer(&priv->lo_ieee.i_dev, lo_loopback); /* Was something received and looped back? */ @@ -304,7 +344,7 @@ static void lo_poll_work(FAR void *arg) /* Yes, poll again for more TX data */ priv->lo_txdone = false; - (void)devif_poll(&priv->lo_ieee.i_dev, lo_txpoll); + (void)devif_poll(&priv->lo_ieee.i_dev, lo_loopback); } /* Setup the watchdog poll timer again */ @@ -458,7 +498,7 @@ static void lo_txavail_work(FAR void *arg) /* If so, then poll the network for new XMIT data */ priv->lo_txdone = false; - (void)devif_poll(&priv->lo_ieee.i_dev, lo_txpoll); + (void)devif_poll(&priv->lo_ieee.i_dev, lo_loopback); } while (priv->lo_txdone); } @@ -492,8 +532,8 @@ static int lo_txavail(FAR struct net_driver_s *dev) ninfo("Available: %u\n", work_available(&priv->lo_work)); /* Is our single work structure available? It may not be if there are - * pending interrupt actions and we will have to ignore the Tx - * availability action. + * pending actions and we will have to ignore the Tx availability + * action. */ if (work_available(&priv->lo_work)) @@ -644,6 +684,92 @@ static int lo_ioctl(FAR struct net_driver_s *dev, int cmd, } #endif +/**************************************************************************** + * Name: lo_get_mhrlen + * + * Description: + * Calculate the MAC header length given the frame meta-data. + * + ****************************************************************************/ + +static int lo_get_mhrlen(FAR struct ieee802154_driver_s *netdev, + FAR struct ieee802154_frame_meta_s *meta) +{ + return MAC_HDRLEN; +} + +/**************************************************************************** + * Name: lo_req_data + * + * Description: + * The MCPS-DATA.request primitive requests the transfer of a data SPDU + * (i.e., MSDU) from a local SSCS entity to a single peer SSCS entity. + * Confirmation is returned via the + * struct ieee802154_maccb_s->conf_data callback. + * + ****************************************************************************/ + +static int lo_req_data(FAR struct ieee802154_driver_s *netdev, + FAR struct ieee802154_frame_meta_s *meta, + FAR struct iob_s *frames) +{ + FAR struct lo_driver_s *priv; + FAR struct iob_s *iob; + + DEBUGASSERT(netdev != NULL && netdev->i_dev.d_private != NULL && iob != NULL); + priv = (FAR struct lo_driver_s *)netdev->i_dev.d_private; + + /* Add the incoming list of frames to queue of frames to loopback */ + + for (iob = frames; iob != NULL; iob = frames) + { + /* Increment statistics */ + + NETDEV_RXPACKETS(&priv->lo_ieee.i_dev); + + /* Remove the IOB from the queue */ + + frames = iob->io_flink; + iob->io_flink = NULL; + + /* Just zero the MAC header for test purposes */ + + DEBUGASSERT(iob->io_offset == MAC_HDRLEN); + memset(iob->io_data, 0, MAC_HDRLEN); + + /* Add the IOB to the tail of teh queue of frames to be looped back */ + + if (priv->tail == NULL) + { + priv->head = iob; + } + else + { + priv->tail->io_flink = iob; + } + + /* Find the new tail of the IOB queue */ + + for (priv->tail = iob, iob = iob->io_flink; + iob != NULL; + priv->tail = iob, iob = iob->io_flink); + } + + /* Is our single work structure available? It may not be if there are + * pending actions and we will have to ignore the Tx availability + * action. + */ + + if (work_available(&priv->lo_work)) + { + /* Schedule to serialize the poll on the worker thread. */ + + work_queue(LPBKWORK, &priv->lo_work, lo_loopback_work, priv, 0); + } + + return OK; +} + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -666,7 +792,8 @@ static int lo_ioctl(FAR struct net_driver_s *dev, int cmd, int ieee8021514_loopback(void) { - FAR struct lo_driver_s *priv; + FAR struct lo_driver_s *priv; + FAR struct ieee802154_driver_s *ieee; FAR struct net_driver_s *dev; ninfo("Initializing\n"); @@ -679,27 +806,33 @@ int ieee8021514_loopback(void) memset(priv, 0, sizeof(struct lo_driver_s)); - dev = &priv->lo_ieee.i_dev; - dev->d_ifup = lo_ifup; /* I/F up (new IP address) callback */ - dev->d_ifdown = lo_ifdown; /* I/F down callback */ - dev->d_txavail = lo_txavail; /* New TX data callback */ + ieee = &priv->lo_ieee; + dev = &ieee->i_dev; + dev->d_ifup = lo_ifup; /* I/F up (new IP address) callback */ + dev->d_ifdown = lo_ifdown; /* I/F down callback */ + dev->d_txavail = lo_txavail; /* New TX data callback */ #ifdef CONFIG_NET_IGMP - dev->d_addmac = lo_addmac; /* Add multicast MAC address */ - dev->d_rmmac = lo_rmmac; /* Remove multicast MAC address */ + dev->d_addmac = lo_addmac; /* Add multicast MAC address */ + dev->d_rmmac = lo_rmmac; /* Remove multicast MAC address */ #endif #ifdef CONFIG_NETDEV_IOCTL - dev->d_ioctl = lo_ioctl; /* Handle network IOCTL commands */ + dev->d_ioctl = lo_ioctl; /* Handle network IOCTL commands */ #endif - dev->d_buf = g_iobuffer; /* Attach the IO buffer */ - dev->d_private = (FAR void *)priv; /* Used to recover private state from dev */ - - /* Create a watchdog for timing polling for and timing of transmissions */ - - priv->lo_polldog = wd_create(); /* Create periodic poll timer */ + dev->d_buf = g_iobuffer; /* Attach the IO buffer */ + dev->d_private = (FAR void *)priv; /* Used to recover private state from dev */ /* Initialize the DSN to a "random" value */ - priv->lo_ieee.i_dsn = 42; + ieee->i_dsn = 42; + + /* Initialize the Network frame-related callbacks */ + + ieee->i_get_mhrlen = lo_get_mhrlen; /* Get MAC header length */ + ieee->i_req_data = lo_req_data; /* Enqueue frame for transmission */ + + /* Create a watchdog for timing polling for and timing of transmissions */ + + priv->lo_polldog = wd_create(); /* Create periodic poll timer */ /* Register the loopabck device with the OS so that socket IOCTLs can b * performed. diff --git a/wireless/ieee802154/mac802154_netdev.c b/wireless/ieee802154/mac802154_netdev.c index 18b2d6e1cd0..f0e4f43cbea 100644 --- a/wireless/ieee802154/mac802154_netdev.c +++ b/wireless/ieee802154/mac802154_netdev.c @@ -257,6 +257,11 @@ static void macnet_ipv6multicast(FAR struct macnet_driver_s *priv); static int macnet_ioctl(FAR struct net_driver_s *dev, int cmd, unsigned long arg); #endif +static int macnet_get_mhrlen(FAR struct ieee802154_driver_s *netdev, + FAR struct ieee802154_frame_meta_s *meta); +static int macnet_req_data(FAR struct ieee802154_driver_s *netdev, + FAR struct ieee802154_frame_meta_s *meta, + FAR struct iob_s *frames); /**************************************************************************** * Private Functions @@ -1494,6 +1499,86 @@ static int macnet_ioctl(FAR struct net_driver_s *dev, int cmd, } #endif +/**************************************************************************** + * Name: macnet_get_mhrlen + * + * Description: + * Calculate the MAC header length given the frame meta-data. + * + ****************************************************************************/ + +static int macnet_get_mhrlen(FAR struct ieee802154_driver_s *netdev, + FAR struct ieee802154_frame_meta_s *meta) +{ + FAR struct macnet_driver_s *priv; + + DEBUGASSERT(netdev != NULL && netdev->i_dev.d_private != NULL && iob != NULL); + priv = (FAR struct macnet_driver_s *)netdev->i_dev.d_private; + + return mac802154_get_mhrlen(priv->md_mac, meta); +} + +/**************************************************************************** + * Name: macnet_req_data + * + * Description: + * The MCPS-DATA.request primitive requests the transfer of a data SPDU + * (i.e., MSDU) from a local SSCS entity to a single peer SSCS entity. + * Confirmation is returned via the + * struct ieee802154_maccb_s->conf_data callback. + * + ****************************************************************************/ + +static int macnet_req_data(FAR struct ieee802154_driver_s *netdev, + FAR struct ieee802154_frame_meta_s *meta, + FAR struct iob_s *frames) +{ + FAR struct macnet_driver_s *priv; + struct ieee802154_data_req_s req; + FAR struct iob_s *iob; + int ret; + + DEBUGASSERT(netdev != NULL && netdev->i_dev.d_private != NULL && iob != NULL); + priv = (FAR struct macnet_driver_s *)netdev->i_dev.d_private; + + /* Add the incoming list of frames to the MAC's outgoing queue */ + + for (iob = frames; iob != NULL; iob = frames) + { + /* Increment statistics */ + + NETDEV_RXPACKETS(&priv->lo_ieee.i_dev); + + /* Remove the IOB from the queue */ + + frames = iob->io_flink; + iob->io_flink = NULL; + + /* Transfer the frame to the MAC */ + + req.meta = mets; + req.frame = iob; + ret = mac802154_req_data(priv->md_mac, req); + if (ret < 0) + { + wlerr("ERROR: mac802154_req_data failed: %d\n", ret); + + iob_free(iob); + for (iob = frames; ; iob != NULL; iob = frames) + { + /* Remove the IOB from the queue and free */ + + frames = iob->io_flink; + iob_free(iob); + } + + return ret; + } + } + + return OK; +} + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -1517,7 +1602,8 @@ static int macnet_ioctl(FAR struct net_driver_s *dev, int cmd, int mac802154netdev_register(MACHANDLE mac) { FAR struct macnet_driver_s *priv; - FAR struct net_driver_s *dev; + FAR struct ieee802154_driver_s *ieee; + FAR struct net_driver_s *dev; FAR struct ieee802154_maccb_s *maccb; FAR uint8_t *pktbuf; int ret; @@ -1549,28 +1635,34 @@ int mac802154netdev_register(MACHANDLE mac) /* Initialize the driver structure */ - dev = &priv->md_dev.i_dev; - dev->d_buf = pktbuf; /* Single packet buffer */ - dev->d_ifup = macnet_ifup; /* I/F up (new IP address) callback */ - dev->d_ifdown = macnet_ifdown; /* I/F down callback */ - dev->d_txavail = macnet_txavail; /* New TX data callback */ + ieee = &priv->lo_ieee; + dev = &ieee->i_dev; + dev->d_buf = pktbuf; /* Single packet buffer */ + dev->d_ifup = macnet_ifup; /* I/F up (new IP address) callback */ + dev->d_ifdown = macnet_ifdown; /* I/F down callback */ + dev->d_txavail = macnet_txavail; /* New TX data callback */ #ifdef CONFIG_NET_IGMP - dev->d_addmac = macnet_addmac; /* Add multicast MAC address */ - dev->d_rmmac = macnet_rmmac; /* Remove multicast MAC address */ + dev->d_addmac = macnet_addmac; /* Add multicast MAC address */ + dev->d_rmmac = macnet_rmmac; /* Remove multicast MAC address */ #endif #ifdef CONFIG_NETDEV_IOCTL - dev->d_ioctl = macnet_ioctl; /* Handle network IOCTL commands */ + dev->d_ioctl = macnet_ioctl; /* Handle network IOCTL commands */ #endif - dev->d_private = (FAR void *)priv; /* Used to recover private state from dev */ + dev->d_private = (FAR void *)priv; /* Used to recover private state from dev */ /* Create a watchdog for timing polling for and timing of transmisstions */ - priv->md_mac = mac; /* Save the MAC interface instance */ - priv->md_txpoll = wd_create(); /* Create periodic poll timer */ - priv->md_txtimeout = wd_create(); /* Create TX timeout timer */ + priv->md_mac = mac; /* Save the MAC interface instance */ + priv->md_txpoll = wd_create(); /* Create periodic poll timer */ + priv->md_txtimeout = wd_create(); /* Create TX timeout timer */ DEBUGASSERT(priv->md_txpoll != NULL && priv->md_txtimeout != NULL); + /* Initialize the Network frame-related callbacks */ + + ieee->i_get_mhrlen = macnet_get_mhrlen; /* Get MAC header length */ + ieee->i_req_data = macnet_req_data; /* Enqueue frame for transmission */ + /* Initialize the MAC callbacks */ priv->md_cb.mc_priv = priv; From 0afae22638f90026f2c3f7b72f89fa4a43433f74 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 3 May 2017 08:01:30 -0600 Subject: [PATCH 117/183] MAC: meta data must be const to assure that it is not modified. --- include/nuttx/wireless/ieee802154/ieee802154_mac.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/nuttx/wireless/ieee802154/ieee802154_mac.h b/include/nuttx/wireless/ieee802154/ieee802154_mac.h index 4231374371b..8c97669c542 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_mac.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_mac.h @@ -504,7 +504,7 @@ struct ieee802154_frame_meta_s #endif #ifdef CONFIG_IEEE802154_UWB - /* The UWB Pulse Repetion Frequency to be used for the transmission */ + /* The UWB Pulse Repetition Frequency to be used for the transmission */ enum ieee802154_uwbprf_e uwb_prf; @@ -535,8 +535,8 @@ struct ieee802154_frame_meta_s struct ieee802154_data_req_s { - FAR struct ieee802154_frame_meta_s *meta; /* Metadata describing the req */ - FAR struct iob_s *frame; /* Frame IOB with payload */ + FAR const struct ieee802154_frame_meta_s *meta; /* Metadata describing the req */ + FAR struct iob_s *frame; /* Frame IOB with payload */ }; /***************************************************************************** From 1ac1b6e68f40f0a7e1e6b8497d32e2970ef51bdf Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 3 May 2017 08:04:20 -0600 Subject: [PATCH 118/183] MAC: meta data must be const to assure that it is not modified. --- wireless/ieee802154/mac802154.c | 4 ++-- wireless/ieee802154/mac802154.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/wireless/ieee802154/mac802154.c b/wireless/ieee802154/mac802154.c index 39bdb2ec2aa..491641da991 100644 --- a/wireless/ieee802154/mac802154.c +++ b/wireless/ieee802154/mac802154.c @@ -844,7 +844,7 @@ int mac802154_ioctl(MACHANDLE mac, int cmd, unsigned long arg) ****************************************************************************/ int mac802154_get_mhrlen(MACHANDLE mac, - FAR struct ieee802154_frame_meta_s *meta) + FAR const struct ieee802154_frame_meta_s *meta) { FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; @@ -927,7 +927,7 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; FAR struct mac802154_trans_s trans; - FAR struct ieee802154_frame_meta_s *meta = req->meta; + FAR const struct ieee802154_frame_meta_s *meta = req->meta; uint16_t *frame_ctrl; uint8_t mhr_len = 3; /* Start assuming frame control and seq. num */ int ret; diff --git a/wireless/ieee802154/mac802154.h b/wireless/ieee802154/mac802154.h index d0d7e82ce23..8042b84c330 100644 --- a/wireless/ieee802154/mac802154.h +++ b/wireless/ieee802154/mac802154.h @@ -106,7 +106,7 @@ int mac802154_ioctl(MACHANDLE mac, int cmd, unsigned long arg); ****************************************************************************/ int mac802154_get_mhrlen(MACHANDLE mac, - FAR struct ieee802154_frame_meta_s *meta); + FAR const struct ieee802154_frame_meta_s *meta); /**************************************************************************** * Name: mac802154_req_data From 893c42561f0191fe6c9f5291dd4037714025b0d9 Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Tue, 2 May 2017 13:58:57 -0400 Subject: [PATCH 119/183] wireless/ieee802154: Sets up default PIB attributes --- wireless/ieee802154/mac802154.c | 58 +++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 3 deletions(-) diff --git a/wireless/ieee802154/mac802154.c b/wireless/ieee802154/mac802154.c index 491641da991..4c906a669d5 100644 --- a/wireless/ieee802154/mac802154.c +++ b/wireless/ieee802154/mac802154.c @@ -219,8 +219,8 @@ struct ieee802154_privmac_s uint32_t batt_life_ext : 1; /* Is BLE enabled */ uint32_t gts_permit : 1; /* Is PAN Coord. accepting GTS reqs. */ - uint32_t promiscuous_mode : 1; /* Is promiscuous mode on? */ - uint32_t ranging_supported : 1; /* Does MAC sublayer support ranging */ + uint32_t promisc_mode : 1; /* Is promiscuous mode on? */ + uint32_t rng_support : 1; /* Does MAC sublayer support ranging */ uint32_t rx_when_idle : 1; /* Recvr. on during idle periods */ uint32_t sec_enabled : 1; /* Does MAC sublayer have security en. */ @@ -415,7 +415,59 @@ static FAR struct mac802154_trans_s * static int mac802154_defaultmib(FAR struct ieee802154_privmac_s *priv) { - /* TODO: Set all MAC fields to default values */ + priv->is_assoc = false; /* Not associated with a PAN */ + priv->assoc_permit = false; /* Device (if coord) not accepting association */ + priv->auto_req = true; /* Auto send data req if addr. in beacon */ + priv->batt_life_ext = false; /* BLE disabled */ + priv->beacon_payload_len = 0; /* Beacon payload NULL */ + priv->beacon_order = 15; /* Non-beacon enabled network */ + priv->superframe_order = 15; /* Length of active portion of outgoing SF */ + priv->beacon_tx_time = 0; /* Device never sent a beacon */ + priv->bsn = + priv->dsn = + priv->gts_permit = true; /* PAN Coord accepting GTS requests */ + priv->min_be = 3; /* Min value of backoff exponent (BE) */ + priv->max_be = 5; /* Max value of backoff exponent (BE) */ + priv->max_csma_backoffs = 4; /* Max # of backoffs before failure */ + priv->max_retries = 3; /* Max # of retries allowed after failure */ + priv->promisc_mode = false; /* Device not in promiscuous mode */ + priv->rng_support = false; /* Ranging not yet supported */ + priv->resp_wait_time = 32; /* 32 SF durations */ + priv->rx_on_idle = false; /* Don't receive while idle */ + priv->sec_enabled = false; /* Security disabled by default */ + priv->tx_total_dur = 0; /* 0 transmit duration */ + + priv->trans_persist_time = 0x01F4; + + + /* Reset the Coordinator address */ + + priv->coord_addr.mode = IEEE802154_ADDRMODE_NONE; + priv->coord_addr.saddr = IEEE802154_SADDR_UNSPEC; + memcpy(&priv->coord_addr.eaddr[0], IEEE802154_EADDR_UNSPEC, 8); + + /* Reset the device's address */ + + priv->addr.mode = IEEE802154_ADDRMODE_NONE; + priv->addr.pan_id = IEEE802154_PAN_UNSPEC; + priv->addr.saddr = IEEE802154_SADDR_UNSPEC; + memcpy(&priv->addr.eaddr[0], IEEE802154_EADDR_UNSPEC, 8); + + + /* These attributes are effected and determined based on the PHY. Need to + * figure out how to "share" attributes between the radio driver and this + * MAC layer + * + * macAckWaitDuration + * macBattLifeExtPeriods + * macMaxFrameTotalWaitTime + * macLIFSPeriod + * macSIFSPeriod + * macSyncSymbolOffset + * macTimestampSupported + * macTxControlActiveDuration + * macTxControlPauseDuration + */ return OK; } From 653a0217f2ff4d48fd76f775a67822d0279af684 Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Tue, 2 May 2017 13:59:22 -0400 Subject: [PATCH 120/183] wireless/ieee802154: Finishes some IOCTL logic for MAC layer --- .../wireless/ieee802154/ieee802154_mac.h | 6 +- wireless/ieee802154/mac802154.c | 100 +++++++++++++++--- wireless/ieee802154/mac802154.h | 12 +-- wireless/ieee802154/mac802154_device.c | 16 ++- 4 files changed, 101 insertions(+), 33 deletions(-) diff --git a/include/nuttx/wireless/ieee802154/ieee802154_mac.h b/include/nuttx/wireless/ieee802154/ieee802154_mac.h index 8c97669c542..68369ab75fc 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_mac.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_mac.h @@ -168,7 +168,7 @@ #define IEEE802154_GTS_DESC_PERSISTENCE_TIME 4 #define IEEE802154_MAX_BEACON_OVERHEAD 75 -#define IEEE802154_MAX_BEACON_PAYLOAD_LENGTH \ +#define IEEE802154_MAX_BEACON_PAYLOAD_LEN \ (IEEE802154_MAX_PHY_PACKET_SIZE - IEEE802154_MAX_BEACON_OVERHEAD) #define IEEE802154_MAX_LOST_BEACONS 4 @@ -840,12 +840,12 @@ struct ieee802154_beaconnotify_ind_s /* Beacon payload */ - uint8_t sdu[IEEE802154_MAX_BEACON_PAYLOAD_LENGTH]; + uint8_t sdu[IEEE802154_MAX_BEACON_PAYLOAD_LEN]; }; #define SIZEOF_IEEE802154_BEACONNOTIFY_IND_S(n) \ (sizeof(struct ieee802154_beaconnotify_ind_s) \ - - IEEE802154_MAX_BEACON_PAYLOAD_LENGTH + (n)) + - IEEE802154_MAX_BEACON_PAYLOAD_LEN + (n)) /***************************************************************************** * Primitive: MLME-COMM-STATUS.indication diff --git a/wireless/ieee802154/mac802154.c b/wireless/ieee802154/mac802154.c index 4c906a669d5..56b220181a3 100644 --- a/wireless/ieee802154/mac802154.c +++ b/wireless/ieee802154/mac802154.c @@ -187,7 +187,7 @@ struct ieee802154_privmac_s /* Contents of beacon payload */ - uint8_t beacon_payload[IEEE802154_MAX_BEACON_PAYLOAD_LENGTH]; + uint8_t beacon_payload[IEEE802154_MAX_BEACON_PAYLOAD_LEN]; uint8_t beacon_payload_len; /* Length of beacon payload */ uint8_t batt_life_ext_periods; /* # of backoff periods during which rx is @@ -219,8 +219,8 @@ struct ieee802154_privmac_s uint32_t batt_life_ext : 1; /* Is BLE enabled */ uint32_t gts_permit : 1; /* Is PAN Coord. accepting GTS reqs. */ - uint32_t promisc_mode : 1; /* Is promiscuous mode on? */ - uint32_t rng_support : 1; /* Does MAC sublayer support ranging */ + uint32_t promisc_mode : 1; /* Is promiscuous mode on? */ + uint32_t rng_support : 1; /* Does MAC sublayer support ranging */ uint32_t rx_when_idle : 1; /* Recvr. on during idle periods */ uint32_t sec_enabled : 1; /* Does MAC sublayer have security en. */ @@ -423,8 +423,9 @@ static int mac802154_defaultmib(FAR struct ieee802154_privmac_s *priv) priv->beacon_order = 15; /* Non-beacon enabled network */ priv->superframe_order = 15; /* Length of active portion of outgoing SF */ priv->beacon_tx_time = 0; /* Device never sent a beacon */ - priv->bsn = - priv->dsn = +#warning Set BSN and DSN to random values! + priv->bsn = 0; + priv->dsn = 0; priv->gts_permit = true; /* PAN Coord accepting GTS requests */ priv->min_be = 3; /* Min value of backoff exponent (BE) */ priv->max_be = 5; /* Max value of backoff exponent (BE) */ @@ -433,7 +434,7 @@ static int mac802154_defaultmib(FAR struct ieee802154_privmac_s *priv) priv->promisc_mode = false; /* Device not in promiscuous mode */ priv->rng_support = false; /* Ranging not yet supported */ priv->resp_wait_time = 32; /* 32 SF durations */ - priv->rx_on_idle = false; /* Don't receive while idle */ + priv->rx_when_idle = false; /* Don't receive while idle */ priv->sec_enabled = false; /* Security disabled by default */ priv->tx_total_dur = 0; /* 0 transmit duration */ @@ -449,7 +450,7 @@ static int mac802154_defaultmib(FAR struct ieee802154_privmac_s *priv) /* Reset the device's address */ priv->addr.mode = IEEE802154_ADDRMODE_NONE; - priv->addr.pan_id = IEEE802154_PAN_UNSPEC; + priv->addr.panid = IEEE802154_PAN_UNSPEC; priv->addr.saddr = IEEE802154_SADDR_UNSPEC; memcpy(&priv->addr.eaddr[0], IEEE802154_EADDR_UNSPEC, 8); @@ -859,6 +860,9 @@ int mac802154_ioctl(MACHANDLE mac, int cmd, unsigned long arg) (FAR struct ieee802154_privmac_s *)mac; int ret = -EINVAL; + FAR union ieee802154_macarg_u *macarg = + (FAR union ieee802154_macarg_u *)((uintptr_t)arg); + DEBUGASSERT(priv != NULL); /* Check for IOCTLs aimed at the IEEE802.15.4 MAC layer */ @@ -866,7 +870,75 @@ int mac802154_ioctl(MACHANDLE mac, int cmd, unsigned long arg) if (_MAC802154IOCVALID(cmd)) { /* Handle the MAC IOCTL command */ -#warning Missing logic + + switch (cmd) + { + case MAC802154IOC_MLME_ASSOC_REQUEST: + { + mac802154_req_associate(mac, &macarg->assocreq); + } + break; + case MAC802154IOC_MLME_ASSOC_RESPONSE: + { + mac802154_resp_associate(mac, &macarg->assocresp); + } + break; + case MAC802154IOC_MLME_DISASSOC_REQUEST: + { + mac802154_req_disassociate(mac, &macarg->disassocreq); + } + break; + case MAC802154IOC_MLME_GET_REQUEST: + { + mac802154_req_get(mac, &macarg->getreq); + } + break; + case MAC802154IOC_MLME_GTS_REQUEST: + { + mac802154_req_gts(mac, &macarg->gtsreq); + } + break; + case MAC802154IOC_MLME_ORPHAN_RESPONSE: + { + mac802154_resp_orphan(mac, &macarg->orphanresp); + } + break; + case MAC802154IOC_MLME_RESET_REQUEST: + { + mac802154_req_reset(mac, &macarg->resetreq); + } + break; + case MAC802154IOC_MLME_RXENABLE_REQUEST: + { + mac802154_req_rxenable(mac, &macarg->rxenabreq); + } + break; + case MAC802154IOC_MLME_SCAN_REQUEST: + { + mac802154_req_scan(mac, &macarg->scanreq); + } + break; + case MAC802154IOC_MLME_SET_REQUEST: + { + mac802154_req_set(mac, &macarg->setreq); + } + break; + case MAC802154IOC_MLME_START_REQUEST: + { + mac802154_req_start(mac, &macarg->startreq); + } + break; + case MAC802154IOC_MLME_SYNC_REQUEST: + { + mac802154_req_sync(mac, &macarg->syncreq); + } + break; + case MAC802154IOC_MLME_POLL_REQUEST: + { + mac802154_req_poll(mac, &macarg->pollreq); + } + break; + } } /* No, other IOCTLs must be aimed at the IEEE802.15.4 radio layer */ @@ -1444,7 +1516,7 @@ int mac802154_req_poll(MACHANDLE mac, FAR struct ieee802154_poll_req_s *req) } /**************************************************************************** - * Name: mac802154_rsp_associate + * Name: mac802154_resp_associate * * Description: * The MLME-ASSOCIATE.response primitive is used to initiate a response to @@ -1452,8 +1524,8 @@ int mac802154_req_poll(MACHANDLE mac, FAR struct ieee802154_poll_req_s *req) * ****************************************************************************/ -int mac802154_rsp_associate(MACHANDLE mac, - FAR struct ieee802154_assoc_resp_s *resp) +int mac802154_resp_associate(MACHANDLE mac, + FAR struct ieee802154_assoc_resp_s *resp) { FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; @@ -1461,7 +1533,7 @@ int mac802154_rsp_associate(MACHANDLE mac, } /**************************************************************************** - * Name: mac802154_rsp_orphan + * Name: mac802154_resp_orphan * * Description: * The MLME-ORPHAN.response primitive allows the next higher layer of a @@ -1469,8 +1541,8 @@ int mac802154_rsp_associate(MACHANDLE mac, * ****************************************************************************/ -int mac802154_rsp_orphan(MACHANDLE mac, - FAR struct ieee802154_orphan_resp_s *resp) +int mac802154_resp_orphan(MACHANDLE mac, + FAR struct ieee802154_orphan_resp_s *resp) { FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; diff --git a/wireless/ieee802154/mac802154.h b/wireless/ieee802154/mac802154.h index 8042b84c330..17df17ebda1 100644 --- a/wireless/ieee802154/mac802154.h +++ b/wireless/ieee802154/mac802154.h @@ -282,7 +282,7 @@ int mac802154_req_sync(MACHANDLE mac, FAR struct ieee802154_sync_req_s *req); int mac802154_req_poll(MACHANDLE mac, FAR struct ieee802154_poll_req_s *req); /**************************************************************************** - * Name: mac802154_rsp_associate + * Name: mac802154_resp_associate * * Description: * The MLME-ASSOCIATE.response primitive is used to initiate a response to @@ -290,11 +290,11 @@ int mac802154_req_poll(MACHANDLE mac, FAR struct ieee802154_poll_req_s *req); * ****************************************************************************/ -int mac802154_rsp_associate(MACHANDLE mac, - FAR struct ieee802154_assoc_resp_s *resp); +int mac802154_resp_associate(MACHANDLE mac, + FAR struct ieee802154_assoc_resp_s *resp); /**************************************************************************** - * Name: mac802154_rsp_orphan + * Name: mac802154_resp_orphan * * Description: * The MLME-ORPHAN.response primitive allows the next higher layer of a @@ -302,8 +302,8 @@ int mac802154_rsp_associate(MACHANDLE mac, * ****************************************************************************/ -int mac802154_rsp_orphan(MACHANDLE mac, - FAR struct ieee802154_orphan_resp_s *resp); +int mac802154_resp_orphan(MACHANDLE mac, + FAR struct ieee802154_orphan_resp_s *resp); #undef EXTERN #ifdef __cplusplus diff --git a/wireless/ieee802154/mac802154_device.c b/wireless/ieee802154/mac802154_device.c index 83798b47346..7f76e8cd3d9 100644 --- a/wireless/ieee802154/mac802154_device.c +++ b/wireless/ieee802154/mac802154_device.c @@ -602,17 +602,13 @@ static int mac802154dev_ioctl(FAR struct file *filep, int cmd, } break; #endif - - case MAC802154IOC_MLME_ASSOC_REQUEST: - { - FAR struct ieee802154_assoc_req_s *req = - (FAR struct ieee802154_assoc_req_s *)((uintptr_t)arg); - } - break; - default: - wlerr("ERROR: Unrecognized command %ld\n", cmd); - ret = -EINVAL; + { + /* Forward any unrecognized commands to the MAC layer */ + + mac802154_ioctl(dev->md_mac, cmd, arg); + } + break; } From 858685e977a55e05814736abed444961c966abf2 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 3 May 2017 09:40:42 -0600 Subject: [PATCH 121/183] 6loWPAN: Changes to use new MAC interfaces. Incomplete and needs some clean-up of dangling, unused definitions. --- include/nuttx/net/netdev.h | 6 +- include/nuttx/net/sixlowpan.h | 227 +++++-------- net/sixlowpan/sixlowpan_framelist.c | 107 +++--- net/sixlowpan/sixlowpan_framer.c | 399 ++++------------------- net/sixlowpan/sixlowpan_input.c | 164 +++------- net/sixlowpan/sixlowpan_internal.h | 160 ++++----- net/sixlowpan/sixlowpan_send.c | 7 +- wireless/ieee802154/mac802154_loopback.c | 111 ++----- wireless/ieee802154/mac802154_netdev.c | 107 +----- 9 files changed, 331 insertions(+), 957 deletions(-) diff --git a/include/nuttx/net/netdev.h b/include/nuttx/net/netdev.h index eb84a7774fd..7f8e4041f45 100644 --- a/include/nuttx/net/netdev.h +++ b/include/nuttx/net/netdev.h @@ -437,7 +437,9 @@ int ipv6_input(FAR struct net_driver_s *dev); #ifdef CONFIG_NET_6LOWPAN struct ieee802154_driver_s; /* See sixlowpan.h */ -int sixlowpan_input(FAR struct ieee802154_driver_s *ieee); +struct iob_s; /* See iob.h */ +int sixlowpan_input(FAR struct ieee802154_driver_s *ieee, + FAR struct iob_s *framelist); #endif /**************************************************************************** @@ -513,7 +515,7 @@ int devif_timer(FAR struct net_driver_s *dev, devif_poll_callback_t callback); * * If no Neighbor Table entry is found for the destination IPv6 address, * the packet in the d_buf[] is replaced by an ICMPv6 Neighbor Solict - * request packet for the IPv6 address. The IPv6 packet is dropped and + * request packet for the IPv6 address. The IPv6 packet is dropped and * it is assumed that the higher level protocols (e.g., TCP) eventually * will retransmit the dropped packet. * diff --git a/include/nuttx/net/sixlowpan.h b/include/nuttx/net/sixlowpan.h index 2e65199513f..85c95329dca 100644 --- a/include/nuttx/net/sixlowpan.h +++ b/include/nuttx/net/sixlowpan.h @@ -1,6 +1,7 @@ /**************************************************************************** * include/nuttx/net/sixlowpan.h - * Header file for the 6lowpan implementation (RFC4944 and draft-hui-6lowpan-hc-01) + * Header file for the 6lowpan implementation (RFC4944 and + * draft-hui-6lowpan-hc-01) * * Copyright (C) 2017, Gregory Nutt, all rights reserved * Author: Gregory Nutt @@ -271,61 +272,6 @@ (a)[4] == 0 && (a)[5] == 0 && (a)[6] == 0 && \ (((a)[7] & HTONS(0xff00)) == 0x0000)) -/* Frame buffer helper macros ***********************************************/ -/* The IEEE802.15.4 MAC driver structures includes a list of IOB - * structures, i_framelist, containing frames to be sent by the driver or - * that were received by the driver. The IOB structure is defined in - * include/nuttx/drivers/iob.h. The length of data in the IOB is provided by - * the io_len field of the IOB structure. - * - * NOTE that IOBs must be configured such that CONFIG_IOB_BUFSIZE >= - * CONFIG_NET_6LOWPAN_FRAMELEN - * - * 1. On a TX poll, the IEEE802.15.4 MAC driver should provide its driver - * structure with i_framelist set to NULL. At the conclusion of the - * poll, if there are frames to be sent, they will have been added to - * the i_framelist. The non-empty frame list is the indication that - * there is data to be sent. - * - * The IEEE802.15.4 may use the FRAME_IOB_EMPTY() macro to determine - * if there there frames to be sent. If so, it should remove each - * frame from the frame list using the FRAME_IOB_REMOVE() macro and send - * it. That macro will return NULL when all of the frames have been - * sent. - * - * After sending each frame, the driver must return the IOB to the pool - * of free IOBs using the FROM_IOB_FREE() macro. - */ - - -#define FRAME_IOB_EMPTY(ieee) ((ieee)->i_framelist == NULL) -#define FRAME_IOB_REMOVE(ieee, iob) \ - do \ - { \ - (iob) = (ieee)->i_framelist; \ - (ieee)->i_framelist = (iob)->io_flink; \ - (iob)->io_flink = NULL; \ - } \ - while (0) -#define FRAME_IOB_FREE(iob) iob_free(iob) - -/* 2. When receiving data, the IEEE802.15.4 MAC driver should receive the - * frame data directly into the payload area of an IOB structure. That - * IOB structure may be obtained using the FRAME_IOB_ALLOC() macro. The - * single frame should be added to the frame list using FRAME_IOB_ADD() - * (it will be a list of length one) . The MAC driver should then inform - * the network of the by calling sixlowpan_input(). - */ - -#define FRAME_IOB_ALLOC() iob_alloc(false) -#define FRAME_IOB_ADD(ieee, iob) \ - do \ - { \ - (iob)->io_flink = (ieee)->i_framelist; \ - (ieee)->i_framelist = (iob); \ - } \ - while (0) - /**************************************************************************** * Public Types ****************************************************************************/ @@ -335,18 +281,21 @@ * difference is that fragmentation must be supported. * * The IEEE802.15.4 MAC does not use the d_buf packet buffer directly. - * Rather, it uses a list smaller frame buffers, i_framelist. + * Rather, it uses a list smaller frame buffers. * - * - The packet fragment data is provided to an IOB in the i_framelist - * buffer each time that the IEEE802.15.4 MAC needs to send more data. - * The length of the frame is provided in the io_len field of the IOB. + * - The packet fragment data is provided in an IOB in the via the + * i_req_data() interface method each time that the IEEE802.15.4 MAC + * needs to send more data. The length of the frame is provided in the + * io_len field of the IOB. * * In this case, the d_buf is not used at all and, if fact, may be * NULL. * * - Received frames are provided by IEEE802.15.4 MAC to the network - * via and IOB in i_framelist with length io_len for reassembly in - * d_buf; d_len will hold the size of the reassembled packet. + * via an IOB parameter in the sixlowpan_submit() interface. The + * length of the frawme is io_len and will be uncompressed and possibly + * reassembled in the d_buf; d_len will hold the size of the + * reassembled packet. * * In this case, a d_buf of size CONFIG_NET_6LOWPAN_MTU must be provided. * @@ -360,49 +309,40 @@ * this structure. In general, all fields must be set to NULL. In * addtion: * - * 1. i_dsn must be set to a random value. After that, it will be managed - * by the network. + * 1. On a TX poll, the IEEE802.15.4 MAC driver should provide its driver + * structure. During the course of the poll, the networking layer may + * generate outgoing frames. These frames will by provided to the MAC + * driver via the req_data() method. * - * 2. On a TX poll, the IEEE802.15.4 MAC driver should provide its driver - * structure with i_framelist set to NULL. At the conclusion of the - * poll, if there are frames to be sent, they will have been added to - * the i_framelist. The non-empty frame list at the conclusion of the - * TX poll is the indication that is data to be sent. + * After sending each frame through the radio, the MAC driver must + * return the frame to the pool of free IOBs using the iob_free(). * - * The IEEE802.15.4 may use the FRAME_IOB_EMPTY() macro to determine - * if there there frames to be sent. If so, it should remove each - * frame from the frame list using the FRAME_IOB_REMOVE() macro and send - * it. That macro will return NULL when all of the frames have been - * sent. - * - * After sending each frame, the driver must return the IOB to the pool - * of free IOBs using the FROM_IOB_FREE() macro. - * - * 3. When receiving data both buffers must be provided: + * 2. When receiving data both buffers must be provided: * * The IEEE802.15.4 MAC driver should receive the frame data directly - * into the payload area of an IOB structure. That IOB structure may be - * obtained using the FRAME_IOB_ALLOC() macro. The single frame should - * be added to the frame list using FRAME_IOB_ADD() (it will be a list of - * length one). + * into the payload area of an IOB frame structure. That IOB structure + * may be obtained using the iob_alloc() function. * * The larger dev.d_buf must have a size of at least the advertised MTU - * of the protocol, CONFIG_NET_6LOWPAN_MTU. If fragmentation is enabled, - * then the logical packet size may be significantly larger than the - * size of the frame buffer. The dev.d_buf is used for de-compressing - * each frame and reassembling any fragmented packets to create the full - * input packet that is provided to the application. + * of the protocol, CONFIG_NET_6LOWPAN_MTU, plus CONFIG_NET_GUARDSIZE. + * If fragmentation is enabled, then the logical packet size may be + * significantly larger than the size of the frame buffer. The dev.d_buf + * is used for de-compressing each frame and reassembling any fragmented + * packets to create the full input packet that is provided to the + * application. * * The MAC driver should then inform the network of the by calling - * sixlowpan_input(). + * sixlowpan_input(). That single frame (or, perhaps, list of frames) + * should be provided as second argument of that call. * - * Normally, the network will free the IOB and will nullify the frame - * list. But ss a complexity, the result of receiving a frame may be - * that the network may respond provide an outgoing frames in the - * frame list. + * The network will free the IOB by calling iob_free after it has + * processed the incoming frame. As a complexity, the result of + * receiving a frame may be that the network may respond provide an + * outgoing frames in the via a nested calle to the req_data() method. */ struct ieee802154_frame_meta_s; /* Forward reference */ +struct iob_s; /* Forward reference */ struct ieee802154_driver_s { @@ -414,33 +354,22 @@ struct ieee802154_driver_s /* IEEE802.15.4 MAC-specific definitions follow. */ - /* The i_framelist is used to hold a outgoing frames contained in IOB - * structures. When the IEEE802.15.4 device polls for new TX data, the - * outgoing frame(s) containing the packet fragments are placed in IOBs - * and queued in i_framelist. + /* The msdu_handle is basically an id for the frame. The standard just + * says that the next highest layer should determine it. It is used in + * three places * - * The i_framelist is similary used to hold incoming frames in IOB - * structures. The IEEE802.15.4 MAC driver must receive frames in an IOB, - * place the IOB in the i_framelist, and call sixlowpan_input(). + * 1. When you do that data request + * 2. When the transmission is complete, the conf_data is called with + * that handle so that the user can be notified of the frames success/ + * failure + * 3. For a req_purge, to basically "cancel" the transaction. This is + * often particularly useful on a coordinator that has indirect data + * waiting to be requested from another device * - * The IEEE802.15.4 MAC driver design may be concurrently sending and - * requesting new frames using lists of IOBs. That IOB frame buffer - * management must be managed by the IEEE802.15.4 MAC driver. + * Here is a simple frame counter. */ - FAR struct iob_s *i_framelist; - - /* Driver Configuration ***************************************************/ - /* i_dsn. The sequence number in the range 0x00-0xff added to the - * transmitted data or MAC command frame. The default is a random value - * within that range. - * - * This field must be initialized to a random number by the IEEE802.15.4 - * MAC driver. It sill be subsequently incremented on each frame by the - * network logic. - */ - - uint8_t i_dsn; + uint8_t i_msdu_handle; #if CONFIG_NET_6LOWPAN_FRAG /* Fragmentation Support *************************************************/ @@ -511,7 +440,7 @@ struct ieee802154_driver_s **************************************************************************/ CODE int (*i_get_mhrlen)(FAR struct ieee802154_driver_s *netdev, - FAR struct ieee802154_frame_meta_s *meta); + FAR const struct ieee802154_frame_meta_s *meta); /************************************************************************** * Name: mac802154_req_data @@ -525,7 +454,7 @@ struct ieee802154_driver_s **************************************************************************/ CODE int (*i_req_data)(FAR struct ieee802154_driver_s *netdev, - FAR struct ieee802154_frame_meta_s *meta, + FAR const struct ieee802154_frame_meta_s *meta, FAR struct iob_s *frames); }; @@ -539,25 +468,32 @@ struct ieee802154_driver_s * Description: * Process an incoming 6loWPAN frame. * - * This function is called when the device driver has received a 6loWPAN - * frame from the network. The frame from the device driver must be - * provided in a IOB present in the i_framelist: The frame data is in the - * IOB io_data[] buffer and the length of the frame is in the IOB io_len - * field. Only a single IOB is expected in the i_framelist. This incoming - * data will be processed one frame at a time. + * This function is called when the device driver has received an + * IEEE802.15.4 frame from the network. The frame from the device + * driver must be provided in by the IOB frame argument of the + * function call: * - * An non-NULL d_buf of size CONFIG_NET_6LOWPAN_MTU must also be provided. - * The frame will be decompressed and placed in the d_buf. Fragmented - * packets will also be reassembled in the d_buf as they are received - * (meaning for the driver, that two packet buffers are required: One for - * reassembly of RX packets and one used for TX polling). + * - The frame data is in the IOB io_data[] buffer, + * - The length of the frame is in the IOB io_len field, and + * - The offset past the IEEE802.15.4 MAC header is provided in the + * io_offset field. * - * After each frame is processed into d_buf, the IOB is removed and - * deallocated. i_framelist will be nullified. If reassembly is - * incomplete, this function will return to called with i_framelist - * equal to NULL. The partially reassembled packet must be preserved by - * the IEEE802.15.4 MAC and provided again when the next frame is - * received. + * The frame argument may refer to a single frame (a list of length one) + * or may it be the head of a list of multiple frames. + * + * - The io_flink field points to the next frame in the list (if enable) + * - The last frame in the list will have io_flink == NULL. + * + * An non-NULL d_buf of size CONFIG_NET_6LOWPAN_MTU + CONFIG_NET_GUARDSIZE + * must also be provided. The frame will be decompressed and placed in + * the d_buf. Fragmented packets will also be reassembled in the d_buf as + * they are received (meaning for the driver, that two packet buffers are + * required: One for reassembly of RX packets and one used for TX polling). + * + * After each frame is processed into d_buf, the IOB is deallocated. If + * reassembly is incomplete, the partially reassembled packet must be + * preserved by the IEEE802.15.4 MAC network drvier sand provided again + * when the next frame is received. * * When the packet in the d_buf is fully reassembled, it will be provided * to the network as with any other received packet. d_len will be set @@ -565,28 +501,25 @@ struct ieee802154_driver_s * * After the network processes the packet, d_len will be set to zero. * Network logic may also decide to send a response to the packet. In - * that case, the outgoing network packet will be placed in d_buf the - * d_buf and d_len will be set to a non-zero value. That case is handled - * by this function. + * that case, the outgoing network packet will be placed in d_buf and + * d_len will be set to a non-zero value. That case is handled by this + * function. * * If that case occurs, the packet will be converted to a list of - * compressed and possibly fragmented frames in i_framelist as with other - * TX operations. - * - * So from the standpoint of the IEEE802.15.4 MAC driver, there are two - * possible results: (1) i_framelist is NULL meaning that the frame - * was fully processed and freed, or (2) i_framelist is non-NULL meaning - * that there are outgoing frame(s) to be sent. + * compressed and possibly fragmented frames and provided to the MAC + * network driver via the req_data() method as with other TX operations. * * Input Parameters: - * ieee - The IEEE802.15.4 MAC network driver interface. + * ieee - The IEEE802.15.4 MAC network driver interface. + * framelist - The head of an incoming list of frames. * * Returned Value: * Ok is returned on success; Othewise a negated errno value is returned. * ****************************************************************************/ -int sixlowpan_input(FAR struct ieee802154_driver_s *ieee); +int sixlowpan_input(FAR struct ieee802154_driver_s *ieee, + FAR struct iob_s *framelist); #endif /* CONFIG_NET_6LOWPAN */ #endif /* __INCLUDE_NUTTX_NET_SIXLOWPAN_H */ diff --git a/net/sixlowpan/sixlowpan_framelist.c b/net/sixlowpan/sixlowpan_framelist.c index 91e3369b819..e4e769c0ce3 100644 --- a/net/sixlowpan/sixlowpan_framelist.c +++ b/net/sixlowpan/sixlowpan_framelist.c @@ -55,6 +55,7 @@ #include #include +#include #include "sixlowpan/sixlowpan_internal.h" @@ -183,9 +184,8 @@ static void sixlowpan_compress_ipv6hdr(FAR const struct ipv6_hdr_s *ipv6hdr, * * The payload data is in the caller 'buf' and is of length 'buflen'. * Compressed headers will be added and if necessary the packet is - * fragmented. The resulting packet/fragments are put in ieee->i_framelist - * and the entire list of frames will be delivered to the 802.15.4 MAC via - * ieee->i_framelist. + * fragmented. The resulting packet/fragments are submitted to the MAC + * where they are queue for transfer. * * Input Parameters: * ieee - The IEEE802.15.4 MAC driver instance @@ -211,6 +211,7 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, FAR const void *buf, size_t buflen, FAR const struct rimeaddr_s *destmac) { + struct ieee802154_frame_meta_s meta; FAR struct iob_s *iob; FAR uint8_t *fptr; int framer_hdrlen; @@ -221,6 +222,7 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, #ifdef CONFIG_NET_6LOWPAN_FRAG uint16_t outlen = 0; #endif + int ret; /* Initialize global data. Locking the network guarantees that we have * exclusive use of the global values for intermediate calculations. @@ -297,18 +299,33 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, dest_panid = 0xffff; (void)sixlowpan_src_panid(ieee, &dest_panid); + /* Based on the collected attributes and addresses, construct the MAC meta + * data structure that we need to interface with the IEEE802.15.4 MAC. + */ + + ret = sixlowpan_meta_data(dest_panid, &meta); + if (ret < 0) + { + nerr("ERROR: sixlowpan_meta_data() failed: %d\n", ret); + } + /* Pre-calculate frame header length. */ - framer_hdrlen = sixlowpan_send_hdrlen(ieee, dest_panid); + framer_hdrlen = sixlowpan_frame_hdrlen(ieee, &meta); if (framer_hdrlen < 0) { /* Failed to determine the size of the header failed. */ - nerr("ERROR: sixlowpan_send_hdrlen() failed: %d\n", framer_hdrlen); + nerr("ERROR: sixlowpan_frame_hdrlen() failed: %d\n", framer_hdrlen); return framer_hdrlen; } - g_frame_hdrlen = framer_hdrlen; + /* This sill be the initial offset into io_data. Valid data begins at + * this offset and must be reflected in io_offset. + */ + + g_frame_hdrlen = framer_hdrlen; + iob->io_offset = framer_hdrlen; #ifndef CONFIG_NET_6LOWPAN_COMPRESSION_IPv6 if (buflen >= CONFIG_NET_6LOWPAN_COMPRESSION_THRESHOLD) @@ -338,15 +355,15 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, if (buflen > (CONFIG_NET_6LOWPAN_FRAMELEN - g_frame_hdrlen)) { #ifdef CONFIG_NET_6LOWPAN_FRAG - /* ieee->i_framelist will hold the generated frames; frames will be + /* qhead will hold the generated frame list; frames will be * added at qtail. */ + FAR struct iob_s *qhead; FAR struct iob_s *qtail; FAR uint8_t *frame1; FAR uint8_t *fragptr; uint16_t frag1_hdrlen; - int verify; /* The outbound IPv6 packet is too large to fit into a single 15.4 * packet, so we fragment it into multiple packets and send them. @@ -358,13 +375,6 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, ninfo("Sending fragmented packet length %d\n", buflen); /* Create 1st Fragment */ - /* Add the frame header using the pre-allocated IOB using the DSN - * selected by sixlowpan_send_hdrlen(). - */ - - verify = sixlowpan_framecreate(ieee, iob, dest_panid); - DEBUGASSERT(verify == framer_hdrlen); - UNUSED(verify); /* Move HC1/HC06/IPv6 header to make space for the FRAG1 header at the * beginning of the frame. @@ -405,8 +415,8 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, /* Set outlen to what we already sent from the IP payload */ - iob->io_len = paysize + g_frame_hdrlen; - outlen = paysize; + iob->io_len = paysize + g_frame_hdrlen; + outlen = paysize; ninfo("First fragment: length %d, tag %d\n", paysize, ieee->i_dgramtag); @@ -415,17 +425,17 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, /* Add the first frame to the IOB queue */ - ieee->i_framelist = iob; - qtail = iob; + qhead = iob; + qtail = iob; /* Keep track of the total amount of data queue */ - iob->io_pktlen = iob->io_len; + iob->io_pktlen = iob->io_len; /* Create following fragments */ - frame1 = iob->io_data; - frag1_hdrlen = g_frame_hdrlen; + frame1 = iob->io_data; + frag1_hdrlen = g_frame_hdrlen; while (outlen < buflen) { @@ -442,20 +452,10 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, iob->io_flink = NULL; iob->io_len = 0; - iob->io_offset = 0; + iob->io_offset = framer_hdrlen; iob->io_pktlen = 0; fptr = iob->io_data; - /* Add a new frame header to the IOB (same as the first but with a - * different DSN). - */ - - g_pktattrs[PACKETBUF_ATTR_MAC_SEQNO] = 0; - - verify = sixlowpan_framecreate(ieee, iob, dest_panid); - DEBUGASSERT(verify == framer_hdrlen); - UNUSED(verify); - /* Copy the HC1/HC06/IPv6 header the frame header from first * frame, into the correct location after the FRAGN header * of subsequent frames. @@ -508,9 +508,23 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, /* Keep track of the total amount of data queue */ - ieee->i_framelist->io_pktlen += iob->io_len; + qhead->io_pktlen += iob->io_len; } + /* Submit all of the fragments to the MAC */ + + while (qhead != NULL) + { + iob = qhead; + qhead = iob->io_flink; + + ret = sixlowpan_frame_submit(ieee, &meta, iob); + if (ret < 0) + { + nerr("ERROR: sixlowpan_frame_submit() failed: %d\n", ret); + } + } + /* Update the datagram TAG value */ ieee->i_dgramtag++; @@ -524,34 +538,27 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, } else { - int verify; - /* The packet does not need to be fragmented just copy the "payload" * and send in one frame. */ - /* Add the frame header to the preallocated IOB. */ - - verify = sixlowpan_framecreate(ieee, iob, dest_panid); - DEBUGASSERT(verify == framer_hdrlen); - UNUSED(verify); - - /* Copy the payload and queue */ + /* Copy the payload into the frame. */ memcpy(fptr + g_frame_hdrlen, buf, buflen); - iob->io_len = buflen + g_frame_hdrlen; + iob->io_len = buflen + g_frame_hdrlen; + iob->io_pktlen = iob->io_len; ninfo("Non-fragmented: length %d\n", iob->io_len); sixlowpan_dumpbuffer("Outgoing frame", (FAR const uint8_t *)iob->io_data, iob->io_len); - /* Add the first frame to the IOB queue */ + /* Submit the frame to the MAC */ - ieee->i_framelist = iob; - - /* Keep track of the total amount of data queue */ - - iob->io_pktlen = iob->io_len; + ret = sixlowpan_frame_submit(ieee, &meta, iob); + if (ret < 0) + { + nerr("ERROR: sixlowpan_frame_submit() failed: %d\n", ret); + } } return OK; diff --git a/net/sixlowpan/sixlowpan_framer.c b/net/sixlowpan/sixlowpan_framer.c index b85819993e4..9a32310d026 100644 --- a/net/sixlowpan/sixlowpan_framer.c +++ b/net/sixlowpan/sixlowpan_framer.c @@ -52,31 +52,16 @@ #include #include #include +#include #include #include "nuttx/net/net.h" +#include "nuttx/wireless/ieee802154/ieee802154_mac.h" #include "sixlowpan/sixlowpan_internal.h" #ifdef CONFIG_NET_6LOWPAN -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/* Structure that contains the lengths of the various addressing and - * security fields in the 802.15.4 header. - */ - -struct field_length_s -{ - uint8_t dest_pid_len; /* Length (in bytes) of destination PAN ID field */ - uint8_t dest_addr_len; /* Length (in bytes) of destination address field */ - uint8_t src_pid_len; /* Length (in bytes) of source PAN ID field */ - uint8_t src_addr_len; /* Length (in bytes) of source address field */ - uint8_t aux_sec_len; /* Length (in bytes) of aux security header field */ -}; - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -138,172 +123,47 @@ static bool sixlowpan_addrnull(FAR uint8_t *addr) return true; } - /**************************************************************************** - * Name: sixlowpan_fieldlengths - * - * Description: - * Return the lengths associated fields of the IEEE802.15.4 header. - * - * Input parameters: - * finfo - IEEE802.15.4 header info (input) - * flen - Field length info (output) - * - * Returned Value: - * None - * + * Public Functions ****************************************************************************/ -static void sixlowpan_fieldlengths(FAR struct frame802154_s *finfo, - FAR struct field_length_s *flen) -{ - /* Initialize to all zero */ - - memset(flen, 0, sizeof(struct field_length_s)); - - /* Determine lengths of each field based on fcf and other args */ - - if ((finfo->fcf.dest_addr_mode & 3) != 0) - { - flen->dest_pid_len = 2; - } - - if ((finfo->fcf.src_addr_mode & 3) != 0) - { - flen->src_pid_len = 2; - } - - /* Set PAN ID compression bit if src pan id matches dest pan id. */ - - if ((finfo->fcf.dest_addr_mode & 3) != 0 && - (finfo->fcf.src_addr_mode & 3) != 0 && - finfo->src_pid == finfo->dest_pid) - { - /* Indicate source PANID compression */ - - finfo->fcf.panid_compression = 1; - - /* Compressed header, only do dest pid. - * - * REVISIT: This was commented out in corresponding Contiki logic, but - * is needed to match sixlowpan_recv_hdrlen(). - */ - - flen->src_pid_len = 0; - } - - /* Determine address lengths */ - - flen->dest_addr_len = sixlowpan_addrlen(finfo->fcf.dest_addr_mode & 3); - flen->src_addr_len = sixlowpan_addrlen(finfo->fcf.src_addr_mode & 3); - - /* Aux security header */ - -#if 0 /* TODO Aux security header not yet implemented */ - if ((finfo->fcf.security_enabled & 1) != 0) - { - switch(finfo->aux_hdr.security_control.key_id_mode) - { - case 0: - flen->aux_sec_len = 5; /* Minimum value */ - break; - - case 1: - flen->aux_sec_len = 6; - break; - - case 2: - flen->aux_sec_len = 10; - break; - - case 3: - flen->aux_sec_len = 14; - break; - - default: - break; - } - } -#endif -} - /**************************************************************************** - * Name: sixlowpan_fieldlengths + * Name: sixlowpan_meta_data * * Description: - * Return the lengths associated fields of the IEEE802.15.4 header. + * Based on the collected attributes and addresses, construct the MAC meta + * data structure that we need to interface with the IEEE802.15.4 MAC. * - * Input parameters: - * finfo - IEEE802.15.4 header info (input) - * flen - Field length info (output) - * - * Returned Value: - * None - * - ****************************************************************************/ - -static int sixlowpan_flen_hdrlen(FAR const struct field_length_s *flen) -{ - return 3 + flen->dest_pid_len + flen->dest_addr_len + - flen->src_pid_len + flen->src_addr_len + flen->aux_sec_len; -} - -/**************************************************************************** - * Name: sixlowpan_802154_hdrlen - * - * Description: - * Calculates the length of the frame header. This function is meant to - * be called by a higher level function, that interfaces to a MAC. - * - * Input parameters: - * finfo - IEEE802.15.4 header info that specifies the frame to send. - * - * Returned Value: - * The length of the frame header. - * - ****************************************************************************/ - -static int sixlowpan_802154_hdrlen(FAR struct frame802154_s *finfo) -{ - struct field_length_s flen; - - sixlowpan_fieldlengths(finfo, &flen); - return sixlowpan_flen_hdrlen(&flen); -} - -/**************************************************************************** - * Name: sixlowpan_setup_params - * - * Description: - * Configure frame parmeters structure. - * - * Input parameters: - * ieee - A reference IEEE802.15.4 MAC network device structure. - * iob - The IOB in which to create the frame. + * Input Parameters: * dest_panid - PAN ID of the destination. May be 0xffff if the destination * is not associated. - * params - Where to put the parmeters + * meta - Location to return the corresponding meta data. * * Returned Value: - * None. + * Ok is returned on success; Othewise a negated errno value is returned. + * + * Assumptions: + * Called with the network locked. * ****************************************************************************/ -static void sixlowpan_setup_params(FAR struct ieee802154_driver_s *ieee, - uint16_t dest_panid, - FAR struct frame802154_s *params) +int sixlowpan_meta_data(uint16_t dest_panid, + FAR struct ieee802154_frame_meta_s *meta) { +#if 0 /* To be provided */ + /* Set up the frame parameters */ + uint16_t src_panid; bool rcvrnull; /* Initialize all prameters to all zero */ - memset(params, 0, sizeof(params)); + memset(meta, 0, sizeof(struct ieee802154_frame_meta_s)); /* Build the FCF (Only non-zero elements need to be initialized). */ - params->fcf.frame_type = FRAME802154_DATAFRAME; - params->fcf.frame_pending = g_pktattrs[PACKETBUF_ATTR_PENDING]; + meta->fcf.frame_type = FRAME802154_DATAFRAME; + meta->fcf.frame_pending = g_pktattrs[PACKETBUF_ATTR_PENDING]; /* If the output address is NULL in the Rime buf, then it is broadcast * on the 802.15.4 network. @@ -312,24 +172,12 @@ static void sixlowpan_setup_params(FAR struct ieee802154_driver_s *ieee, rcvrnull = sixlowpan_addrnull(g_pktaddrs[PACKETBUF_ADDR_RECEIVER].u8); if (rcvrnull) { - params->fcf.ack_required = g_pktattrs[PACKETBUF_ATTR_MAC_ACK]; + meta->fcf.ack_required = g_pktattrs[PACKETBUF_ATTR_MAC_ACK]; } /* Insert IEEE 802.15.4 (2003) version bit. */ - params->fcf.frame_version = FRAME802154_IEEE802154_2003; - - /* Increment and set the data sequence number. */ - - if (g_pktattrs[PACKETBUF_ATTR_MAC_SEQNO] != 0) - { - params->seq = g_pktattrs[PACKETBUF_ATTR_MAC_SEQNO] & 0xff; - } - else - { - params->seq = ieee->i_dsn++; - g_pktattrs[PACKETBUF_ATTR_MAC_SEQNO] = params->seq | 0x100; - } + meta->fcf.frame_version = FRAME802154_IEEE802154_2003; /* Complete the addressing fields. */ /* Get the source PAN ID from the IEEE802.15.4 radio driver */ @@ -339,8 +187,8 @@ static void sixlowpan_setup_params(FAR struct ieee802154_driver_s *ieee, /* Set the source and destination PAN ID. */ - params->src_pid = src_panid; - params->dest_pid = dest_panid; + meta->src_pid = src_panid; + meta->dest_pid = dest_panid; /* If the output address is NULL in the Rime buf, then it is broadcast * on the 802.15.4 network. @@ -350,46 +198,46 @@ static void sixlowpan_setup_params(FAR struct ieee802154_driver_s *ieee, { /* Broadcast requires short address mode. */ - params->fcf.dest_addr_mode = FRAME802154_SHORTADDRMODE; - params->dest_addr[0] = 0xff; - params->dest_addr[1] = 0xff; + meta->fcf.dest_addr_mode = FRAME802154_SHORTADDRMODE; + meta->dest_addr[0] = 0xff; + meta->dest_addr[1] = 0xff; } else { /* Copy the destination address */ - rimeaddr_copy((struct rimeaddr_s *)¶ms->dest_addr, + rimeaddr_copy((struct rimeaddr_s *)&meta->dest_addr, g_pktaddrs[PACKETBUF_ADDR_RECEIVER].u8); /* Use short destination address mode if so configured */ #ifdef CONFIG_NET_6LOWPAN_RIMEADDR_EXTENDED - params->fcf.dest_addr_mode = FRAME802154_LONGADDRMODE; + meta->fcf.dest_addr_mode = FRAME802154_LONGADDRMODE; #else - params->fcf.dest_addr_mode = FRAME802154_SHORTADDRMODE; + meta->fcf.dest_addr_mode = FRAME802154_SHORTADDRMODE; #endif } /* Set the source address to the node address assigned to the device */ - rimeaddr_copy((struct rimeaddr_s *)¶ms->src_addr, + rimeaddr_copy((struct rimeaddr_s *)&meta->src_addr, &ieee->i_dev.d_mac.ieee802154); /* Use short soruce address mode if so configured */ #ifdef CONFIG_NET_6LOWPAN_RIMEADDR_EXTENDED - params->fcf.src_addr_mode = FRAME802154_LONGADDRMODE; + meta->fcf.src_addr_mode = FRAME802154_LONGADDRMODE; #else - params->fcf.src_addr_mode = FRAME802154_SHORTADDRMODE; + meta->fcf.src_addr_mode = FRAME802154_SHORTADDRMODE; #endif +#endif + +#warning Missing logic + return -ENOSYS; } /**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: sixlowpan_send_hdrlen + * Name: sixlowpan_frame_hdrlen * * Description: * This function is before the first frame has been sent in order to @@ -397,9 +245,8 @@ static void sixlowpan_setup_params(FAR struct ieee802154_driver_s *ieee, * buffer is required to make this determination. * * Input parameters: - * ieee - A reference IEEE802.15.4 MAC network device structure. - * dest_panid - PAN ID of the destination. May be 0xffff if the destination - * is not associated. + * ieee - A reference IEEE802.15.4 MAC network device structure. + * meta - Meta data that describes the MAC header * * Returned Value: * The frame header length is returnd on success; otherwise, a negated @@ -407,171 +254,37 @@ static void sixlowpan_setup_params(FAR struct ieee802154_driver_s *ieee, * ****************************************************************************/ -int sixlowpan_send_hdrlen(FAR struct ieee802154_driver_s *ieee, - uint16_t dest_panid) +int sixlowpan_frame_hdrlen(FAR struct ieee802154_driver_s *ieee, + FAR const struct ieee802154_frame_meta_s *meta) { - struct frame802154_s params; - - /* Set up the frame parameters */ - - sixlowpan_setup_params(ieee, dest_panid, ¶ms); - - /* Return the length of the header */ - - return sixlowpan_802154_hdrlen(¶ms); + return ieee->i_get_mhrlen(ieee, meta); } /**************************************************************************** - * Name: sixlowpan_802154_framecreate - * - * Description: - * Creates a frame for transmission over the air. This function is meant - * to be called by a higher level function, that interfaces to a MAC. - * - * Input parameters: - * finfo - Pointer to struct EEE802.15.4 header structure that specifies - * the frame to send. - * buf - Pointer to the buffer to use for the frame. - * buflen - The length of the buffer to use for the frame. - * finfo - Specifies the frame to send. - * - * Returned Value: - * The length of the frame header or 0 if there was insufficient space in - * the buffer for the frame headers. - * - ****************************************************************************/ - -int sixlowpan_802154_framecreate(FAR struct frame802154_s *finfo, - FAR uint8_t *buf, int buflen) -{ - struct field_length_s flen; - uint8_t pos; - int hdrlen; - int i; - - sixlowpan_fieldlengths(finfo, &flen); - - hdrlen = sixlowpan_flen_hdrlen(&flen); - if (hdrlen > buflen) - { - /* Too little space for headers. */ - - return 0; - } - - /* OK, now we have field lengths. Time to actually construct the outgoing - * frame, and store it in the provided buffer - */ - - buf[0] = ((finfo->fcf.frame_type & 7) << FRAME802154_FRAMETYPE_SHIFT) | - ((finfo->fcf.security_enabled & 1) << FRAME802154_SECENABLED_SHIFT) | - ((finfo->fcf.frame_pending & 1) << FRAME802154_FRAMEPENDING_SHIFT) | - ((finfo->fcf.ack_required & 1) << FRAME802154_ACKREQUEST_SHIFT) | - ((finfo->fcf.panid_compression & 1) << FRAME802154_PANIDCOMP_SHIFT); - buf[1] = ((finfo->fcf.dest_addr_mode & 3) << FRAME802154_DSTADDR_SHIFT) | - ((finfo->fcf.frame_version & 3) << FRAME802154_VERSION_SHIFT) | - ((finfo->fcf.src_addr_mode & 3) << FRAME802154_SRCADDR_SHIFT); - - /* Sequence number */ - - buf[2] = finfo->seq; - pos = 3; - - /* Destination PAN ID */ - - if (flen.dest_pid_len == 2) - { - buf[pos++] = finfo->dest_pid & 0xff; - buf[pos++] = (finfo->dest_pid >> 8) & 0xff; - } - - /* Destination address */ - - for (i = flen.dest_addr_len; i > 0; i--) - { - buf[pos++] = finfo->dest_addr[i - 1]; - } - - /* Source PAN ID */ - - if (flen.src_pid_len == 2) - { - buf[pos++] = finfo->src_pid & 0xff; - buf[pos++] = (finfo->src_pid >> 8) & 0xff; - } - - /* Source address */ - - for (i = flen.src_addr_len; i > 0; i--) - { - buf[pos++] = finfo->src_addr[i - 1]; - } - - /* Aux header */ - -#if 0 /* TODO Aux security header not yet implemented */ - if (flen.aux_sec_len) - { - pos += flen.aux_sec_len; - } -#endif - - DEBUGASSERT(pos == hdrlen); - return (int)pos; -} - -/**************************************************************************** - * Name: sixlowpan_framecreate + * Name: sixlowpan_frame_submit * * Description: * This function is called after eiether (1) the IEEE802.15.4 MAC driver - * polls for TX data or (2) after the IEEE802.15.4 MAC driver provides an - * in frame and the network responds with an outgoing packet. It creates - * the IEEE802.15.4 header in the frame buffer. + * polls for TX data or (2) after the IEEE802.15.4 MAC driver provides a + * new incoming frame and the network responds with an outgoing packet. It + * submits any new outgoing frame to the MAC. * * Input parameters: - * ieee - A reference IEEE802.15.4 MAC network device structure. - * iob - The IOB in which to create the frame. - * dest_panid - PAN ID of the destination. May be 0xffff if the destination - * is not associated. + * ieee - A reference IEEE802.15.4 MAC network device structure. + * meta - Meta data that describes the MAC header + * frame - The IOB containing the frame to be submitted. * * Returned Value: - * The frame header length is returnd on success; otherwise, a negated - * errno value is return on failure. + * Zero (OK) is returned on success; otherwise, a negated errno value is + * return on any failure. * ****************************************************************************/ -int sixlowpan_framecreate(FAR struct ieee802154_driver_s *ieee, - FAR struct iob_s *iob, uint16_t dest_panid) +int sixlowpan_frame_submit(FAR struct ieee802154_driver_s *ieee, + FAR const struct ieee802154_frame_meta_s *meta, + FAR struct iob_s *frame) { - struct frame802154_s params; - int hdrlen; - - /* Set up the frame parameters */ - - sixlowpan_setup_params(ieee, dest_panid, ¶ms); - - /* Get the length of the header */ - - hdrlen = sixlowpan_802154_hdrlen(¶ms); - - /* Then create the frame */ - - sixlowpan_802154_framecreate(¶ms, iob->io_data, hdrlen); - - wlinfo("Frame type: %02x hdrlen: %d\n", - params.fcf.frame_type, hdrlen); -#ifdef CONFIG_NET_6LOWPAN_RIMEADDR_EXTENDED - wlinfo("Dest address: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", - params.dest_addr[0], params.dest_addr[1], params.dest_addr[2], - params.dest_addr[3], params.dest_addr[4], params.dest_addr[5], - params.dest_addr[6], params.dest_addr[7]); -#else - wlinfo("Dest address: %02x:%02x\n", - params.dest_addr[0], params.dest_addr[1]); -#endif - - return hdrlen; + return ieee->i_req_data(ieee, meta, frame); } #endif /* CONFIG_NET_6LOWPAN */ diff --git a/net/sixlowpan/sixlowpan_input.c b/net/sixlowpan/sixlowpan_input.c index bccd97677b7..0c573913d92 100644 --- a/net/sixlowpan/sixlowpan_input.c +++ b/net/sixlowpan/sixlowpan_input.c @@ -129,92 +129,6 @@ static uint8_t g_bitbucket[UNCOMP_MAXHDR]; * Private Functions ****************************************************************************/ -/**************************************************************************** - * Name: sixlowpan_recv_hdrlen - * - * Description: - * Get the length of the IEEE802.15.4 FCF header on the received frame. - * - * Input Parameters: - * ieee - The IEEE802.15.4 MAC network driver interface. - * iob - The IOB containing the frame. - * - * Returned Value: - * Ok is returned on success; Othewise a negated errno value is returned. - * - * Assumptions: - * Network is locked - * - ****************************************************************************/ - -int sixlowpan_recv_hdrlen(FAR const uint8_t *fptr) -{ - uint16_t hdrlen; - uint8_t addrmode; - - /* Minimum header: 2 byte FCF + 1 byte sequence number */ - - hdrlen = 3; - - /* Account for destination address size */ - - addrmode = (fptr[1] & FRAME802154_DSTADDR_MASK) >> FRAME802154_DSTADDR_SHIFT; - if (addrmode == FRAME802154_SHORTADDRMODE) - { - /* 2 byte dest PAN + 2 byte dest short address */ - - hdrlen += 4; - } - else if (addrmode == FRAME802154_LONGADDRMODE) - { - /* 2 byte dest PAN + 8 byte dest long address */ - - hdrlen += 10; - } - else if (addrmode != FRAME802154_NOADDR) - { - nwarn("WARNING: Unrecognized address mode\n"); - - return -ENOSYS; - } - else if ((fptr[0] & (1 << FRAME802154_PANIDCOMP_SHIFT)) != 0) - { - nwarn("WARNING: PAN compression, but no destination address\n"); - - return -EINVAL; - } - - /* Account for source address size */ - - addrmode = (fptr[1] & FRAME802154_SRCADDR_MASK) >> FRAME802154_SRCADDR_SHIFT; - if (addrmode == FRAME802154_NOADDR) - { - return hdrlen; - } - else - { - /* Add source PANID if PANIDs are not compressed */ - - if ((fptr[0] & (1 << FRAME802154_PANIDCOMP_SHIFT)) == 0) - { - hdrlen += 2; - } - - /* Add the length of the source address */ - - if (addrmode == FRAME802154_SHORTADDRMODE) - { - return hdrlen + 2; - } - else if (addrmode == FRAME802154_LONGADDRMODE) - { - return hdrlen + 8; - } - } - - return 0; -} - /**************************************************************************** * Name: sixlowpan_compress_ipv6hdr * @@ -245,7 +159,7 @@ static void sixlowpan_uncompress_ipv6hdr(FAR uint8_t *fptr, FAR uint8_t *bptr) { FAR struct ipv6_hdr_s *ipv6 = (FAR struct ipv6_hdr_s *)bptr; uint16_t protosize; - + /* Put uncompressed IPv6 header in d_buf. */ g_frame_hdrlen += SIXLOWPAN_IPV6_HDR_LEN; @@ -355,8 +269,8 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, * This size includes both fragmentation and FCF headers. */ - fptr = iob->io_data; - hdrsize = sixlowpan_recv_hdrlen(fptr); + fptr = iob->io_data; /* Frame data is in I/O buffer */ + hdrsize = iob->io_offset; /* Offset past the MAC header */ if (hdrsize < 0) { nwarn("Invalid IEEE802.15.2 header: %d\n", hdrsize); @@ -729,25 +643,32 @@ static int sixlowpan_dispatch(FAR struct ieee802154_driver_s *ieee) * Description: * Process an incoming 6loWPAN frame. * - * This function is called when the device driver has received a 6loWPAN - * frame from the network. The frame from the device driver must be - * provided in a IOB present in the i_framelist: The frame data is in the - * IOB io_data[] buffer and the length of the frame is in the IOB io_len - * field. Only a single IOB is expected in the i_framelist. This incoming - * data will be processed one frame at a time. + * This function is called when the device driver has received an + * IEEE802.15.4 frame from the network. The frame from the device + * driver must be provided in by the IOB frame argument of the + * function call: * - * An non-NULL d_buf of size CONFIG_NET_6LOWPAN_MTU must also be provided. - * The frame will be decompressed and placed in the d_buf. Fragmented - * packets will also be reassembled in the d_buf as they are received - * (meaning for the driver, that two packet buffers are required: One for - * reassembly of RX packets and one used for TX polling). + * - The frame data is in the IOB io_data[] buffer, + * - The length of the frame is in the IOB io_len field, and + * - The offset past the IEEE802.15.4 MAC header is provided in the + * io_offset field. * - * After each frame is processed into d_buf, the IOB is removed and - * deallocated. i_framelist will be nullified. If reassembly is - * incomplete, this function will return to called with i_framelist - * equal to NULL. The partially reassembled packet must be preserved by - * the IEEE802.15.4 MAC and provided again when the next frame is - * received. + * The frame argument may refer to a single frame (a list of length one) + * or may it be the head of a list of multiple frames. + * + * - The io_flink field points to the next frame in the list (if enable) + * - The last frame in the list will have io_flink == NULL. + * + * An non-NULL d_buf of size CONFIG_NET_6LOWPAN_MTU + CONFIG_NET_GUARDSIZE + * must also be provided. The frame will be decompressed and placed in + * the d_buf. Fragmented packets will also be reassembled in the d_buf as + * they are received (meaning for the driver, that two packet buffers are + * required: One for reassembly of RX packets and one used for TX polling). + * + * After each frame is processed into d_buf, the IOB is deallocated. If + * reassembly is incomplete, the partially reassembled packet must be + * preserved by the IEEE802.15.4 MAC network drvier sand provided again + * when the next frame is received. * * When the packet in the d_buf is fully reassembled, it will be provided * to the network as with any other received packet. d_len will be set @@ -755,43 +676,40 @@ static int sixlowpan_dispatch(FAR struct ieee802154_driver_s *ieee) * * After the network processes the packet, d_len will be set to zero. * Network logic may also decide to send a response to the packet. In - * that case, the outgoing network packet will be placed in d_buf the - * d_buf and d_len will be set to a non-zero value. That case is handled - * by this function. + * that case, the outgoing network packet will be placed in d_buf and + * d_len will be set to a non-zero value. That case is handled by this + * function. * * If that case occurs, the packet will be converted to a list of - * compressed and possibly fragmented frames in i_framelist as with other - * TX operations. - * - * So from the standpoint of the IEEE802.15.4 MAC driver, there are two - * possible results: (1) i_framelist is NULL meaning that the frame - * was fully processed and freed, or (2) i_framelist is non-NULL meaning - * that there are outgoing frame(s) to be sent. + * compressed and possibly fragmented frames and provided to the MAC + * network driver via the req_data() method as with other TX operations. * * Input Parameters: - * ieee - The IEEE802.15.4 MAC network driver interface. + * ieee - The IEEE802.15.4 MAC network driver interface. + * framelist - The head of an incoming list of frames. * * Returned Value: * Ok is returned on success; Othewise a negated errno value is returned. * ****************************************************************************/ -int sixlowpan_input(FAR struct ieee802154_driver_s *ieee) +int sixlowpan_input(FAR struct ieee802154_driver_s *ieee, + FAR struct iob_s *framelist) { int ret = -EINVAL; - DEBUGASSERT(ieee != NULL && !FRAME_IOB_EMPTY(ieee)); + DEBUGASSERT(ieee != NULL && framelist != NULL); - /* Verify that an IOB is provided in the device structure */ + /* Verify that an frame has been provided. */ - while (!FRAME_IOB_EMPTY(ieee)) + while (framelist != NULL) { FAR struct iob_s *iob; /* Remove the IOB containing the frame from the device structure */ - FRAME_IOB_REMOVE(ieee, iob); - DEBUGASSERT(iob != NULL); + iob = framelist; + framelist = iob->io_flink; sixlowpan_dumpbuffer("Incoming frame", iob->io_data, iob->io_len); diff --git a/net/sixlowpan/sixlowpan_internal.h b/net/sixlowpan/sixlowpan_internal.h index 08b2fc445cb..8eecb3b49b7 100644 --- a/net/sixlowpan/sixlowpan_internal.h +++ b/net/sixlowpan/sixlowpan_internal.h @@ -107,28 +107,27 @@ #define PACKETBUF_ATTR_LISTEN_TIME 7 #define PACKETBUF_ATTR_TRANSMIT_TIME 8 #define PACKETBUF_ATTR_MAX_MAC_TRANSMISSIONS 9 -#define PACKETBUF_ATTR_MAC_SEQNO 10 -#define PACKETBUF_ATTR_MAC_ACK 11 +#define PACKETBUF_ATTR_MAC_ACK 10 /* Scope 1 attributes: used between two neighbors only. */ -#define PACKETBUF_ATTR_RELIABLE 12 -#define PACKETBUF_ATTR_PACKET_ID 13 -#define PACKETBUF_ATTR_PACKET_TYPE 14 -#define PACKETBUF_ATTR_REXMIT 15 -#define PACKETBUF_ATTR_MAX_REXMIT 16 -#define PACKETBUF_ATTR_NUM_REXMIT 17 -#define PACKETBUF_ATTR_PENDING 18 +#define PACKETBUF_ATTR_RELIABLE 11 +#define PACKETBUF_ATTR_PACKET_ID 12 +#define PACKETBUF_ATTR_PACKET_TYPE 13 +#define PACKETBUF_ATTR_REXMIT 14 +#define PACKETBUF_ATTR_MAX_REXMIT 15 +#define PACKETBUF_ATTR_NUM_REXMIT 16 +#define PACKETBUF_ATTR_PENDING 17 /* Scope 2 attributes: used between end-to-end nodes. */ -#define PACKETBUF_ATTR_HOPS 11 -#define PACKETBUF_ATTR_TTL 20 -#define PACKETBUF_ATTR_EPACKET_ID 21 -#define PACKETBUF_ATTR_EPACKET_TYPE 22 -#define PACKETBUF_ATTR_ERELIABLE 23 +#define PACKETBUF_ATTR_HOPS 18 +#define PACKETBUF_ATTR_TTL 19 +#define PACKETBUF_ATTR_EPACKET_ID 20 +#define PACKETBUF_ATTR_EPACKET_TYPE 21 +#define PACKETBUF_ATTR_ERELIABLE 22 -#define PACKETBUF_NUM_ATTRS 24 +#define PACKETBUF_NUM_ATTRS 23 /* Addresses (indices into g_pktaddrs) */ @@ -188,69 +187,6 @@ struct ipv6icmp_hdr_s struct icmpv6_iphdr_s icmp; }; -/* IEEE802.15.4 Frame Definitions *******************************************/ -/* The IEEE 802.15.4 frame has a number of constant/fixed fields that can be - * counted to make frame construction and max payload calculations easier. - * These include: - * - * 1. FCF - 2 bytes - Fixed - * 2. Sequence number - 1 byte - Fixed - * 3. Addressing fields - 4 - 20 bytes - Variable - * 4. Aux security header - 0 - 14 bytes - Variable - * 5. CRC - 2 bytes - Fixed -*/ - -/* Defines the bitfields of the frame control field (FCF). */ - -struct frame802154_fcf_s -{ - uint8_t frame_type; /* 3 bit. Frame type field, see 802.15.4 */ - uint8_t security_enabled; /* 1 bit. True if security is used in this frame */ - uint8_t frame_pending; /* 1 bit. True if sender has more data to send */ - uint8_t ack_required; /* 1 bit. Is an ack frame required? */ - uint8_t panid_compression; /* 1 bit. Is this a compressed header? */ - /* 3 bit. Unused bits */ - uint8_t dest_addr_mode; /* 2 bit. Destination address mode, see 802.15.4 */ - uint8_t frame_version; /* 2 bit. 802.15.4 frame version */ - uint8_t src_addr_mode; /* 2 bit. Source address mode, see 802.15.4 */ -}; - -/* 802.15.4 security control bitfield. See section 7.6.2.2.1 in 802.15.4 - * specification. - */ - -struct frame802154_scf_s -{ - uint8_t security_level; /* 3 bit. security level */ - uint8_t key_id_mode; /* 2 bit. Key identifier mode */ - uint8_t reserved; /* 3 bit. Reserved bits */ -}; - -/* 802.15.4 Aux security header */ - -struct frame802154_aux_hdr_s -{ - struct frame802154_scf_s security_control; /* Security control bitfield */ - uint32_t frame_counter; /* Frame counter, used for security */ - uint8_t key[9]; /* The key itself, or an index to the key */ -}; - -/* Parameters used by the frame802154_create() function. These parameters - * are used in the 802.15.4 frame header. See the 802.15.4 specification - * for details. - */ - -struct frame802154_s -{ - struct frame802154_fcf_s fcf; /* Frame control field */ - uint8_t seq; /* Sequence number */ - uint16_t dest_pid; /* Destination PAN ID */ - uint8_t dest_addr[8]; /* Destination address */ - uint16_t src_pid; /* Source PAN ID */ - uint8_t src_addr[8]; /* Source address */ - struct frame802154_aux_hdr_s aux_hdr; /* Aux security header */ -}; - /**************************************************************************** * Public Data ****************************************************************************/ @@ -313,9 +249,8 @@ struct iob_s; /* Forward reference */ * * The payload data is in the caller 'buf' and is of length 'buflen'. * Compressed headers will be added and if necessary the packet is - * fragmented. The resulting packet/fragments are put in ieee->i_framelist - * and the entire list of frames will be delivered to the 802.15.4 MAC via - * ieee->i_framelist. + * fragmented. The resulting packet/fragments are submitted to the MAC + * via the network driver i_req_data method. * * Input Parameters: * dev - The IEEE802.15.4 MAC network driver interface. @@ -344,7 +279,30 @@ int sixlowpan_send(FAR struct net_driver_s *dev, uint16_t timeout); /**************************************************************************** - * Name: sixlowpan_send_hdrlen + * Name: sixlowpan_meta_data + * + * Description: + * Based on the collected attributes and addresses, construct the MAC meta + * data structure that we need to interface with the IEEE802.15.4 MAC. + * + * Input Parameters: + * dest_panid - PAN ID of the destination. May be 0xffff if the destination + * is not associated. + * meta - Location to return the corresponding meta data. + * + * Returned Value: + * Ok is returned on success; Othewise a negated errno value is returned. + * + * Assumptions: + * Called with the network locked. + * + ****************************************************************************/ + +int sixlowpan_meta_data(uint16_t dest_panid, + FAR struct ieee802154_frame_meta_s *meta); + +/**************************************************************************** + * Name: sixlowpan_frame_hdrlen * * Description: * This function is before the first frame has been sent in order to @@ -352,9 +310,8 @@ int sixlowpan_send(FAR struct net_driver_s *dev, * buffer is required to make this determination. * * Input parameters: - * ieee - A reference IEEE802.15.4 MAC network device structure. - * dest_panid - PAN ID of the destination. May be 0xffff if the destination - * is not associated. + * ieee - A reference IEEE802.15.4 MAC network device structure. + * meta - Meta data that describes the MAC header * * Returned Value: * The frame header length is returnd on success; otherwise, a negated @@ -362,30 +319,32 @@ int sixlowpan_send(FAR struct net_driver_s *dev, * ****************************************************************************/ -int sixlowpan_send_hdrlen(FAR struct ieee802154_driver_s *ieee, - uint16_t dest_panid); +int sixlowpan_frame_hdrlen(FAR struct ieee802154_driver_s *ieee, + FAR const struct ieee802154_frame_meta_s *meta); /**************************************************************************** - * Name: sixlowpan_framecreate + * Name: sixlowpan_frame_submit * * Description: - * This function is called after the IEEE802.15.4 MAC driver polls for - * TX data. It creates the IEEE802.15.4 header in the frame buffer. + * This function is called after eiether (1) the IEEE802.15.4 MAC driver + * polls for TX data or (2) after the IEEE802.15.4 MAC driver provides a + * new incoming frame and the network responds with an outgoing packet. It + * submits any new outgoing frame to the MAC. * * Input parameters: - * ieee - A reference IEEE802.15.4 MAC network device structure. - * iob - The IOB in which to create the frame. - * dest_panid - PAN ID of the destination. May be 0xffff if the destination - * is not associated. + * ieee - A reference IEEE802.15.4 MAC network device structure. + * meta - Meta data that describes the MAC header + * frame - The IOB containing the frame to be submitted. * * Returned Value: - * The frame header length is returnd on success; otherwise, a negated - * errno value is return on failure. + * Zero (OK) is returned on success; otherwise, a negated errno value is + * return on any failure. * ****************************************************************************/ -int sixlowpan_framecreate(FAR struct ieee802154_driver_s *ieee, - FAR struct iob_s *iob, uint16_t dest_panid); +int sixlowpan_frame_submit(FAR struct ieee802154_driver_s *ieee, + FAR const struct ieee802154_frame_meta_s *meta, + FAR struct iob_s *frame); /**************************************************************************** * Name: sixlowpan_queue_frames @@ -397,9 +356,8 @@ int sixlowpan_framecreate(FAR struct ieee802154_driver_s *ieee, * * The payload data is in the caller 'buf' and is of length 'buflen'. * Compressed headers will be added and if necessary the packet is - * fragmented. The resulting packet/fragments are put in ieee->i_framelist - * and the entire list of frames will be delivered to the 802.15.4 MAC via - * ieee->i_framelist. + * fragmented. The resulting packet/fragments are submitted to the MAC + * via the network driver i_req_data method. * * Input Parameters: * ieee - The IEEE802.15.4 MAC driver instance diff --git a/net/sixlowpan/sixlowpan_send.c b/net/sixlowpan/sixlowpan_send.c index 3ad68554aec..64b7088735e 100644 --- a/net/sixlowpan/sixlowpan_send.c +++ b/net/sixlowpan/sixlowpan_send.c @@ -246,11 +246,10 @@ end_wait: * it to be sent on an 802.15.4 network using 6lowpan. Called from common * UDP/TCP send logic. * - * The payload data is in the caller 'buf' and is of length 'len'. + * The payload data is in the caller 'buf' and is of length 'buflen'. * Compressed headers will be added and if necessary the packet is - * fragmented. The resulting packet/fragments are put in ieee->i_framelist - * and the entire list of frames will be delivered to the 802.15.4 MAC via - * ieee->i_framelist. + * fragmented. The resulting packet/fragments are submitted to the MAC + * via the network driver i_req_data method. * * Input Parameters: * dev - The IEEE802.15.4 MAC network driver interface. diff --git a/wireless/ieee802154/mac802154_loopback.c b/wireless/ieee802154/mac802154_loopback.c index 92a30d35194..3d2fcf144f3 100644 --- a/wireless/ieee802154/mac802154_loopback.c +++ b/wireless/ieee802154/mac802154_loopback.c @@ -102,8 +102,8 @@ struct lo_driver_s uint16_t lo_panid; /* Fake PAN ID for testing */ WDOG_ID lo_polldog; /* TX poll timer */ struct work_s lo_work; /* For deferring poll work to the work queue */ - FAR struct iob_s *head; /* Head of IOBs queued for loopback */ - FAR struct iob_s *tail; /* Tail of IOBs queued for loopback */ + FAR struct iob_s *lo_head; /* Head of IOBs queued for loopback */ + FAR struct iob_s *lo_tail; /* Tail of IOBs queued for loopback */ /* This holds the information visible to the NuttX network */ @@ -145,9 +145,9 @@ static int lo_ioctl(FAR struct net_driver_s *dev, int cmd, unsigned long arg); #endif static int lo_get_mhrlen(FAR struct ieee802154_driver_s *netdev, - FAR struct ieee802154_frame_meta_s *meta); + FAR const struct ieee802154_frame_meta_s *meta); static int lo_req_data(FAR struct ieee802154_driver_s *netdev, - FAR struct ieee802154_frame_meta_s *meta, + FAR const struct ieee802154_frame_meta_s *meta, FAR struct iob_s *frames); /**************************************************************************** @@ -177,43 +177,15 @@ static int lo_req_data(FAR struct ieee802154_driver_s *netdev, static int lo_loopback(FAR struct net_driver_s *dev) { FAR struct lo_driver_s *priv = (FAR struct lo_driver_s *)dev->d_private; - FAR struct iob_s *head; - FAR struct iob_s *tail; FAR struct iob_s *iob; int ret; - if (dev->d_len > 0 || priv->lo_ieee.i_framelist != NULL) - { - ninfo("d_len: %u i_framelist: %p\n", - dev->d_len, priv->lo_ieee.i_framelist); - - /* The only two valid settings are: - * - * 1. Nothing to send: - * dev->d_len == 0 && priv->lo_ieee.i_framelist == NULL - * 2. Outgoing packet has been converted to IEEE802.15.4 frames: - * dev->d_len == 0 && priv->lo_ieee.i_framelist != NULL - */ - - DEBUGASSERT(dev->d_len == 0 && priv->lo_ieee.i_framelist != NULL); - } - - /* Remove the queued IOBs from driver structure */ - - head = priv->lo_ieee.i_framelist; - - /* Find the tail of the IOB queue */ - - for (tail = NULL, iob = head; - iob != NULL; - tail = iob, iob = iob->io_flink); - - /* Loop while there frames to be sent, i.e., while the IOB list is not - * emtpy. Sending, of course, just means relaying back through the network + /* Loop while there frames to be sent, i.e., while the freme list is not + * emtpy. Sending, of course, just means relaying back through the network * for this driver. */ - while (head != NULL) + while (priv->lo_head != NULL) { /* Increment statistics */ @@ -221,24 +193,23 @@ static int lo_loopback(FAR struct net_driver_s *dev) /* Remove the IOB from the queue */ - iob = head; - head = iob->io_flink; + iob = priv->lo_head; + priv->lo_head = iob->io_flink; iob->io_flink = NULL; - /* Is the queue now empty? */ + /* Did the framelist become empty? */ - if (head == NULL) + if (priv->lo_head == NULL) { - tail = NULL; + priv->lo_tail = NULL; } /* Return the next frame to the network */ - iob->io_flink = NULL; - priv->lo_ieee.i_framelist = iob; + ninfo("Send frame %p to the network: Offset=%u Length=%u\n", + iob, iob->io_offset, iob->io_len); - ninfo("Send frame %p to the network. Length=%u\n", iob, iob->io_len); - ret = sixlowpan_input(&priv->lo_ieee); + ret = sixlowpan_input(&priv->lo_ieee, iob); /* Increment statistics */ @@ -250,33 +221,6 @@ static int lo_loopback(FAR struct net_driver_s *dev) NETDEV_TXERRORS(&priv->lo_ieee.i_dev); NETDEV_ERRORS(&priv->lo_ieee.i_dev); } - - /* What if the network responds with more frames to send? */ - - if (priv->lo_ieee.i_framelist != NULL) - { - /* Append the new list to the tail of the queue */ - - iob = priv->lo_ieee.i_framelist; - priv->lo_ieee.i_framelist = NULL; - - if (tail == NULL) - { - head = iob; - } - else - { - tail->io_flink = iob; - } - - /* Find the new tail of the IOB queue */ - - for (tail = iob, iob = iob->io_flink; - iob != NULL; - tail = iob, iob = iob->io_flink); - } - - priv->lo_txdone = true; } return 0; @@ -693,7 +637,7 @@ static int lo_ioctl(FAR struct net_driver_s *dev, int cmd, ****************************************************************************/ static int lo_get_mhrlen(FAR struct ieee802154_driver_s *netdev, - FAR struct ieee802154_frame_meta_s *meta) + FAR const struct ieee802154_frame_meta_s *meta) { return MAC_HDRLEN; } @@ -710,13 +654,14 @@ static int lo_get_mhrlen(FAR struct ieee802154_driver_s *netdev, ****************************************************************************/ static int lo_req_data(FAR struct ieee802154_driver_s *netdev, - FAR struct ieee802154_frame_meta_s *meta, + FAR const struct ieee802154_frame_meta_s *meta, FAR struct iob_s *frames) { FAR struct lo_driver_s *priv; FAR struct iob_s *iob; - DEBUGASSERT(netdev != NULL && netdev->i_dev.d_private != NULL && iob != NULL); + DEBUGASSERT(netdev != NULL && netdev->i_dev.d_private != NULL && + frames != NULL); priv = (FAR struct lo_driver_s *)netdev->i_dev.d_private; /* Add the incoming list of frames to queue of frames to loopback */ @@ -737,22 +682,18 @@ static int lo_req_data(FAR struct ieee802154_driver_s *netdev, DEBUGASSERT(iob->io_offset == MAC_HDRLEN); memset(iob->io_data, 0, MAC_HDRLEN); - /* Add the IOB to the tail of teh queue of frames to be looped back */ + /* Add the IOB to the tail of the queue of frames to be looped back */ - if (priv->tail == NULL) + if (priv->lo_tail == NULL) { - priv->head = iob; + priv->lo_head = iob; } else { - priv->tail->io_flink = iob; + priv->lo_tail->io_flink = iob; } - /* Find the new tail of the IOB queue */ - - for (priv->tail = iob, iob = iob->io_flink; - iob != NULL; - priv->tail = iob, iob = iob->io_flink); + priv->lo_tail = iob; } /* Is our single work structure available? It may not be if there are @@ -821,10 +762,6 @@ int ieee8021514_loopback(void) dev->d_buf = g_iobuffer; /* Attach the IO buffer */ dev->d_private = (FAR void *)priv; /* Used to recover private state from dev */ - /* Initialize the DSN to a "random" value */ - - ieee->i_dsn = 42; - /* Initialize the Network frame-related callbacks */ ieee->i_get_mhrlen = lo_get_mhrlen; /* Get MAC header length */ diff --git a/wireless/ieee802154/mac802154_netdev.c b/wireless/ieee802154/mac802154_netdev.c index f0e4f43cbea..a5816205e4d 100644 --- a/wireless/ieee802154/mac802154_netdev.c +++ b/wireless/ieee802154/mac802154_netdev.c @@ -140,16 +140,6 @@ struct macnet_driver_s WDOG_ID md_txtimeout; /* TX timeout timer */ struct work_s md_irqwork; /* Defer interupt work to the work queue */ struct work_s md_pollwork; /* Defer poll work to the work queue */ - - /* This is queue of outgoing, ready-to-send frames that will be sent - * indirectly. This list should only be used by a MAC acting as a - * coordinator. These transactions will stay here until the data is - * extracted by the destination device sending a Data Request MAC - * command or if too much time passes. - */ - - FAR volatile struct iob_s *md_head; - FAR volatile struct iob_s *md_tail; }; /**************************************************************************** @@ -258,9 +248,9 @@ static int macnet_ioctl(FAR struct net_driver_s *dev, int cmd, unsigned long arg); #endif static int macnet_get_mhrlen(FAR struct ieee802154_driver_s *netdev, - FAR struct ieee802154_frame_meta_s *meta); + FAR const struct ieee802154_frame_meta_s *meta); static int macnet_req_data(FAR struct ieee802154_driver_s *netdev, - FAR struct ieee802154_frame_meta_s *meta, + FAR const struct ieee802154_frame_meta_s *meta, FAR struct iob_s *frames); /**************************************************************************** @@ -654,57 +644,6 @@ static int macnet_transmit(FAR struct macnet_driver_s *priv) return OK; } -/**************************************************************************** - * Name: macnet_txqueue - * - * Description: - * Add new frames from the network to the list of outgoing frames. - * - * Parameters: - * dev - Reference to the NuttX driver state structure - * - * Returned Value: - * OK on success; a negated errno on failure - * - * Assumptions: - * May or may not be called from an interrupt handler. In either case, - * the network is locked. - * - ****************************************************************************/ - -static void macnet_txqueue(FAR struct net_driver_s *dev) -{ - /* Check if there is a new list of outgoing frames from the network. */ - - if (priv->lo_ieee.i_framelist != NULL) - { - /* Yes.. Remove the frame list from the driver structure */ - - iob = priv->lo_ieee.i_framelist; - priv->lo_ieee.i_framelist = NULL; - - /* Append the new list to the tail of the queue of outgoing frames. */ - - if (priv->md_tail == NULL) - { - priv->md_head = iob; - } - else - { - priv->md_tail->io_flink = iob; - } - - /* Find the new tail of the outgoing frame queue */ - - for (priv->md_tail = iob, iob = iob->io_flink; - iob != NULL; - priv->md_tail = iob, iob = iob->io_flink); - - /* Notify the radio driver that there is data available */ -#warning Missing logic - } -} - /**************************************************************************** * Name: macnet_txpoll * @@ -724,30 +663,12 @@ static void macnet_txqueue(FAR struct net_driver_s *dev) * OK on success; a negated errno on failure * * Assumptions: - * May or may not be called from an interrupt handler. In either case, - * the network is locked. + * The network is locked. * ****************************************************************************/ static int macnet_txpoll(FAR struct net_driver_s *dev) { - FAR struct macnet_driver_s *priv = - (FAR struct macnet_driver_s *)dev->d_private; - FAR struct iob_s *iob; - - /* If the polling resulted in data that should be sent out, the field - * i_framelist will set to a new, outgoing list of frames. - */ - - if (priv->lo_ieee.i_framelist != NULL) - { - /* Remove the frame list from the driver structure and append it to - * the tail of the ist of outgoing frames. - */ - - macnet_txqueue(priv); - } - /* If zero is returned, the polling will continue until all connections have * been examined. */ @@ -781,6 +702,7 @@ static void macnet_receive(FAR struct macnet_driver_s *priv) net_lock(); iob = iob_alloc(false); +#warning Allocated by radio layer, right? if (iob == NULL) { nerr("ERROR: Failed to allocate an IOB\n") @@ -796,22 +718,7 @@ static void macnet_receive(FAR struct macnet_driver_s *priv) /* Transfer the frame to the network logic */ - priv->md_dev.framelist = iob; - sixlowpan_input(&priv->md_dev); - - /* If the above function invocation resulted in data that should be sent - * out, the field i_framelist will have been set to a new, outgoing list - * of frames. - */ - - if (priv->md_dev.i_framelist != NULL) - { - /* Remove the frame list from the driver structure and append it to - * the tail of the ist of outgoing frames. - */ - - macnet_txqueue(priv); - } + sixlowpan_input(&priv->md_dev, iob); } /**************************************************************************** @@ -1508,7 +1415,7 @@ static int macnet_ioctl(FAR struct net_driver_s *dev, int cmd, ****************************************************************************/ static int macnet_get_mhrlen(FAR struct ieee802154_driver_s *netdev, - FAR struct ieee802154_frame_meta_s *meta) + FAR const struct ieee802154_frame_meta_s *meta) { FAR struct macnet_driver_s *priv; @@ -1530,7 +1437,7 @@ static int macnet_get_mhrlen(FAR struct ieee802154_driver_s *netdev, ****************************************************************************/ static int macnet_req_data(FAR struct ieee802154_driver_s *netdev, - FAR struct ieee802154_frame_meta_s *meta, + FAR const struct ieee802154_frame_meta_s *meta, FAR struct iob_s *frames) { FAR struct macnet_driver_s *priv; From 2c2cddd44bb4ffea699aac7a5bd5b2c9bc07e60e Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Wed, 3 May 2017 11:14:06 -0400 Subject: [PATCH 122/183] wireless/ieee802154: Starts work on setting PIB attributes --- .../wireless/ieee802154/ieee802154_mac.h | 67 ++++++++++++++----- wireless/ieee802154/mac802154.c | 39 ++++++++++- 2 files changed, 86 insertions(+), 20 deletions(-) diff --git a/include/nuttx/wireless/ieee802154/ieee802154_mac.h b/include/nuttx/wireless/ieee802154/ieee802154_mac.h index 68369ab75fc..f91fbbceae4 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_mac.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_mac.h @@ -206,7 +206,7 @@ enum ieee802154_status_e { - IEEE802154_STATUS_OK = 0, + IEEE802154_STATUS_SUCCESS = 0, IEEE802154_STATUS_BEACON_LOSS = 0xE0, IEEE802154_STATUS_CHANNEL_ACCESS_FAILURE, IEEE802154_STATUS_DENIED, @@ -455,7 +455,49 @@ struct ieee802154_pend_addr_s union ieee802154_attr_val_u { - /* TODO: Finish this */ + uint8_t eaddr[8]; + uint16_t saddr; + uint16_t pan_id; + + uint8_t coord_eaddr[8]; + uint16_t coord_saddr; + + uint8_t is_assoc : 1; + uint8_t assoc_permit : 1; + uint8_t auto_req : 1; + uint8_t batt_life_ext : 1; + uint8_t gts_permit : 1; + uint8_t promisc_mode : 1; + uint8_t rng_support : 1; + uint8_t resp_wait_time; + uint8_t rx_when_idle : 1; + uint8_t sec_enabled : 1; + uint8_t timestamp_support : 1; + + uint32_t ack_wait_dur; + uint8_t batt_life_ext_periods; + uint8_t max_csma_backoffs : 3; + uint8_t max_be : 4; + uint8_t min_be : 4; + uint32_t max_frame_wait_time; + uint8_t max_retries; + uint8_t lifs_period; + uint8_t sifs_period; + uint32_t sync_symb_offset : 12; + uint16_t trans_persist_time; + uint32_t tx_ctrl_active_dur; + uint32_t tx_ctrl_pause_dur; + uint32_t tx_total_dur; + + uint8_t beacon_payload[IEEE802154_PIB_MAC_BEACON_PAYLOAD_LEN]; + uint8_t beacon_payload_len; + uint8_t beacon_order; + uint32_t beacon_tx_time : 24; + + uint8_t superframe_order; + + uint8_t bsn; + uint8_t dsn; }; struct ieee802154_gts_info_s @@ -1109,6 +1151,12 @@ struct ieee802154_scan_conf_s * Description: * Attempts to write the given value to the indicated PIB attribute. * + * NOTE: The standard specifies that confirmation should be indicated via + * the asynchronous MLME-SET.confirm primitve. However, in our implementation + * there is no reason not to synchronously return the status immediately. + * Therefore, we do merge the functionality of the MLME-SET.request and + * MLME-SET.confirm primitives together. + * *****************************************************************************/ struct ieee802154_set_req_s @@ -1117,20 +1165,6 @@ struct ieee802154_set_req_s union ieee802154_attr_val_u attr_value; }; -/***************************************************************************** - * Primitive: MLME-SET.confirm - * - * Description: - * Reports the results of an attempt to write a value to a PIB attribute. - * - *****************************************************************************/ - -struct ieee802154_set_conf_s -{ - enum ieee802154_status_e status; - enum ieee802154_pib_attr_e pib_attr; -}; - /***************************************************************************** * Primitive: MLME-START.request * @@ -1258,7 +1292,6 @@ union ieee802154_mlme_notify_u struct ieee802154_reset_conf_s resetconf; struct ieee802154_rxenable_conf_s rxenableconf; struct ieee802154_scan_conf_s scanconf; - struct ieee802154_set_conf_s setconf; struct ieee802154_start_conf_s startconf; struct ieee802154_poll_conf_s pollconf; diff --git a/wireless/ieee802154/mac802154.c b/wireless/ieee802154/mac802154.c index 56b220181a3..3f42d006c83 100644 --- a/wireless/ieee802154/mac802154.c +++ b/wireless/ieee802154/mac802154.c @@ -1450,8 +1450,13 @@ int mac802154_req_scan(MACHANDLE mac, FAR struct ieee802154_scan_req_s *req) * * Description: * The MLME-SET.request primitive attempts to write the given value to the - * indicated MAC PIB attribute. Confirmation is returned via the - * struct ieee802154_maccb_s->conf_set callback. + * indicated MAC PIB attribute. + * + * NOTE: The standard specifies that confirmation should be indicated via + * the asynchronous MLME-SET.confirm primitve. However, in our implementation + * there is no reason not to synchronously return the status immediately. + * Therefore, we do merge the functionality of the MLME-SET.request and + * MLME-SET.confirm primitives together. * ****************************************************************************/ @@ -1459,7 +1464,35 @@ int mac802154_req_set(MACHANDLE mac, FAR struct ieee802154_set_req_s *req) { FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; - return -ENOTTY; + union ieee802154_radioarg_u radio_arg; + int ret; + + switch (req->pib_attr) + { + case IEEE802154_PIB_MAC_EXTENDED_ADDR: + { + /* Set the attribute in the structure to the new value */ + + memcpy(&priv->addr.eaddr[0], &req->attr_value.eaddr[0], 8); + + + /* The radio device needs to be updated as well */ + + memcpy(&radio_arg.eaddr[0], &priv->addr.eaddr[0], 8); + ret = priv->radio->ops->ioctl(priv->radio, PHY802154IOC_SET_EADDR, + (unsigned long)&radio_arg); + + ret = IEEE802154_STATUS_SUCCESS; + } + break; + default: + { + ret = -IEEE802154_STATUS_UNSUPPORTED_ATTRIBUTE; + } + break; + } + + return ret; } /**************************************************************************** From cf988309aad3b5f8f308ae2c6d1d8f0ac20ed251 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 3 May 2017 11:13:07 -0600 Subject: [PATCH 123/183] 6loWPAN: Fixes hang in loopback test. --- include/nuttx/net/sixlowpan.h | 24 ++++-- net/sixlowpan/sixlowpan_framelist.c | 21 ++--- net/sixlowpan/sixlowpan_framer.c | 27 ------ wireless/ieee802154/mac802154_loopback.c | 105 ++++++++++++----------- wireless/ieee802154/mac802154_netdev.c | 34 +++++--- 5 files changed, 106 insertions(+), 105 deletions(-) diff --git a/include/nuttx/net/sixlowpan.h b/include/nuttx/net/sixlowpan.h index 85c95329dca..507f08eb517 100644 --- a/include/nuttx/net/sixlowpan.h +++ b/include/nuttx/net/sixlowpan.h @@ -437,6 +437,14 @@ struct ieee802154_driver_s * Description: * Calculate the MAC header length given the frame meta-data. * + * Input parameters: + * netdev - The networkd device that will mediate the MAC interface + * meta - Meta data needed to recreate the MAC header + * + * Returned Value: + * A non-negative MAC headeer length is returned on success; a negated + * errno value is returned on any failure. + * **************************************************************************/ CODE int (*i_get_mhrlen)(FAR struct ieee802154_driver_s *netdev, @@ -446,16 +454,22 @@ struct ieee802154_driver_s * Name: mac802154_req_data * * Description: - * The MCPS-DATA.request primitive requests the transfer of a data SPDU - * (i.e., MSDU) from a local SSCS entity to a single peer SSCS entity. - * Confirmation is returned via the - * struct ieee802154_maccb_s->conf_data callback. + * Requests the transfer of a list of frames to the MAC. + * + * Input parameters: + * netdev - The networkd device that will mediate the MAC interface + * meta - Meta data needed to recreate the MAC header + * framelist - Head of a list of frames to be transferred. + * + * Returned Value: + * Zero (OK) returned on success; a negated errno value is returned on + * any failure. * **************************************************************************/ CODE int (*i_req_data)(FAR struct ieee802154_driver_s *netdev, FAR const struct ieee802154_frame_meta_s *meta, - FAR struct iob_s *frames); + FAR struct iob_s *framelist); }; /**************************************************************************** diff --git a/net/sixlowpan/sixlowpan_framelist.c b/net/sixlowpan/sixlowpan_framelist.c index e4e769c0ce3..fb03af457ff 100644 --- a/net/sixlowpan/sixlowpan_framelist.c +++ b/net/sixlowpan/sixlowpan_framelist.c @@ -511,19 +511,16 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, qhead->io_pktlen += iob->io_len; } - /* Submit all of the fragments to the MAC */ + /* Submit all of the fragments to the MAC. We send all frames back- + * to-back like this to eliminate any possible condition where some + * frame which is not a fragment from this sequence from intervening. + */ - while (qhead != NULL) - { - iob = qhead; - qhead = iob->io_flink; - - ret = sixlowpan_frame_submit(ieee, &meta, iob); - if (ret < 0) - { - nerr("ERROR: sixlowpan_frame_submit() failed: %d\n", ret); - } - } + ret = sixlowpan_frame_submit(ieee, &meta, qhead); + if (ret < 0) + { + nerr("ERROR: sixlowpan_frame_submit() failed: %d\n", ret); + } /* Update the datagram TAG value */ diff --git a/net/sixlowpan/sixlowpan_framer.c b/net/sixlowpan/sixlowpan_framer.c index 9a32310d026..47afecf6af7 100644 --- a/net/sixlowpan/sixlowpan_framer.c +++ b/net/sixlowpan/sixlowpan_framer.c @@ -66,33 +66,6 @@ * Public Functions ****************************************************************************/ -/**************************************************************************** - * Name: sixlowpan_addrlen - * - * Description: - * Return the address length associated with a 2-bit address mode - * - * Input parameters: - * addrmode - The address mode - * - * Returned Value: - * The address length associated with the address mode. - * - ****************************************************************************/ - -static inline uint8_t sixlowpan_addrlen(uint8_t addrmode) -{ - switch (addrmode) - { - case FRAME802154_SHORTADDRMODE: /* 16-bit address */ - return 2; - case FRAME802154_LONGADDRMODE: /* 64-bit address */ - return 8; - default: - return 0; - } -} - /**************************************************************************** * Name: sixlowpan_addrnull * diff --git a/wireless/ieee802154/mac802154_loopback.c b/wireless/ieee802154/mac802154_loopback.c index 3d2fcf144f3..c4cb8de1536 100644 --- a/wireless/ieee802154/mac802154_loopback.c +++ b/wireless/ieee802154/mac802154_loopback.c @@ -98,7 +98,7 @@ struct lo_driver_s { bool lo_bifup; /* true:ifup false:ifdown */ - bool lo_txdone; /* One RX packet was looped back */ + bool lo_pending; /* True: TX poll pending */ uint16_t lo_panid; /* Fake PAN ID for testing */ WDOG_ID lo_polldog; /* TX poll timer */ struct work_s lo_work; /* For deferring poll work to the work queue */ @@ -148,7 +148,7 @@ static int lo_get_mhrlen(FAR struct ieee802154_driver_s *netdev, FAR const struct ieee802154_frame_meta_s *meta); static int lo_req_data(FAR struct ieee802154_driver_s *netdev, FAR const struct ieee802154_frame_meta_s *meta, - FAR struct iob_s *frames); + FAR struct iob_s *framelist); /**************************************************************************** * Private Functions @@ -180,13 +180,15 @@ static int lo_loopback(FAR struct net_driver_s *dev) FAR struct iob_s *iob; int ret; - /* Loop while there frames to be sent, i.e., while the freme list is not + /* Loop while there framelist to be sent, i.e., while the freme list is not * emtpy. Sending, of course, just means relaying back through the network * for this driver. */ while (priv->lo_head != NULL) { + ninfo("Looping frame IOB %p\n", iob); + /* Increment statistics */ NETDEV_RXPACKETS(&priv->lo_ieee.i_dev); @@ -230,7 +232,7 @@ static int lo_loopback(FAR struct net_driver_s *dev) * Name: lo_loopback_work * * Description: - * Perform loopback of received frames. + * Perform loopback of received framelist. * * Parameters: * arg - The argument passed when work_queue() as called. @@ -278,19 +280,8 @@ static void lo_poll_work(FAR void *arg) /* Perform the poll */ net_lock(); - priv->lo_txdone = false; (void)devif_timer(&priv->lo_ieee.i_dev, lo_loopback); - /* Was something received and looped back? */ - - while (priv->lo_txdone) - { - /* Yes, poll again for more TX data */ - - priv->lo_txdone = false; - (void)devif_poll(&priv->lo_ieee.i_dev, lo_loopback); - } - /* Setup the watchdog poll timer again */ (void)wd_start(priv->lo_polldog, LO_WDDELAY, lo_poll_expiry, 1, priv); @@ -319,14 +310,18 @@ static void lo_poll_expiry(int argc, wdparm_t arg, ...) { FAR struct lo_driver_s *priv = (FAR struct lo_driver_s *)arg; - if (!work_available(&priv->lo_work)) + if (!work_available(&priv->lo_work) || priv->lo_head != NULL) { nwarn("WARNING: lo_work NOT available\n"); + priv->lo_pending = true; } + else + { + /* Schedule to perform the interrupt processing on the worker thread. */ - /* Schedule to perform the interrupt processing on the worker thread. */ - - work_queue(LPBKWORK, &priv->lo_work, lo_poll_work, priv, 0); + priv->lo_pending = false; + work_queue(LPBKWORK, &priv->lo_work, lo_poll_work, priv, 0); + } } /**************************************************************************** @@ -430,21 +425,16 @@ static void lo_txavail_work(FAR void *arg) { FAR struct lo_driver_s *priv = (FAR struct lo_driver_s *)arg; - ninfo("IP up: %u\n", priv->lo_bifup); + ninfo("TX available work. IP up: %u\n", priv->lo_bifup); /* Ignore the notification if the interface is not yet up */ net_lock(); if (priv->lo_bifup) { - do - { - /* If so, then poll the network for new XMIT data */ + /* If so, then poll the network for new XMIT data */ - priv->lo_txdone = false; - (void)devif_poll(&priv->lo_ieee.i_dev, lo_loopback); - } - while (priv->lo_txdone); + (void)devif_poll(&priv->lo_ieee.i_dev, lo_loopback); } net_unlock(); @@ -480,10 +470,16 @@ static int lo_txavail(FAR struct net_driver_s *dev) * action. */ - if (work_available(&priv->lo_work)) + if (!work_available(&priv->lo_work) || priv->lo_head != NULL) { - /* Schedule to serialize the poll on the worker thread. */ + nwarn("WARNING: lo_work NOT available\n"); + priv->lo_pending = true; + } + else + { + /* Schedule to perform the interrupt processing on the worker thread. */ + priv->lo_pending = false; work_queue(LPBKWORK, &priv->lo_work, lo_txavail_work, priv, 0); } @@ -634,6 +630,14 @@ static int lo_ioctl(FAR struct net_driver_s *dev, int cmd, * Description: * Calculate the MAC header length given the frame meta-data. * + * Input parameters: + * netdev - The networkd device that will mediate the MAC interface + * meta - Meta data needed to recreate the MAC header + * + * Returned Value: + * A non-negative MAC headeer length is returned on success; a negated + * errno value is returned on any failure. + * ****************************************************************************/ static int lo_get_mhrlen(FAR struct ieee802154_driver_s *netdev, @@ -646,27 +650,33 @@ static int lo_get_mhrlen(FAR struct ieee802154_driver_s *netdev, * Name: lo_req_data * * Description: - * The MCPS-DATA.request primitive requests the transfer of a data SPDU - * (i.e., MSDU) from a local SSCS entity to a single peer SSCS entity. - * Confirmation is returned via the - * struct ieee802154_maccb_s->conf_data callback. + * Requests the transfer of a list of frames to the MAC. + * + * Input parameters: + * netdev - The networkd device that will mediate the MAC interface + * meta - Meta data needed to recreate the MAC header + * framelist - Head of a list of frames to be transferred. + * + * Returned Value: + * Zero (OK) returned on success; a negated errno value is returned on + * any failure. * ****************************************************************************/ static int lo_req_data(FAR struct ieee802154_driver_s *netdev, FAR const struct ieee802154_frame_meta_s *meta, - FAR struct iob_s *frames) + FAR struct iob_s *framelist) { FAR struct lo_driver_s *priv; FAR struct iob_s *iob; DEBUGASSERT(netdev != NULL && netdev->i_dev.d_private != NULL && - frames != NULL); + framelist != NULL); priv = (FAR struct lo_driver_s *)netdev->i_dev.d_private; - /* Add the incoming list of frames to queue of frames to loopback */ + /* Add the incoming list of framelist to queue of framelist to loopback */ - for (iob = frames; iob != NULL; iob = frames) + for (iob = framelist; iob != NULL; iob = framelist) { /* Increment statistics */ @@ -674,15 +684,17 @@ static int lo_req_data(FAR struct ieee802154_driver_s *netdev, /* Remove the IOB from the queue */ - frames = iob->io_flink; + framelist = iob->io_flink; iob->io_flink = NULL; + ninfo("Queuing frame IOB %p\n", iob); + /* Just zero the MAC header for test purposes */ DEBUGASSERT(iob->io_offset == MAC_HDRLEN); memset(iob->io_data, 0, MAC_HDRLEN); - /* Add the IOB to the tail of the queue of frames to be looped back */ + /* Add the IOB to the tail of the queue of framelist to be looped back */ if (priv->lo_tail == NULL) { @@ -696,18 +708,9 @@ static int lo_req_data(FAR struct ieee802154_driver_s *netdev, priv->lo_tail = iob; } - /* Is our single work structure available? It may not be if there are - * pending actions and we will have to ignore the Tx availability - * action. - */ - - if (work_available(&priv->lo_work)) - { - /* Schedule to serialize the poll on the worker thread. */ - - work_queue(LPBKWORK, &priv->lo_work, lo_loopback_work, priv, 0); - } + /* Schedule to serialize the poll on the worker thread. */ + work_queue(LPBKWORK, &priv->lo_work, lo_loopback_work, priv, 0); return OK; } @@ -771,7 +774,7 @@ int ieee8021514_loopback(void) priv->lo_polldog = wd_create(); /* Create periodic poll timer */ - /* Register the loopabck device with the OS so that socket IOCTLs can b + /* Register the loopabck device with the OS so that socket IOCTLs can be * performed. */ diff --git a/wireless/ieee802154/mac802154_netdev.c b/wireless/ieee802154/mac802154_netdev.c index a5816205e4d..b81ad465bc0 100644 --- a/wireless/ieee802154/mac802154_netdev.c +++ b/wireless/ieee802154/mac802154_netdev.c @@ -251,7 +251,7 @@ static int macnet_get_mhrlen(FAR struct ieee802154_driver_s *netdev, FAR const struct ieee802154_frame_meta_s *meta); static int macnet_req_data(FAR struct ieee802154_driver_s *netdev, FAR const struct ieee802154_frame_meta_s *meta, - FAR struct iob_s *frames); + FAR struct iob_s *framelist); /**************************************************************************** * Private Functions @@ -1412,6 +1412,14 @@ static int macnet_ioctl(FAR struct net_driver_s *dev, int cmd, * Description: * Calculate the MAC header length given the frame meta-data. * + * Input parameters: + * netdev - The networkd device that will mediate the MAC interface + * meta - Meta data needed to recreate the MAC header + * + * Returned Value: + * A non-negative MAC headeer length is returned on success; a negated + * errno value is returned on any failure. + * ****************************************************************************/ static int macnet_get_mhrlen(FAR struct ieee802154_driver_s *netdev, @@ -1429,16 +1437,22 @@ static int macnet_get_mhrlen(FAR struct ieee802154_driver_s *netdev, * Name: macnet_req_data * * Description: - * The MCPS-DATA.request primitive requests the transfer of a data SPDU - * (i.e., MSDU) from a local SSCS entity to a single peer SSCS entity. - * Confirmation is returned via the - * struct ieee802154_maccb_s->conf_data callback. + * Requests the transfer of a list of frames to the MAC. + * + * Input parameters: + * netdev - The networkd device that will mediate the MAC interface + * meta - Meta data needed to recreate the MAC header + * framelist - Head of a list of frames to be transferred. + * + * Returned Value: + * Zero (OK) returned on success; a negated errno value is returned on + * any failure. * ****************************************************************************/ static int macnet_req_data(FAR struct ieee802154_driver_s *netdev, FAR const struct ieee802154_frame_meta_s *meta, - FAR struct iob_s *frames) + FAR struct iob_s *framelist) { FAR struct macnet_driver_s *priv; struct ieee802154_data_req_s req; @@ -1450,7 +1464,7 @@ static int macnet_req_data(FAR struct ieee802154_driver_s *netdev, /* Add the incoming list of frames to the MAC's outgoing queue */ - for (iob = frames; iob != NULL; iob = frames) + for (iob = framelist; iob != NULL; iob = framelist) { /* Increment statistics */ @@ -1458,7 +1472,7 @@ static int macnet_req_data(FAR struct ieee802154_driver_s *netdev, /* Remove the IOB from the queue */ - frames = iob->io_flink; + framelist = iob->io_flink; iob->io_flink = NULL; /* Transfer the frame to the MAC */ @@ -1471,11 +1485,11 @@ static int macnet_req_data(FAR struct ieee802154_driver_s *netdev, wlerr("ERROR: mac802154_req_data failed: %d\n", ret); iob_free(iob); - for (iob = frames; ; iob != NULL; iob = frames) + for (iob = framelist; ; iob != NULL; iob = framelist) { /* Remove the IOB from the queue and free */ - frames = iob->io_flink; + framelist = iob->io_flink; iob_free(iob); } From ba32b6581392439701b6341b0ddf4332b8374ced Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Wed, 3 May 2017 13:26:06 -0400 Subject: [PATCH 124/183] wireless/ieee802154: Simplifies some primitive prototypes --- .../wireless/ieee802154/ieee802154_ioctl.h | 4 +- .../wireless/ieee802154/ieee802154_mac.h | 86 ++----------- wireless/ieee802154/mac802154.c | 114 +++++++++++------- wireless/ieee802154/mac802154.h | 66 +++++++--- wireless/ieee802154/mac802154_device.c | 14 +-- 5 files changed, 135 insertions(+), 149 deletions(-) diff --git a/include/nuttx/wireless/ieee802154/ieee802154_ioctl.h b/include/nuttx/wireless/ieee802154/ieee802154_ioctl.h index 019fedd55a7..cd5550057c9 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_ioctl.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_ioctl.h @@ -48,6 +48,8 @@ #include #include +#include + #ifdef CONFIG_WIRELESS_IEEE802154 /************************************************************************************ @@ -74,7 +76,7 @@ struct mac802154dev_notify_s struct mac802154dev_txframe_s { - FAR struct ieee802154_frame_meta_s *meta; + struct ieee802154_frame_meta_s meta; FAR uint8_t *payload; }; diff --git a/include/nuttx/wireless/ieee802154/ieee802154_mac.h b/include/nuttx/wireless/ieee802154/ieee802154_mac.h index f91fbbceae4..5b6ba898adc 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_mac.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_mac.h @@ -462,17 +462,17 @@ union ieee802154_attr_val_u uint8_t coord_eaddr[8]; uint16_t coord_saddr; - uint8_t is_assoc : 1; - uint8_t assoc_permit : 1; - uint8_t auto_req : 1; - uint8_t batt_life_ext : 1; - uint8_t gts_permit : 1; - uint8_t promisc_mode : 1; - uint8_t rng_support : 1; - uint8_t resp_wait_time; - uint8_t rx_when_idle : 1; - uint8_t sec_enabled : 1; - uint8_t timestamp_support : 1; + bool is_assoc; + bool assoc_permit; + bool auto_req; + bool batt_life_ext; + bool gts_permit; + bool promisc_mode; + bool rng_support; + bool resp_wait_time; + bool rx_when_idle; + bool sec_enabled; + bool timestamp_support; uint32_t ack_wait_dur; uint8_t batt_life_ext_periods; @@ -567,20 +567,6 @@ struct ieee802154_frame_meta_s /* Primitive Semantics *******************************************************/ -/***************************************************************************** - * Primitive: MCPS-DATA.request - * - * Description: - * Requests the transfer of data to another device. - * - *****************************************************************************/ - -struct ieee802154_data_req_s -{ - FAR const struct ieee802154_frame_meta_s *meta; /* Metadata describing the req */ - FAR struct iob_s *frame; /* Frame IOB with payload */ -}; - /***************************************************************************** * Primitive: MCPS-DATA.confirm * @@ -658,21 +644,6 @@ struct ieee802154_purge_req_s uint8_t msdu_handle; /* Handle assoc. with MSDU */ }; -/***************************************************************************** - * Primitive: MCPS-PURGE.confirm - * - * Description: - * Allows the MAC sublayer to notify the next higher layer of the success of - * its request to purge an MSDU from the transaction queue. - * - *****************************************************************************/ - -struct ieee802154_purge_conf_s -{ - uint8_t msdu_handle; /* Handle assoc. with MSDU */ - enum ieee802154_status_e status; /* The status of the MSDU transmission */ -}; - /***************************************************************************** * Primitive: MLME-ASSOCIATE.request * @@ -921,21 +892,7 @@ struct ieee802154_commstatus_ind_s struct ieee802154_get_req_s { enum ieee802154_pib_attr_e pib_attr; -}; - -/***************************************************************************** - * Primitive: MLME-GET.confirm - * - * Description: - * Reports the results of an information request from the PIB. - * - *****************************************************************************/ - -struct ieee802154_get_conf_s -{ - enum ieee802154_status_e status; - enum ieee802154_pib_attr_e pib_attr; - union ieee802154_attr_val_u attr_value; + FAR union ieee802154_attr_val_u *attr_value; }; /***************************************************************************** @@ -1049,19 +1006,6 @@ struct ieee802154_reset_req_s bool rst_pibattr; }; -/***************************************************************************** - * Primitive: MLME-RESET.confirm - * - * Description: - * Reports the results of the reset operation. - * - *****************************************************************************/ - -struct ieee802154_reset_conf_s -{ - enum ieee802154_status_e status; -}; - /***************************************************************************** * Primitive: MLME-RXENABLE.request * @@ -1287,9 +1231,7 @@ union ieee802154_mlme_notify_u { struct ieee802154_assoc_conf_s assocconf; struct ieee802154_disassoc_conf_s disassocconf; - struct ieee802154_get_conf_s getconf; struct ieee802154_gts_conf_s gtsconf; - struct ieee802154_reset_conf_s resetconf; struct ieee802154_rxenable_conf_s rxenableconf; struct ieee802154_scan_conf_s scanconf; struct ieee802154_start_conf_s startconf; @@ -1307,7 +1249,6 @@ union ieee802154_mlme_notify_u union ieee802154_mcps_notify_u { struct ieee802154_data_conf_s dataconf; - struct ieee802154_purge_conf_s purgeconf; struct ieee802154_data_ind_s dataind; }; @@ -1362,19 +1303,16 @@ enum ieee802154_macnotify_e /* MCPS Notifications */ IEEE802154_NOTIFY_CONF_DATA = 0x00, - IEEE802154_NOTIFY_CONF_PURGE, IEEE802154_NOTIFY_IND_DATA, /* MLME Notifications */ IEEE802154_NOTIFY_CONF_ASSOC, IEEE802154_NOTIFY_CONF_DISASSOC, - IEEE802154_NOTIFY_CONF_GET, IEEE802154_NOTIFY_CONF_GTS, IEEE802154_NOTIFY_CONF_RESET, IEEE802154_NOTIFY_CONF_RXENABLE, IEEE802154_NOTIFY_CONF_SCAN, - IEEE802154_NOTIFY_CONF_SET, IEEE802154_NOTIFY_CONF_START, IEEE802154_NOTIFY_CONF_POLL, diff --git a/wireless/ieee802154/mac802154.c b/wireless/ieee802154/mac802154.c index 3f42d006c83..2b373a51da0 100644 --- a/wireless/ieee802154/mac802154.c +++ b/wireless/ieee802154/mac802154.c @@ -890,7 +890,8 @@ int mac802154_ioctl(MACHANDLE mac, int cmd, unsigned long arg) break; case MAC802154IOC_MLME_GET_REQUEST: { - mac802154_req_get(mac, &macarg->getreq); + mac802154_req_get(mac, macarg->getreq.pib_attr, + macarg->getreq.attr_value); } break; case MAC802154IOC_MLME_GTS_REQUEST: @@ -905,7 +906,7 @@ int mac802154_ioctl(MACHANDLE mac, int cmd, unsigned long arg) break; case MAC802154IOC_MLME_RESET_REQUEST: { - mac802154_req_reset(mac, &macarg->resetreq); + mac802154_req_reset(mac, macarg->resetreq.rst_pibattr); } break; case MAC802154IOC_MLME_RXENABLE_REQUEST: @@ -1046,26 +1047,27 @@ int mac802154_get_mhrlen(MACHANDLE mac, * ****************************************************************************/ -int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) +int mac802154_req_data(MACHANDLE mac, + FAR const struct ieee802154_frame_meta_s *meta, + FAR struct iob_s *frame) { FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; FAR struct mac802154_trans_s trans; - FAR const struct ieee802154_frame_meta_s *meta = req->meta; uint16_t *frame_ctrl; uint8_t mhr_len = 3; /* Start assuming frame control and seq. num */ int ret; /* Check the required frame size */ - if (req->frame->io_len > IEEE802154_MAX_PHY_PACKET_SIZE) + if (frame->io_len > IEEE802154_MAX_PHY_PACKET_SIZE) { return -E2BIG; } /* Cast the first two bytes of the IOB to a uint16_t frame control field */ - frame_ctrl = (uint16_t *)&req->frame->io_data[0]; + frame_ctrl = (uint16_t *)&frame->io_data[0]; /* Ensure we start with a clear frame control field */ @@ -1097,17 +1099,17 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) if (meta->dest_addr.mode != IEEE802154_ADDRMODE_NONE) { - memcpy(&req->frame->io_data[mhr_len], &meta->dest_addr.panid, 2); + memcpy(&frame->io_data[mhr_len], &meta->dest_addr.panid, 2); mhr_len += 2; if (meta->dest_addr.mode == IEEE802154_ADDRMODE_SHORT) { - memcpy(&req->frame->io_data[mhr_len], &meta->dest_addr.saddr, 2); + memcpy(&frame->io_data[mhr_len], &meta->dest_addr.saddr, 2); mhr_len += 2; } else if (meta->dest_addr.mode == IEEE802154_ADDRMODE_EXTENDED) { - memcpy(&req->frame->io_data[mhr_len], &meta->dest_addr.eaddr, 8); + memcpy(&frame->io_data[mhr_len], &meta->dest_addr.eaddr, 8); mhr_len += 8; } } @@ -1153,18 +1155,18 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) if ((meta->dest_addr.mode == IEEE802154_ADDRMODE_NONE) || (*frame_ctrl & IEEE802154_FRAMECTRL_PANIDCOMP)) { - memcpy(&req->frame->io_data[mhr_len], &priv->addr.panid, 2); + memcpy(&frame->io_data[mhr_len], &priv->addr.panid, 2); mhr_len += 2; } if (meta->src_addr_mode == IEEE802154_ADDRMODE_SHORT) { - memcpy(&req->frame->io_data[mhr_len], &priv->addr.saddr, 2); + memcpy(&frame->io_data[mhr_len], &priv->addr.saddr, 2); mhr_len += 2; } else if (meta->src_addr_mode == IEEE802154_ADDRMODE_EXTENDED) { - memcpy(&req->frame->io_data[mhr_len], &priv->addr.eaddr, 8); + memcpy(&frame->io_data[mhr_len], &priv->addr.eaddr, 8); mhr_len += 8; } } @@ -1178,7 +1180,7 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) * of the outgoing frame and then increment it by one. [1] pg. 40. */ - req->frame->io_data[2] = priv->dsn++; + frame->io_data[2] = priv->dsn++; /* The MAC header we just created must never have exceeded where the app * data starts. This should never happen since the offset should have @@ -1186,14 +1188,14 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) * here that created the header */ - DEBUGASSERT(mhr_len == req->frame->io_offset); + DEBUGASSERT(mhr_len == frame->io_offset); - req->frame->io_offset = 0; /* Set the offset to 0 to include the header */ + frame->io_offset = 0; /* Set the offset to 0 to include the header */ /* Setup our transaction */ trans.msdu_handle = meta->msdu_handle; - trans.frame = req->frame; + trans.frame = frame; sem_init(&trans.sem, 0, 1); /* If the TxOptions parameter specifies that a GTS transmission is required, @@ -1234,6 +1236,9 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) * coordinator, the destination address is not present, or the * TxOptions parameter also specifies a GTS transmission, the indirect * transmission option will be ignored. [1] + * + * NOTE: We don't just ignore the parameter. Instead, we throw an + * error, since this really shouldn't be happening. */ if (priv->is_coord && meta->dest_addr.mode != IEEE802154_ADDRMODE_NONE) @@ -1243,15 +1248,10 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) } else { - /* Override the setting since it wasn't valid */ - - meta->msdu_flags.indirect_tx = 0; + return -EINVAL; } } - - /* If this is a direct transmission not during a GTS */ - - if (!meta->msdu_flags.indirect_tx) + else { /* Link the transaction into the CSMA transaction list */ @@ -1281,9 +1281,15 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req) * an MSDU from the transaction queue. Confirmation is returned via * the struct ieee802154_maccb_s->conf_purge callback. * + * NOTE: The standard specifies that confirmation should be indicated via + * the asynchronous MLME-PURGE.confirm primitve. However, in our + * implementation we synchronously return the status from the request. + * Therefore, we merge the functionality of the MLME-PURGE.request and + * MLME-PURGE.confirm primitives together. + * ****************************************************************************/ -int mac802154_req_purge(MACHANDLE mac, FAR struct ieee802154_purge_req_s *req) +int mac802154_req_purge(MACHANDLE mac, uint8_t msdu_handle) { FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; @@ -1352,22 +1358,6 @@ int mac802154_req_disassociate(MACHANDLE mac, return -ENOTTY; } -/**************************************************************************** - * Name: mac802154_req_get - * - * Description: - * The MLME-GET.request primitive requests information about a given PIB - * attribute. Actual data is returned via the - * struct ieee802154_maccb_s->conf_get callback. - * - ****************************************************************************/ - -int mac802154_req_get(MACHANDLE mac, FAR struct ieee802154_get_req_s *req) -{ - FAR struct ieee802154_privmac_s *priv = - (FAR struct ieee802154_privmac_s *)mac; - return -ENOTTY; -} /**************************************************************************** * Name: mac802154_req_gts @@ -1392,12 +1382,21 @@ int mac802154_req_gts(MACHANDLE mac, FAR struct ieee802154_gts_req_s *req) * * Description: * The MLME-RESET.request primitive allows the next higher layer to request - * that the MLME performs a reset operation. Confirmation is returned via - * the struct ieee802154_maccb_s->conf_reset callback. + * that the MLME performs a reset operation. + * + * NOTE: The standard specifies that confirmation should be provided via + * via the asynchronous MLME-RESET.confirm primitve. However, in our + * implementation we synchronously return the value immediately. Therefore, + * we merge the functionality of the MLME-RESET.request and MLME-RESET.confirm + * primitives together. + * + * Input Parameters: + * mac - Handle to the MAC layer instance + * rst_pibattr - Whether or not to reset the MAC PIB attributes to defaults * ****************************************************************************/ -int mac802154_req_reset(MACHANDLE mac, FAR struct ieee802154_reset_req_s *req) +int mac802154_req_reset(MACHANDLE mac, bool rst_pibattr) { FAR struct ieee802154_privmac_s * priv = (FAR struct ieee802154_privmac_s *) mac; @@ -1445,6 +1444,29 @@ int mac802154_req_scan(MACHANDLE mac, FAR struct ieee802154_scan_req_s *req) return -ENOTTY; } +/**************************************************************************** + * Name: mac802154_req_get + * + * Description: + * The MLME-GET.request primitive requests information about a given PIB + * attribute. + * + * NOTE: The standard specifies that the attribute value should be returned + * via the asynchronous MLME-GET.confirm primitve. However, in our + * implementation, we synchronously return the value immediately.Therefore, we + * merge the functionality of the MLME-GET.request and MLME-GET.confirm + * primitives together. + * + ****************************************************************************/ + +int mac802154_req_get(MACHANDLE mac, enum ieee802154_pib_attr_e pib_attr, + FAR union ieee802154_attr_val_u *attr_value) +{ + FAR struct ieee802154_privmac_s *priv = + (FAR struct ieee802154_privmac_s *)mac; + return -ENOTTY; +} + /**************************************************************************** * Name: mac802154_req_set * @@ -1454,9 +1476,9 @@ int mac802154_req_scan(MACHANDLE mac, FAR struct ieee802154_scan_req_s *req) * * NOTE: The standard specifies that confirmation should be indicated via * the asynchronous MLME-SET.confirm primitve. However, in our implementation - * there is no reason not to synchronously return the status immediately. - * Therefore, we do merge the functionality of the MLME-SET.request and - * MLME-SET.confirm primitives together. + * we synchronously return the status from the request. Therefore, we do merge + * the functionality of the MLME-SET.request and MLME-SET.confirm primitives + * together. * ****************************************************************************/ diff --git a/wireless/ieee802154/mac802154.h b/wireless/ieee802154/mac802154.h index 17df17ebda1..883d0180ee9 100644 --- a/wireless/ieee802154/mac802154.h +++ b/wireless/ieee802154/mac802154.h @@ -119,7 +119,9 @@ int mac802154_get_mhrlen(MACHANDLE mac, * ****************************************************************************/ -int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req); +int mac802154_req_data(MACHANDLE mac, + FAR const struct ieee802154_frame_meta_s *meta, + FAR struct iob_s *frame); /**************************************************************************** * Name: mac802154_req_purge @@ -129,9 +131,15 @@ int mac802154_req_data(MACHANDLE mac, FAR struct ieee802154_data_req_s *req); * an MSDU from the transaction queue. Confirmation is returned via * the struct ieee802154_maccb_s->conf_purge callback. * + * NOTE: The standard specifies that confirmation should be indicated via + * the asynchronous MLME-PURGE.confirm primitve. However, in our + * implementation we synchronously return the status from the request. + * Therefore, we merge the functionality of the MLME-PURGE.request and + * MLME-PURGE.confirm primitives together. + * ****************************************************************************/ -int mac802154_req_purge(MACHANDLE mac, FAR struct ieee802154_purge_req_s *req); +int mac802154_req_purge(MACHANDLE mac, uint8_t msdu_handle); /**************************************************************************** * Name: mac802154_req_associate @@ -163,18 +171,6 @@ int mac802154_req_associate(MACHANDLE mac, int mac802154_req_disassociate(MACHANDLE mac, FAR struct ieee802154_disassoc_req_s *req); -/**************************************************************************** - * Name: mac802154_req_get - * - * Description: - * The MLME-GET.request primitive requests information about a given PIB - * attribute. Actual data is returned via the - * struct ieee802154_maccb_s->conf_get callback. - * - ****************************************************************************/ - -int mac802154_req_get(MACHANDLE mac, FAR struct ieee802154_get_req_s *req); - /**************************************************************************** * Name: mac802154_req_gts * @@ -193,12 +189,21 @@ int mac802154_req_gts(MACHANDLE mac, FAR struct ieee802154_gts_req_s *req); * * Description: * The MLME-RESET.request primitive allows the next higher layer to request - * that the MLME performs a reset operation. Confirmation is returned via - * the struct ieee802154_maccb_s->conf_reset callback. + * that the MLME performs a reset operation. + * + * NOTE: The standard specifies that confirmation should be provided via + * via the asynchronous MLME-RESET.confirm primitve. However, in our + * implementation we synchronously return the value immediately. Therefore, + * we merge the functionality of the MLME-RESET.request and MLME-RESET.confirm + * primitives together. + * + * Input Parameters: + * mac - Handle to the MAC layer instance + * rst_pibattr - Whether or not to reset the MAC PIB attributes to defaults * ****************************************************************************/ -int mac802154_req_reset(MACHANDLE mac, FAR struct ieee802154_reset_req_s *req); +int mac802154_req_reset(MACHANDLE mac, bool rst_pibattr); /**************************************************************************** * Name: mac802154_req_rxenable @@ -231,13 +236,36 @@ int mac802154_req_rxenable(MACHANDLE mac, int mac802154_req_scan(MACHANDLE mac, FAR struct ieee802154_scan_req_s *req); +/**************************************************************************** + * Name: mac802154_req_get + * + * Description: + * The MLME-GET.request primitive requests information about a given PIB + * attribute. + * + * NOTE: The standard specifies that the attribute value should be returned + * via the asynchronous MLME-GET.confirm primitve. However, in our + * implementation, we synchronously return the value immediately.Therefore, we + * merge the functionality of the MLME-GET.request and MLME-GET.confirm + * primitives together. + * + ****************************************************************************/ + +int mac802154_req_get(MACHANDLE mac, enum ieee802154_pib_attr_e pib_attr, + FAR union ieee802154_attr_val_u *attr_value); + /**************************************************************************** * Name: mac802154_req_set * * Description: * The MLME-SET.request primitive attempts to write the given value to the - * indicated MAC PIB attribute. Confirmation is returned via the - * struct ieee802154_maccb_s->conf_set callback. + * indicated MAC PIB attribute. + * + * NOTE: The standard specifies that confirmation should be indicated via + * the asynchronous MLME-SET.confirm primitve. However, in our implementation + * we synchronously return the status from the request. Therefore, we do merge + * the functionality of the MLME-SET.request and MLME-SET.confirm primitives + * together. * ****************************************************************************/ diff --git a/wireless/ieee802154/mac802154_device.c b/wireless/ieee802154/mac802154_device.c index 7f76e8cd3d9..d78e7acfdc1 100644 --- a/wireless/ieee802154/mac802154_device.c +++ b/wireless/ieee802154/mac802154_device.c @@ -406,7 +406,6 @@ static ssize_t mac802154dev_write(FAR struct file *filep, FAR struct mac802154_chardevice_s *dev; FAR struct mac802154dev_txframe_s *tx; FAR struct iob_s *iob; - struct ieee802154_data_req_s req; struct mac802154dev_dwait_s dwait; int ret; @@ -440,7 +439,7 @@ static ssize_t mac802154dev_write(FAR struct file *filep, /* Get the MAC header length */ - ret = mac802154_get_mhrlen(dev->md_mac, tx->meta); + ret = mac802154_get_mhrlen(dev->md_mac, &tx->meta); if (ret < 0) { wlerr("ERROR: TX meta-data is invalid"); @@ -450,9 +449,9 @@ static ssize_t mac802154dev_write(FAR struct file *filep, iob->io_offset = ret; iob->io_len = iob->io_offset; - memcpy(&iob->io_data[iob->io_offset], tx->payload, tx->meta->msdu_length); + memcpy(&iob->io_data[iob->io_offset], tx->payload, tx->meta.msdu_length); - iob->io_len += tx->meta->msdu_length; + iob->io_len += tx->meta.msdu_length; /* If this is a blocking operation, we need to setup a wait struct so we * can unblock when the packet transmission has finished. If this is a @@ -473,7 +472,7 @@ static ssize_t mac802154dev_write(FAR struct file *filep, /* Setup the wait struct */ - dwait.mw_handle = tx->meta->msdu_handle; + dwait.mw_handle = tx->meta.msdu_handle; /* Link the wait struct */ @@ -486,12 +485,9 @@ static ssize_t mac802154dev_write(FAR struct file *filep, mac802154dev_givesem(&dev->md_exclsem); } - req.meta = tx->meta; - req.frame = iob; - /* Pass the request to the MAC layer */ - ret = mac802154_req_data(dev->md_mac, &req); + ret = mac802154_req_data(dev->md_mac, &tx->meta, iob); if (ret < 0) { From dd1b9dfa81c30e0011f3e7419a9227c96dedc316 Mon Sep 17 00:00:00 2001 From: Juha Niskanen Date: Tue, 2 May 2017 15:14:45 +0300 Subject: [PATCH 125/183] STM32L4: modularize Kconfig to support different product lines/families This is modeled after STM32F7. Idea is to declare each chip in Kconfig but allow for flash size override. Commit adds many STM32L4_HAVE_XXX feature test macros. --- arch/arm/src/stm32l4/Kconfig | 555 ++++++++++++++++++++++--- arch/arm/src/stm32l4/stm32l4x6xx_rcc.c | 9 +- configs/nucleo-l496zg/nsh/defconfig | 27 +- 3 files changed, 513 insertions(+), 78 deletions(-) diff --git a/arch/arm/src/stm32l4/Kconfig b/arch/arm/src/stm32l4/Kconfig index 28be165f448..74b3f9ae700 100644 --- a/arch/arm/src/stm32l4/Kconfig +++ b/arch/arm/src/stm32l4/Kconfig @@ -12,57 +12,218 @@ choice default ARCH_CHIP_STM32L476RG depends on ARCH_CHIP_STM32L4 +config ARCH_CHIP_STM32L432KB + bool "STM32L432KB" + select STM32L4_STM32L432XX + select STM32L4_FLASH_CONFIG_B + select STM32L4_IO_CONFIG_K + ---help--- + STM32 L4 Cortex M4, 128 Kb FLASH, 64 Kb SRAM + +config ARCH_CHIP_STM32L432KC + bool "STM32L432KC" + select STM32L4_STM32L432XX + select STM32L4_FLASH_CONFIG_C + select STM32L4_IO_CONFIG_K + ---help--- + STM32 L4 Cortex M4, 256 Kb FLASH, 64 Kb SRAM + +config ARCH_CHIP_STM32L442KC + bool "STM32L442KC" + select STM32L4_STM32L442XX + select STM32L4_FLASH_CONFIG_C + select STM32L4_IO_CONFIG_K + ---help--- + STM32 L4 Cortex M4, AES, 256 Kb FLASH, 64 Kb SRAM + +config ARCH_CHIP_STM32L451CC + bool "STM32L451CC" + select STM32L4_STM32L451XX + select STM32L4_FLASH_CONFIG_C + select STM32L4_IO_CONFIG_C + ---help--- + STM32 L4 Cortex M4, 256 Kb FLASH, 128+32 Kb SRAM + +config ARCH_CHIP_STM32L451CE + bool "STM32L451CE" + select STM32L4_STM32L451XX + select STM32L4_FLASH_CONFIG_E + select STM32L4_IO_CONFIG_C + ---help--- + STM32 L4 Cortex M4, 512 Kb FLASH, 128+32 Kb SRAM + +config ARCH_CHIP_STM32L451RC + bool "STM32L451RC" + select STM32L4_STM32L451XX + select STM32L4_FLASH_CONFIG_C + select STM32L4_IO_CONFIG_R + ---help--- + STM32 L4 Cortex M4, 256 Kb FLASH, 128+32 Kb SRAM + +config ARCH_CHIP_STM32L451RE + bool "STM32L451RE" + select STM32L4_STM32L451XX + select STM32L4_FLASH_CONFIG_E + select STM32L4_IO_CONFIG_R + ---help--- + STM32 L4 Cortex M4, 512 Kb FLASH, 128+32 Kb SRAM + +config ARCH_CHIP_STM32L451VC + bool "STM32L451VC" + select STM32L4_STM32L451XX + select STM32L4_FLASH_CONFIG_C + select STM32L4_IO_CONFIG_V + ---help--- + STM32 L4 Cortex M4, 256 Kb FLASH, 128+32 Kb SRAM + +config ARCH_CHIP_STM32L451VE + bool "STM32L451VE" + select STM32L4_STM32L451XX + select STM32L4_FLASH_CONFIG_E + select STM32L4_IO_CONFIG_V + ---help--- + STM32 L4 Cortex M4, 512 Kb FLASH, 128+32 Kb SRAM + +config ARCH_CHIP_STM32L452CC + bool "STM32L452CC" + select STM32L4_STM32L452XX + select STM32L4_FLASH_CONFIG_C + select STM32L4_IO_CONFIG_C + ---help--- + STM32 L4 Cortex M4, 256 Kb FLASH, 128+32 Kb SRAM + +config ARCH_CHIP_STM32L452CE + bool "STM32L452CE" + select STM32L4_STM32L452XX + select STM32L4_FLASH_CONFIG_E + select STM32L4_IO_CONFIG_C + ---help--- + STM32 L4 Cortex M4, 512 Kb FLASH, 128+32 Kb SRAM + +config ARCH_CHIP_STM32L452RC + bool "STM32L452RC" + select STM32L4_STM32L452XX + select STM32L4_FLASH_CONFIG_C + select STM32L4_IO_CONFIG_R + ---help--- + STM32 L4 Cortex M4, 256 Kb FLASH, 128+32 Kb SRAM + +config ARCH_CHIP_STM32L452RE + bool "STM32L452RE" + select STM32L4_STM32L452XX + select STM32L4_FLASH_CONFIG_E + select STM32L4_IO_CONFIG_R + ---help--- + STM32 L4 Cortex M4, 512 Kb FLASH, 128+32 Kb SRAM + +config ARCH_CHIP_STM32L452VC + bool "STM32L452VC" + select STM32L4_STM32L452XX + select STM32L4_FLASH_CONFIG_C + select STM32L4_IO_CONFIG_V + ---help--- + STM32 L4 Cortex M4, 256 Kb FLASH, 128+32 Kb SRAM + +config ARCH_CHIP_STM32L452VE + bool "STM32L452VE" + select STM32L4_STM32L452XX + select STM32L4_FLASH_CONFIG_E + select STM32L4_IO_CONFIG_V + ---help--- + STM32 L4 Cortex M4, 512 Kb FLASH, 128+32 Kb SRAM + +config ARCH_CHIP_STM32L462CE + bool "STM32L462CE" + select STM32L4_STM32L462XX + select STM32L4_FLASH_CONFIG_E + select STM32L4_IO_CONFIG_C + ---help--- + STM32 L4 Cortex M4, USB FS, AES, 512 Kb FLASH, 128+32 Kb SRAM + +config ARCH_CHIP_STM32L462RE + bool "STM32L462RE" + select STM32L4_STM32L462XX + select STM32L4_FLASH_CONFIG_E + select STM32L4_IO_CONFIG_R + ---help--- + STM32 L4 Cortex M4, USB FS, AES, 512 Kb FLASH, 128+32 Kb SRAM + +config ARCH_CHIP_STM32L462VE + bool "STM32L462VE" + select STM32L4_STM32L462XX + select STM32L4_FLASH_CONFIG_E + select STM32L4_IO_CONFIG_V + ---help--- + STM32 L4 Cortex M4, USB FS, AES, 512 Kb FLASH, 128+32 Kb SRAM + config ARCH_CHIP_STM32L476RG bool "STM32L476RG" select STM32L4_STM32L476XX - select STM32L4_FLASH_1024KB + select STM32L4_FLASH_CONFIG_G + select STM32L4_IO_CONFIG_R ---help--- STM32 L4 Cortex M4, 1024Kb FLASH, 96+32 Kb SRAM config ARCH_CHIP_STM32L476RE bool "STM32L476RE" select STM32L4_STM32L476XX - select STM32L4_FLASH_512KB + select STM32L4_FLASH_CONFIG_E + select STM32L4_IO_CONFIG_R ---help--- STM32 L4 Cortex M4, 512Kb FLASH, 96+32 Kb SRAM -config ARCH_CHIP_STM32L486 +config ARCH_CHIP_STM32L486 # REVISIT: expand for each chip bool "STM32L486xx" select STM32L4_STM32L486XX - select STM32L4_HAVE_AES + select STM32L4_FLASH_CONFIG_G ---help--- STM32 L4 Cortex M4, AES, 1024Kb FLASH, 96+32 Kb SRAM config ARCH_CHIP_STM32L496ZE bool "STM32L496ZE" select STM32L4_STM32L496XX - select STM32L4_FLASH_512KB + select STM32L4_FLASH_CONFIG_E + select STM32L4_IO_CONFIG_Z ---help--- STM32 L4 Cortex M4, 512Kb FLASH, 320 Kb SRAM config ARCH_CHIP_STM32L496ZG bool "STM32L496ZG" select STM32L4_STM32L496XX - select STM32L4_FLASH_1024KB + select STM32L4_FLASH_CONFIG_G + select STM32L4_IO_CONFIG_Z ---help--- STM32 L4 Cortex M4, 1024Kb FLASH, 320 Kb SRAM -config ARCH_CHIP_STM32L4A6 +config ARCH_CHIP_STM32L4A6 # REVISIT: expand for each chip bool "STM32L4A6xx" - select STM32L4_STM32L496XX # Close enough to L496 - select STM32L4_FLASH_1024KB - select STM32L4_HAVE_AES - select STM32L4_HAVE_HASH + select STM32L4_STM32L4A6XX + select STM32L4_FLASH_CONFIG_G ---help--- STM32 L4 Cortex M4, AES, HASH, 1024Kb FLASH, 320 Kb SRAM endchoice # STM32 L4 Chip Selection -# Chip families +# Chip product lines + +config STM32L4_STM32L4X1 + # Note: This is _not_ for L471xx as in RM0392 + bool + default n + select STM32L4_STM32L4X3 + +config STM32L4_STM32L4X2 + bool + default n + select STM32L4_STM32L4X3 config STM32L4_STM32L4X3 bool default n + select ARCH_HAVE_FPU + select ARCH_HAVE_DPFPU # REVISIT + select ARMV7M_HAVE_ITCM + select ARMV7M_HAVE_DTCM select STM32L4_HAVE_USART1 select STM32L4_HAVE_USART2 select STM32L4_HAVE_USART3 if !(STM32L4_L432XX || STM32L4_L442XX) @@ -78,64 +239,259 @@ config STM32L4_STM32L4X5 select STM32L4_HAVE_USART1 select STM32L4_HAVE_USART2 select STM32L4_HAVE_USART3 + select STM32L4_HAVE_UART4 + select STM32L4_HAVE_UART5 + select STM32L4_HAVE_ADC2 + select STM32L4_HAVE_ADC3 + select STM32L4_HAVE_DAC2 + select STM32L4_HAVE_FSMC + select STM32L4_HAVE_TIM3 + select STM32L4_HAVE_TIM4 + select STM32L4_HAVE_TIM5 + select STM32L4_HAVE_TIM7 + select STM32L4_HAVE_TIM8 + select STM32L4_HAVE_TIM17 select STM32L4_HAVE_LPTIM1 select STM32L4_HAVE_LPTIM2 select STM32L4_HAVE_COMP select STM32L4_HAVE_SAI1 select STM32L4_HAVE_SAI2 + select STM32L4_HAVE_SDMMC1 + select STM32L4_HAVE_OTGFS + select STM32L4_HAVE_DFSDM1 config STM32L4_STM32L4X6 bool default n + select ARCH_HAVE_FPU + select ARCH_HAVE_DPFPU # REVISIT + select ARMV7M_HAVE_ITCM + select ARMV7M_HAVE_DTCM select STM32L4_HAVE_USART1 select STM32L4_HAVE_USART2 select STM32L4_HAVE_USART3 select STM32L4_HAVE_UART4 select STM32L4_HAVE_UART5 + select STM32L4_HAVE_ADC2 + select STM32L4_HAVE_ADC3 + select STM32L4_HAVE_DAC2 + select STM32L4_HAVE_FSMC + select STM32L4_HAVE_TIM3 + select STM32L4_HAVE_TIM4 + select STM32L4_HAVE_TIM5 + select STM32L4_HAVE_TIM7 + select STM32L4_HAVE_TIM8 + select STM32L4_HAVE_TIM17 select STM32L4_HAVE_LPTIM1 select STM32L4_HAVE_LPTIM2 select STM32L4_HAVE_COMP select STM32L4_HAVE_SAI1 select STM32L4_HAVE_SAI2 + select STM32L4_HAVE_SDMMC1 + select STM32L4_HAVE_OTGFS + select STM32L4_HAVE_LCD + +# Chip subfamilies: + +config STM32L4_STM32L431XX + bool + default n + select STM32L4_STM32L4X1 + select STM32L4_HAVE_TIM7 + select STM32L4_HAVE_SDMMC1 if (STM32L4_IO_CONFIG_V || STM32L4_IO_CONFIG_R) + +config STM32L4_STM32L432XX + bool + default n + select STM32L4_STM32L4X2 + select STM32L4_HAVE_TIM7 + +config STM32L4_STM32L433XX + bool + default n + select STM32L4_STM32L4X3 + select STM32L4_HAVE_TIM7 + +config STM32L4_STM32L442XX + bool + default n + select STM32L4_STM32L4X2 + select STM32L4_HAVE_TIM7 + select STM32L4_HAVE_AES + +config STM32L4_STM32L443XX + bool + default n + select STM32L4_STM32L4X3 + select STM32L4_HAVE_TIM7 + select STM32L4_HAVE_SDMMC1 + select STM32L4_HAVE_AES + +config STM32L4_STM32L451XX + bool + default n + select STM32L4_STM32L4X1 + select STM32L4_HAVE_UART4 + select STM32L4_HAVE_TIM3 + select STM32L4_HAVE_I2C4 + select STM32L4_HAVE_SDMMC1 if !STM32L4_IO_CONFIG_C + select STM32L4_HAVE_DFSDM1 + +config STM32L4_STM32L452XX + bool + default n + select STM32L4_STM32L4X2 + select STM32L4_HAVE_UART4 + select STM32L4_HAVE_TIM3 + select STM32L4_HAVE_I2C4 + select STM32L4_HAVE_SDMMC1 + select STM32L4_HAVE_DFSDM1 + +config STM32L4_STM32L462XX + bool + default n + select STM32L4_STM32L4X2 + select STM32L4_HAVE_UART4 + select STM32L4_HAVE_TIM3 + select STM32L4_HAVE_I2C4 + select STM32L4_HAVE_SDMMC1 + select STM32L4_HAVE_DFSDM1 + select STM32L4_HAVE_AES + +config STM32L4_STM32L471XX + bool + default n + # TODO config STM32L4_STM32L476XX bool default n select STM32L4_STM32L4X6 - select ARCH_HAVE_FPU config STM32L4_STM32L486XX bool default n select STM32L4_STM32L4X6 - select ARCH_HAVE_FPU - select STM32L4_FLASH_1024KB + select STM32L4_HAVE_AES config STM32L4_STM32L496XX bool default n select STM32L4_STM32L4X6 - select ARCH_HAVE_FPU select STM32L4_HAVE_I2C4 select STM32L4_HAVE_CAN2 select STM32L4_HAVE_DCMI select STM32L4_HAVE_DMA2D + select STM32L4_HAVE_DFSDM1 + +config STM32L4_STM32L4A6XX + bool + default n + select STM32L4_STM32L496XX + select STM32L4_HAVE_AES + select STM32L4_HAVE_HASH choice - prompt "Embedded FLASH size" - default STM32L4_FLASH_1024KB + prompt "Override Flash Size Designator" + depends on ARCH_CHIP_STM32L4 + default STM32L4_FLASH_OVERRIDE_DEFAULT + ---help--- + STM32L4 series parts numbering (sans the package type) ends with a letter + that designates the FLASH size. -config STM32L4_FLASH_256KB - bool "256 KB" + Designator Size in KiB + B 128 + C 256 + E 512 + G 1024 + + This configuration option defaults to using the configuration based on that designator + or the default smaller size if there is no last character designator is present in the + STM32 Chip Selection. + + Examples: + If the STM32L476VE is chosen, the Flash configuration would be 'E', if a variant of + the part with a 1024 KiB Flash is released in the future one could simply select + the 'G' designator here. + + If an STM32L4xxx Series parts is chosen the default Flash configuration will be set + herein and can be changed. + +config STM32L4_FLASH_OVERRIDE_DEFAULT + bool "Default" + +config STM32L4_FLASH_OVERRIDE_B + bool "B 128 KB" + +config STM32L4_FLASH_OVERRIDE_C + bool "C 256 KB" + +config STM32L4_FLASH_OVERRIDE_E + bool "E 512 KB" + +config STM32L4_FLASH_OVERRIDE_G + bool "G 1024 KB" + +endchoice # "Override Flash Size Designator" + +# Flash configurations + +config STM32L4_FLASH_CONFIG_B + bool + default n + depends on STM32L4_STM32L4X1 || STM32L4_STM32L4X3 + +config STM32L4_FLASH_CONFIG_C + bool + default n depends on !STM32L4_STM32L496XX -config STM32L4_FLASH_512KB - bool "512 KB" +config STM32L4_FLASH_CONFIG_E + bool + default n -config STM32L4_FLASH_1024KB - bool "1024 KB" +config STM32L4_FLASH_CONFIG_G + bool + default n + depends on STM32L4_STM32L4X5 || STM32L4_STM32L4X6 -endchoice # Embedded FLASH size +# Pin/package configurations + +config STM32L4_IO_CONFIG_K + bool + default n + +config STM32L4_IO_CONFIG_C + bool + default n + +config STM32L4_IO_CONFIG_R + bool + default n + +config STM32L4_IO_CONFIG_J + bool + default n + +config STM32L4_IO_CONFIG_M + bool + default n + +config STM32L4_IO_CONFIG_V + bool + default n + +config STM32L4_IO_CONFIG_Q + bool + default n + +config STM32L4_IO_CONFIG_Z + bool + default n + +config STM32L4_IO_CONFIG_A + bool + default n comment "STM32L4 SRAM2 Options" @@ -172,6 +528,14 @@ menu "STM32L4 Peripheral Support" # These "hidden" settings determine is a peripheral option is available for the # selection MCU +config STM32L4_HAVE_ADC2 + bool + default n + +config STM32L4_HAVE_ADC3 + bool + default n + config STM32L4_HAVE_AES bool default n @@ -184,14 +548,26 @@ config STM32L4_HAVE_COMP bool default n +config STM32L4_HAVE_DAC2 + bool + default n + config STM32L4_HAVE_DCMI bool default n +config STM32L4_HAVE_DFSDM1 + bool + default n + config STM32L4_HAVE_DMA2D bool default n +config STM32L4_HAVE_FSMC + bool + default n + config STM32L4_HAVE_HASH bool default n @@ -200,6 +576,10 @@ config STM32L4_HAVE_I2C4 bool default n +config STM32L4_HAVE_LCD + bool + default n + config STM32L4_HAVE_LTDC bool default n @@ -212,6 +592,10 @@ config STM32L4_HAVE_LPTIM2 bool default n +config STM32L4_HAVE_OTGFS + bool + default n + config STM32L4_HAVE_SAI1 bool default n @@ -220,6 +604,34 @@ config STM32L4_HAVE_SAI2 bool default n +config STM32L4_HAVE_SDMMC1 + bool + default n + +config STM32L4_HAVE_TIM3 + bool + default n + +config STM32L4_HAVE_TIM4 + bool + default n + +config STM32L4_HAVE_TIM5 + bool + default n + +config STM32L4_HAVE_TIM7 + bool + default n + +config STM32L4_HAVE_TIM8 + bool + default n + +config STM32L4_HAVE_TIM17 + bool + default n + # These "hidden" settings are the OR of individual peripheral selections # indicating that the general capability is required. @@ -289,6 +701,7 @@ config STM32L4_OTGFS bool "OTG FS" default n select USBHOST_HAVE_ASYNCH if USBHOST + depends on STM32L4_HAVE_OTGFS config STM32L4_ADC1 bool "ADC1" @@ -299,11 +712,13 @@ config STM32L4_ADC2 bool "ADC2" default n select STM32L4_ADC + depends on STM32L4_HAVE_ADC2 config STM32L4_ADC3 bool "ADC3" default n select STM32L4_ADC + depends on STM32L4_HAVE_ADC3 config STM32L4_AES bool "AES" @@ -330,43 +745,12 @@ config STM32L4_RNG default n select ARCH_HAVE_RNG -config STM32L4_SAI1_A - bool "SAI1 Block A" - default n - select AUDIO - select I2S - select SCHED_WORKQUEUE - select STM32L4_SAI - -config STM32L4_SAI1_B - bool "SAI1 Block B" - default n - select AUDIO - select I2S - select SCHED_WORKQUEUE - select STM32L4_SAI - -config STM32L4_SAI2_A - bool "SAI2 Block A" - default n - select AUDIO - select I2S - select SCHED_WORKQUEUE - select STM32L4_SAI - -config STM32L4_SAI2_B - bool "SAI2 Block B" - default n - select AUDIO - select I2S - select SCHED_WORKQUEUE - select STM32L4_SAI - comment "AHB3 Peripherals" -config STM32L4_FMC - bool "FMC" +config STM32L4_FSMC + bool "FSMC" default n + depends on STM32L4_HAVE_FSMC config STM32L4_QSPI bool "QuadSPI" @@ -526,14 +910,17 @@ config STM32L4_TIM2 config STM32L4_TIM3 bool "TIM3" default n + depends on STM32L4_HAVE_TIM3 config STM32L4_TIM4 bool "TIM4" default n + depends on STM32L4_HAVE_TIM4 config STM32L4_TIM5 bool "TIM5" default n + depends on STM32L4_HAVE_TIM5 config STM32L4_TIM6 bool "TIM6" @@ -542,14 +929,17 @@ config STM32L4_TIM6 config STM32L4_TIM7 bool "TIM7" default n + depends on STM32L4_HAVE_TIM7 config STM32L4_LCD bool "LCD" default n + depends on STM32L4_HAVE_LCD config STM32L4_SPI2 bool "SPI2" default n + depends on !(STM32L4_L432XX || STM32L4_L442XX) select SPI select STM32L4_SPI @@ -607,6 +997,7 @@ config STM32L4_I2C1 config STM32L4_I2C2 bool "I2C2" default n + depends on !(STM32L4_L432XX || STM32L4_L442XX) select STM32L4_I2C config STM32L4_I2C3 @@ -642,6 +1033,7 @@ config STM32L4_DAC2 bool "DAC2" default n select STM32L4_DAC + depends on STM32L4_HAVE_DAC2 config STM32L4_OPAMP bool "OPAMP" @@ -684,6 +1076,7 @@ config STM32L4_SDMMC1 bool "SDMMC1" default n select ARCH_HAVE_SDIO + depends on STM32L4_HAVE_SDMMC1 config STM32L4_TIM1 bool "TIM1" @@ -698,6 +1091,7 @@ config STM32L4_SPI1 config STM32L4_TIM8 bool "TIM8" default n + depends on STM32L4_HAVE_TIM8 config STM32L4_USART1 bool "USART1" @@ -717,6 +1111,7 @@ config STM32L4_TIM16 config STM32L4_TIM17 bool "TIM17" default n + depends on STM32L4_HAVE_TIM17 config STM32L4_COMP bool "COMP" @@ -728,14 +1123,51 @@ config STM32L4_SAI1 default n depends on STM32L4_HAVE_SAI1 +config STM32L4_SAI1_A + bool "SAI1 Block A" + default n + select AUDIO + select I2S + select SCHED_WORKQUEUE + select STM32L4_SAI + depends on STM32L4_SAI1 + +config STM32L4_SAI1_B + bool "SAI1 Block B" + default n + select AUDIO + select I2S + select SCHED_WORKQUEUE + select STM32L4_SAI + depends on STM32L4_SAI1 + config STM32L4_SAI2 bool "SAI2" default n depends on STM32L4_HAVE_SAI2 -config STM32L4_DFSDM - bool "DFSDM" +config STM32L4_SAI2_A + bool "SAI2 Block A" default n + select AUDIO + select I2S + select SCHED_WORKQUEUE + select STM32L4_SAI + depends on STM32L4_SAI2 + +config STM32L4_SAI2_B + bool "SAI2 Block B" + default n + select AUDIO + select I2S + select SCHED_WORKQUEUE + select STM32L4_SAI + depends on STM32L4_SAI2 + +config STM32L4_DFSDM1 + bool "DFSDM1" + default n + depends on STM32L4_HAVE_DFSDM1 comment "Other Peripherals" @@ -809,6 +1241,7 @@ config STM32L4_SAI1PLL config STM32L4_SAI2PLL bool "SAI2PLL" default n + depends on STM32L4_HAVE_SAI2 ---help--- The STM32L476 has a separate PLL for the SAI2 block. Set this true and provide configuration parameters in diff --git a/arch/arm/src/stm32l4/stm32l4x6xx_rcc.c b/arch/arm/src/stm32l4/stm32l4x6xx_rcc.c index 08344fa0ba6..3b174177402 100644 --- a/arch/arm/src/stm32l4/stm32l4x6xx_rcc.c +++ b/arch/arm/src/stm32l4/stm32l4x6xx_rcc.c @@ -277,7 +277,7 @@ static inline void rcc_enableahb3(void) #ifdef CONFIG_STM32L4_FSMC /* Flexible static memory controller module clock enable */ - regval |= RCC_AHB3ENR_FMCEN; + regval |= RCC_AHB3ENR_FSMCEN; #endif @@ -563,7 +563,7 @@ static inline void rcc_enableapb2(void) regval |= RCC_APB2ENR_SAI2EN; #endif -#ifdef CONFIG_STM32L4_DFSDM +#ifdef CONFIG_STM32L4_DFSDM1 /* DFSDM clock enable */ regval |= RCC_APB2ENR_DFSDMEN; @@ -814,7 +814,6 @@ static void stm32l4_stdclockconfig(void) regval = getreg32(STM32L4_RCC_PLLSAI2CFG); - /* Enable the SAI2 PLL */ /* Set the PLL dividers and multipliers to configure the SAI2 PLL */ regval = (STM32L4_PLLSAI2CFG_PLLN | STM32L4_PLLSAI2CFG_PLLP | @@ -829,7 +828,7 @@ static void stm32l4_stdclockconfig(void) putreg32(regval, STM32L4_RCC_PLLSAI2CFG); - /* Enable the SAI1 PLL */ + /* Enable the SAI2 PLL */ regval = getreg32(STM32L4_RCC_CR); regval |= RCC_CR_PLLSAI2ON; @@ -842,7 +841,7 @@ static void stm32l4_stdclockconfig(void) } #endif - /* Enable FLASH prefetch, instruction cache, data cache, and 5 wait states */ + /* Enable FLASH prefetch, instruction cache, data cache, and 4 wait states */ #ifdef CONFIG_STM32L4_FLASH_PREFETCH regval = (FLASH_ACR_LATENCY_4 | FLASH_ACR_ICEN | FLASH_ACR_DCEN | FLASH_ACR_PRFTEN); diff --git a/configs/nucleo-l496zg/nsh/defconfig b/configs/nucleo-l496zg/nsh/defconfig index 3808958bd41..4bc74debafe 100644 --- a/configs/nucleo-l496zg/nsh/defconfig +++ b/configs/nucleo-l496zg/nsh/defconfig @@ -166,7 +166,7 @@ CONFIG_ARCH_HAVE_CMNVECTOR=y CONFIG_ARMV7M_CMNVECTOR=y # CONFIG_ARMV7M_LAZYFPU is not set CONFIG_ARCH_HAVE_FPU=y -CONFIG_ARCH_HAVE_DPFPU=y +# CONFIG_ARCH_HAVE_DPFPU is not set # CONFIG_ARCH_FPU is not set # CONFIG_ARCH_HAVE_TRUSTZONE is not set CONFIG_ARM_HAVE_MPU_UNIFIED=y @@ -178,15 +178,13 @@ CONFIG_ARM_HAVE_MPU_UNIFIED=y # # CONFIG_ARMV7M_HAVE_ICACHE is not set # CONFIG_ARMV7M_HAVE_DCACHE is not set -CONFIG_ARMV7M_HAVE_ITCM=y -CONFIG_ARMV7M_HAVE_DTCM=y -# CONFIG_ARMV7M_ITCM is not set -# CONFIG_ARMV7M_DTCM is not set +# CONFIG_ARMV7M_HAVE_ITCM is not set +# CONFIG_ARMV7M_HAVE_DTCM is not set # CONFIG_ARMV7M_TOOLCHAIN_IARL is not set # CONFIG_ARMV7M_TOOLCHAIN_BUILDROOT is not set # CONFIG_ARMV7M_TOOLCHAIN_CODEREDL is not set -CONFIG_ARMV7M_TOOLCHAIN_CODESOURCERYL=y -# CONFIG_ARMV7M_TOOLCHAIN_GNU_EABIL is not set +# CONFIG_ARMV7M_TOOLCHAIN_CODESOURCERYL is not set +CONFIG_ARMV7M_TOOLCHAIN_GNU_EABIL=y CONFIG_ARMV7M_HAVE_STACKCHECK=y CONFIG_ARMV7M_STACKCHECK=y # CONFIG_ARMV7M_ITMSYSLOG is not set @@ -281,6 +279,7 @@ CONFIG_STM32L4_HAVE_DAC2=y CONFIG_STM32L4_HAVE_DCMI=y CONFIG_STM32L4_HAVE_DFSDM1=y CONFIG_STM32L4_HAVE_DMA2D=y +CONFIG_STM32L4_HAVE_FSMC=y # CONFIG_STM32L4_HAVE_HASH is not set CONFIG_STM32L4_HAVE_I2C4=y CONFIG_STM32L4_HAVE_LCD=y @@ -292,7 +291,11 @@ CONFIG_STM32L4_HAVE_SAI1=y CONFIG_STM32L4_HAVE_SAI2=y CONFIG_STM32L4_HAVE_SDMMC1=y CONFIG_STM32L4_HAVE_TIM3=y +CONFIG_STM32L4_HAVE_TIM4=y +CONFIG_STM32L4_HAVE_TIM5=y CONFIG_STM32L4_HAVE_TIM7=y +CONFIG_STM32L4_HAVE_TIM8=y +CONFIG_STM32L4_HAVE_TIM17=y CONFIG_STM32L4_ADC=y # CONFIG_STM32L4_CAN is not set # CONFIG_STM32L4_DAC is not set @@ -321,15 +324,11 @@ CONFIG_STM32L4_ADC1=y # CONFIG_STM32L4_DCMI is not set # CONFIG_STM32L4_DMA2D is not set CONFIG_STM32L4_RNG=y -# CONFIG_STM32L4_SAI1_A is not set -# CONFIG_STM32L4_SAI1_B is not set -# CONFIG_STM32L4_SAI2_A is not set -# CONFIG_STM32L4_SAI2_B is not set # # AHB3 Peripherals # -# CONFIG_STM32L4_FMC is not set +CONFIG_STM32L4_FSMC=y # CONFIG_STM32L4_QSPI is not set # @@ -402,6 +401,9 @@ CONFIG_STM32L4_SAI1PLL=y # CONFIG_STM32L4_ONESHOT is not set # CONFIG_STM32L4_FREERUN is not set # CONFIG_STM32L4_TIM3_CAP is not set +# CONFIG_STM32L4_TIM4_CAP is not set +# CONFIG_STM32L4_TIM5_CAP is not set +# CONFIG_STM32L4_TIM8_CAP is not set # # ADC Configuration @@ -698,6 +700,7 @@ CONFIG_ANALOG=y # CONFIG_ADC is not set # CONFIG_COMP is not set # CONFIG_DAC is not set +# CONFIG_OPAMP is not set # CONFIG_AUDIO_DEVICES is not set # CONFIG_VIDEO_DEVICES is not set # CONFIG_BCH is not set From ae22eb224a1474538f5264a79d3f4ff0c36e713d Mon Sep 17 00:00:00 2001 From: Juha Niskanen Date: Tue, 2 May 2017 15:20:11 +0300 Subject: [PATCH 126/183] STM32L4: changes needed for STM32L452 and Nucleo-L452RE board GPIO and UART seem similar across STMicro product matrix, so renamed files accordingly. RCC is cloned just in case, while conflicting differences there seem to be very minor. --- arch/arm/include/stm32l4/chip.h | 77 +- arch/arm/include/stm32l4/irq.h | 5 +- arch/arm/include/stm32l4/stm32l4x3xx_irq.h | 185 ++++ .../{stm32l4x6xx_gpio.h => stm32l4_gpio.h} | 8 +- arch/arm/src/stm32l4/chip/stm32l4_memorymap.h | 27 +- arch/arm/src/stm32l4/chip/stm32l4_pinmap.h | 5 +- .../{stm32l4x6xx_uart.h => stm32l4_uart.h} | 18 +- arch/arm/src/stm32l4/chip/stm32l4x3xx_dma.h | 461 ++++++++++ .../arm/src/stm32l4/chip/stm32l4x3xx_pinmap.h | 559 +++++++++++ arch/arm/src/stm32l4/chip/stm32l4x3xx_rcc.h | 789 ++++++++++++++++ arch/arm/src/stm32l4/chip/stm32l4x6xx_rcc.h | 5 +- arch/arm/src/stm32l4/stm32l4_dma.c | 25 +- arch/arm/src/stm32l4/stm32l4_dma.h | 5 +- arch/arm/src/stm32l4/stm32l4_gpio.h | 5 +- arch/arm/src/stm32l4/stm32l4_rcc.c | 5 +- arch/arm/src/stm32l4/stm32l4_rcc.h | 5 +- arch/arm/src/stm32l4/stm32l4_serial.c | 1 + arch/arm/src/stm32l4/stm32l4_uart.h | 5 +- arch/arm/src/stm32l4/stm32l4x3xx_rcc.c | 864 ++++++++++++++++++ 19 files changed, 2992 insertions(+), 62 deletions(-) create mode 100644 arch/arm/include/stm32l4/stm32l4x3xx_irq.h rename arch/arm/src/stm32l4/chip/{stm32l4x6xx_gpio.h => stm32l4_gpio.h} (98%) rename arch/arm/src/stm32l4/chip/{stm32l4x6xx_uart.h => stm32l4_uart.h} (97%) create mode 100644 arch/arm/src/stm32l4/chip/stm32l4x3xx_dma.h create mode 100644 arch/arm/src/stm32l4/chip/stm32l4x3xx_pinmap.h create mode 100644 arch/arm/src/stm32l4/chip/stm32l4x3xx_rcc.h create mode 100644 arch/arm/src/stm32l4/stm32l4x3xx_rcc.c diff --git a/arch/arm/include/stm32l4/chip.h b/arch/arm/include/stm32l4/chip.h index 7cd275e2806..589d88f675b 100644 --- a/arch/arm/include/stm32l4/chip.h +++ b/arch/arm/include/stm32l4/chip.h @@ -68,7 +68,7 @@ * Parts STM32L4x6xE have 512Kb of FLASH * Parts STM32L4x6xG have 1024Kb of FLASH * - * The correct FLASH size must be set with a CONFIG_STM32L4_FLASH_*KB + * The correct FLASH size must be set with a CONFIG_STM32L4_FLASH_CONFIG_* * selection. */ @@ -78,10 +78,18 @@ #elif defined(CONFIG_STM32L4_STM32L476XX) || defined(CONFIG_STM32L4_STM32L486XX) # define STM32L4_SRAM1_SIZE (96*1024) /* 96Kb SRAM1 on AHB bus Matrix */ # define STM32L4_SRAM2_SIZE (32*1024) /* 32Kb SRAM2 on AHB bus Matrix */ +#elif defined(CONFIG_STM32L4_STM32L451XX) || defined(CONFIG_STM32L4_STM32L452XX) || \ + defined(CONFIG_STM32L4_STM32L462XX) +# define STM32L4_SRAM1_SIZE (128*1024) /* 128Kb SRAM1 on AHB bus Matrix */ +# define STM32L4_SRAM2_SIZE (32*1024) /* 32Kb SRAM2 on AHB bus Matrix */ +#elif defined(CONFIG_STM32L4_STM32L432XX) +# define STM32L4_SRAM1_SIZE (48*1024) /* 48Kb SRAM1 on AHB bus Matrix */ +# define STM32L4_SRAM2_SIZE (16*1024) /* 16Kb SRAM2 on AHB bus Matrix */ #else # error "Unsupported STM32L4 chip" #endif +#if defined(CONFIG_STM32L4_STM32L4X6) # define STM32L4_NFSMC 1 /* Have FSMC memory controller */ # define STM32L4_NATIM 2 /* Two advanced timers TIM1 and 8 */ # define STM32L4_NGTIM32 2 /* 32-bit general timers TIM2 and 5 with DMA */ @@ -100,6 +108,7 @@ # define STM32L4_NI2C 3 /* I2C1-3 */ #endif # define STM32L4_NUSBOTGFS 1 /* USB OTG FS */ +# define STM32L4_NUSBFS 0 /* No USB FS */ #if defined(CONFIG_STM32L4_STM32L496XX) # define STM32L4_NCAN 2 /* CAN1-2 */ #else @@ -118,6 +127,72 @@ # define STM32L4_NCRC 1 /* CRC */ # define STM32L4_NCOMP 2 /* Comparators */ # define STM32L4_NOPAMP 2 /* Operational Amplifiers */ +#endif /* CONFIG_STM32L4_STM32L4X6 */ + +#if defined(CONFIG_STM32L4_STM32L451XX) || defined(CONFIG_STM32L4_STM32L452XX) || \ + defined(CONFIG_STM32L4_STM32L462XX) +# define STM32L4_NFSMC 0 /* No FSMC memory controller */ +# define STM32L4_NATIM 1 /* One advanced timer TIM1 */ +# define STM32L4_NGTIM32 1 /* 32-bit general timer TIM2 with DMA */ +# define STM32L4_NGTIM16 3 /* 16-bit general timers TIM3, TIM15-16 with DMA */ +# define STM32L4_NGTIMNDMA 0 /* No 16-bit general timers without DMA */ +# define STM32L4_NBTIM 1 /* One basic timer, TIM6 */ +# define STM32L4_NLPTIM 2 /* Two low-power timers, LPTIM1-2 */ +# define STM32L4_NRNG 1 /* Random number generator (RNG) */ +# define STM32L4_NUART 1 /* UART 4 */ +# define STM32L4_NUSART 3 /* USART 1-3 */ +# define STM32L4_NLPUART 1 /* LPUART 1 */ +# define STM32L4_NSPI 3 /* SPI1-3 */ +# define STM32L4_NI2C 4 /* I2C1-4 */ +# define STM32L4_NUSBOTGFS 0 /* No USB OTG FS */ +#if defined(CONFIG_STM32L4_STM32L451XX) +# define STM32L4_NUSBFS 0 /* No USB FS */ +#else +# define STM32L4_NUSBFS 1 /* USB FS */ +#endif +# define STM32L4_NCAN 1 /* CAN1 */ +# define STM32L4_NSAI 1 /* SAI1 */ +#if defined(CONFIG_STM32L4_HAVE_SDMMC1) +# define STM32L4_NSDMMC 1 /* SDMMC interface */ +#else +# define STM32L4_NSDMMC 0 /* No SDMMC interface */ +#endif +# define STM32L4_NDMA 2 /* DMA1-2 */ +# define STM32L4_NPORTS 8 /* 8 GPIO ports, GPIOA-H */ +# define STM32L4_NADC 1 /* 12-bit ADC1, 16 channels (10 in CE,CV) */ +# define STM32L4_NDAC 1 /* 12-bit DAC1 */ +# define STM32L4_NCRC 1 /* CRC */ +# define STM32L4_NCOMP 2 /* Comparators */ +# define STM32L4_NOPAMP 1 /* Operational Amplifiers */ +#endif /* CONFIG_STM32L4_STM32L451XX */ + +#if defined(CONFIG_STM32L4_STM32L432XX) +# define STM32L4_NFSMC 0 /* No FSMC memory controller */ +# define STM32L4_NATIM 1 /* One advanced timer TIM1 */ +# define STM32L4_NGTIM32 1 /* 32-bit general timer TIM2 with DMA */ +# define STM32L4_NGTIM16 2 /* 16-bit general timers TIM15-16 with DMA */ +# define STM32L4_NGTIMNDMA 0 /* No 16-bit general timers without DMA */ +# define STM32L4_NBTIM 2 /* Two basic timers, TIM6-7 */ +# define STM32L4_NLPTIM 2 /* Two low-power timers, LPTIM1-2 */ +# define STM32L4_NRNG 1 /* Random number generator (RNG) */ +# define STM32L4_NUART 0 /* No UART */ +# define STM32L4_NUSART 2 /* USART 1-2 */ +# define STM32L4_NLPUART 1 /* LPUART 1 */ +# define STM32L4_NSPI 2 /* SPI1, SPI3 */ +# define STM32L4_NI2C 2 /* I2C1, I2C3 */ +# define STM32L4_NUSBOTGFS 0 /* No USB OTG FS */ +# define STM32L4_NUSBFS 1 /* USB FS */ +# define STM32L4_NCAN 1 /* CAN1 */ +# define STM32L4_NSAI 1 /* SAI1 */ +# define STM32L4_NSDMMC 0 /* No SDMMC interface */ +# define STM32L4_NDMA 2 /* DMA1-2 */ +# define STM32L4_NPORTS 8 /* 8 GPIO ports, GPIOA-H */ +# define STM32L4_NADC 1 /* 12-bit ADC1, 10 channels */ +# define STM32L4_NDAC 2 /* 12-bit DAC1-2 */ +# define STM32L4_NCRC 1 /* CRC */ +# define STM32L4_NCOMP 2 /* Comparators */ +# define STM32L4_NOPAMP 1 /* Operational Amplifiers */ +#endif /* CONFIG_STM32L4_STM32L432XX */ /* NVIC priority levels *************************************************************/ /* 16 Programmable interrupt levels */ diff --git a/arch/arm/include/stm32l4/irq.h b/arch/arm/include/stm32l4/irq.h index abb543bc723..480b7d693a4 100644 --- a/arch/arm/include/stm32l4/irq.h +++ b/arch/arm/include/stm32l4/irq.h @@ -76,9 +76,10 @@ #define STM32L4_IRQ_FIRST (16) /* Vector number of the first external interrupt */ -#if defined(CONFIG_STM32L4_STM32L476XX) || defined(CONFIG_STM32L4_STM32L486XX) || \ - defined(CONFIG_STM32L4_STM32L496XX) +#if defined(CONFIG_STM32L4_STM32L4X6) # include +#elif defined(CONFIG_STM32L4_STM32L4X3) +# include #else # error "Unsupported STM32 L4 chip" #endif diff --git a/arch/arm/include/stm32l4/stm32l4x3xx_irq.h b/arch/arm/include/stm32l4/stm32l4x3xx_irq.h new file mode 100644 index 00000000000..e3c3c8cf17d --- /dev/null +++ b/arch/arm/include/stm32l4/stm32l4x3xx_irq.h @@ -0,0 +1,185 @@ +/**************************************************************************************************** + * arch/arm/include/stm32l4/stm32l4x3xx_irq.h + * + * Copyright (C) 2015 Sebastien Lorquet. All rights reserved. + * Authors: Sebastien Lorquet + * Juha Niskanen + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************************************/ + +/* This file should never be included directed but, rather, only indirectly through arch/irq.h */ + +#ifndef __ARCH_ARM_INCLUDE_STM32L4_STM32L4X3XX_IRQ_H +#define __ARCH_ARM_INCLUDE_STM32L4_STM32L4X3XX_IRQ_H + +/**************************************************************************************************** + * Included Files + ****************************************************************************************************/ + +#include + +/**************************************************************************************************** + * Pre-processor Definitions + ****************************************************************************************************/ + +/* IRQ numbers. The IRQ number corresponds vector number and hence map directly to bits in the + * NVIC. This does, however, waste several words of memory in the IRQ to handle mapping tables. + * + * Processor Exceptions (vectors 0-15). These common definitions can be found in the file + * nuttx/arch/arm/include/stm32f7/irq.h which includes this file + * + * External interrupts (vectors >= 16) + */ + +#define STM32L4_IRQ_WWDG (STM32L4_IRQ_FIRST+0) /* 0: Window Watchdog interrupt */ +#define STM32L4_IRQ_PVD (STM32L4_IRQ_FIRST+1) /* 1: PVD through EXTI Line detection interrupt */ +#define STM32L4_IRQ_TAMPER (STM32L4_IRQ_FIRST+2) /* 2: Tamper and time stamp interrupts */ +#define STM32L4_IRQ_TIMESTAMP (STM32L4_IRQ_FIRST+2) /* 2: Tamper and time stamp interrupts */ +#define STM32L4_IRQ_RTC_WKUP (STM32L4_IRQ_FIRST+3) /* 3: RTC global interrupt */ +#define STM32L4_IRQ_FLASH (STM32L4_IRQ_FIRST+4) /* 4: Flash global interrupt */ +#define STM32L4_IRQ_RCC (STM32L4_IRQ_FIRST+5) /* 5: RCC global interrupt */ +#define STM32L4_IRQ_EXTI0 (STM32L4_IRQ_FIRST+6) /* 6: EXTI Line 0 interrupt */ +#define STM32L4_IRQ_EXTI1 (STM32L4_IRQ_FIRST+7) /* 7: EXTI Line 1 interrupt */ +#define STM32L4_IRQ_EXTI2 (STM32L4_IRQ_FIRST+8) /* 8: EXTI Line 2 interrupt */ +#define STM32L4_IRQ_EXTI3 (STM32L4_IRQ_FIRST+9) /* 9: EXTI Line 3 interrupt */ +#define STM32L4_IRQ_EXTI4 (STM32L4_IRQ_FIRST+10) /* 10: EXTI Line 4 interrupt */ +#define STM32L4_IRQ_DMA1CH1 (STM32L4_IRQ_FIRST+11) /* 12: DMA1 Channel 1 global interrupt */ +#define STM32L4_IRQ_DMA1CH2 (STM32L4_IRQ_FIRST+12) /* 13: DMA1 Channel 2 global interrupt */ +#define STM32L4_IRQ_DMA1CH3 (STM32L4_IRQ_FIRST+13) /* 14: DMA1 Channel 3 global interrupt */ +#define STM32L4_IRQ_DMA1CH4 (STM32L4_IRQ_FIRST+14) /* 15: DMA1 Channel 4 global interrupt */ +#define STM32L4_IRQ_DMA1CH5 (STM32L4_IRQ_FIRST+15) /* 16: DMA1 Channel 5 global interrupt */ +#define STM32L4_IRQ_DMA1CH6 (STM32L4_IRQ_FIRST+16) /* 17: DMA1 Channel 6 global interrupt */ +#define STM32L4_IRQ_DMA1CH7 (STM32L4_IRQ_FIRST+17) /* 17: DMA1 Channel 7 global interrupt */ +#define STM32L4_IRQ_ADC1 (STM32L4_IRQ_FIRST+18) /* 18: ADC1 global interrupt */ +#define STM32L4_IRQ_CAN1TX (STM32L4_IRQ_FIRST+19) /* 19: CAN1 TX interrupts */ +#define STM32L4_IRQ_CAN1RX0 (STM32L4_IRQ_FIRST+20) /* 20: CAN1 RX0 interrupts */ +#define STM32L4_IRQ_CAN1RX1 (STM32L4_IRQ_FIRST+21) /* 21: CAN1 RX1 interrupt */ +#define STM32L4_IRQ_CAN1SCE (STM32L4_IRQ_FIRST+22) /* 22: CAN1 SCE interrupt */ +#define STM32L4_IRQ_EXTI95 (STM32L4_IRQ_FIRST+23) /* 23: EXTI Line[9:5] interrupts */ +#define STM32L4_IRQ_TIM1BRK (STM32L4_IRQ_FIRST+24) /* 24: TIM1 Break interrupt */ +#define STM32L4_IRQ_TIM15 (STM32L4_IRQ_FIRST+24) /* 24: TIM15 global interrupt */ +#define STM32L4_IRQ_TIM1UP (STM32L4_IRQ_FIRST+25) /* 25: TIM1 Update interrupt */ +#define STM32L4_IRQ_TIM16 (STM32L4_IRQ_FIRST+25) /* 25: TIM16 global interrupt */ +#define STM32L4_IRQ_TIM1TRGCOM (STM32L4_IRQ_FIRST+26) /* 26: TIM1 Trigger and Commutation interrupts */ +#define STM32L4_IRQ_TIM1CC (STM32L4_IRQ_FIRST+27) /* 27: TIM1 Capture Compare interrupt */ +#define STM32L4_IRQ_TIM2 (STM32L4_IRQ_FIRST+28) /* 28: TIM2 global interrupt */ +#define STM32L4_IRQ_TIM3 (STM32L4_IRQ_FIRST+29) /* 29: TIM3 global interrupt */ +/* Reserved */ /* 30: TIM4 global interrupt */ +#define STM32L4_IRQ_I2C1EV (STM32L4_IRQ_FIRST+31) /* 31: I2C1 event interrupt */ +#define STM32L4_IRQ_I2C1ER (STM32L4_IRQ_FIRST+32) /* 32: I2C1 error interrupt */ +#define STM32L4_IRQ_I2C2EV (STM32L4_IRQ_FIRST+33) /* 33: I2C2 event interrupt */ +#define STM32L4_IRQ_I2C2ER (STM32L4_IRQ_FIRST+34) /* 34: I2C2 error interrupt */ +#define STM32L4_IRQ_SPI1 (STM32L4_IRQ_FIRST+35) /* 35: SPI1 global interrupt */ +#define STM32L4_IRQ_SPI2 (STM32L4_IRQ_FIRST+36) /* 36: SPI2 global interrupt */ +#define STM32L4_IRQ_USART1 (STM32L4_IRQ_FIRST+37) /* 37: USART1 global interrupt */ +#define STM32L4_IRQ_USART2 (STM32L4_IRQ_FIRST+38) /* 38: USART2 global interrupt */ +#define STM32L4_IRQ_USART3 (STM32L4_IRQ_FIRST+39) /* 39: USART3 global interrupt */ +#define STM32L4_IRQ_EXTI1510 (STM32L4_IRQ_FIRST+40) /* 40: EXTI Line[15:10] interrupts */ +#define STM32L4_IRQ_RTCALRM (STM32L4_IRQ_FIRST+41) /* 41: RTC alarm through EXTI line interrupt */ +/* Reserved */ /* 42-48: reserved */ +#define STM32L4_IRQ_SDMMC1 (STM32L4_IRQ_FIRST+49) /* 49: SDMMC1 global interrupt */ +/* Reserved */ /* 50: TIM5 global interrupt */ +#define STM32L4_IRQ_SPI3 (STM32L4_IRQ_FIRST+51) /* 51: SPI3 global interrupt */ +#define STM32L4_IRQ_UART4 (STM32L4_IRQ_FIRST+52) /* 52: UART4 global interrupt */ +/* Reserved */ /* 53: UART5 global interrupt */ +#define STM32L4_IRQ_TIM6 (STM32L4_IRQ_FIRST+54) /* 54: TIM6 global interrupt */ +#define STM32L4_IRQ_DAC (STM32L4_IRQ_FIRST+54) /* 54: DAC1 underrun error interrupts */ +#define STM32L4_IRQ_TIM7 (STM32L4_IRQ_FIRST+55) /* 55: TIM7 global interrupt */ +#define STM32L4_IRQ_DMA2CH1 (STM32L4_IRQ_FIRST+56) /* 56: DMA2 Channel 1 global interrupt */ +#define STM32L4_IRQ_DMA2CH2 (STM32L4_IRQ_FIRST+57) /* 57: DMA2 Channel 2 global interrupt */ +#define STM32L4_IRQ_DMA2CH3 (STM32L4_IRQ_FIRST+58) /* 58: DMA2 Channel 3 global interrupt */ +#define STM32L4_IRQ_DMA2CH4 (STM32L4_IRQ_FIRST+59) /* 59: DMA2 Channel 4 global interrupt */ +#define STM32L4_IRQ_DMA2CH5 (STM32L4_IRQ_FIRST+60) /* 60: DMA2 Channel 5 global interrupt */ +#define STM32L4_IRQ_DFSDM0 (STM32L4_IRQ_FIRST+61) /* 61: DFSDM0 global interrupt */ +#define STM32L4_IRQ_DFSDM1 (STM32L4_IRQ_FIRST+62) /* 62: DFSDM1 global interrupt*/ +/* Reserved */ /* 63: DFSDM2 global interrupt */ +#define STM32L4_IRQ_COMP (STM32L4_IRQ_FIRST+64) /* 64: COMP1/COMP2 interrupts */ +#define STM32L4_IRQ_LPTIM1 (STM32L4_IRQ_FIRST+65) /* 65: LPTIM1 global interrupt */ +#define STM32L4_IRQ_LPTIM2 (STM32L4_IRQ_FIRST+66) /* 66: LPTIM2 global interrupt */ +#define STM32L4_IRQ_USB_FS (STM32L4_IRQ_FIRST+67) /* 67: USB event interrupt through EXTI line 17 */ +#define STM32L4_IRQ_DMA2CH6 (STM32L4_IRQ_FIRST+68) /* 68: DMA2 Channel 6 global interrupt */ +#define STM32L4_IRQ_DMA2CH7 (STM32L4_IRQ_FIRST+69) /* 69: DMA2 Channel 7 global interrupt */ +#define STM32L4_IRQ_LPUART1 (STM32L4_IRQ_FIRST+70) /* 70: Low power UART 1 global interrupt */ +#define STM32L4_IRQ_QUADSPI (STM32L4_IRQ_FIRST+71) /* 71: QUADSPI global interrupt */ +#define STM32L4_IRQ_I2C3EV (STM32L4_IRQ_FIRST+72) /* 72: I2C3 event interrupt */ +#define STM32L4_IRQ_I2C3ER (STM32L4_IRQ_FIRST+73) /* 73: I2C3 error interrupt */ +#define STM32L4_IRQ_SAI1 (STM32L4_IRQ_FIRST+74) /* 74: SAI1 global interrupt */ +/* Reserved */ /* 75: SAI2 global interrupt */ +#define STM32L4_IRQ_SWPMI1 (STM32L4_IRQ_FIRST+76) /* 76: SWPMI1 global interrupt */ +#define STM32L4_IRQ_TSC (STM32L4_IRQ_FIRST+77) /* 77: TSC global interrupt */ +#define STM32L4_IRQ_LCD (STM32L4_IRQ_FIRST+78) /* 78: LCD global interrupt */ +#define STM32L4_IRQ_AES (STM32L4_IRQ_FIRST+79) /* 79: AES crypto global interrupt */ +#define STM32L4_IRQ_RNG (STM32L4_IRQ_FIRST+80) /* 80: RNG global interrupt */ +#define STM32L4_IRQ_FPU (STM32L4_IRQ_FIRST+81) /* 81: FPU global interrupt */ +#define STM32L4_IRQ_CRS (STM32L4_IRQ_FIRST+82) /* 82: CRS global interrupt */ +#define STM32L4_IRQ_I2C4EV (STM32L4_IRQ_FIRST+83) /* 83: I2C4 event interrupt */ +#define STM32L4_IRQ_I2C4ER (STM32L4_IRQ_FIRST+84) /* 84: I2C4 error interrupt */ + +#if defined(CONFIG_STM32L4_STM32L4X3) +# define NR_INTERRUPTS 85 +#else +# error "Unsupported STM32L4 chip" +#endif + +#define NR_VECTORS (STM32L4_IRQ_FIRST+NR_INTERRUPTS) + +/* EXTI interrupts (Do not use IRQ numbers) */ + +#define NR_IRQS NR_VECTORS + +/**************************************************************************************************** + * Public Types + ****************************************************************************************************/ + +/**************************************************************************************************** + * Public Data + ****************************************************************************************************/ + +#ifndef __ASSEMBLY__ +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************************************** + * Public Functions + ****************************************************************************************************/ + +#undef EXTERN +#ifdef __cplusplus +} +#endif +#endif + +#endif /* __ARCH_ARM_INCLUDE_STM32L4_STM32L4X3XX_IRQ_H */ diff --git a/arch/arm/src/stm32l4/chip/stm32l4x6xx_gpio.h b/arch/arm/src/stm32l4/chip/stm32l4_gpio.h similarity index 98% rename from arch/arm/src/stm32l4/chip/stm32l4x6xx_gpio.h rename to arch/arm/src/stm32l4/chip/stm32l4_gpio.h index f4f32e7f926..08e0e9e5197 100644 --- a/arch/arm/src/stm32l4/chip/stm32l4x6xx_gpio.h +++ b/arch/arm/src/stm32l4/chip/stm32l4_gpio.h @@ -1,5 +1,5 @@ /************************************************************************************ - * arch/arm/src/stm32l4/chip/stm32l4x6xx_gpio.h + * arch/arm/src/stm32l4/chip/stm32l4_gpio.h * * Copyright (C) 2016, Sebastien Lorquet. All rights reserved. * Author: Sebastien Lorquet @@ -33,8 +33,8 @@ * ************************************************************************************/ -#ifndef __ARCH_ARM_SRC_STM32L4_CHIP_STM32L4X6XX_GPIO_H -#define __ARCH_ARM_SRC_STM32L4_CHIP_STM32L4X6XX_GPIO_H +#ifndef __ARCH_ARM_SRC_STM32L4_CHIP_STM32L4_GPIO_H +#define __ARCH_ARM_SRC_STM32L4_CHIP_STM32L4_GPIO_H /************************************************************************************ * Included Files @@ -371,5 +371,5 @@ #define GPIO_AFRH15_SHIFT (28) #define GPIO_AFRH15_MASK (15 << GPIO_AFRH15_SHIFT) -#endif /* __ARCH_ARM_SRC_STM32L4_CHIP_STM32L4X6XX_GPIO_H */ +#endif /* __ARCH_ARM_SRC_STM32L4_CHIP_STM32L4_GPIO_H */ diff --git a/arch/arm/src/stm32l4/chip/stm32l4_memorymap.h b/arch/arm/src/stm32l4/chip/stm32l4_memorymap.h index 33a9b5bd566..cbd89cc429f 100644 --- a/arch/arm/src/stm32l4/chip/stm32l4_memorymap.h +++ b/arch/arm/src/stm32l4/chip/stm32l4_memorymap.h @@ -40,7 +40,7 @@ * Pre-processor Definitions ************************************************************************************/ -/* STM32F40XXX Address Blocks *******************************************************/ +/* STM32L4XXX Address Blocks ********************************************************/ #define STM32L4_CODE_BASE 0x00000000 /* 0x00000000-0x1fffffff: 512Mb code block */ #define STM32L4_SRAM_BASE 0x20000000 /* 0x20000000-0x3fffffff: 512Mb sram block (96k or 256k) */ @@ -50,7 +50,7 @@ # define STM32L4_FSMC_BANK2 0x70000000 /* 0x70000000-0x7fffffff: 256Mb NAND FLASH */ #define STM32L4_FSMC_BASE34 0x80000000 /* 0x80000000-0x8fffffff: 512Mb FSMC bank3 / QSPI block */ # define STM32L4_FSMC_BANK3 0x80000000 /* 0x80000000-0x8fffffff: 256Mb NAND FLASH */ -# define STM32L4_QSPI_BANK 0x90000000 /* 0x90000000-0x9fffffff: 256Mb QUADSPI*/ +# define STM32L4_QSPI_BANK 0x90000000 /* 0x90000000-0x9fffffff: 256Mb QUADSPI */ #define STM32L4_FSMC_BASE 0xa0000000 /* 0xa0000000-0xbfffffff: FSMC register block */ #define STM32L4_QSPI_BASE 0xa0001000 /* 0xa0000000-0xbfffffff: QSPI register block */ /* 0xc0000000-0xdfffffff: 512Mb (not used) */ @@ -68,10 +68,13 @@ /* 0x08100000-0x0fffffff: Reserved */ #define STM32L4_SRAM2_BASE 0x10000000 /* 0x10000000-0x1000ffff: 32Kb or 64Kb SRAM2 */ /* 0x10010000-0x1ffeffff: Reserved */ -#define STM32L4_SYSMEM_BASE 0x1fff0000 /* 0x1fff0000-0x1fff7a0f: System memory */ - /* 0x1fff7a10-0x1fff7fff: Reserved */ -#define STM32L4_OPTION_BASE 0x1fffc000 /* 0x1fffc000-0x1fffc007: Option bytes */ - /* 0x1fffc008-0x1fffffff: Reserved */ +#define STM32L4_SYSMEM_BASE 0x1fff0000 /* 0x1fff0000-0x1fff6fff: System memory */ +#define STM32L4_OTP_BASE 0x1fff7000 /* 0x1fff7000-0x1fff73ff: OTP memory */ + /* 0x1fff7400-0x1fff77ff: Reserved */ +#define STM32L4_OPTION_BASE 0x1fff7800 /* 0x1fff7800-0x1fff780f: Option bytes */ + /* 0x1fff7810-0x1ffff7ff: Reserved */ +#define STM32L4_OPTION2_BASE 0x1ffff800 /* 0x1ffff800-0x1ffff80f: Option bytes 2 */ + /* 0x1ffff810-0x1fffffff: Reserved */ /* System Memory Addresses **********************************************************/ @@ -84,9 +87,13 @@ #define STM32L4_SYSMEM_PACKAGE 0x1fff7500 /* This bitfield indicates the package * type. * 0: LQFP64 + * 1: WLCSP64 * 2: LQFP100 * 3: UFBGA132 * 4: LQFP144, WLCSP81 or WLCSP72 + * 10: WLCSP49 + * 11: UFBGA64 + * 12: UFBGA100 * 16: UFBGA169 * 17: WLCSP100 */ @@ -124,8 +131,14 @@ #define STM32L4_OPAMP_BASE 0x40007800 #define STM32L4_DAC_BASE 0x40007400 #define STM32L4_PWR_BASE 0x40007000 -#define STM32L4_CAN2_BASE 0x40006800 +#if defined(CONFIG_STM32L4_STM32L4X2) +# define STM32L4_USB_SRAM_BASE 0x40006c00 +# define STM32L4_USB_FS_BASE 0x40006800 +#else +# define STM32L4_CAN2_BASE 0x40006800 +#endif #define STM32L4_CAN1_BASE 0x40006400 +#define STM32L4_CRS_BASE 0x40006000 #define STM32L4_I2C3_BASE 0x40005c00 #define STM32L4_I2C2_BASE 0x40005800 #define STM32L4_I2C1_BASE 0x40005400 diff --git a/arch/arm/src/stm32l4/chip/stm32l4_pinmap.h b/arch/arm/src/stm32l4/chip/stm32l4_pinmap.h index 28257e17386..85140db0343 100644 --- a/arch/arm/src/stm32l4/chip/stm32l4_pinmap.h +++ b/arch/arm/src/stm32l4/chip/stm32l4_pinmap.h @@ -43,9 +43,10 @@ #include #include "chip.h" -#if defined(CONFIG_STM32L4_STM32L476XX) || defined(CONFIG_STM32L4_STM32L486XX) || \ - defined(CONFIG_STM32L4_STM32L496XX) +#if defined(CONFIG_STM32L4_STM32L4X6) # include "chip/stm32l4x6xx_pinmap.h" +#elif defined(CONFIG_STM32L4_STM32L4X3) +# include "chip/stm32l4x3xx_pinmap.h" #else # error "Unsupported STM32 L4 pin map" #endif diff --git a/arch/arm/src/stm32l4/chip/stm32l4x6xx_uart.h b/arch/arm/src/stm32l4/chip/stm32l4_uart.h similarity index 97% rename from arch/arm/src/stm32l4/chip/stm32l4x6xx_uart.h rename to arch/arm/src/stm32l4/chip/stm32l4_uart.h index 7e1855061d5..c7605ab8ad8 100644 --- a/arch/arm/src/stm32l4/chip/stm32l4x6xx_uart.h +++ b/arch/arm/src/stm32l4/chip/stm32l4_uart.h @@ -1,5 +1,5 @@ /************************************************************************************ - * arch/arm/src/stm32l4/chip/stm32l4x6xx_uart.h + * arch/arm/src/stm32l4/chip/stm32l4_uart.h * * Copyright (C) 2009, 2011-2014 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -33,8 +33,8 @@ * ************************************************************************************/ -#ifndef __ARCH_ARM_SRC_STM32L4_CHIP_STM32L4X6XX_UART_H -#define __ARCH_ARM_SRC_STM32L4_CHIP_STM32L4X6XX_UART_H +#ifndef __ARCH_ARM_SRC_STM32L4_CHIP_STM32L4_UART_H +#define __ARCH_ARM_SRC_STM32L4_CHIP_STM32L4_UART_H /************************************************************************************ * Included Files @@ -57,7 +57,7 @@ #define STM32L4_USART_GTPR_OFFSET 0x0010 /* Guard time and prescaler register */ #define STM32L4_USART_RTOR_OFFSET 0x0014 /* Receiver timeout register */ #define STM32L4_USART_RQR_OFFSET 0x0018 /* Request register */ -#define STM32L4_USART_ISR_OFFSET 0x001c /* Interrupot and status register */ +#define STM32L4_USART_ISR_OFFSET 0x001c /* Interrupt and status register */ #define STM32L4_USART_ICR_OFFSET 0x0020 /* Interrupt flag clear register */ #define STM32L4_USART_RDR_OFFSET 0x0024 /* Receive Data register */ #define STM32L4_USART_TDR_OFFSET 0x0028 /* Transmit Data register */ @@ -139,7 +139,7 @@ /* Control register 1 */ #define USART_CR1_UE (1 << 0) /* Bit 0: USART Enable */ -#define USART_CR1_UESM (1 << 1) /* Bit 1: USART Enable in Stop mode*/ +#define USART_CR1_UESM (1 << 1) /* Bit 1: USART Enable in Stop mode */ #define USART_CR1_RE (1 << 2) /* Bit 2: Receiver Enable */ #define USART_CR1_TE (1 << 3) /* Bit 3: Transmitter Enable */ #define USART_CR1_IDLEIE (1 << 4) /* Bit 4: IDLE Interrupt Enable */ @@ -150,7 +150,7 @@ #define USART_CR1_PS (1 << 9) /* Bit 9: Parity Selection */ #define USART_CR1_PCE (1 << 10) /* Bit 10: Parity Control Enable */ #define USART_CR1_WAKE (1 << 11) /* Bit 11: Wakeup method */ -#define USART_CR1_M0 (1 << 12) /* Bit 12: word length */ +#define USART_CR1_M0 (1 << 12) /* Bit 12: Word length */ #define USART_CR1_MME (1 << 13) /* Bit 13: Mute mode enable */ #define USART_CR1_CMIE (1 << 14) /* Bit 14: Character match interrupt enable */ #define USART_CR1_OVER8 (1 << 15) /* Bit 15: Oversampling mode */ @@ -163,7 +163,7 @@ #define USART_CR1_RTOIE (1 << 26) /* Bit 26: Receiver timeout interrupt enable */ #define USART_CR1_EOBIE (1 << 27) /* Bit 27: End of block interrupt enable */ -#define USART_CR1_M1 (1 << 28) /* Bit 12: word length */ +#define USART_CR1_M1 (1 << 28) /* Bit 28: Word length */ #define USART_CR1_ALLINTS (USART_CR1_IDLEIE|USART_CR1_RXNEIE| \ USART_CR1_TCIE|USART_CR1_TXEIE|USART_CR1_PEIE|USART_CR1_CMIE| \ @@ -171,7 +171,7 @@ /* Control register 2 */ -#define USART_CR2_ADDM7 (1 << 4) /* Bit 4: */ +#define USART_CR2_ADDM7 (1 << 4) /* Bit 4: 7-bit/4-bit Address Detection */ #define USART_CR2_LBDL (1 << 5) /* Bit 5: LIN Break Detection Length */ #define USART_CR2_LBDIE (1 << 6) /* Bit 6: LIN Break Detection Interrupt Enable */ #define USART_CR2_LBCL (1 << 8) /* Bit 8: Last Bit Clock pulse */ @@ -314,5 +314,5 @@ * Public Functions ************************************************************************************/ -#endif /* __ARCH_ARM_STC_STM32L4_CHIP_STM32L4X6XX_UART_H */ +#endif /* __ARCH_ARM_STC_STM32L4_CHIP_STM32L4_UART_H */ diff --git a/arch/arm/src/stm32l4/chip/stm32l4x3xx_dma.h b/arch/arm/src/stm32l4/chip/stm32l4x3xx_dma.h new file mode 100644 index 00000000000..166562c9c5b --- /dev/null +++ b/arch/arm/src/stm32l4/chip/stm32l4x3xx_dma.h @@ -0,0 +1,461 @@ +/************************************************************************************ + * arch/arm/src/stm32l4/chip/stm32l4x3xx_dma.h + * + * Copyright (C) 2009, 2011-2013 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ************************************************************************************/ + +#ifndef __ARCH_ARM_SRC_STM32L4_CHIP_STM32L4X3XX_DMA_H +#define __ARCH_ARM_SRC_STM32L4_CHIP_STM32L4X3XX_DMA_H + +/************************************************************************************ + * Pre-processor Definitions + ************************************************************************************/ +/* 14 Channels Total: 7 DMA1 Channels(1-7) and 7 DMA2 channels (1-7) */ + +#define DMA1 0 +#define DMA2 1 +#define DMA3 2 +#define DMA4 3 +#define DMA5 4 +#define DMA6 5 +#define DMA7 6 + +/* Register Offsets *****************************************************************/ + +#define STM32L4_DMA_ISR_OFFSET 0x0000 /* DMA interrupt status register */ +#define STM32L4_DMA_IFCR_OFFSET 0x0004 /* DMA interrupt flag clear register */ + +#define STM32L4_DMACHAN_OFFSET(n) (0x0014*(n)) +#define STM32L4_DMACHAN1_OFFSET 0x0000 +#define STM32L4_DMACHAN2_OFFSET 0x0014 +#define STM32L4_DMACHAN3_OFFSET 0x0028 +#define STM32L4_DMACHAN4_OFFSET 0x003c +#define STM32L4_DMACHAN5_OFFSET 0x0050 +#define STM32L4_DMACHAN6_OFFSET 0x0064 +#define STM32L4_DMACHAN7_OFFSET 0x0078 + +#define STM32L4_DMACHAN_CCR_OFFSET 0x0008 /* DMA channel configuration register */ +#define STM32L4_DMACHAN_CNDTR_OFFSET 0x000c /* DMA channel number of data register */ +#define STM32L4_DMACHAN_CPAR_OFFSET 0x0010 /* DMA channel peripheral address register */ +#define STM32L4_DMACHAN_CMAR_OFFSET 0x0014 /* DMA channel memory address register */ + +#define STM32L4_DMA_CCR_OFFSET(n) (STM32L4_DMACHAN_CCR_OFFSET+STM32L4_DMACHAN_OFFSET(n)) +#define STM32L4_DMA_CNDTR_OFFSET(n) (STM32L4_DMACHAN_CNDTR_OFFSET+STM32L4_DMACHAN_OFFSET(n)) +#define STM32L4_DMA_CPAR_OFFSET(n) (STM32L4_DMACHAN_CPAR_OFFSET+STM32L4_DMACHAN_OFFSET(n)) +#define STM32L4_DMA_CMAR_OFFSET(n) (STM32L4_DMACHAN_CMAR_OFFSET+STM32L4_DMACHAN_OFFSET(n)) + +#define STM32L4_DMA_CCR1_OFFSET 0x0008 /* DMA channel 1 configuration register */ +#define STM32L4_DMA_CCR2_OFFSET 0x001c /* DMA channel 2 configuration register */ +#define STM32L4_DMA_CCR3_OFFSET 0x0030 /* DMA channel 3 configuration register */ +#define STM32L4_DMA_CCR4_OFFSET 0x0044 /* DMA channel 4 configuration register */ +#define STM32L4_DMA_CCR5_OFFSET 0x0058 /* DMA channel 5 configuration register */ +#define STM32L4_DMA_CCR6_OFFSET 0x006c /* DMA channel 6 configuration register */ +#define STM32L4_DMA_CCR7_OFFSET 0x0080 /* DMA channel 7 configuration register */ + +#define STM32L4_DMA_CNDTR1_OFFSET 0x000c /* DMA channel 1 number of data register */ +#define STM32L4_DMA_CNDTR2_OFFSET 0x0020 /* DMA channel 2 number of data register */ +#define STM32L4_DMA_CNDTR3_OFFSET 0x0034 /* DMA channel 3 number of data register */ +#define STM32L4_DMA_CNDTR4_OFFSET 0x0048 /* DMA channel 4 number of data register */ +#define STM32L4_DMA_CNDTR5_OFFSET 0x005c /* DMA channel 5 number of data register */ +#define STM32L4_DMA_CNDTR6_OFFSET 0x0070 /* DMA channel 6 number of data register */ +#define STM32L4_DMA_CNDTR7_OFFSET 0x0084 /* DMA channel 7 number of data register */ + +#define STM32L4_DMA_CPAR1_OFFSET 0x0010 /* DMA channel 1 peripheral address register */ +#define STM32L4_DMA_CPAR2_OFFSET 0x0024 /* DMA channel 2 peripheral address register */ +#define STM32L4_DMA_CPAR3_OFFSET 0x0038 /* DMA channel 3 peripheral address register */ +#define STM32L4_DMA_CPAR4_OFFSET 0x004c /* DMA channel 4 peripheral address register */ +#define STM32L4_DMA_CPAR5_OFFSET 0x0060 /* DMA channel 5 peripheral address register */ +#define STM32L4_DMA_CPAR6_OFFSET 0x0074 /* DMA channel 6 peripheral address register */ +#define STM32L4_DMA_CPAR7_OFFSET 0x0088 /* DMA channel 7 peripheral address register */ + +#define STM32L4_DMA_CMAR1_OFFSET 0x0014 /* DMA channel 1 memory address register */ +#define STM32L4_DMA_CMAR2_OFFSET 0x0028 /* DMA channel 2 memory address register */ +#define STM32L4_DMA_CMAR3_OFFSET 0x003c /* DMA channel 3 memory address register */ +#define STM32L4_DMA_CMAR4_OFFSET 0x0050 /* DMA channel 4 memory address register */ +#define STM32L4_DMA_CMAR5_OFFSET 0x0064 /* DMA channel 5 memory address register */ +#define STM32L4_DMA_CMAR6_OFFSET 0x0078 /* DMA channel 6 memory address register */ +#define STM32L4_DMA_CMAR7_OFFSET 0x008c /* DMA channel 7 memory address register */ + +#define STM32L4_DMA_CSELR_OFFSET 0x00a8 /* DMA channel selection register */ + +/* Register Addresses ***************************************************************/ + +#define STM32L4_DMA1_ISRC (STM32L4_DMA1_BASE+STM32L4_DMA_ISR_OFFSET) +#define STM32L4_DMA1_IFCR (STM32L4_DMA1_BASE+STM32L4_DMA_IFCR_OFFSET) + +#define STM32L4_DMA1_CCR(n) (STM32L4_DMA1_BASE+STM32L4_DMA_CCR_OFFSET(n)) +#define STM32L4_DMA1_CCR1 (STM32L4_DMA1_BASE+STM32L4_DMA_CCR1_OFFSET) +#define STM32L4_DMA1_CCR2 (STM32L4_DMA1_BASE+STM32L4_DMA_CCR2_OFFSET) +#define STM32L4_DMA1_CCR3 (STM32L4_DMA1_BASE+STM32L4_DMA_CCR3_OFFSET) +#define STM32L4_DMA1_CCR4 (STM32L4_DMA1_BASE+STM32L4_DMA_CCR4_OFFSET) +#define STM32L4_DMA1_CCR5 (STM32L4_DMA1_BASE+STM32L4_DMA_CCR5_OFFSET) +#define STM32L4_DMA1_CCR6 (STM32L4_DMA1_BASE+STM32L4_DMA_CCR6_OFFSET) +#define STM32L4_DMA1_CCR7 (STM32L4_DMA1_BASE+STM32L4_DMA_CCR7_OFFSET) + +#define STM32L4_DMA1_CNDTR(n) (STM32L4_DMA1_BASE+STM32L4_DMA_CNDTR_OFFSET(n)) +#define STM32L4_DMA1_CNDTR1 (STM32L4_DMA1_BASE+STM32L4_DMA_CNDTR1_OFFSET) +#define STM32L4_DMA1_CNDTR2 (STM32L4_DMA1_BASE+STM32L4_DMA_CNDTR2_OFFSET) +#define STM32L4_DMA1_CNDTR3 (STM32L4_DMA1_BASE+STM32L4_DMA_CNDTR3_OFFSET) +#define STM32L4_DMA1_CNDTR4 (STM32L4_DMA1_BASE+STM32L4_DMA_CNDTR4_OFFSET) +#define STM32L4_DMA1_CNDTR5 (STM32L4_DMA1_BASE+STM32L4_DMA_CNDTR5_OFFSET) +#define STM32L4_DMA1_CNDTR6 (STM32L4_DMA1_BASE+STM32L4_DMA_CNDTR6_OFFSET) +#define STM32L4_DMA1_CNDTR7 (STM32L4_DMA1_BASE+STM32L4_DMA_CNDTR7_OFFSET) + +#define STM32L4_DMA1_CPAR(n) (STM32L4_DMA1_BASE+STM32L4_DMA_CPAR_OFFSET(n)) +#define STM32L4_DMA1_CPAR1 (STM32L4_DMA1_BASE+STM32L4_DMA_CPAR1_OFFSET) +#define STM32L4_DMA1_CPAR2 (STM32L4_DMA1_BASE+STM32L4_DMA_CPAR2_OFFSET) +#define STM32L4_DMA1_CPAR3 (STM32L4_DMA1_BASE+STM32L4_DMA_CPAR3_OFFSET) +#define STM32L4_DMA1_CPAR4 (STM32L4_DMA1_BASE+STM32L4_DMA_CPAR4_OFFSET) +#define STM32L4_DMA1_CPAR5 (STM32L4_DMA1_BASE+STM32L4_DMA_CPAR5_OFFSET) +#define STM32L4_DMA1_CPAR6 (STM32L4_DMA1_BASE+STM32L4_DMA_CPAR6_OFFSET) +#define STM32L4_DMA1_CPAR7 (STM32L4_DMA1_BASE+STM32L4_DMA_CPAR7_OFFSET) + +#define STM32L4_DMA1_CMAR(n) (STM32L4_DMA1_BASE+STM32L4_DMA_CMAR_OFFSET(n)) +#define STM32L4_DMA1_CMAR1 (STM32L4_DMA1_BASE+STM32L4_DMA_CMAR1_OFFSET) +#define STM32L4_DMA1_CMAR2 (STM32L4_DMA1_BASE+STM32L4_DMA_CMAR2_OFFSET) +#define STM32L4_DMA1_CMAR3 (STM32L4_DMA1_BASE+STM32L4_DMA_CMAR3_OFFSET) +#define STM32L4_DMA1_CMAR4 (STM32L4_DMA1_BASE+STM32L4_DMA_CMAR4_OFFSET) +#define STM32L4_DMA1_CMAR5 (STM32L4_DMA1_BASE+STM32L4_DMA_CMAR5_OFFSET) +#define STM32L4_DMA1_CMAR6 (STM32L4_DMA1_BASE+STM32L4_DMA_CMAR6_OFFSET) +#define STM32L4_DMA1_CMAR7 (STM32L4_DMA1_BASE+STM32L4_DMA_CMAR7_OFFSET) + +#define STM32L4_DMA2_ISRC (STM32L4_DMA2_BASE+STM32L4_DMA_ISR_OFFSET) +#define STM32L4_DMA2_IFCR (STM32L4_DMA2_BASE+STM32L4_DMA_IFCR_OFFSET) + +#define STM32L4_DMA2_CCR(n) (STM32L4_DMA2_BASE+STM32L4_DMA_CCR_OFFSET(n)) +#define STM32L4_DMA2_CCR1 (STM32L4_DMA2_BASE+STM32L4_DMA_CCR1_OFFSET) +#define STM32L4_DMA2_CCR2 (STM32L4_DMA2_BASE+STM32L4_DMA_CCR2_OFFSET) +#define STM32L4_DMA2_CCR3 (STM32L4_DMA2_BASE+STM32L4_DMA_CCR3_OFFSET) +#define STM32L4_DMA2_CCR4 (STM32L4_DMA2_BASE+STM32L4_DMA_CCR4_OFFSET) +#define STM32L4_DMA2_CCR5 (STM32L4_DMA2_BASE+STM32L4_DMA_CCR5_OFFSET) +#define STM32L4_DMA2_CCR6 (STM32L4_DMA2_BASE+STM32L4_DMA_CCR6_OFFSET) +#define STM32L4_DMA2_CCR7 (STM32L4_DMA2_BASE+STM32L4_DMA_CCR7_OFFSET) + +#define STM32L4_DMA2_CNDTR(n) (STM32L4_DMA2_BASE+STM32L4_DMA_CNDTR_OFFSET(n)) +#define STM32L4_DMA2_CNDTR1 (STM32L4_DMA2_BASE+STM32L4_DMA_CNDTR1_OFFSET) +#define STM32L4_DMA2_CNDTR2 (STM32L4_DMA2_BASE+STM32L4_DMA_CNDTR2_OFFSET) +#define STM32L4_DMA2_CNDTR3 (STM32L4_DMA2_BASE+STM32L4_DMA_CNDTR3_OFFSET) +#define STM32L4_DMA2_CNDTR4 (STM32L4_DMA2_BASE+STM32L4_DMA_CNDTR4_OFFSET) +#define STM32L4_DMA2_CNDTR5 (STM32L4_DMA2_BASE+STM32L4_DMA_CNDTR5_OFFSET) +#define STM32L4_DMA2_CNDTR6 (STM32L4_DMA2_BASE+STM32L4_DMA_CNDTR6_OFFSET) +#define STM32L4_DMA2_CNDTR7 (STM32L4_DMA2_BASE+STM32L4_DMA_CNDTR7_OFFSET) + +#define STM32L4_DMA2_CPAR(n) (STM32L4_DMA2_BASE+STM32L4_DMA_CPAR_OFFSET(n)) +#define STM32L4_DMA2_CPAR1 (STM32L4_DMA2_BASE+STM32L4_DMA_CPAR1_OFFSET) +#define STM32L4_DMA2_CPAR2 (STM32L4_DMA2_BASE+STM32L4_DMA_CPAR2_OFFSET) +#define STM32L4_DMA2_CPAR3 (STM32L4_DMA2_BASE+STM32L4_DMA_CPAR3_OFFSET) +#define STM32L4_DMA2_CPAR4 (STM32L4_DMA2_BASE+STM32L4_DMA_CPAR4_OFFSET) +#define STM32L4_DMA2_CPAR5 (STM32L4_DMA2_BASE+STM32L4_DMA_CPAR5_OFFSET) +#define STM32L4_DMA2_CPAR6 (STM32L4_DMA2_BASE+STM32L4_DMA_CPAR6_OFFSET) +#define STM32L4_DMA2_CPAR7 (STM32L4_DMA2_BASE+STM32L4_DMA_CPAR7_OFFSET) + +#define STM32L4_DMA2_CMAR(n) (STM32L4_DMA2_BASE+STM32L4_DMA_CMAR_OFFSET(n)) +#define STM32L4_DMA2_CMAR1 (STM32L4_DMA2_BASE+STM32L4_DMA_CMAR1_OFFSET) +#define STM32L4_DMA2_CMAR2 (STM32L4_DMA2_BASE+STM32L4_DMA_CMAR2_OFFSET) +#define STM32L4_DMA2_CMAR3 (STM32L4_DMA2_BASE+STM32L4_DMA_CMAR3_OFFSET) +#define STM32L4_DMA2_CMAR4 (STM32L4_DMA2_BASE+STM32L4_DMA_CMAR4_OFFSET) +#define STM32L4_DMA2_CMAR5 (STM32L4_DMA2_BASE+STM32L4_DMA_CMAR5_OFFSET) +#define STM32L4_DMA2_CMAR6 (STM32L4_DMA2_BASE+STM32L4_DMA_CMAR6_OFFSET) +#define STM32L4_DMA2_CMAR7 (STM32L4_DMA2_BASE+STM32L4_DMA_CMAR7_OFFSET) + +/* Register Bitfield Definitions ****************************************************/ + +#define DMA_CHAN_SHIFT(n) ((n) << 2) +#define DMA_CHAN_MASK 0x0f +#define DMA_CHAN_GIF_BIT (1 << 0) /* Bit 0: Channel Global interrupt flag */ +#define DMA_CHAN_TCIF_BIT (1 << 1) /* Bit 1: Channel Transfer Complete flag */ +#define DMA_CHAN_HTIF_BIT (1 << 2) /* Bit 2: Channel Half Transfer flag */ +#define DMA_CHAN_TEIF_BIT (1 << 3) /* Bit 3: Channel Transfer Error flag */ + +/* DMA interrupt status register */ + +#define DMA_ISR_CHAN_SHIFT(n) DMA_CHAN_SHIFT(n) +#define DMA_ISR_CHAN_MASK(n) (DMA_CHAN_MASK << DMA_ISR_CHAN_SHIFT(n)) +#define DMA_ISR_CHAN1_SHIFT (0) /* Bits 3-0: DMA Channel 1 interrupt status */ +#define DMA_ISR_CHAN1_MASK (DMA_CHAN_MASK << DMA_ISR_CHAN1_SHIFT) +#define DMA_ISR_CHAN2_SHIFT (4) /* Bits 7-4: DMA Channel 2 interrupt status */ +#define DMA_ISR_CHAN2_MASK (DMA_CHAN_MASK << DMA_ISR_CHAN2_SHIFT) +#define DMA_ISR_CHAN3_SHIFT (8) /* Bits 11-8: DMA Channel 3 interrupt status */ +#define DMA_ISR_CHAN3_MASK (DMA_CHAN_MASK << DMA_ISR_CHAN3_SHIFT) +#define DMA_ISR_CHAN4_SHIFT (12) /* Bits 15-12: DMA Channel 4 interrupt status */ +#define DMA_ISR_CHAN4_MASK (DMA_CHAN_MASK << DMA_ISR_CHAN4_SHIFT) +#define DMA_ISR_CHAN5_SHIFT (16) /* Bits 19-16: DMA Channel 5 interrupt status */ +#define DMA_ISR_CHAN5_MASK (DMA_CHAN_MASK << DMA_ISR_CHAN5_SHIFT) +#define DMA_ISR_CHAN6_SHIFT (20) /* Bits 23-20: DMA Channel 6 interrupt status */ +#define DMA_ISR_CHAN6_MASK (DMA_CHAN_MASK << DMA_ISR_CHAN6_SHIFT) +#define DMA_ISR_CHAN7_SHIFT (24) /* Bits 27-24: DMA Channel 7 interrupt status */ +#define DMA_ISR_CHAN7_MASK (DMA_CHAN_MASK << DMA_ISR_CHAN7_SHIFT) + +#define DMA_ISR_GIF(n) (DMA_CHAN_GIF_BIT << DMA_ISR_CHAN_SHIFT(n)) +#define DMA_ISR_TCIF(n) (DMA_CHAN_TCIF_BIT << DMA_ISR_CHAN_SHIFT(n)) +#define DMA_ISR_HTIF(n) (DMA_CHAN_HTIF_BIT << DMA_ISR_CHAN_SHIFT(n)) +#define DMA_ISR_TEIF(n) (DMA_CHAN_TEIF_BIT << DMA_ISR_CHAN_SHIFT(n)) + +/* DMA interrupt flag clear register */ + +#define DMA_IFCR_CHAN_SHIFT(n) DMA_CHAN_SHIFT(n) +#define DMA_IFCR_CHAN_MASK(n) (DMA_CHAN_MASK << DMA_IFCR_CHAN_SHIFT(n)) +#define DMA_IFCR_CHAN1_SHIFT (0) /* Bits 3-0: DMA Channel 1 interrupt flag clear */ +#define DMA_IFCR_CHAN1_MASK (DMA_CHAN_MASK << DMA_IFCR_CHAN1_SHIFT) +#define DMA_IFCR_CHAN2_SHIFT (4) /* Bits 7-4: DMA Channel 2 interrupt flag clear */ +#define DMA_IFCR_CHAN2_MASK (DMA_CHAN_MASK << DMA_IFCR_CHAN2_SHIFT) +#define DMA_IFCR_CHAN3_SHIFT (8) /* Bits 11-8: DMA Channel 3 interrupt flag clear */ +#define DMA_IFCR_CHAN3_MASK (DMA_CHAN_MASK << DMA_IFCR_CHAN3_SHIFT) +#define DMA_IFCR_CHAN4_SHIFT (12) /* Bits 15-12: DMA Channel 4 interrupt flag clear */ +#define DMA_IFCR_CHAN4_MASK (DMA_CHAN_MASK << DMA_IFCR_CHAN4_SHIFT) +#define DMA_IFCR_CHAN5_SHIFT (16) /* Bits 19-16: DMA Channel 5 interrupt flag clear */ +#define DMA_IFCR_CHAN5_MASK (DMA_CHAN_MASK << DMA_IFCR_CHAN5_SHIFT) +#define DMA_IFCR_CHAN6_SHIFT (20) /* Bits 23-20: DMA Channel 6 interrupt flag clear */ +#define DMA_IFCR_CHAN6_MASK (DMA_CHAN_MASK << DMA_IFCR_CHAN6_SHIFT) +#define DMA_IFCR_CHAN7_SHIFT (24) /* Bits 27-24: DMA Channel 7 interrupt flag clear */ +#define DMA_IFCR_CHAN7_MASK (DMA_CHAN_MASK << DMA_IFCR_CHAN7_SHIFT) +#define DMA_IFCR_ALLCHANNELS (0x0fffffff) + +#define DMA_IFCR_CGIF(n) (DMA_CHAN_GIF_BIT << DMA_IFCR_CHAN_SHIFT(n)) +#define DMA_IFCR_CTCIF(n) (DMA_CHAN_TCIF_BIT << DMA_IFCR_CHAN_SHIFT(n)) +#define DMA_IFCR_CHTIF(n) (DMA_CHAN_HTIF_BIT << DMA_IFCR_CHAN_SHIFT(n)) +#define DMA_IFCR_CTEIF(n) (DMA_CHAN_TEIF_BIT << DMA_IFCR_CHAN_SHIFT(n)) + +/* DMA channel configuration register */ + +#define DMA_CCR_EN (1 << 0) /* Bit 0: Channel enable */ +#define DMA_CCR_TCIE (1 << 1) /* Bit 1: Transfer complete interrupt enable */ +#define DMA_CCR_HTIE (1 << 2) /* Bit 2: Half Transfer interrupt enable */ +#define DMA_CCR_TEIE (1 << 3) /* Bit 3: Transfer error interrupt enable */ +#define DMA_CCR_DIR (1 << 4) /* Bit 4: Data transfer direction */ +#define DMA_CCR_CIRC (1 << 5) /* Bit 5: Circular mode */ +#define DMA_CCR_PINC (1 << 6) /* Bit 6: Peripheral increment mode */ +#define DMA_CCR_MINC (1 << 7) /* Bit 7: Memory increment mode */ +#define DMA_CCR_PSIZE_SHIFT (8) /* Bits 8-9: Peripheral size */ +#define DMA_CCR_PSIZE_MASK (3 << DMA_CCR_PSIZE_SHIFT) +# define DMA_CCR_PSIZE_8BITS (0 << DMA_CCR_PSIZE_SHIFT) /* 00: 8-bits */ +# define DMA_CCR_PSIZE_16BITS (1 << DMA_CCR_PSIZE_SHIFT) /* 01: 16-bits */ +# define DMA_CCR_PSIZE_32BITS (2 << DMA_CCR_PSIZE_SHIFT) /* 10: 32-bits */ +#define DMA_CCR_MSIZE_SHIFT (10) /* Bits 10-11: Memory size */ +#define DMA_CCR_MSIZE_MASK (3 << DMA_CCR_MSIZE_SHIFT) +# define DMA_CCR_MSIZE_8BITS (0 << DMA_CCR_MSIZE_SHIFT) /* 00: 8-bits */ +# define DMA_CCR_MSIZE_16BITS (1 << DMA_CCR_MSIZE_SHIFT) /* 01: 16-bits */ +# define DMA_CCR_MSIZE_32BITS (2 << DMA_CCR_MSIZE_SHIFT) /* 10: 32-bits */ +#define DMA_CCR_PL_SHIFT (12) /* Bits 12-13: Channel Priority level */ +#define DMA_CCR_PL_MASK (3 << DMA_CCR_PL_SHIFT) +# define DMA_CCR_PRILO (0 << DMA_CCR_PL_SHIFT) /* 00: Low */ +# define DMA_CCR_PRIMED (1 << DMA_CCR_PL_SHIFT) /* 01: Medium */ +# define DMA_CCR_PRIHI (2 << DMA_CCR_PL_SHIFT) /* 10: High */ +# define DMA_CCR_PRIVERYHI (3 << DMA_CCR_PL_SHIFT) /* 11: Very high */ +#define DMA_CCR_MEM2MEM (1 << 14) /* Bit 14: Memory to memory mode */ + +#define DMA_CCR_ALLINTS (DMA_CCR_TEIE|DMA_CCR_HTIE|DMA_CCR_TCIE) + +/* DMA channel number of data register */ + +#define DMA_CNDTR_NDT_SHIFT (0) /* Bits 15-0: Number of data to Transfer */ +#define DMA_CNDTR_NDT_MASK (0xffff << DMA_CNDTR_NDT_SHIFT) + +/* DMA Channel mapping. Each DMA channel has a mapping to one of several + * possible sources/sinks of data. The requests from peripherals assigned to a + * channel are multiplexed together before entering the DMA block. This means + * that only one request on a given channel can be enabled at once. + * + * Alternative DMA channel selections are provided with a numeric suffix like _1, + * _2, etc. Drivers, however, will use the pin selection without the numeric suffix. + * Additional definitions are required in the board.h file. + */ + +#define STM32L4_DMA1_CHAN1 (0) +#define STM32L4_DMA1_CHAN2 (1) +#define STM32L4_DMA1_CHAN3 (2) +#define STM32L4_DMA1_CHAN4 (3) +#define STM32L4_DMA1_CHAN5 (4) +#define STM32L4_DMA1_CHAN6 (5) +#define STM32L4_DMA1_CHAN7 (6) + +#define STM32L4_DMA2_CHAN1 (7) +#define STM32L4_DMA2_CHAN2 (8) +#define STM32L4_DMA2_CHAN3 (9) +#define STM32L4_DMA2_CHAN4 (10) +#define STM32L4_DMA2_CHAN5 (11) +#define STM32L4_DMA2_CHAN6 (12) +#define STM32L4_DMA2_CHAN7 (13) + +/* DMA Channel settings include a channel and an alternative function. + * Channel is in bits 0..7 + * Request number is in bits 8..15 + */ + +#define DMACHAN_SETTING(chan, req) ((((req) & 0xff) << 8) | ((chan) & 0xff)) +#define DMACHAN_SETTING_CHANNEL_MASK 0x00FF +#define DMACHAN_SETTING_CHANNEL_SHIFT (0) +#define DMACHAN_SETTING_FUNCTION_MASK 0xFF00 +#define DMACHAN_SETTING_FUNCTION_SHIFT (8) + +/* ADC */ + +#define DMACHAN_ADC1_1 DMACHAN_SETTING(STM32L4_DMA1_CHAN1, 0) +#define DMACHAN_ADC1_2 DMACHAN_SETTING(STM32L4_DMA2_CHAN3, 0) + +/* AES */ + +#define DMACHAN_AES_IN_1 DMACHAN_SETTING(STM32L4_DMA2_CHAN1, 6) +#define DMACHAN_AES_IN_2 DMACHAN_SETTING(STM32L4_DMA2_CHAN5, 6) +#define DMACHAN_AES_OUT_1 DMACHAN_SETTING(STM32L4_DMA2_CHAN2, 6) +#define DMACHAN_AES_OUT_2 DMACHAN_SETTING(STM32L4_DMA2_CHAN3, 6) + +/* DAC */ + +#define DMACHAN_DAC1_1 DMACHAN_SETTING(STM32L4_DMA1_CHAN3, 6) +#define DMACHAN_DAC1_2 DMACHAN_SETTING(STM32L4_DMA1_CHAN4, 5) +#define DMACHAN_DAC1_3 DMACHAN_SETTING(STM32L4_DMA2_CHAN4, 3) + +/* DCMI */ + +#define DMACHAN_DCMI_1 DMACHAN_SETTING(STM32L4_DMA2_CHAN5, 4) +#define DMACHAN_DCMI_2 DMACHAN_SETTING(STM32L4_DMA2_CHAN6, 0) + +/* DFSDM */ + +#define DMACHAN_DFSDM1_FLT0 DMACHAN_SETTING(STM32L4_DMA1_CHAN5, 0) +#define DMACHAN_DFSDM1_FLT1 DMACHAN_SETTING(STM32L4_DMA1_CHAN6, 0) + +/* I2C */ + +#define DMACHAN_I2C1_RX_1 DMACHAN_SETTING(STM32L4_DMA1_CHAN7, 3) +#define DMACHAN_I2C1_RX_2 DMACHAN_SETTING(STM32L4_DMA2_CHAN6, 5) +#define DMACHAN_I2C1_TX_1 DMACHAN_SETTING(STM32L4_DMA1_CHAN6, 3) +#define DMACHAN_I2C1_TX_2 DMACHAN_SETTING(STM32L4_DMA2_CHAN7, 5) + +#define DMACHAN_I2C2_RX DMACHAN_SETTING(STM32L4_DMA1_CHAN5, 3) +#define DMACHAN_I2C2_TX DMACHAN_SETTING(STM32L4_DMA1_CHAN4, 3) + +#define DMACHAN_I2C3_RX DMACHAN_SETTING(STM32L4_DMA1_CHAN3, 2) +#define DMACHAN_I2C3_TX DMACHAN_SETTING(STM32L4_DMA1_CHAN2, 3) + +#define DMACHAN_I2C4_RX DMACHAN_SETTING(STM32L4_DMA2_CHAN1, 0) +#define DMACHAN_I2C4_TX DMACHAN_SETTING(STM32L4_DMA2_CHAN2, 0) + +/* QUADSPI */ + +#define DMACHAN_QUADSPI_1 DMACHAN_SETTING(STM32L4_DMA1_CHAN5, 5) +#define DMACHAN_QUADSPI_2 DMACHAN_SETTING(STM32L4_DMA2_CHAN7, 3) + +/* SAI */ + +#define DMACHAN_SAI1_A_1 DMACHAN_SETTING(STM32L4_DMA2_CHAN1, 1) +#define DMACHAN_SAI1_A_2 DMACHAN_SETTING(STM32L4_DMA2_CHAN6, 1) +#define DMACHAN_SAI1_B_1 DMACHAN_SETTING(STM32L4_DMA2_CHAN2, 1) +#define DMACHAN_SAI1_B_2 DMACHAN_SETTING(STM32L4_DMA2_CHAN7, 1) + +#define DMACHAN_SAI2_A_1 DMACHAN_SETTING(STM32L4_DMA1_CHAN6, 1) +#define DMACHAN_SAI2_A_2 DMACHAN_SETTING(STM32L4_DMA2_CHAN3, 1) +#define DMACHAN_SAI2_B_1 DMACHAN_SETTING(STM32L4_DMA1_CHAN7, 1) +#define DMACHAN_SAI2_B_2 DMACHAN_SETTING(STM32L4_DMA2_CHAN4, 1) + +/* SDMMC */ + +#define DMACHAN_SDMMC_1 DMACHAN_SETTING(STM32L4_DMA2_CHAN4, 7) +#define DMACHAN_SDMMC_2 DMACHAN_SETTING(STM32L4_DMA2_CHAN5, 7) + +/* SPI */ + +#define DMACHAN_SPI1_RX_1 DMACHAN_SETTING(STM32L4_DMA1_CHAN2, 1) +#define DMACHAN_SPI1_RX_2 DMACHAN_SETTING(STM32L4_DMA2_CHAN3, 4) +#define DMACHAN_SPI1_TX_1 DMACHAN_SETTING(STM32L4_DMA1_CHAN3, 1) +#define DMACHAN_SPI1_TX_2 DMACHAN_SETTING(STM32L4_DMA2_CHAN4, 4) + +#define DMACHAN_SPI2_RX DMACHAN_SETTING(STM32L4_DMA1_CHAN4, 1) +#define DMACHAN_SPI2_TX DMACHAN_SETTING(STM32L4_DMA1_CHAN5, 1) + +#define DMACHAN_SPI3_RX DMACHAN_SETTING(STM32L4_DMA2_CHAN1, 3) +#define DMACHAN_SPI3_TX DMACHAN_SETTING(STM32L4_DMA2_CHAN2, 3) + +/* SWPMI */ + +#define DMACHAN_SWPMI_RX DMACHAN_SETTING(STM32L4_DMA2_CHAN1, 4) +#define DMACHAN_SWPMI_TX DMACHAN_SETTING(STM32L4_DMA2_CHAN2, 4) + +/* TIM */ + +#define DMACHAN_TIM1_CH1 DMACHAN_SETTING(STM32L4_DMA1_CHAN2, 7) +#define DMACHAN_TIM1_CH2 DMACHAN_SETTING(STM32L4_DMA1_CHAN3, 7) +#define DMACHAN_TIM1_CH3 DMACHAN_SETTING(STM32L4_DMA1_CHAN7, 7) +#define DMACHAN_TIM1_CH4 DMACHAN_SETTING(STM32L4_DMA1_CHAN4, 7) +#define DMACHAN_TIM1_COM DMACHAN_SETTING(STM32L4_DMA1_CHAN4, 7) +#define DMACHAN_TIM1_TRIG DMACHAN_SETTING(STM32L4_DMA1_CHAN4, 7) +#define DMACHAN_TIM1_UP DMACHAN_SETTING(STM32L4_DMA1_CHAN6, 7) + +#define DMACHAN_TIM2_CH1 DMACHAN_SETTING(STM32L4_DMA1_CHAN5, 4) +#define DMACHAN_TIM2_CH2 DMACHAN_SETTING(STM32L4_DMA1_CHAN7, 4) +#define DMACHAN_TIM2_CH3 DMACHAN_SETTING(STM32L4_DMA1_CHAN1, 4) +#define DMACHAN_TIM2_CH4 DMACHAN_SETTING(STM32L4_DMA1_CHAN7, 4) +#define DMACHAN_TIM2_UP DMACHAN_SETTING(STM32L4_DMA1_CHAN2, 4) + +#define DMACHAN_TIM3_CH1 DMACHAN_SETTING(STM32L4_DMA1_CHAN6, 5) +#define DMACHAN_TIM3_CH3 DMACHAN_SETTING(STM32L4_DMA1_CHAN2, 5) +#define DMACHAN_TIM3_CH4 DMACHAN_SETTING(STM32L4_DMA1_CHAN3, 5) +#define DMACHAN_TIM3_TRIG DMACHAN_SETTING(STM32L4_DMA1_CHAN6, 5) +#define DMACHAN_TIM3_UP DMACHAN_SETTING(STM32L4_DMA1_CHAN3, 5) + +#define DMACHAN_TIM6_UP_1 DMACHAN_SETTING(STM32L4_DMA1_CHAN3, 6) +#define DMACHAN_TIM6_UP_2 DMACHAN_SETTING(STM32L4_DMA2_CHAN4, 3) + +#define DMACHAN_TIM7_UP_1 DMACHAN_SETTING(STM32L4_DMA1_CHAN4, 5) +#define DMACHAN_TIM7_UP_2 DMACHAN_SETTING(STM32L4_DMA2_CHAN5, 3) + +#define DMACHAN_TIM15_CH1 DMACHAN_SETTING(STM32L4_DMA1_CHAN5, 7) +#define DMACHAN_TIM15_COM DMACHAN_SETTING(STM32L4_DMA1_CHAN5, 7) +#define DMACHAN_TIM15_TRIG DMACHAN_SETTING(STM32L4_DMA1_CHAN5, 7) +#define DMACHAN_TIM15_UP DMACHAN_SETTING(STM32L4_DMA1_CHAN5, 7) + +#define DMACHAN_TIM16_CH1_1 DMACHAN_SETTING(STM32L4_DMA1_CHAN3, 4) +#define DMACHAN_TIM16_CH1_2 DMACHAN_SETTING(STM32L4_DMA1_CHAN6, 4) +#define DMACHAN_TIM16_UP_1 DMACHAN_SETTING(STM32L4_DMA1_CHAN3, 4) +#define DMACHAN_TIM16_UP_2 DMACHAN_SETTING(STM32L4_DMA1_CHAN6, 4) + +/* UART */ + +#define DMACHAN_USART1_RX_1 DMACHAN_SETTING(STM32L4_DMA1_CHAN5, 2) +#define DMACHAN_USART1_RX_2 DMACHAN_SETTING(STM32L4_DMA2_CHAN7, 2) +#define DMACHAN_USART1_TX_1 DMACHAN_SETTING(STM32L4_DMA1_CHAN4, 2) +#define DMACHAN_USART1_TX_2 DMACHAN_SETTING(STM32L4_DMA2_CHAN6, 2) + +#define DMACHAN_USART2_RX DMACHAN_SETTING(STM32L4_DMA1_CHAN6, 2) +#define DMACHAN_USART2_TX DMACHAN_SETTING(STM32L4_DMA1_CHAN7, 2) + +#define DMACHAN_USART3_RX DMACHAN_SETTING(STM32L4_DMA1_CHAN3, 1) +#define DMACHAN_USART3_TX DMACHAN_SETTING(STM32L4_DMA1_CHAN2, 2) + +#define DMACHAN_UART4_RX DMACHAN_SETTING(STM32L4_DMA2_CHAN5, 2) +#define DMACHAN_UART4_TX DMACHAN_SETTING(STM32L4_DMA2_CHAN3, 2) + +#define DMACHAN_LPUART_RX DMACHAN_SETTING(STM32L4_DMA2_CHAN7, 4) +#define DMACHAN_LPUART_TX DMACHAN_SETTING(STM32L4_DMA2_CHAN6, 4) + +#endif /* __ARCH_ARM_SRC_STM32L4_CHIP_STM32L4X3XX_DMA_H */ diff --git a/arch/arm/src/stm32l4/chip/stm32l4x3xx_pinmap.h b/arch/arm/src/stm32l4/chip/stm32l4x3xx_pinmap.h new file mode 100644 index 00000000000..5820f2a009f --- /dev/null +++ b/arch/arm/src/stm32l4/chip/stm32l4x3xx_pinmap.h @@ -0,0 +1,559 @@ +/************************************************************************************ + * arch/arm/src/stm32l4/chip/stm32l4x3xx_pinmap.h + * + * Copyright (C) 2015-2016 Sebastien Lorquet. All rights reserved. + * Authors: Sebastien Lorquet + * Juha Niskanen + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ************************************************************************************/ + +#ifndef __ARCH_ARM_SRC_STM32L4_CHIP_STM32L4X3XX_PINMAP_H +#define __ARCH_ARM_SRC_STM32L4_CHIP_STM32L4X3XX_PINMAP_H + +/************************************************************************************ + * Included Files + ************************************************************************************/ + +#include + +#include "stm32l4_gpio.h" + +/************************************************************************************ + * Pre-processor Definitions + ************************************************************************************/ + +/* Alternate Pin Functions. All members of the STM32L4xxx family share the same + * pin multiplexing (although they may differ in the pins physically available). + * + * Alternative pin selections are provided with a numeric suffix like _1, _2, etc. + * Drivers, however, will use the pin selection without the numeric suffix. + * Additional definitions are required in the board.h file. For example, if + * CAN1_RX connects vis PA11 on some board, then the following definitions should + * appear inthe board.h header file for that board: + * + * #define GPIO_CAN1_RX GPIO_CAN1_RX_1 + * + * The driver will then automatically configre PA11 as the CAN1 RX pin. + */ + +/* WARNING!!! WARNING!!! WARNING!!! WARNING!!! WARNING!!! WARNING!!! WARNING!!! + * Additional effort is required to select specific GPIO options such as frequency, + * open-drain/push-pull, and pull-up/down! Just the basics are defined for most + * pins in this file. + */ + +/* ADC */ + +#define GPIO_ADC1_IN1 (GPIO_ANALOG|GPIO_PORTC|GPIO_PIN0) +#define GPIO_ADC1_IN2 (GPIO_ANALOG|GPIO_PORTC|GPIO_PIN1) +#define GPIO_ADC1_IN3 (GPIO_ANALOG|GPIO_PORTC|GPIO_PIN2) +#define GPIO_ADC1_IN4 (GPIO_ANALOG|GPIO_PORTC|GPIO_PIN3) +#define GPIO_ADC1_IN5 (GPIO_ANALOG|GPIO_PORTA|GPIO_PIN0) +#define GPIO_ADC1_IN6 (GPIO_ANALOG|GPIO_PORTA|GPIO_PIN1) +#define GPIO_ADC1_IN7 (GPIO_ANALOG|GPIO_PORTA|GPIO_PIN2) +#define GPIO_ADC1_IN8 (GPIO_ANALOG|GPIO_PORTA|GPIO_PIN3) +#define GPIO_ADC1_IN9 (GPIO_ANALOG|GPIO_PORTA|GPIO_PIN4) +#define GPIO_ADC1_IN10 (GPIO_ANALOG|GPIO_PORTA|GPIO_PIN5) +#define GPIO_ADC1_IN11 (GPIO_ANALOG|GPIO_PORTA|GPIO_PIN6) +#define GPIO_ADC1_IN12 (GPIO_ANALOG|GPIO_PORTA|GPIO_PIN7) +#define GPIO_ADC1_IN13 (GPIO_ANALOG|GPIO_PORTC|GPIO_PIN4) +#define GPIO_ADC1_IN14 (GPIO_ANALOG|GPIO_PORTC|GPIO_PIN5) +#define GPIO_ADC1_IN15 (GPIO_ANALOG|GPIO_PORTB|GPIO_PIN0) +#define GPIO_ADC1_IN16 (GPIO_ANALOG|GPIO_PORTB|GPIO_PIN1) + +/* CAN */ + +#define GPIO_CAN1_RX_1 (GPIO_ALT|GPIO_AF9 |GPIO_PORTA|GPIO_PIN11) +#define GPIO_CAN1_RX_2 (GPIO_ALT|GPIO_AF3 |GPIO_PORTB|GPIO_PIN5) +#define GPIO_CAN1_RX_3 (GPIO_ALT|GPIO_AF9 |GPIO_PORTB|GPIO_PIN8) +#define GPIO_CAN1_RX_4 (GPIO_ALT|GPIO_AF10 |GPIO_PORTB|GPIO_PIN12) +#define GPIO_CAN1_RX_5 (GPIO_ALT|GPIO_AF9 |GPIO_PORTD|GPIO_PIN0) +#define GPIO_CAN1_TX_1 (GPIO_ALT|GPIO_AF9 |GPIO_PORTA|GPIO_PIN12) +#define GPIO_CAN1_TX_2 (GPIO_ALT|GPIO_AF8 |GPIO_PORTB|GPIO_PIN6) +#define GPIO_CAN1_TX_3 (GPIO_ALT|GPIO_AF9 |GPIO_PORTB|GPIO_PIN9) +#define GPIO_CAN1_TX_4 (GPIO_ALT|GPIO_AF10 |GPIO_PORTB|GPIO_PIN13) +#define GPIO_CAN1_TX_5 (GPIO_ALT|GPIO_AF9 |GPIO_PORTD|GPIO_PIN1) + +/* Clocks outputs */ + +#define GPIO_MCO (GPIO_ALT|GPIO_AF0 |GPIO_PORTA|GPIO_PIN8) + +/* Comparators */ + +#define GPIO_COMP1_INM_1 (GPIO_ANALOG|GPIO_PORTA|GPIO_PIN0) +#define GPIO_COMP1_INM_2 (GPIO_ANALOG|GPIO_PORTB|GPIO_PIN1) +#define GPIO_COMP1_INM_3 (GPIO_ANALOG|GPIO_PORTC|GPIO_PIN4) +#define GPIO_COMP1_INP_1 (GPIO_ANALOG|GPIO_PORTA|GPIO_PIN1) +#define GPIO_COMP1_INP_2 (GPIO_ANALOG|GPIO_PORTB|GPIO_PIN2) +#define GPIO_COMP1_INP_3 (GPIO_ANALOG|GPIO_PORTC|GPIO_PIN5) +#define GPIO_COMP1_OUT_1 (GPIO_ALT|GPIO_AF6|GPIO_PORTA|GPIO_PIN6) +#define GPIO_COMP1_OUT_2 (GPIO_ALT|GPIO_AF6|GPIO_PORTA|GPIO_PIN11) +#define GPIO_COMP1_OUT_3 (GPIO_ALT|GPIO_AF12|GPIO_PORTA|GPIO_PIN0) +#define GPIO_COMP1_OUT_4 (GPIO_ALT|GPIO_AF12|GPIO_PORTB|GPIO_PIN0) +#define GPIO_COMP1_OUT_5 (GPIO_ALT|GPIO_AF12|GPIO_PORTB|GPIO_PIN10) + +#define GPIO_COMP2_INM_1 (GPIO_ANALOG|GPIO_PORTA|GPIO_PIN2) +#define GPIO_COMP2_INM_2 (GPIO_ANALOG|GPIO_PORTB|GPIO_PIN3) +#define GPIO_COMP2_INM_3 (GPIO_ANALOG|GPIO_PORTB|GPIO_PIN7) +#define GPIO_COMP2_INP_1 (GPIO_ANALOG|GPIO_PORTA|GPIO_PIN3) +#define GPIO_COMP2_INP_2 (GPIO_ANALOG|GPIO_PORTB|GPIO_PIN4) +#define GPIO_COMP2_INP_3 (GPIO_ANALOG|GPIO_PORTB|GPIO_PIN6) +#define GPIO_COMP2_OUT_1 (GPIO_ALT|GPIO_AF12|GPIO_PORTA|GPIO_PIN2) +#define GPIO_COMP2_OUT_2 (GPIO_ALT|GPIO_AF12|GPIO_PORTA|GPIO_PIN7) +#define GPIO_COMP2_OUT_3 (GPIO_ALT|GPIO_AF12|GPIO_PORTB|GPIO_PIN5) +#define GPIO_COMP2_OUT_4 (GPIO_ALT|GPIO_AF12|GPIO_PORTB|GPIO_PIN11) + +/* DAC */ + +#define GPIO_DAC1_OUT (GPIO_ANALOG|GPIO_PORTA|GPIO_PIN4) + +/* Digital Filter for Sigma-Delta Modulators (DFSDM) */ + +#define GPIO_DFSDM_DATIN0_1 (GPIO_ALT|GPIO_AF6 |GPIO_PORTB|GPIO_PIN1) +#define GPIO_DFSDM_DATIN0_2 (GPIO_ALT|GPIO_AF6 |GPIO_PORTD|GPIO_PIN3) +#define GPIO_DFSDM_DATIN1_1 (GPIO_ALT|GPIO_AF6 |GPIO_PORTB|GPIO_PIN12) +#define GPIO_DFSDM_DATIN1_2 (GPIO_ALT|GPIO_AF6 |GPIO_PORTD|GPIO_PIN6) +#define GPIO_DFSDM_DATIN2_1 (GPIO_ALT|GPIO_AF6 |GPIO_PORTB|GPIO_PIN14) +#define GPIO_DFSDM_DATIN2_2 (GPIO_ALT|GPIO_AF6 |GPIO_PORTE|GPIO_PIN7) +#define GPIO_DFSDM_DATIN3_1 (GPIO_ALT|GPIO_AF6 |GPIO_PORTC|GPIO_PIN7) +#define GPIO_DFSDM_DATIN3_2 (GPIO_ALT|GPIO_AF6 |GPIO_PORTE|GPIO_PIN4) + +#define GPIO_DFSDM_CKIN0_1 (GPIO_ALT|GPIO_AF6 |GPIO_PORTB|GPIO_PIN2) +#define GPIO_DFSDM_CKIN0_2 (GPIO_ALT|GPIO_AF6 |GPIO_PORTD|GPIO_PIN4) +#define GPIO_DFSDM_CKIN1_1 (GPIO_ALT|GPIO_AF6 |GPIO_PORTB|GPIO_PIN13) +#define GPIO_DFSDM_CKIN1_2 (GPIO_ALT|GPIO_AF6 |GPIO_PORTD|GPIO_PIN7) +#define GPIO_DFSDM_CKIN2_1 (GPIO_ALT|GPIO_AF6 |GPIO_PORTB|GPIO_PIN15) +#define GPIO_DFSDM_CKIN2_2 (GPIO_ALT|GPIO_AF6 |GPIO_PORTE|GPIO_PIN8) +#define GPIO_DFSDM_CKIN3_1 (GPIO_ALT|GPIO_AF6 |GPIO_PORTC|GPIO_PIN6) +#define GPIO_DFSDM_CKIN3_2 (GPIO_ALT|GPIO_AF6 |GPIO_PORTE|GPIO_PIN5) + +#define GPIO_DFSDM_CKOUT_1 (GPIO_ALT|GPIO_AF6 |GPIO_PORTA|GPIO_PIN5) +#define GPIO_DFSDM_CKOUT_2 (GPIO_ALT|GPIO_AF6 |GPIO_PORTC|GPIO_PIN2) +#define GPIO_DFSDM_CKOUT_3 (GPIO_ALT|GPIO_AF6 |GPIO_PORTE|GPIO_PIN9) + +/* I2C */ + +#define GPIO_I2C1_SDA_1 (GPIO_ALT|GPIO_AF4 |GPIO_PORTB|GPIO_PIN7) +#define GPIO_I2C1_SDA_2 (GPIO_ALT|GPIO_AF4 |GPIO_PORTB|GPIO_PIN9) +#define GPIO_I2C1_SCL_1 (GPIO_ALT|GPIO_AF4 |GPIO_PORTB|GPIO_PIN6) +#define GPIO_I2C1_SCL_2 (GPIO_ALT|GPIO_AF4 |GPIO_PORTB|GPIO_PIN8) +#define GPIO_I2C1_SMBA_1 (GPIO_ALT|GPIO_AF4 |GPIO_PORTA|GPIO_PIN1) +#define GPIO_I2C1_SMBA_2 (GPIO_ALT|GPIO_AF4 |GPIO_PORTA|GPIO_PIN14) +#define GPIO_I2C1_SMBA_3 (GPIO_ALT|GPIO_AF4 |GPIO_PORTB|GPIO_PIN5) + +#define GPIO_I2C2_SDA_1 (GPIO_ALT|GPIO_AF4 |GPIO_PORTB|GPIO_PIN11) +#define GPIO_I2C2_SDA_2 (GPIO_ALT|GPIO_AF4 |GPIO_PORTB|GPIO_PIN14) +#define GPIO_I2C2_SCL_1 (GPIO_ALT|GPIO_AF4 |GPIO_PORTB|GPIO_PIN10) +#define GPIO_I2C2_SCL_2 (GPIO_ALT|GPIO_AF4 |GPIO_PORTB|GPIO_PIN13) +#define GPIO_I2C2_SMBA_1 (GPIO_ALT|GPIO_AF4 |GPIO_PORTB|GPIO_PIN12) + +#define GPIO_I2C3_SDA_1 (GPIO_ALT|GPIO_AF4 |GPIO_PORTB|GPIO_PIN4) +#define GPIO_I2C3_SDA_2 (GPIO_ALT|GPIO_AF4 |GPIO_PORTC|GPIO_PIN1) +#define GPIO_I2C3_SCL_1 (GPIO_ALT|GPIO_AF4 |GPIO_PORTA|GPIO_PIN7) +#define GPIO_I2C3_SCL_2 (GPIO_ALT|GPIO_AF4 |GPIO_PORTC|GPIO_PIN0) +#define GPIO_I2C3_SMBA_1 (GPIO_ALT|GPIO_AF4 |GPIO_PORTB|GPIO_PIN2) + +#define GPIO_I2C4_SDA_1 (GPIO_ALT|GPIO_AF5 |GPIO_PORTB|GPIO_PIN7) +#define GPIO_I2C4_SDA_2 (GPIO_ALT|GPIO_AF3 |GPIO_PORTB|GPIO_PIN11) +#define GPIO_I2C4_SDA_3 (GPIO_ALT|GPIO_AF2 |GPIO_PORTC|GPIO_PIN1) +#define GPIO_I2C4_SDA_4 (GPIO_ALT|GPIO_AF4 |GPIO_PORTD|GPIO_PIN13) +#define GPIO_I2C4_SCL_1 (GPIO_ALT|GPIO_AF5 |GPIO_PORTB|GPIO_PIN6) +#define GPIO_I2C4_SCL_2 (GPIO_ALT|GPIO_AF3 |GPIO_PORTB|GPIO_PIN10) +#define GPIO_I2C4_SCL_3 (GPIO_ALT|GPIO_AF2 |GPIO_PORTC|GPIO_PIN0) +#define GPIO_I2C4_SCL_4 (GPIO_ALT|GPIO_AF4 |GPIO_PORTD|GPIO_PIN12) +#define GPIO_I2C4_SMBA_1 (GPIO_ALT|GPIO_AF5 |GPIO_PORTA|GPIO_PIN14) +#define GPIO_I2C4_SMBA_2 (GPIO_ALT|GPIO_AF4 |GPIO_PORTD|GPIO_PIN11) + +/* JTAG */ + +#define GPIO_JTCK_SWCLK (GPIO_ALT|GPIO_AF0|GPIO_PORTA|GPIO_PIN14) +#define GPIO_JTDI (GPIO_ALT|GPIO_AF0|GPIO_PORTA|GPIO_PIN15) +#define GPIO_JTDO (GPIO_ALT|GPIO_AF0|GPIO_PORTB|GPIO_PIN3) +#define GPIO_JTMS_SWDAT (GPIO_ALT|GPIO_AF0|GPIO_PORTA|GPIO_PIN13) +#define GPIO_JTRST (GPIO_ALT|GPIO_AF0|GPIO_PORTB|GPIO_PIN4) + +/* QUADSPI */ + +#define GPIO_QSPI_NCS_1 (GPIO_ALT|GPIO_AF10|GPIO_PORTB|GPIO_PIN11) +#define GPIO_QSPI_NCS_2 (GPIO_ALT|GPIO_AF10|GPIO_PORTE|GPIO_PIN11) +#define GPIO_QSPI_CLK_1 (GPIO_ALT|GPIO_AF10|GPIO_PORTB|GPIO_PIN10) +#define GPIO_QSPI_CLK_2 (GPIO_ALT|GPIO_AF10|GPIO_PORTE|GPIO_PIN10) +#define GPIO_QSPI_BK1_IO0_1 (GPIO_ALT|GPIO_AF10|GPIO_PORTB|GPIO_PIN1) +#define GPIO_QSPI_BK1_IO0_2 (GPIO_ALT|GPIO_AF10|GPIO_PORTE|GPIO_PIN12) +#define GPIO_QSPI_BK1_IO1_1 (GPIO_ALT|GPIO_AF10|GPIO_PORTB|GPIO_PIN0) +#define GPIO_QSPI_BK1_IO1_2 (GPIO_ALT|GPIO_AF10|GPIO_PORTE|GPIO_PIN13) +#define GPIO_QSPI_BK1_IO2_1 (GPIO_ALT|GPIO_AF10|GPIO_PORTA|GPIO_PIN7) +#define GPIO_QSPI_BK1_IO2_2 (GPIO_ALT|GPIO_AF10|GPIO_PORTE|GPIO_PIN14) +#define GPIO_QSPI_BK1_IO3_1 (GPIO_ALT|GPIO_AF10|GPIO_PORTA|GPIO_PIN6) +#define GPIO_QSPI_BK1_IO3_2 (GPIO_ALT|GPIO_AF10|GPIO_PORTE|GPIO_PIN15) + +/* RTC */ + +#define GPIO_RTC_OUT (GPIO_ALT|GPIO_AF0 |GPIO_PORTB|GPIO_PIN2) +#define GPIO_RTC_REFIN (GPIO_ALT|GPIO_AF0 |GPIO_PORTB|GPIO_PIN15) + +/* SAI */ + +#define GPIO_SAI1_EXTCLK (GPIO_ALT|GPIO_AF13|GPIO_PORTA|GPIO_PIN0) + +#define GPIO_SAI1_FS_A_1 (GPIO_ALT|GPIO_AF13|GPIO_PORTB|GPIO_PIN9) +#define GPIO_SAI1_FS_A_2 (GPIO_ALT|GPIO_AF13|GPIO_PORTE|GPIO_PIN4) +#define GPIO_SAI1_SCK_A_1 (GPIO_ALT|GPIO_AF13|GPIO_PORTB|GPIO_PIN10) +#define GPIO_SAI1_SCK_A_2 (GPIO_ALT|GPIO_AF13|GPIO_PORTE|GPIO_PIN5) +#define GPIO_SAI1_SD_A_1 (GPIO_ALT|GPIO_AF13|GPIO_PORTC|GPIO_PIN3) +#define GPIO_SAI1_SD_A_2 (GPIO_ALT|GPIO_AF13|GPIO_PORTD|GPIO_PIN6) +#define GPIO_SAI1_SD_A_3 (GPIO_ALT|GPIO_AF13|GPIO_PORTE|GPIO_PIN6) +#define GPIO_SAI1_MCLK_A_1 (GPIO_ALT|GPIO_AF13|GPIO_PORTB|GPIO_PIN8) +#define GPIO_SAI1_MCLK_A_2 (GPIO_ALT|GPIO_AF13|GPIO_PORTE|GPIO_PIN2) + +#define GPIO_SAI1_FS_B_1 (GPIO_ALT|GPIO_AF13|GPIO_PORTA|GPIO_PIN4) +#define GPIO_SAI1_FS_B_2 (GPIO_ALT|GPIO_AF13|GPIO_PORTB|GPIO_PIN6) +#define GPIO_SAI1_FS_B_3 (GPIO_ALT|GPIO_AF13|GPIO_PORTE|GPIO_PIN9) +#define GPIO_SAI1_SCK_B_1 (GPIO_ALT|GPIO_AF13|GPIO_PORTB|GPIO_PIN3) +#define GPIO_SAI1_SCK_B_2 (GPIO_ALT|GPIO_AF13|GPIO_PORTE|GPIO_PIN8) +#define GPIO_SAI1_SD_B_1 (GPIO_ALT|GPIO_AF13|GPIO_PORTB|GPIO_PIN5) +#define GPIO_SAI1_SD_B_2 (GPIO_ALT|GPIO_AF13|GPIO_PORTE|GPIO_PIN3) +#define GPIO_SAI1_SD_B_3 (GPIO_ALT|GPIO_AF13|GPIO_PORTE|GPIO_PIN7) +#define GPIO_SAI1_MCLK_B_1 (GPIO_ALT|GPIO_AF13|GPIO_PORTB|GPIO_PIN4) +#define GPIO_SAI1_MCLK_B_2 (GPIO_ALT|GPIO_AF13|GPIO_PORTE|GPIO_PIN10) + +/* SDIO */ + +#define GPIO_SDMMC1_CK (GPIO_ALT|GPIO_AF12|GPIO_PORTC|GPIO_PIN12) +#define GPIO_SDMMC1_CMD (GPIO_ALT|GPIO_AF12|GPIO_PORTD|GPIO_PIN2) +#define GPIO_SDMMC1_D0 (GPIO_ALT|GPIO_AF12|GPIO_PORTC|GPIO_PIN8) +#define GPIO_SDMMC1_D1 (GPIO_ALT|GPIO_AF12|GPIO_PORTC|GPIO_PIN9) +#define GPIO_SDMMC1_D2 (GPIO_ALT|GPIO_AF12|GPIO_PORTC|GPIO_PIN10) +#define GPIO_SDMMC1_D3 (GPIO_ALT|GPIO_AF12|GPIO_PORTC|GPIO_PIN11) +#define GPIO_SDMMC1_D4 (GPIO_ALT|GPIO_AF12|GPIO_PORTB|GPIO_PIN8) +#define GPIO_SDMMC1_D5 (GPIO_ALT|GPIO_AF12|GPIO_PORTB|GPIO_PIN9) +#define GPIO_SDMMC1_D6 (GPIO_ALT|GPIO_AF12|GPIO_PORTC|GPIO_PIN6) +#define GPIO_SDMMC1_D7 (GPIO_ALT|GPIO_AF12|GPIO_PORTC|GPIO_PIN7) + +/* Single Wire Protocol Interface */ + +#define GPIO_SWPMI1_IO (GPIO_ALT|GPIO_AF12|GPIO_PORTB|GPIO_PIN12) +#define GPIO_SWPMI1_TX (GPIO_ALT|GPIO_AF12|GPIO_PORTB|GPIO_PIN13) +#define GPIO_SWPMI1_RX (GPIO_ALT|GPIO_AF12|GPIO_PORTB|GPIO_PIN14) +#define GPIO_SWPMI1_SUSPEND (GPIO_ALT|GPIO_AF12|GPIO_PORTB|GPIO_PIN15) + +/* SPI */ + +#define GPIO_SPI1_NSS_1 (GPIO_ALT|GPIO_AF5 |GPIO_PORTA|GPIO_PIN4) +#define GPIO_SPI1_NSS_2 (GPIO_ALT|GPIO_AF5 |GPIO_PORTA|GPIO_PIN15) +#define GPIO_SPI1_NSS_3 (GPIO_ALT|GPIO_AF5 |GPIO_PORTB|GPIO_PIN0) +#define GPIO_SPI1_NSS_4 (GPIO_ALT|GPIO_AF5 |GPIO_PORTE|GPIO_PIN12) +#define GPIO_SPI1_SCK_1 (GPIO_ALT|GPIO_AF5 |GPIO_PORTA|GPIO_PIN1) +#define GPIO_SPI1_SCK_2 (GPIO_ALT|GPIO_AF5 |GPIO_PORTA|GPIO_PIN5) +#define GPIO_SPI1_SCK_3 (GPIO_ALT|GPIO_AF5 |GPIO_PORTB|GPIO_PIN3) +#define GPIO_SPI1_SCK_4 (GPIO_ALT|GPIO_AF5 |GPIO_PORTE|GPIO_PIN13) +#define GPIO_SPI1_MOSI_1 (GPIO_ALT|GPIO_AF5 |GPIO_PORTA|GPIO_PIN7) +#define GPIO_SPI1_MOSI_2 (GPIO_ALT|GPIO_AF5 |GPIO_PORTA|GPIO_PIN12) +#define GPIO_SPI1_MOSI_3 (GPIO_ALT|GPIO_AF5 |GPIO_PORTB|GPIO_PIN5) +#define GPIO_SPI1_MOSI_4 (GPIO_ALT|GPIO_AF5 |GPIO_PORTE|GPIO_PIN15) +#define GPIO_SPI1_MISO_1 (GPIO_ALT|GPIO_AF5 |GPIO_PORTA|GPIO_PIN6) +#define GPIO_SPI1_MISO_2 (GPIO_ALT|GPIO_AF5 |GPIO_PORTA|GPIO_PIN11) +#define GPIO_SPI1_MISO_3 (GPIO_ALT|GPIO_AF5 |GPIO_PORTB|GPIO_PIN4) +#define GPIO_SPI1_MISO_4 (GPIO_ALT|GPIO_AF5 |GPIO_PORTE|GPIO_PIN14) + +#define GPIO_SPI2_NSS_1 (GPIO_ALT|GPIO_AF5 |GPIO_PORTB|GPIO_PIN9) +#define GPIO_SPI2_NSS_2 (GPIO_ALT|GPIO_AF5 |GPIO_PORTB|GPIO_PIN12) +#define GPIO_SPI2_NSS_3 (GPIO_ALT|GPIO_AF5 |GPIO_PORTD|GPIO_PIN0) +#define GPIO_SPI2_SCK_1 (GPIO_ALT|GPIO_AF5 |GPIO_PORTB|GPIO_PIN10) +#define GPIO_SPI2_SCK_2 (GPIO_ALT|GPIO_AF5 |GPIO_PORTB|GPIO_PIN13) +#define GPIO_SPI2_SCK_3 (GPIO_ALT|GPIO_AF5 |GPIO_PORTD|GPIO_PIN1) +#define GPIO_SPI2_MOSI_1 (GPIO_ALT|GPIO_AF5 |GPIO_PORTB|GPIO_PIN15) +#define GPIO_SPI2_MOSI_2 (GPIO_ALT|GPIO_AF5 |GPIO_PORTC|GPIO_PIN3) +#define GPIO_SPI2_MOSI_3 (GPIO_ALT|GPIO_AF5 |GPIO_PORTD|GPIO_PIN4) +#define GPIO_SPI2_MISO_1 (GPIO_ALT|GPIO_AF5 |GPIO_PORTB|GPIO_PIN14) +#define GPIO_SPI2_MISO_2 (GPIO_ALT|GPIO_AF5 |GPIO_PORTC|GPIO_PIN2) +#define GPIO_SPI2_MISO_3 (GPIO_ALT|GPIO_AF5 |GPIO_PORTD|GPIO_PIN3) + +#define GPIO_SPI3_NSS_1 (GPIO_ALT|GPIO_AF6 |GPIO_PORTA|GPIO_PIN4) +#define GPIO_SPI3_NSS_2 (GPIO_ALT|GPIO_AF6 |GPIO_PORTA|GPIO_PIN15) +#define GPIO_SPI3_SCK_1 (GPIO_ALT|GPIO_AF6 |GPIO_PORTB|GPIO_PIN3) +#define GPIO_SPI3_SCK_2 (GPIO_ALT|GPIO_AF6 |GPIO_PORTC|GPIO_PIN10) +#define GPIO_SPI3_MOSI_1 (GPIO_ALT|GPIO_AF6 |GPIO_PORTB|GPIO_PIN5) +#define GPIO_SPI3_MOSI_2 (GPIO_ALT|GPIO_AF6 |GPIO_PORTC|GPIO_PIN12) +#define GPIO_SPI3_MISO_1 (GPIO_ALT|GPIO_AF6 |GPIO_PORTB|GPIO_PIN4) +#define GPIO_SPI3_MISO_2 (GPIO_ALT|GPIO_AF6 |GPIO_PORTC|GPIO_PIN11) + +/* Timers */ + +#define GPIO_TIM1_CH1IN_1 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTA|GPIO_PIN8) +#define GPIO_TIM1_CH1IN_2 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTE|GPIO_PIN9) +#define GPIO_TIM1_CH1OUT_1 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTA|GPIO_PIN8) +#define GPIO_TIM1_CH1OUT_2 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTE|GPIO_PIN9) +#define GPIO_TIM1_CH2IN_1 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTA|GPIO_PIN9) +#define GPIO_TIM1_CH2IN_2 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTE|GPIO_PIN11) +#define GPIO_TIM1_CH2OUT_1 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTA|GPIO_PIN9) +#define GPIO_TIM1_CH2OUT_2 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTE|GPIO_PIN11) +#define GPIO_TIM1_CH3IN_1 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTA|GPIO_PIN10) +#define GPIO_TIM1_CH3IN_2 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTE|GPIO_PIN13) +#define GPIO_TIM1_CH3OUT_1 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTA|GPIO_PIN10) +#define GPIO_TIM1_CH3OUT_2 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTE|GPIO_PIN13) +#define GPIO_TIM1_CH4IN_1 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTA|GPIO_PIN11) +#define GPIO_TIM1_CH4IN_2 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTE|GPIO_PIN14) +#define GPIO_TIM1_CH4OUT_1 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTA|GPIO_PIN11) +#define GPIO_TIM1_CH4OUT_2 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTE|GPIO_PIN14) +#define GPIO_TIM1_CH1N_1 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTA|GPIO_PIN7) +#define GPIO_TIM1_CH1N_2 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTB|GPIO_PIN13) +#define GPIO_TIM1_CH1N_3 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTE|GPIO_PIN8) +#define GPIO_TIM1_CH2N_1 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTB|GPIO_PIN0) +#define GPIO_TIM1_CH2N_2 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTB|GPIO_PIN14) +#define GPIO_TIM1_CH2N_3 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTE|GPIO_PIN10) +#define GPIO_TIM1_CH3N_1 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTB|GPIO_PIN1) +#define GPIO_TIM1_CH3N_2 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTB|GPIO_PIN15) +#define GPIO_TIM1_CH3N_3 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTE|GPIO_PIN12) +#define GPIO_TIM1_BKIN_1 (GPIO_ALT|GPIO_AF1 |GPIO_PORTA|GPIO_PIN6) +#define GPIO_TIM1_BKIN_2 (GPIO_ALT|GPIO_AF1 |GPIO_PORTB|GPIO_PIN12) +#define GPIO_TIM1_BKIN_3 (GPIO_ALT|GPIO_AF1 |GPIO_PORTE|GPIO_PIN15) +#define GPIO_TIM1_BKIN_COMP1 (GPIO_ALT|GPIO_AF3 |GPIO_PORTE|GPIO_PIN15) +#define GPIO_TIM1_BKIN_COMP2_1 (GPIO_ALT|GPIO_AF12|GPIO_PORTA|GPIO_PIN6) +#define GPIO_TIM1_BKIN_COMP2_2 (GPIO_ALT|GPIO_AF3 |GPIO_PORTB|GPIO_PIN12) +#define GPIO_TIM1_BKIN2 (GPIO_ALT|GPIO_AF2 |GPIO_PORTA|GPIO_PIN11) +#define GPIO_TIM1_BKIN2_COMP1 (GPIO_ALT|GPIO_AF12|GPIO_PORTA|GPIO_PIN11) +#define GPIO_TIM1_BKIN2_COMP2 (GPIO_ALT|GPIO_AF3 |GPIO_PORTE|GPIO_PIN14) +#define GPIO_TIM1_ETR_1 (GPIO_ALT|GPIO_AF1 |GPIO_PORTA|GPIO_PIN12) +#define GPIO_TIM1_ETR_2 (GPIO_ALT|GPIO_AF1 |GPIO_PORTE|GPIO_PIN7) + +#define GPIO_TIM2_CH1IN_1 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTA|GPIO_PIN0) +#define GPIO_TIM2_CH1IN_2 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTA|GPIO_PIN5) +#define GPIO_TIM2_CH1IN_3 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTA|GPIO_PIN15) +#define GPIO_TIM2_CH1OUT_1 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTA|GPIO_PIN0) +#define GPIO_TIM2_CH1OUT_2 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTA|GPIO_PIN5) +#define GPIO_TIM2_CH1OUT_3 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTA|GPIO_PIN15) +#define GPIO_TIM2_CH2IN_1 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTA|GPIO_PIN1) +#define GPIO_TIM2_CH2IN_2 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTB|GPIO_PIN3) +#define GPIO_TIM2_CH2OUT_1 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTA|GPIO_PIN1) +#define GPIO_TIM2_CH2OUT_2 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTB|GPIO_PIN3) +#define GPIO_TIM2_CH3IN_1 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTA|GPIO_PIN2) +#define GPIO_TIM2_CH3IN_2 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTB|GPIO_PIN10) +#define GPIO_TIM2_CH3OUT_1 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTA|GPIO_PIN2) +#define GPIO_TIM2_CH3OUT_2 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTB|GPIO_PIN10) +#define GPIO_TIM2_CH4IN_1 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTA|GPIO_PIN3) +#define GPIO_TIM2_CH4IN_2 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTB|GPIO_PIN11) +#define GPIO_TIM2_CH4OUT_1 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTA|GPIO_PIN3) +#define GPIO_TIM2_CH4OUT_2 (GPIO_ALT|GPIO_AF1 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTB|GPIO_PIN11) +#define GPIO_TIM2_BKIN (GPIO_ALT|GPIO_AF2 |GPIO_PORTE|GPIO_PIN14) +#define GPIO_TIM2_ETR_1 (GPIO_ALT|GPIO_AF14|GPIO_PORTA|GPIO_PIN0) +#define GPIO_TIM2_ETR_2 (GPIO_ALT|GPIO_AF2 |GPIO_PORTA|GPIO_PIN5) +#define GPIO_TIM2_ETR_3 (GPIO_ALT|GPIO_AF2 |GPIO_PORTA|GPIO_PIN15) + +#define GPIO_TIM3_CH1IN_1 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTA|GPIO_PIN6) +#define GPIO_TIM3_CH1IN_2 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTB|GPIO_PIN4) +#define GPIO_TIM3_CH1IN_3 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTC|GPIO_PIN6) +#define GPIO_TIM3_CH1IN_4 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTE|GPIO_PIN3) +#define GPIO_TIM3_CH1OUT_1 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTA|GPIO_PIN6) +#define GPIO_TIM3_CH1OUT_2 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTB|GPIO_PIN4) +#define GPIO_TIM3_CH1OUT_3 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTC|GPIO_PIN6) +#define GPIO_TIM3_CH1OUT_4 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTE|GPIO_PIN3) +#define GPIO_TIM3_CH2IN_1 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTA|GPIO_PIN7) +#define GPIO_TIM3_CH2IN_2 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTB|GPIO_PIN5) +#define GPIO_TIM3_CH2IN_3 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTC|GPIO_PIN7) +#define GPIO_TIM3_CH2IN_4 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTE|GPIO_PIN4) +#define GPIO_TIM3_CH2OUT_1 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTA|GPIO_PIN7) +#define GPIO_TIM3_CH2OUT_2 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTB|GPIO_PIN5) +#define GPIO_TIM3_CH2OUT_3 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTC|GPIO_PIN7) +#define GPIO_TIM3_CH2OUT_4 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTE|GPIO_PIN4) +#define GPIO_TIM3_CH3IN_1 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTB|GPIO_PIN0) +#define GPIO_TIM3_CH3IN_2 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTC|GPIO_PIN8) +#define GPIO_TIM3_CH3IN_3 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTE|GPIO_PIN5) +#define GPIO_TIM3_CH3OUT_1 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTB|GPIO_PIN0) +#define GPIO_TIM3_CH3OUT_2 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTC|GPIO_PIN8) +#define GPIO_TIM3_CH3OUT_3 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTE|GPIO_PIN5) +#define GPIO_TIM3_CH4IN_1 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTB|GPIO_PIN1) +#define GPIO_TIM3_CH4IN_2 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTC|GPIO_PIN9) +#define GPIO_TIM3_CH4IN_3 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTE|GPIO_PIN6) +#define GPIO_TIM3_CH4OUT_1 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTB|GPIO_PIN1) +#define GPIO_TIM3_CH4OUT_2 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTC|GPIO_PIN9) +#define GPIO_TIM3_CH4OUT_3 (GPIO_ALT|GPIO_AF2 |GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTE|GPIO_PIN6) +#define GPIO_TIM3_ETR_1 (GPIO_ALT|GPIO_AF2 |GPIO_PORTD|GPIO_PIN2) +#define GPIO_TIM3_ETR_2 (GPIO_ALT|GPIO_AF2 |GPIO_PORTE|GPIO_PIN2) + +#define GPIO_TIM15_CH1IN_1 (GPIO_ALT|GPIO_AF14|GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTA|GPIO_PIN2) +#define GPIO_TIM15_CH1IN_2 (GPIO_ALT|GPIO_AF14|GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTB|GPIO_PIN14) +#define GPIO_TIM15_CH1OUT_1 (GPIO_ALT|GPIO_AF14|GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTA|GPIO_PIN2) +#define GPIO_TIM15_CH1OUT_2 (GPIO_ALT|GPIO_AF14|GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTB|GPIO_PIN14) +#define GPIO_TIM15_CH2IN_1 (GPIO_ALT|GPIO_AF14|GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTA|GPIO_PIN3) +#define GPIO_TIM15_CH2IN_2 (GPIO_ALT|GPIO_AF14|GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTB|GPIO_PIN15) +#define GPIO_TIM15_CH2OUT_1 (GPIO_ALT|GPIO_AF14|GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTA|GPIO_PIN3) +#define GPIO_TIM15_CH2OUT_2 (GPIO_ALT|GPIO_AF14|GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTB|GPIO_PIN15) +#define GPIO_TIM15_CH1N_1 (GPIO_ALT|GPIO_AF14|GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTA|GPIO_PIN1) +#define GPIO_TIM15_CH1N_2 (GPIO_ALT|GPIO_AF14|GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTB|GPIO_PIN13) +#define GPIO_TIM15_BKIN_1 (GPIO_ALT|GPIO_AF14|GPIO_PORTA|GPIO_PIN9) +#define GPIO_TIM15_BKIN_2 (GPIO_ALT|GPIO_AF14|GPIO_PORTB|GPIO_PIN12) + +#define GPIO_TIM16_CH1IN_1 (GPIO_ALT|GPIO_AF14|GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTA|GPIO_PIN6) +#define GPIO_TIM16_CH1IN_2 (GPIO_ALT|GPIO_AF14|GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTB|GPIO_PIN8) +#define GPIO_TIM16_CH1IN_3 (GPIO_ALT|GPIO_AF14|GPIO_SPEED_50MHz|GPIO_FLOAT|GPIO_PORTE|GPIO_PIN0) +#define GPIO_TIM16_CH1OUT_1 (GPIO_ALT|GPIO_AF14|GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTA|GPIO_PIN6) +#define GPIO_TIM16_CH1OUT_2 (GPIO_ALT|GPIO_AF14|GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTB|GPIO_PIN8) +#define GPIO_TIM16_CH1OUT_3 (GPIO_ALT|GPIO_AF14|GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTE|GPIO_PIN0) +#define GPIO_TIM16_CH1N (GPIO_ALT|GPIO_AF14|GPIO_SPEED_50MHz|GPIO_PUSHPULL|GPIO_PORTB|GPIO_PIN6) +#define GPIO_TIM16_BKIN (GPIO_ALT|GPIO_AF14|GPIO_PORTB|GPIO_PIN5) + +#define GPIO_LPTIM1_IN1_1 (GPIO_ALT|GPIO_AF1 |GPIO_PORTB|GPIO_PIN5) +#define GPIO_LPTIM1_IN1_2 (GPIO_ALT|GPIO_AF1 |GPIO_PORTC|GPIO_PIN0) +#define GPIO_LPTIM1_IN2_1 (GPIO_ALT|GPIO_AF1 |GPIO_PORTB|GPIO_PIN7) +#define GPIO_LPTIM1_IN2_2 (GPIO_ALT|GPIO_AF1 |GPIO_PORTC|GPIO_PIN2) +#define GPIO_LPTIM1_OUT_1 (GPIO_ALT|GPIO_AF1 |GPIO_PORTB|GPIO_PIN2) +#define GPIO_LPTIM1_OUT_2 (GPIO_ALT|GPIO_AF1 |GPIO_PORTC|GPIO_PIN1) +#define GPIO_LPTIM1_ETR_1 (GPIO_ALT|GPIO_AF1 |GPIO_PORTB|GPIO_PIN6) +#define GPIO_LPTIM1_ETR_2 (GPIO_ALT|GPIO_AF1 |GPIO_PORTC|GPIO_PIN3) + +#define GPIO_LPTIM2_IN1_1 (GPIO_ALT|GPIO_AF14|GPIO_PORTB|GPIO_PIN1) +#define GPIO_LPTIM2_IN1_2 (GPIO_ALT|GPIO_AF14|GPIO_PORTC|GPIO_PIN0) +#define GPIO_LPTIM2_IN1_3 (GPIO_ALT|GPIO_AF14|GPIO_PORTD|GPIO_PIN12) +#define GPIO_LPTIM2_OUT_1 (GPIO_ALT|GPIO_AF14|GPIO_PORTA|GPIO_PIN4) +#define GPIO_LPTIM2_OUT_2 (GPIO_ALT|GPIO_AF14|GPIO_PORTA|GPIO_PIN8) +#define GPIO_LPTIM2_OUT_3 (GPIO_ALT|GPIO_AF14|GPIO_PORTD|GPIO_PIN13) +#define GPIO_LPTIM2_ETR_1 (GPIO_ALT|GPIO_AF14|GPIO_PORTA|GPIO_PIN5) +#define GPIO_LPTIM2_ETR_2 (GPIO_ALT|GPIO_AF14|GPIO_PORTC|GPIO_PIN3) +#define GPIO_LPTIM2_ETR_3 (GPIO_ALT|GPIO_AF14|GPIO_PORTD|GPIO_PIN11) + +/* Touch Screen Controller */ + +#define GPIO_TSC_SYNC (GPIO_ALT|GPIO_AF9 |GPIO_PORTD|GPIO_PIN2) + +#define GPIO_TSC_G1_IO1 (GPIO_ALT|GPIO_AF9 |GPIO_PORTB|GPIO_PIN12) +#define GPIO_TSC_G1_IO2 (GPIO_ALT|GPIO_AF9 |GPIO_PORTB|GPIO_PIN13) +#define GPIO_TSC_G1_IO3 (GPIO_ALT|GPIO_AF9 |GPIO_PORTB|GPIO_PIN14) +#define GPIO_TSC_G1_IO4 (GPIO_ALT|GPIO_AF9 |GPIO_PORTB|GPIO_PIN15) + +#define GPIO_TSC_G2_IO1 (GPIO_ALT|GPIO_AF9 |GPIO_PORTB|GPIO_PIN4) +#define GPIO_TSC_G2_IO2 (GPIO_ALT|GPIO_AF9 |GPIO_PORTB|GPIO_PIN5) +#define GPIO_TSC_G2_IO3 (GPIO_ALT|GPIO_AF9 |GPIO_PORTB|GPIO_PIN6) +#define GPIO_TSC_G2_IO4 (GPIO_ALT|GPIO_AF9 |GPIO_PORTB|GPIO_PIN7) + +#define GPIO_TSC_G3_IO1 (GPIO_ALT|GPIO_AF9 |GPIO_PORTA|GPIO_PIN15) +#define GPIO_TSC_G3_IO2 (GPIO_ALT|GPIO_AF9 |GPIO_PORTC|GPIO_PIN10) +#define GPIO_TSC_G3_IO3 (GPIO_ALT|GPIO_AF9 |GPIO_PORTC|GPIO_PIN11) +#define GPIO_TSC_G3_IO4 (GPIO_ALT|GPIO_AF9 |GPIO_PORTC|GPIO_PIN12) + +#define GPIO_TSC_G4_IO1 (GPIO_ALT|GPIO_AF9 |GPIO_PORTC|GPIO_PIN6) +#define GPIO_TSC_G4_IO2 (GPIO_ALT|GPIO_AF9 |GPIO_PORTC|GPIO_PIN7) +#define GPIO_TSC_G4_IO3 (GPIO_ALT|GPIO_AF9 |GPIO_PORTC|GPIO_PIN8) +#define GPIO_TSC_G4_IO4 (GPIO_ALT|GPIO_AF9 |GPIO_PORTC|GPIO_PIN9) + +#define GPIO_TSC_G5_IO1 (GPIO_ALT|GPIO_AF9 |GPIO_PORTE|GPIO_PIN10) +#define GPIO_TSC_G5_IO2 (GPIO_ALT|GPIO_AF9 |GPIO_PORTE|GPIO_PIN11) +#define GPIO_TSC_G5_IO3 (GPIO_ALT|GPIO_AF9 |GPIO_PORTE|GPIO_PIN12) +#define GPIO_TSC_G5_IO4 (GPIO_ALT|GPIO_AF9 |GPIO_PORTE|GPIO_PIN13) + +#define GPIO_TSC_G6_IO1 (GPIO_ALT|GPIO_AF9 |GPIO_PORTD|GPIO_PIN10) +#define GPIO_TSC_G6_IO2 (GPIO_ALT|GPIO_AF9 |GPIO_PORTD|GPIO_PIN11) +#define GPIO_TSC_G6_IO3 (GPIO_ALT|GPIO_AF9 |GPIO_PORTD|GPIO_PIN12) +#define GPIO_TSC_G6_IO4 (GPIO_ALT|GPIO_AF9 |GPIO_PORTD|GPIO_PIN13) + +#define GPIO_TSC_G7_IO1 (GPIO_ALT|GPIO_AF9 |GPIO_PORTE|GPIO_PIN2) +#define GPIO_TSC_G7_IO2 (GPIO_ALT|GPIO_AF9 |GPIO_PORTE|GPIO_PIN3) +#define GPIO_TSC_G7_IO3 (GPIO_ALT|GPIO_AF9 |GPIO_PORTE|GPIO_PIN4) +#define GPIO_TSC_G7_IO4 (GPIO_ALT|GPIO_AF9 |GPIO_PORTE|GPIO_PIN5) + +/* IR interface (with timers 16 and 17) */ + +#define GPIO_IR_OUT_1 (GPIO_ALT|GPIO_AF1 |GPIO_PORTA|GPIO_PIN13) +#define GPIO_IR_OUT_2 (GPIO_ALT|GPIO_AF1 |GPIO_PORTB|GPIO_PIN9) + +/* Trace */ + +#define GPIO_TRACECK (GPIO_ALT|GPIO_AF0 |GPIO_PORTE|GPIO_PIN2) +#define GPIO_TRACED0 (GPIO_ALT|GPIO_AF0 |GPIO_PORTE|GPIO_PIN3) +#define GPIO_TRACED1 (GPIO_ALT|GPIO_AF0 |GPIO_PORTE|GPIO_PIN4) +#define GPIO_TRACED2 (GPIO_ALT|GPIO_AF0 |GPIO_PORTE|GPIO_PIN5) +#define GPIO_TRACED3 (GPIO_ALT|GPIO_AF0 |GPIO_PORTE|GPIO_PIN6) + +/* UARTs/USARTs */ + +#define GPIO_USART1_TX_1 (GPIO_ALT|GPIO_AF7 |GPIO_PORTA|GPIO_PIN9) +#define GPIO_USART1_TX_2 (GPIO_ALT|GPIO_AF7 |GPIO_PORTB|GPIO_PIN6) +#define GPIO_USART1_RX_1 (GPIO_ALT|GPIO_AF7 |GPIO_PORTA|GPIO_PIN10) +#define GPIO_USART1_RX_2 (GPIO_ALT|GPIO_AF7 |GPIO_PORTB|GPIO_PIN7) +#define GPIO_USART1_CK_1 (GPIO_ALT|GPIO_AF7 |GPIO_PORTA|GPIO_PIN8) +#define GPIO_USART1_CK_2 (GPIO_ALT|GPIO_AF7 |GPIO_PORTB|GPIO_PIN5) +#define GPIO_USART1_CTS_1 (GPIO_ALT|GPIO_AF7 |GPIO_PORTA|GPIO_PIN11) +#define GPIO_USART1_CTS_2 (GPIO_ALT|GPIO_AF7 |GPIO_PORTB|GPIO_PIN4) +#define GPIO_USART1_RTS_DE_1 (GPIO_ALT|GPIO_AF7 |GPIO_PORTA|GPIO_PIN12) +#define GPIO_USART1_RTS_DE_2 (GPIO_ALT|GPIO_AF7 |GPIO_PORTB|GPIO_PIN3) + +#define GPIO_USART2_TX_1 (GPIO_ALT|GPIO_AF7 |GPIO_PORTA|GPIO_PIN2) +#define GPIO_USART2_TX_2 (GPIO_ALT|GPIO_AF7 |GPIO_PORTD|GPIO_PIN5) +#define GPIO_USART2_RX_1 (GPIO_ALT|GPIO_AF7 |GPIO_PORTA|GPIO_PIN3) +#define GPIO_USART2_RX_2 (GPIO_ALT|GPIO_AF7 |GPIO_PORTD|GPIO_PIN6) +#define GPIO_USART2_CK_1 (GPIO_ALT|GPIO_AF7 |GPIO_PORTA|GPIO_PIN4) +#define GPIO_USART2_CK_2 (GPIO_ALT|GPIO_AF7 |GPIO_PORTD|GPIO_PIN7) +#define GPIO_USART2_CTS_1 (GPIO_ALT|GPIO_AF7 |GPIO_PORTA|GPIO_PIN0) +#define GPIO_USART2_CTS_2 (GPIO_ALT|GPIO_AF7 |GPIO_PORTD|GPIO_PIN3) +#define GPIO_USART2_RTS_DE_1 (GPIO_ALT|GPIO_AF7 |GPIO_PORTA|GPIO_PIN1) +#define GPIO_USART2_RTS_DE_2 (GPIO_ALT|GPIO_AF7 |GPIO_PORTD|GPIO_PIN4) + +#define GPIO_USART3_TX_1 (GPIO_ALT|GPIO_AF7 |GPIO_PORTB|GPIO_PIN10) +#define GPIO_USART3_TX_2 (GPIO_ALT|GPIO_AF7 |GPIO_PORTC|GPIO_PIN4) +#define GPIO_USART3_TX_3 (GPIO_ALT|GPIO_AF7 |GPIO_PORTC|GPIO_PIN10) +#define GPIO_USART3_TX_4 (GPIO_ALT|GPIO_AF7 |GPIO_PORTD|GPIO_PIN8) +#define GPIO_USART3_RX_1 (GPIO_ALT|GPIO_AF7 |GPIO_PORTB|GPIO_PIN11) +#define GPIO_USART3_RX_2 (GPIO_ALT|GPIO_AF7 |GPIO_PORTC|GPIO_PIN5) +#define GPIO_USART3_RX_3 (GPIO_ALT|GPIO_AF7 |GPIO_PORTC|GPIO_PIN11) +#define GPIO_USART3_RX_4 (GPIO_ALT|GPIO_AF7 |GPIO_PORTD|GPIO_PIN9) +#define GPIO_USART3_CK_1 (GPIO_ALT|GPIO_AF7 |GPIO_PORTB|GPIO_PIN0) +#define GPIO_USART3_CK_2 (GPIO_ALT|GPIO_AF7 |GPIO_PORTB|GPIO_PIN12) +#define GPIO_USART3_CK_3 (GPIO_ALT|GPIO_AF7 |GPIO_PORTC|GPIO_PIN12) +#define GPIO_USART3_CK_4 (GPIO_ALT|GPIO_AF7 |GPIO_PORTD|GPIO_PIN10) +#define GPIO_USART3_CTS_1 (GPIO_ALT|GPIO_AF7 |GPIO_PORTA|GPIO_PIN6) +#define GPIO_USART3_CTS_2 (GPIO_ALT|GPIO_AF7 |GPIO_PORTB|GPIO_PIN13) +#define GPIO_USART3_CTS_3 (GPIO_ALT|GPIO_AF7 |GPIO_PORTD|GPIO_PIN11) +#define GPIO_USART3_RTS_DE_1 (GPIO_ALT|GPIO_AF7 |GPIO_PORTB|GPIO_PIN1) +#define GPIO_USART3_RTS_DE_2 (GPIO_ALT|GPIO_AF7 |GPIO_PORTB|GPIO_PIN14) +#define GPIO_USART3_RTS_DE_3 (GPIO_ALT|GPIO_AF7 |GPIO_PORTD|GPIO_PIN2) +#define GPIO_USART3_RTS_DE_4 (GPIO_ALT|GPIO_AF7 |GPIO_PORTD|GPIO_PIN12) + +#define GPIO_UART4_TX_1 (GPIO_ALT|GPIO_AF8 |GPIO_PORTA|GPIO_PIN0) +#define GPIO_UART4_TX_2 (GPIO_ALT|GPIO_AF8 |GPIO_PORTC|GPIO_PIN10) +#define GPIO_UART4_RX_1 (GPIO_ALT|GPIO_AF8 |GPIO_PORTA|GPIO_PIN1) +#define GPIO_UART4_RX_2 (GPIO_ALT|GPIO_AF8 |GPIO_PORTC|GPIO_PIN11) +#define GPIO_UART4_CTS (GPIO_ALT|GPIO_AF8 |GPIO_PORTB|GPIO_PIN7) +#define GPIO_UART4_RTS_DE (GPIO_ALT|GPIO_AF8 |GPIO_PORTA|GPIO_PIN15) + +#define GPIO_UART5_TX (GPIO_ALT|GPIO_AF8 |GPIO_PORTC|GPIO_PIN12) +#define GPIO_UART5_RX (GPIO_ALT|GPIO_AF8 |GPIO_PORTD|GPIO_PIN2) +#define GPIO_UART5_CTS (GPIO_ALT|GPIO_AF8 |GPIO_PORTB|GPIO_PIN5) +#define GPIO_UART5_RTS_DE (GPIO_ALT|GPIO_AF8 |GPIO_PORTB|GPIO_PIN4) + +#define GPIO_LPUART1_TX_1 (GPIO_ALT|GPIO_AF8 |GPIO_PORTB|GPIO_PIN11) +#define GPIO_LPUART1_TX_2 (GPIO_ALT|GPIO_AF8 |GPIO_PORTC|GPIO_PIN1) +#define GPIO_LPUART1_RX_1 (GPIO_ALT|GPIO_AF8 |GPIO_PORTB|GPIO_PIN10) +#define GPIO_LPUART1_RX_2 (GPIO_ALT|GPIO_AF8 |GPIO_PORTC|GPIO_PIN0) +#define GPIO_LPUART1_CTS_1 (GPIO_ALT|GPIO_AF8 |GPIO_PORTA|GPIO_PIN6) +#define GPIO_LPUART1_CTS_2 (GPIO_ALT|GPIO_AF8 |GPIO_PORTB|GPIO_PIN13) +#define GPIO_LPUART1_RTS_DE_1 (GPIO_ALT|GPIO_AF8 |GPIO_PORTB|GPIO_PIN1) +#define GPIO_LPUART1_RTS_DE_2 (GPIO_ALT|GPIO_AF8 |GPIO_PORTB|GPIO_PIN12) + +#endif /* __ARCH_ARM_SRC_STM32L4_CHIP_STM32L4X3XX_PINMAP_H */ diff --git a/arch/arm/src/stm32l4/chip/stm32l4x3xx_rcc.h b/arch/arm/src/stm32l4/chip/stm32l4x3xx_rcc.h new file mode 100644 index 00000000000..7aa7edfd6c6 --- /dev/null +++ b/arch/arm/src/stm32l4/chip/stm32l4x3xx_rcc.h @@ -0,0 +1,789 @@ +/**************************************************************************************************** + * arch/arm/src/stm32l4/chip/stm32l4x3xx_rcc.h + * + * Copyright (C) 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2016 Sebastien Lorquet. All rights reserved. + * Author: Gregory Nutt + * Author: Sebastien Lorquet + * Author: Juha Niskanen + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************************************/ + +#ifndef __ARCH_ARM_SRC_STM32L4_CHIP_STM32L4X3XX_RCC_H +#define __ARCH_ARM_SRC_STM32L4_CHIP_STM32L4X3XX_RCC_H + +/**************************************************************************************************** + * Included Files + ****************************************************************************************************/ + +#include + +#if defined(CONFIG_STM32L4_STM32L4X3) + +/**************************************************************************************************** + * Pre-processor Definitions + ****************************************************************************************************/ + +/* Register Offsets *********************************************************************************/ + +#define STM32L4_RCC_CR_OFFSET 0x0000 /* Clock control register */ +#define STM32L4_RCC_ICSCR_OFFSET 0x0004 /* Internal clock sources calibration register */ +#define STM32L4_RCC_CFGR_OFFSET 0x0008 /* Clock configuration register */ +#define STM32L4_RCC_PLLCFG_OFFSET 0x000c /* PLL configuration register */ +#define STM32L4_RCC_PLLSAI1CFG_OFFSET 0x0010 /* PLLSAI1 configuration register */ +#define STM32L4_RCC_PLLSAI2CFG_OFFSET 0x0014 /* PLLSAI2 configuration register */ +#define STM32L4_RCC_CIER_OFFSET 0x0018 /* Clock interrupt enable register */ +#define STM32L4_RCC_CIFR_OFFSET 0x001c /* Clock interrupt flag register */ +#define STM32L4_RCC_CICR_OFFSET 0x0020 /* Clock interrupt clear register */ +#define STM32L4_RCC_AHB1RSTR_OFFSET 0x0028 /* AHB1 peripheral reset register */ +#define STM32L4_RCC_AHB2RSTR_OFFSET 0x002c /* AHB2 peripheral reset register */ +#define STM32L4_RCC_AHB3RSTR_OFFSET 0x0030 /* AHB3 peripheral reset register */ +#define STM32L4_RCC_APB1RSTR1_OFFSET 0x0038 /* APB1 Peripheral reset register 1 */ +#define STM32L4_RCC_APB1RSTR2_OFFSET 0x003c /* APB1 Peripheral reset register 2 */ +#define STM32L4_RCC_APB2RSTR_OFFSET 0x0040 /* APB2 Peripheral reset register */ +#define STM32L4_RCC_AHB1ENR_OFFSET 0x0048 /* AHB1 Peripheral Clock enable register */ +#define STM32L4_RCC_AHB2ENR_OFFSET 0x004c /* AHB2 Peripheral Clock enable register */ +#define STM32L4_RCC_AHB3ENR_OFFSET 0x0050 /* AHB3 Peripheral Clock enable register */ +#define STM32L4_RCC_APB1ENR1_OFFSET 0x0058 /* APB1 Peripheral Clock enable register 1 */ +#define STM32L4_RCC_APB1ENR2_OFFSET 0x005c /* APB1 Peripheral Clock enable register 2 */ +#define STM32L4_RCC_APB2ENR_OFFSET 0x0060 /* APB2 Peripheral Clock enable register */ +#define STM32L4_RCC_AHB1SMENR_OFFSET 0x0068 /* RCC AHB1 low power mode peripheral clock enable register */ +#define STM32L4_RCC_AHB2SMENR_OFFSET 0x006c /* RCC AHB2 low power mode peripheral clock enable register */ +#define STM32L4_RCC_AHB3SMENR_OFFSET 0x0070 /* RCC AHB3 low power mode peripheral clock enable register */ +#define STM32L4_RCC_APB1SMENR1_OFFSET 0x0078 /* RCC APB1 low power mode peripheral clock enable register 1 */ +#define STM32L4_RCC_APB1SMENR2_OFFSET 0x007c /* RCC APB1 low power mode peripheral clock enable register 2 */ +#define STM32L4_RCC_APB2SMENR_OFFSET 0x0080 /* RCC APB2 low power mode peripheral clock enable register */ +#define STM32L4_RCC_CCIPR_OFFSET 0x0088 /* Peripherals independent clock configuration register 1 */ +#define STM32L4_RCC_BDCR_OFFSET 0x0090 /* Backup domain control register */ +#define STM32L4_RCC_CSR_OFFSET 0x0094 /* Control/status register */ +#define STM32L4_RCC_CRRCR_OFFSET 0x0098 /* Clock recovery RC register */ + +/* Register Addresses *******************************************************************************/ + +#define STM32L4_RCC_CR (STM32L4_RCC_BASE+STM32L4_RCC_CR_OFFSET) +#define STM32L4_RCC_ICSCR (STM32L4_RCC_BASE+STM32L4_RCC_ICSCR_OFFSET) +#define STM32L4_RCC_CFGR (STM32L4_RCC_BASE+STM32L4_RCC_CFGR_OFFSET) +#define STM32L4_RCC_PLLCFG (STM32L4_RCC_BASE+STM32L4_RCC_PLLCFG_OFFSET) +#define STM32L4_RCC_PLLSAI1CFG (STM32L4_RCC_BASE+STM32L4_RCC_PLLSAI1CFG_OFFSET) +#define STM32L4_RCC_PLLSAI2CFG (STM32L4_RCC_BASE+STM32L4_RCC_PLLSAI2CFG_OFFSET) +#define STM32L4_RCC_CIER (STM32L4_RCC_BASE+STM32L4_RCC_CIER_OFFSET) +#define STM32L4_RCC_CIFR (STM32L4_RCC_BASE+STM32L4_RCC_CIFR_OFFSET) +#define STM32L4_RCC_CICR (STM32L4_RCC_BASE+STM32L4_RCC_CICR_OFFSET) +#define STM32L4_RCC_AHB1RSTR (STM32L4_RCC_BASE+STM32L4_RCC_AHB1RSTR_OFFSET) +#define STM32L4_RCC_AHB2RSTR (STM32L4_RCC_BASE+STM32L4_RCC_AHB2RSTR_OFFSET) +#define STM32L4_RCC_AHB3RSTR (STM32L4_RCC_BASE+STM32L4_RCC_AHB3RSTR_OFFSET) +#define STM32L4_RCC_APB1RSTR1 (STM32L4_RCC_BASE+STM32L4_RCC_APB1RSTR1_OFFSET) +#define STM32L4_RCC_APB1RSTR2 (STM32L4_RCC_BASE+STM32L4_RCC_APB1RSTR2_OFFSET) +#define STM32L4_RCC_APB2RSTR (STM32L4_RCC_BASE+STM32L4_RCC_APB2RSTR_OFFSET) +#define STM32L4_RCC_AHB1ENR (STM32L4_RCC_BASE+STM32L4_RCC_AHB1ENR_OFFSET) +#define STM32L4_RCC_AHB2ENR (STM32L4_RCC_BASE+STM32L4_RCC_AHB2ENR_OFFSET) +#define STM32L4_RCC_AHB3ENR (STM32L4_RCC_BASE+STM32L4_RCC_AHB3ENR_OFFSET) +#define STM32L4_RCC_APB1ENR1 (STM32L4_RCC_BASE+STM32L4_RCC_APB1ENR1_OFFSET) +#define STM32L4_RCC_APB1ENR2 (STM32L4_RCC_BASE+STM32L4_RCC_APB1ENR2_OFFSET) +#define STM32L4_RCC_APB2ENR (STM32L4_RCC_BASE+STM32L4_RCC_APB2ENR_OFFSET) +#define STM32L4_RCC_AHB1SMENR (STM32L4_RCC_BASE+STM32L4_RCC_AHB1SMENR_OFFSET) +#define STM32L4_RCC_AHB2SMENR (STM32L4_RCC_BASE+STM32L4_RCC_AHB2SMENR) +#define STM32L4_RCC_AHB3SMENR (STM32L4_RCC_BASE+STM32L4_RCC_AHB3SMENR_OFFSET) +#define STM32L4_RCC_APB1SMENR1 (STM32L4_RCC_BASE+STM32L4_RCC_APB1SMENR1_OFFSET) +#define STM32L4_RCC_APB1SMENR2 (STM32L4_RCC_BASE+STM32L4_RCC_APB1SMENR2_OFFSET) +#define STM32L4_RCC_APB2SMENR (STM32L4_RCC_BASE+STM32L4_RCC_APB2SMENR_OFFSET) +#define STM32L4_RCC_CCIPR (STM32L4_RCC_BASE+STM32L4_RCC_CCIPR_OFFSET) +#define STM32L4_RCC_BDCR (STM32L4_RCC_BASE+STM32L4_RCC_BDCR_OFFSET) +#define STM32L4_RCC_CSR (STM32L4_RCC_BASE+STM32L4_RCC_CSR_OFFSET) +#define STM32L4_RCC_CRRCR (STM32L4_RCC_BASE+STM32L4_RCC_CRRCR_OFFSET) + +/* Register Bitfield Definitions ********************************************************************/ + +/* Clock control register */ + +#define RCC_CR_MSION (1 << 0) /* Bit 0: Internal Multi Speed clock enable */ +#define RCC_CR_MSIRDY (1 << 1) /* Bit 1: Internal Multi Speed clock ready flag */ +#define RCC_CR_MSIPLLEN (1 << 2) /* Bit 2: MSI clock PLL enable */ +#define RCC_CR_MSIRGSEL (1 << 3) /* Bit 2: MSI clock range selection */ +#define RCC_CR_MSIRANGE_SHIFT (4) /* Bits 7-4: MSI clock range */ +#define RCC_CR_MSIRANGE_MASK (0x0f << RCC_CR_MSIRANGE_SHIFT) +# define RCC_CR_MSIRANGE_100K (0 << RCC_CR_MSIRANGE_SHIFT) /* 0000: around 100 kHz */ +# define RCC_CR_MSIRANGE_200K (1 << RCC_CR_MSIRANGE_SHIFT) /* 0001: around 200 kHz */ +# define RCC_CR_MSIRANGE_400K (2 << RCC_CR_MSIRANGE_SHIFT) /* 0010: around 400 kHz */ +# define RCC_CR_MSIRANGE_800K (3 << RCC_CR_MSIRANGE_SHIFT) /* 0011: around 800 kHz */ +# define RCC_CR_MSIRANGE_1M (4 << RCC_CR_MSIRANGE_SHIFT) /* 0100: around 1 MHz */ +# define RCC_CR_MSIRANGE_2M (5 << RCC_CR_MSIRANGE_SHIFT) /* 0101: around 2 MHz */ +# define RCC_CR_MSIRANGE_4M (6 << RCC_CR_MSIRANGE_SHIFT) /* 0110: around 4 MHz */ +# define RCC_CR_MSIRANGE_8M (7 << RCC_CR_MSIRANGE_SHIFT) /* 0111: around 8 MHz */ +# define RCC_CR_MSIRANGE_16M (8 << RCC_CR_MSIRANGE_SHIFT) /* 1000: around 16 MHz */ +# define RCC_CR_MSIRANGE_24M (9 << RCC_CR_MSIRANGE_SHIFT) /* 1001: around 24 MHz */ +# define RCC_CR_MSIRANGE_32M (10 << RCC_CR_MSIRANGE_SHIFT) /* 1010: around 32 MHz */ +# define RCC_CR_MSIRANGE_48M (11 << RCC_CR_MSIRANGE_SHIFT) /* 1011: around 48 MHz */ + +#define RCC_CR_HSION (1 << 8) /* Bit 8: Internal High Speed clock enable */ +#define RCC_CR_HSIKERON (1 << 9) /* Bit 9: HSI16 always enable for peripheral kernels */ +#define RCC_CR_HSIRDY (1 << 10) /* Bit 10: Internal High Speed clock ready flag */ +#define RCC_CR_HSIASFS (1 << 11) /* Bit 11: HSI automatic start from stop */ + +#define RCC_CR_HSEON (1 << 16) /* Bit 16: External High Speed clock enable */ +#define RCC_CR_HSERDY (1 << 17) /* Bit 17: External High Speed clock ready flag */ +#define RCC_CR_HSEBYP (1 << 18) /* Bit 18: External High Speed clock Bypass */ +#define RCC_CR_CSSON (1 << 19) /* Bit 19: Clock Security System enable */ +#define RCC_CR_PLLON (1 << 24) /* Bit 24: PLL enable */ +#define RCC_CR_PLLRDY (1 << 25) /* Bit 25: PLL clock ready flag */ +#define RCC_CR_PLLSAI1ON (1 << 26) /* Bit 26: PLLSAI1 enable */ +#define RCC_CR_PLLSAI1RDY (1 << 27) /* Bit 27: PLLSAI1 clock ready flag */ +#define RCC_CR_PLLSAI2ON (1 << 28) /* Bit 28: PLLSAI2 enable */ +#define RCC_CR_PLLSAI2RDY (1 << 29) /* Bit 29: PLLSAI2 clock ready flag */ + +/* Internal Clock Sources Calibration */ + +#define RCC_CR_HSITRIM_SHIFT (24) /* Bits 28-24: Internal High Speed clock trimming */ +#define RCC_CR_HSITRIM_MASK (0x1f << RCC_CR_HSITRIM_SHIFT) +#define RCC_CR_HSICAL_SHIFT (16) /* Bits 23-16: Internal High Speed clock Calibration */ +#define RCC_CR_HSICAL_MASK (0xff << RCC_CR_HSICAL_SHIFT) +#define RCC_CR_MSITRIM_SHIFT (8) /* Bits 15-8: Internal Multi Speed clock trimming */ +#define RCC_CR_MSITRIM_MASK (0xff << RCC_CR_MSITRIM_SHIFT) +#define RCC_CR_MSICAL_SHIFT (0) /* Bits 7-0: Internal Multi Speed clock Calibration */ +#define RCC_CR_MSICAL_MASK (0xff << RCC_CR_MSICAL_SHIFT) + +/* Clock configuration register */ + +#define RCC_CFGR_SW_SHIFT (0) /* Bits 0-1: System clock Switch */ +#define RCC_CFGR_SW_MASK (3 << RCC_CFGR_SW_SHIFT) +# define RCC_CFGR_SW_MSI (0 << RCC_CFGR_SW_SHIFT) /* 00: HSI selected as system clock */ +# define RCC_CFGR_SW_HSI (1 << RCC_CFGR_SW_SHIFT) /* 00: HSI selected as system clock */ +# define RCC_CFGR_SW_HSE (2 << RCC_CFGR_SW_SHIFT) /* 01: HSE selected as system clock */ +# define RCC_CFGR_SW_PLL (3 << RCC_CFGR_SW_SHIFT) /* 10: PLL selected as system clock */ + +#define RCC_CFGR_SWS_SHIFT (2) /* Bits 2-3: System Clock Switch Status */ +#define RCC_CFGR_SWS_MASK (3 << RCC_CFGR_SWS_SHIFT) +# define RCC_CFGR_SWS_MSI (0 << RCC_CFGR_SWS_SHIFT) /* 00: HSI oscillator used as system clock */ +# define RCC_CFGR_SWS_HSI (1 << RCC_CFGR_SWS_SHIFT) /* 00: HSI oscillator used as system clock */ +# define RCC_CFGR_SWS_HSE (2 << RCC_CFGR_SWS_SHIFT) /* 01: HSE oscillator used as system clock */ +# define RCC_CFGR_SWS_PLL (3 << RCC_CFGR_SWS_SHIFT) /* 10: PLL used as system clock */ + +#define RCC_CFGR_HPRE_SHIFT (4) /* Bits 4-7: AHB prescaler */ +#define RCC_CFGR_HPRE_MASK (0x0f << RCC_CFGR_HPRE_SHIFT) +# define RCC_CFGR_HPRE_SYSCLK (0 << RCC_CFGR_HPRE_SHIFT) /* 0xxx: SYSCLK not divided */ +# define RCC_CFGR_HPRE_SYSCLKd2 (8 << RCC_CFGR_HPRE_SHIFT) /* 1000: SYSCLK divided by 2 */ +# define RCC_CFGR_HPRE_SYSCLKd4 (9 << RCC_CFGR_HPRE_SHIFT) /* 1001: SYSCLK divided by 4 */ +# define RCC_CFGR_HPRE_SYSCLKd8 (10 << RCC_CFGR_HPRE_SHIFT) /* 1010: SYSCLK divided by 8 */ +# define RCC_CFGR_HPRE_SYSCLKd16 (11 << RCC_CFGR_HPRE_SHIFT) /* 1011: SYSCLK divided by 16 */ +# define RCC_CFGR_HPRE_SYSCLKd64 (12 << RCC_CFGR_HPRE_SHIFT) /* 1100: SYSCLK divided by 64 */ +# define RCC_CFGR_HPRE_SYSCLKd128 (13 << RCC_CFGR_HPRE_SHIFT) /* 1101: SYSCLK divided by 128 */ +# define RCC_CFGR_HPRE_SYSCLKd256 (14 << RCC_CFGR_HPRE_SHIFT) /* 1110: SYSCLK divided by 256 */ +# define RCC_CFGR_HPRE_SYSCLKd512 (15 << RCC_CFGR_HPRE_SHIFT) /* 1111: SYSCLK divided by 512 */ + +#define RCC_CFGR_PPRE1_SHIFT (8) /* Bits 8-10: APB Low speed prescaler (APB1) */ +#define RCC_CFGR_PPRE1_MASK (7 << RCC_CFGR_PPRE1_SHIFT) +# define RCC_CFGR_PPRE1_HCLK (0 << RCC_CFGR_PPRE1_SHIFT) /* 0xx: HCLK not divided */ +# define RCC_CFGR_PPRE1_HCLKd2 (4 << RCC_CFGR_PPRE1_SHIFT) /* 100: HCLK divided by 2 */ +# define RCC_CFGR_PPRE1_HCLKd4 (5 << RCC_CFGR_PPRE1_SHIFT) /* 101: HCLK divided by 4 */ +# define RCC_CFGR_PPRE1_HCLKd8 (6 << RCC_CFGR_PPRE1_SHIFT) /* 110: HCLK divided by 8 */ +# define RCC_CFGR_PPRE1_HCLKd16 (7 << RCC_CFGR_PPRE1_SHIFT) /* 111: HCLK divided by 16 */ + +#define RCC_CFGR_PPRE2_SHIFT (11) /* Bits 11-13: APB High speed prescaler (APB2) */ +#define RCC_CFGR_PPRE2_MASK (7 << RCC_CFGR_PPRE2_SHIFT) +# define RCC_CFGR_PPRE2_HCLK (0 << RCC_CFGR_PPRE2_SHIFT) /* 0xx: HCLK not divided */ +# define RCC_CFGR_PPRE2_HCLKd2 (4 << RCC_CFGR_PPRE2_SHIFT) /* 100: HCLK divided by 2 */ +# define RCC_CFGR_PPRE2_HCLKd4 (5 << RCC_CFGR_PPRE2_SHIFT) /* 101: HCLK divided by 4 */ +# define RCC_CFGR_PPRE2_HCLKd8 (6 << RCC_CFGR_PPRE2_SHIFT) /* 110: HCLK divided by 8 */ +# define RCC_CFGR_PPRE2_HCLKd16 (7 << RCC_CFGR_PPRE2_SHIFT) /* 111: HCLK divided by 16 */ + +#define RCC_CFGR_STOPWUCK (1 << 15) /* Bit 15: Wakeup from Stop and CSS backup clock selection */ +# define RCC_CFGR_STOPWUCK_MSI (0 << 15) /* 0: MSI */ +# define RCC_CFGR_STOPWUCK_HSI (1 << 15) /* 0: HSI */ + +#define RCC_CFGR_MCO_SHIFT (24) /* Bits 24-26: Microcontroller Clock Output */ +#define RCC_CFGR_MCO_MASK (7 << RCC_CFGR_MCO_SHIFT) +# define RCC_CFGR_MCO_NONE (0 << RCC_CFGR_MCO_SHIFT) /* 000: Disabled */ +# define RCC_CFGR_MCO_SYSCLK (1 << RCC_CFGR_MCO_SHIFT) /* 001: SYSCLK system clock selected */ +# define RCC_CFGR_MCO_MSI (2 << RCC_CFGR_MCO_SHIFT) /* 010: MSI clock selected */ +# define RCC_CFGR_MCO_HSI (3 << RCC_CFGR_MCO_SHIFT) /* 011: HSI clock selected */ +# define RCC_CFGR_MCO_HSE (4 << RCC_CFGR_MCO_SHIFT) /* 100: HSE clock selected */ +# define RCC_CFGR_MCO_PLL (5 << RCC_CFGR_MCO_SHIFT) /* 101: Main PLL selected */ +# define RCC_CFGR_MCO_LSI (6 << RCC_CFGR_MCO_SHIFT) /* 110: LSI clock selected */ +# define RCC_CFGR_MCO_LSE (7 << RCC_CFGR_MCO_SHIFT) /* 111: LSE clock selected */ + +#define RCC_CFGR_MCOPRE_SHIFT (28) /* Bits 28-30: MCO prescaler */ +#define RCC_CFGR_MCOPRE_MASK (7 << RCC_CFGR_MCOPRE_SHIFT) +# define RCC_CFGR_MCOPRE_NONE (0 << RCC_CFGR_MCOPRE_SHIFT) /* 000: no division */ +# define RCC_CFGR_MCOPRE_DIV2 (1 << RCC_CFGR_MCOPRE_SHIFT) /* 001: division by 2 */ +# define RCC_CFGR_MCOPRE_DIV4 (2 << RCC_CFGR_MCOPRE_SHIFT) /* 010: division by 4 */ +# define RCC_CFGR_MCOPRE_DIV8 (3 << RCC_CFGR_MCOPRE_SHIFT) /* 011: division by 8 */ +# define RCC_CFGR_MCOPRE_DIV16 (4 << RCC_CFGR_MCOPRE_SHIFT) /* 100: division by 16 */ + +/* PLL configuration register */ + +#define RCC_PLLCFG_PLLSRC_SHIFT (0) /* Bit 0-1: Main PLL(PLL) and audio PLLs (PLLSAIx) + * entry clock source */ +#define RCC_PLLCFG_PLLSRC_MASK (3 << RCC_PLLCFG_PLLSRC_SHIFT) +# define RCC_PLLCFG_PLLSRC_NONE (0 << RCC_PLLCFG_PLLSRC_SHIFT) /* 000: No clock sent to PLLs */ +# define RCC_PLLCFG_PLLSRC_MSI (1 << RCC_PLLCFG_PLLSRC_SHIFT) /* 001: MSI selected as PLL source */ +# define RCC_PLLCFG_PLLSRC_HSI (2 << RCC_PLLCFG_PLLSRC_SHIFT) /* 001: HSI selected as PLL source */ +# define RCC_PLLCFG_PLLSRC_HSE (3 << RCC_PLLCFG_PLLSRC_SHIFT) /* 001: HSE selected as PLL source */ + +#define RCC_PLLCFG_PLLM_SHIFT (4) /* Bits 4-6: Main PLL (PLL) input clock divider */ +#define RCC_PLLCFG_PLLM_MASK (0x07 << RCC_PLLCFG_PLLM_SHIFT) +# define RCC_PLLCFG_PLLM(n) ((n-1) << RCC_PLLCFG_PLLM_SHIFT) /* m = 1..8 */ + +#define RCC_PLLCFG_PLLN_SHIFT (8) /* Bits 6-14: Main PLL (PLL) VCO multiplier */ +#define RCC_PLLCFG_PLLN_MASK (0x7f << RCC_PLLCFG_PLLN_SHIFT) +# define RCC_PLLCFG_PLLN(n) ((n) << RCC_PLLCFG_PLLN_SHIFT) /* n = 8..86 */ + +#define RCC_PLLCFG_PLLPEN (1 << 16) /* Bit 16: Main PLL PLLSAI3CLK output enable */ + +#define RCC_PLLCFG_PLLP (1 << 17) /* Bit 17: Main PLL div factor for PLLSAI3CLK */ +# define RCC_PLLCFG_PLLP_7 0 /* 0: PLLP = 7 */ +# define RCC_PLLCFG_PLLP_17 RCC_PLLCFG_PLLP /* 1: PLLP = 17 */ + +#define RCC_PLLCFG_PLLQEN (1 << 20) /* Bit 20: Main PLL PLL48M1CLK output enable */ + +#define RCC_PLLCFG_PLLQ_SHIFT (21) +#define RCC_PLLCFG_PLLQ_MASK (3 << RCC_PLLCFG_PLLQ_SHIFT) +# define RCC_PLLCFG_PLLQ(n) ((((n)>>1)-1)<< RCC_PLLCFG_PLLQ_SHIFT) /* n=2,4,6,8 */ +# define RCC_PLLCFG_PLLQ_2 (0 << RCC_PLLCFG_PLLQ_SHIFT) /* 00: PLLQ = 2 */ +# define RCC_PLLCFG_PLLQ_4 (1 << RCC_PLLCFG_PLLQ_SHIFT) /* 01: PLLQ = 4 */ +# define RCC_PLLCFG_PLLQ_6 (2 << RCC_PLLCFG_PLLQ_SHIFT) /* 10: PLLQ = 6 */ +# define RCC_PLLCFG_PLLQ_8 (3 << RCC_PLLCFG_PLLQ_SHIFT) /* 11: PLLQ = 8 */ + +#define RCC_PLLCFG_PLLREN (1 << 24) /* Bit 24: Main PLL PLLCLK output enable */ + +#define RCC_PLLCFG_PLLR_SHIFT (25) +#define RCC_PLLCFG_PLLR_MASK (3 << RCC_PLLCFG_PLLR_SHIFT) +# define RCC_PLLCFG_PLLR(n) ((((n)>>1)-1)<< RCC_PLLCFG_PLLR_SHIFT) /* n=2,4,6,8 */ +# define RCC_PLLCFG_PLLR_2 (0 << RCC_PLLCFG_PLLR_SHIFT) /* 00: PLLR = 2 */ +# define RCC_PLLCFG_PLLR_4 (1 << RCC_PLLCFG_PLLR_SHIFT) /* 01: PLLR = 4 */ +# define RCC_PLLCFG_PLLR_6 (2 << RCC_PLLCFG_PLLR_SHIFT) /* 10: PLLR = 6 */ +# define RCC_PLLCFG_PLLR_8 (3 << RCC_PLLCFG_PLLR_SHIFT) /* 11: PLLR = 8 */ + +#define RCC_PLLCFG_RESET (0x00001000) /* PLLCFG reset value */ + +/* PLLSAI1 Configuration register */ + +#define RCC_PLLSAI1CFG_PLLN_SHIFT (8) /* Bits 6-14: SAI1 PLL (PLLSAI1) VCO multiplier */ +#define RCC_PLLSAI1CFG_PLLN_MASK (0x7f << RCC_PLLSAI1CFG_PLLN_SHIFT) +# define RCC_PLLSAI1CFG_PLLN(n) ((n) << RCC_PLLSAI1CFG_PLLN_SHIFT) /* n = 8..86 */ + +#define RCC_PLLSAI1CFG_PLLPEN (1 << 16) /* Bit 16: SAI1 PLL PLLSAI1CLK output enable */ + +#define RCC_PLLSAI1CFG_PLLP (1 << 17) /* Bit 17: Main PLL div factor for PLLSAI1CLK */ +# define RCC_PLLSAI1CFG_PLLP_7 0 /* 0: PLLP = 7 */ +# define RCC_PLLSAI1CFG_PLLP_17 RCC_PLLSAI1CFG_PLLP /* 1: PLLP = 17 */ + +#define RCC_PLLSAI1CFG_PLLQEN (1 << 20) /* Bit 20: Main PLL PLL48M2CLK output enable */ + +#define RCC_PLLSAI1CFG_PLLQ_SHIFT (21) +#define RCC_PLLSAI1CFG_PLLQ_MASK (3 << RCC_PLLSAI1CFG_PLLQ_SHIFT) +# define RCC_PLLSAI1CFG_PLLQ(n) ((((n)>>1)-1)<< RCC_PLLSAI1CFG_PLLQ_SHIFT) /* n=2,4,6,8 */ +# define RCC_PLLSAI1CFG_PLLQ_2 (0 << RCC_PLLSAI1CFG_PLLQ_SHIFT) /* 00: PLLQ = 2 */ +# define RCC_PLLSAI1CFG_PLLQ_4 (1 << RCC_PLLSAI1CFG_PLLQ_SHIFT) /* 01: PLLQ = 4 */ +# define RCC_PLLSAI1CFG_PLLQ_6 (2 << RCC_PLLSAI1CFG_PLLQ_SHIFT) /* 10: PLLQ = 6 */ +# define RCC_PLLSAI1CFG_PLLQ_8 (3 << RCC_PLLSAI1CFG_PLLQ_SHIFT) /* 11: PLLQ = 8 */ + +#define RCC_PLLSAI1CFG_PLLREN (1 << 24) /* Bit 24: SAI1 PLL PLLADC1CLK output enable */ + +#define RCC_PLLSAI1CFG_PLLR_SHIFT (25) +#define RCC_PLLSAI1CFG_PLLR_MASK (3 << RCC_PLLSAI1CFG_PLLR_SHIFT) +# define RCC_PLLSAI1CFG_PLLR(n) ((((n)>>1)-1)<< RCC_PLLSAI1CFG_PLLR_SHIFT) /* n=2,4,6,8 */ +# define RCC_PLLSAI1CFG_PLLR_2 (0 << RCC_PLLSAI1CFG_PLLR_SHIFT) /* 00: PLLR = 2 */ +# define RCC_PLLSAI1CFG_PLLR_4 (1 << RCC_PLLSAI1CFG_PLLR_SHIFT) /* 01: PLLR = 4 */ +# define RCC_PLLSAI1CFG_PLLR_6 (2 << RCC_PLLSAI1CFG_PLLR_SHIFT) /* 10: PLLR = 6 */ +# define RCC_PLLSAI1CFG_PLLR_8 (3 << RCC_PLLSAI1CFG_PLLR_SHIFT) /* 11: PLLR = 8 */ + +/* PLLSAI2 Configuration register */ + +#define RCC_PLLSAI2CFG_PLLN_SHIFT (8) /* Bits 6-14: SAI2 PLL (PLLSAI2) VCO multiplier */ +#define RCC_PLLSAI2CFG_PLLN_MASK (0x7f << RCC_PLLSAI2CFG_PLLN_SHIFT) +# define RCC_PLLSAI2CFG_PLLN(n) ((n) << RCC_PLLSAI2CFG_PLLN_SHIFT) /* n = 8..86 */ + +#define RCC_PLLSAI2CFG_PLLPEN (1 << 16) /* Bit 16: SAI1 PLL PLLSAI2CLK output enable */ + +#define RCC_PLLSAI2CFG_PLLP (1 << 17) /* Bit 17: Main PLL div factor for PLLSAI2CLK */ +# define RCC_PLLSAI2CFG_PLLP_7 0 /* 0: PLLP = 7 */ +# define RCC_PLLSAI2CFG_PLLP_17 RCC_PLLSAI2CFG_PLLP /* 1: PLLP = 17 */ + +#define RCC_PLLSAI2CFG_PLLREN (1 << 24) /* Bit 24: SAI2 PLL PLLADC2CLK output enable */ + +#define RCC_PLLSAI2CFG_PLLR_SHIFT (25) +#define RCC_PLLSAI2CFG_PLLR_MASK (3 << RCC_PLLSAI2CFG_PLLR_SHIFT) +# define RCC_PLLSAI2CFG_PLLR(n) ((((n)>>1)-1)<< RCC_PLLSAI2CFG_PLLR_SHIFT) /* n=2,4,6,8 */ +# define RCC_PLLSAI2CFG_PLLR_2 (0 << RCC_PLLSAI2CFG_PLLR_SHIFT) /* 00: PLLR = 2 */ +# define RCC_PLLSAI2CFG_PLLR_4 (1 << RCC_PLLSAI2CFG_PLLR_SHIFT) /* 01: PLLR = 4 */ +# define RCC_PLLSAI2CFG_PLLR_6 (2 << RCC_PLLSAI2CFG_PLLR_SHIFT) /* 10: PLLR = 6 */ +# define RCC_PLLSAI2CFG_PLLR_8 (3 << RCC_PLLSAI2CFG_PLLR_SHIFT) /* 11: PLLR = 8 */ + +/* Clock interrupt enable register */ + +#define RCC_CIR_LSIRDYIE (1 << 0) /* Bit 0: LSI Ready Interrupt Enable */ +#define RCC_CIR_LSERDYIE (1 << 1) /* Bit 1: LSE Ready Interrupt Enable */ +#define RCC_CIR_MSIRDYIE (1 << 2) /* Bit 2: MSI Ready Interrupt Enable */ +#define RCC_CIR_HSIRDYIE (1 << 3) /* Bit 3: HSI Ready Interrupt Enable */ +#define RCC_CIR_HSERDYIE (1 << 4) /* Bit 4: HSE Ready Interrupt Enable */ +#define RCC_CIR_PLLRDYIE (1 << 5) /* Bit 5: PLL Ready Interrupt Enable */ +#define RCC_CIR_PLLSAI1RDYIE (1 << 6) /* Bit 6: PLLSAI1 Ready Interrupt enable */ +#define RCC_CIR_PLLSAI2RDYIE (1 << 7) /* Bit 7: PLLSAI2 Ready Interrupt enable */ +#define RCC_CIR_LSECSSIE (1 << 9) /* Bit 9: LSE Clock Security System Interrupt Enable */ +#define RCC_CIR_HSI48RDYIE (1 << 10) /* Bit 10: HSI48 Ready Interrupt Enable */ + +/* Clock interrupt flag register */ + +#define RCC_CIR_LSIRDYIF (1 << 0) /* Bit 0: LSI Ready Interrupt Flag */ +#define RCC_CIR_LSERDYIF (1 << 1) /* Bit 1: LSE Ready Interrupt Flag */ +#define RCC_CIR_MSIRDYIF (1 << 2) /* Bit 2: MSI Ready Interrupt Flag */ +#define RCC_CIR_HSIRDYIF (1 << 3) /* Bit 3: HSI Ready Interrupt Flag */ +#define RCC_CIR_HSERDYIF (1 << 4) /* Bit 4: HSE Ready Interrupt Flag */ +#define RCC_CIR_PLLRDYIF (1 << 5) /* Bit 5: PLL Ready Interrupt Flag */ +#define RCC_CIR_PLLSAI1RDYIF (1 << 6) /* Bit 6: PLLSAI1 Ready Interrupt Flag */ +#define RCC_CIR_PLLSAI2RDYIF (1 << 7) /* Bit 7: PLLSAI2 Ready Interrupt Flag */ +#define RCC_CIR_CSSF (1 << 8) /* Bit 8: Clock Security System Interrupt Flag */ +#define RCC_CIR_LSECSSIF (1 << 9) /* Bit 9: LSE Clock Security System Interrupt Flag */ +#define RCC_CIR_HSI48RDYIF (1 << 10) /* Bit 10: HSI48 Ready Interrupt Flag */ + +/* Clock interrupt clear register */ + +#define RCC_CIR_LSIRDYIC (1 << 0) /* Bit 0: LSI Ready Interrupt Clear */ +#define RCC_CIR_LSERDYIC (1 << 1) /* Bit 1: LSE Ready Interrupt Clear */ +#define RCC_CIR_MSIRDYIC (1 << 2) /* Bit 2: MSI Ready Interrupt Clear */ +#define RCC_CIR_HSIRDYIC (1 << 3) /* Bit 3: HSI Ready Interrupt Clear */ +#define RCC_CIR_HSERDYIC (1 << 4) /* Bit 4: HSE Ready Interrupt Clear */ +#define RCC_CIR_PLLRDYIC (1 << 5) /* Bit 5: PLL Ready Interrupt Clear */ +#define RCC_CIR_PLLSAI1RDYIC (1 << 6) /* Bit 6: PLLSAI1 Ready Interrupt Clear */ +#define RCC_CIR_PLLSAI2RDYIC (1 << 7) /* Bit 7: PLLSAI2 Ready Interrupt Clear */ +#define RCC_CIR_CSSC (1 << 8) /* Bit 8: Clock Security System Interrupt Clear */ +#define RCC_CIR_LSECSSIC (1 << 9) /* Bit 9: LSE Clock Security System Interrupt Clear */ +#define RCC_CIR_HSI48RDYIC (1 << 10) /* Bit 10: HSI48 Oscillator Ready Interrupt Clear */ + +/* AHB1 peripheral reset register */ + +#define RCC_AHB1RSTR_DMA1RST (1 << 0) /* Bit 0: DMA1 reset */ +#define RCC_AHB1RSTR_DMA2RST (1 << 1) /* Bit 1: DMA2 reset */ +#define RCC_AHB1RSTR_FLASHRST (1 << 8) /* Bit 8: Flash memory interface reset */ +#define RCC_AHB1RSTR_CRCRST (1 << 12) /* Bit 12: CRC reset */ +#define RCC_AHB1RSTR_TSCRST (1 << 16) /* Bit 16: Touch Sensing Controller reset */ +#define RCC_AHB1RSTR_DMA2DRST (1 << 17) /* Bit 17: DMA2D reset */ + +/* AHB2 peripheral reset register */ + +#define RCC_AHB1ENR_GPIOEN(port) (1 << (port)) +#define RCC_AHB2RSTR_GPIOARST (1 << 0) /* Bit 0: IO port A reset */ +#define RCC_AHB2RSTR_GPIOBRST (1 << 1) /* Bit 1: IO port B reset */ +#define RCC_AHB2RSTR_GPIOCRST (1 << 2) /* Bit 2: IO port C reset */ +#define RCC_AHB2RSTR_GPIODRST (1 << 3) /* Bit 3: IO port D reset */ +#define RCC_AHB2RSTR_GPIOERST (1 << 4) /* Bit 4: IO port E reset */ +#define RCC_AHB2RSTR_GPIOHRST (1 << 7) /* Bit 7: IO port H reset */ +#define RCC_AHB2RSTR_ADCRST (1 << 13) /* Bit 13: ADC interface reset (common to all ADCs) */ +#define RCC_AHB2RSTR_DCMIRST (1 << 14) /* Bit 14: DCMI interface reset */ +#define RCC_AHB2RSTR_AESRST (1 << 16) /* Bit 16: AES Cryptographic module reset */ +#define RCC_AHB2RSTR_HASHRST (1 << 17) /* Bit 17: HASH module reset */ +#define RCC_AHB2RSTR_RNGRST (1 << 18) /* Bit 18: Random number generator module reset */ + +/* AHB3 peripheral reset register */ + +#define RCC_AHB3RSTR_FSMCRST (1 << 0) /* Bit 0: Flexible static memory controller module reset */ +#define RCC_AHB3RSTR_QSPIRST (1 << 8) /* Bit 8: Quad SPI module reset */ + +/* APB1 Peripheral reset register 1 */ + +#define RCC_APB1RSTR1_TIM2RST (1 << 0) /* Bit 0: TIM2 reset */ +#define RCC_APB1RSTR1_TIM3RST (1 << 1) /* Bit 1: TIM3 reset */ +#define RCC_APB1RSTR1_TIM4RST (1 << 2) /* Bit 2: TIM4 reset */ +#define RCC_APB1RSTR1_TIM5RST (1 << 3) /* Bit 3: TIM5 reset */ +#define RCC_APB1RSTR1_TIM6RST (1 << 4) /* Bit 4: TIM6 reset */ +#define RCC_APB1RSTR1_TIM7RST (1 << 5) /* Bit 5: TIM7 reset */ +#define RCC_APB1RSTR1_LCDRST (1 << 9) /* Bit 9: LCD controller reset */ +#define RCC_APB1RSTR1_SPI2RST (1 << 14) /* Bit 14: SPI2 reset */ +#define RCC_APB1RSTR1_SPI3RST (1 << 15) /* Bit 15: SPI3 reset */ +#define RCC_APB1RSTR1_USART2RST (1 << 17) /* Bit 17: USART2 reset */ +#define RCC_APB1RSTR1_USART3RST (1 << 18) /* Bit 18: USART3 reset */ +#define RCC_APB1RSTR1_UART4RST (1 << 19) /* Bit 19: USART4 reset */ +#define RCC_APB1RSTR1_UART5RST (1 << 20) /* Bit 20: USART5 reset */ +#define RCC_APB1RSTR1_I2C1RST (1 << 21) /* Bit 21: I2C1 reset */ +#define RCC_APB1RSTR1_I2C2RST (1 << 22) /* Bit 22: I2C2 reset */ +#define RCC_APB1RSTR1_I2C3RST (1 << 23) /* Bit 23: I2C3 reset */ +#define RCC_APB1RSTR1_CRSRST (1 << 24) /* Bit 24: CRS reset */ +#define RCC_APB1RSTR1_CAN1RST (1 << 25) /* Bit 25: CAN1 reset */ +#define RCC_APB1RSTR1_USBFSRST (1 << 26) /* Bit 26: USB FS reset */ +#define RCC_APB1RSTR1_PWRRST (1 << 28) /* Bit 28: Power interface reset */ +#define RCC_APB1RSTR1_DAC1RST (1 << 29) /* Bit 29: DAC1 reset */ +#define RCC_APB1RSTR1_OPAMPRST (1 << 30) /* Bit 30: OPAMP reset */ +#define RCC_APB1RSTR1_LPTIM1RST (1 << 31) /* Bit 31: Low-power Timer 1 reset */ + +/* APB1 Peripheral reset register 2 */ + +#define RCC_APB1RSTR2_LPUART1RST (1 << 0) /* Bit 0: Low-power UART 1 reset */ +#define RCC_APB1RSTR2_I2C4RST (1 << 1) /* Bit 1: I2C4 reset */ +#define RCC_APB1RSTR2_SWPMI1RST (1 << 2) /* Bit 2: Single Wire Protocol reset */ +#define RCC_APB1RSTR2_LPTIM2RST (1 << 5) /* Bit 5: Low-power Timer 2 reset */ + +/* APB2 Peripheral reset register */ + +#define RCC_APB2RSTR_SYSCFGRST (1 << 0) /* Bit 0: System configuration controller reset */ +#define RCC_APB2RSTR_SDMMCRST (1 << 10) /* Bit 10: SDMMC reset */ +#define RCC_APB2RSTR_TIM1RST (1 << 11) /* Bit 11: TIM1 reset */ +#define RCC_APB2RSTR_SPI1RST (1 << 12) /* Bit 12: SPI1 reset */ +#define RCC_APB2RSTR_TIM8RST (1 << 13) /* Bit 13: TIM8 reset */ +#define RCC_APB2RSTR_USART1RST (1 << 14) /* Bit 14: USART1 reset */ +#define RCC_APB2RSTR_TIM15RST (1 << 16) /* Bit 16: TIM15 reset */ +#define RCC_APB2RSTR_TIM16RST (1 << 17) /* Bit 17: TIM16 reset */ +#define RCC_APB2RSTR_TIM17RST (1 << 18) /* Bit 18: TIM17 reset */ +#define RCC_APB2RSTR_SAI1RST (1 << 21) /* Bit 21: SAI1 reset */ +#define RCC_APB2RSTR_SAI2RST (1 << 22) /* Bit 22: SAI2 reset */ +#define RCC_APB2RSTR_DFSDMRST (1 << 24) /* Bit 24: DFSDM reset */ + +/* AHB1 Peripheral Clock enable register */ + +#define RCC_AHB1ENR_DMA1EN (1 << 0) /* Bit 0: DMA1 enable */ +#define RCC_AHB1ENR_DMA2EN (1 << 1) /* Bit 1: DMA2 enable */ +#define RCC_AHB1ENR_FLASHEN (1 << 8) /* Bit 8: Flash memory interface enable */ +#define RCC_AHB1ENR_CRCEN (1 << 12) /* Bit 12: CRC enable */ +#define RCC_AHB1ENR_TSCEN (1 << 16) /* Bit 16: Touch Sensing Controller enable */ +#define RCC_AHB1ENR_DMA2DEN (1 << 17) /* Bit 17: DMA2D enable */ + +/* AHB2 Peripheral Clock enable register */ + +#define RCC_AHB2ENR_GPIOAEN (1 << 0) /* Bit 0: IO port A enable */ +#define RCC_AHB2ENR_GPIOBEN (1 << 1) /* Bit 1: IO port B enable */ +#define RCC_AHB2ENR_GPIOCEN (1 << 2) /* Bit 2: IO port C enable */ +#define RCC_AHB2ENR_GPIODEN (1 << 3) /* Bit 3: IO port D enable */ +#define RCC_AHB2ENR_GPIOEEN (1 << 4) /* Bit 4: IO port E enable */ +#define RCC_AHB2ENR_GPIOHEN (1 << 7) /* Bit 7: IO port H enable */ +#define RCC_AHB2ENR_ADCEN (1 << 13) /* Bit 13: ADC interface enable (common to all ADCs) */ +#define RCC_AHB2ENR_DCMIEN (1 << 14) /* Bit 14: DCMI interface enable */ +#define RCC_AHB2ENR_AESEN (1 << 16) /* Bit 16: AES Cryptographic module enable */ +#define RCC_AHB2ENR_HASHEN (1 << 17) /* Bit 17: HASH module enable */ +#define RCC_AHB2ENR_RNGEN (1 << 18) /* Bit 18: Random number generator module enable */ + +/* AHB3 Peripheral Clock enable register */ + +#define RCC_AHB3ENR_FSMCEN (1 << 0) /* Bit 0: Flexible static memory controller module enable */ +#define RCC_AHB3ENR_QSPIEN (1 << 8) /* Bit 8: Quad SPI module enable */ + +/* APB1 Peripheral Clock enable register 1 */ + +#define RCC_APB1ENR1_TIM2EN (1 << 0) /* Bit 0: TIM2 enable */ +#define RCC_APB1ENR1_TIM3EN (1 << 1) /* Bit 1: TIM3 enable */ +#define RCC_APB1ENR1_TIM4EN (1 << 2) /* Bit 2: TIM4 enable */ +#define RCC_APB1ENR1_TIM5EN (1 << 3) /* Bit 3: TIM5 enable */ +#define RCC_APB1ENR1_TIM6EN (1 << 4) /* Bit 4: TIM6 enable */ +#define RCC_APB1ENR1_TIM7EN (1 << 5) /* Bit 5: TIM7 enable */ +#define RCC_APB1ENR1_LCDEN (1 << 9) /* Bit 9: LCD controller enable */ +#define RCC_APB1ENR1_RTCAPBEN (1 << 10) /* Bit 10: RTC APB clock enable */ +#define RCC_APB1ENR1_WWDGEN (1 << 11) /* Bit 11: Windowed Watchdog enable */ +#define RCC_APB1ENR1_SPI2EN (1 << 14) /* Bit 14: SPI2 enable */ +#define RCC_APB1ENR1_SPI3EN (1 << 15) /* Bit 15: SPI3 enable */ +#define RCC_APB1ENR1_USART2EN (1 << 17) /* Bit 17: USART2 enable */ +#define RCC_APB1ENR1_USART3EN (1 << 18) /* Bit 18: USART3 enable */ +#define RCC_APB1ENR1_UART4EN (1 << 19) /* Bit 19: USART4 enable */ +#define RCC_APB1ENR1_UART5EN (1 << 20) /* Bit 20: USART5 enable */ +#define RCC_APB1ENR1_I2C1EN (1 << 21) /* Bit 21: I2C1 enable */ +#define RCC_APB1ENR1_I2C2EN (1 << 22) /* Bit 22: I2C2 enable */ +#define RCC_APB1ENR1_I2C3EN (1 << 23) /* Bit 23: I2C3 enable */ +#define RCC_APB1ENR1_CRSEN (1 << 24) /* Bit 24: CRSEN enable */ +#define RCC_APB1ENR1_CAN1EN (1 << 25) /* Bit 25: CAN1 enable */ +#define RCC_APB1ENR1_USBFSEN (1 << 26) /* Bit 26: USB FS enable */ +#define RCC_APB1ENR1_PWREN (1 << 28) /* Bit 28: Power interface enable */ +#define RCC_APB1ENR1_DAC1EN (1 << 29) /* Bit 29: DAC1 enable */ +#define RCC_APB1ENR1_OPAMPEN (1 << 30) /* Bit 30: OPAMP enable */ +#define RCC_APB1ENR1_LPTIM1EN (1 << 31) /* Bit 31: Low-power Timer 1 enable */ + +/* APB1 Peripheral Clock enable register 2 */ + +#define RCC_APB1ENR2_LPUART1EN (1 << 0) /* Bit 0: Low-power UART 1 enable */ +#define RCC_APB1ENR2_I2C4EN (1 << 1) /* Bit 1: I2C4 enable */ +#define RCC_APB1ENR2_SWPMI1EN (1 << 2) /* Bit 2: Single Wire Protocol enable */ +#define RCC_APB1ENR2_LPTIM2EN (1 << 5) /* Bit 5: Low-power Timer 2 enable */ + +/* APB2 Peripheral Clock enable register */ + +#define RCC_APB2ENR_SYSCFGEN (1 << 0) /* Bit 0: System configuration controller enable */ +#define RCC_APB2ENR_FWEN (1 << 7) /* Bit 7: Firewall enable */ +#define RCC_APB2ENR_SDMMCEN (1 << 10) /* Bit 10: SDMMC enable */ +#define RCC_APB2ENR_TIM1EN (1 << 11) /* Bit 11: TIM1 enable */ +#define RCC_APB2ENR_SPI1EN (1 << 12) /* Bit 12: SPI1 enable */ +#define RCC_APB2ENR_TIM8EN (1 << 13) /* Bit 13: TIM8 enable */ +#define RCC_APB2ENR_USART1EN (1 << 14) /* Bit 14: USART1 enable */ +#define RCC_APB2ENR_TIM15EN (1 << 16) /* Bit 16: TIM15 enable */ +#define RCC_APB2ENR_TIM16EN (1 << 17) /* Bit 17: TIM16 enable */ +#define RCC_APB2ENR_TIM17EN (1 << 18) /* Bit 18: TIM17 enable */ +#define RCC_APB2ENR_SAI1EN (1 << 21) /* Bit 21: SAI1 enable */ +#define RCC_APB2ENR_SAI2EN (1 << 22) /* Bit 22: SAI2 enable */ +#define RCC_APB2ENR_DFSDMEN (1 << 24) /* Bit 24: DFSDM enable */ + +/* RCC AHB1 low power mode peripheral clock enable register */ + +#define RCC_AHB1SMENR_DMA1LPSMEN (1 << 0) /* Bit 0: DMA1 enable during Sleep mode */ +#define RCC_AHB1SMENR_DMA2LPSMEN (1 << 1) /* Bit 1: DMA2 enable during Sleep mode */ +#define RCC_AHB1SMENR_FLASHLPSMEN (1 << 8) /* Bit 8: Flash memory interface enable during Sleep mode */ +#define RCC_AHB1SMENR_SRAM1SMEN (1 << 9) /* Bit 9: SRAM1 enable during Sleep mode */ +#define RCC_AHB1SMENR_CRCLPSMEN (1 << 12) /* Bit 12: CRC enable during Sleep mode */ +#define RCC_AHB1SMENR_TSCLPSMEN (1 << 16) /* Bit 16: Touch Sensing Controller enable during Sleep mode */ +#define RCC_AHB1SMENR_DMA2DSMEN (1 << 17) /* Bit 17: DMA2D enable during Sleep mode */ + +/* RCC AHB2 low power mode peripheral clock enable register */ + +#define RCC_AHB2SMENR_GPIOASMEN (1 << 0) /* Bit 0: IO port A enable during Sleep mode */ +#define RCC_AHB2SMENR_GPIOBSMEN (1 << 1) /* Bit 1: IO port B enable during Sleep mode */ +#define RCC_AHB2SMENR_GPIOCSMEN (1 << 2) /* Bit 2: IO port C enable during Sleep mode */ +#define RCC_AHB2SMENR_GPIODSMEN (1 << 3) /* Bit 3: IO port D enable during Sleep mode */ +#define RCC_AHB2SMENR_GPIOESMEN (1 << 4) /* Bit 4: IO port E enable during Sleep mode */ +#define RCC_AHB2SMENR_GPIOHSMEN (1 << 7) /* Bit 7: IO port H enable during Sleep mode */ +#define RCC_AHB2SMENR_SRAM2SMEN (1 << 9) /* Bit 9: SRAM2 enable during Sleep mode */ +#define RCC_AHB2SMENR_ADCSMEN (1 << 13) /* Bit 13: ADC interface enable during Sleep mode (common to all ADCs) */ +#define RCC_AHB2SMENR_DCMISMEN (1 << 14) /* Bit 14: DCMI interface enable during Sleep mode */ +#define RCC_AHB2SMENR_AESSMEN (1 << 16) /* Bit 16: AES Cryptographic module enable during Sleep mode */ +#define RCC_AHB2SMENR_HASHSMEN (1 << 17) /* Bit 17: HASH module enable during Sleep mode */ +#define RCC_AHB2SMENR_RNGSMEN (1 << 18) /* Bit 18: Random number generator module enable during Sleep mode */ + +/* RCC AHB3 low power mode peripheral clock enable register */ + +#define RCC_AHB3SMENR_FSMCSMEN (1 << 0) /* Bit 0: Flexible static memory controller module enable during Sleep mode */ +#define RCC_AHB3SMENR_QSPISMEN (1 << 8) /* Bit 8: Quad SPI module enable during Sleep mode */ + +/* RCC APB1 low power mode peripheral clock enable register 1 */ + +#define RCC_APB1SMENR1_TIM2SMEN (1 << 0) /* Bit 0: TIM2 enable during Sleep mode */ +#define RCC_APB1SMENR1_TIM3SMEN (1 << 1) /* Bit 1: TIM3 enable during Sleep mode */ +#define RCC_APB1SMENR1_TIM4SMEN (1 << 2) /* Bit 2: TIM4 enable during Sleep mode */ +#define RCC_APB1SMENR1_TIM5SMEN (1 << 3) /* Bit 3: TIM5 enable during Sleep mode */ +#define RCC_APB1SMENR1_TIM6SMEN (1 << 4) /* Bit 4: TIM6 enable during Sleep mode */ +#define RCC_APB1SMENR1_TIM7SMEN (1 << 5) /* Bit 5: TIM7 enable during Sleep mode */ +#define RCC_APB1SMENR1_LCDSMEN (1 << 9) /* Bit 9: LCD controller enable during Sleep mode */ +#define RCC_APB1SMENR1_RTCAPBSMEN (1 << 10) /* Bit 10: RTC APB clock enable during Sleep mode */ +#define RCC_APB1SMENR1_WWDGSMEN (1 << 11) /* Bit 11: Windowed Watchdog enable during Sleep mode */ +#define RCC_APB1SMENR1_SPI2SMEN (1 << 14) /* Bit 14: SPI2 enable during Sleep mode */ +#define RCC_APB1SMENR1_SPI3SMEN (1 << 15) /* Bit 15: SPI3 enable during Sleep mode */ +#define RCC_APB1SMENR1_USART2SMEN (1 << 17) /* Bit 17: USART2 enable during Sleep mode */ +#define RCC_APB1SMENR1_USART3SMEN (1 << 18) /* Bit 18: USART3 enable during Sleep mode */ +#define RCC_APB1SMENR1_UART4SMEN (1 << 19) /* Bit 19: USART4 enable during Sleep mode */ +#define RCC_APB1SMENR1_UART5SMEN (1 << 20) /* Bit 20: USART5 enable during Sleep mode */ +#define RCC_APB1SMENR1_I2C1SMEN (1 << 21) /* Bit 21: I2C1 enable during Sleep mode */ +#define RCC_APB1SMENR1_I2C2SMEN (1 << 22) /* Bit 22: I2C2 enable during Sleep mode */ +#define RCC_APB1SMENR1_I2C3SMEN (1 << 23) /* Bit 23: I2C3 enable during Sleep mode */ +#define RCC_APB1SMENR1_CRSSMEN (1 << 24) /* Bit 24: CRS enable during Sleep mode */ +#define RCC_APB1SMENR1_CAN1SMEN (1 << 25) /* Bit 25: CAN1 enable during Sleep mode */ +#define RCC_APB1SMENR1_USBFSSMEN (1 << 26) /* Bit 26: USB FS enable during Sleep mode */ +#define RCC_APB1SMENR1_PWRSMEN (1 << 28) /* Bit 28: Power interface enable during Sleep mode */ +#define RCC_APB1SMENR1_DAC1SMEN (1 << 29) /* Bit 29: DAC1 enable during Sleep mode */ +#define RCC_APB1SMENR1_OPAMPSMEN (1 << 30) /* Bit 30: OPAMP enable during Sleep mode */ +#define RCC_APB1SMENR1_LPTIM1SMEN (1 << 31) /* Bit 31: Low-power Timer 1 enable during Sleep mode */ + +/* RCC APB1 low power modeperipheral clock enable register 2 */ + +#define RCC_APB1SMENR2_LPUART1SMEN (1 << 0) /* Bit 0: Low-power UART 1 enable during Sleep mode */ +#define RCC_APB1SMENR2_I2C4SMEN (1 << 1) /* Bit 1: I2C4 enable during Sleep mode */ +#define RCC_APB1SMENR2_SWPMI1SMEN (1 << 2) /* Bit 2: Single Wire Protocol enable during Sleep mode */ +#define RCC_APB1SMENR2_LPTIM2SMEN (1 << 5) /* Bit 5: Low-power Timer 2 enable during Sleep mode */ + +/* RCC APB2 low power mode peripheral clock enable register */ + +#define RCC_APB2SMENR_SYSCFGSMEN (1 << 0) /* Bit 0: System configuration controller enable during Sleep mode */ +#define RCC_APB2SMENR_SDMMCSMEN (1 << 10) /* Bit 10: SDMMC enable during Sleep mode */ +#define RCC_APB2SMENR_TIM1SMEN (1 << 11) /* Bit 11: TIM1 enable during Sleep mode */ +#define RCC_APB2SMENR_SPI1SMEN (1 << 12) /* Bit 12: SPI1 enable during Sleep mode */ +#define RCC_APB2SMENR_TIM8SMEN (1 << 13) /* Bit 13: TIM8 enable during Sleep mode */ +#define RCC_APB2SMENR_USART1SMEN (1 << 14) /* Bit 14: USART1 enable during Sleep mode */ +#define RCC_APB2SMENR_TIM15SMEN (1 << 16) /* Bit 16: TIM15 enable during Sleep mode */ +#define RCC_APB2SMENR_TIM16SMEN (1 << 17) /* Bit 17: TIM16 enable during Sleep mode */ +#define RCC_APB2SMENR_TIM17SMEN (1 << 18) /* Bit 18: TIM17 enable during Sleep mode */ +#define RCC_APB2SMENR_SAI1SMEN (1 << 21) /* Bit 21: SAI1 enable during Sleep mode */ +#define RCC_APB2SMENR_SAI2SMEN (1 << 22) /* Bit 22: SAI2 enable during Sleep mode */ +#define RCC_APB2SMENR_DFSDMSMEN (1 << 24) /* Bit 24: DFSDM enable during Sleep mode */ + +/* Peripheral Independent Clock Configuration register */ + +#define RCC_CCIPR_USART1SEL_SHIFT (0) +#define RCC_CCIPR_USART1SEL_MASK (3 << RCC_CCIPR_USART1SEL_SHIFT) +# define RCC_CCIPR_USART1SEL_PCLK (0 << RCC_CCIPR_USART1SEL_SHIFT) +# define RCC_CCIPR_USART1SEL_SYSCLK (1 << RCC_CCIPR_USART1SEL_SHIFT) +# define RCC_CCIPR_USART1SEL_HSI (2 << RCC_CCIPR_USART1SEL_SHIFT) +# define RCC_CCIPR_USART1SEL_LSE (3 << RCC_CCIPR_USART1SEL_SHIFT) + +#define RCC_CCIPR_USART2SEL_SHIFT (2) +#define RCC_CCIPR_USART2SEL_MASK (3 << RCC_CCIPR_USART2SEL_SHIFT) +# define RCC_CCIPR_USART2SEL_PCLK (0 << RCC_CCIPR_USART2SEL_SHIFT) +# define RCC_CCIPR_USART2SEL_SYSCLK (1 << RCC_CCIPR_USART2SEL_SHIFT) +# define RCC_CCIPR_USART2SEL_HSI (2 << RCC_CCIPR_USART2SEL_SHIFT) +# define RCC_CCIPR_USART2SEL_LSE (3 << RCC_CCIPR_USART2SEL_SHIFT) + +#define RCC_CCIPR_USART3SEL_SHIFT (4) +#define RCC_CCIPR_USART3SEL_MASK (3 << RCC_CCIPR_USART3SEL_SHIFT) +# define RCC_CCIPR_USART3SEL_PCLK (0 << RCC_CCIPR_USART3SEL_SHIFT) +# define RCC_CCIPR_USART3SEL_SYSCLK (1 << RCC_CCIPR_USART3SEL_SHIFT) +# define RCC_CCIPR_USART3SEL_HSI (2 << RCC_CCIPR_USART3SEL_SHIFT) +# define RCC_CCIPR_USART3SEL_LSE (3 << RCC_CCIPR_USART3SEL_SHIFT) + +#define RCC_CCIPR_UART4SEL_SHIFT (6) +#define RCC_CCIPR_UART4SEL_MASK (3 << RCC_CCIPR_UART4SEL_SHIFT) +# define RCC_CCIPR_UART4SEL_PCLK (0 << RCC_CCIPR_UART4SEL_SHIFT) +# define RCC_CCIPR_UART4SEL_SYSCLK (1 << RCC_CCIPR_UART4SEL_SHIFT) +# define RCC_CCIPR_UART4SEL_HSI (2 << RCC_CCIPR_UART4SEL_SHIFT) +# define RCC_CCIPR_UART4SEL_LSE (3 << RCC_CCIPR_UART4SEL_SHIFT) + +#define RCC_CCIPR_UART5SEL_SHIFT (8) +#define RCC_CCIPR_UART5SEL_MASK (3 << RCC_CCIPR_UART5SEL_SHIFT) +# define RCC_CCIPR_UART5SEL_PCLK (0 << RCC_CCIPR_UART5SEL_SHIFT) +# define RCC_CCIPR_UART5SEL_SYSCLK (1 << RCC_CCIPR_UART5SEL_SHIFT) +# define RCC_CCIPR_UART5SEL_HSI (2 << RCC_CCIPR_UART5SEL_SHIFT) +# define RCC_CCIPR_UART5SEL_LSE (3 << RCC_CCIPR_UART5SEL_SHIFT) + +#define RCC_CCIPR_LPUART1SEL_SHIFT (10) +#define RCC_CCIPR_LPUART1SEL_MASK (3 << RCC_CCIPR_LPUART1SEL_SHIFT) +# define RCC_CCIPR_LPUART1SEL_PCLK (0 << RCC_CCIPR_LPUART1SEL_SHIFT) +# define RCC_CCIPR_LPUART1SEL_SYSCLK (1 << RCC_CCIPR_LPUART1SEL_SHIFT) +# define RCC_CCIPR_LPUART1SEL_HSI (2 << RCC_CCIPR_LPUART1SEL_SHIFT) +# define RCC_CCIPR_LPUART1SEL_LSE (3 << RCC_CCIPR_LPUART1SEL_SHIFT) + +#define RCC_CCIPR_I2C1SEL_SHIFT (12) +#define RCC_CCIPR_I2C1SEL_MASK (3 << RCC_CCIPR_I2C1SEL_SHIFT) +# define RCC_CCIPR_I2C1SEL_PCLK (0 << RCC_CCIPR_I2C1SEL_SHIFT) +# define RCC_CCIPR_I2C1SEL_SYSCLK (1 << RCC_CCIPR_I2C1SEL_SHIFT) +# define RCC_CCIPR_I2C1SEL_HSI (2 << RCC_CCIPR_I2C1SEL_SHIFT) + +#define RCC_CCIPR_I2C2SEL_SHIFT (14) +#define RCC_CCIPR_I2C2SEL_MASK (3 << RCC_CCIPR_I2C2SEL_SHIFT) +# define RCC_CCIPR_I2C2SEL_PCLK (0 << RCC_CCIPR_I2C2SEL_SHIFT) +# define RCC_CCIPR_I2C2SEL_SYSCLK (1 << RCC_CCIPR_I2C2SEL_SHIFT) +# define RCC_CCIPR_I2C2SEL_HSI (2 << RCC_CCIPR_I2C2SEL_SHIFT) + +#define RCC_CCIPR_I2C3SEL_SHIFT (16) +#define RCC_CCIPR_I2C3SEL_MASK (3 << RCC_CCIPR_I2C3SEL_SHIFT) +# define RCC_CCIPR_I2C3SEL_PCLK (0 << RCC_CCIPR_I2C3SEL_SHIFT) +# define RCC_CCIPR_I2C3SEL_SYSCLK (1 << RCC_CCIPR_I2C3SEL_SHIFT) +# define RCC_CCIPR_I2C3SEL_HSI (2 << RCC_CCIPR_I2C3SEL_SHIFT) + +#define RCC_CCIPR_LPTIM1SEL_SHIFT (18) +#define RCC_CCIPR_LPTIM1SEL_MASK (3 << RCC_CCIPR_LPTIM1SEL_SHIFT) +# define RCC_CCIPR_LPTIM1SEL_PCLK (0 << RCC_CCIPR_LPTIM1SEL_SHIFT) +# define RCC_CCIPR_LPTIM1SEL_LSI (1 << RCC_CCIPR_LPTIM1SEL_SHIFT) +# define RCC_CCIPR_LPTIM1SEL_HSI (2 << RCC_CCIPR_LPTIM1SEL_SHIFT) +# define RCC_CCIPR_LPTIM1SEL_LSE (3 << RCC_CCIPR_LPTIM1SEL_SHIFT) + +#define RCC_CCIPR_LPTIM2SEL_SHIFT (20) +#define RCC_CCIPR_LPTIM2SEL_MASK (3 << RCC_CCIPR_LPTIM2SEL_SHIFT) +# define RCC_CCIPR_LPTIM2SEL_PCLK (0 << RCC_CCIPR_LPTIM2SEL_SHIFT) +# define RCC_CCIPR_LPTIM2SEL_LSI (1 << RCC_CCIPR_LPTIM2SEL_SHIFT) +# define RCC_CCIPR_LPTIM2SEL_HSI (2 << RCC_CCIPR_LPTIM2SEL_SHIFT) +# define RCC_CCIPR_LPTIM2SEL_LSE (3 << RCC_CCIPR_LPTIM2SEL_SHIFT) + +#define RCC_CCIPR_SAI1SEL_SHIFT (22) +#define RCC_CCIPR_SAI1SEL_MASK (3 << RCC_CCIPR_SAI1SEL_SHIFT) +# define RCC_CCIPR_SAI1SEL_PLLSAI1 (0 << RCC_CCIPR_SAI1SEL_SHIFT) +# define RCC_CCIPR_SAI1SEL_PLLSAI2 (1 << RCC_CCIPR_SAI1SEL_SHIFT) +# define RCC_CCIPR_SAI1SEL_PLLMAIN (2 << RCC_CCIPR_SAI1SEL_SHIFT) +# define RCC_CCIPR_SAI1SEL_EXTCLK (3 << RCC_CCIPR_SAI1SEL_SHIFT) + +#define RCC_CCIPR_SAI2SEL_SHIFT (24) +#define RCC_CCIPR_SAI2SEL_MASK (3 << RCC_CCIPR_SAI2SEL_SHIFT) +# define RCC_CCIPR_SAI2SEL_PLLSAI1 (0 << RCC_CCIPR_SAI2SEL_SHIFT) +# define RCC_CCIPR_SAI2SEL_PLLSAI2 (1 << RCC_CCIPR_SAI2SEL_SHIFT) +# define RCC_CCIPR_SAI2SEL_PLLMAIN (2 << RCC_CCIPR_SAI2SEL_SHIFT) +# define RCC_CCIPR_SAI2SEL_EXTCLK (3 << RCC_CCIPR_SAI2SEL_SHIFT) + +#define RCC_CCIPR_CLK48SEL_SHIFT (26) +#define RCC_CCIPR_CLK48SEL_MASK (3 << RCC_CCIPR_CLK48SEL_SHIFT) +# define RCC_CCIPR_CLK48SEL_NONE (0 << RCC_CCIPR_CLK48SEL_SHIFT) +# define RCC_CCIPR_CLK48SEL_PLLSAI1 (1 << RCC_CCIPR_CLK48SEL_SHIFT) +# define RCC_CCIPR_CLK48SEL_PLLMAIN (2 << RCC_CCIPR_CLK48SEL_SHIFT) +# define RCC_CCIPR_CLK48SEL_MSI (3 << RCC_CCIPR_CLK48SEL_SHIFT) + +#define RCC_CCIPR_ADCSEL_SHIFT (28) +#define RCC_CCIPR_ADCSEL_MASK (3 << RCC_CCIPR_ADCSEL_SHIFT) +# define RCC_CCIPR_ADCSEL_NONE (0 << RCC_CCIPR_ADCSEL_SHIFT) +# define RCC_CCIPR_ADCSEL_PLLSAI1 (1 << RCC_CCIPR_ADCSEL_SHIFT) +# define RCC_CCIPR_ADCSEL_PLLSAI2 (2 << RCC_CCIPR_ADCSEL_SHIFT) +# define RCC_CCIPR_ADCSEL_SYSCLK (3 << RCC_CCIPR_ADCSEL_SHIFT) + +#define RCC_CCIPR_SWPMI1SEL (1 << 30) +# define RCC_CCIPR_SWPMI1SEL_PCLK 0 +# define RCC_CCIPR_SWPMI1SEL_HSI RCC_CCIPR_SWPMI1SEL + +#define RCC_CCIPR_DFSDMSEL (1 << 31) +# define RCC_CCIPR_DFSDMSEL_PCLK 0 +# define RCC_CCIPR_DFSDMSEL_SYSCLK RCC_CCIPR_DFSDMSEL + +/* Backup domain control register */ + +#define RCC_BDCR_LSEON (1 << 0) /* Bit 0: External Low Speed oscillator enable */ +#define RCC_BDCR_LSERDY (1 << 1) /* Bit 1: External Low Speed oscillator Ready */ +#define RCC_BDCR_LSEBYP (1 << 2) /* Bit 2: External Low Speed oscillator Bypass */ + +#define RCC_BDCR_LSEDRV_SHIFT (3) /* Bits 3-4: LSE oscillator drive capability */ +#define RCC_BDCR_LSEDRV_MASK (3 << RCC_BDCR_LSEDRV_SHIFT) +# define RCC_BDCR_LSEDRV_LOWER (0 << RCC_BDCR_LSEDRV_SHIFT) /* 00: Lower driving capability */ +# define RCC_BDCR_LSEDRV_MIDLOW (1 << RCC_BDCR_LSEDRV_SHIFT) /* 01: Medium Low driving capability */ +# define RCC_BDCR_LSEDRV_MIDHI (2 << RCC_BDCR_LSEDRV_SHIFT) /* 10: Medium High driving capability*/ +# define RCC_BDCR_LSEDRV_HIGER (3 << RCC_BDCR_LSEDRV_SHIFT) /* 11: Higher driving capability */ + +#define RCC_BDCR_LSECSSON (1 << 5) /* Bit 5: CSS on LSE enable */ +#define RCC_BDCR_LSECSSD (1 << 6) /* Bit 6: CSS on LSE failure Detection */ + +#define RCC_BDCR_RTCSEL_SHIFT (8) /* Bits 9:8: RTC clock source selection */ +#define RCC_BDCR_RTCSEL_MASK (3 << RCC_BDCR_RTCSEL_SHIFT) +# define RCC_BDCR_RTCSEL_NOCLK (0 << RCC_BDCR_RTCSEL_SHIFT) /* 00: No clock */ +# define RCC_BDCR_RTCSEL_LSE (1 << RCC_BDCR_RTCSEL_SHIFT) /* 01: LSE oscillator clock used as RTC clock */ +# define RCC_BDCR_RTCSEL_LSI (2 << RCC_BDCR_RTCSEL_SHIFT) /* 10: LSI oscillator clock used as RTC clock */ +# define RCC_BDCR_RTCSEL_HSE (3 << RCC_BDCR_RTCSEL_SHIFT) /* 11: HSE oscillator clock divided by 32 used as RTC clock */ + +#define RCC_BDCR_RTCEN (1 << 15) /* Bit 15: RTC clock enable */ +#define RCC_BDCR_BDRST (1 << 16) /* Bit 16: Backup domain software reset */ +#define RCC_BDCR_LSCOEN (1 << 24) /* Bit 24: Low speed clock output enable */ +#define RCC_BDCR_LSCOSEL (1 << 25) /* Bit 25: Low speed clock output selection */ +# define RCC_BCDR_LSCOSEL_LSI 0 /* LSI selected */ +# define RCC_BDCR_LSCOSEL_LSE RCC_BDCR_LSCOSEL /* LSE selected */ + +/* Control/status register */ + +#define RCC_CSR_LSION (1 << 0) /* Bit 0: Internal Low Speed oscillator enable */ +#define RCC_CSR_LSIRDY (1 << 1) /* Bit 1: Internal Low Speed oscillator Ready */ + +#define RCC_CSR_MSISRANGE_SHIFT 8 +# define RCC_CSR_MSISRANGE_MASK (0x0F << RCC_CSR_MSISRANGE_SHIFT) /* MSI range after Standby mode */ +# define RCC_CSR_MSISRANGE_1M (4 << RCC_CSR_MSISRANGE_SHIFT) /* 0100: around 1 MHz */ +# define RCC_CSR_MSISRANGE_2M (5 << RCC_CSR_MSISRANGE_SHIFT) /* 0101: around 2 MHz */ +# define RCC_CSR_MSISRANGE_4M (6 << RCC_CSR_MSISRANGE_SHIFT) /* 0110: around 4 MHz */ +# define RCC_CSR_MSISRANGE_8M (7 << RCC_CSR_MSISRANGE_SHIFT) /* 0111: around 8 MHz */ + +#define RCC_CSR_RMVF (1 << 23) /* Bit 23: Remove reset flag */ +#define RCC_CSR_FWRSTF (1 << 24) /* Bit 24: Firewall reset flag */ +#define RCC_CSR_OBLRSTF (1 << 25) /* Bit 25: Option byte loader reset flag */ +#define RCC_CSR_PINRSTF (1 << 26) /* Bit 26: PIN reset flag */ +#define RCC_CSR_BORRSTF (1 << 27) /* Bit 27: BOR reset flag */ +#define RCC_CSR_SFTRSTF (1 << 28) /* Bit 28: Software Reset flag */ +#define RCC_CSR_IWDGRSTF (1 << 29) /* Bit 29: Independent Watchdog reset flag */ +#define RCC_CSR_WWDGRSTF (1 << 30) /* Bit 30: Window watchdog reset flag */ +#define RCC_CSR_LPWRRSTF (1 << 31) /* Bit 31: Low-Power reset flag */ + +/* Clock recovery RC register */ + +#define RCC_CRRCR_HSI48CAL_SHIFT 7 +# define RCC_CRRCR_HSI48CAL_MASK (0x01ff << RCC_CRRCR_HSI48CAL_SHIFT) /* HSI48 clock calibration */ + +#define RCC_CRRCR_HSI48ON (1 << 0) /* Bit 0: HSI48 clock enable */ +#define RCC_CRRCR_HSI48RDY (1 << 1) /* Bit 1: HSI48 clock ready flag */ + +#endif /* CONFIG_STM32L4_STM32L4X3 */ +#endif /* __ARCH_ARM_SRC_STM32L4_CHIP_STM32L4X3XX_RCC_H */ diff --git a/arch/arm/src/stm32l4/chip/stm32l4x6xx_rcc.h b/arch/arm/src/stm32l4/chip/stm32l4x6xx_rcc.h index d180033ad28..6d55cfea9ad 100644 --- a/arch/arm/src/stm32l4/chip/stm32l4x6xx_rcc.h +++ b/arch/arm/src/stm32l4/chip/stm32l4x6xx_rcc.h @@ -44,8 +44,7 @@ #include -#if defined(CONFIG_STM32L4_STM32L476XX) || defined(CONFIG_STM32L4_STM32L486XX) || \ - defined(CONFIG_STM32L4_STM32L496XX) +#if defined(CONFIG_STM32L4_STM32L4X6) /**************************************************************************************************** * Pre-processor Definitions @@ -807,5 +806,5 @@ # define RCC_CCIPR2_I2C4SEL_SYSCLK (1 << RCC_CCIPR2_I2C4SEL_SHIFT) # define RCC_CCIPR2_I2C4SEL_HSI (2 << RCC_CCIPR2_I2C4SEL_SHIFT) -#endif /* CONFIG_STM32L4_STM32L476XX || CONFIG_STM32L4_STM32L486XX || CONFIG_STM32L4_STM32L496XX */ +#endif /* CONFIG_STM32L4_STM32L4X6 */ #endif /* __ARCH_ARM_SRC_STM32L4_CHIP_STM32L4X6XX_RCC_H */ diff --git a/arch/arm/src/stm32l4/stm32l4_dma.c b/arch/arm/src/stm32l4/stm32l4_dma.c index d2fd26546eb..fbde7e04e6a 100644 --- a/arch/arm/src/stm32l4/stm32l4_dma.c +++ b/arch/arm/src/stm32l4/stm32l4_dma.c @@ -41,34 +41,15 @@ #include "chip.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - /* This file is only a thin shell that includes the correct DMA implementation * for the selected STM32 family. The correct file cannot be selected by * the make system because it needs the intelligence that only exists in * chip.h that can associate an STM32 part number with an STM32 family. + * + * TODO: do we need separate implementation for STM32L4X3? */ -#if defined(CONFIG_STM32L4_STM32L476XX) || defined(CONFIG_STM32L4_STM32L486XX) || \ - defined(CONFIG_STM32L4_STM32L496XX) +#if defined(CONFIG_STM32L4_STM32L4X6) || defined(CONFIG_STM32L4_STM32L4X3) #include "stm32l4x6xx_dma.c" #else # error "Unsupported STM32L4 chip" diff --git a/arch/arm/src/stm32l4/stm32l4_dma.h b/arch/arm/src/stm32l4/stm32l4_dma.h index 89196cb3811..c12013782d6 100644 --- a/arch/arm/src/stm32l4/stm32l4_dma.h +++ b/arch/arm/src/stm32l4/stm32l4_dma.h @@ -49,9 +49,10 @@ /* Include the correct DMA register definitions for this STM32 family */ -#if defined(CONFIG_STM32L4_STM32L476XX) || defined(CONFIG_STM32L4_STM32L486XX) || \ - defined(CONFIG_STM32L4_STM32L496XX) +#if defined(CONFIG_STM32L4_STM32L4X6) # include "chip/stm32l4x6xx_dma.h" +#elif defined(CONFIG_STM32L4_STM32L4X3) +# include "chip/stm32l4x3xx_dma.h" #else # error "Unsupported STM32L4 chip" #endif diff --git a/arch/arm/src/stm32l4/stm32l4_gpio.h b/arch/arm/src/stm32l4/stm32l4_gpio.h index 57076a83ed5..e0fac1e2734 100644 --- a/arch/arm/src/stm32l4/stm32l4_gpio.h +++ b/arch/arm/src/stm32l4/stm32l4_gpio.h @@ -54,9 +54,8 @@ #include "chip.h" -#if defined(CONFIG_STM32L4_STM32L476XX) || defined(CONFIG_STM32L4_STM32L486XX) || \ - defined(CONFIG_STM32L4_STM32L496XX) -# include "chip/stm32l4x6xx_gpio.h" +#if defined(CONFIG_STM32L4_STM32L4X6) || defined(CONFIG_STM32L4_STM32L4X3) +# include "chip/stm32l4_gpio.h" #else # error "Unsupported STM32L4 chip" #endif diff --git a/arch/arm/src/stm32l4/stm32l4_rcc.c b/arch/arm/src/stm32l4/stm32l4_rcc.c index 6d7a240d89b..ffe1c4d2dc7 100644 --- a/arch/arm/src/stm32l4/stm32l4_rcc.c +++ b/arch/arm/src/stm32l4/stm32l4_rcc.c @@ -78,9 +78,10 @@ /* Include chip-specific clocking initialization logic */ -#if defined(CONFIG_STM32L4_STM32L476XX) || defined(CONFIG_STM32L4_STM32L486XX) || \ - defined(CONFIG_STM32L4_STM32L496XX) +#if defined(CONFIG_STM32L4_STM32L4X6) # include "stm32l4x6xx_rcc.c" +#elif defined(CONFIG_STM32L4_STM32L4X3) +# include "stm32l4x3xx_rcc.c" #else # error "Unsupported STM32L4 chip" #endif diff --git a/arch/arm/src/stm32l4/stm32l4_rcc.h b/arch/arm/src/stm32l4/stm32l4_rcc.h index 6c77771ec67..8e3f84adc8e 100644 --- a/arch/arm/src/stm32l4/stm32l4_rcc.h +++ b/arch/arm/src/stm32l4/stm32l4_rcc.h @@ -45,9 +45,10 @@ #include "up_arch.h" #include "chip.h" -#if defined(CONFIG_STM32L4_STM32L476XX) || defined(CONFIG_STM32L4_STM32L486XX) || \ - defined(CONFIG_STM32L4_STM32L496XX) +#if defined(CONFIG_STM32L4_STM32L4X6) # include "chip/stm32l4x6xx_rcc.h" +#elif defined(CONFIG_STM32L4_STM32L4X3) +# include "chip/stm32l4x3xx_rcc.h" #else # error "Unsupported STM32L4 chip" #endif diff --git a/arch/arm/src/stm32l4/stm32l4_serial.c b/arch/arm/src/stm32l4/stm32l4_serial.c index 187a8f8f9bb..955fb548e1f 100644 --- a/arch/arm/src/stm32l4/stm32l4_serial.c +++ b/arch/arm/src/stm32l4/stm32l4_serial.c @@ -61,6 +61,7 @@ #include #include "chip.h" +#include "stm32l4_gpio.h" #include "stm32l4_uart.h" #include "stm32l4_dma.h" #include "stm32l4_rcc.h" diff --git a/arch/arm/src/stm32l4/stm32l4_uart.h b/arch/arm/src/stm32l4/stm32l4_uart.h index d6922269fb9..286ba8eeb85 100644 --- a/arch/arm/src/stm32l4/stm32l4_uart.h +++ b/arch/arm/src/stm32l4/stm32l4_uart.h @@ -44,9 +44,8 @@ #include "chip.h" -#if defined(CONFIG_STM32L4_STM32L476XX) || defined(CONFIG_STM32L4_STM32L486XX) || \ - defined(CONFIG_STM32L4_STM32L496XX) -# include "chip/stm32l4x6xx_uart.h" +#if defined(CONFIG_STM32L4_STM32L4X6) || defined(CONFIG_STM32L4_STM32L4X3) +# include "chip/stm32l4_uart.h" #else # error "Unsupported STM32L4 chip" #endif diff --git a/arch/arm/src/stm32l4/stm32l4x3xx_rcc.c b/arch/arm/src/stm32l4/stm32l4x3xx_rcc.c new file mode 100644 index 00000000000..855481df090 --- /dev/null +++ b/arch/arm/src/stm32l4/stm32l4x3xx_rcc.c @@ -0,0 +1,864 @@ +/**************************************************************************** + * arch/arm/src/stm32l4/stm32l4x3xx_rcc.c + * + * Copyright (C) 2011-2012, 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2016 Sebastien Lorquet. All rights reserved. + * Authors: Gregory Nutt + * Sebastien Lorquet + * Juha Niskanen + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +#include "stm32l4_pwr.h" +#include "stm32l4_flash.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Allow up to 100 milliseconds for the high speed clock to become ready. + * that is a very long delay, but if the clock does not become ready we are + * hosed anyway. Normally this is very fast, but I have seen at least one + * board that required this long, long timeout for the HSE to be ready. + */ + +#define HSERDY_TIMEOUT (100 * CONFIG_BOARD_LOOPSPERMSEC) + +/* Same for HSI and MSI */ + +#define HSIRDY_TIMEOUT HSERDY_TIMEOUT +#define MSIRDY_TIMEOUT HSERDY_TIMEOUT + +/* HSE divisor to yield ~1MHz RTC clock */ + +#define HSE_DIVISOR (STM32L4_HSE_FREQUENCY + 500000) / 1000000 + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: rcc_reset + * + * Description: + * Reset the RCC clock configuration to the default reset state + * + ****************************************************************************/ + +static inline void rcc_reset(void) +{ + uint32_t regval; + + /* Enable the Internal High Speed clock (HSI) */ + + regval = getreg32(STM32L4_RCC_CR); + regval |= RCC_CR_HSION; + putreg32(regval, STM32L4_RCC_CR); + + /* Reset CFGR register */ + + putreg32(0x00000000, STM32L4_RCC_CFGR); + + /* Reset HSION, HSEON, CSSON and PLLON bits */ + + regval = getreg32(STM32L4_RCC_CR); + regval &= ~(RCC_CR_HSION | RCC_CR_HSEON | RCC_CR_CSSON | RCC_CR_PLLON); + putreg32(regval, STM32L4_RCC_CR); + + /* Reset PLLCFGR register to reset default */ + + putreg32(RCC_PLLCFG_RESET, STM32L4_RCC_PLLCFG); + + /* Reset HSEBYP bit */ + + regval = getreg32(STM32L4_RCC_CR); + regval &= ~RCC_CR_HSEBYP; + putreg32(regval, STM32L4_RCC_CR); + + /* Disable all interrupts */ + + putreg32(0x00000000, STM32L4_RCC_CIER); +} + +/**************************************************************************** + * Name: rcc_enableahb1 + * + * Description: + * Enable selected AHB1 peripherals + * + ****************************************************************************/ + +static inline void rcc_enableahb1(void) +{ + uint32_t regval; + + /* Set the appropriate bits in the AHB1ENR register to enabled the + * selected AHB1 peripherals. + */ + + regval = getreg32(STM32L4_RCC_AHB1ENR); + +#ifdef CONFIG_STM32L4_DMA1 + /* DMA 1 clock enable */ + + regval |= RCC_AHB1ENR_DMA1EN; +#endif + +#ifdef CONFIG_STM32L4_DMA2 + /* DMA 2 clock enable */ + + regval |= RCC_AHB1ENR_DMA2EN; +#endif + +#ifdef CONFIG_STM32L4_CRC + /* CRC clock enable */ + + regval |= RCC_AHB1ENR_CRCEN; +#endif + +#ifdef CONFIG_STM32L4_TSC + /* TSC clock enable */ + + regval |= RCC_AHB1ENR_TSCEN; +#endif + + putreg32(regval, STM32L4_RCC_AHB1ENR); /* Enable peripherals */ +} + +/**************************************************************************** + * Name: rcc_enableahb2 + * + * Description: + * Enable selected AHB2 peripherals + * + ****************************************************************************/ + +static inline void rcc_enableahb2(void) +{ + uint32_t regval; + + /* Set the appropriate bits in the AHB2ENR register to enable the + * selected AHB2 peripherals. + */ + + regval = getreg32(STM32L4_RCC_AHB2ENR); + + /* Enable GPIOA, GPIOB, .... GPIOH */ + +#if STM32L4_NPORTS > 0 + regval |= (RCC_AHB2ENR_GPIOAEN +#if STM32L4_NPORTS > 1 + | RCC_AHB2ENR_GPIOBEN +#endif +#if STM32L4_NPORTS > 2 + | RCC_AHB2ENR_GPIOCEN +#endif +#if STM32L4_NPORTS > 3 + | RCC_AHB2ENR_GPIODEN +#endif +#if STM32L4_NPORTS > 4 + | RCC_AHB2ENR_GPIOEEN +#endif +/* These chips have no GPIOF, GPIOG or GPIOI */ +#if STM32L4_NPORTS > 7 + | RCC_AHB2ENR_GPIOHEN +#endif + ); +#endif + +#if defined(CONFIG_STM32L4_ADC1) || defined(CONFIG_STM32L4_ADC2) || defined(CONFIG_STM32L4_ADC3) + /* ADC clock enable */ + + regval |= RCC_AHB2ENR_ADCEN; +#endif + +#ifdef CONFIG_STM32L4_AES + /* Cryptographic modules clock enable */ + + regval |= RCC_AHB2ENR_AESEN; +#endif + +#ifdef CONFIG_STM32L4_RNG + /* Random number generator clock enable */ + + regval |= RCC_AHB2ENR_RNGEN; +#endif + + putreg32(regval, STM32L4_RCC_AHB2ENR); /* Enable peripherals */ +} + +/**************************************************************************** + * Name: rcc_enableahb3 + * + * Description: + * Enable selected AHB3 peripherals + * + ****************************************************************************/ + +static inline void rcc_enableahb3(void) +{ + uint32_t regval; + + /* Set the appropriate bits in the AHB3ENR register to enabled the + * selected AHB3 peripherals. + */ + + regval = getreg32(STM32L4_RCC_AHB3ENR); + +#ifdef CONFIG_STM32L4_QSPI + /* QuadSPI module clock enable */ + + regval |= RCC_AHB3ENR_QSPIEN; +#endif + + putreg32(regval, STM32L4_RCC_AHB3ENR); /* Enable peripherals */ +} + +/**************************************************************************** + * Name: rcc_enableapb1 + * + * Description: + * Enable selected APB1 peripherals + * + ****************************************************************************/ + +static inline void rcc_enableapb1(void) +{ + uint32_t regval; + + /* Set the appropriate bits in the APB1ENR register to enabled the + * selected APB1 peripherals. + */ + + regval = getreg32(STM32L4_RCC_APB1ENR1); + +#ifdef CONFIG_STM32L4_TIM2 + /* TIM2 clock enable */ + + regval |= RCC_APB1ENR1_TIM2EN; +#endif + +#ifdef CONFIG_STM32L4_TIM3 + /* TIM3 clock enable */ + + regval |= RCC_APB1ENR1_TIM3EN; +#endif + +#ifdef CONFIG_STM32L4_TIM6 + /* TIM6 clock enable */ + + regval |= RCC_APB1ENR1_TIM6EN; +#endif + +#ifdef CONFIG_STM32L4_TIM7 + /* TIM7 clock enable */ + + regval |= RCC_APB1ENR1_TIM7EN; +#endif + +#ifdef CONFIG_STM32L4_LCD + /* LCD clock enable */ + + regval |= RCC_APB1ENR1_LCDEN; +#endif + +#ifdef CONFIG_STM32L4_SPI2 + /* SPI2 clock enable */ + + regval |= RCC_APB1ENR1_SPI2EN; +#endif + +#ifdef CONFIG_STM32L4_SPI3 + /* SPI3 clock enable */ + + regval |= RCC_APB1ENR1_SPI3EN; +#endif + +#ifdef CONFIG_STM32L4_USART2 + /* USART 2 clock enable */ + + regval |= RCC_APB1ENR1_USART2EN; +#endif + +#ifdef CONFIG_STM32L4_USART3 + /* USART3 clock enable */ + + regval |= RCC_APB1ENR1_USART3EN; +#endif + +#ifdef CONFIG_STM32L4_UART4 + /* UART4 clock enable */ + + regval |= RCC_APB1ENR1_UART4EN; +#endif + +#ifdef CONFIG_STM32L4_I2C1 + /* I2C1 clock enable */ + + regval |= RCC_APB1ENR1_I2C1EN; +#endif + +#ifdef CONFIG_STM32L4_I2C2 + /* I2C2 clock enable */ + + regval |= RCC_APB1ENR1_I2C2EN; +#endif + +#ifdef CONFIG_STM32L4_I2C3 + /* I2C3 clock enable */ + + regval |= RCC_APB1ENR1_I2C3EN; +#endif + +#ifdef CONFIG_STM32L4_CAN1 + /* CAN 1 clock enable */ + + regval |= RCC_APB1ENR1_CAN1EN; +#endif + +#ifdef CONFIG_STM32L4_USBFS + /* USB FS clock enable */ + + regval |= RCC_APB1ENR1_USBFSEN; +#endif + + /* Power interface clock enable. The PWR block is always enabled so that + * we can set the internal voltage regulator as required. + */ + + regval |= RCC_APB1ENR1_PWREN; + +#if defined (CONFIG_STM32L4_DAC1) || defined(CONFIG_STM32L4_DAC2) + /* DAC interface clock enable */ + + regval |= RCC_APB1ENR1_DACEN; +#endif + +#ifdef CONFIG_STM32L4_OPAMP + /* OPAMP clock enable */ + + regval |= RCC_APB1ENR1_OPAMPEN; +#endif + +#ifdef CONFIG_STM32L4_LPTIM1 + /* Low power timer 1 clock enable */ + + regval |= RCC_APB1ENR1_LPTIM1EN; +#endif + + putreg32(regval, STM32L4_RCC_APB1ENR1); /* Enable peripherals */ + + /* Second APB1 register */ + + regval = getreg32(STM32L4_RCC_APB1ENR2); + +#ifdef CONFIG_STM32L4_LPUART1 + /* Low power uart clock enable */ + + regval |= RCC_APB1ENR2_LPUART1EN; +#endif + +#ifdef CONFIG_STM32L4_I2C4 + /* I2C4 clock enable */ + + regval |= RCC_APB1ENR2_I2C4EN; +#endif + +#ifdef CONFIG_STM32L4_SWPMI + /* Single-wire protocol master clock enable */ + + regval |= RCC_APB1ENR2_SWPMI1EN; +#endif + +#ifdef CONFIG_STM32L4_LPTIM2 + /* Low power timer 2 clock enable */ + + regval |= RCC_APB1ENR2_LPTIM2EN; +#endif + + putreg32(regval, STM32L4_RCC_APB1ENR2); /* Enable peripherals */ +} + +/**************************************************************************** + * Name: rcc_enableapb2 + * + * Description: + * Enable selected APB2 peripherals + * + ****************************************************************************/ + +static inline void rcc_enableapb2(void) +{ + uint32_t regval; + + /* Set the appropriate bits in the APB2ENR register to enabled the + * selected APB2 peripherals. + */ + + regval = getreg32(STM32L4_RCC_APB2ENR); + +#ifdef CONFIG_STM32L4_SYSCFG + /* System configuration controller clock enable */ + + regval |= RCC_APB2ENR_SYSCFGEN; +#endif + +#ifdef CONFIG_STM32L4_FIREWALL + /* Firewall clock enable */ + + regval |= RCC_APB2ENR_FWEN; +#endif + +#ifdef CONFIG_STM32L4_SDMMC + /* SDMMC clock enable */ + + regval |= RCC_APB2ENR_SDMMCEN; +#endif + +#ifdef CONFIG_STM32L4_TIM1 + /* TIM1 clock enable */ + + regval |= RCC_APB2ENR_TIM1EN; +#endif + +#ifdef CONFIG_STM32L4_SPI1 + /* SPI1 clock enable */ + + regval |= RCC_APB2ENR_SPI1EN; +#endif + +#ifdef CONFIG_STM32L4_USART1 + /* USART1 clock enable */ + + regval |= RCC_APB2ENR_USART1EN; +#endif + +#ifdef CONFIG_STM32L4_TIM15 + /* TIM15 clock enable */ + + regval |= RCC_APB2ENR_TIM15EN; +#endif + +#ifdef CONFIG_STM32L4_TIM16 + /* TIM16 clock enable */ + + regval |= RCC_APB2ENR_TIM16EN; +#endif + +#ifdef CONFIG_STM32L4_SAI1 + /* SAI1 clock enable */ + + regval |= RCC_APB2ENR_SAI1EN; +#endif + +#ifdef CONFIG_STM32L4_DFSDM1 + /* DFSDM clock enable */ + + regval |= RCC_APB2ENR_DFSDMEN; +#endif + + putreg32(regval, STM32L4_RCC_APB2ENR); /* Enable peripherals */ +} + +/**************************************************************************** + * Name: stm32l4_stdclockconfig + * + * Description: + * Called to change to new clock based on settings in board.h + * + * NOTE: This logic would need to be extended if you need to select low- + * power clocking modes! + ****************************************************************************/ + +#ifndef CONFIG_ARCH_BOARD_STM32L4_CUSTOM_CLOCKCONFIG +static void stm32l4_stdclockconfig(void) +{ + uint32_t regval; + volatile int32_t timeout; + +#ifdef STM32L4_BOARD_USEHSI + /* Enable Internal High-Speed Clock (HSI) */ + + regval = getreg32(STM32L4_RCC_CR); + regval |= RCC_CR_HSION; /* Enable HSI */ + putreg32(regval, STM32L4_RCC_CR); + + /* Wait until the HSI is ready (or until a timeout elapsed) */ + + for (timeout = HSIRDY_TIMEOUT; timeout > 0; timeout--) + { + /* Check if the HSIRDY flag is the set in the CR */ + + if ((getreg32(STM32L4_RCC_CR) & RCC_CR_HSIRDY) != 0) + { + /* If so, then break-out with timeout > 0 */ + + break; + } + } + +#elif defined(STM32L4_BOARD_USEMSI) + /* Enable Internal Multi-Speed Clock (MSI) */ + + /* Wait until the MSI is either off or ready (or until a timeout elapsed) */ + + for (timeout = MSIRDY_TIMEOUT; timeout > 0; timeout--) + { + if ((regval = getreg32(STM32L4_RCC_CR)), (regval & RCC_CR_MSIRDY) || ~(regval & RCC_CR_MSION)) + { + /* If so, then break-out with timeout > 0 */ + + break; + } + } + + /* setting MSIRANGE */ + + regval = getreg32(STM32L4_RCC_CR); + regval |= (STM32L4_BOARD_MSIRANGE | RCC_CR_MSION); /* Enable MSI and frequency */ + putreg32(regval, STM32L4_RCC_CR); + + /* Wait until the MSI is ready (or until a timeout elapsed) */ + + for (timeout = MSIRDY_TIMEOUT; timeout > 0; timeout--) + { + /* Check if the MSIRDY flag is the set in the CR */ + + if ((getreg32(STM32L4_RCC_CR) & RCC_CR_MSIRDY) != 0) + { + /* If so, then break-out with timeout > 0 */ + + break; + } + } + +#elif defined(STM32L4_BOARD_USEHSE) + /* Enable External High-Speed Clock (HSE) */ + + regval = getreg32(STM32L4_RCC_CR); + regval |= RCC_CR_HSEON; /* Enable HSE */ + putreg32(regval, STM32L4_RCC_CR); + + /* Wait until the HSE is ready (or until a timeout elapsed) */ + + for (timeout = HSERDY_TIMEOUT; timeout > 0; timeout--) + { + /* Check if the HSERDY flag is the set in the CR */ + + if ((getreg32(STM32L4_RCC_CR) & RCC_CR_HSERDY) != 0) + { + /* If so, then break-out with timeout > 0 */ + + break; + } + } +#else + +# error stm32l4_stdclockconfig(), must have one of STM32L4_BOARD_USEHSI, STM32L4_BOARD_USEMSI, STM32L4_BOARD_USEHSE defined + +#endif + + /* Check for a timeout. If this timeout occurs, then we are hosed. We + * have no real back-up plan, although the following logic makes it look + * as though we do. + */ + + if (timeout > 0) + { +#warning todo: regulator voltage according to clock freq +#if 0 + /* Ensure Power control is enabled before modifying it. */ + + regval = getreg32(STM32L4_RCC_APB1ENR); + regval |= RCC_APB1ENR_PWREN; + putreg32(regval, STM32L4_RCC_APB1ENR); + + /* Select regulator voltage output Scale 1 mode to support system + * frequencies up to 168 MHz. + */ + + regval = getreg32(STM32L4_PWR_CR); + regval &= ~PWR_CR_VOS_MASK; + regval |= PWR_CR_VOS_SCALE_1; + putreg32(regval, STM32L4_PWR_CR); +#endif + + /* Set the HCLK source/divider */ + + regval = getreg32(STM32L4_RCC_CFGR); + regval &= ~RCC_CFGR_HPRE_MASK; + regval |= STM32L4_RCC_CFGR_HPRE; + putreg32(regval, STM32L4_RCC_CFGR); + + /* Set the PCLK2 divider */ + + regval = getreg32(STM32L4_RCC_CFGR); + regval &= ~RCC_CFGR_PPRE2_MASK; + regval |= STM32L4_RCC_CFGR_PPRE2; + putreg32(regval, STM32L4_RCC_CFGR); + + /* Set the PCLK1 divider */ + + regval = getreg32(STM32L4_RCC_CFGR); + regval &= ~RCC_CFGR_PPRE1_MASK; + regval |= STM32L4_RCC_CFGR_PPRE1; + putreg32(regval, STM32L4_RCC_CFGR); + +#ifdef CONFIG_RTC_HSECLOCK + /* Set the RTC clock divisor */ + + regval = getreg32(STM32L4_RCC_CFGR); + regval &= ~RCC_CFGR_RTCPRE_MASK; + regval |= RCC_CFGR_RTCPRE(HSE_DIVISOR); + putreg32(regval, STM32L4_RCC_CFGR); +#endif + + /* Set the PLL source and main divider */ + + regval = getreg32(STM32L4_RCC_PLLCFG); + + /* Configure Main PLL */ + + /* Set the PLL dividers and multipliers to configure the main PLL */ + + regval = (STM32L4_PLLCFG_PLLM | STM32L4_PLLCFG_PLLN | STM32L4_PLLCFG_PLLP + | STM32L4_PLLCFG_PLLQ | STM32L4_PLLCFG_PLLR); + +#ifdef STM32L4_PLLCFG_PLLP_ENABLED + regval |= RCC_PLLCFG_PLLPEN; +#endif +#ifdef STM32L4_PLLCFG_PLLQ_ENABLED + regval |= RCC_PLLCFG_PLLQEN; +#endif +#ifdef STM32L4_PLLCFG_PLLR_ENABLED + regval |= RCC_PLLCFG_PLLREN; +#endif + + /* XXX The choice of clock source to PLL (all three) is independent + * of the sys clock source choice, review the STM32L4_BOARD_USEHSI + * name; probably split it into two, one for PLL source and one + * for sys clock source. + */ + +#ifdef STM32L4_BOARD_USEHSI + regval |= RCC_PLLCFG_PLLSRC_HSI; +#elif defined(STM32L4_BOARD_USEMSI) + regval |= RCC_PLLCFG_PLLSRC_MSI; +#else /* if STM32L4_BOARD_USEHSE */ + regval |= RCC_PLLCFG_PLLSRC_HSE; +#endif + + putreg32(regval, STM32L4_RCC_PLLCFG); + + /* Enable the main PLL */ + + regval = getreg32(STM32L4_RCC_CR); + regval |= RCC_CR_PLLON; + putreg32(regval, STM32L4_RCC_CR); + + /* Wait until the PLL is ready */ + + while ((getreg32(STM32L4_RCC_CR) & RCC_CR_PLLRDY) == 0) + { + } + +#ifdef CONFIG_STM32L4_SAI1PLL + /* Configure SAI1 PLL */ + + regval = getreg32(STM32L4_RCC_PLLSAI1CFG); + + /* Set the PLL dividers and multipliers to configure the SAI1 PLL */ + + regval = (STM32L4_PLLSAI1CFG_PLLN | STM32L4_PLLSAI1CFG_PLLP + | STM32L4_PLLSAI1CFG_PLLQ | STM32L4_PLLSAI1CFG_PLLR); + +#ifdef STM32L4_PLLSAI1CFG_PLLP_ENABLED + regval |= RCC_PLLSAI1CFG_PLLPEN; +#endif +#ifdef STM32L4_PLLSAI1CFG_PLLQ_ENABLED + regval |= RCC_PLLSAI1CFG_PLLQEN; +#endif +#ifdef STM32L4_PLLSAI1CFG_PLLR_ENABLED + regval |= RCC_PLLSAI1CFG_PLLREN; +#endif + + putreg32(regval, STM32L4_RCC_PLLSAI1CFG); + + /* Enable the SAI1 PLL */ + + regval = getreg32(STM32L4_RCC_CR); + regval |= RCC_CR_PLLSAI1ON; + putreg32(regval, STM32L4_RCC_CR); + + /* Wait until the PLL is ready */ + + while ((getreg32(STM32L4_RCC_CR) & RCC_CR_PLLSAI1RDY) == 0) + { + } +#endif + +#ifdef CONFIG_STM32L4_SAI2PLL + /* Configure SAI2 PLL */ + + regval = getreg32(STM32L4_RCC_PLLSAI2CFG); + + /* Set the PLL dividers and multipliers to configure the SAI2 PLL */ + + regval = (STM32L4_PLLSAI2CFG_PLLN | STM32L4_PLLSAI2CFG_PLLP | + STM32L4_PLLSAI2CFG_PLLR); + +#ifdef STM32L4_PLLSAI2CFG_PLLP_ENABLED + regval |= RCC_PLLSAI2CFG_PLLPEN; +#endif +#ifdef STM32L4_PLLSAI2CFG_PLLR_ENABLED + regval |= RCC_PLLSAI2CFG_PLLREN; +#endif + + putreg32(regval, STM32L4_RCC_PLLSAI2CFG); + + /* Enable the SAI2 PLL */ + + regval = getreg32(STM32L4_RCC_CR); + regval |= RCC_CR_PLLSAI2ON; + putreg32(regval, STM32L4_RCC_CR); + + /* Wait until the PLL is ready */ + + while ((getreg32(STM32L4_RCC_CR) & RCC_CR_PLLSAI2RDY) == 0) + { + } +#endif + + /* Enable FLASH prefetch, instruction cache, data cache, and 4 wait states */ + +#ifdef CONFIG_STM32L4_FLASH_PREFETCH + regval = (FLASH_ACR_LATENCY_4 | FLASH_ACR_ICEN | FLASH_ACR_DCEN | FLASH_ACR_PRFTEN); +#else + regval = (FLASH_ACR_LATENCY_4 | FLASH_ACR_ICEN | FLASH_ACR_DCEN); +#endif + putreg32(regval, STM32L4_FLASH_ACR); + + /* Select the main PLL as system clock source */ + + regval = getreg32(STM32L4_RCC_CFGR); + regval &= ~RCC_CFGR_SW_MASK; + regval |= RCC_CFGR_SW_PLL; + putreg32(regval, STM32L4_RCC_CFGR); + + /* Wait until the PLL source is used as the system clock source */ + + while ((getreg32(STM32L4_RCC_CFGR) & RCC_CFGR_SWS_MASK) != RCC_CFGR_SWS_PLL) + { + } + +#if defined(CONFIG_STM32L4_IWDG) || defined(CONFIG_RTC_LSICLOCK) + /* Low speed internal clock source LSI */ + + stm32l4_rcc_enablelsi(); +#endif + +#if defined(STM32L4_USE_LSE) + /* Low speed external clock source LSE + * + * TODO: There is another case where the LSE needs to + * be enabled: if the MCO1 pin selects LSE as source. + * XXX and other cases, like automatic trimming of MSI for USB use + */ + + /* ensure Power control is enabled since it is indirectly required + * to alter the LSE parameters. + */ + stm32l4_pwr_enableclk(true); + + /* XXX other LSE settings must be made before turning on the oscillator + * and we need to ensure it is first off before doing so. + */ + + /* Turn on the LSE oscillator + * XXX this will almost surely get moved since we also want to use + * this for automatically trimming MSI, etc. + */ + + stm32l4_rcc_enablelse(); + +# if defined(STM32L4_BOARD_USEMSI) + /* Now that LSE is up, auto trim the MSI */ + + regval = getreg32(STM32L4_RCC_CR); + regval |= RCC_CR_MSIPLLEN; + putreg32(regval, STM32L4_RCC_CR); +# endif +#endif + +#if defined(STM32L4_USE_CLK48) + /* XXX sanity if sdmmc1 or usb or rng, then we need to set the clk48 source + * and then we can also do away with STM32L4_USE_CLK48, and give better + * warning messages + * + * XXX sanity if our STM32L4_CLK48_SEL is YYY then we need to have already + * enabled ZZZ + */ + + regval = getreg32(STM32L4_RCC_CCIPR); + regval &= RCC_CCIPR_CLK48SEL_MASK; + regval |= STM32L4_CLK48_SEL; + putreg32(regval, STM32L4_RCC_CCIPR); +#endif + } +} +#endif + +/**************************************************************************** + * Name: rcc_enableperipherals + ****************************************************************************/ + +static inline void rcc_enableperipherals(void) +{ + rcc_enableahb1(); + rcc_enableahb2(); + rcc_enableahb3(); + rcc_enableapb1(); + rcc_enableapb2(); +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ From 80c2d384bb511baf595785479ac17d66ac9b6b00 Mon Sep 17 00:00:00 2001 From: Juha Niskanen Date: Tue, 2 May 2017 15:21:06 +0300 Subject: [PATCH 127/183] STM32L4: flash: update override config macros and add FLASH_CONFIG_B --- arch/arm/src/stm32l4/stm32l4_flash.h | 78 +++++++++++++++++++--------- 1 file changed, 54 insertions(+), 24 deletions(-) diff --git a/arch/arm/src/stm32l4/stm32l4_flash.h b/arch/arm/src/stm32l4/stm32l4_flash.h index 96bd6135d90..c29a8d35a55 100644 --- a/arch/arm/src/stm32l4/stm32l4_flash.h +++ b/arch/arm/src/stm32l4/stm32l4_flash.h @@ -41,42 +41,72 @@ * Pre-processor Definitions ************************************************************************************/ +/* Flash size is known from the chip selection: + * + * When CONFIG_STM32L4_FLASH_OVERRIDE_DEFAULT is set the + * CONFIG_STM32L4_FLASH_CONFIG_x selects the default FLASH size based on the chip + * part number. This value can be overridden with CONFIG_STM32L4_FLASH_OVERRIDE_x + * + * Parts STM32L4xxE have 512Kb of FLASH + * Parts STM32L4xxG have 1024Kb of FLASH + * + * N.B. Only Single bank mode is supported + */ + #define _K(x) ((x)*1024) -#if !defined(CONFIG_STM32L4_FLASH_CONFIG_DEFAULT) && \ +#if !defined(CONFIG_STM32L4_FLASH_OVERRIDE_DEFAULT) && \ + !defined(CONFIG_STM32L4_FLASH_OVERRIDE_B) && \ + !defined(CONFIG_STM32L4_FLASH_OVERRIDE_C) && \ + !defined(CONFIG_STM32L4_FLASH_OVERRIDE_E) && \ + !defined(CONFIG_STM32L4_FLASH_OVERRIDE_G) && \ + !defined(CONFIG_STM32L4_FLASH_CONFIG_B) && \ !defined(CONFIG_STM32L4_FLASH_CONFIG_C) && \ !defined(CONFIG_STM32L4_FLASH_CONFIG_E) && \ !defined(CONFIG_STM32L4_FLASH_CONFIG_G) -# define CONFIG_STM32L4_FLASH_CONFIG_DEFAULT +# define CONFIG_STM32L4_FLASH_OVERRIDE_E +# warning "Flash size not defined defaulting to 512KiB (E)" #endif -#if defined(CONFIG_STM32L4_FLASH_CONFIG_DEFAULT) -# define STM32L4_FLASH_NPAGES 512 -# define STM32L4_FLASH_PAGESIZE 2048 -#endif /* CONFIG_STM32L4_FLASH_CONFIG_DEFAULT */ +/* Override of the Flash has been chosen */ -/* Override of the Flash Has been Chosen */ - -#if !defined(CONFIG_STM32L4_FLASH_CONFIG_DEFAULT) - -/* Define the Valid Configuration the F1 and F3 */ - -# if defined(CONFIG_STM32L4_FLASH_CONFIG_C) /* 256 kB */ -# define STM32L4_FLASH_NPAGES 128 -# define STM32L4_FLASH_PAGESIZE 2048 -# elif defined(CONFIG_STM32L4_FLASH_CONFIG_E) /* 512 kB */ -# define STM32L4_FLASH_NPAGES 256 -# define STM32L4_FLASH_PAGESIZE 2048 -# elif defined(CONFIG_STM32L4_FLASH_CONFIG_G) /* 1 MB */ -# define STM32L4_FLASH_NPAGES 512 -# define STM32L4_FLASH_PAGESIZE 2048 -# else +#if !defined(CONFIG_STM32L4_FLASH_OVERRIDE_DEFAULT) +# undef CONFIG_STM32L4_FLASH_CONFIG_B +# undef CONFIG_STM32L4_FLASH_CONFIG_C +# undef CONFIG_STM32L4_FLASH_CONFIG_E +# undef CONFIG_STM32L4_FLASH_CONFIG_G +# if defined(CONFIG_STM32L4_FLASH_OVERRIDE_B) +# define CONFIG_STM32L4_FLASH_CONFIG_B +# elif defined(CONFIG_STM32L4_FLASH_OVERRIDE_C) +# define CONFIG_STM32L4_FLASH_CONFIG_C +# elif defined(CONFIG_STM32L4_FLASH_OVERRIDE_E) +# define CONFIG_STM32L4_FLASH_CONFIG_E +# elif defined(CONFIG_STM32L4_FLASH_OVERRIDE_G) +# define CONFIG_STM32L4_FLASH_CONFIG_G # endif #endif +/* Define the valid configuration */ + +#if defined(CONFIG_STM32L4_FLASH_CONFIG_B) /* 128 kB */ +# define STM32L4_FLASH_NPAGES 64 +# define STM32L4_FLASH_PAGESIZE 2048 +#elif defined(CONFIG_STM32L4_FLASH_CONFIG_C) /* 256 kB */ +# define STM32L4_FLASH_NPAGES 128 +# define STM32L4_FLASH_PAGESIZE 2048 +#elif defined(CONFIG_STM32L4_FLASH_CONFIG_E) /* 512 kB */ +# define STM32L4_FLASH_NPAGES 256 +# define STM32L4_FLASH_PAGESIZE 2048 +#elif defined(CONFIG_STM32L4_FLASH_CONFIG_G) /* 1 MB */ +# define STM32L4_FLASH_NPAGES 512 +# define STM32L4_FLASH_PAGESIZE 2048 +#else +# error "unknown flash configuration!" +#endif + #ifdef STM32L4_FLASH_PAGESIZE # define STM32L4_FLASH_SIZE (STM32L4_FLASH_NPAGES * STM32L4_FLASH_PAGESIZE) -#endif /* def STM32L4_FLASH_PAGESIZE */ +#endif /* Register Offsets *****************************************************************/ @@ -128,7 +158,7 @@ # define FLASH_ACR_LATENCY_3 (3 << FLASH_ACR_LATENCY_SHIFT) /* 011: Three wait states <=64 <=26 */ # define FLASH_ACR_LATENCY_4 (4 << FLASH_ACR_LATENCY_SHIFT) /* 100: Four wait states <=80 <=26 */ -#define FLASH_ACR_PRFTEN (1 << 8) /* Bit 8: Pprefetch enable */ +#define FLASH_ACR_PRFTEN (1 << 8) /* Bit 8: Prefetch enable */ #define FLASH_ACR_ICEN (1 << 9) /* Bit 9: Instruction cache enable */ #define FLASH_ACR_DCEN (1 << 10) /* Bit 10: Data cache enable */ #define FLASH_ACR_ICRST (1 << 11) /* Bit 11: Instruction cache reset */ From 0ce7815efe39376f7fa06b4e0b8baf602e055427 Mon Sep 17 00:00:00 2001 From: Juha Niskanen Date: Thu, 4 May 2017 14:45:37 +0300 Subject: [PATCH 128/183] configs: add nucleo-l452re board files --- configs/Kconfig | 13 + configs/nucleo-l452re/Kconfig | 8 + configs/nucleo-l452re/README.txt | 271 ++++ configs/nucleo-l452re/include/board.h | 272 ++++ configs/nucleo-l452re/include/nucleo-l452re.h | 510 +++++++ configs/nucleo-l452re/nsh/Make.defs | 112 ++ configs/nucleo-l452re/nsh/defconfig | 1258 +++++++++++++++++ configs/nucleo-l452re/scripts/l452re-flash.ld | 119 ++ configs/nucleo-l452re/src/.gitignore | 2 + configs/nucleo-l452re/src/Makefile | 56 + configs/nucleo-l452re/src/nucleo-l452re.h | 149 ++ configs/nucleo-l452re/src/stm32_appinit.c | 87 ++ configs/nucleo-l452re/src/stm32_autoleds.c | 96 ++ configs/nucleo-l452re/src/stm32_boot.c | 94 ++ configs/nucleo-l452re/src/stm32_bringup.c | 117 ++ configs/nucleo-l452re/src/stm32_buttons.c | 128 ++ configs/nucleo-l452re/src/stm32_spi.c | 223 +++ configs/nucleo-l452re/src/stm32_userleds.c | 217 +++ 18 files changed, 3732 insertions(+) create mode 100644 configs/nucleo-l452re/Kconfig create mode 100644 configs/nucleo-l452re/README.txt create mode 100644 configs/nucleo-l452re/include/board.h create mode 100644 configs/nucleo-l452re/include/nucleo-l452re.h create mode 100644 configs/nucleo-l452re/nsh/Make.defs create mode 100644 configs/nucleo-l452re/nsh/defconfig create mode 100644 configs/nucleo-l452re/scripts/l452re-flash.ld create mode 100644 configs/nucleo-l452re/src/.gitignore create mode 100644 configs/nucleo-l452re/src/Makefile create mode 100644 configs/nucleo-l452re/src/nucleo-l452re.h create mode 100644 configs/nucleo-l452re/src/stm32_appinit.c create mode 100644 configs/nucleo-l452re/src/stm32_autoleds.c create mode 100644 configs/nucleo-l452re/src/stm32_boot.c create mode 100644 configs/nucleo-l452re/src/stm32_bringup.c create mode 100644 configs/nucleo-l452re/src/stm32_buttons.c create mode 100644 configs/nucleo-l452re/src/stm32_spi.c create mode 100644 configs/nucleo-l452re/src/stm32_userleds.c diff --git a/configs/Kconfig b/configs/Kconfig index 6daffc80e0a..d61c7ef8793 100644 --- a/configs/Kconfig +++ b/configs/Kconfig @@ -810,6 +810,15 @@ config ARCH_BOARD_NUCLEO_F411RE This is a minimal configuration that supports low-level test of the Nucleo F411RE in the NuttX source tree. +config ARCH_BOARD_NUCLEO_L452RE + bool "STM32L452 Nucleo L452RE" + depends on ARCH_CHIP_STM32L452RE + select ARCH_HAVE_LEDS + select ARCH_HAVE_BUTTONS + select ARCH_HAVE_IRQBUTTONS + ---help--- + STMicro Nucleo L452RE board based on the STMicro STM32L452RET6 MCU. + config ARCH_BOARD_NUCLEO_L476RG bool "STM32L476 Nucleo L476RG" depends on ARCH_CHIP_STM32L476RG @@ -1557,6 +1566,7 @@ config ARCH_BOARD default "nucleo-f303re" if ARCH_BOARD_NUCLEO_F303RE default "nucleo-f334r8" if ARCH_BOARD_NUCLEO_F334R8 default "nucleo-f4x1re" if ARCH_BOARD_NUCLEO_F401RE || ARCH_BOARD_NUCLEO_F411RE + default "nucleo-l452re" if ARCH_BOARD_NUCLEO_L452RE default "nucleo-l476rg" if ARCH_BOARD_NUCLEO_L476RG default "nucleo-l496zg" if ARCH_BOARD_NUCLEO_L496ZG default "qemu-i486" if ARCH_BOARD_QEMU_I486 @@ -1876,6 +1886,9 @@ endif if ARCH_BOARD_NUCLEO_F401RE || ARCH_BOARD_NUCLEO_F411RE source "configs/nucleo-f4x1re/Kconfig" endif +if ARCH_BOARD_NUCLEO_L452RE +source "configs/nucleo-l452re/Kconfig" +endif if ARCH_BOARD_NUCLEO_L476RG source "configs/nucleo-l476rg/Kconfig" endif diff --git a/configs/nucleo-l452re/Kconfig b/configs/nucleo-l452re/Kconfig new file mode 100644 index 00000000000..e0e29ca22cd --- /dev/null +++ b/configs/nucleo-l452re/Kconfig @@ -0,0 +1,8 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +if ARCH_BOARD_NUCLEO_L452RE + +endif diff --git a/configs/nucleo-l452re/README.txt b/configs/nucleo-l452re/README.txt new file mode 100644 index 00000000000..386c1ad8f70 --- /dev/null +++ b/configs/nucleo-l452re/README.txt @@ -0,0 +1,271 @@ +Nucleo-L452RE README +==================== + + This README file discusses the port of NuttX to the STMicro Nucleo-L452RE + board. That board features the STM32L452RET6 MCU with 512KiB of FLASH + and 160KiB of SRAM. + +Contents +======== + + - Status + - Nucleo-64 Boards + - LEDs + - Buttons + - Serial Console + - Configurations + +Status +====== + 2017-05-04: The board now boots and the basic NSH configurations works + without problem. + +Nucleo-64 Boards +================ + + The Nucleo-L452RE is a member of the Nucleo-64 board family. The Nucleo-64 + is a standard board for use with several STM32 parts in the LQFP64 package. + Variants including: + + Order code Targeted STM32 + ------------- -------------- + NUCLEO-F030R8 STM32F030R8T6 + NUCLEO-F070RB STM32F070RBT6 + NUCLEO-F072RB STM32F072RBT6 + NUCLEO-F091RC STM32F091RCT6 + NUCLEO-F103RB STM32F103RBT6 + NUCLEO-F302R8 STM32F302R8T6 + NUCLEO-F303RE STM32F303RET6 + NUCLEO-F334R8 STM32F334R8T6 + NUCLEO-F401RE STM32F401RET6 + NUCLEO-F410RB STM32F410RBT6 + NUCLEO-F411RE STM32F411RET6 + NUCLEO-F446RE STM32F446RET6 + NUCLEO-L053R8 STM32L053R8T6 + NUCLEO-L073RZ STM32L073RZT6 + NUCLEO-L152RE STM32L152RET6 + NUCLEO-L452RE STM32L452RET6 + NUCLEO-L476RG STM32L476RGT6 + +LEDs +==== + + The Nucleo-64 board has one user controlable LED, User LD2. This green + LED is a user LED connected to Arduino signal D13 corresponding to STM32 + I/O PA5 (PB13 on other some other Nucleo-64 boards). + + - When the I/O is HIGH value, the LED is on + - When the I/O is LOW, the LED is off + + These LEDs are not used by the board port unless CONFIG_ARCH_LEDS is + defined. In that case, the usage by the board port is defined in + include/board.h and src/stm32_autoleds.c. The LEDs are used to encode + OS-related events as follows when the red LED (PE24) is available: + + SYMBOL Meaning LD2 + ------------------- ----------------------- ----------- + LED_STARTED NuttX has been started OFF + LED_HEAPALLOCATE Heap has been allocated OFF + LED_IRQSENABLED Interrupts enabled OFF + LED_STACKCREATED Idle stack created ON + LED_INIRQ In an interrupt No change + LED_SIGNAL In a signal handler No change + LED_ASSERTION An assertion failed No change + LED_PANIC The system has crashed Blinking + LED_IDLE MCU is is sleep mode Not used + + Thus if LD2, NuttX has successfully booted and is, apparently, running + normally. If LD2 is flashing at approximately 2Hz, then a fatal error + has been detected and the system has halted. + +Buttons +======= + + B1 USER: the user button is connected to the I/O PC13 (pin 2) of the STM32 + microcontroller. + +Serial Console +============== + + USART1 + ------ + Pins and Connectors: + + RXD: PA10 D3 CN9 pin 3, CN10 pin 33 + PB7 CN7 pin 21 + TXD: PA9 D8 CN5 pin 1, CN10 pin 21 + PB6 D10 CN5 pin 3, CN10 pin 17 + + NOTE: You may need to edit the include/board.h to select different USART1 + pin selections. + + TTL to RS-232 converter connection: + + Nucleo CN10 STM32F072RB + ----------- ------------ + Pin 21 PA9 USART1_TX *Warning you make need to reverse RX/TX on + Pin 33 PA10 USART1_RX some RS-232 converters + Pin 20 GND + Pin 8 U5V + + To configure USART1 as the console: + + CONFIG_STM32_USART1=y + CONFIG_USART1_SERIALDRIVER=y + CONFIG_USART1_SERIAL_CONSOLE=y + CONFIG_USART1_RXBUFSIZE=256 + CONFIG_USART1_TXBUFSIZE=256 + CONFIG_USART1_BAUD=115200 + CONFIG_USART1_BITS=8 + CONFIG_USART1_PARITY=0 + CONFIG_USART1_2STOP=0 + + USART2 + ------ + Pins and Connectors: + + RXD: PA3 To be provided + PA15 + PD6 + TXD: PA2 + PA14 + PD5 + + See "Virtual COM Port" and "RS-232 Shield" below. + + USART3 + ------ + Pins and Connectors: + + RXD: PB11 To be provided + PC5 + PC11 + D9 + TXD: PB10 + PC4 + PC10 + D8 + + USART3 + ------ + Pins and Connectors: + + RXD: PA1 To be provided + PC11 + TXD: PA0 + PC10 + + Virtual COM Port + ---------------- + Yet another option is to use UART2 and the USB virtual COM port. This + option may be more convenient for long term development, but is painful + to use during board bring-up. + + Solder Bridges. This configuration requires: + + - SB62 and SB63 Open: PA2 and PA3 on STM32 MCU are disconnected to D1 + and D0 (pin 7 and pin 8) on Arduino connector CN9 and ST Morpho + connector CN10. + + - SB13 and SB14 Closed: PA2 and PA3 on STM32F103C8T6 (ST-LINK MCU) are + connected to PA3 and PA2 on STM32 MCU to have USART communication + between them. Thus SB61, SB62 and SB63 should be OFF. + + Configuring USART2 is the same as given above. + + 115200 8N1 BAUD should be configure to interface with the Virtual COM + port. + + Default + ------- + As shipped, SB62 and SB63 are open and SB13 and SB14 closed, so the + virtual COM port is enabled. + + RS-232 Shield + ------------- + Supports a single RS-232 connected via + + Nucleo STM32F4x1RE Shield + --------- --------------- -------- + CN9 Pin 1 PA3 USART2_RXD RXD + CN9 Pin 2 PA2 USART2_TXD TXD + + Support for this shield is enabled by selecting USART2 and configuring + SB13, 14, 62, and 63 as described above under "Virtual COM Port" + +Configurations +============== + + Information Common to All Configurations + ---------------------------------------- + Each configuration is maintained in a sub-directory and can be + selected as follow: + + cd tools + ./configure.sh nucleo-l452re/ + cd - + + Before building, make sure the PATH environment variable includes the + correct path to the directory than holds your toolchain binaries. + + And then build NuttX by simply typing the following. At the conclusion of + the make, the nuttx binary will reside in an ELF file called, simply, nuttx. + + make oldconfig + make + + The that is provided above as an argument to the tools/configure.sh + must be is one of the following. + + NOTES: + + 1. These configurations use the mconf-based configuration tool. To + change any of these configurations using that tool, you should: + + a. Build and install the kconfig-mconf tool. See nuttx/README.txt + see additional README.txt files in the NuttX tools repository. + + b. Execute 'make menuconfig' in nuttx/ in order to start the + reconfiguration process. + + 2. Unless stated otherwise, all configurations generate console + output on USART2, as described above under "Serial Console". The + elevant configuration settings are listed below: + + CONFIG_STM32_USART2=y + CONFIG_STM32_USART2_SERIALDRIVER=y + CONFIG_STM32_USART=y + + CONFIG_USART2_SERIALDRIVER=y + CONFIG_USART2_SERIAL_CONSOLE=y + + CONFIG_USART2_RXBUFSIZE=256 + CONFIG_USART2_TXBUFSIZE=256 + CONFIG_USART2_BAUD=115200 + CONFIG_USART2_BITS=8 + CONFIG_USART2_PARITY=0 + CONFIG_USART2_2STOP=0 + + 3. All of these configurations are set up to build under Linux using the + "GNU Tools for ARM Embedded Processors" that is maintained by ARM + (unless stated otherwise in the description of the configuration). + + https://launchpad.net/gcc-arm-embedded + + That toolchain selection can easily be reconfigured using + 'make menuconfig'. Here are the relevant current settings: + + Build Setup: + CONFIG_HOST_LINUX=y : Linux environment + + System Type -> Toolchain: + CONFIG_ARMV7M_TOOLCHAIN_GNU_EABIL=y : GNU ARM EABI toolchain + + Configuration sub-directories + ----------------------------- + + nsh: + + Configures the NuttShell (nsh) located at examples/nsh. This + configuration is focused on low level, command-line driver testing. + diff --git a/configs/nucleo-l452re/include/board.h b/configs/nucleo-l452re/include/board.h new file mode 100644 index 00000000000..30e452dca75 --- /dev/null +++ b/configs/nucleo-l452re/include/board.h @@ -0,0 +1,272 @@ +/************************************************************************************ + * configs/nucleo-l452re/include/board.h + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ************************************************************************************/ + +#ifndef __CONFIGS_NUCLEO_L452RE_INCLUDE_BOARD_H +#define __CONFIGS_NUCLEO_L452RE_INCLUDE_BOARD_H + +/************************************************************************************ + * Included Files + ************************************************************************************/ + +#include +#ifndef __ASSEMBLY__ +# include +#endif + +#include + +/************************************************************************************ + * Pre-processor Definitions + ************************************************************************************/ + +/* Clocking *************************************************************************/ + +#if defined(CONFIG_ARCH_CHIP_STM32L452RE) +# include +#endif + +/* DMA Channel/Stream Selections ****************************************************/ +/* Stream selections are arbitrary for now but might become important in the future + * is we set aside more DMA channels/streams. + */ + +/* Values defined in arch/arm/src/stm32l4/chip/stm32l4x3xx_dma.h */ + +#define DMACHAN_SDMMC DMACHAN_SDMMC_1 /* 2 choices */ + +#define DMACHAN_SPI1_RX DMACHAN_SPI1_RX_1 /* 2 choices */ +#define DMACHAN_SPI1_TX DMACHAN_SPI1_TX_1 /* 2 choices */ + +/* UART RX DMA configurations */ + +#define DMACHAN_USART1_RX DMACHAN_USART1_RX_2 + +/* Alternate function pin selections ************************************************/ + +/* USART1: + * RXD: PA10 CN9 pin 3, CN10 pin 33 + * PB7 CN7 pin 21 + * TXD: PA9 CN5 pin 1, CN10 pin 21 + * PB6 CN5 pin 3, CN10 pin 17 + */ + +#if 1 +# define GPIO_USART1_RX GPIO_USART1_RX_1 /* PA10 */ +# define GPIO_USART1_TX GPIO_USART1_TX_1 /* PA9 */ +#else +# define GPIO_USART1_RX GPIO_USART1_RX_2 /* PB7 */ +# define GPIO_USART1_TX GPIO_USART1_TX_2 /* PB6 */ +#endif + +/* USART2: Connected to STLink Debug via PA2, PA3 + * RXD: PA3 CN9 pin 1 (See SB13, 14, 62, 63). CN10 pin 37 + * PD6 + * TXD: PA2 CN9 pin 2 (See SB13, 14, 62, 63). CN10 pin 35 + * PD5 + */ + +#define GPIO_USART2_RX GPIO_USART2_RX_1 /* PA3 */ +#define GPIO_USART2_TX GPIO_USART2_TX_1 /* PA2 */ +#define GPIO_USART2_RTS GPIO_USART2_RTS_2 +#define GPIO_USART2_CTS GPIO_USART2_CTS_2 + +#define GPIO_USART3_RX GPIO_USART3_RX_3 /* PC11 */ +#define GPIO_USART3_TX GPIO_USART3_TX_3 /* PC10 */ + +#define GPIO_UART4_RX GPIO_UART4_RX_1 /* PA1 */ +#define GPIO_UART4_TX GPIO_UART4_TX_1 /* PA0 */ + +/* I2C + * + * The optional _GPIO configurations allow the I2C driver to manually + * reset the bus to clear stuck slaves. They match the pin configuration, + * but are normally-high GPIOs. + */ + +#define GPIO_I2C1_SCL \ + (GPIO_I2C1_SCL_2 | GPIO_OPENDRAIN | GPIO_SPEED_50MHz | GPIO_OUTPUT_SET) +#define GPIO_I2C1_SDA \ + (GPIO_I2C1_SDA_2 | GPIO_OPENDRAIN | GPIO_SPEED_50MHz | GPIO_OUTPUT_SET) +#define GPIO_I2C1_SCL_GPIO \ + (GPIO_OUTPUT | GPIO_OPENDRAIN | GPIO_SPEED_50MHz | GPIO_OUTPUT_SET | \ + GPIO_PORTB | GPIO_PIN8) +#define GPIO_I2C1_SDA_GPIO \ + (GPIO_OUTPUT | GPIO_OPENDRAIN | GPIO_SPEED_50MHz | GPIO_OUTPUT_SET | \ + GPIO_PORTB | GPIO_PIN9) + +#define GPIO_I2C2_SCL \ + (GPIO_I2C2_SCL_1 | GPIO_OPENDRAIN | GPIO_SPEED_50MHz | GPIO_OUTPUT_SET) +#define GPIO_I2C2_SDA \ + (GPIO_I2C2_SDA_1 | GPIO_OPENDRAIN | GPIO_SPEED_50MHz | GPIO_OUTPUT_SET) +#define GPIO_I2C2_SCL_GPIO \ + (GPIO_OUTPUT | GPIO_OPENDRAIN | GPIO_SPEED_50MHz | GPIO_OUTPUT_SET | \ + GPIO_PORTB | GPIO_PIN10) +#define GPIO_I2C2_SDA_GPIO \ + (GPIO_OUTPUT | GPIO_OPENDRAIN | GPIO_SPEED_50MHz | GPIO_OUTPUT_SET | \ + GPIO_PORTB | GPIO_PIN11) + +/* SPI */ + +#define GPIO_SPI1_MISO GPIO_SPI1_MISO_1 +#define GPIO_SPI1_MOSI GPIO_SPI1_MOSI_1 +#define GPIO_SPI1_SCK GPIO_SPI1_SCK_1 + +#define GPIO_SPI2_MISO GPIO_SPI2_MISO_1 +#define GPIO_SPI2_MOSI GPIO_SPI2_MOSI_1 +#define GPIO_SPI2_SCK GPIO_SPI2_SCK_2 + +/* LEDs + * + * The Nucleo L452RE board provides a single user LED, LD2. LD2 + * is the green LED connected to Arduino signal D13 corresponding to MCU I/O + * PA5 (pin 21) or PB13 (pin 34) depending on the STM32 target. + * + * - When the I/O is HIGH value, the LED is on. + * - When the I/O is LOW, the LED is off. + */ + +/* LED index values for use with board_userled() */ + +#define BOARD_LD2 0 +#define BOARD_NLEDS 1 + +/* LED bits for use with board_userled_all() */ + +#define BOARD_LD2_BIT (1 << BOARD_LD2) + +/* These LEDs are not used by the board port unless CONFIG_ARCH_LEDS is + * defined. In that case, the usage by the board port is defined in + * include/board.h and src/stm32_autoleds.c. The LEDs are used to encode + * OS-related events as follows when the red LED (PE24) is available: + * + * SYMBOL Meaning LD2 + * ------------------- ----------------------- ----------- + * LED_STARTED NuttX has been started OFF + * LED_HEAPALLOCATE Heap has been allocated OFF + * LED_IRQSENABLED Interrupts enabled OFF + * LED_STACKCREATED Idle stack created ON + * LED_INIRQ In an interrupt No change + * LED_SIGNAL In a signal handler No change + * LED_ASSERTION An assertion failed No change + * LED_PANIC The system has crashed Blinking + * LED_IDLE MCU is is sleep mode Not used + * + * Thus if LD2, NuttX has successfully booted and is, apparently, running + * normally. If LD2 is flashing at approximately 2Hz, then a fatal error + * has been detected and the system has halted. + */ + +#define LED_STARTED 0 +#define LED_HEAPALLOCATE 0 +#define LED_IRQSENABLED 0 +#define LED_STACKCREATED 1 +#define LED_INIRQ 1 +#define LED_SIGNAL 2 +#define LED_ASSERTION 2 +#define LED_PANIC 1 + +/* Buttons + * + * B1 USER: the user button is connected to the I/O PC13 (pin 2) of the STM32 + * microcontroller. + */ + +#define BUTTON_USER 0 +#define NUM_BUTTONS 1 + +#define BUTTON_USER_BIT (1 << BUTTON_USER) + +/* Quadrature encoder + * Default is to use timer 5 (32-bit) and encoder on PA0/PA1 + */ + +#define GPIO_TIM2_CH1IN GPIO_TIM2_CH1IN_1 +#define GPIO_TIM2_CH2IN GPIO_TIM2_CH2IN_1 + +#define GPIO_TIM3_CH1IN GPIO_TIM3_CH1IN_3 +#define GPIO_TIM3_CH2IN GPIO_TIM3_CH2IN_3 + +#define GPIO_TIM5_CH1IN GPIO_TIM5_CH1IN_1 +#define GPIO_TIM5_CH2IN GPIO_TIM5_CH2IN_1 + +/* PWM output for full bridge, uses config 1, because port E is N/A on QFP64 + * CH1 | 1(A8) 2(E9) + * CH2 | 1(A9) 2(E11) + * CHN1 | 1(A7) 2(B13) 3(E8) + * CHN2 | 1(B0) 2(B14) 3(E10) + */ + +#define GPIO_TIM1_CH1OUT GPIO_TIM1_CH1OUT_1 +#define GPIO_TIM1_CH1NOUT GPIO_TIM1_CH1N_1 +#define GPIO_TIM1_CH2OUT GPIO_TIM1_CH2OUT_1 +#define GPIO_TIM1_CH2NOUT GPIO_TIM1_CH2N_1 + +/************************************************************************************ + * Public Data + ************************************************************************************/ + +#ifndef __ASSEMBLY__ + +#undef EXTERN +#if defined(__cplusplus) +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/************************************************************************************ + * Public Function Prototypes + ************************************************************************************/ +/************************************************************************************ + * Name: stm32l4_boardinitialize + * + * Description: + * All STM32L4 architectures must provide the following entry point. This entry point + * is called early in the initialization -- after all memory has been configured + * and mapped but before any devices have been initialized. + * + ************************************************************************************/ + +void stm32l4_boardinitialize(void); + +#undef EXTERN +#if defined(__cplusplus) +} +#endif + +#endif /* __ASSEMBLY__ */ +#endif /* __CONFIGS_NUCLEO_L452RE_INCLUDE_BOARD_H */ diff --git a/configs/nucleo-l452re/include/nucleo-l452re.h b/configs/nucleo-l452re/include/nucleo-l452re.h new file mode 100644 index 00000000000..0074a64d9b9 --- /dev/null +++ b/configs/nucleo-l452re/include/nucleo-l452re.h @@ -0,0 +1,510 @@ +/************************************************************************************ + * configs/nucleo-l452re/include/nucleo-l452re.h + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ************************************************************************************/ + +#ifndef __CONFIGS_NUCLEO_L452RE_INCLUDE_NUCLEO_L452RE_H +#define __CONFIGS_NUCLEO_L452RE_INCLUDE_NUCLEO_L452RE_H + +/************************************************************************************ + * Included Files + ************************************************************************************/ + +#include +#ifndef __ASSEMBLY__ +# include +#endif + +/************************************************************************************ + * Pre-processor Definitions + ************************************************************************************/ + +#if 1 +# define HSI_CLOCK_CONFIG /* HSI-16 clock configuration */ +#elif 0 +/* Make sure you installed one! */ + +# define HSE_CLOCK_CONFIG /* HSE with 8 MHz xtal */ +#else +# define MSI_CLOCK_CONFIG /* MSI @ 4 MHz autotrimmed via LSE */ +#endif + +/* Clocking *************************************************************************/ + +#if defined(HSI_CLOCK_CONFIG) +/* The NUCLEOL452RE supports both HSE and LSE crystals (X2 and X3). However, as + * shipped, the X3 crystal is not populated. Therefore the Nucleo-L452RE + * will need to run off the 16MHz HSI clock, or the 32khz-synced MSI. + * + * System Clock source : PLL (HSI) + * SYSCLK(Hz) : 80000000 Determined by PLL configuration + * HCLK(Hz) : 80000000 (STM32L4_RCC_CFGR_HPRE) (Max 80 MHz) + * AHB Prescaler : 1 (STM32L4_RCC_CFGR_HPRE) (Max 80 MHz) + * APB1 Prescaler : 1 (STM32L4_RCC_CFGR_PPRE1) (Max 80 MHz) + * APB2 Prescaler : 1 (STM32L4_RCC_CFGR_PPRE2) (Max 80 MHz) + * HSI Frequency(Hz) : 16000000 (nominal) + * PLLM : 1 (STM32L4_PLLCFG_PLLM) + * PLLN : 10 (STM32L4_PLLCFG_PLLN) + * PLLP : 0 (STM32L4_PLLCFG_PLLP) + * PLLQ : 0 (STM32L4_PLLCFG_PLLQ) + * PLLR : 2 (STM32L4_PLLCFG_PLLR) + * PLLSAI1N : 12 + * PLLSAI1Q : 4 + * Flash Latency(WS) : 4 + * Prefetch Buffer : OFF + * 48MHz for USB OTG FS, : Doable if required using PLLSAI1 or MSI + * SDIO and RNG clock + */ + +/* HSI - 16 MHz RC factory-trimmed + * LSI - 32 KHz RC + * MSI - variable up to 48 MHz, synchronized to LSE + * HSE - not installed + * LSE - 32.768 kHz installed + */ + +#define STM32L4_HSI_FREQUENCY 16000000ul +#define STM32L4_LSI_FREQUENCY 32000 +#define STM32L4_LSE_FREQUENCY 32768 + +#define STM32L4_BOARD_USEHSI 1 + +/* XXX sysclk mux = pllclk */ + +/* XXX pll source mux = hsi */ + +/* REVISIT: Trimming of the HSI and MSI is not yet supported. */ + +/* Main PLL Configuration. + * + * Formulae: + * + * VCO input frequency = PLL input clock frequency / PLLM, 1 <= PLLM <= 8 + * VCO output frequency = VCO input frequency × PLLN, 8 <= PLLN <= 86, frequency range 64 to 344 MHz + * PLL output P (SAI3) clock frequency = VCO frequency / PLLP, PLLP = 7, or 17, or 0 to disable + * PLL output Q (48M1) clock frequency = VCO frequency / PLLQ, PLLQ = 2, 4, 6, or 8, or 0 to disable + * PLL output R (CLK) clock frequency = VCO frequency / PLLR, PLLR = 2, 4, 6, or 8, or 0 to disable + * + * PLL output P is used for SAI + * PLL output Q is used for OTG FS, SDMMC, RNG + * PLL output R is used for SYSCLK + * PLLP = 0 (not used) + * PLLQ = 0 (not used) + * PLLR = 2 + * PLLN = 10 + * PLLM = 1 + * + * We will configure like this + * + * PLL source is HSI + * + * PLL_REF = STM32L4_HSI_FREQUENCY / PLLM + * = 16,000,000 / 1 + * = 16,000,000 + * + * PLL_VCO = PLL_REF * PLLN + * = 16,000,000 * 10 + * = 160,000,000 + * + * PLL_CLK = PLL_VCO / PLLR + * = 160,000,000 / 2 = 80,000,000 + * PLL_48M1 = disabled + * PLL_SAI3 = disabled + * + * ---------------------------------------- + * + * PLLSAI1 Configuration + * + * The clock input and M divider are identical to the main PLL. + * However the multiplier and postscalers are independent. + * The PLLSAI1 is configured only if CONFIG_STM32L4_SAI1PLL is defined + * + * SAI1VCO input frequency = PLL input clock frequency + * SAI1VCO output frequency = SAI1VCO input frequency × PLLSAI1N, 8 <= PLLSAI1N <= 86, frequency range 64 to 344 MHz + * SAI1PLL output P (SAI1) clock frequency = SAI1VCO frequency / PLLSAI1P, PLLP = 7, or 17, or 0 to disable + * SAI1PLL output Q (48M2) clock frequency = SAI1VCO frequency / PLLSAI1Q, PLLQ = 2, 4, 6, or 8, or 0 to disable + * SAI1PLL output R (ADC1) clock frequency = SAI1VCO frequency / PLLSAI1R, PLLR = 2, 4, 6, or 8, or 0 to disable + * + * We will configure like this + * + * PLLSAI1 disabled + * + * ---------------------------------------- + * + * PLLSAI2 Configuration + * + * The clock input and M divider are identical to the main PLL. + * However the multiplier and postscalers are independent. + * The PLLSAI2 is configured only if CONFIG_STM32L4_SAI2PLL is defined + * + * SAI2VCO input frequency = PLL input clock frequency + * SAI2VCO output frequency = SAI2VCO input frequency × PLLSAI2N, 8 <= PLLSAI1N <= 86, frequency range 64 to 344 MHz + * SAI2PLL output P (SAI2) clock frequency = SAI2VCO frequency / PLLSAI2P, PLLP = 7, or 17, or 0 to disable + * SAI2PLL output R (ADC2) clock frequency = SAI2VCO frequency / PLLSAI2R, PLLR = 2, 4, 6, or 8, or 0 to disable + * + * We will configure like this + * + * PLLSAI2 disabled + * + * ---------------------------------------- + * + * TODO: The STM32L is a low power peripheral and all these clocks should be configurable at runtime. + * + * ---------------------------------------- + * + * TODO These clock sources can be configured in Kconfig (this is not a board feature) + * USART1 + * USART2 + * USART3 + * UART4 + * UART5 + * LPUART1 + * I2C1 + * I2C2 + * I2C3 + * LPTIM1 + * LPTIM2 + * SAI1 + * SAI2 + * CLK48 + * ADC + * SWPMI + * DFSDM + */ + +/* prescaler common to all PLL inputs; will be 1 (XXX source is implicitly + as per comment above HSI) */ + +#define STM32L4_PLLCFG_PLLM RCC_PLLCFG_PLLM(1) + +/* 'main' PLL config; we use this to generate our system clock via the R + * output. We set it up as 16 MHz / 1 * 10 / 2 = 80 MHz + * + * XXX NOTE: currently the main PLL is implicitly turned on and is implicitly + * the system clock; this should be configurable since not all applications may + * want things done this way. + */ + +#define STM32L4_PLLCFG_PLLN RCC_PLLCFG_PLLN(10) +#define STM32L4_PLLCFG_PLLP 0 +#undef STM32L4_PLLCFG_PLLP_ENABLED +#define STM32L4_PLLCFG_PLLQ RCC_PLLCFG_PLLQ_2 +#define STM32L4_PLLCFG_PLLQ_ENABLED +#define STM32L4_PLLCFG_PLLR RCC_PLLCFG_PLLR(2) +#define STM32L4_PLLCFG_PLLR_ENABLED + +/* 'SAIPLL1' is used to generate the 48 MHz clock, since we can't + * do that with the main PLL's N value. We set N = 12, and enable + * the Q output (ultimately for CLK48) with /4. So, + * 16 MHz / 1 * 12 / 4 = 48 MHz + * + * XXX NOTE: currently the SAIPLL /must/ be explicitly selected in the + * menuconfig, or else all this is a moot point, and the various 48 MHz + * peripherals will not work (RNG at present). I would suggest removing + * that option from Kconfig altogether, and simply making it an option + * that is selected via a #define here, like all these other params. + */ + +#define STM32L4_PLLSAI1CFG_PLLN RCC_PLLSAI1CFG_PLLN(12) +#define STM32L4_PLLSAI1CFG_PLLP 0 +#undef STM32L4_PLLSAI1CFG_PLLP_ENABLED +#define STM32L4_PLLSAI1CFG_PLLQ RCC_PLLSAI1CFG_PLLQ_4 +#define STM32L4_PLLSAI1CFG_PLLQ_ENABLED +#define STM32L4_PLLSAI1CFG_PLLR 0 +#undef STM32L4_PLLSAI1CFG_PLLR_ENABLED + +/* 'SAIPLL2' is not used in this application */ + +#define STM32L4_PLLSAI2CFG_PLLN RCC_PLLSAI2CFG_PLLN(8) +#define STM32L4_PLLSAI2CFG_PLLP 0 +#undef STM32L4_PLLSAI2CFG_PLLP_ENABLED +#define STM32L4_PLLSAI2CFG_PLLR 0 +#undef STM32L4_PLLSAI2CFG_PLLR_ENABLED + +#define STM32L4_SYSCLK_FREQUENCY 80000000ul + +/* CLK48 will come from PLLSAI1 (implicitly Q) */ + +#define STM32L4_USE_CLK48 +#define STM32L4_CLK48_SEL RCC_CCIPR_CLK48SEL_PLLSAI1 + +/* enable the LSE oscillator, used automatically trim the MSI, and for RTC */ + +#define STM32L4_USE_LSE 1 + +/* AHB clock (HCLK) is SYSCLK (80MHz) */ + +#define STM32L4_RCC_CFGR_HPRE RCC_CFGR_HPRE_SYSCLK /* HCLK = SYSCLK / 1 */ +#define STM32L4_HCLK_FREQUENCY STM32L4_SYSCLK_FREQUENCY +#define STM32L4_BOARD_HCLK STM32L4_HCLK_FREQUENCY /* Same as above, to satisfy compiler */ + +/* APB1 clock (PCLK1) is HCLK/1 (80MHz) */ + +#define STM32L4_RCC_CFGR_PPRE1 RCC_CFGR_PPRE1_HCLK /* PCLK1 = HCLK / 1 */ +#define STM32L4_PCLK1_FREQUENCY (STM32L4_HCLK_FREQUENCY/1) + +/* Timers driven from APB1 will be twice PCLK1 */ +/* REVISIT : this can be configured */ + +#define STM32L4_APB1_TIM2_CLKIN (2*STM32L4_PCLK1_FREQUENCY) +#define STM32L4_APB1_TIM3_CLKIN (2*STM32L4_PCLK1_FREQUENCY) +#define STM32L4_APB1_TIM4_CLKIN (2*STM32L4_PCLK1_FREQUENCY) +#define STM32L4_APB1_TIM5_CLKIN (2*STM32L4_PCLK1_FREQUENCY) +#define STM32L4_APB1_TIM6_CLKIN (2*STM32L4_PCLK1_FREQUENCY) +#define STM32L4_APB1_TIM7_CLKIN (2*STM32L4_PCLK1_FREQUENCY) + +/* APB2 clock (PCLK2) is HCLK (80MHz) */ + +#define STM32L4_RCC_CFGR_PPRE2 RCC_CFGR_PPRE2_HCLK /* PCLK2 = HCLK / 1 */ +#define STM32L4_PCLK2_FREQUENCY (STM32L4_HCLK_FREQUENCY/1) + +/* Timers driven from APB2 will be twice PCLK2 */ +/* REVISIT : this can be configured */ + +#define STM32L4_APB2_TIM1_CLKIN (2*STM32L4_PCLK2_FREQUENCY) +#define STM32L4_APB2_TIM8_CLKIN (2*STM32L4_PCLK2_FREQUENCY) + +/* Timer Frequencies, if APBx is set to 1, frequency is same to APBx + * otherwise frequency is 2xAPBx. + * Note: TIM1,8 are on APB2, others on APB1 + */ +/* REVISIT : this can be configured */ + +/* TODO SDMMC */ + +#elif defined(HSE_CLOCK_CONFIG) + +/* Use the HSE */ + +#define STM32L4_BOARD_USEHSE 1 + +/* XXX sysclk mux = pllclk */ + +/* XXX pll source mux = hse */ + +/* Prescaler common to all PLL inputs */ + +#define STM32L4_PLLCFG_PLLM RCC_PLLCFG_PLLM(1) + +/* 'main' PLL config; we use this to generate our system clock */ + +#define STM32L4_PLLCFG_PLLN RCC_PLLCFG_PLLN(20) +#define STM32L4_PLLCFG_PLLP 0 +#undef STM32L4_PLLCFG_PLLP_ENABLED +#define STM32L4_PLLCFG_PLLQ 0 +#undef STM32L4_PLLCFG_PLLQ_ENABLED +#define STM32L4_PLLCFG_PLLR RCC_PLLCFG_PLLR_2 +#define STM32L4_PLLCFG_PLLR_ENABLED + +/* 'SAIPLL1' is used to generate the 48 MHz clock */ + +#define STM32L4_PLLSAI1CFG_PLLN RCC_PLLSAI1CFG_PLLN(12) +#define STM32L4_PLLSAI1CFG_PLLP 0 +#undef STM32L4_PLLSAI1CFG_PLLP_ENABLED +#define STM32L4_PLLSAI1CFG_PLLQ RCC_PLLSAI1CFG_PLLQ_2 +#define STM32L4_PLLSAI1CFG_PLLQ_ENABLED +#define STM32L4_PLLSAI1CFG_PLLR 0 +#undef STM32L4_PLLSAI1CFG_PLLR_ENABLED + +/* 'SAIPLL2' is not used in this application */ + +#define STM32L4_PLLSAI2CFG_PLLN RCC_PLLSAI2CFG_PLLN(8) +#define STM32L4_PLLSAI2CFG_PLLP 0 +#undef STM32L4_PLLSAI2CFG_PLLP_ENABLED +#define STM32L4_PLLSAI2CFG_PLLR 0 +#undef STM32L4_PLLSAI2CFG_PLLR_ENABLED + +#define STM32L4_SYSCLK_FREQUENCY 80000000ul + +/* Enable CLK48; get it from PLLSAI1 */ + +#define STM32L4_USE_CLK48 +#define STM32L4_CLK48_SEL RCC_CCIPR_CLK48SEL_PLLSAI1 + +/* Enable LSE (for the RTC) */ + +#define STM32L4_USE_LSE 1 + +/* Configure the HCLK divisor (for the AHB bus, core, memory, and DMA */ + +#define STM32L4_RCC_CFGR_HPRE RCC_CFGR_HPRE_SYSCLK /* HCLK = SYSCLK / 1 */ +#define STM32L4_HCLK_FREQUENCY STM32L4_SYSCLK_FREQUENCY +#define STM32L4_BOARD_HCLK STM32L4_HCLK_FREQUENCY /* Same as above, to satisfy compiler */ + +/* Configure the APB1 prescaler */ + +#define STM32L4_RCC_CFGR_PPRE1 RCC_CFGR_PPRE1_HCLK /* PCLK1 = HCLK / 1 */ +#define STM32L4_PCLK1_FREQUENCY (STM32L4_HCLK_FREQUENCY/1) + +#define STM32L4_APB1_TIM2_CLKIN (2*STM32L4_PCLK1_FREQUENCY) +#define STM32L4_APB1_TIM3_CLKIN (2*STM32L4_PCLK1_FREQUENCY) +#define STM32L4_APB1_TIM4_CLKIN (2*STM32L4_PCLK1_FREQUENCY) +#define STM32L4_APB1_TIM5_CLKIN (2*STM32L4_PCLK1_FREQUENCY) +#define STM32L4_APB1_TIM6_CLKIN (2*STM32L4_PCLK1_FREQUENCY) +#define STM32L4_APB1_TIM7_CLKIN (2*STM32L4_PCLK1_FREQUENCY) + +/* Configure the APB2 prescaler */ + +#define STM32L4_RCC_CFGR_PPRE2 RCC_CFGR_PPRE2_HCLK /* PCLK2 = HCLK / 1 */ +#define STM32L4_PCLK2_FREQUENCY (STM32L4_HCLK_FREQUENCY/1) + +#define STM32L4_APB2_TIM1_CLKIN (2*STM32L4_PCLK2_FREQUENCY) +#define STM32L4_APB2_TIM8_CLKIN (2*STM32L4_PCLK2_FREQUENCY) + +#elif defined(MSI_CLOCK_CONFIG) + +/* Use the MSI; frequ = 4 MHz; autotrim from LSE */ + +#define STM32L4_BOARD_USEMSI 1 +#define STM32L4_BOARD_MSIRANGE RCC_CR_MSIRANGE_4M + +/* XXX sysclk mux = pllclk */ + +/* XXX pll source mux = msi */ + +/* prescaler common to all PLL inputs */ + +#define STM32L4_PLLCFG_PLLM RCC_PLLCFG_PLLM(1) + +/* 'main' PLL config; we use this to generate our system clock */ + +#define STM32L4_PLLCFG_PLLN RCC_PLLCFG_PLLN(40) +#define STM32L4_PLLCFG_PLLP 0 +#undef STM32L4_PLLCFG_PLLP_ENABLED +#define STM32L4_PLLCFG_PLLQ 0 +#undef STM32L4_PLLCFG_PLLQ_ENABLED +#define STM32L4_PLLCFG_PLLR RCC_PLLCFG_PLLR_2 +#define STM32L4_PLLCFG_PLLR_ENABLED + +/* 'SAIPLL1' is used to generate the 48 MHz clock */ + +#define STM32L4_PLLSAI1CFG_PLLN RCC_PLLSAI1CFG_PLLN(24) +#define STM32L4_PLLSAI1CFG_PLLP 0 +#undef STM32L4_PLLSAI1CFG_PLLP_ENABLED +#define STM32L4_PLLSAI1CFG_PLLQ RCC_PLLSAI1CFG_PLLQ_2 +#define STM32L4_PLLSAI1CFG_PLLQ_ENABLED +#define STM32L4_PLLSAI1CFG_PLLR 0 +#undef STM32L4_PLLSAI1CFG_PLLR_ENABLED + +/* 'SAIPLL2' is not used in this application */ + +#define STM32L4_PLLSAI2CFG_PLLN RCC_PLLSAI2CFG_PLLN(8) +#define STM32L4_PLLSAI2CFG_PLLP 0 +#undef STM32L4_PLLSAI2CFG_PLLP_ENABLED +#define STM32L4_PLLSAI2CFG_PLLR 0 +#undef STM32L4_PLLSAI2CFG_PLLR_ENABLED + +#define STM32L4_SYSCLK_FREQUENCY 80000000ul + +/* Enable CLK48; get it from PLLSAI1 */ + +#define STM32L4_USE_CLK48 +#define STM32L4_CLK48_SEL RCC_CCIPR_CLK48SEL_PLLSAI1 + +/* Enable LSE (for the RTC) */ + +#define STM32L4_USE_LSE 1 + +/* Configure the HCLK divisor (for the AHB bus, core, memory, and DMA */ + +#define STM32L4_RCC_CFGR_HPRE RCC_CFGR_HPRE_SYSCLK /* HCLK = SYSCLK / 1 */ +#define STM32L4_HCLK_FREQUENCY STM32L4_SYSCLK_FREQUENCY +#define STM32L4_BOARD_HCLK STM32L4_HCLK_FREQUENCY /* Same as above, to satisfy compiler */ + +/* Configure the APB1 prescaler */ + +#define STM32L4_RCC_CFGR_PPRE1 RCC_CFGR_PPRE1_HCLK /* PCLK1 = HCLK / 1 */ +#define STM32L4_PCLK1_FREQUENCY (STM32L4_HCLK_FREQUENCY/1) + +#define STM32L4_APB1_TIM2_CLKIN (2*STM32L4_PCLK1_FREQUENCY) +#define STM32L4_APB1_TIM3_CLKIN (2*STM32L4_PCLK1_FREQUENCY) +#define STM32L4_APB1_TIM4_CLKIN (2*STM32L4_PCLK1_FREQUENCY) +#define STM32L4_APB1_TIM5_CLKIN (2*STM32L4_PCLK1_FREQUENCY) +#define STM32L4_APB1_TIM6_CLKIN (2*STM32L4_PCLK1_FREQUENCY) +#define STM32L4_APB1_TIM7_CLKIN (2*STM32L4_PCLK1_FREQUENCY) + +/* Configure the APB2 prescaler */ + +#define STM32L4_RCC_CFGR_PPRE2 RCC_CFGR_PPRE2_HCLK /* PCLK2 = HCLK / 1 */ +#define STM32L4_PCLK2_FREQUENCY (STM32L4_HCLK_FREQUENCY/1) + +#define STM32L4_APB2_TIM1_CLKIN (2*STM32L4_PCLK2_FREQUENCY) +#define STM32L4_APB2_TIM8_CLKIN (2*STM32L4_PCLK2_FREQUENCY) + +#endif + +/* Timer Frequencies, if APBx is set to 1, frequency is same to APBx + * otherwise frequency is 2xAPBx. + * Note: TIM1,8,15,16,17 are on APB2, others on APB1 + */ + +#define BOARD_TIM1_FREQUENCY STM32L4_HCLK_FREQUENCY +#define BOARD_TIM2_FREQUENCY (STM32L4_HCLK_FREQUENCY / 2) +#define BOARD_TIM3_FREQUENCY (STM32L4_HCLK_FREQUENCY / 2) +#define BOARD_TIM4_FREQUENCY (STM32L4_HCLK_FREQUENCY / 2) +#define BOARD_TIM5_FREQUENCY (STM32L4_HCLK_FREQUENCY / 2) +#define BOARD_TIM6_FREQUENCY (STM32L4_HCLK_FREQUENCY / 2) +#define BOARD_TIM7_FREQUENCY (STM32L4_HCLK_FREQUENCY / 2) +#define BOARD_TIM8_FREQUENCY STM32L4_HCLK_FREQUENCY +#define BOARD_TIM15_FREQUENCY STM32L4_HCLK_FREQUENCY +#define BOARD_TIM16_FREQUENCY STM32L4_HCLK_FREQUENCY +#define BOARD_TIM17_FREQUENCY STM32L4_HCLK_FREQUENCY +#define BOARD_LPTIM1_FREQUENCY (STM32L4_HCLK_FREQUENCY / 2) +#define BOARD_LPTIM2_FREQUENCY (STM32L4_HCLK_FREQUENCY / 2) + +/************************************************************************************ + * Public Data + ************************************************************************************/ + +#ifndef __ASSEMBLY__ + +#undef EXTERN +#if defined(__cplusplus) +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/************************************************************************************ + * Public Function Prototypes + ************************************************************************************/ + +#undef EXTERN +#if defined(__cplusplus) +} +#endif + +#endif /* __ASSEMBLY__ */ +#endif /* __CONFIGS_NUCLEO_L452RE_INCLUDE_NUCLEO_L452RE_H */ diff --git a/configs/nucleo-l452re/nsh/Make.defs b/configs/nucleo-l452re/nsh/Make.defs new file mode 100644 index 00000000000..39adcf7611d --- /dev/null +++ b/configs/nucleo-l452re/nsh/Make.defs @@ -0,0 +1,112 @@ +############################################################################ +# configs/nucleo-l452re/nsh/Make.defs +# +# Copyright (C) 2014 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name NuttX nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + +include ${TOPDIR}/.config +include ${TOPDIR}/tools/Config.mk +include ${TOPDIR}/arch/arm/src/armv7-m/Toolchain.defs + +LDSCRIPT = l452re-flash.ld + +ifeq ($(WINTOOL),y) + # Windows-native toolchains + DIRLINK = $(TOPDIR)/tools/copydir.sh + DIRUNLINK = $(TOPDIR)/tools/unlink.sh + MKDEP = $(TOPDIR)/tools/mknulldeps.sh + ARCHINCLUDES = -I. -isystem "${shell cygpath -w $(TOPDIR)/include}" + ARCHXXINCLUDES = -I. -isystem "${shell cygpath -w $(TOPDIR)/include}" -isystem "${shell cygpath -w $(TOPDIR)/include/cxx}" + ARCHSCRIPT = -T "${shell cygpath -w $(TOPDIR)/configs/$(CONFIG_ARCH_BOARD)/scripts/$(LDSCRIPT)}" +else + # Linux/Cygwin-native toolchain + MKDEP = $(TOPDIR)/tools/mkdeps$(HOSTEXEEXT) + ARCHINCLUDES = -I. -isystem $(TOPDIR)/include + ARCHXXINCLUDES = -I. -isystem $(TOPDIR)/include -isystem $(TOPDIR)/include/cxx + ARCHSCRIPT = -T$(TOPDIR)/configs/$(CONFIG_ARCH_BOARD)/scripts/$(LDSCRIPT) +endif + +CC = $(CROSSDEV)gcc +CXX = $(CROSSDEV)g++ +CPP = $(CROSSDEV)gcc -E +LD = $(CROSSDEV)ld +AR = $(ARCROSSDEV)ar rcs +NM = $(ARCROSSDEV)nm +OBJCOPY = $(CROSSDEV)objcopy +OBJDUMP = $(CROSSDEV)objdump + +ARCHCCVERSION = ${shell $(CC) -v 2>&1 | sed -n '/^gcc version/p' | sed -e 's/^gcc version \([0-9\.]\)/\1/g' -e 's/[-\ ].*//g' -e '1q'} +ARCHCCMAJOR = ${shell echo $(ARCHCCVERSION) | cut -d'.' -f1} + +ifeq ($(CONFIG_DEBUG_SYMBOLS),y) + ARCHOPTIMIZATION = -g +endif + +ifneq ($(CONFIG_DEBUG_NOOPT),y) + ARCHOPTIMIZATION += $(MAXOPTIMIZATION) -fno-strict-aliasing -fno-strength-reduce -fomit-frame-pointer +endif + +ARCHCFLAGS = -fno-builtin +ARCHCXXFLAGS = -fno-builtin -fno-exceptions -fcheck-new -fno-rtti +ARCHWARNINGS = -Wall -Wstrict-prototypes -Wshadow -Wundef +ARCHWARNINGSXX = -Wall -Wshadow -Wundef +ARCHDEFINES = +ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10 + +CFLAGS = $(ARCHCFLAGS) $(ARCHWARNINGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRADEFINES) -pipe +CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS) +CXXFLAGS = $(ARCHCXXFLAGS) $(ARCHWARNINGSXX) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRADEFINES) -pipe +CXXPICFLAGS = $(ARCHPICFLAGS) $(CXXFLAGS) +CPPFLAGS = $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRADEFINES) +AFLAGS = $(CFLAGS) -D__ASSEMBLY__ + +NXFLATLDFLAGS1 = -r -d -warn-common +NXFLATLDFLAGS2 = $(NXFLATLDFLAGS1) -T$(TOPDIR)/binfmt/libnxflat/gnu-nxflat-pcrel.ld -no-check-sections +LDNXFLATFLAGS = -e main -s 2048 + +ASMEXT = .S +OBJEXT = .o +LIBEXT = .a +EXEEXT = + +ifneq ($(CROSSDEV),arm-nuttx-elf-) + LDFLAGS += -nostartfiles -nodefaultlibs +endif +ifeq ($(CONFIG_DEBUG_SYMBOLS),y) + LDFLAGS += -g +endif + +HOSTCC = gcc +HOSTINCLUDES = -I. +HOSTCFLAGS = -Wall -Wstrict-prototypes -Wshadow -Wundef -g -pipe +HOSTLDFLAGS = + diff --git a/configs/nucleo-l452re/nsh/defconfig b/configs/nucleo-l452re/nsh/defconfig new file mode 100644 index 00000000000..5030287da06 --- /dev/null +++ b/configs/nucleo-l452re/nsh/defconfig @@ -0,0 +1,1258 @@ +# +# Automatically generated file; DO NOT EDIT. +# Nuttx/ Configuration +# + +# +# Build Setup +# +# CONFIG_EXPERIMENTAL is not set +# CONFIG_DEFAULT_SMALL is not set +CONFIG_HOST_LINUX=y +# CONFIG_HOST_OSX is not set +# CONFIG_HOST_WINDOWS is not set +# CONFIG_HOST_OTHER is not set + +# +# Build Configuration +# +CONFIG_APPS_DIR="../apps" +CONFIG_BUILD_FLAT=y +# CONFIG_BUILD_2PASS is not set + +# +# Binary Output Formats +# +# CONFIG_RRLOAD_BINARY is not set +# CONFIG_INTELHEX_BINARY is not set +# CONFIG_MOTOROLA_SREC is not set +CONFIG_RAW_BINARY=y +# CONFIG_UBOOT_UIMAGE is not set + +# +# Customize Header Files +# +# CONFIG_ARCH_STDINT_H is not set +# CONFIG_ARCH_STDBOOL_H is not set +# CONFIG_ARCH_MATH_H is not set +# CONFIG_ARCH_FLOAT_H is not set +# CONFIG_ARCH_STDARG_H is not set +# CONFIG_ARCH_DEBUG_H is not set + +# +# Debug Options +# +CONFIG_DEBUG_ALERT=y +CONFIG_DEBUG_FEATURES=y + +# +# Debug SYSLOG Output Controls +# +CONFIG_DEBUG_ERROR=y +CONFIG_DEBUG_WARN=y +CONFIG_DEBUG_INFO=y +CONFIG_DEBUG_ASSERTIONS=y + +# +# Subsystem Debug Options +# +# CONFIG_DEBUG_BINFMT is not set +# CONFIG_DEBUG_FS is not set +# CONFIG_DEBUG_GRAPHICS is not set +# CONFIG_DEBUG_LIB is not set +# CONFIG_DEBUG_MM is not set +# CONFIG_DEBUG_SCHED is not set + +# +# OS Function Debug Options +# +# CONFIG_DEBUG_DMA is not set +# CONFIG_DEBUG_IRQ is not set + +# +# Driver Debug Options +# +# CONFIG_DEBUG_LEDS is not set +# CONFIG_DEBUG_ANALOG is not set +# CONFIG_DEBUG_GPIO is not set +# CONFIG_DEBUG_I2C is not set +# CONFIG_DEBUG_RTC is not set +# CONFIG_DEBUG_SPI is not set +# CONFIG_DEBUG_TIMER is not set +CONFIG_ARCH_HAVE_STACKCHECK=y +CONFIG_STACK_COLORATION=y +CONFIG_ARCH_HAVE_HEAPCHECK=y +# CONFIG_HEAP_COLORATION is not set +CONFIG_DEBUG_SYMBOLS=y +CONFIG_ARCH_HAVE_CUSTOMOPT=y +CONFIG_DEBUG_NOOPT=y +# CONFIG_DEBUG_CUSTOMOPT is not set +# CONFIG_DEBUG_FULLOPT is not set + +# +# System Type +# +CONFIG_ARCH_ARM=y +# CONFIG_ARCH_AVR is not set +# CONFIG_ARCH_HC is not set +# CONFIG_ARCH_MIPS is not set +# CONFIG_ARCH_MISOC is not set +# CONFIG_ARCH_RENESAS is not set +# CONFIG_ARCH_RISCV is not set +# CONFIG_ARCH_SIM is not set +# CONFIG_ARCH_X86 is not set +# CONFIG_ARCH_XTENSA is not set +# CONFIG_ARCH_Z16 is not set +# CONFIG_ARCH_Z80 is not set +CONFIG_ARCH="arm" + +# +# ARM Options +# +# CONFIG_ARCH_CHIP_A1X is not set +# CONFIG_ARCH_CHIP_C5471 is not set +# CONFIG_ARCH_CHIP_DM320 is not set +# CONFIG_ARCH_CHIP_EFM32 is not set +# CONFIG_ARCH_CHIP_IMX1 is not set +# CONFIG_ARCH_CHIP_IMX6 is not set +# CONFIG_ARCH_CHIP_KINETIS is not set +# CONFIG_ARCH_CHIP_KL is not set +# CONFIG_ARCH_CHIP_LM is not set +# CONFIG_ARCH_CHIP_TIVA is not set +# CONFIG_ARCH_CHIP_LPC11XX is not set +# CONFIG_ARCH_CHIP_LPC17XX is not set +# CONFIG_ARCH_CHIP_LPC214X is not set +# CONFIG_ARCH_CHIP_LPC2378 is not set +# CONFIG_ARCH_CHIP_LPC31XX is not set +# CONFIG_ARCH_CHIP_LPC43XX is not set +# CONFIG_ARCH_CHIP_MOXART is not set +# CONFIG_ARCH_CHIP_NUC1XX is not set +# CONFIG_ARCH_CHIP_SAMA5 is not set +# CONFIG_ARCH_CHIP_SAMD is not set +# CONFIG_ARCH_CHIP_SAML is not set +# CONFIG_ARCH_CHIP_SAM34 is not set +# CONFIG_ARCH_CHIP_SAMV7 is not set +# CONFIG_ARCH_CHIP_STM32 is not set +# CONFIG_ARCH_CHIP_STM32F0 is not set +# CONFIG_ARCH_CHIP_STM32F7 is not set +CONFIG_ARCH_CHIP_STM32L4=y +# CONFIG_ARCH_CHIP_STR71X is not set +# CONFIG_ARCH_CHIP_TMS570 is not set +# CONFIG_ARCH_CHIP_XMC4 is not set +# CONFIG_ARCH_ARM7TDMI is not set +# CONFIG_ARCH_ARM926EJS is not set +# CONFIG_ARCH_ARM920T is not set +# CONFIG_ARCH_CORTEXM0 is not set +# CONFIG_ARCH_CORTEXM23 is not set +# CONFIG_ARCH_CORTEXM3 is not set +# CONFIG_ARCH_CORTEXM33 is not set +CONFIG_ARCH_CORTEXM4=y +# CONFIG_ARCH_CORTEXM7 is not set +# CONFIG_ARCH_CORTEXA5 is not set +# CONFIG_ARCH_CORTEXA8 is not set +# CONFIG_ARCH_CORTEXA9 is not set +# CONFIG_ARCH_CORTEXR4 is not set +# CONFIG_ARCH_CORTEXR4F is not set +# CONFIG_ARCH_CORTEXR5 is not set +# CONFIG_ARCH_CORTEX5F is not set +# CONFIG_ARCH_CORTEXR7 is not set +# CONFIG_ARCH_CORTEXR7F is not set +CONFIG_ARCH_FAMILY="armv7-m" +CONFIG_ARCH_CHIP="stm32l4" +# CONFIG_ARM_TOOLCHAIN_IAR is not set +CONFIG_ARM_TOOLCHAIN_GNU=y +# CONFIG_ARMV7M_USEBASEPRI is not set +CONFIG_ARCH_HAVE_CMNVECTOR=y +CONFIG_ARMV7M_CMNVECTOR=y +# CONFIG_ARMV7M_LAZYFPU is not set +CONFIG_ARCH_HAVE_FPU=y +# CONFIG_ARCH_HAVE_DPFPU is not set +# CONFIG_ARCH_FPU is not set +# CONFIG_ARCH_HAVE_TRUSTZONE is not set +CONFIG_ARM_HAVE_MPU_UNIFIED=y +# CONFIG_ARM_MPU is not set +# CONFIG_DEBUG_HARDFAULT is not set + +# +# ARMV7M Configuration Options +# +# CONFIG_ARMV7M_HAVE_ICACHE is not set +# CONFIG_ARMV7M_HAVE_DCACHE is not set +# CONFIG_ARMV7M_HAVE_ITCM is not set +# CONFIG_ARMV7M_HAVE_DTCM is not set +# CONFIG_ARMV7M_TOOLCHAIN_IARL is not set +# CONFIG_ARMV7M_TOOLCHAIN_BUILDROOT is not set +# CONFIG_ARMV7M_TOOLCHAIN_CODEREDL is not set +# CONFIG_ARMV7M_TOOLCHAIN_CODESOURCERYL is not set +CONFIG_ARMV7M_TOOLCHAIN_GNU_EABIL=y +CONFIG_ARMV7M_HAVE_STACKCHECK=y +CONFIG_ARMV7M_STACKCHECK=y +# CONFIG_ARMV7M_ITMSYSLOG is not set +CONFIG_SERIAL_TERMIOS=y +# CONFIG_USART2_RS485 is not set +# CONFIG_USART2_RXDMA is not set +# CONFIG_SERIAL_DISABLE_REORDERING is not set + +# +# STM32L4 Configuration Options +# +# CONFIG_ARCH_CHIP_STM32L432KB is not set +# CONFIG_ARCH_CHIP_STM32L432KC is not set +# CONFIG_ARCH_CHIP_STM32L442KC is not set +# CONFIG_ARCH_CHIP_STM32L451CC is not set +# CONFIG_ARCH_CHIP_STM32L451CE is not set +# CONFIG_ARCH_CHIP_STM32L451RC is not set +# CONFIG_ARCH_CHIP_STM32L451RE is not set +# CONFIG_ARCH_CHIP_STM32L451VC is not set +# CONFIG_ARCH_CHIP_STM32L451VE is not set +# CONFIG_ARCH_CHIP_STM32L452CC is not set +# CONFIG_ARCH_CHIP_STM32L452CE is not set +# CONFIG_ARCH_CHIP_STM32L452RC is not set +CONFIG_ARCH_CHIP_STM32L452RE=y +# CONFIG_ARCH_CHIP_STM32L452VC is not set +# CONFIG_ARCH_CHIP_STM32L452VE is not set +# CONFIG_ARCH_CHIP_STM32L462CE is not set +# CONFIG_ARCH_CHIP_STM32L462RE is not set +# CONFIG_ARCH_CHIP_STM32L462VE is not set +# CONFIG_ARCH_CHIP_STM32L476RG is not set +# CONFIG_ARCH_CHIP_STM32L476RE is not set +# CONFIG_ARCH_CHIP_STM32L486 is not set +# CONFIG_ARCH_CHIP_STM32L496ZE is not set +# CONFIG_ARCH_CHIP_STM32L496ZG is not set +# CONFIG_ARCH_CHIP_STM32L4A6 is not set +# CONFIG_STM32L4_STM32L4X1 is not set +CONFIG_STM32L4_STM32L4X2=y +CONFIG_STM32L4_STM32L4X3=y +# CONFIG_STM32L4_STM32L4X5 is not set +# CONFIG_STM32L4_STM32L4X6 is not set +# CONFIG_STM32L4_STM32L431XX is not set +# CONFIG_STM32L4_STM32L432XX is not set +# CONFIG_STM32L4_STM32L433XX is not set +# CONFIG_STM32L4_STM32L442XX is not set +# CONFIG_STM32L4_STM32L443XX is not set +# CONFIG_STM32L4_STM32L451XX is not set +CONFIG_STM32L4_STM32L452XX=y +# CONFIG_STM32L4_STM32L462XX is not set +# CONFIG_STM32L4_STM32L471XX is not set +# CONFIG_STM32L4_STM32L476XX is not set +# CONFIG_STM32L4_STM32L486XX is not set +# CONFIG_STM32L4_STM32L496XX is not set +# CONFIG_STM32L4_STM32L4A6XX is not set +CONFIG_STM32L4_FLASH_OVERRIDE_DEFAULT=y +# CONFIG_STM32L4_FLASH_OVERRIDE_B is not set +# CONFIG_STM32L4_FLASH_OVERRIDE_C is not set +# CONFIG_STM32L4_FLASH_OVERRIDE_E is not set +# CONFIG_STM32L4_FLASH_OVERRIDE_G is not set +# CONFIG_STM32L4_FLASH_CONFIG_B is not set +# CONFIG_STM32L4_FLASH_CONFIG_C is not set +CONFIG_STM32L4_FLASH_CONFIG_E=y +# CONFIG_STM32L4_IO_CONFIG_K is not set +# CONFIG_STM32L4_IO_CONFIG_C is not set +CONFIG_STM32L4_IO_CONFIG_R=y +# CONFIG_STM32L4_IO_CONFIG_J is not set +# CONFIG_STM32L4_IO_CONFIG_M is not set +# CONFIG_STM32L4_IO_CONFIG_V is not set +# CONFIG_STM32L4_IO_CONFIG_Q is not set +# CONFIG_STM32L4_IO_CONFIG_Z is not set +# CONFIG_STM32L4_IO_CONFIG_A is not set + +# +# STM32L4 SRAM2 Options +# +CONFIG_STM32L4_SRAM2_HEAP=y +CONFIG_STM32L4_SRAM2_INIT=y + +# +# STM32L4 Peripherals +# + +# +# STM32L4 Peripheral Support +# +# CONFIG_STM32L4_HAVE_ADC2 is not set +# CONFIG_STM32L4_HAVE_ADC3 is not set +# CONFIG_STM32L4_HAVE_AES is not set +# CONFIG_STM32L4_HAVE_CAN2 is not set +CONFIG_STM32L4_HAVE_COMP=y +# CONFIG_STM32L4_HAVE_DAC2 is not set +# CONFIG_STM32L4_HAVE_DCMI is not set +CONFIG_STM32L4_HAVE_DFSDM1=y +# CONFIG_STM32L4_HAVE_DMA2D is not set +# CONFIG_STM32L4_HAVE_FSMC is not set +# CONFIG_STM32L4_HAVE_HASH is not set +CONFIG_STM32L4_HAVE_I2C4=y +# CONFIG_STM32L4_HAVE_LCD is not set +# CONFIG_STM32L4_HAVE_LTDC is not set +CONFIG_STM32L4_HAVE_LPTIM1=y +CONFIG_STM32L4_HAVE_LPTIM2=y +# CONFIG_STM32L4_HAVE_OTGFS is not set +CONFIG_STM32L4_HAVE_SAI1=y +# CONFIG_STM32L4_HAVE_SAI2 is not set +CONFIG_STM32L4_HAVE_SDMMC1=y +CONFIG_STM32L4_HAVE_TIM3=y +# CONFIG_STM32L4_HAVE_TIM4 is not set +# CONFIG_STM32L4_HAVE_TIM5 is not set +# CONFIG_STM32L4_HAVE_TIM7 is not set +# CONFIG_STM32L4_HAVE_TIM8 is not set +# CONFIG_STM32L4_HAVE_TIM17 is not set +# CONFIG_STM32L4_ADC is not set +# CONFIG_STM32L4_CAN is not set +# CONFIG_STM32L4_DAC is not set +CONFIG_STM32L4_DMA=y +CONFIG_STM32L4_I2C=y +# CONFIG_STM32L4_SAI is not set +CONFIG_STM32L4_SPI=y +CONFIG_STM32L4_USART=y +# CONFIG_STM32L4_LPTIM is not set + +# +# AHB1 Peripherals +# +CONFIG_STM32L4_DMA1=y +CONFIG_STM32L4_DMA2=y +# CONFIG_STM32L4_CRC is not set +# CONFIG_STM32L4_TSC is not set + +# +# AHB2 Peripherals +# +# CONFIG_STM32L4_ADC1 is not set +CONFIG_STM32L4_RNG=y + +# +# AHB3 Peripherals +# +# CONFIG_STM32L4_QSPI is not set + +# +# APB1 Peripherals +# +CONFIG_STM32L4_PWR=y +# CONFIG_STM32L4_TIM2 is not set +# CONFIG_STM32L4_TIM3 is not set +# CONFIG_STM32L4_TIM6 is not set +# CONFIG_STM32L4_SPI2 is not set +# CONFIG_STM32L4_SPI3 is not set +# CONFIG_STM32L4_USART1 is not set +CONFIG_STM32L4_USART2=y +# CONFIG_STM32L4_USART3 is not set +# CONFIG_STM32L4_UART4 is not set +CONFIG_STM32L4_I2C1=y +# CONFIG_STM32L4_I2C2 is not set +# CONFIG_STM32L4_I2C3 is not set +# CONFIG_STM32L4_I2C4 is not set +# CONFIG_STM32L4_CAN1 is not set +# CONFIG_STM32L4_DAC1 is not set +# CONFIG_STM32L4_OPAMP is not set +# CONFIG_STM32L4_LPTIM1 is not set +# CONFIG_STM32L4_LPUART1 is not set +# CONFIG_STM32L4_SWPMI is not set +# CONFIG_STM32L4_LPTIM2 is not set + +# +# APB2 Peripherals +# +CONFIG_STM32L4_SYSCFG=y +CONFIG_STM32L4_FIREWALL=y +# CONFIG_STM32L4_SDMMC1 is not set +# CONFIG_STM32L4_TIM1 is not set +CONFIG_STM32L4_SPI1=y +# CONFIG_STM32L4_TIM15 is not set +# CONFIG_STM32L4_TIM16 is not set +# CONFIG_STM32L4_COMP is not set +# CONFIG_STM32L4_SAI1 is not set +# CONFIG_STM32L4_DFSDM1 is not set + +# +# Other Peripherals +# +# CONFIG_STM32L4_BKPSRAM is not set +# CONFIG_STM32L4_IWDG is not set +# CONFIG_STM32L4_WWDG is not set +CONFIG_STM32L4_FLASH_PREFETCH=y +CONFIG_STM32L4_DISABLE_IDLE_SLEEP_DURING_DEBUG=y +# CONFIG_ARCH_BOARD_STM32L4_CUSTOM_CLOCKCONFIG is not set +CONFIG_STM32L4_RTC_LSECLOCK=y +# CONFIG_STM32L4_RTC_LSICLOCK is not set +# CONFIG_STM32L4_RTC_HSECLOCK is not set +CONFIG_STM32L4_SAI1PLL=y + +# +# Timer Configuration +# +# CONFIG_STM32L4_ONESHOT is not set +# CONFIG_STM32L4_FREERUN is not set +# CONFIG_STM32L4_TIM3_CAP is not set +CONFIG_STM32L4_HAVE_USART1=y +CONFIG_STM32L4_HAVE_USART2=y +CONFIG_STM32L4_HAVE_USART3=y +CONFIG_STM32L4_HAVE_UART4=y +# CONFIG_STM32L4_HAVE_UART5 is not set + +# +# U[S]ART Configuration +# +# CONFIG_STM32L4_FLOWCONTROL_BROKEN is not set +# CONFIG_STM32L4_USART_BREAKS is not set + +# +# SPI Configuration +# +# CONFIG_STM32L4_SPI_INTERRUPTS is not set +# CONFIG_STM32L4_SPI_DMA is not set + +# +# I2C Configuration +# +# CONFIG_STM32L4_I2C_DYNTIMEO is not set +CONFIG_STM32L4_I2CTIMEOSEC=0 +CONFIG_STM32L4_I2CTIMEOMS=500 +CONFIG_STM32L4_I2CTIMEOTICKS=500 +# CONFIG_STM32L4_I2C_DUTY16_9 is not set + +# +# Architecture Options +# +# CONFIG_ARCH_NOINTC is not set +# CONFIG_ARCH_VECNOTIRQ is not set +CONFIG_ARCH_DMA=y +CONFIG_ARCH_HAVE_IRQPRIO=y +# CONFIG_ARCH_L2CACHE is not set +# CONFIG_ARCH_HAVE_COHERENT_DCACHE is not set +# CONFIG_ARCH_HAVE_ADDRENV is not set +# CONFIG_ARCH_NEED_ADDRENV_MAPPING is not set +# CONFIG_ARCH_HAVE_MULTICPU is not set +CONFIG_ARCH_HAVE_VFORK=y +# CONFIG_ARCH_HAVE_MMU is not set +CONFIG_ARCH_HAVE_MPU=y +# CONFIG_ARCH_NAND_HWECC is not set +# CONFIG_ARCH_HAVE_EXTCLK is not set +# CONFIG_ARCH_HAVE_POWEROFF is not set +CONFIG_ARCH_HAVE_RESET=y +# CONFIG_ARCH_HAVE_RTC_SUBSECONDS is not set +# CONFIG_ARCH_USE_MPU is not set +# CONFIG_ARCH_IRQPRIO is not set +CONFIG_ARCH_STACKDUMP=y +# CONFIG_ENDIAN_BIG is not set +# CONFIG_ARCH_IDLE_CUSTOM is not set +# CONFIG_ARCH_HAVE_RAMFUNCS is not set +CONFIG_ARCH_HAVE_RAMVECTORS=y +# CONFIG_ARCH_RAMVECTORS is not set +# CONFIG_ARCH_MINIMAL_VECTORTABLE is not set + +# +# Board Settings +# +CONFIG_BOARD_LOOPSPERMSEC=8499 +# CONFIG_ARCH_CALIBRATION is not set + +# +# Interrupt options +# +CONFIG_ARCH_HAVE_INTERRUPTSTACK=y +CONFIG_ARCH_INTERRUPTSTACK=2048 +CONFIG_ARCH_HAVE_HIPRI_INTERRUPT=y +# CONFIG_ARCH_HIPRI_INTERRUPT is not set + +# +# Boot options +# +# CONFIG_BOOT_RUNFROMEXTSRAM is not set +CONFIG_BOOT_RUNFROMFLASH=y +# CONFIG_BOOT_RUNFROMISRAM is not set +# CONFIG_BOOT_RUNFROMSDRAM is not set +# CONFIG_BOOT_COPYTORAM is not set + +# +# Boot Memory Configuration +# +CONFIG_RAM_START=0x20000000 +CONFIG_RAM_SIZE=131072 +# CONFIG_ARCH_HAVE_SDRAM is not set + +# +# Board Selection +# +CONFIG_ARCH_BOARD_NUCLEO_L452RE=y +# CONFIG_ARCH_BOARD_CUSTOM is not set +CONFIG_ARCH_BOARD="nucleo-l452re" + +# +# Common Board Options +# +CONFIG_ARCH_HAVE_LEDS=y +CONFIG_ARCH_LEDS=y +CONFIG_ARCH_HAVE_BUTTONS=y +CONFIG_ARCH_BUTTONS=y +CONFIG_ARCH_HAVE_IRQBUTTONS=y +CONFIG_ARCH_IRQBUTTONS=y + +# +# Board-Specific Options +# +# CONFIG_BOARD_CRASHDUMP is not set +CONFIG_LIB_BOARDCTL=y +# CONFIG_BOARDCTL_RESET is not set +# CONFIG_BOARDCTL_UNIQUEID is not set +# CONFIG_BOARDCTL_TSCTEST is not set +# CONFIG_BOARDCTL_GRAPHICS is not set +# CONFIG_BOARDCTL_IOCTL is not set + +# +# RTOS Features +# +CONFIG_DISABLE_OS_API=y +# CONFIG_DISABLE_POSIX_TIMERS is not set +# CONFIG_DISABLE_PTHREAD is not set +# CONFIG_DISABLE_SIGNALS is not set +# CONFIG_DISABLE_MQUEUE is not set +# CONFIG_DISABLE_ENVIRON is not set + +# +# Clocks and Timers +# +CONFIG_ARCH_HAVE_TICKLESS=y +# CONFIG_SCHED_TICKLESS is not set +CONFIG_USEC_PER_TICK=10000 +# CONFIG_SYSTEM_TIME64 is not set +# CONFIG_CLOCK_MONOTONIC is not set +# CONFIG_ARCH_HAVE_TIMEKEEPING is not set +# CONFIG_JULIAN_TIME is not set +CONFIG_START_YEAR=2017 +CONFIG_START_MONTH=1 +CONFIG_START_DAY=1 +CONFIG_MAX_WDOGPARMS=2 +CONFIG_PREALLOC_WDOGS=8 +CONFIG_WDOG_INTRESERVE=1 +CONFIG_PREALLOC_TIMERS=4 + +# +# Tasks and Scheduling +# +# CONFIG_SPINLOCK is not set +# CONFIG_INIT_NONE is not set +CONFIG_INIT_ENTRYPOINT=y +# CONFIG_INIT_FILEPATH is not set +CONFIG_USER_ENTRYPOINT="nsh_main" +CONFIG_RR_INTERVAL=200 +# CONFIG_SCHED_SPORADIC is not set +CONFIG_TASK_NAME_SIZE=0 +CONFIG_MAX_TASKS=16 +# CONFIG_SCHED_HAVE_PARENT is not set +CONFIG_SCHED_WAITPID=y + +# +# Pthread Options +# +# CONFIG_PTHREAD_MUTEX_TYPES is not set +CONFIG_PTHREAD_MUTEX_ROBUST=y +# CONFIG_PTHREAD_MUTEX_UNSAFE is not set +# CONFIG_PTHREAD_MUTEX_BOTH is not set +CONFIG_NPTHREAD_KEYS=4 +# CONFIG_PTHREAD_CLEANUP is not set +# CONFIG_CANCELLATION_POINTS is not set + +# +# Performance Monitoring +# +# CONFIG_SCHED_CPULOAD is not set +# CONFIG_SCHED_INSTRUMENTATION is not set + +# +# Files and I/O +# +CONFIG_DEV_CONSOLE=y +# CONFIG_FDCLONE_DISABLE is not set +# CONFIG_FDCLONE_STDIO is not set +CONFIG_SDCLONE_DISABLE=y +CONFIG_NFILE_DESCRIPTORS=8 +CONFIG_NFILE_STREAMS=8 +CONFIG_NAME_MAX=32 +# CONFIG_PRIORITY_INHERITANCE is not set + +# +# RTOS hooks +# +# CONFIG_BOARD_INITIALIZE is not set +# CONFIG_SCHED_STARTHOOK is not set +# CONFIG_SCHED_ATEXIT is not set +# CONFIG_SCHED_ONEXIT is not set + +# +# Signal Numbers +# +CONFIG_SIG_SIGUSR1=1 +CONFIG_SIG_SIGUSR2=2 +CONFIG_SIG_SIGALARM=3 +CONFIG_SIG_SIGCONDTIMEDOUT=16 + +# +# POSIX Message Queue Options +# +CONFIG_PREALLOC_MQ_MSGS=4 +CONFIG_MQ_MAXMSGSIZE=32 +# CONFIG_MODULE is not set + +# +# Work queue support +# +# CONFIG_SCHED_WORKQUEUE is not set +# CONFIG_SCHED_HPWORK is not set +# CONFIG_SCHED_LPWORK is not set + +# +# Stack and heap information +# +CONFIG_IDLETHREAD_STACKSIZE=1024 +CONFIG_USERMAIN_STACKSIZE=2048 +CONFIG_PTHREAD_STACK_MIN=256 +CONFIG_PTHREAD_STACK_DEFAULT=2048 +# CONFIG_LIB_SYSCALL is not set + +# +# Device Drivers +# +CONFIG_DISABLE_POLL=y +CONFIG_DEV_NULL=y +# CONFIG_DEV_ZERO is not set +CONFIG_ARCH_HAVE_RNG=y +CONFIG_DEV_RANDOM=y +# CONFIG_DEV_URANDOM is not set +# CONFIG_DEV_LOOP is not set + +# +# Buffering +# + +# +# Common I/O Buffer Support +# +# CONFIG_DRIVERS_IOB is not set +# CONFIG_DRVR_WRITEBUFFER is not set +# CONFIG_DRVR_READAHEAD is not set +# CONFIG_RAMDISK is not set +# CONFIG_CAN is not set +# CONFIG_ARCH_HAVE_PWM_PULSECOUNT is not set +# CONFIG_ARCH_HAVE_PWM_MULTICHAN is not set +# CONFIG_PWM is not set +CONFIG_ARCH_HAVE_I2CRESET=y +CONFIG_I2C=y +# CONFIG_I2C_SLAVE is not set +# CONFIG_I2C_POLLED is not set +CONFIG_I2C_RESET=y +# CONFIG_I2C_TRACE is not set +CONFIG_I2C_DRIVER=y +# CONFIG_ARCH_HAVE_SPI_CRCGENERATION is not set +# CONFIG_ARCH_HAVE_SPI_CS_CONTROL is not set +CONFIG_ARCH_HAVE_SPI_BITORDER=y +CONFIG_SPI=y +# CONFIG_SPI_SLAVE is not set +CONFIG_SPI_EXCHANGE=y +# CONFIG_SPI_CMDDATA is not set +# CONFIG_SPI_CALLBACK is not set +# CONFIG_SPI_HWFEATURES is not set +# CONFIG_SPI_BITORDER is not set +# CONFIG_SPI_CS_DELAY_CONTROL is not set +# CONFIG_SPI_DRIVER is not set +# CONFIG_SPI_BITBANG is not set +# CONFIG_I2S is not set + +# +# Timer Driver Support +# +# CONFIG_TIMER is not set +# CONFIG_ONESHOT is not set +CONFIG_RTC=y +CONFIG_RTC_DATETIME=y +CONFIG_RTC_ALARM=y +CONFIG_RTC_NALARMS=2 +CONFIG_RTC_DRIVER=y +CONFIG_RTC_IOCTL=y +# CONFIG_RTC_EXTERNAL is not set +# CONFIG_WATCHDOG is not set +# CONFIG_TIMERS_CS2100CP is not set +CONFIG_ANALOG=y +# CONFIG_ADC is not set +# CONFIG_COMP is not set +# CONFIG_DAC is not set +# CONFIG_OPAMP is not set +# CONFIG_AUDIO_DEVICES is not set +# CONFIG_VIDEO_DEVICES is not set +# CONFIG_BCH is not set +# CONFIG_INPUT is not set + +# +# IO Expander/GPIO Support +# +# CONFIG_IOEXPANDER is not set +# CONFIG_DEV_GPIO is not set + +# +# LCD Driver Support +# +# CONFIG_LCD is not set +# CONFIG_SLCD is not set + +# +# LED Support +# +# CONFIG_USERLED is not set +# CONFIG_RGBLED is not set +# CONFIG_PCA9635PW is not set +# CONFIG_NCP5623C is not set +# CONFIG_MMCSD is not set +# CONFIG_MODEM is not set +# CONFIG_MTD is not set +# CONFIG_EEPROM is not set +# CONFIG_PIPES is not set +# CONFIG_PM is not set +# CONFIG_POWER is not set +# CONFIG_SENSORS is not set +CONFIG_SERIAL=y +# CONFIG_DEV_LOWCONSOLE is not set +# CONFIG_SERIAL_REMOVABLE is not set +CONFIG_SERIAL_CONSOLE=y +# CONFIG_16550_UART is not set +# CONFIG_UART_SERIALDRIVER is not set +# CONFIG_UART0_SERIALDRIVER is not set +# CONFIG_UART1_SERIALDRIVER is not set +# CONFIG_UART2_SERIALDRIVER is not set +# CONFIG_UART3_SERIALDRIVER is not set +# CONFIG_UART4_SERIALDRIVER is not set +# CONFIG_UART5_SERIALDRIVER is not set +# CONFIG_UART6_SERIALDRIVER is not set +# CONFIG_UART7_SERIALDRIVER is not set +# CONFIG_UART8_SERIALDRIVER is not set +# CONFIG_SCI0_SERIALDRIVER is not set +# CONFIG_SCI1_SERIALDRIVER is not set +# CONFIG_USART0_SERIALDRIVER is not set +# CONFIG_USART1_SERIALDRIVER is not set +CONFIG_USART2_SERIALDRIVER=y +# CONFIG_USART3_SERIALDRIVER is not set +# CONFIG_USART4_SERIALDRIVER is not set +# CONFIG_USART5_SERIALDRIVER is not set +# CONFIG_USART6_SERIALDRIVER is not set +# CONFIG_USART7_SERIALDRIVER is not set +# CONFIG_USART8_SERIALDRIVER is not set +# CONFIG_OTHER_UART_SERIALDRIVER is not set +CONFIG_MCU_SERIAL=y +CONFIG_STANDARD_SERIAL=y +# CONFIG_SERIAL_IFLOWCONTROL is not set +# CONFIG_SERIAL_OFLOWCONTROL is not set +# CONFIG_SERIAL_DMA is not set +# CONFIG_SERIAL_TIOCSERGSTRUCT is not set +CONFIG_ARCH_HAVE_SERIAL_TERMIOS=y +CONFIG_USART2_SERIAL_CONSOLE=y +# CONFIG_OTHER_SERIAL_CONSOLE is not set +# CONFIG_NO_SERIAL_CONSOLE is not set + +# +# USART2 Configuration +# +CONFIG_USART2_RXBUFSIZE=128 +CONFIG_USART2_TXBUFSIZE=128 +CONFIG_USART2_BAUD=115200 +CONFIG_USART2_BITS=8 +CONFIG_USART2_PARITY=0 +CONFIG_USART2_2STOP=0 +# CONFIG_USART2_IFLOWCONTROL is not set +# CONFIG_USART2_OFLOWCONTROL is not set +# CONFIG_USART2_DMA is not set +# CONFIG_PSEUDOTERM is not set +# CONFIG_USBDEV is not set +# CONFIG_USBHOST is not set +# CONFIG_USBMISC is not set +# CONFIG_HAVE_USBTRACE is not set +# CONFIG_DRIVERS_WIRELESS is not set +# CONFIG_DRIVERS_CONTACTLESS is not set + +# +# System Logging +# +# CONFIG_ARCH_SYSLOG is not set +# CONFIG_RAMLOG is not set +# CONFIG_SYSLOG_INTBUFFER is not set +# CONFIG_SYSLOG_TIMESTAMP is not set +CONFIG_SYSLOG_SERIAL_CONSOLE=y +# CONFIG_SYSLOG_CHAR is not set +CONFIG_SYSLOG_CONSOLE=y +# CONFIG_SYSLOG_NONE is not set +# CONFIG_SYSLOG_FILE is not set +# CONFIG_SYSLOG_CHARDEV is not set + +# +# Networking Support +# +# CONFIG_ARCH_HAVE_NET is not set +# CONFIG_ARCH_HAVE_PHY is not set +# CONFIG_NET is not set + +# +# Crypto API +# +# CONFIG_CRYPTO is not set + +# +# File Systems +# + +# +# File system configuration +# +# CONFIG_DISABLE_MOUNTPOINT is not set +# CONFIG_FS_AUTOMOUNTER is not set +# CONFIG_DISABLE_PSEUDOFS_OPERATIONS is not set +# CONFIG_PSEUDOFS_SOFTLINKS is not set +CONFIG_FS_READABLE=y +# CONFIG_FS_WRITABLE is not set +# CONFIG_FS_NAMED_SEMAPHORES is not set +CONFIG_FS_MQUEUE_MPATH="/var/mqueue" +# CONFIG_FS_RAMMAP is not set +# CONFIG_FS_FAT is not set +# CONFIG_FS_NXFFS is not set +# CONFIG_FS_ROMFS is not set +# CONFIG_FS_TMPFS is not set +# CONFIG_FS_SMARTFS is not set +# CONFIG_FS_BINFS is not set +CONFIG_FS_PROCFS=y +CONFIG_FS_PROCFS_REGISTER=y + +# +# Exclude individual procfs entries +# +# CONFIG_FS_PROCFS_EXCLUDE_PROCESS is not set +# CONFIG_FS_PROCFS_EXCLUDE_UPTIME is not set +# CONFIG_FS_PROCFS_EXCLUDE_MOUNTS is not set +# CONFIG_FS_UNIONFS is not set + +# +# Graphics Support +# +# CONFIG_NX is not set + +# +# Memory Management +# +# CONFIG_MM_SMALL is not set +CONFIG_MM_REGIONS=2 +# CONFIG_ARCH_HAVE_HEAP2 is not set +# CONFIG_GRAN is not set + +# +# Audio Support +# +# CONFIG_AUDIO is not set + +# +# Wireless Support +# + +# +# Binary Loader +# +# CONFIG_BINFMT_DISABLE is not set +# CONFIG_BINFMT_EXEPATH is not set +# CONFIG_NXFLAT is not set +# CONFIG_ELF is not set +CONFIG_BUILTIN=y +# CONFIG_PIC is not set +# CONFIG_SYMTAB_ORDEREDBYNAME is not set + +# +# Library Routines +# + +# +# Standard C Library Options +# + +# +# Standard C I/O +# +# CONFIG_STDIO_DISABLE_BUFFERING is not set +CONFIG_STDIO_BUFFER_SIZE=64 +CONFIG_STDIO_LINEBUFFER=y +CONFIG_NUNGET_CHARS=2 +# CONFIG_NOPRINTF_FIELDWIDTH is not set +# CONFIG_LIBC_FLOATINGPOINT is not set +CONFIG_LIBC_LONG_LONG=y +# CONFIG_LIBC_SCANSET is not set +# CONFIG_EOL_IS_CR is not set +# CONFIG_EOL_IS_LF is not set +# CONFIG_EOL_IS_BOTH_CRLF is not set +CONFIG_EOL_IS_EITHER_CRLF=y +# CONFIG_MEMCPY_VIK is not set +# CONFIG_LIBM is not set + +# +# Architecture-Specific Support +# +CONFIG_ARCH_LOWPUTC=y +# CONFIG_ARCH_ROMGETC is not set +# CONFIG_LIBC_ARCH_MEMCPY is not set +# CONFIG_LIBC_ARCH_MEMCMP is not set +# CONFIG_LIBC_ARCH_MEMMOVE is not set +# CONFIG_LIBC_ARCH_MEMSET is not set +# CONFIG_LIBC_ARCH_STRCHR is not set +# CONFIG_LIBC_ARCH_STRCMP is not set +# CONFIG_LIBC_ARCH_STRCPY is not set +# CONFIG_LIBC_ARCH_STRNCPY is not set +# CONFIG_LIBC_ARCH_STRLEN is not set +# CONFIG_LIBC_ARCH_STRNLEN is not set +# CONFIG_LIBC_ARCH_ELF is not set +# CONFIG_ARMV7M_MEMCPY is not set + +# +# stdlib Options +# +CONFIG_LIB_RAND_ORDER=1 +CONFIG_LIB_HOMEDIR="/" + +# +# Program Execution Options +# +# CONFIG_LIBC_EXECFUNCS is not set +CONFIG_POSIX_SPAWN_PROXY_STACKSIZE=1024 +CONFIG_TASK_SPAWN_DEFAULT_STACKSIZE=2048 + +# +# errno Decode Support +# +# CONFIG_LIBC_STRERROR is not set +# CONFIG_LIBC_PERROR_STDOUT is not set + +# +# memcpy/memset Options +# +# CONFIG_MEMSET_OPTSPEED is not set +# CONFIG_LIBC_DLLFCN is not set +# CONFIG_LIBC_MODLIB is not set +# CONFIG_LIBC_WCHAR is not set +# CONFIG_LIBC_LOCALE is not set + +# +# Time/Time Zone Support +# +# CONFIG_LIBC_LOCALTIME is not set +# CONFIG_TIME_EXTENDED is not set +CONFIG_ARCH_HAVE_TLS=y + +# +# Thread Local Storage (TLS) +# +# CONFIG_TLS is not set + +# +# Network-Related Options +# +# CONFIG_LIBC_IPv4_ADDRCONV is not set +# CONFIG_LIBC_IPv6_ADDRCONV is not set +# CONFIG_LIBC_NETDB is not set + +# +# NETDB Support +# +# CONFIG_NETDB_HOSTFILE is not set +# CONFIG_LIBC_IOCTL_VARIADIC is not set +CONFIG_LIB_SENDFILE_BUFSIZE=512 + +# +# Non-standard Library Support +# +# CONFIG_LIB_CRC64_FAST is not set +# CONFIG_LIB_KBDCODEC is not set +# CONFIG_LIB_SLCDCODEC is not set +# CONFIG_LIB_HEX2BIN is not set + +# +# Basic CXX Support +# +# CONFIG_C99_BOOL8 is not set +CONFIG_HAVE_CXX=y +CONFIG_HAVE_CXXINITIALIZE=y +# CONFIG_CXX_NEWLONG is not set + +# +# LLVM C++ Library (libcxx) +# +# CONFIG_LIBCXX is not set + +# +# uClibc++ Standard C++ Library +# +# CONFIG_UCLIBCXX is not set + +# +# Application Configuration +# + +# +# Built-In Applications +# +CONFIG_BUILTIN_PROXY_STACKSIZE=1024 + +# +# CAN Utilities +# + +# +# Examples +# +CONFIG_EXAMPLES_ALARM=y +CONFIG_EXAMPLES_ALARM_PRIORITY=100 +CONFIG_EXAMPLES_ALARM_STACKSIZE=2048 +CONFIG_EXAMPLES_ALARM_DEVPATH="/dev/rtc0" +CONFIG_EXAMPLES_ALARM_SIGNO=1 +# CONFIG_EXAMPLES_BUTTONS is not set +# CONFIG_EXAMPLES_CCTYPE is not set +# CONFIG_EXAMPLES_CHAT is not set +# CONFIG_EXAMPLES_CONFIGDATA is not set +# CONFIG_EXAMPLES_CXXTEST is not set +# CONFIG_EXAMPLES_DHCPD is not set +# CONFIG_EXAMPLES_ELF is not set +# CONFIG_EXAMPLES_FTPC is not set +# CONFIG_EXAMPLES_FTPD is not set +# CONFIG_EXAMPLES_HELLO is not set +# CONFIG_EXAMPLES_HELLOXX is not set +# CONFIG_EXAMPLES_HIDKBD is not set +# CONFIG_EXAMPLES_IGMP is not set +# CONFIG_EXAMPLES_JSON is not set +# CONFIG_EXAMPLES_KEYPADTEST is not set +# CONFIG_EXAMPLES_MEDIA is not set +# CONFIG_EXAMPLES_MM is not set +# CONFIG_EXAMPLES_MODBUS is not set +# CONFIG_EXAMPLES_MOUNT is not set +CONFIG_EXAMPLES_NSH=y +CONFIG_EXAMPLES_NSH_CXXINITIALIZE=y +# CONFIG_EXAMPLES_NULL is not set +# CONFIG_EXAMPLES_NXFFS is not set +# CONFIG_EXAMPLES_NXHELLO is not set +# CONFIG_EXAMPLES_NXIMAGE is not set +# CONFIG_EXAMPLES_NX is not set +# CONFIG_EXAMPLES_NXLINES is not set +# CONFIG_EXAMPLES_NXTERM is not set +# CONFIG_EXAMPLES_NXTEXT is not set +CONFIG_EXAMPLES_OSTEST=y +CONFIG_EXAMPLES_OSTEST_LOOPS=1 +CONFIG_EXAMPLES_OSTEST_STACKSIZE=8192 +CONFIG_EXAMPLES_OSTEST_NBARRIER_THREADS=8 +CONFIG_EXAMPLES_OSTEST_RR_RANGE=10000 +CONFIG_EXAMPLES_OSTEST_RR_RUNS=10 +CONFIG_EXAMPLES_OSTEST_WAITRESULT=y +# CONFIG_EXAMPLES_PCA9635 is not set +# CONFIG_EXAMPLES_POSIXSPAWN is not set +# CONFIG_EXAMPLES_PPPD is not set +CONFIG_EXAMPLES_RANDOM=y +CONFIG_EXAMPLES_MAXSAMPLES=64 +CONFIG_EXAMPLES_NSAMPLES=8 +# CONFIG_EXAMPLES_RFID_READUID is not set +# CONFIG_EXAMPLES_RGBLED is not set +# CONFIG_EXAMPLES_SENDMAIL is not set +# CONFIG_EXAMPLES_SERIALBLASTER is not set +# CONFIG_EXAMPLES_SERIALRX is not set +# CONFIG_EXAMPLES_SERLOOP is not set +# CONFIG_EXAMPLES_SLCD is not set +# CONFIG_EXAMPLES_SMART is not set +# CONFIG_EXAMPLES_SMART_TEST is not set +# CONFIG_EXAMPLES_SMP is not set +# CONFIG_EXAMPLES_STAT is not set +# CONFIG_EXAMPLES_TCPECHO is not set +# CONFIG_EXAMPLES_TELNETD is not set +# CONFIG_EXAMPLES_TIFF is not set +# CONFIG_EXAMPLES_TOUCHSCREEN is not set +# CONFIG_EXAMPLES_USBSERIAL is not set +# CONFIG_EXAMPLES_WATCHDOG is not set +# CONFIG_EXAMPLES_WEBSERVER is not set +# CONFIG_EXAMPLES_XBC_TEST is not set + +# +# File System Utilities +# +# CONFIG_FSUTILS_INIFILE is not set +# CONFIG_FSUTILS_PASSWD is not set + +# +# GPS Utilities +# +# CONFIG_GPSUTILS_MINMEA_LIB is not set + +# +# Graphics Support +# +# CONFIG_TIFF is not set +# CONFIG_GRAPHICS_TRAVELER is not set + +# +# Interpreters +# +# CONFIG_INTERPRETERS_BAS is not set +# CONFIG_INTERPRETERS_FICL is not set +# CONFIG_INTERPRETERS_MICROPYTHON is not set +# CONFIG_INTERPRETERS_MINIBASIC is not set +# CONFIG_INTERPRETERS_PCODE is not set + +# +# FreeModBus +# +# CONFIG_MODBUS is not set + +# +# Network Utilities +# +# CONFIG_NETUTILS_CODECS is not set +# CONFIG_NETUTILS_ESP8266 is not set +# CONFIG_NETUTILS_FTPC is not set +# CONFIG_NETUTILS_JSON is not set +# CONFIG_NETUTILS_SMTP is not set + +# +# NSH Library +# +CONFIG_NSH_LIBRARY=y +# CONFIG_NSH_MOTD is not set + +# +# Command Line Configuration +# +CONFIG_NSH_READLINE=y +# CONFIG_NSH_CLE is not set +CONFIG_NSH_LINELEN=64 +# CONFIG_NSH_DISABLE_SEMICOLON is not set +# CONFIG_NSH_CMDPARMS is not set +CONFIG_NSH_MAXARGUMENTS=6 +# CONFIG_NSH_ARGCAT is not set +CONFIG_NSH_NESTDEPTH=3 +# CONFIG_NSH_DISABLEBG is not set +CONFIG_NSH_BUILTIN_APPS=y + +# +# Disable Individual commands +# +# CONFIG_NSH_DISABLE_ADDROUTE is not set +# CONFIG_NSH_DISABLE_BASENAME is not set +# CONFIG_NSH_DISABLE_CAT is not set +# CONFIG_NSH_DISABLE_CD is not set +# CONFIG_NSH_DISABLE_CP is not set +# CONFIG_NSH_DISABLE_CMP is not set +# CONFIG_NSH_DISABLE_DATE is not set +# CONFIG_NSH_DISABLE_DD is not set +# CONFIG_NSH_DISABLE_DF is not set +# CONFIG_NSH_DISABLE_DELROUTE is not set +# CONFIG_NSH_DISABLE_DIRNAME is not set +# CONFIG_NSH_DISABLE_ECHO is not set +# CONFIG_NSH_DISABLE_EXEC is not set +# CONFIG_NSH_DISABLE_EXIT is not set +# CONFIG_NSH_DISABLE_FREE is not set +# CONFIG_NSH_DISABLE_GET is not set +# CONFIG_NSH_DISABLE_HELP is not set +# CONFIG_NSH_DISABLE_HEXDUMP is not set +# CONFIG_NSH_DISABLE_IFCONFIG is not set +CONFIG_NSH_DISABLE_IFUPDOWN=y +# CONFIG_NSH_DISABLE_KILL is not set +# CONFIG_NSH_DISABLE_LOSETUP is not set +CONFIG_NSH_DISABLE_LOSMART=y +# CONFIG_NSH_DISABLE_LS is not set +# CONFIG_NSH_DISABLE_MB is not set +# CONFIG_NSH_DISABLE_MKDIR is not set +# CONFIG_NSH_DISABLE_MKRD is not set +# CONFIG_NSH_DISABLE_MH is not set +# CONFIG_NSH_DISABLE_MOUNT is not set +# CONFIG_NSH_DISABLE_MV is not set +# CONFIG_NSH_DISABLE_MW is not set +CONFIG_NSH_DISABLE_PRINTF=y +# CONFIG_NSH_DISABLE_PS is not set +# CONFIG_NSH_DISABLE_PSSTACKUSAGE is not set +# CONFIG_NSH_DISABLE_PUT is not set +# CONFIG_NSH_DISABLE_PWD is not set +# CONFIG_NSH_DISABLE_RM is not set +# CONFIG_NSH_DISABLE_RMDIR is not set +# CONFIG_NSH_DISABLE_SET is not set +# CONFIG_NSH_DISABLE_SH is not set +# CONFIG_NSH_DISABLE_SLEEP is not set +# CONFIG_NSH_DISABLE_TIME is not set +# CONFIG_NSH_DISABLE_TEST is not set +# CONFIG_NSH_DISABLE_UMOUNT is not set +# CONFIG_NSH_DISABLE_UNAME is not set +# CONFIG_NSH_DISABLE_UNSET is not set +# CONFIG_NSH_DISABLE_USLEEP is not set +# CONFIG_NSH_DISABLE_WGET is not set +# CONFIG_NSH_DISABLE_XD is not set +CONFIG_NSH_MMCSDMINOR=0 + +# +# Configure Command Options +# +# CONFIG_NSH_CMDOPT_DF_H is not set +# CONFIG_NSH_CMDOPT_DD_STATS is not set +CONFIG_NSH_CODECS_BUFSIZE=128 +CONFIG_NSH_CMDOPT_HEXDUMP=y +CONFIG_NSH_PROC_MOUNTPOINT="/proc" +CONFIG_NSH_FILEIOSIZE=512 + +# +# Scripting Support +# +# CONFIG_NSH_DISABLESCRIPT is not set +# CONFIG_NSH_DISABLE_ITEF is not set +# CONFIG_NSH_DISABLE_LOOPS is not set + +# +# Console Configuration +# +CONFIG_NSH_CONSOLE=y +# CONFIG_NSH_ALTCONDEV is not set +CONFIG_NSH_ARCHINIT=y +# CONFIG_NSH_LOGIN is not set +# CONFIG_NSH_CONSOLE_LOGIN is not set + +# +# NxWidgets/NxWM +# + +# +# Platform-specific Support +# +# CONFIG_PLATFORM_CONFIGDATA is not set + +# +# System Libraries and NSH Add-Ons +# +# CONFIG_SYSTEM_CLE is not set +# CONFIG_SYSTEM_CUTERM is not set +# CONFIG_SYSTEM_FREE is not set +# CONFIG_SYSTEM_HEX2BIN is not set +# CONFIG_SYSTEM_HEXED is not set +CONFIG_SYSTEM_I2CTOOL=y +CONFIG_I2CTOOL_MINBUS=0 +CONFIG_I2CTOOL_MAXBUS=3 +CONFIG_I2CTOOL_MINADDR=0x03 +CONFIG_I2CTOOL_MAXADDR=0x77 +CONFIG_I2CTOOL_MAXREGADDR=0xff +CONFIG_I2CTOOL_DEFFREQ=400000 +# CONFIG_SYSTEM_INSTALL is not set +# CONFIG_SYSTEM_RAMTEST is not set +CONFIG_READLINE_HAVE_EXTMATCH=y +CONFIG_SYSTEM_READLINE=y +CONFIG_READLINE_ECHO=y +CONFIG_READLINE_TABCOMPLETION=y +CONFIG_READLINE_MAX_BUILTINS=64 +CONFIG_READLINE_MAX_EXTCMDS=64 +CONFIG_READLINE_CMD_HISTORY=y +CONFIG_READLINE_CMD_HISTORY_LINELEN=80 +CONFIG_READLINE_CMD_HISTORY_LEN=16 +CONFIG_SYSTEM_STACKMONITOR=y +CONFIG_SYSTEM_STACKMONITOR_STACKSIZE=2048 +CONFIG_SYSTEM_STACKMONITOR_PRIORITY=50 +CONFIG_SYSTEM_STACKMONITOR_INTERVAL=2 +# CONFIG_SYSTEM_SUDOKU is not set +# CONFIG_SYSTEM_SYSTEM is not set +CONFIG_SYSTEM_TEE=y +CONFIG_SYSTEM_TEE_STACKSIZE=1536 +CONFIG_SYSTEM_TEE_PRIORITY=100 +# CONFIG_SYSTEM_UBLOXMODEM is not set +# CONFIG_SYSTEM_VI is not set +# CONFIG_SYSTEM_ZMODEM is not set + +# +# Wireless Libraries and NSH Add-Ons +# diff --git a/configs/nucleo-l452re/scripts/l452re-flash.ld b/configs/nucleo-l452re/scripts/l452re-flash.ld new file mode 100644 index 00000000000..362a34d600c --- /dev/null +++ b/configs/nucleo-l452re/scripts/l452re-flash.ld @@ -0,0 +1,119 @@ +/**************************************************************************** + * configs/nucleo-l452re/scripts/l452re-flash.ld + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * Sebastien Lorquet + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/* The STM32L452RE has 512Kb of FLASH beginning at address 0x0800:0000 and + * 160Kb of SRAM beginning at address 0x2000:0000. When booting from FLASH, + * FLASH memory is aliased to address 0x0000:0000 where the code expects to + * begin execution by jumping to the entry point in the 0x0800:0000 address + * range. + */ + +MEMORY +{ + flash (rx) : ORIGIN = 0x08000000, LENGTH = 512K + sram (rwx) : ORIGIN = 0x20000000, LENGTH = 160K +} + +OUTPUT_ARCH(arm) +ENTRY(_stext) +SECTIONS +{ + .text : { + _stext = ABSOLUTE(.); + *(.vectors) + *(.text .text.*) + *(.fixup) + *(.gnu.warning) + *(.rodata .rodata.*) + *(.gnu.linkonce.t.*) + *(.glue_7) + *(.glue_7t) + *(.got) + *(.gcc_except_table) + *(.gnu.linkonce.r.*) + _etext = ABSOLUTE(.); + } > flash + + .init_section : { + _sinit = ABSOLUTE(.); + *(.init_array .init_array.*) + _einit = ABSOLUTE(.); + } > flash + + .ARM.extab : { + *(.ARM.extab*) + } > flash + + __exidx_start = ABSOLUTE(.); + .ARM.exidx : { + *(.ARM.exidx*) + } > flash + __exidx_end = ABSOLUTE(.); + + _eronly = ABSOLUTE(.); + + /* The STM32L452RE has 160Kb of SRAM beginning at the following address */ + + .data : { + _sdata = ABSOLUTE(.); + *(.data .data.*) + *(.gnu.linkonce.d.*) + CONSTRUCTORS + _edata = ABSOLUTE(.); + } > sram AT > flash + + .bss : { + _sbss = ABSOLUTE(.); + *(.bss .bss.*) + *(.gnu.linkonce.b.*) + *(COMMON) + _ebss = ABSOLUTE(.); + } > sram + + /* Stabs debugging sections. */ + .stab 0 : { *(.stab) } + .stabstr 0 : { *(.stabstr) } + .stab.excl 0 : { *(.stab.excl) } + .stab.exclstr 0 : { *(.stab.exclstr) } + .stab.index 0 : { *(.stab.index) } + .stab.indexstr 0 : { *(.stab.indexstr) } + .comment 0 : { *(.comment) } + .debug_abbrev 0 : { *(.debug_abbrev) } + .debug_info 0 : { *(.debug_info) } + .debug_line 0 : { *(.debug_line) } + .debug_pubnames 0 : { *(.debug_pubnames) } + .debug_aranges 0 : { *(.debug_aranges) } +} diff --git a/configs/nucleo-l452re/src/.gitignore b/configs/nucleo-l452re/src/.gitignore new file mode 100644 index 00000000000..726d936e1e3 --- /dev/null +++ b/configs/nucleo-l452re/src/.gitignore @@ -0,0 +1,2 @@ +/.depend +/Make.dep diff --git a/configs/nucleo-l452re/src/Makefile b/configs/nucleo-l452re/src/Makefile new file mode 100644 index 00000000000..4cd0f2e7c47 --- /dev/null +++ b/configs/nucleo-l452re/src/Makefile @@ -0,0 +1,56 @@ +############################################################################ +# configs/nucleo-l452re/src/Makefile +# +# Copyright (C) 2017 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# Alan Carvalho de Assis +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name NuttX nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + +-include $(TOPDIR)/Make.defs + +ASRCS = +CSRCS = stm32_boot.c stm32_bringup.c stm32_spi.c + +ifeq ($(CONFIG_ARCH_LEDS),y) +CSRCS += stm32_autoleds.c +else +CSRCS += stm32_userleds.c +endif + +ifeq ($(CONFIG_ARCH_BUTTONS),y) +CSRCS += stm32_buttons.c +endif + +ifeq ($(CONFIG_LIB_BOARDCTL),y) +CSRCS += stm32_appinit.c +endif + +include $(TOPDIR)/configs/Board.mk diff --git a/configs/nucleo-l452re/src/nucleo-l452re.h b/configs/nucleo-l452re/src/nucleo-l452re.h new file mode 100644 index 00000000000..4ab3436861b --- /dev/null +++ b/configs/nucleo-l452re/src/nucleo-l452re.h @@ -0,0 +1,149 @@ +/**************************************************************************** + * configs/nucleo-l452re/src/nucleo-l452re.h + * + * Copyright (C) 2017 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * Alan Carvalho de Assis + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __CONFIGS_NUCLEO_L452RE_SRC_NUCLEO_L452RE_H +#define __CONFIGS_NUCLEO_L452RE_SRC_NUCLEO_L452RE_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include + +#include "stm32l4_gpio.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Configuration ************************************************************/ + +#define HAVE_PROC 1 +#define HAVE_RTC_DRIVER 1 +#define HAVE_MMCSD 1 + +#if !defined(CONFIG_FS_PROCFS) +# undef HAVE_PROC +#endif + +#if defined(HAVE_PROC) && defined(CONFIG_DISABLE_MOUNTPOINT) +# warning Mountpoints disabled. No procfs support +# undef HAVE_PROC +#endif + +/* Check if we can support the RTC driver */ + +#if !defined(CONFIG_RTC) || !defined(CONFIG_RTC_DRIVER) +# undef HAVE_RTC_DRIVER +#endif + +#if !defined(CONFIG_STM32L4_SDIO) || !defined(CONFIG_MMCSD) || \ + !defined(CONFIG_MMCSD_SDIO) +# undef HAVE_MMCSD +#endif + +/* How many SPI modules does this chip support? */ + +#if STM32L4_NSPI < 1 +# undef CONFIG_STM32L4_SPI1 +# undef CONFIG_STM32L4_SPI2 +# undef CONFIG_STM32L4_SPI3 +#elif STM32L4_NSPI < 2 +# undef CONFIG_STM32L4_SPI2 +# undef CONFIG_STM32L4_SPI3 +#elif STM32L4_NSPI < 3 +# undef CONFIG_STM32L4_SPI3 +#endif + +/* Nucleo-L452RE GPIOs ******************************************************/ +/* LED. User LD2: the green LED is a user LED connected to Arduino signal + * D13 corresponding to MCU I/O PA5 (pin 21) or PB13 (pin 34) depending on + * the STM32 target. + * + * - When the I/O is HIGH value, the LED is on. + * - When the I/O is LOW, the LED is off. + */ + +#define GPIO_LD2 (GPIO_OUTPUT | GPIO_PUSHPULL | GPIO_SPEED_2MHz | \ + GPIO_OUTPUT_CLEAR | GPIO_PORTA | GPIO_PIN5) + + +/* Button definitions *******************************************************/ +/* B1 USER: the user button is connected to the I/O PC13 (pin 2) of the STM32 + * microcontroller. + */ + +#define MIN_IRQBUTTON BUTTON_USER +#define MAX_IRQBUTTON BUTTON_USER +#define NUM_IRQBUTTONS 1 + +#define GPIO_BTN_USER (GPIO_INPUT | GPIO_FLOAT | GPIO_EXTI | \ + GPIO_PORTC | GPIO_PIN13) + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/**************************************************************************** + * Public data + ****************************************************************************/ + +#ifndef __ASSEMBLY__ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: stm32_bringup + * + * Description: + * Perform architecture-specific initialization + * + * CONFIG_BOARD_INITIALIZE=y : + * Called from board_initialize(). + * + * CONFIG_BOARD_INITIALIZE=n && CONFIG_LIB_BOARDCTL=y : + * Called from the NSH library + * + ****************************************************************************/ + +int stm32_bringup(void); + +#endif /* __ASSEMBLY__ */ +#endif /* __CONFIGS_NUCLEO_L452RE_SRC_NUCLEO_L452RE_H */ diff --git a/configs/nucleo-l452re/src/stm32_appinit.c b/configs/nucleo-l452re/src/stm32_appinit.c new file mode 100644 index 00000000000..26b1b4f4c51 --- /dev/null +++ b/configs/nucleo-l452re/src/stm32_appinit.c @@ -0,0 +1,87 @@ +/**************************************************************************** + * config/nucleo-l452re/src/stm32_appinit.c + * + * Copyright (C) 2017 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * Alan Carvalho de Assis + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#include + +#include "nucleo-l452re.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_app_initialize + * + * Description: + * Perform application specific initialization. This function is never + * called directly from application code, but only indirectly via the + * (non-standard) boardctl() interface using the command BOARDIOC_INIT. + * + * Input Parameters: + * arg - The boardctl() argument is passed to the board_app_initialize() + * implementation without modification. The argument has no + * meaning to NuttX; the meaning of the argument is a contract + * between the board-specific initalization logic and the the + * matching application logic. The value cold be such things as a + * mode enumeration value, a set of DIP switch switch settings, a + * pointer to configuration data read from a file or serial FLASH, + * or whatever you would like to do with it. Every implementation + * should accept zero/NULL as a default configuration. + * + * Returned Value: + * Zero (OK) is returned on success; a negated errno value is returned on + * any failure to indicate the nature of the failure. + * + ****************************************************************************/ + +int board_app_initialize(uintptr_t arg) +{ + /* Did we already initialize via board_initialize()? */ + +#ifndef CONFIG_BOARD_INITIALIZE + return stm32_bringup(); +#else + return OK; +#endif +} diff --git a/configs/nucleo-l452re/src/stm32_autoleds.c b/configs/nucleo-l452re/src/stm32_autoleds.c new file mode 100644 index 00000000000..197478aeaa9 --- /dev/null +++ b/configs/nucleo-l452re/src/stm32_autoleds.c @@ -0,0 +1,96 @@ +/**************************************************************************** + * configs/nucleo-l452re/src/stm32_autoleds.c + * + * Copyright (C) 2017 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include +#include + +#include "chip.h" +#include "up_arch.h" +#include "up_internal.h" +#include "stm32l4_gpio.h" +#include "nucleo-l452re.h" + +#ifdef CONFIG_ARCH_LEDS + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_autoled_initialize + ****************************************************************************/ + +void board_autoled_initialize(void) +{ + /* Configure LD2 GPIO for output */ + + stm32l4_configgpio(GPIO_LD2); +} + +/**************************************************************************** + * Name: board_autoled_on + ****************************************************************************/ + +void board_autoled_on(int led) +{ + if (led == 1) + { + stm32l4_gpiowrite(GPIO_LD2, true); + } +} + +/**************************************************************************** + * Name: board_autoled_off + ****************************************************************************/ + +void board_autoled_off(int led) +{ + if (led == 1) + { + stm32l4_gpiowrite(GPIO_LD2, false); + } +} + +#endif /* CONFIG_ARCH_LEDS */ diff --git a/configs/nucleo-l452re/src/stm32_boot.c b/configs/nucleo-l452re/src/stm32_boot.c new file mode 100644 index 00000000000..9e7c287303d --- /dev/null +++ b/configs/nucleo-l452re/src/stm32_boot.c @@ -0,0 +1,94 @@ +/************************************************************************************ + * configs/nucleo-l452re/src/stm32_boot.c + * + * Copyright (C) 2017 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * Alan Carvalho de Assis + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ************************************************************************************/ + +/************************************************************************************ + * Included Files + ************************************************************************************/ + +#include + +#include + +#include +#include + +#include "up_arch.h" +#include "nucleo-l452re.h" + +/************************************************************************************ + * Public Functions + ************************************************************************************/ + +/************************************************************************************ + * Name: stm32l4_boardinitialize + * + * Description: + * All STM32 architectures must provide the following entry point. This entry point + * is called early in the intitialization -- after all memory has been configured + * and mapped but before any devices have been initialized. + * + ************************************************************************************/ + +void stm32l4_boardinitialize(void) +{ +#ifdef CONFIG_ARCH_LEDS + /* Configure on-board LEDs if LED support has been selected. */ + + board_autoled_initialize(); +#endif +} + +/**************************************************************************** + * Name: board_initialize + * + * Description: + * If CONFIG_BOARD_INITIALIZE is selected, then an additional + * initialization call will be performed in the boot-up sequence to a + * function called board_initialize(). board_initialize() will be + * called immediately after up_initialize() is called and just before the + * initial application is started. This additional initialization phase + * may be used, for example, to initialize board-specific device drivers. + * + ****************************************************************************/ + +#ifdef CONFIG_BOARD_INITIALIZE +void board_initialize(void) +{ + /* Perform board-specific initialization here if so configured */ + + (void)stm32_bringup(); +} +#endif diff --git a/configs/nucleo-l452re/src/stm32_bringup.c b/configs/nucleo-l452re/src/stm32_bringup.c new file mode 100644 index 00000000000..b50fe958276 --- /dev/null +++ b/configs/nucleo-l452re/src/stm32_bringup.c @@ -0,0 +1,117 @@ +/**************************************************************************** + * config/nucleo-l452re/src/stm32_bringup.c + * + * Copyright (C) 2017 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include + +#include "stm32l4_i2c.h" +#include "nucleo-l452re.h" + +/**************************************************************************** + * Pre-processor Defintiionis + ****************************************************************************/ + +#undef HAVE_I2C_DRIVER +#if defined(CONFIG_STM32L4_I2C1) && defined(CONFIG_I2C_DRIVER) +# define HAVE_I2C_DRIVER 1 +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: stm32_bringup + * + * Description: + * Perform architecture-specific initialization + * + * CONFIG_BOARD_INITIALIZE=y : + * Called from board_initialize(). + * + * CONFIG_BOARD_INITIALIZE=n && CONFIG_LIB_BOARDCTL=y : + * Called from the NSH library + * + ****************************************************************************/ + +int stm32_bringup(void) +{ +#ifdef HAVE_I2C_DRIVER + FAR struct i2c_master_s *i2c; +#endif + int ret; + +#ifdef CONFIG_FS_PROCFS + /* Mount the procfs file system */ + + ret = mount(NULL, "/proc", "procfs", 0, NULL); + if (ret < 0) + { + ferr("ERROR: Failed to mount procfs at /proc: %d\n", ret); + } +#endif + +#ifdef HAVE_I2C_DRIVER + /* Get the I2C lower half instance */ + + i2c = stm32l4_i2cbus_initialize(1); + if (i2c == NULL) + { + i2cerr("ERROR: Initialize I2C1: %d\n", ret); + } + else + { + /* Register the I2C character driver */ + + ret = i2c_register(i2c, 1); + if (ret < 0) + { + i2cerr("ERROR: Failed to register I2C1 device: %d\n", ret); + } + } +#endif + + UNUSED(ret); + return OK; +} diff --git a/configs/nucleo-l452re/src/stm32_buttons.c b/configs/nucleo-l452re/src/stm32_buttons.c new file mode 100644 index 00000000000..1d48c1f4a6d --- /dev/null +++ b/configs/nucleo-l452re/src/stm32_buttons.c @@ -0,0 +1,128 @@ +/**************************************************************************** + * configs/nucleo-l452re/src/stm32_buttons.c + * + * Copyright (C) 2017 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include +#include +#include + +#include "stm32l4_gpio.h" +#include "nucleo-l452re.h" + +#ifdef CONFIG_ARCH_BUTTONS + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_button_initialize + * + * Description: + * board_button_initialize() must be called to initialize button resources. + * After that, board_buttons() may be called to collect the current state + * of all buttons or board_button_irq() may be called to register button + * interrupt handlers. + * + ****************************************************************************/ + +void board_button_initialize(void) +{ + /* Configure the single button as an input. NOTE that EXTI interrupts are + * also configured for the pin. + */ + + stm32l4_configgpio(GPIO_BTN_USER); +} + +/**************************************************************************** + * Name: board_buttons + ****************************************************************************/ + +uint32_t board_buttons(void) +{ + /* Check that state of each USER button. A LOW value means that the key is + * pressed. + */ + + bool released = stm32l4_gpioread(GPIO_BTN_USER); + return !released; +} + +/************************************************************************************ + * Button support. + * + * Description: + * board_button_initialize() must be called to initialize button resources. After + * that, board_buttons() may be called to collect the current state of all + * buttons or board_button_irq() may be called to register button interrupt + * handlers. + * + * After board_button_initialize() has been called, board_buttons() may be called to + * collect the state of all buttons. board_buttons() returns an 32-bit bit set + * with each bit associated with a button. See the BUTTON_*_BIT + * definitions in board.h for the meaning of each bit. + * + * board_button_irq() may be called to register an interrupt handler that will + * be called when a button is depressed or released. The ID value is a + * button enumeration value that uniquely identifies a button resource. See the + * BUTTON_* definitions in board.h for the meaning of enumeration + * value. + * + ************************************************************************************/ + +#ifdef CONFIG_ARCH_IRQBUTTONS +int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg) +{ + int ret = -EINVAL; + + if (id == BUTTON_USER) + { + ret = stm32l4_gpiosetevent(GPIO_BTN_USER, true, true, true, irqhandler, arg); + } + + return ret; +} +#endif +#endif /* CONFIG_ARCH_BUTTONS */ diff --git a/configs/nucleo-l452re/src/stm32_spi.c b/configs/nucleo-l452re/src/stm32_spi.c new file mode 100644 index 00000000000..02f17ca6078 --- /dev/null +++ b/configs/nucleo-l452re/src/stm32_spi.c @@ -0,0 +1,223 @@ +/**************************************************************************** + * configs/nucleo-l452re/src/stm32_spi.c + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/************************************************************************************ + * Included Files + ************************************************************************************/ + +#include + +#include +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include "nucleo-l452re.h" + +#if defined(CONFIG_STM32L4_SPI1) || defined(CONFIG_STM32L4_SPI2) || defined(CONFIG_STM32L4_SPI3) + +/************************************************************************************ + * Public Data + ************************************************************************************/ +/* Global driver instances */ + +#ifdef CONFIG_STM32L4_SPI1 +struct spi_dev_s *g_spi1; +#endif +#ifdef CONFIG_STM32L4_SPI2 +struct spi_dev_s *g_spi2; +#endif + +/************************************************************************************ + * Public Functions + ************************************************************************************/ + +/************************************************************************************ + * Name: stm32l4_spiinitialize + * + * Description: + * Called to configure SPI chip select GPIO pins. + * + ************************************************************************************/ + +void weak_function stm32l4_spiinitialize(void) +{ +#ifdef CONFIG_STM32L4_SPI1 + /* Configure SPI-based devices */ + + g_spi1 = stm32l4_spibus_initialize(1); + if (!g_spi1) + { + spierr("ERROR: FAILED to initialize SPI port 1\n"); + } + +#ifdef HAVE_MMCSD + stm32l4_configgpio(GPIO_SPI_CS_SD_CARD); +#endif +#endif + +#ifdef CONFIG_STM32L4_SPI2 + /* Configure SPI-based devices */ + + g_spi2 = stm32l4_spibus_initialize(2); + if (!g_spi2) + { + spierr("ERROR: FAILED to initialize SPI port 1\n"); + } +#endif +} + +/**************************************************************************** + * Name: stm32l4_spi1/2/3select and stm32l4_spi1/2/3status + * + * Description: + * The external functions, stm32l4_spi1/2/3select and stm32l4_spi1/2/3status must be + * provided by board-specific logic. They are implementations of the select + * and status methods of the SPI interface defined by struct spi_ops_s (see + * include/nuttx/spi/spi.h). All other methods (including up_spiinitialize()) + * are provided by common STM32 logic. To use this common SPI logic on your + * board: + * + * 1. Provide logic in stm32l4_boardinitialize() to configure SPI chip select + * pins. + * 2. Provide stm32l4_spi1/2/3select() and stm32l4_spi1/2/3status() functions in your + * board-specific logic. These functions will perform chip selection and + * status operations using GPIOs in the way your board is configured. + * 3. Add a calls to up_spiinitialize() in your low level application + * initialization logic + * 4. The handle returned by up_spiinitialize() may then be used to bind the + * SPI driver to higher level logic (e.g., calling + * mmcsd_spislotinitialize(), for example, will bind the SPI driver to + * the SPI MMC/SD driver). + * + ****************************************************************************/ + +#ifdef CONFIG_STM32L4_SPI1 +void stm32l4_spi1select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected) +{ + spiinfo("devid: %d CS: %s\n", (int)devid, selected ? "assert" : "de-assert"); + +#ifdef HAVE_MMCSD + if (devid == SPIDEV_MMCSD(0)) + { + stm32l4_gpiowrite(GPIO_SPI_CS_SD_CARD, !selected); + } +#endif +} + +uint8_t stm32l4_spi1status(FAR struct spi_dev_s *dev, uint32_t devid) +{ + return 0; +} +#endif + +#ifdef CONFIG_STM32L4_SPI2 +void stm32l4_spi2select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected) +{ + spiinfo("devid: %d CS: %s\n", (int)devid, selected ? "assert" : "de-assert"); +} + +uint8_t stm32l4_spi2status(FAR struct spi_dev_s *dev, uint32_t devid) +{ + return 0; +} +#endif + +#ifdef CONFIG_STM32L4_SPI3 +void stm32l4_spi3select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected) + + spiinfo("devid: %d CS: %s\n", (int)devid, selected ? "assert" : "de-assert"); +} + +uint8_t stm32l4_spi3status(FAR struct spi_dev_s *dev, uint32_t devid) +{ + return 0; +} +#endif + +/**************************************************************************** + * Name: stm32l4_spi1cmddata + * + * Description: + * Set or clear the SH1101A A0 or SD1306 D/C n bit to select data (true) + * or command (false). This function must be provided by platform-specific + * logic. This is an implementation of the cmddata method of the SPI + * interface defined by struct spi_ops_s (see include/nuttx/spi/spi.h). + * + * Input Parameters: + * + * spi - SPI device that controls the bus the device that requires the CMD/ + * DATA selection. + * devid - If there are multiple devices on the bus, this selects which one + * to select cmd or data. NOTE: This design restricts, for example, + * one one SPI display per SPI bus. + * cmd - true: select command; false: select data + * + * Returned Value: + * None + * + ****************************************************************************/ + +#ifdef CONFIG_SPI_CMDDATA +#ifdef CONFIG_STM32L4_SPI1 +int stm32l4_spi1cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd) +{ + return OK; +} +#endif + +#ifdef CONFIG_STM32L4_SPI2 +int stm32l4_spi2cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd) +{ + return OK; +} +#endif + +#ifdef CONFIG_STM32L4_SPI3 +int stm32l4_spi3cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd) +{ + return OK; +} +#endif +#endif /* CONFIG_SPI_CMDDATA */ + +#endif /* CONFIG_STM32L4_SPI1 || CONFIG_STM32L4_SPI2 || CONFIG_STM32L4_SPI3 */ diff --git a/configs/nucleo-l452re/src/stm32_userleds.c b/configs/nucleo-l452re/src/stm32_userleds.c new file mode 100644 index 00000000000..77ba277c342 --- /dev/null +++ b/configs/nucleo-l452re/src/stm32_userleds.c @@ -0,0 +1,217 @@ +/**************************************************************************** + * configs/nucleo-l452re/src/stm32_userleds.c + * + * Copyright (C) 2017 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include +#include + +#include "chip.h" +#include "up_arch.h" +#include "up_internal.h" +#include "stm32l4_gpio.h" +#include "nucleo-l452re.h" + +#ifndef CONFIG_ARCH_LEDS + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/* LED Power Management */ + +#ifdef CONFIG_PM +static void led_pm_notify(struct pm_callback_s *cb, int domain, + enum pm_state_e pmstate); +static int led_pm_prepare(struct pm_callback_s *cb, int domain, + enum pm_state_e pmstate); +#endif + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +#ifdef CONFIG_PM +static struct pm_callback_s g_ledscb = +{ + .notify = led_pm_notify, + .prepare = led_pm_prepare, +}; +#endif + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: led_pm_notify + * + * Description: + * Notify the driver of new power state. This callback is called after + * all drivers have had the opportunity to prepare for the new power state. + * + ****************************************************************************/ + +#ifdef CONFIG_PM +static void led_pm_notify(struct pm_callback_s *cb, int domain, + enum pm_state_e pmstate) +{ + switch (pmstate) + { + case(PM_NORMAL): + { + /* Restore normal LEDs operation */ + + } + break; + + case(PM_IDLE): + { + /* Entering IDLE mode - Turn leds off */ + + } + break; + + case(PM_STANDBY): + { + /* Entering STANDBY mode - Logic for PM_STANDBY goes here */ + + } + break; + + case(PM_SLEEP): + { + /* Entering SLEEP mode - Logic for PM_SLEEP goes here */ + + } + break; + + default: + { + /* Should not get here */ + + } + break; + } +} +#endif + +/**************************************************************************** + * Name: led_pm_prepare + * + * Description: + * Request the driver to prepare for a new power state. This is a warning + * that the system is about to enter into a new power state. The driver + * should begin whatever operations that may be required to enter power + * state. The driver may abort the state change mode by returning a + * non-zero value from the callback function. + * + ****************************************************************************/ + +#ifdef CONFIG_PM +static int led_pm_prepare(struct pm_callback_s *cb, int domain, + enum pm_state_e pmstate) +{ + /* No preparation to change power modes is required by the LEDs driver. + * We always accept the state change by returning OK. + */ + + return OK; +} +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_userled_initialize + ****************************************************************************/ + +void board_userled_initialize(void) +{ + /* Configure LD2 GPIO for output */ + + stm32l4_configgpio(GPIO_LD2); +} + +/**************************************************************************** + * Name: board_userled + ****************************************************************************/ + +void board_userled(int led, bool ledon) +{ + if (led == 1) + { + stm32l4_gpiowrite(GPIO_LD2, ldeon); + } +} + +/**************************************************************************** + * Name: board_userled_all + ****************************************************************************/ + +void board_userled_all(uint8_t ledset) +{ + if (led == 1) + { + stm32l4_gpiowrite(GPIO_LD2, (ledset & BOARD_LD2_BIT) != 0); + } +} + +/**************************************************************************** + * Name: stm32l4_led_pminitialize + ****************************************************************************/ + +#ifdef CONFIG_PM +void stm32l4_led_pminitialize(void) +{ + /* Register to receive power management callbacks */ + + int ret = pm_register(&g_ledscb); + DEBUGASSERT(ret == OK); + UNUSED(ret); +} +#endif /* CONFIG_PM */ + +#endif /* !CONFIG_ARCH_LEDS */ From 969c1ab6144e4f2e4cf56ea5d5799d8ad6c0cf83 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 4 May 2017 08:20:59 -0600 Subject: [PATCH 129/183] 6loWPAN: Replace some Rime address naming with more consistent short/exended address terminology --- configs/sim/sixlowpan/defconfig | 2 +- include/nuttx/net/ieee802154.h | 39 ++++++++++++++++++------ include/nuttx/net/netdev.h | 2 +- include/nuttx/net/sixlowpan.h | 2 +- net/netdev/netdev_ioctl.c | 6 ++-- net/procfs/netdev_statistics.c | 4 +-- net/sixlowpan/Kconfig | 2 +- net/sixlowpan/sixlowpan_framelist.c | 8 ++--- net/sixlowpan/sixlowpan_framer.c | 10 +++--- net/sixlowpan/sixlowpan_globals.c | 2 +- net/sixlowpan/sixlowpan_hc06.c | 14 ++++----- net/sixlowpan/sixlowpan_hc1.c | 2 +- net/sixlowpan/sixlowpan_input.c | 2 +- net/sixlowpan/sixlowpan_internal.h | 22 ++++++------- net/sixlowpan/sixlowpan_send.c | 4 +-- net/sixlowpan/sixlowpan_tcpsend.c | 4 +-- net/sixlowpan/sixlowpan_udpsend.c | 2 +- net/sixlowpan/sixlowpan_utils.c | 20 ++++++------ wireless/ieee802154/mac802154_loopback.c | 6 ++-- 19 files changed, 87 insertions(+), 66 deletions(-) diff --git a/configs/sim/sixlowpan/defconfig b/configs/sim/sixlowpan/defconfig index 5c64eb13e65..f46639d0039 100644 --- a/configs/sim/sixlowpan/defconfig +++ b/configs/sim/sixlowpan/defconfig @@ -548,7 +548,7 @@ CONFIG_NET_6LOWPAN_MAXADDRCONTEXT=1 CONFIG_NET_6LOWPAN_MAXADDRCONTEXT_PREFIX_0_0=0xaa CONFIG_NET_6LOWPAN_MAXADDRCONTEXT_PREFIX_0_1=0xaa # CONFIG_NET_6LOWPAN_MAXADDRCONTEXT_PREINIT_1 is not set -# CONFIG_NET_6LOWPAN_RIMEADDR_EXTENDED is not set +# CONFIG_NET_6LOWPAN_EXTENDEDADDR is not set CONFIG_NET_6LOWPAN_MAXAGE=20 CONFIG_NET_6LOWPAN_MAX_MACTRANSMITS=4 CONFIG_NET_6LOWPAN_MTU=1294 diff --git a/include/nuttx/net/ieee802154.h b/include/nuttx/net/ieee802154.h index 6132d3d02bc..9d9260f61b4 100644 --- a/include/nuttx/net/ieee802154.h +++ b/include/nuttx/net/ieee802154.h @@ -58,15 +58,18 @@ * Pre-processor Definitions ****************************************************************************/ -/* By default, a 2-byte Rime address is used for the IEEE802.15.4 MAC - * device's link layer address. If CONFIG_NET_6LOWPAN_RIMEADDR_EXTENDED - * is selected, then an 8-byte Rime address will be used. +/* By default, a 2-byte short address is used for the IEEE802.15.4 MAC + * device's link layer address. If CONFIG_NET_6LOWPAN_EXTENDEDADDR + * is selected, then an 8-byte extended address will be used. */ -#ifdef CONFIG_NET_6LOWPAN_RIMEADDR_EXTENDED -# define NET_6LOWPAN_RIMEADDR_SIZE 8 +#define NET_6LOWPAN_SADDRSIZE 2 +#define NET_6LOWPAN_EADDRSIZE 8 + +#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR +# define NET_6LOWPAN_ADDRSIZE NET_6LOWPAN_EADDRSIZE #else -# define NET_6LOWPAN_RIMEADDR_SIZE 2 +# define NET_6LOWPAN_ADDRSIZE NET_6LOWPAN_SADDRSIZE #endif /* Frame format definitions *************************************************/ @@ -123,11 +126,29 @@ * Public Types ****************************************************************************/ -/* Rime address representation */ +/* IEEE 802.15.4 address representations */ -struct rimeaddr_s +struct sixlowpan_saddr_s { - uint8_t u8[NET_6LOWPAN_RIMEADDR_SIZE]; + uint8_t u8[NET_6LOWPAN_SADDRSIZE]; +}; + +struct sixlowpan_eaddr_s +{ + uint8_t u8[NET_6LOWPAN_EADDRSIZE]; +}; + +union sixlowpan_anyaddr_u +{ + struct sixlowpan_saddr_s saddr; + struct sixlowpan_eaddr_s eaddr; +}; + +/* Represents the configured address size */ + +struct sixlowpan_addr_s +{ + uint8_t u8[NET_6LOWPAN_ADDRSIZE]; }; /**************************************************************************** diff --git a/include/nuttx/net/netdev.h b/include/nuttx/net/netdev.h index 7f8e4041f45..fe2743f5e97 100644 --- a/include/nuttx/net/netdev.h +++ b/include/nuttx/net/netdev.h @@ -224,7 +224,7 @@ struct net_driver_s #ifdef CONFIG_NET_6LOWPAN /* The address assigned to an IEEE 802.15.4 radio. */ - struct rimeaddr_s ieee802154; /* IEEE 802.15.4 Radio address */ + struct sixlowpan_addr_s ieee802154; /* IEEE 802.15.4 Radio address */ #endif } d_mac; #endif diff --git a/include/nuttx/net/sixlowpan.h b/include/nuttx/net/sixlowpan.h index 507f08eb517..94061a365ec 100644 --- a/include/nuttx/net/sixlowpan.h +++ b/include/nuttx/net/sixlowpan.h @@ -420,7 +420,7 @@ struct ieee802154_driver_s /* The source MAC address of the fragments being merged */ - struct rimeaddr_s i_fragsrc; + struct sixlowpan_addr_s i_fragsrc; /* That time at which reassembly was started. If the elapsed time * exceeds CONFIG_NET_6LOWPAN_MAXAGE, then the reassembly will diff --git a/net/netdev/netdev_ioctl.c b/net/netdev/netdev_ioctl.c index 9eb099dddb9..81bfe9a0b34 100644 --- a/net/netdev/netdev_ioctl.c +++ b/net/netdev/netdev_ioctl.c @@ -790,7 +790,7 @@ static int netdev_ifr_ioctl(FAR struct socket *psock, int cmd, { req->ifr_hwaddr.sa_family = AF_INETX; memcpy(req->ifr_hwaddr.sa_data, - dev->d_mac.ieee802154.u8, NET_6LOWPAN_RIMEADDR_SIZE); + dev->d_mac.ieee802154.u8, NET_6LOWPAN_ADDRSIZE); } else #endif @@ -828,7 +828,7 @@ static int netdev_ifr_ioctl(FAR struct socket *psock, int cmd, #endif { memcpy(dev->d_mac.ieee802154.u8, - req->ifr_hwaddr.sa_data, NET_6LOWPAN_RIMEADDR_SIZE); + req->ifr_hwaddr.sa_data, NET_6LOWPAN_ADDRSIZE); ret = OK; } else @@ -1023,7 +1023,7 @@ static int netdev_arp_ioctl(FAR struct socket *psock, int cmd, case SIOCSARP: /* Set an ARP mapping */ { if (req != NULL && - req->arp_pa.sa_family == AF_INET && + req->arp_pa.sa_family == AF_INET && req->arp_ha.sa_family == ARPHRD_ETHER) { FAR struct sockaddr_in *addr = diff --git a/net/procfs/netdev_statistics.c b/net/procfs/netdev_statistics.c index 5383adfc6a4..109f4cdca28 100644 --- a/net/procfs/netdev_statistics.c +++ b/net/procfs/netdev_statistics.c @@ -151,7 +151,7 @@ static int netprocfs_linklayer(FAR struct netprocfs_file_s *netfile) #ifdef CONFIG_NET_6LOWPAN case NET_LL_IEEE802154: { -#ifdef CONFIG_NET_6LOWPAN_RIMEADDR_EXTENDED +#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR len += snprintf(&netfile->line[len], NET_LINELEN - len, "%s\tLink encap:6loWPAN HWaddr " "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", @@ -213,7 +213,7 @@ static int netprocfs_linklayer(FAR struct netprocfs_file_s *netfile) dev->d_ifname, ether_ntoa(&dev->d_mac.ether), status); #elif defined(CONFIG_NET_6LOWPAN) -#ifdef CONFIG_NET_6LOWPAN_RIMEADDR_EXTENDED +#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR len += snprintf(&netfile->line[len], NET_LINELEN - len, "%s\tLink encap:6loWPAN HWaddr " "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x at %s\n", diff --git a/net/sixlowpan/Kconfig b/net/sixlowpan/Kconfig index 021571fbd01..4b1c4df409d 100644 --- a/net/sixlowpan/Kconfig +++ b/net/sixlowpan/Kconfig @@ -133,7 +133,7 @@ config NET_6LOWPAN_MAXADDRCONTEXT_PREFIX_2_1 endif # NET_6LOWPAN_MAXADDRCONTEXT_PREINIT_0 endif # NET_6LOWPAN_COMPRESSION_HC06 -config NET_6LOWPAN_RIMEADDR_EXTENDED +config NET_6LOWPAN_EXTENDEDADDR bool "Extended Rime address" default n ---help--- diff --git a/net/sixlowpan/sixlowpan_framelist.c b/net/sixlowpan/sixlowpan_framelist.c index fb03af457ff..013f7cbb7e6 100644 --- a/net/sixlowpan/sixlowpan_framelist.c +++ b/net/sixlowpan/sixlowpan_framelist.c @@ -209,13 +209,13 @@ static void sixlowpan_compress_ipv6hdr(FAR const struct ipv6_hdr_s *ipv6hdr, int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, FAR const struct ipv6_hdr_s *destip, FAR const void *buf, size_t buflen, - FAR const struct rimeaddr_s *destmac) + FAR const struct sixlowpan_addr_s *destmac) { struct ieee802154_frame_meta_s meta; FAR struct iob_s *iob; FAR uint8_t *fptr; int framer_hdrlen; - struct rimeaddr_s bcastmac; + struct sixlowpan_addr_s bcastmac; uint16_t pktlen; uint16_t paysize; uint16_t dest_panid; @@ -234,7 +234,7 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, /* Reset rime buffer, packet buffer metatadata */ memset(g_pktattrs, 0, PACKETBUF_NUM_ATTRS * sizeof(uint16_t)); - memset(g_pktaddrs, 0, PACKETBUF_NUM_ADDRS * sizeof(struct rimeaddr_s)); + memset(g_pktaddrs, 0, PACKETBUF_NUM_ADDRS * sizeof(struct sixlowpan_addr_s)); g_pktattrs[PACKETBUF_ATTR_MAX_MAC_TRANSMISSIONS] = CONFIG_NET_6LOWPAN_MAX_MACTRANSMITS; @@ -263,7 +263,7 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, if (destmac == NULL) { - memset(&bcastmac, 0, sizeof(struct rimeaddr_s)); + memset(&bcastmac, 0, sizeof(struct sixlowpan_addr_s)); destmac = &bcastmac; } diff --git a/net/sixlowpan/sixlowpan_framer.c b/net/sixlowpan/sixlowpan_framer.c index 47afecf6af7..e8b68eede40 100644 --- a/net/sixlowpan/sixlowpan_framer.c +++ b/net/sixlowpan/sixlowpan_framer.c @@ -83,7 +83,7 @@ static bool sixlowpan_addrnull(FAR uint8_t *addr) { - int i = NET_6LOWPAN_RIMEADDR_SIZE; + int i = NET_6LOWPAN_ADDRSIZE; while (i-- > 0) { @@ -179,12 +179,12 @@ int sixlowpan_meta_data(uint16_t dest_panid, { /* Copy the destination address */ - rimeaddr_copy((struct rimeaddr_s *)&meta->dest_addr, + rimeaddr_copy((struct sixlowpan_addr_s *)&meta->dest_addr, g_pktaddrs[PACKETBUF_ADDR_RECEIVER].u8); /* Use short destination address mode if so configured */ -#ifdef CONFIG_NET_6LOWPAN_RIMEADDR_EXTENDED +#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR meta->fcf.dest_addr_mode = FRAME802154_LONGADDRMODE; #else meta->fcf.dest_addr_mode = FRAME802154_SHORTADDRMODE; @@ -193,12 +193,12 @@ int sixlowpan_meta_data(uint16_t dest_panid, /* Set the source address to the node address assigned to the device */ - rimeaddr_copy((struct rimeaddr_s *)&meta->src_addr, + rimeaddr_copy((struct sixlowpan_addr_s *)&meta->src_addr, &ieee->i_dev.d_mac.ieee802154); /* Use short soruce address mode if so configured */ -#ifdef CONFIG_NET_6LOWPAN_RIMEADDR_EXTENDED +#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR meta->fcf.src_addr_mode = FRAME802154_LONGADDRMODE; #else meta->fcf.src_addr_mode = FRAME802154_SHORTADDRMODE; diff --git a/net/sixlowpan/sixlowpan_globals.c b/net/sixlowpan/sixlowpan_globals.c index aac17f7eb9c..646e2fec219 100644 --- a/net/sixlowpan/sixlowpan_globals.c +++ b/net/sixlowpan/sixlowpan_globals.c @@ -70,6 +70,6 @@ uint8_t g_frame_hdrlen; /* Packet buffer metadata: Attributes and addresses */ uint16_t g_pktattrs[PACKETBUF_NUM_ATTRS]; -struct rimeaddr_s g_pktaddrs[PACKETBUF_NUM_ADDRS]; +struct sixlowpan_addr_s g_pktaddrs[PACKETBUF_NUM_ADDRS]; #endif /* CONFIG_NET_6LOWPAN */ diff --git a/net/sixlowpan/sixlowpan_hc06.c b/net/sixlowpan/sixlowpan_hc06.c index a2ceb53cb65..751daf4dc88 100644 --- a/net/sixlowpan/sixlowpan_hc06.c +++ b/net/sixlowpan/sixlowpan_hc06.c @@ -233,7 +233,7 @@ static FAR struct sixlowpan_addrcontext_s * ****************************************************************************/ static uint8_t compress_addr_64(FAR const net_ipv6addr_t ipaddr, - FAR const struct rimeaddr_s *macaddr, + FAR const struct sixlowpan_addr_s *macaddr, uint8_t bitpos) { ninfo("ipaddr=%p macaddr=%p bitpos=%u g_hc06ptr=%p\n", @@ -275,7 +275,7 @@ static uint8_t compress_addr_64(FAR const net_ipv6addr_t ipaddr, ****************************************************************************/ static void uncompress_addr(FAR net_ipv6addr_t ipaddr, uint8_t const prefix[], - uint8_t prefpost, FAR struct rimeaddr_s *macaddr) + uint8_t prefpost, FAR struct sixlowpan_addr_s *macaddr) { uint8_t prefcount = prefpost >> 4; uint8_t postcount = prefpost & 0x0f; @@ -446,7 +446,7 @@ void sixlowpan_hc06_initialize(void) void sixlowpan_compresshdr_hc06(FAR struct ieee802154_driver_s *ieee, FAR const struct ipv6_hdr_s *ipv6, - FAR const struct rimeaddr_s *destmac, + FAR const struct sixlowpan_addr_s *destmac, FAR uint8_t *fptr) { FAR uint8_t *iphc = fptr + g_frame_hdrlen; @@ -987,14 +987,14 @@ void sixlowpan_uncompresshdr_hc06(uint16_t iplen, FAR struct iob_s *iob, uncompress_addr(ipv6->srcipaddr, tmp != 0 ? addrcontext->prefix : NULL, g_unc_ctxconf[tmp], - (FAR struct rimeaddr_s *)&g_pktaddrs[PACKETBUF_ADDR_SENDER]); + (FAR struct sixlowpan_addr_s *)&g_pktaddrs[PACKETBUF_ADDR_SENDER]); } else { /* No compression and link local */ uncompress_addr(ipv6->srcipaddr, g_llprefix, g_unc_llconf[tmp], - (FAR struct rimeaddr_s *)&g_pktaddrs[PACKETBUF_ADDR_SENDER]); + (FAR struct sixlowpan_addr_s *)&g_pktaddrs[PACKETBUF_ADDR_SENDER]); } /* Destination address */ @@ -1053,14 +1053,14 @@ void sixlowpan_uncompresshdr_hc06(uint16_t iplen, FAR struct iob_s *iob, } uncompress_addr(ipv6->destipaddr, addrcontext->prefix, g_unc_ctxconf[tmp], - (FAR struct rimeaddr_s *)&g_pktaddrs[PACKETBUF_ADDR_RECEIVER]); + (FAR struct sixlowpan_addr_s *)&g_pktaddrs[PACKETBUF_ADDR_RECEIVER]); } else { /* Not address context based => link local M = 0, DAC = 0 - same as SAC */ uncompress_addr(ipv6->destipaddr, g_llprefix, g_unc_llconf[tmp], - (FAR struct rimeaddr_s *)&g_pktaddrs[PACKETBUF_ADDR_RECEIVER]); + (FAR struct sixlowpan_addr_s *)&g_pktaddrs[PACKETBUF_ADDR_RECEIVER]); } } diff --git a/net/sixlowpan/sixlowpan_hc1.c b/net/sixlowpan/sixlowpan_hc1.c index 3696c4a34f7..5b8829745eb 100644 --- a/net/sixlowpan/sixlowpan_hc1.c +++ b/net/sixlowpan/sixlowpan_hc1.c @@ -120,7 +120,7 @@ void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee, FAR const struct ipv6_hdr_s *ipv6, - FAR const struct rimeaddr_s *destmac, + FAR const struct sixlowpan_addr_s *destmac, FAR uint8_t *fptr) { FAR uint8_t *hc1 = fptr + g_frame_hdrlen; diff --git a/net/sixlowpan/sixlowpan_input.c b/net/sixlowpan/sixlowpan_input.c index 0c573913d92..dc45b3fdd00 100644 --- a/net/sixlowpan/sixlowpan_input.c +++ b/net/sixlowpan/sixlowpan_input.c @@ -740,7 +740,7 @@ int sixlowpan_input(FAR struct ieee802154_driver_s *ieee, { FAR struct ipv6_hdr_s *ipv6hdr; FAR uint8_t *buffer; - struct rimeaddr_s destmac; + struct sixlowpan_addr_s destmac; size_t hdrlen; size_t buflen; diff --git a/net/sixlowpan/sixlowpan_internal.h b/net/sixlowpan/sixlowpan_internal.h index 8eecb3b49b7..0a9cf07424a 100644 --- a/net/sixlowpan/sixlowpan_internal.h +++ b/net/sixlowpan/sixlowpan_internal.h @@ -75,12 +75,12 @@ /* Copy a Rime address */ #define rimeaddr_copy(dest,src) \ - memcpy(dest, src, NET_6LOWPAN_RIMEADDR_SIZE) + memcpy(dest, src, NET_6LOWPAN_ADDRSIZE) /* Compare two Rime addresses */ #define rimeaddr_cmp(addr1,addr2) \ - (memcmp(addr1, addr2, NET_6LOWPAN_RIMEADDR_SIZE) == 0) + (memcmp(addr1, addr2, NET_6LOWPAN_ADDRSIZE) == 0) /* Pointers in the Rime buffer */ @@ -222,7 +222,7 @@ extern uint8_t g_frame_hdrlen; /* Packet buffer metadata: Attributes and addresses */ extern uint16_t g_pktattrs[PACKETBUF_NUM_ATTRS]; -extern struct rimeaddr_s g_pktaddrs[PACKETBUF_NUM_ADDRS]; +extern struct sixlowpan_addr_s g_pktaddrs[PACKETBUF_NUM_ADDRS]; /**************************************************************************** * Public Types @@ -236,7 +236,7 @@ struct net_driver_s; /* Forward reference */ struct ieee802154_driver_s; /* Forward reference */ struct devif_callback_s; /* Forward reference */ struct ipv6_hdr_s; /* Forward reference */ -struct rimeaddr_s; /* Forward reference */ +struct sixlowpan_addr_s; /* Forward reference */ struct iob_s; /* Forward reference */ /**************************************************************************** @@ -275,7 +275,7 @@ struct iob_s; /* Forward reference */ int sixlowpan_send(FAR struct net_driver_s *dev, FAR struct devif_callback_s **list, FAR const struct ipv6_hdr_s *ipv6hdr, FAR const void *buf, - size_t buflen, FAR const struct rimeaddr_s *raddr, + size_t buflen, FAR const struct sixlowpan_addr_s *raddr, uint16_t timeout); /**************************************************************************** @@ -381,7 +381,7 @@ int sixlowpan_frame_submit(FAR struct ieee802154_driver_s *ieee, int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, FAR const struct ipv6_hdr_s *ipv6hdr, FAR const void *buf, size_t buflen, - FAR const struct rimeaddr_s *destmac); + FAR const struct sixlowpan_addr_s *destmac); /**************************************************************************** * Name: sixlowpan_hc06_initialize @@ -437,7 +437,7 @@ void sixlowpan_hc06_initialize(void); #ifdef CONFIG_NET_6LOWPAN_COMPRESSION_HC06 void sixlowpan_compresshdr_hc06(FAR struct ieee802154_driver_s *ieee, FAR const struct ipv6_hdr_s *ipv6, - FAR const struct rimeaddr_s *destmac, + FAR const struct sixlowpan_addr_s *destmac, FAR uint8_t *fptr); #endif @@ -498,7 +498,7 @@ void sixlowpan_uncompresshdr_hc06(uint16_t iplen, FAR struct iob_s *iob, #ifdef CONFIG_NET_6LOWPAN_COMPRESSION_HC1 void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee, FAR const struct ipv6_hdr_s *ipv6, - FAR const struct rimeaddr_s *destmac, + FAR const struct sixlowpan_addr_s *destmac, FAR uint8_t *fptr); #endif @@ -557,12 +557,12 @@ int sixlowpan_uncompresshdr_hc1(uint16_t iplen, FAR struct iob_s *iob, #define sixlowpan_islinklocal(ipaddr) ((ipaddr)[0] == NTOHS(0xfe80)) -void sixlowpan_ipfromrime(FAR const struct rimeaddr_s *rime, +void sixlowpan_ipfromrime(FAR const struct sixlowpan_addr_s *rime, net_ipv6addr_t ipaddr); void sixlowpan_rimefromip(const net_ipv6addr_t ipaddr, - FAR struct rimeaddr_s *rime); + FAR struct sixlowpan_addr_s *rime); bool sixlowpan_ismacbased(const net_ipv6addr_t ipaddr, - FAR const struct rimeaddr_s *rime); + FAR const struct sixlowpan_addr_s *rime); /**************************************************************************** * Name: sixlowpan_src_panid diff --git a/net/sixlowpan/sixlowpan_send.c b/net/sixlowpan/sixlowpan_send.c index 64b7088735e..e742acfe7dc 100644 --- a/net/sixlowpan/sixlowpan_send.c +++ b/net/sixlowpan/sixlowpan_send.c @@ -83,7 +83,7 @@ struct sixlowpan_send_s uint16_t s_timeout; /* Send timeout in deciseconds */ systime_t s_time; /* Last send time for determining timeout */ FAR const struct ipv6_hdr_s *s_ipv6hdr; /* IPv6 header, followed by UDP or TCP header. */ - FAR const struct rimeaddr_s *s_destmac; /* Destination MAC address */ + FAR const struct sixlowpan_addr_s *s_destmac; /* Destination MAC address */ FAR const void *s_buf; /* Data to send */ size_t s_len; /* Length of data in buf */ }; @@ -274,7 +274,7 @@ end_wait: int sixlowpan_send(FAR struct net_driver_s *dev, FAR struct devif_callback_s **list, FAR const struct ipv6_hdr_s *ipv6hdr, FAR const void *buf, - size_t len, FAR const struct rimeaddr_s *destmac, + size_t len, FAR const struct sixlowpan_addr_s *destmac, uint16_t timeout) { struct sixlowpan_send_s sinfo; diff --git a/net/sixlowpan/sixlowpan_tcpsend.c b/net/sixlowpan/sixlowpan_tcpsend.c index 2bb6c49130c..9091c040165 100644 --- a/net/sixlowpan/sixlowpan_tcpsend.c +++ b/net/sixlowpan/sixlowpan_tcpsend.c @@ -164,7 +164,7 @@ ssize_t psock_6lowpan_tcp_send(FAR struct socket *psock, FAR const void *buf, FAR struct tcp_conn_s *conn; FAR struct net_driver_s *dev; struct ipv6tcp_hdr_s ipv6tcp; - struct rimeaddr_s destmac; + struct sixlowpan_addr_s destmac; uint16_t timeout; uint16_t iplen; int ret; @@ -409,7 +409,7 @@ void sixlowpan_tcp_send(FAR struct net_driver_s *dev) } else { - struct rimeaddr_s destmac; + struct sixlowpan_addr_s destmac; FAR uint8_t *buf; uint16_t hdrlen; uint16_t buflen; diff --git a/net/sixlowpan/sixlowpan_udpsend.c b/net/sixlowpan/sixlowpan_udpsend.c index a29197eec70..2ab4286d8fa 100644 --- a/net/sixlowpan/sixlowpan_udpsend.c +++ b/net/sixlowpan/sixlowpan_udpsend.c @@ -162,7 +162,7 @@ ssize_t psock_6lowpan_udp_sendto(FAR struct socket *psock, FAR struct udp_conn_s *conn; FAR struct net_driver_s *dev; struct ipv6udp_hdr_s ipv6udp; - struct rimeaddr_s destmac; + struct sixlowpan_addr_s destmac; uint16_t iplen; uint16_t timeout; int ret; diff --git a/net/sixlowpan/sixlowpan_utils.c b/net/sixlowpan/sixlowpan_utils.c index 7e1a6ac2eed..072a1b26d61 100644 --- a/net/sixlowpan/sixlowpan_utils.c +++ b/net/sixlowpan/sixlowpan_utils.c @@ -80,7 +80,7 @@ * ****************************************************************************/ -void sixlowpan_ipfromrime(FAR const struct rimeaddr_s *rime, +void sixlowpan_ipfromrime(FAR const struct sixlowpan_addr_s *rime, net_ipv6addr_t ipaddr) { /* We consider only links with IEEE EUI-64 identifier or IEEE 48-bit MAC @@ -90,13 +90,13 @@ void sixlowpan_ipfromrime(FAR const struct rimeaddr_s *rime, memset(ipaddr, 0, sizeof(net_ipv6addr_t)); ipaddr[0] = HTONS(0xfe80); -#ifdef CONFIG_NET_6LOWPAN_RIMEADDR_EXTENDED - memcpy(&ipaddr[4], rime, NET_6LOWPAN_RIMEADDR_SIZE); +#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR + memcpy(&ipaddr[4], rime, NET_6LOWPAN_ADDRSIZE); ipaddr[4] ^= HTONS(0x0200); #else ipaddr[5] = HTONS(0x00ff); ipaddr[6] = HTONS(0xfe00); - memcpy(&ipaddr[7], rime, NET_6LOWPAN_RIMEADDR_SIZE); + memcpy(&ipaddr[7], rime, NET_6LOWPAN_ADDRSIZE); ipaddr[7] ^= HTONS(0x0200); #endif } @@ -115,16 +115,16 @@ void sixlowpan_ipfromrime(FAR const struct rimeaddr_s *rime, ****************************************************************************/ void sixlowpan_rimefromip(const net_ipv6addr_t ipaddr, - FAR struct rimeaddr_s *rime) + FAR struct sixlowpan_addr_s *rime) { /* REVISIT: See notes about 2 byte addresses in sixlowpan_ipfromrime() */ DEBUGASSERT(ipaddr[0] == HTONS(0xfe80)); -#ifdef CONFIG_NET_6LOWPAN_RIMEADDR_EXTENDED - memcpy(rime, &ipaddr[4], NET_6LOWPAN_RIMEADDR_SIZE); +#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR + memcpy(rime, &ipaddr[4], NET_6LOWPAN_ADDRSIZE); #else - memcpy(rime, &ipaddr[7], NET_6LOWPAN_RIMEADDR_SIZE); + memcpy(rime, &ipaddr[7], NET_6LOWPAN_ADDRSIZE); #endif rime->u8[0] ^= 0x02; } @@ -143,11 +143,11 @@ void sixlowpan_rimefromip(const net_ipv6addr_t ipaddr, ****************************************************************************/ bool sixlowpan_ismacbased(const net_ipv6addr_t ipaddr, - FAR const struct rimeaddr_s *rime) + FAR const struct sixlowpan_addr_s *rime) { FAR const uint8_t *rimeptr = rime->u8; -#ifdef CONFIG_NET_6LOWPAN_RIMEADDR_EXTENDED +#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR return (ipaddr[4] == htons((GETINT16(rimeptr, 0) ^ 0x0200)) && ipaddr[5] == GETINT16(rimeptr, 2) && ipaddr[6] == GETINT16(rimeptr, 4) && diff --git a/wireless/ieee802154/mac802154_loopback.c b/wireless/ieee802154/mac802154_loopback.c index c4cb8de1536..51780af2c49 100644 --- a/wireless/ieee802154/mac802154_loopback.c +++ b/wireless/ieee802154/mac802154_loopback.c @@ -350,7 +350,7 @@ static int lo_ifup(FAR struct net_driver_s *dev) dev->d_ipv6addr[3], dev->d_ipv6addr[4], dev->d_ipv6addr[5], dev->d_ipv6addr[6], dev->d_ipv6addr[7]); -#ifdef CONFIG_NET_6LOWPAN_RIMEADDR_EXTENDED +#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR ninfo(" Node: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x PANID=%04x\n", dev->d_mac.ieee802154.u8[0], dev->d_mac.ieee802154.u8[1], dev->d_mac.ieee802154.u8[2], dev->d_mac.ieee802154.u8[3], @@ -507,7 +507,7 @@ static int lo_txavail(FAR struct net_driver_s *dev) #if defined(CONFIG_NET_IGMP) || defined(CONFIG_NET_ICMPv6) static int lo_addmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac) { -#ifdef CONFIG_NET_6LOWPAN_RIMEADDR_EXTENDED +#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR ninfo("MAC: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], mac[6], mac[7]); #else @@ -542,7 +542,7 @@ static int lo_addmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac) #ifdef CONFIG_NET_IGMP static int lo_rmmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac) { -#ifdef CONFIG_NET_6LOWPAN_RIMEADDR_EXTENDED +#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR ninfo("MAC: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], mac[6], mac[7]); #else From 6f6e61769ac14817ed98d5514cb536366255d0e1 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 4 May 2017 09:05:41 -0600 Subject: [PATCH 130/183] 6loWPAN: Remove final references to Rime from code. --- include/nuttx/net/sixlowpan.h | 158 ++++++++++++++-------------- net/sixlowpan/Kconfig | 6 +- net/sixlowpan/README.txt | 32 +++--- net/sixlowpan/sixlowpan_framelist.c | 16 +-- net/sixlowpan/sixlowpan_framer.c | 16 +-- net/sixlowpan/sixlowpan_hc06.c | 6 +- net/sixlowpan/sixlowpan_hc1.c | 54 +++++----- net/sixlowpan/sixlowpan_input.c | 38 +++---- net/sixlowpan/sixlowpan_internal.h | 50 ++++----- net/sixlowpan/sixlowpan_tcpsend.c | 12 +-- net/sixlowpan/sixlowpan_udpsend.c | 6 +- net/sixlowpan/sixlowpan_utils.c | 52 ++++----- 12 files changed, 218 insertions(+), 228 deletions(-) diff --git a/include/nuttx/net/sixlowpan.h b/include/nuttx/net/sixlowpan.h index 94061a365ec..91869dd41f5 100644 --- a/include/nuttx/net/sixlowpan.h +++ b/include/nuttx/net/sixlowpan.h @@ -82,132 +82,132 @@ * bytes for all subsequent headers. */ -#define RIME_FRAG_DISPATCH_SIZE 0 /* 16 bit */ -#define RIME_FRAG_TAG 2 /* 16 bit */ -#define RIME_FRAG_OFFSET 4 /* 8 bit */ +#define SIXLOWPAN_FRAG_DISPATCH_SIZE 0 /* 16 bit */ +#define SIXLOWPAN_FRAG_TAG 2 /* 16 bit */ +#define SIXLOWPAN_FRAG_OFFSET 4 /* 8 bit */ -/* Define the Rime buffer as a byte array */ +/* Define the frame buffer as a byte array */ -#define RIME_HC1_DISPATCH 0 /* 8 bit */ -#define RIME_HC1_ENCODING 1 /* 8 bit */ -#define RIME_HC1_TTL 2 /* 8 bit */ +#define SIXLOWPAN_HC1_DISPATCH 0 /* 8 bit */ +#define SIXLOWPAN_HC1_ENCODING 1 /* 8 bit */ +#define SIXLOWPAN_HC1_TTL 2 /* 8 bit */ -#define RIME_HC1_HC_UDP_DISPATCH 0 /* 8 bit */ -#define RIME_HC1_HC_UDP_HC1_ENCODING 1 /* 8 bit */ -#define RIME_HC1_HC_UDP_UDP_ENCODING 2 /* 8 bit */ -#define RIME_HC1_HC_UDP_TTL 3 /* 8 bit */ -#define RIME_HC1_HC_UDP_PORTS 4 /* 8 bit */ -#define RIME_HC1_HC_UDP_CHKSUM 5 /* 16 bit */ +#define SIXLOWPAN_HC1_HC_UDP_DISPATCH 0 /* 8 bit */ +#define SIXLOWPAN_HC1_HC_UDP_HC1_ENCODING 1 /* 8 bit */ +#define SIXLOWPAN_HC1_HC_UDP_UDP_ENCODING 2 /* 8 bit */ +#define SIXLOWPAN_HC1_HC_UDP_TTL 3 /* 8 bit */ +#define SIXLOWPAN_HC1_HC_UDP_PORTS 4 /* 8 bit */ +#define SIXLOWPAN_HC1_HC_UDP_CHKSUM 5 /* 16 bit */ /* Min and Max compressible UDP ports - HC06 */ -#define SIXLOWPAN_UDP_4_BIT_PORT_MIN 0xf0b0 -#define SIXLOWPAN_UDP_4_BIT_PORT_MAX 0xf0bf /* f0b0 + 15 */ -#define SIXLOWPAN_UDP_8_BIT_PORT_MIN 0xf000 -#define SIXLOWPAN_UDP_8_BIT_PORT_MAX 0xf0ff /* f000 + 255 */ +#define SIXLOWPAN_UDP_4_BIT_PORT_MIN 0xf0b0 +#define SIXLOWPAN_UDP_4_BIT_PORT_MAX 0xf0bf /* f0b0 + 15 */ +#define SIXLOWPAN_UDP_8_BIT_PORT_MIN 0xf000 +#define SIXLOWPAN_UDP_8_BIT_PORT_MAX 0xf0ff /* f000 + 255 */ /* 6lowpan dispatches */ -#define SIXLOWPAN_DISPATCH_NALP 0x00 /* 00xxxxxx Not a LoWPAN packet */ -#define SIXLOWPAN_DISPATCH_NALP_MASK 0xc0 /* 11000000 */ +#define SIXLOWPAN_DISPATCH_NALP 0x00 /* 00xxxxxx Not a LoWPAN packet */ +#define SIXLOWPAN_DISPATCH_NALP_MASK 0xc0 /* 11000000 */ -#define SIXLOWPAN_DISPATCH_IPV6 0x41 /* 01000001 Uncompressed IPv6 addresses */ -#define SIXLOWPAN_DISPATCH_HC1 0x42 /* 01000010 HC1 Compressed IPv6 header */ -#define SIXLOWPAN_DISPATCH_BC0 0x50 /* 01010000 BC0 Broadcast header */ -#define SIXLOWPAN_DISPATCH_ESC 0x7f /* 01111111 Additional Dispatch octet follows */ +#define SIXLOWPAN_DISPATCH_IPV6 0x41 /* 01000001 Uncompressed IPv6 addresses */ +#define SIXLOWPAN_DISPATCH_HC1 0x42 /* 01000010 HC1 Compressed IPv6 header */ +#define SIXLOWPAN_DISPATCH_BC0 0x50 /* 01010000 BC0 Broadcast header */ +#define SIXLOWPAN_DISPATCH_ESC 0x7f /* 01111111 Additional Dispatch octet follows */ -#define SIXLOWPAN_DISPATCH_IPHC 0x60 /* 011xxxxx IP Header Compression (IPHC)*/ -#define SIXLOWPAN_DISPATCH_IPHC_MASK 0xe0 /* 11100000 */ +#define SIXLOWPAN_DISPATCH_IPHC 0x60 /* 011xxxxx IP Header Compression (IPHC)*/ +#define SIXLOWPAN_DISPATCH_IPHC_MASK 0xe0 /* 11100000 */ -#define SIXLOWPAN_DISPATCH_MESH 0x80 /* 10xxxxxx Mesh routing header */ -#define SIXLOWPAN_DISPATCH_MESH_MASK 0xc0 /* 11000000 */ +#define SIXLOWPAN_DISPATCH_MESH 0x80 /* 10xxxxxx Mesh routing header */ +#define SIXLOWPAN_DISPATCH_MESH_MASK 0xc0 /* 11000000 */ -#define SIXLOWPAN_DISPATCH_FRAG1 0xc0 /* 11000xxx Fragmentation header (first) */ -#define SIXLOWPAN_DISPATCH_FRAGN 0xe0 /* 11100xxx Fragmentation header (subsequent) */ -#define SIXLOWPAN_DISPATCH_FRAG_MASK 0xf8 /* 11111000 */ +#define SIXLOWPAN_DISPATCH_FRAG1 0xc0 /* 11000xxx Fragmentation header (first) */ +#define SIXLOWPAN_DISPATCH_FRAGN 0xe0 /* 11100xxx Fragmentation header (subsequent) */ +#define SIXLOWPAN_DISPATCH_FRAG_MASK 0xf8 /* 11111000 */ /* HC1 encoding */ -#define SIXLOWPAN_HC1_NH_UDP 0x02 -#define SIXLOWPAN_HC1_NH_TCP 0x06 -#define SIXLOWPAN_HC1_NH_ICMP6 0x04 +#define SIXLOWPAN_HC1_NH_UDP 0x02 +#define SIXLOWPAN_HC1_NH_TCP 0x06 +#define SIXLOWPAN_HC1_NH_ICMP6 0x04 /* HC_UDP encoding (works together with HC1) */ -#define SIXLOWPAN_HC_UDP_ALL_C 0xe0 +#define SIXLOWPAN_HC_UDP_ALL_C 0xe0 /* IPHC encoding * * Values of fields within the IPHC encoding first byte * (Using MS-to-LS bit numbering of the draft RFC) */ - /* Bits 0-2: 011 */ -#define SIXLOWPAN_IPHC_TC_MASK 0x18 /* Bits 3-4: Traffic Class, Flow Label */ -# define SIXLOWPAN_IPHC_TC_00 0x00 /* ECN+DSCP+4-bit Pad+Flow Label (4 bytes) */ -# define SIXLOWPAN_IPHC_TC_01 0x08 /* ECN+2-bit Pad+ Flow Label (3 bytes), DSCP is elided. */ -# define SIXLOWPAN_IPHC_TC_10 0x10 /* ECN+DSCP (1 byte), Flow Label is elided */ -# define SIXLOWPAN_IPHC_TC_11 0x11 /* Traffic Class and Flow Label are elided */ -#define SIXLOWPAN_IPHC_NH 0x04 /* Bit 5: Next Header Compressed */ -#define SIXLOWPAN_IPHC_HLIM_MASK 0x03 /* Bits 6-7: Hop Limit */ -# define SIXLOWPAN_IPHC_HLIM_INLINE 0x00 /* Carried in-line */ -# define SIXLOWPAN_IPHC_HLIM_1 0x01 /* Compressed hop limit of 1 */ -# define SIXLOWPAN_IPHC_HLIM_64 0x02 /* Compressed hop limit of 64 */ -# define SIXLOWPAN_IPHC_HLIM_255 0x03 /* Compressed hop limit of 255 */ + /* Bits 0-2: 011 */ +#define SIXLOWPAN_IPHC_TC_MASK 0x18 /* Bits 3-4: Traffic Class, Flow Label */ +# define SIXLOWPAN_IPHC_TC_00 0x00 /* ECN+DSCP+4-bit Pad+Flow Label (4 bytes) */ +# define SIXLOWPAN_IPHC_TC_01 0x08 /* ECN+2-bit Pad+ Flow Label (3 bytes), DSCP is elided. */ +# define SIXLOWPAN_IPHC_TC_10 0x10 /* ECN+DSCP (1 byte), Flow Label is elided */ +# define SIXLOWPAN_IPHC_TC_11 0x11 /* Traffic Class and Flow Label are elided */ +#define SIXLOWPAN_IPHC_NH 0x04 /* Bit 5: Next Header Compressed */ +#define SIXLOWPAN_IPHC_HLIM_MASK 0x03 /* Bits 6-7: Hop Limit */ +# define SIXLOWPAN_IPHC_HLIM_INLINE 0x00 /* Carried in-line */ +# define SIXLOWPAN_IPHC_HLIM_1 0x01 /* Compressed hop limit of 1 */ +# define SIXLOWPAN_IPHC_HLIM_64 0x02 /* Compressed hop limit of 64 */ +# define SIXLOWPAN_IPHC_HLIM_255 0x03 /* Compressed hop limit of 255 */ /* Values of fields within the IPHC encoding second byte */ -#define SIXLOWPAN_IPHC_CID 0x80 /* Bit 8: Context identifier extension */ -#define SIXLOWPAN_IPHC_SAC 0x40 /* Bit 9: Source address compression */ -#define SIXLOWPAN_IPHC_SAM_MASK 0x30 /* Bits 10-11: Source address mode */ -# define SIXLOWPAN_IPHC_SAM_128 0x00 /* 128-bits */ -# define SIXLOWPAN_IPHC_SAM_64 0x10 /* 64-bits */ -# define SIXLOWPAN_IPHC_SAM_16 0x20 /* 16-bits */ -# define SIXLOWPAN_IPHC_SAM_0 0x30 /* 0-bits */ -#define SIXLOWPAN_IPHC_M 0x08 /* Bit 12: Multicast compression */ -#define SIXLOWPAN_IPHC_DAC 0x04 /* Bit 13: Destination address compression */ -#define SIXLOWPAN_IPHC_DAM_MASK 0x03 /* Bits 14-15: Destination address mode */ -# define SIXLOWPAN_IPHC_DAM_128 0x00 /* 128-bits */ -# define SIXLOWPAN_IPHC_DAM_64 0x01 /* 64-bits */ -# define SIXLOWPAN_IPHC_DAM_16 0x02 /* 16-bits */ -# define SIXLOWPAN_IPHC_DAM_0 0x03 /* 0-bits */ +#define SIXLOWPAN_IPHC_CID 0x80 /* Bit 8: Context identifier extension */ +#define SIXLOWPAN_IPHC_SAC 0x40 /* Bit 9: Source address compression */ +#define SIXLOWPAN_IPHC_SAM_MASK 0x30 /* Bits 10-11: Source address mode */ +# define SIXLOWPAN_IPHC_SAM_128 0x00 /* 128-bits */ +# define SIXLOWPAN_IPHC_SAM_64 0x10 /* 64-bits */ +# define SIXLOWPAN_IPHC_SAM_16 0x20 /* 16-bits */ +# define SIXLOWPAN_IPHC_SAM_0 0x30 /* 0-bits */ +#define SIXLOWPAN_IPHC_M 0x08 /* Bit 12: Multicast compression */ +#define SIXLOWPAN_IPHC_DAC 0x04 /* Bit 13: Destination address compression */ +#define SIXLOWPAN_IPHC_DAM_MASK 0x03 /* Bits 14-15: Destination address mode */ +# define SIXLOWPAN_IPHC_DAM_128 0x00 /* 128-bits */ +# define SIXLOWPAN_IPHC_DAM_64 0x01 /* 64-bits */ +# define SIXLOWPAN_IPHC_DAM_16 0x02 /* 16-bits */ +# define SIXLOWPAN_IPHC_DAM_0 0x03 /* 0-bits */ -#define SIXLOWPAN_IPHC_SAM_BIT 4 -#define SIXLOWPAN_IPHC_DAM_BIT 0 +#define SIXLOWPAN_IPHC_SAM_BIT 4 +#define SIXLOWPAN_IPHC_DAM_BIT 0 /* Link local context number */ -#define SIXLOWPAN_IPHC_ADDR_CONTEXT_LL 0 +#define SIXLOWPAN_IPHC_ADDR_CONTEXT_LL 0 /* 16-bit multicast addresses compression */ -#define SIXLOWPAN_IPHC_MCAST_RANGE 0xa0 +#define SIXLOWPAN_IPHC_MCAST_RANGE 0xa0 /* NHC_EXT_HDR */ -#define SIXLOWPAN_NHC_MASK 0xf0 -#define SIXLOWPAN_NHC_EXT_HDR 0xe0 +#define SIXLOWPAN_NHC_MASK 0xf0 +#define SIXLOWPAN_NHC_EXT_HDR 0xe0 /* LOWPAN_UDP encoding (works together with IPHC) */ -#define SIXLOWPAN_NHC_UDP_MASK 0xf8 -#define SIXLOWPAN_NHC_UDP_ID 0xf0 -#define SIXLOWPAN_NHC_UDP_CHECKSUMC 0x04 -#define SIXLOWPAN_NHC_UDP_CHECKSUMI 0x00 +#define SIXLOWPAN_NHC_UDP_MASK 0xf8 +#define SIXLOWPAN_NHC_UDP_ID 0xf0 +#define SIXLOWPAN_NHC_UDP_CHECKSUMC 0x04 +#define SIXLOWPAN_NHC_UDP_CHECKSUMI 0x00 /* Values for port compression, _with checksum_ ie bit 5 set to 0 */ -#define SIXLOWPAN_NHC_UDP_CS_P_00 0xf0 /* All inline */ -#define SIXLOWPAN_NHC_UDP_CS_P_01 0xf1 /* Source 16bit inline, dest = 0xf0 + 8 bit inline */ -#define SIXLOWPAN_NHC_UDP_CS_P_10 0xf2 /* Source = 0xf0 + 8bit inline, dest = 16 bit inline */ -#define SIXLOWPAN_NHC_UDP_CS_P_11 0xf3 /* Source & dest = 0xf0b + 4bit inline */ +#define SIXLOWPAN_NHC_UDP_CS_P_00 0xf0 /* All inline */ +#define SIXLOWPAN_NHC_UDP_CS_P_01 0xf1 /* Source 16bit inline, dest = 0xf0 + 8 bit inline */ +#define SIXLOWPAN_NHC_UDP_CS_P_10 0xf2 /* Source = 0xf0 + 8bit inline, dest = 16 bit inline */ +#define SIXLOWPAN_NHC_UDP_CS_P_11 0xf3 /* Source & dest = 0xf0b + 4bit inline */ /* The 6lowpan "headers" length */ -#define SIXLOWPAN_IPV6_HDR_LEN 1 /* One byte */ -#define SIXLOWPAN_HC1_HDR_LEN 3 -#define SIXLOWPAN_HC1_HC_UDP_HDR_LEN 7 -#define SIXLOWPAN_FRAG1_HDR_LEN 4 -#define SIXLOWPAN_FRAGN_HDR_LEN 5 +#define SIXLOWPAN_IPV6_HDR_LEN 1 /* One byte */ +#define SIXLOWPAN_HC1_HDR_LEN 3 +#define SIXLOWPAN_HC1_HC_UDP_HDR_LEN 7 +#define SIXLOWPAN_FRAG1_HDR_LEN 4 +#define SIXLOWPAN_FRAGN_HDR_LEN 5 /* Address compressibility test macros **************************************/ diff --git a/net/sixlowpan/Kconfig b/net/sixlowpan/Kconfig index 4b1c4df409d..d7c709c311e 100644 --- a/net/sixlowpan/Kconfig +++ b/net/sixlowpan/Kconfig @@ -134,12 +134,12 @@ endif # NET_6LOWPAN_MAXADDRCONTEXT_PREINIT_0 endif # NET_6LOWPAN_COMPRESSION_HC06 config NET_6LOWPAN_EXTENDEDADDR - bool "Extended Rime address" + bool "Extended IEEE 802.15.4 address" default n ---help--- - By default, a 2-byte Rime address is used for the IEEE802.15.4 MAC + By default, a 2-byte short address is used for the IEEE802.15.4 MAC device's link layer address. If this option is selected, then an - 8-byte Rime address will be used. + 8-byte extended address will be used. config NET_6LOWPAN_MAXAGE int "Packet reassembly timeout" diff --git a/net/sixlowpan/README.txt b/net/sixlowpan/README.txt index 5b6b4e298d2..9eb848144e8 100644 --- a/net/sixlowpan/README.txt +++ b/net/sixlowpan/README.txt @@ -10,12 +10,12 @@ Optimal 6loWPAN Configuration 128 112 96 80 64 48 32 16 ---- ---- ---- ---- ---- ---- ---- ---- - AAAA xxxx xxxx xxxx xxxx 00ff fe00 MMMM 2-byte Rime address IEEE 48-bit MAC - AAAA 0000 0000 0000 NNNN NNNN NNNN NNNN 8-byte Rime address IEEE EUI-64 + AAAA xxxx xxxx xxxx xxxx 00ff fe00 MMMM 2-byte short address IEEE 48-bit MAC + AAAA 0000 0000 0000 NNNN NNNN NNNN NNNN 8-byte extended address IEEE EUI-64 - Where MMM is the 2-byte rime address XORed 0x0200. For example, the MAC + Where MMM is the 2-byte short address XORed 0x0200. For example, the MAC address of 0xabcd would be 0xa9cd. And NNNN NNNN NNNN NNNN is the 8-byte - rime address address XOR 02000 0000 0000 0000. + extended address address XOR 02000 0000 0000 0000. For link-local address, AAAA is 0xfe80 @@ -23,8 +23,8 @@ Optimal 6loWPAN Configuration 128 112 96 80 64 48 32 16 ---- ---- ---- ---- ---- ---- ---- ---- - fe80 0000 0000 0000 0000 00ff fe00 MMMM 2-byte Rime address IEEE 48-bit MAC - fe80 0000 0000 0000 NNNN NNNN NNNN NNNN 8-byte Rime address IEEE EUI-64 + fe80 0000 0000 0000 0000 00ff fe00 MMMM 2-byte short address IEEE 48-bit MAC + fe80 0000 0000 0000 NNNN NNNN NNNN NNNN 8-byte extended address IEEE EUI-64 4. Compressable port numbers in the rangs 0xf0b0-0xf0bf @@ -52,11 +52,11 @@ this is a HC1 compressed first frame of a packet 41 88 2a cefa 3412 cdab ### 9-byte MAC header c50e 000b ### 4-byte FRAG1 header 42 ### SIXLOWPAN_DISPATCH_HC1 - fb ### RIME_HC1_HC_UDP_HC1_ENCODING - e0 ### RIME_HC1_HC_UDP_UDP_ENCODING - 00 ### RIME_HC1_HC_UDP_TTL - 10 ### RIME_HC1_HC_UDP_PORTS - 0000 ### RIME_HC1_HC_UDP_CHKSUM + fb ### SIXLOWPAN_HC1_HC_UDP_HC1_ENCODING + e0 ### SIXLOWPAN_HC1_HC_UDP_UDP_ENCODING + 00 ### SIXLOWPAN_HC1_HC_UDP_TTL + 10 ### SIXLOWPAN_HC1_HC_UDP_PORTS + 0000 ### SIXLOWPAN_HC1_HC_UDP_CHKSUM 104 byte Payload follows: 4f4e452064617920 48656e6e792d7065 6e6e792077617320 7069636b696e6720 @@ -69,11 +69,11 @@ This is the second frame of the same transfer: 41 88 2b cefa 3412 cdab ### 9-byte MAC header e50e 000b 0d ### 5 byte FRAGN header 42 ### SIXLOWPAN_DISPATCH_HC1 - fb ### RIME_HC1_HC_UDP_HC1_ENCODING - e0 ### RIME_HC1_HC_UDP_UDP_ENCODING - 00 ### RIME_HC1_HC_UDP_TTL - 10 ### RIME_HC1_HC_UDP_PORTS - 0000 ### RIME_HC1_HC_UDP_CHKSUM + fb ### SIXLOWPAN_HC1_HC_UDP_HC1_ENCODING + e0 ### SIXLOWPAN_HC1_HC_UDP_UDP_ENCODING + 00 ### SIXLOWPAN_HC1_HC_UDP_TTL + 10 ### SIXLOWPAN_HC1_HC_UDP_PORTS + 0000 ### SIXLOWPAN_HC1_HC_UDP_CHKSUM 104 byte Payload follows: 476f6f646e657373 2067726163696f75 73206d6521272073 6169642048656e6e diff --git a/net/sixlowpan/sixlowpan_framelist.c b/net/sixlowpan/sixlowpan_framelist.c index 013f7cbb7e6..005473c4e05 100644 --- a/net/sixlowpan/sixlowpan_framelist.c +++ b/net/sixlowpan/sixlowpan_framelist.c @@ -231,7 +231,7 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, g_uncomp_hdrlen = 0; g_frame_hdrlen = 0; - /* Reset rime buffer, packet buffer metatadata */ + /* Reset address buffer and packet buffer metatadata */ memset(g_pktattrs, 0, PACKETBUF_NUM_ATTRS * sizeof(uint16_t)); memset(g_pktaddrs, 0, PACKETBUF_NUM_ADDRS * sizeof(struct sixlowpan_addr_s)); @@ -286,9 +286,9 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, /* Set the source and destination address */ - rimeaddr_copy(&g_pktaddrs[PACKETBUF_ADDR_SENDER], + sixlowpan_addrcopy(&g_pktaddrs[PACKETBUF_ADDR_SENDER], &ieee->i_dev.d_mac.ieee802154); - rimeaddr_copy(&g_pktaddrs[PACKETBUF_ADDR_RECEIVER], destmac); + sixlowpan_addrcopy(&g_pktaddrs[PACKETBUF_ADDR_RECEIVER], destmac); /* Get the destination PAN ID. * @@ -400,9 +400,9 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, */ pktlen = buflen + g_uncomp_hdrlen; - PUTINT16(fragptr, RIME_FRAG_DISPATCH_SIZE, + PUTINT16(fragptr, SIXLOWPAN_FRAG_DISPATCH_SIZE, ((SIXLOWPAN_DISPATCH_FRAG1 << 8) | pktlen)); - PUTINT16(fragptr, RIME_FRAG_TAG, ieee->i_dgramtag); + PUTINT16(fragptr, SIXLOWPAN_FRAG_TAG, ieee->i_dgramtag); g_frame_hdrlen += SIXLOWPAN_FRAG1_HDR_LEN; @@ -469,10 +469,10 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, /* Setup up the FRAGN header after the frame header. */ - PUTINT16(fragptr, RIME_FRAG_DISPATCH_SIZE, + PUTINT16(fragptr, SIXLOWPAN_FRAG_DISPATCH_SIZE, ((SIXLOWPAN_DISPATCH_FRAGN << 8) | pktlen)); - PUTINT16(fragptr, RIME_FRAG_TAG, ieee->i_dgramtag); - fragptr[RIME_FRAG_OFFSET] = outlen >> 3; + PUTINT16(fragptr, SIXLOWPAN_FRAG_TAG, ieee->i_dgramtag); + fragptr[SIXLOWPAN_FRAG_OFFSET] = outlen >> 3; fragn_hdrlen += SIXLOWPAN_FRAGN_HDR_LEN; diff --git a/net/sixlowpan/sixlowpan_framer.c b/net/sixlowpan/sixlowpan_framer.c index e8b68eede40..49b1548498e 100644 --- a/net/sixlowpan/sixlowpan_framer.c +++ b/net/sixlowpan/sixlowpan_framer.c @@ -70,8 +70,8 @@ * Name: sixlowpan_addrnull * * Description: - * If the output address is NULL in the Rime buf, then it is broadcast - * on the 802.15.4 network. + * If the output address is NULL in the MAC header buf, then it is + * broadcast on the 802.15.4 network. * * Input parameters: * addrmode - The address mode @@ -138,8 +138,8 @@ int sixlowpan_meta_data(uint16_t dest_panid, meta->fcf.frame_type = FRAME802154_DATAFRAME; meta->fcf.frame_pending = g_pktattrs[PACKETBUF_ATTR_PENDING]; - /* If the output address is NULL in the Rime buf, then it is broadcast - * on the 802.15.4 network. + /* If the output address is NULL in the MAC header buf, then it is + * broadcast on the 802.15.4 network. */ rcvrnull = sixlowpan_addrnull(g_pktaddrs[PACKETBUF_ADDR_RECEIVER].u8); @@ -163,8 +163,8 @@ int sixlowpan_meta_data(uint16_t dest_panid, meta->src_pid = src_panid; meta->dest_pid = dest_panid; - /* If the output address is NULL in the Rime buf, then it is broadcast - * on the 802.15.4 network. + /* If the output address is NULL in the MAC header buf, then it is + * broadcast on the 802.15.4 network. */ if (rcvrnull) @@ -179,7 +179,7 @@ int sixlowpan_meta_data(uint16_t dest_panid, { /* Copy the destination address */ - rimeaddr_copy((struct sixlowpan_addr_s *)&meta->dest_addr, + sixlowpan_addrcopy((struct sixlowpan_addr_s *)&meta->dest_addr, g_pktaddrs[PACKETBUF_ADDR_RECEIVER].u8); /* Use short destination address mode if so configured */ @@ -193,7 +193,7 @@ int sixlowpan_meta_data(uint16_t dest_panid, /* Set the source address to the node address assigned to the device */ - rimeaddr_copy((struct sixlowpan_addr_s *)&meta->src_addr, + sixlowpan_addrcopy((struct sixlowpan_addr_s *)&meta->src_addr, &ieee->i_dev.d_mac.ieee802154); /* Use short soruce address mode if so configured */ diff --git a/net/sixlowpan/sixlowpan_hc06.c b/net/sixlowpan/sixlowpan_hc06.c index 751daf4dc88..2a262f5b53b 100644 --- a/net/sixlowpan/sixlowpan_hc06.c +++ b/net/sixlowpan/sixlowpan_hc06.c @@ -316,7 +316,7 @@ static void uncompress_addr(FAR net_ipv6addr_t ipaddr, uint8_t const prefix[], { /* No IID based configuration if no prefix and no data => unspec */ - sixlowpan_ipfromrime(macaddr, ipaddr); + sixlowpan_ipfromaddr(macaddr, ipaddr); } ninfo("Uncompressing %d + %d => %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n", @@ -828,8 +828,8 @@ void sixlowpan_compresshdr_hc06(FAR struct ieee802154_driver_s *ieee, * sixlowpan_buf * * This function is called by the input function when the dispatch is HC06. - * We process the packet in the rime buffer, uncompress the header fields, - * and copy the result in the sixlowpan buffer. At the end of the + * We process the frame in the IOB buffer, uncompress the header fields, + * and copy the result into the driver packet buffer. At the end of the * decompression, g_frame_hdrlen and g_uncompressed_hdrlen are set to the * appropriate values * diff --git a/net/sixlowpan/sixlowpan_hc1.c b/net/sixlowpan/sixlowpan_hc1.c index 5b8829745eb..d0e5b13d992 100644 --- a/net/sixlowpan/sixlowpan_hc1.c +++ b/net/sixlowpan/sixlowpan_hc1.c @@ -137,12 +137,12 @@ void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee, { /* IPV6 DISPATCH * Something cannot be compressed, use IPV6 DISPATCH, compress - * nothing, copy IPv6 header in rime buffer + * nothing, copy IPv6 header into the frame buffer */ /* IPv6 dispatch header (1 byte) */ - hc1[RIME_HC1_DISPATCH] = SIXLOWPAN_DISPATCH_IPV6; + hc1[SIXLOWPAN_HC1_DISPATCH] = SIXLOWPAN_DISPATCH_IPV6; g_frame_hdrlen += SIXLOWPAN_IPV6_HDR_LEN; memcpy(fptr + g_frame_hdrlen, ipv6, IPv6_HDRLEN); @@ -156,15 +156,15 @@ void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee, * header is UDP, we compress UDP header using HC2 */ - hc1[RIME_HC1_DISPATCH] = SIXLOWPAN_DISPATCH_HC1; + hc1[SIXLOWPAN_HC1_DISPATCH] = SIXLOWPAN_DISPATCH_HC1; g_uncomp_hdrlen += IPv6_HDRLEN; switch (ipv6->proto) { case IP_PROTO_ICMP6: /* HC1 encoding and ttl */ - hc1[RIME_HC1_ENCODING] = 0xfc; - hc1[RIME_HC1_TTL] = ipv6->ttl; + hc1[SIXLOWPAN_HC1_ENCODING] = 0xfc; + hc1[SIXLOWPAN_HC1_TTL] = ipv6->ttl; g_frame_hdrlen += SIXLOWPAN_HC1_HDR_LEN; break; @@ -172,8 +172,8 @@ void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee, case IP_PROTO_TCP: /* HC1 encoding and ttl */ - hc1[RIME_HC1_ENCODING] = 0xfe; - hc1[RIME_HC1_TTL] = ipv6->ttl; + hc1[SIXLOWPAN_HC1_ENCODING] = 0xfe; + hc1[SIXLOWPAN_HC1_TTL] = ipv6->ttl; g_frame_hdrlen += SIXLOWPAN_HC1_HDR_LEN; break; #endif /* CONFIG_NET_TCP */ @@ -201,17 +201,17 @@ void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee, /* HC1 encoding */ - hcudp[RIME_HC1_HC_UDP_HC1_ENCODING] = 0xfb; + hcudp[SIXLOWPAN_HC1_HC_UDP_HC1_ENCODING] = 0xfb; /* HC_UDP encoding, ttl, src and dest ports, checksum */ - hcudp[RIME_HC1_HC_UDP_UDP_ENCODING] = 0xe0; - hcudp[RIME_HC1_HC_UDP_TTL] = ipv6->ttl; - hcudp[RIME_HC1_HC_UDP_PORTS] = + hcudp[SIXLOWPAN_HC1_HC_UDP_UDP_ENCODING] = 0xe0; + hcudp[SIXLOWPAN_HC1_HC_UDP_TTL] = ipv6->ttl; + hcudp[SIXLOWPAN_HC1_HC_UDP_PORTS] = (uint8_t)((ntohs(udp->srcport) - CONFIG_NET_6LOWPAN_MINPORT) << 4) + (uint8_t)((ntohs(udp->destport) - CONFIG_NET_6LOWPAN_MINPORT)); - memcpy(&hcudp[RIME_HC1_HC_UDP_CHKSUM], &udp->udpchksum, 2); + memcpy(&hcudp[SIXLOWPAN_HC1_HC_UDP_CHKSUM], &udp->udpchksum, 2); g_frame_hdrlen += SIXLOWPAN_HC1_HC_UDP_HDR_LEN; g_uncomp_hdrlen += UDP_HDRLEN; @@ -220,8 +220,8 @@ void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee, { /* HC1 encoding and ttl */ - hc1[RIME_HC1_ENCODING] = 0xfa; - hc1[RIME_HC1_TTL] = ipv6->ttl; + hc1[SIXLOWPAN_HC1_ENCODING] = 0xfa; + hc1[SIXLOWPAN_HC1_TTL] = ipv6->ttl; g_frame_hdrlen += SIXLOWPAN_HC1_HDR_LEN; } } @@ -238,8 +238,8 @@ void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee, * Uncompress HC1 (and HC_UDP) headers and put them in sixlowpan_buf * * This function is called by the input function when the dispatch is - * HC1. It processes the packet in the rime buffer, uncompresses the - * header fields, and copies the result in the sixlowpan buffer. At the + * HC1. It processes the frame in the IOB buffer, uncompresses the + * header fields, and copies the result in the packet buffer. At the * end of the decompression, g_frame_hdrlen and uncompressed_hdr_len * are set to the appropriate values * @@ -275,26 +275,26 @@ int sixlowpan_uncompresshdr_hc1(uint16_t iplen, FAR struct iob_s *iob, * addresses. */ - sixlowpan_ipfromrime(&g_pktaddrs[PACKETBUF_ADDR_SENDER], + sixlowpan_ipfromaddr(&g_pktaddrs[PACKETBUF_ADDR_SENDER], ipv6->srcipaddr); - sixlowpan_ipfromrime(&g_pktaddrs[PACKETBUF_ADDR_RECEIVER], + sixlowpan_ipfromaddr(&g_pktaddrs[PACKETBUF_ADDR_RECEIVER], ipv6->destipaddr); g_uncomp_hdrlen += IPv6_HDRLEN; /* len[], proto, and ttl depend on the encoding */ - switch (hc1[RIME_HC1_ENCODING] & 0x06) + switch (hc1[SIXLOWPAN_HC1_ENCODING] & 0x06) { case SIXLOWPAN_HC1_NH_ICMP6: ipv6->proto = IP_PROTO_ICMP6; - ipv6->ttl = hc1[RIME_HC1_TTL]; + ipv6->ttl = hc1[SIXLOWPAN_HC1_TTL]; g_frame_hdrlen += SIXLOWPAN_HC1_HDR_LEN; break; #if CONFIG_NET_TCP case SIXLOWPAN_HC1_NH_TCP: ipv6->proto = IP_PROTO_TCP; - ipv6->ttl = hc1[RIME_HC1_TTL]; + ipv6->ttl = hc1[SIXLOWPAN_HC1_TTL]; g_frame_hdrlen += SIXLOWPAN_HC1_HDR_LEN; break; #endif /* CONFIG_NET_TCP */ @@ -306,11 +306,11 @@ int sixlowpan_uncompresshdr_hc1(uint16_t iplen, FAR struct iob_s *iob, FAR uint8_t *hcudp = fptr + g_frame_hdrlen; ipv6->proto = IP_PROTO_UDP; - if ((hcudp[RIME_HC1_HC_UDP_HC1_ENCODING] & 0x01) != 0) + if ((hcudp[SIXLOWPAN_HC1_HC_UDP_HC1_ENCODING] & 0x01) != 0) { /* UDP header is compressed with HC_UDP */ - if (hcudp[RIME_HC1_HC_UDP_UDP_ENCODING] != + if (hcudp[SIXLOWPAN_HC1_HC_UDP_UDP_ENCODING] != SIXLOWPAN_HC_UDP_ALL_C) { nwarn("WARNING: sixlowpan (uncompress_hdr), packet not supported"); @@ -319,16 +319,16 @@ int sixlowpan_uncompresshdr_hc1(uint16_t iplen, FAR struct iob_s *iob, /* IP TTL */ - ipv6->ttl = hcudp[RIME_HC1_HC_UDP_TTL]; + ipv6->ttl = hcudp[SIXLOWPAN_HC1_HC_UDP_TTL]; /* UDP ports, len, checksum */ udp->srcport = - htons(CONFIG_NET_6LOWPAN_MINPORT + (hcudp[RIME_HC1_HC_UDP_PORTS] >> 4)); + htons(CONFIG_NET_6LOWPAN_MINPORT + (hcudp[SIXLOWPAN_HC1_HC_UDP_PORTS] >> 4)); udp->destport = - htons(CONFIG_NET_6LOWPAN_MINPORT + (hcudp[RIME_HC1_HC_UDP_PORTS] & 0x0F)); + htons(CONFIG_NET_6LOWPAN_MINPORT + (hcudp[SIXLOWPAN_HC1_HC_UDP_PORTS] & 0x0F)); - memcpy(&udp->udpchksum, &hcudp[RIME_HC1_HC_UDP_CHKSUM], 2); + memcpy(&udp->udpchksum, &hcudp[SIXLOWPAN_HC1_HC_UDP_CHKSUM], 2); g_uncomp_hdrlen += UDP_HDRLEN; g_frame_hdrlen += SIXLOWPAN_HC1_HC_UDP_HDR_LEN; diff --git a/net/sixlowpan/sixlowpan_input.c b/net/sixlowpan/sixlowpan_input.c index dc45b3fdd00..7a2621cfbab 100644 --- a/net/sixlowpan/sixlowpan_input.c +++ b/net/sixlowpan/sixlowpan_input.c @@ -291,7 +291,7 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, */ fragptr = fptr + hdrsize; - switch ((GETINT16(fragptr, RIME_FRAG_DISPATCH_SIZE) & 0xf800) >> 8) + switch ((GETINT16(fragptr, SIXLOWPAN_FRAG_DISPATCH_SIZE) & 0xf800) >> 8) { /* First fragment of new reassembly */ @@ -299,8 +299,8 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, { /* Set up for the reassembly */ - fragsize = GETINT16(fragptr, RIME_FRAG_DISPATCH_SIZE) & 0x07ff; - fragtag = GETINT16(fragptr, RIME_FRAG_TAG); + fragsize = GETINT16(fragptr, SIXLOWPAN_FRAG_DISPATCH_SIZE) & 0x07ff; + fragtag = GETINT16(fragptr, SIXLOWPAN_FRAG_TAG); g_frame_hdrlen += SIXLOWPAN_FRAG1_HDR_LEN; ninfo("FRAG1: fragsize=%d fragtag=%d fragoffset=%d\n", @@ -317,9 +317,9 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, { /* Set offset, tag, size. Offset is in units of 8 bytes. */ - fragoffset = fragptr[RIME_FRAG_OFFSET]; - fragtag = GETINT16(fragptr, RIME_FRAG_TAG); - fragsize = GETINT16(fragptr, RIME_FRAG_DISPATCH_SIZE) & 0x07ff; + fragoffset = fragptr[SIXLOWPAN_FRAG_OFFSET]; + fragtag = GETINT16(fragptr, SIXLOWPAN_FRAG_TAG); + fragsize = GETINT16(fragptr, SIXLOWPAN_FRAG_DISPATCH_SIZE) & 0x07ff; g_frame_hdrlen += SIXLOWPAN_FRAGN_HDR_LEN; ninfo("FRAGN: fragsize=%d fragtag=%d fragoffset=%d\n", @@ -402,7 +402,7 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, /* Verify that this fragment is part of that reassembly sequence */ else if (fragsize != ieee->i_pktlen || ieee->i_reasstag != fragtag || - !rimeaddr_cmp(&ieee->i_fragsrc, &g_pktaddrs[PACKETBUF_ADDR_SENDER])) + !sixlowpan_addrcmp(&ieee->i_fragsrc, &g_pktaddrs[PACKETBUF_ADDR_SENDER])) { /* The packet is a fragment that does not belong to the packet * being reassembled or the packet is not a fragment. @@ -454,7 +454,7 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, ninfo("Starting reassembly: i_pktlen %u, i_reasstag %d\n", ieee->i_pktlen, ieee->i_reasstag); - rimeaddr_copy(&ieee->i_fragsrc, &g_pktaddrs[PACKETBUF_ADDR_SENDER]); + sixlowpan_addrcopy(&ieee->i_fragsrc, &g_pktaddrs[PACKETBUF_ADDR_SENDER]); } #endif /* CONFIG_NET_6LOWPAN_FRAG */ @@ -463,7 +463,7 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, hc1 = fptr + g_frame_hdrlen; #ifdef CONFIG_NET_6LOWPAN_COMPRESSION_HC06 - if ((hc1[RIME_HC1_DISPATCH] & SIXLOWPAN_DISPATCH_IPHC_MASK) == SIXLOWPAN_DISPATCH_IPHC) + if ((hc1[SIXLOWPAN_HC1_DISPATCH] & SIXLOWPAN_DISPATCH_IPHC_MASK) == SIXLOWPAN_DISPATCH_IPHC) { ninfo("IPHC Dispatch\n"); sixlowpan_uncompresshdr_hc06(fragsize, iob, fptr, bptr); @@ -472,7 +472,7 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, #endif /* CONFIG_NET_6LOWPAN_COMPRESSION_HC06 */ #ifdef CONFIG_NET_6LOWPAN_COMPRESSION_HC1 - if (hc1[RIME_HC1_DISPATCH] == SIXLOWPAN_DISPATCH_HC1) + if (hc1[SIXLOWPAN_HC1_DISPATCH] == SIXLOWPAN_DISPATCH_HC1) { ninfo("HC1 Dispatch\n"); sixlowpan_uncompresshdr_hc1(fragsize, iob, fptr, bptr); @@ -480,7 +480,7 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, else #endif /* CONFIG_NET_6LOWPAN_COMPRESSION_HC1 */ - if (hc1[RIME_HC1_DISPATCH] == SIXLOWPAN_DISPATCH_IPV6) + if (hc1[SIXLOWPAN_HC1_DISPATCH] == SIXLOWPAN_DISPATCH_IPV6) { ninfo("IPv6 Dispatch\n"); sixlowpan_uncompress_ipv6hdr(fptr, bptr); @@ -489,7 +489,7 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, { /* Unknown or unsupported header */ - nwarn("WARNING: Unknown dispatch: %u\n", hc1[RIME_HC1_DISPATCH]); + nwarn("WARNING: Unknown dispatch: %u\n", hc1[SIXLOWPAN_HC1_DISPATCH]); return OK; } @@ -519,10 +519,10 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, #endif /* CONFIG_NET_6LOWPAN_FRAG */ - /* Copy "payload" from the rime buffer to the IEEE802.15.4 MAC driver's - * d_buf. If this frame is a first fragment or not part of a fragmented - * packet, we have already copied the compressed headers, g_uncomp_hdrlen - * and g_frame_hdrlen are non-zerio, fragoffset is. + /* Copy "payload" from the frame buffer to the IEEE802.15.4 MAC driver's + * packet buffer, d_buf. If this frame is a first fragment or not part of + * a fragmented packet, we have already copied the compressed headers, + * g_uncomp_hdrlen and g_frame_hdrlen are non-zerio, fragoffset is. */ paysize = iob->io_len - g_frame_hdrlen; @@ -751,12 +751,12 @@ int sixlowpan_input(FAR struct ieee802154_driver_s *ieee, ipv6hdr = IPv6BUF(&ieee->i_dev); - /* Get the Rime MAC address of the destination. This - * assumes an encoding of the MAC address in the IPv6 + /* Get the IEEE 802.15.4 MAC address of the destination. + * This assumes an encoding of the MAC address in the IPv6 * address. */ - sixlowpan_rimefromip(ipv6hdr->destipaddr, &destmac); + sixlowpan_addrfromip(ipv6hdr->destipaddr, &destmac); /* The data payload should follow the IPv6 header plus * the protocol header. diff --git a/net/sixlowpan/sixlowpan_internal.h b/net/sixlowpan/sixlowpan_internal.h index 0a9cf07424a..aefe48b11b7 100644 --- a/net/sixlowpan/sixlowpan_internal.h +++ b/net/sixlowpan/sixlowpan_internal.h @@ -71,19 +71,17 @@ * Pre-processor Definitions ****************************************************************************/ -/* Rime addres macros */ -/* Copy a Rime address */ +/* IEEE 802.15.4 addres macros */ +/* Copy a an IEEE 802.15.4 address */ -#define rimeaddr_copy(dest,src) \ +#define sixlowpan_addrcopy(dest,src) \ memcpy(dest, src, NET_6LOWPAN_ADDRSIZE) -/* Compare two Rime addresses */ +/* Compare two IEEE 802.15.4 addresses */ -#define rimeaddr_cmp(addr1,addr2) \ +#define sixlowpan_addrcmp(addr1,addr2) \ (memcmp(addr1, addr2, NET_6LOWPAN_ADDRSIZE) == 0) -/* Pointers in the Rime buffer */ - /* Packet buffer Definitions */ #define PACKETBUF_ATTR_PACKET_TYPE_DATA 0 @@ -198,14 +196,6 @@ struct ipv6icmp_hdr_s * during that processing */ -/* A pointer to the rime buffer. - * - * We initialize it to the beginning of the rime buffer, then access - * different fields by updating the offset ieee->g_frame_hdrlen. - */ - -extern FAR uint8_t *g_rimeptr; - /* g_uncomp_hdrlen is the length of the headers before compression (if HC2 * is used this includes the UDP header in addition to the IP header). */ @@ -449,8 +439,8 @@ void sixlowpan_compresshdr_hc06(FAR struct ieee802154_driver_s *ieee, * sixlowpan_buf * * This function is called by the input function when the dispatch is HC06. - * We process the packet in the rime buffer, uncompress the header fields, - * and copy the result in the sixlowpan buffer. At the end of the + * We process the frame in the IOB buffer, uncompress the header fields, + * and copy the result into the driver packet buffer. At the end of the * decompression, g_frame_hdrlen and g_uncompressed_hdrlen are set to the * appropriate values * @@ -509,8 +499,8 @@ void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee, * Uncompress HC1 (and HC_UDP) headers and put them in sixlowpan_buf * * This function is called by the input function when the dispatch is - * HC1. It processes the packet in the rime buffer, uncompresses the - * header fields, and copies the result in the sixlowpan buffer. At the + * HC1. It processes the frame in the IOB buffer, uncompresses the + * header fields, and copies the result in the packet buffer. At the * end of the decompression, g_frame_hdrlen and uncompressed_hdr_len * are set to the appropriate values * @@ -535,34 +525,34 @@ int sixlowpan_uncompresshdr_hc1(uint16_t iplen, FAR struct iob_s *iob, #endif /**************************************************************************** - * Name: sixlowpan_islinklocal, sixlowpan_ipfromrime, sixlowpan_rimefromip, + * Name: sixlowpan_islinklocal, sixlowpan_ipfromaddr, sixlowpan_addrfromip, * and sixlowpan_ismacbased * * Description: - * sixlowpan_ipfromrime: Create a link local IPv6 address from a rime - * address. + * sixlowpan_ipfromaddr: Create a link local IPv6 address from an IEEE + * 802.15.4 address. * - * sixlowpan_rimefromip: Extract the rime address from a link local IPv6 - * address. + * sixlowpan_addrfromip: Extract the IEEE 802.15.14 address from a link + * local IPv6 address. * * sixlowpan_islinklocal and sixlowpan_ismacbased will return true for * address created in this fashion. * * 128 112 96 80 64 48 32 16 * ---- ---- ---- ---- ---- ---- ---- ---- - * fe80 0000 0000 0000 xxxx 0000 0000 0000 2-byte Rime address (VALID?) - * fe80 0000 0000 0000 xxxx xxxx xxxx xxxx 8-byte Rime address + * fe80 0000 0000 0000 xxxx 0000 0000 0000 2-byte short address (VALID?) + * fe80 0000 0000 0000 xxxx xxxx xxxx xxxx 8-byte extended address * ****************************************************************************/ #define sixlowpan_islinklocal(ipaddr) ((ipaddr)[0] == NTOHS(0xfe80)) -void sixlowpan_ipfromrime(FAR const struct sixlowpan_addr_s *rime, +void sixlowpan_ipfromaddr(FAR const struct sixlowpan_addr_s *addr, net_ipv6addr_t ipaddr); -void sixlowpan_rimefromip(const net_ipv6addr_t ipaddr, - FAR struct sixlowpan_addr_s *rime); +void sixlowpan_addrfromip(const net_ipv6addr_t ipaddr, + FAR struct sixlowpan_addr_s *addr); bool sixlowpan_ismacbased(const net_ipv6addr_t ipaddr, - FAR const struct sixlowpan_addr_s *rime); + FAR const struct sixlowpan_addr_s *addr); /**************************************************************************** * Name: sixlowpan_src_panid diff --git a/net/sixlowpan/sixlowpan_tcpsend.c b/net/sixlowpan/sixlowpan_tcpsend.c index 9091c040165..5e5d07bdfb8 100644 --- a/net/sixlowpan/sixlowpan_tcpsend.c +++ b/net/sixlowpan/sixlowpan_tcpsend.c @@ -317,11 +317,11 @@ ssize_t psock_6lowpan_tcp_send(FAR struct socket *psock, FAR const void *buf, psock->s_flags = _SS_SETSTATE(psock->s_flags, _SF_SEND); - /* Get the Rime MAC address of the destination This assumes an encoding - * of the MAC address in the IPv6 address. + /* Get the IEEE 802.15.4 MAC address of the destination. This assumes + * an encoding of the MAC address in the IPv6 address. */ - sixlowpan_rimefromip(conn->u.ipv6.raddr, &destmac); + sixlowpan_addrfromip(conn->u.ipv6.raddr, &destmac); /* If routable, then call sixlowpan_send() to format and send the 6loWPAN * packet. @@ -414,11 +414,11 @@ void sixlowpan_tcp_send(FAR struct net_driver_s *dev) uint16_t hdrlen; uint16_t buflen; - /* Get the Rime MAC address of the destination. This assumes an - * encoding of the MAC address in the IPv6 address. + /* Get the IEEE 802.15.4 MAC address of the destination. This + * assumes an encoding of the MAC address in the IPv6 address. */ - sixlowpan_rimefromip(ipv6hdr->ipv6.destipaddr, &destmac); + sixlowpan_addrfromip(ipv6hdr->ipv6.destipaddr, &destmac); /* Get the IPv6 + TCP combined header length. The size of the TCP * header is encoded in the top 4 bits of the tcpoffset field (in diff --git a/net/sixlowpan/sixlowpan_udpsend.c b/net/sixlowpan/sixlowpan_udpsend.c index 2ab4286d8fa..bbc39ef758a 100644 --- a/net/sixlowpan/sixlowpan_udpsend.c +++ b/net/sixlowpan/sixlowpan_udpsend.c @@ -292,11 +292,11 @@ ssize_t psock_6lowpan_udp_sendto(FAR struct socket *psock, psock->s_flags = _SS_SETSTATE(psock->s_flags, _SF_SEND); - /* Get the Rime MAC address of the destination This assumes an encoding - * of the MAC address in the IPv6 address. + /* Get the IEEE 802.15.4 MAC address of the destination This assumes an + * encoding of the MAC address in the IPv6 address. */ - sixlowpan_rimefromip(to6->sin6_addr.in6_u.u6_addr16, &destmac); + sixlowpan_addrfromip(to6->sin6_addr.in6_u.u6_addr16, &destmac); /* If routable, then call sixlowpan_send() to format and send the 6loWPAN * packet. diff --git a/net/sixlowpan/sixlowpan_utils.c b/net/sixlowpan/sixlowpan_utils.c index 072a1b26d61..e194786e3b6 100644 --- a/net/sixlowpan/sixlowpan_utils.c +++ b/net/sixlowpan/sixlowpan_utils.c @@ -68,19 +68,19 @@ ****************************************************************************/ /**************************************************************************** - * Name: sixlowpan_ipfromrime + * Name: sixlowpan_ipfromaddr * * Description: - * Create a link local IPv6 address from a rime address: + * Create a link local IPv6 address from an IEEE 802.15.4 address: * * 128 112 96 80 64 48 32 16 * ---- ---- ---- ---- ---- ---- ---- ---- - * fe80 0000 0000 0000 0000 00ff fe00 xxxx 2-byte Rime address IEEE 48-bit MAC - * fe80 0000 0000 0000 xxxx xxxx xxxx xxxx 8-byte Rime address IEEE EUI-64 + * fe80 0000 0000 0000 0000 00ff fe00 xxxx 2-byte address IEEE 48-bit MAC + * fe80 0000 0000 0000 xxxx xxxx xxxx xxxx 8-byte address IEEE EUI-64 * ****************************************************************************/ -void sixlowpan_ipfromrime(FAR const struct sixlowpan_addr_s *rime, +void sixlowpan_ipfromaddr(FAR const struct sixlowpan_addr_s *addr, net_ipv6addr_t ipaddr) { /* We consider only links with IEEE EUI-64 identifier or IEEE 48-bit MAC @@ -91,42 +91,42 @@ void sixlowpan_ipfromrime(FAR const struct sixlowpan_addr_s *rime, ipaddr[0] = HTONS(0xfe80); #ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR - memcpy(&ipaddr[4], rime, NET_6LOWPAN_ADDRSIZE); + memcpy(&ipaddr[4], addr, NET_6LOWPAN_ADDRSIZE); ipaddr[4] ^= HTONS(0x0200); #else ipaddr[5] = HTONS(0x00ff); ipaddr[6] = HTONS(0xfe00); - memcpy(&ipaddr[7], rime, NET_6LOWPAN_ADDRSIZE); + memcpy(&ipaddr[7], addr, NET_6LOWPAN_ADDRSIZE); ipaddr[7] ^= HTONS(0x0200); #endif } /**************************************************************************** - * Name: sixlowpan_rimefromip + * Name: sixlowpan_addrfromip * * Description: - * Extract the rime address from a link local IPv6 address: + * Extract the IEEE 802.15.4 address from a link local IPv6 address: * * 128 112 96 80 64 48 32 16 * ---- ---- ---- ---- ---- ---- ---- ---- - * fe80 0000 0000 0000 0000 00ff fe00 xxxx 2-byte Rime address IEEE 48-bit MAC - * fe80 0000 0000 0000 xxxx xxxx xxxx xxxx 8-byte Rime address IEEE EUI-64 + * fe80 0000 0000 0000 0000 00ff fe00 xxxx 2-byte short address IEEE 48-bit MAC + * fe80 0000 0000 0000 xxxx xxxx xxxx xxxx 8-byte extended address IEEE EUI-64 * ****************************************************************************/ -void sixlowpan_rimefromip(const net_ipv6addr_t ipaddr, - FAR struct sixlowpan_addr_s *rime) +void sixlowpan_addrfromip(const net_ipv6addr_t ipaddr, + FAR struct sixlowpan_addr_s *addr) { - /* REVISIT: See notes about 2 byte addresses in sixlowpan_ipfromrime() */ + /* REVISIT: See notes about 2 byte addresses in sixlowpan_ipfromaddr() */ DEBUGASSERT(ipaddr[0] == HTONS(0xfe80)); #ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR - memcpy(rime, &ipaddr[4], NET_6LOWPAN_ADDRSIZE); + memcpy(addr, &ipaddr[4], NET_6LOWPAN_ADDRSIZE); #else - memcpy(rime, &ipaddr[7], NET_6LOWPAN_ADDRSIZE); + memcpy(addr, &ipaddr[7], NET_6LOWPAN_ADDRSIZE); #endif - rime->u8[0] ^= 0x02; + addr->u8[0] ^= 0x02; } /**************************************************************************** @@ -137,24 +137,24 @@ void sixlowpan_rimefromip(const net_ipv6addr_t ipaddr, * * 128 112 96 80 64 48 32 16 * ---- ---- ---- ---- ---- ---- ---- ---- - * fe80 0000 0000 0000 0000 00ff fe00 xxxx 2-byte Rime address IEEE 48-bit MAC - * fe80 0000 0000 0000 xxxx xxxx xxxx xxxx 8-byte Rime address IEEE EUI-64 + * fe80 0000 0000 0000 0000 00ff fe00 xxxx 2-byte short address IEEE 48-bit MAC + * fe80 0000 0000 0000 xxxx xxxx xxxx xxxx 8-byte extended address IEEE EUI-64 * ****************************************************************************/ bool sixlowpan_ismacbased(const net_ipv6addr_t ipaddr, - FAR const struct sixlowpan_addr_s *rime) + FAR const struct sixlowpan_addr_s *addr) { - FAR const uint8_t *rimeptr = rime->u8; + FAR const uint8_t *byteptr = addr->u8; #ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR - return (ipaddr[4] == htons((GETINT16(rimeptr, 0) ^ 0x0200)) && - ipaddr[5] == GETINT16(rimeptr, 2) && - ipaddr[6] == GETINT16(rimeptr, 4) && - ipaddr[7] == GETINT16(rimeptr, 6)); + return (ipaddr[4] == htons((GETINT16(byteptr, 0) ^ 0x0200)) && + ipaddr[5] == GETINT16(byteptr, 2) && + ipaddr[6] == GETINT16(byteptr, 4) && + ipaddr[7] == GETINT16(byteptr, 6)); #else return (ipaddr[5] == HTONS(0x00ff) && ipaddr[6] == HTONS(0xfe00) && - ipaddr[7] == htons((GETINT16(rimeptr, 0) ^ 0x0200))); + ipaddr[7] == htons((GETINT16(byteptr, 0) ^ 0x0200))); #endif } From 1cf891bbe1c30496fe2c930ce0df257947f136e2 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 4 May 2017 11:33:22 -0600 Subject: [PATCH 131/183] Another baby step in removing MAC knowledge from 6loWPAN. --- include/nuttx/net/ieee802154.h | 44 ---------- include/nuttx/net/netdev.h | 4 +- include/nuttx/net/sixlowpan.h | 13 ++- net/sixlowpan/sixlowpan_framelist.c | 29 +++++-- net/sixlowpan/sixlowpan_framer.c | 103 +++++++++++++++++------ net/sixlowpan/sixlowpan_globals.c | 15 +++- net/sixlowpan/sixlowpan_hc06.c | 26 +++--- net/sixlowpan/sixlowpan_hc1.c | 8 -- net/sixlowpan/sixlowpan_input.c | 27 ++++-- net/sixlowpan/sixlowpan_internal.h | 53 +++++++++--- wireless/ieee802154/mac802154_loopback.c | 2 +- wireless/ieee802154/mac802154_netdev.c | 2 +- 12 files changed, 206 insertions(+), 120 deletions(-) diff --git a/include/nuttx/net/ieee802154.h b/include/nuttx/net/ieee802154.h index 9d9260f61b4..b6771957158 100644 --- a/include/nuttx/net/ieee802154.h +++ b/include/nuttx/net/ieee802154.h @@ -72,50 +72,6 @@ # define NET_6LOWPAN_ADDRSIZE NET_6LOWPAN_SADDRSIZE #endif -/* Frame format definitions *************************************************/ -/* These are some definitions of element values used in the FCF. See the - * IEEE802.15.4 spec for details. - */ - -#define FRAME802154_FRAMETYPE_SHIFT (0) /* Bits 0-2: Frame type */ -#define FRAME802154_FRAMETYPE_MASK (7 << FRAME802154_FRAMETYPE_SHIFT) -#define FRAME802154_SECENABLED_SHIFT (3) /* Bit 3: Security enabled */ -#define FRAME802154_FRAMEPENDING_SHIFT (4) /* Bit 4: Frame pending */ -#define FRAME802154_ACKREQUEST_SHIFT (5) /* Bit 5: ACK request */ -#define FRAME802154_PANIDCOMP_SHIFT (6) /* Bit 6: PANID compression */ - /* Bits 7-9: Reserved */ -#define FRAME802154_DSTADDR_SHIFT (2) /* Bits 10-11: Dest address mode */ -#define FRAME802154_DSTADDR_MASK (3 << FRAME802154_DSTADDR_SHIFT) -#define FRAME802154_VERSION_SHIFT (4) /* Bit 12-13: Frame version */ -#define FRAME802154_VERSION_MASK (3 << FRAME802154_VERSION_SHIFT) -#define FRAME802154_SRCADDR_SHIFT (6) /* Bits 14-15: Source address mode */ -#define FRAME802154_SRCADDR_MASK (3 << FRAME802154_SRCADDR_SHIFT) - -/* Unshifted values for use in struct frame802154_fcf_s */ - -#define FRAME802154_BEACONFRAME (0) -#define FRAME802154_DATAFRAME (1) -#define FRAME802154_ACKFRAME (2) -#define FRAME802154_CMDFRAME (3) - -#define FRAME802154_BEACONREQ (7) - -#define FRAME802154_IEEERESERVED (0) -#define FRAME802154_NOADDR (0) /* Only valid for ACK or Beacon frames */ -#define FRAME802154_SHORTADDRMODE (2) -#define FRAME802154_LONGADDRMODE (3) - -#define FRAME802154_NOBEACONS 0x0f - -#define FRAME802154_BROADCASTADDR 0xffff -#define FRAME802154_BROADCASTPANDID 0xffff - -#define FRAME802154_IEEE802154_2003 (0) -#define FRAME802154_IEEE802154_2006 (1) - -#define FRAME802154_SECURITY_LEVEL_NONE (0) -#define FRAME802154_SECURITY_LEVEL_128 (3) - /* This maximum size of an IEEE802.15.4 frame. Certain, non-standard * devices may exceed this value, however. */ diff --git a/include/nuttx/net/netdev.h b/include/nuttx/net/netdev.h index fe2743f5e97..0b65d2afd3d 100644 --- a/include/nuttx/net/netdev.h +++ b/include/nuttx/net/netdev.h @@ -437,9 +437,11 @@ int ipv6_input(FAR struct net_driver_s *dev); #ifdef CONFIG_NET_6LOWPAN struct ieee802154_driver_s; /* See sixlowpan.h */ +struct eee802154_data_ind_s; /* See sixlowpan.h */ struct iob_s; /* See iob.h */ int sixlowpan_input(FAR struct ieee802154_driver_s *ieee, - FAR struct iob_s *framelist); + FAR struct iob_s *framelist, + FAR const struct eee802154_data_ind_s *ind); #endif /**************************************************************************** diff --git a/include/nuttx/net/sixlowpan.h b/include/nuttx/net/sixlowpan.h index 91869dd41f5..48370a79e5a 100644 --- a/include/nuttx/net/sixlowpan.h +++ b/include/nuttx/net/sixlowpan.h @@ -342,6 +342,7 @@ */ struct ieee802154_frame_meta_s; /* Forward reference */ +struct eee802154_data_ind_s; /* Forward reference */ struct iob_s; /* Forward reference */ struct ieee802154_driver_s @@ -420,7 +421,7 @@ struct ieee802154_driver_s /* The source MAC address of the fragments being merged */ - struct sixlowpan_addr_s i_fragsrc; + union sixlowpan_anyaddr_u i_fragsrc; /* That time at which reassembly was started. If the elapsed time * exceeds CONFIG_NET_6LOWPAN_MAXAGE, then the reassembly will @@ -525,7 +526,12 @@ struct ieee802154_driver_s * * Input Parameters: * ieee - The IEEE802.15.4 MAC network driver interface. - * framelist - The head of an incoming list of frames. + * framelist - The head of an incoming list of frames. Normally this + * would be a single frame. A list may be provided if + * appropriate, however. + * ind - Meta data characterizing the received packet. If there are + * multilple frames in the list, this meta data must apply to + * all of the frames! * * Returned Value: * Ok is returned on success; Othewise a negated errno value is returned. @@ -533,7 +539,8 @@ struct ieee802154_driver_s ****************************************************************************/ int sixlowpan_input(FAR struct ieee802154_driver_s *ieee, - FAR struct iob_s *framelist); + FAR struct iob_s *framelist, + FAR const struct eee802154_data_ind_s *ind); #endif /* CONFIG_NET_6LOWPAN */ #endif /* __INCLUDE_NUTTX_NET_SIXLOWPAN_H */ diff --git a/net/sixlowpan/sixlowpan_framelist.c b/net/sixlowpan/sixlowpan_framelist.c index 005473c4e05..46e2bd750de 100644 --- a/net/sixlowpan/sixlowpan_framelist.c +++ b/net/sixlowpan/sixlowpan_framelist.c @@ -234,7 +234,7 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, /* Reset address buffer and packet buffer metatadata */ memset(g_pktattrs, 0, PACKETBUF_NUM_ATTRS * sizeof(uint16_t)); - memset(g_pktaddrs, 0, PACKETBUF_NUM_ADDRS * sizeof(struct sixlowpan_addr_s)); + memset(&g_packet_meta, 0, sizeof(struct packet_metadata_s)); g_pktattrs[PACKETBUF_ATTR_MAX_MAC_TRANSMISSIONS] = CONFIG_NET_6LOWPAN_MAX_MACTRANSMITS; @@ -284,11 +284,30 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, ninfo("Sending packet length %d\n", buflen); - /* Set the source and destination address */ + /* Set the source and destination address. The source MAC address + * is a fixed size, determined by a configuration setting. The + * destination MAC address many be either short or extended. + */ - sixlowpan_addrcopy(&g_pktaddrs[PACKETBUF_ADDR_SENDER], - &ieee->i_dev.d_mac.ieee802154); - sixlowpan_addrcopy(&g_pktaddrs[PACKETBUF_ADDR_RECEIVER], destmac); +#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR + g_packet_meta.sextended = TRUE; + sixlowpan_eaddrcopy(g_packet_meta.source.eaddr.u8, + &ieee->i_dev.d_mac.ieee802154); +#else + sixlowpan_saddrcopy(g_packet_meta.source.saddr.u8, + &ieee->i_dev.d_mac.ieee802154); +#endif + + /* REVISIT: Destination MAC address could be of different size than + * the source MAC address. + */ + +#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR + g_packet_meta.dextended = TRUE; + sixlowpan_addrcopy(g_packet_meta.dest.eaddr.u8, destmac); +#else + sixlowpan_addrcopy(g_packet_meta.dest.saddr.u8, destmac); +#endif /* Get the destination PAN ID. * diff --git a/net/sixlowpan/sixlowpan_framer.c b/net/sixlowpan/sixlowpan_framer.c index 49b1548498e..db2ac6dfce4 100644 --- a/net/sixlowpan/sixlowpan_framer.c +++ b/net/sixlowpan/sixlowpan_framer.c @@ -67,27 +67,26 @@ ****************************************************************************/ /**************************************************************************** - * Name: sixlowpan_addrnull + * Name: sixlowpan_anyaddrnull * * Description: - * If the output address is NULL in the MAC header buf, then it is + * If the destination address is all zero in the MAC header buf, then it is * broadcast on the 802.15.4 network. * * Input parameters: - * addrmode - The address mode + * addr - The address to check + * addrlen - The length of the address in bytes * * Returned Value: - * The address length associated with the address mode. + * True if the address is all zero. * ****************************************************************************/ -static bool sixlowpan_addrnull(FAR uint8_t *addr) +static bool sixlowpan_anyaddrnull(FAR uint8_t *addr, uint8_t addrlen) { - int i = NET_6LOWPAN_ADDRSIZE; - - while (i-- > 0) + while (addrlen-- > 0) { - if (addr[i] != 0x00) + if (addr[addrlen] != 0x00) { return false; } @@ -96,6 +95,46 @@ static bool sixlowpan_addrnull(FAR uint8_t *addr) return true; } +/**************************************************************************** + * Name: sixlowpan_saddrnull + * + * Description: + * If the destination address is all zero in the MAC header buf, then it is + * broadcast on the 802.15.4 network. + * + * Input parameters: + * eaddr - The short address to check + * + * Returned Value: + * The address length associated with the address mode. + * + ****************************************************************************/ + +static inline bool sixlowpan_saddrnull(FAR uint8_t *saddr) +{ + return sixlowpan_anyaddrnull(saddr, NET_6LOWPAN_SADDRSIZE); +} + +/**************************************************************************** + * Name: sixlowpan_eaddrnull + * + * Description: + * If the destination address is all zero in the MAC header buf, then it is + * broadcast on the 802.15.4 network. + * + * Input parameters: + * eaddr - The extended address to check + * + * Returned Value: + * The address length associated with the address mode. + * + ****************************************************************************/ + +static inline bool sixlowpan_eaddrnull(FAR uint8_t *eaddr) +{ + return sixlowpan_anyaddrnull(eaddr, NET_6LOWPAN_EADDRSIZE); +} + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -142,7 +181,15 @@ int sixlowpan_meta_data(uint16_t dest_panid, * broadcast on the 802.15.4 network. */ - rcvrnull = sixlowpan_addrnull(g_pktaddrs[PACKETBUF_ADDR_RECEIVER].u8); + if (g_packet_meta.dextended != 0) + { + rcvrnull = sixlowpan_eaddrnull(g_packet_meta.dest.eaddr.u8); + } + else + { + rcvrnull = sixlowpan_saddrnull(g_packet_meta.dest.saddr.u8); + } + if (rcvrnull) { meta->fcf.ack_required = g_pktattrs[PACKETBUF_ATTR_MAC_ACK]; @@ -175,26 +222,30 @@ int sixlowpan_meta_data(uint16_t dest_panid, meta->dest_addr[0] = 0xff; meta->dest_addr[1] = 0xff; } + else if (g_packet_meta.dextended != 0) + { + meta->fcf.dest_addr_mode = FRAME802154_LONGADDRMODE; + sixlowpan_eaddrcopy((struct sixlowpan_addr_s *)&meta->dest_addr, + g_packet_meta.dest.eaddr.u8); + } else { - /* Copy the destination address */ - - sixlowpan_addrcopy((struct sixlowpan_addr_s *)&meta->dest_addr, - g_pktaddrs[PACKETBUF_ADDR_RECEIVER].u8); - - /* Use short destination address mode if so configured */ - -#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR - meta->fcf.dest_addr_mode = FRAME802154_LONGADDRMODE; -#else meta->fcf.dest_addr_mode = FRAME802154_SHORTADDRMODE; -#endif + sixlowpan_saddrcopy((struct sixlowpan_addr_s *)&meta->dest_addr, + g_packet_meta.dest.saddr.u8); } - /* Set the source address to the node address assigned to the device */ - - sixlowpan_addrcopy((struct sixlowpan_addr_s *)&meta->src_addr, - &ieee->i_dev.d_mac.ieee802154); +#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR + DEBUGASSERT(g_packet_meta.sextended != 0); + meta->fcf.src_addr_mode = FRAME802154_LONGADDRMODE; + sixlowpan_eaddrcopy((struct sixlowpan_addr_s *)&meta->src_addr, + g_packet_meta.source.eaddr.u8); +#else + DEBUGASSERT(g_packet_meta.sextended == 0); + meta->fcf.src_addr_mode = FRAME802154_SHORTADDRMODE; + sixlowpan_saddrcopy((struct sixlowpan_addr_s *)&meta->src_addr, + g_packet_meta.source.saddr.u8); +#endif /* Use short soruce address mode if so configured */ @@ -203,7 +254,7 @@ int sixlowpan_meta_data(uint16_t dest_panid, #else meta->fcf.src_addr_mode = FRAME802154_SHORTADDRMODE; #endif -#endif +#endif /* 0 */ #warning Missing logic return -ENOSYS; diff --git a/net/sixlowpan/sixlowpan_globals.c b/net/sixlowpan/sixlowpan_globals.c index 646e2fec219..c1f4f9ef500 100644 --- a/net/sixlowpan/sixlowpan_globals.c +++ b/net/sixlowpan/sixlowpan_globals.c @@ -67,9 +67,22 @@ uint8_t g_uncomp_hdrlen; uint8_t g_frame_hdrlen; +/* In order to provide a customizable IEEE 802.15.4 MAC header, a structure + * of meta data is passed to the MAC network driver, struct + * ieee802154_frame_meta_s. Many of the settings in this meta data are + * fixed, deterimined by the 6loWPAN configuration. Other settings depend + * on the protocol used in the current packet or on chacteristics of the + * destination node. + * + * The following structure is used to summarize those per-packet + * customizations and, along, with the fixed configuratin settings, + * determines the full form of that meta data. + */ + /* Packet buffer metadata: Attributes and addresses */ uint16_t g_pktattrs[PACKETBUF_NUM_ATTRS]; -struct sixlowpan_addr_s g_pktaddrs[PACKETBUF_NUM_ADDRS]; + +struct packet_metadata_s g_packet_meta; #endif /* CONFIG_NET_6LOWPAN */ diff --git a/net/sixlowpan/sixlowpan_hc06.c b/net/sixlowpan/sixlowpan_hc06.c index 2a262f5b53b..0413e834c9d 100644 --- a/net/sixlowpan/sixlowpan_hc06.c +++ b/net/sixlowpan/sixlowpan_hc06.c @@ -275,7 +275,7 @@ static uint8_t compress_addr_64(FAR const net_ipv6addr_t ipaddr, ****************************************************************************/ static void uncompress_addr(FAR net_ipv6addr_t ipaddr, uint8_t const prefix[], - uint8_t prefpost, FAR struct sixlowpan_addr_s *macaddr) + uint8_t prefpost) { uint8_t prefcount = prefpost >> 4; uint8_t postcount = prefpost & 0x0f; @@ -316,7 +316,7 @@ static void uncompress_addr(FAR net_ipv6addr_t ipaddr, uint8_t const prefix[], { /* No IID based configuration if no prefix and no data => unspec */ - sixlowpan_ipfromaddr(macaddr, ipaddr); + nwarn("WARNING: No IID based configuration\n") } ninfo("Uncompressing %d + %d => %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n", @@ -983,18 +983,22 @@ void sixlowpan_uncompresshdr_hc06(uint16_t iplen, FAR struct iob_s *iob, } } - /* If tmp == 0 we do not have a Address context and therefore no prefix */ + /* If tmp == 0 we do not have a address context and therefore no prefix */ + /* REVISIT: Source address may not be the same size as the destination + * address. + */ uncompress_addr(ipv6->srcipaddr, - tmp != 0 ? addrcontext->prefix : NULL, g_unc_ctxconf[tmp], - (FAR struct sixlowpan_addr_s *)&g_pktaddrs[PACKETBUF_ADDR_SENDER]); + tmp != 0 ? addrcontext->prefix : NULL, g_unc_ctxconf[tmp]); } else { /* No compression and link local */ + /* REVISIT: Source address may not be the same size as the destination + * address. + */ - uncompress_addr(ipv6->srcipaddr, g_llprefix, g_unc_llconf[tmp], - (FAR struct sixlowpan_addr_s *)&g_pktaddrs[PACKETBUF_ADDR_SENDER]); + uncompress_addr(ipv6->srcipaddr, g_llprefix, g_unc_llconf[tmp]); } /* Destination address */ @@ -1029,7 +1033,7 @@ void sixlowpan_uncompresshdr_hc06(uint16_t iplen, FAR struct iob_s *iob, g_hc06ptr++; } - uncompress_addr(ipv6->destipaddr, prefix, g_unc_mxconf[tmp], NULL); + uncompress_addr(ipv6->destipaddr, prefix, g_unc_mxconf[tmp]); } } else @@ -1052,15 +1056,13 @@ void sixlowpan_uncompresshdr_hc06(uint16_t iplen, FAR struct iob_s *iob, return; } - uncompress_addr(ipv6->destipaddr, addrcontext->prefix, g_unc_ctxconf[tmp], - (FAR struct sixlowpan_addr_s *)&g_pktaddrs[PACKETBUF_ADDR_RECEIVER]); + uncompress_addr(ipv6->destipaddr, addrcontext->prefix, g_unc_ctxconf[tmp]); } else { /* Not address context based => link local M = 0, DAC = 0 - same as SAC */ - uncompress_addr(ipv6->destipaddr, g_llprefix, g_unc_llconf[tmp], - (FAR struct sixlowpan_addr_s *)&g_pktaddrs[PACKETBUF_ADDR_RECEIVER]); + uncompress_addr(ipv6->destipaddr, g_llprefix, g_unc_llconf[tmp]); } } diff --git a/net/sixlowpan/sixlowpan_hc1.c b/net/sixlowpan/sixlowpan_hc1.c index d0e5b13d992..88d7f724122 100644 --- a/net/sixlowpan/sixlowpan_hc1.c +++ b/net/sixlowpan/sixlowpan_hc1.c @@ -271,14 +271,6 @@ int sixlowpan_uncompresshdr_hc1(uint16_t iplen, FAR struct iob_s *iob, ipv6->tcf = 0; /* Bits 0-3: traffic class (LS), 4-bits: flow label (MS) */ ipv6->flow = 0; /* 16-bit flow label (LS) */ - /* Use stateless auto-configuration to set source and destination IP - * addresses. - */ - - sixlowpan_ipfromaddr(&g_pktaddrs[PACKETBUF_ADDR_SENDER], - ipv6->srcipaddr); - sixlowpan_ipfromaddr(&g_pktaddrs[PACKETBUF_ADDR_RECEIVER], - ipv6->destipaddr); g_uncomp_hdrlen += IPv6_HDRLEN; /* len[], proto, and ttl depend on the encoding */ diff --git a/net/sixlowpan/sixlowpan_input.c b/net/sixlowpan/sixlowpan_input.c index 7a2621cfbab..58ee8af571e 100644 --- a/net/sixlowpan/sixlowpan_input.c +++ b/net/sixlowpan/sixlowpan_input.c @@ -401,8 +401,8 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, /* Verify that this fragment is part of that reassembly sequence */ - else if (fragsize != ieee->i_pktlen || ieee->i_reasstag != fragtag || - !sixlowpan_addrcmp(&ieee->i_fragsrc, &g_pktaddrs[PACKETBUF_ADDR_SENDER])) + else if (fragsize != ieee->i_pktlen || ieee->i_reasstag != fragtag /* || + !sixlowpan_addrcmp(&ieee->i_fragsrc, &ind->???) */) { /* The packet is a fragment that does not belong to the packet * being reassembled or the packet is not a fragment. @@ -454,7 +454,15 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, ninfo("Starting reassembly: i_pktlen %u, i_reasstag %d\n", ieee->i_pktlen, ieee->i_reasstag); - sixlowpan_addrcopy(&ieee->i_fragsrc, &g_pktaddrs[PACKETBUF_ADDR_SENDER]); + /* Extract the source address from the 'ind' meta data. NOTE that the + * size of the source address may be different that our local, destination + * address. + */ + +#warning Missing logic +#if 0 + sixlowpan_addrcopy(&ieee->i_fragsrc, ind->???]); +#endif } #endif /* CONFIG_NET_6LOWPAN_FRAG */ @@ -496,7 +504,6 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, #ifdef CONFIG_NET_6LOWPAN_FRAG /* Is this the first fragment is a sequence? */ - if (isfirstfrag) { /* Yes.. Remember the offset from the beginning of d_buf where we @@ -517,6 +524,8 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, g_uncomp_hdrlen = ieee->i_boffset; } + + #endif /* CONFIG_NET_6LOWPAN_FRAG */ /* Copy "payload" from the frame buffer to the IEEE802.15.4 MAC driver's @@ -686,7 +695,12 @@ static int sixlowpan_dispatch(FAR struct ieee802154_driver_s *ieee) * * Input Parameters: * ieee - The IEEE802.15.4 MAC network driver interface. - * framelist - The head of an incoming list of frames. + * framelist - The head of an incoming list of frames. Normally this + * would be a single frame. A list may be provided if + * appropriate, however. + * ind - Meta data characterizing the received packet. If there are + * multilple frames in the list, this meta data must apply to + * all of the frames! * * Returned Value: * Ok is returned on success; Othewise a negated errno value is returned. @@ -694,7 +708,8 @@ static int sixlowpan_dispatch(FAR struct ieee802154_driver_s *ieee) ****************************************************************************/ int sixlowpan_input(FAR struct ieee802154_driver_s *ieee, - FAR struct iob_s *framelist) + FAR struct iob_s *framelist, + FAR const struct eee802154_data_ind_s *ind) { int ret = -EINVAL; diff --git a/net/sixlowpan/sixlowpan_internal.h b/net/sixlowpan/sixlowpan_internal.h index aefe48b11b7..1720ddcdf4f 100644 --- a/net/sixlowpan/sixlowpan_internal.h +++ b/net/sixlowpan/sixlowpan_internal.h @@ -74,13 +74,31 @@ /* IEEE 802.15.4 addres macros */ /* Copy a an IEEE 802.15.4 address */ +#define sixlowpan_anyaddrcopy(dest,src,len) \ + memcpy(dest, src, len) + +#define sixlowpan_saddrcopy(dest,src) \ + sixlowpan_anyaddrcopy(dest,src,NET_6LOWPAN_SADDRSIZE) + +#define sixlowpan_aeddrcopy(dest,src) \ + sixlowpan_anyaddrcopy(dest,src,NET_6LOWPAN_EADDRSIZE) + #define sixlowpan_addrcopy(dest,src) \ - memcpy(dest, src, NET_6LOWPAN_ADDRSIZE) + sixlowpan_anyaddrcopy(dest,src,NET_6LOWPAN_ADDRSIZE) /* Compare two IEEE 802.15.4 addresses */ +#define sixlowpan_anyaddrcmp(addr1,addr2,len) \ + (memcmp(addr1, addr2, len) == 0) + +#define sixlowpan_saddrcmp(addr1,addr2) \ + sixlowpan_anyaddrcmp(addr1,addr2,NET_6LOWPAN_SADDRSIZE) + +#define sixlowpan_eaddrcmp(addr1,addr2) \ + sixlowpan_anyaddrcmp(addr1,addr2,NET_6LOWPAN_EADDRSIZE) + #define sixlowpan_addrcmp(addr1,addr2) \ - (memcmp(addr1, addr2, NET_6LOWPAN_ADDRSIZE) == 0) + sixlowpan_anyaddrcmp(addr1,addr2,NET_6LOWPAN_ADDRSIZE) /* Packet buffer Definitions */ @@ -127,15 +145,6 @@ #define PACKETBUF_NUM_ATTRS 23 -/* Addresses (indices into g_pktaddrs) */ - -#define PACKETBUF_ADDR_SENDER 0 -#define PACKETBUF_ADDR_RECEIVER 1 -#define PACKETBUF_ADDR_ESENDER 2 -#define PACKETBUF_ADDR_ERECEIVER 3 - -#define PACKETBUF_NUM_ADDRS 4 - /* General helper macros ****************************************************/ #define GETINT16(ptr,index) \ @@ -185,6 +194,26 @@ struct ipv6icmp_hdr_s struct icmpv6_iphdr_s icmp; }; +/* In order to provide a customizable IEEE 802.15.4 MAC header, a structure + * of meta data is passed to the MAC network driver, struct + * ieee802154_frame_meta_s. Many of the settings in this meta data are + * fixed, deterimined by the 6loWPAN configuration. Other settings depend + * on the protocol used in the current packet or on chacteristics of the + * destination node. + * + * The following structure is used to summarize those per-packet + * customizations and, along, with the fixed configuratin settings, + * determines the full form of that meta data. + */ + +struct packet_metadata_s +{ + uint8_t sextended : 1; /* Extended source address */ + uint8_t dextended : 1; /* Extended destination address */ + union sixlowpan_anyaddr_u source; /* Source IEEE 802.15.4 address */ + union sixlowpan_anyaddr_u dest; /* Destination IEEE 802.15.4 address */ +}; + /**************************************************************************** * Public Data ****************************************************************************/ @@ -212,7 +241,7 @@ extern uint8_t g_frame_hdrlen; /* Packet buffer metadata: Attributes and addresses */ extern uint16_t g_pktattrs[PACKETBUF_NUM_ATTRS]; -extern struct sixlowpan_addr_s g_pktaddrs[PACKETBUF_NUM_ADDRS]; +extern struct packet_metadata_s g_packet_meta; /**************************************************************************** * Public Types diff --git a/wireless/ieee802154/mac802154_loopback.c b/wireless/ieee802154/mac802154_loopback.c index 51780af2c49..8b0abaf5b5d 100644 --- a/wireless/ieee802154/mac802154_loopback.c +++ b/wireless/ieee802154/mac802154_loopback.c @@ -211,7 +211,7 @@ static int lo_loopback(FAR struct net_driver_s *dev) ninfo("Send frame %p to the network: Offset=%u Length=%u\n", iob, iob->io_offset, iob->io_len); - ret = sixlowpan_input(&priv->lo_ieee, iob); + ret = sixlowpan_input(&priv->lo_ieee, iob, NULL); /* Increment statistics */ diff --git a/wireless/ieee802154/mac802154_netdev.c b/wireless/ieee802154/mac802154_netdev.c index b81ad465bc0..bf4c9013cb0 100644 --- a/wireless/ieee802154/mac802154_netdev.c +++ b/wireless/ieee802154/mac802154_netdev.c @@ -718,7 +718,7 @@ static void macnet_receive(FAR struct macnet_driver_s *priv) /* Transfer the frame to the network logic */ - sixlowpan_input(&priv->md_dev, iob); + sixlowpan_input(&priv->md_dev, iob, NULL); } /**************************************************************************** From 920c0a2e50884ce11753d6a33849f5b58dac90eb Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 4 May 2017 12:06:28 -0600 Subject: [PATCH 132/183] One more baby step in removing MAC knowledge from 6loWPAN. --- net/sixlowpan/Kconfig | 1 + net/sixlowpan/sixlowpan_framelist.c | 11 +++--- net/sixlowpan/sixlowpan_framer.c | 4 +-- net/sixlowpan/sixlowpan_globals.c | 4 --- net/sixlowpan/sixlowpan_internal.h | 54 ++++++----------------------- 5 files changed, 17 insertions(+), 57 deletions(-) diff --git a/net/sixlowpan/Kconfig b/net/sixlowpan/Kconfig index d7c709c311e..674eff01f6e 100644 --- a/net/sixlowpan/Kconfig +++ b/net/sixlowpan/Kconfig @@ -151,6 +151,7 @@ config NET_6LOWPAN_MAXAGE config NET_6LOWPAN_MAX_MACTRANSMITS int "Max MAC transmissions" default 4 + range 1 255 ---help--- CONFIG_NET_6LOWPAN_MAX_MACTRANSMITS specifies how many times the MAC layer should resend packets if no link-layer ACK wasreceived. This diff --git a/net/sixlowpan/sixlowpan_framelist.c b/net/sixlowpan/sixlowpan_framelist.c index 46e2bd750de..048944d674f 100644 --- a/net/sixlowpan/sixlowpan_framelist.c +++ b/net/sixlowpan/sixlowpan_framelist.c @@ -231,13 +231,10 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, g_uncomp_hdrlen = 0; g_frame_hdrlen = 0; - /* Reset address buffer and packet buffer metatadata */ + /* Reset frame meta data */ - memset(g_pktattrs, 0, PACKETBUF_NUM_ATTRS * sizeof(uint16_t)); memset(&g_packet_meta, 0, sizeof(struct packet_metadata_s)); - - g_pktattrs[PACKETBUF_ATTR_MAX_MAC_TRANSMISSIONS] = - CONFIG_NET_6LOWPAN_MAX_MACTRANSMITS; + g_packet_meta.xmits = CONFIG_NET_6LOWPAN_MAX_MACTRANSMITS; /* Set stream mode for all TCP packets, except FIN packets. */ @@ -249,11 +246,11 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, if ((tcp->flags & TCP_FIN) == 0 && (tcp->flags & TCP_CTL) != TCP_ACK) { - g_pktattrs[PACKETBUF_ATTR_PACKET_TYPE] = PACKETBUF_ATTR_PACKET_TYPE_STREAM; + g_packet_meta.type = FRAME_ATTR_TYPE_STREAM; } else if ((tcp->flags & TCP_FIN) == TCP_FIN) { - g_pktattrs[PACKETBUF_ATTR_PACKET_TYPE] = PACKETBUF_ATTR_PACKET_TYPE_STREAM_END; + g_packet_meta.type = FRAME_ATTR_TYPE_STREAM_END; } } diff --git a/net/sixlowpan/sixlowpan_framer.c b/net/sixlowpan/sixlowpan_framer.c index db2ac6dfce4..f5c5c259663 100644 --- a/net/sixlowpan/sixlowpan_framer.c +++ b/net/sixlowpan/sixlowpan_framer.c @@ -175,7 +175,7 @@ int sixlowpan_meta_data(uint16_t dest_panid, /* Build the FCF (Only non-zero elements need to be initialized). */ meta->fcf.frame_type = FRAME802154_DATAFRAME; - meta->fcf.frame_pending = g_pktattrs[PACKETBUF_ATTR_PENDING]; + meta->fcf.frame_pending = g_packet_meta.pending; /* If the output address is NULL in the MAC header buf, then it is * broadcast on the 802.15.4 network. @@ -192,7 +192,7 @@ int sixlowpan_meta_data(uint16_t dest_panid, if (rcvrnull) { - meta->fcf.ack_required = g_pktattrs[PACKETBUF_ATTR_MAC_ACK]; + meta->fcf.ack_required = g_packet_meta.macack; } /* Insert IEEE 802.15.4 (2003) version bit. */ diff --git a/net/sixlowpan/sixlowpan_globals.c b/net/sixlowpan/sixlowpan_globals.c index c1f4f9ef500..7c5740df9e9 100644 --- a/net/sixlowpan/sixlowpan_globals.c +++ b/net/sixlowpan/sixlowpan_globals.c @@ -79,10 +79,6 @@ uint8_t g_frame_hdrlen; * determines the full form of that meta data. */ -/* Packet buffer metadata: Attributes and addresses */ - -uint16_t g_pktattrs[PACKETBUF_NUM_ATTRS]; - struct packet_metadata_s g_packet_meta; #endif /* CONFIG_NET_6LOWPAN */ diff --git a/net/sixlowpan/sixlowpan_internal.h b/net/sixlowpan/sixlowpan_internal.h index 1720ddcdf4f..7e3f45332a1 100644 --- a/net/sixlowpan/sixlowpan_internal.h +++ b/net/sixlowpan/sixlowpan_internal.h @@ -100,50 +100,13 @@ #define sixlowpan_addrcmp(addr1,addr2) \ sixlowpan_anyaddrcmp(addr1,addr2,NET_6LOWPAN_ADDRSIZE) -/* Packet buffer Definitions */ +/* Frame meta data definitions */ -#define PACKETBUF_ATTR_PACKET_TYPE_DATA 0 -#define PACKETBUF_ATTR_PACKET_TYPE_ACK 1 -#define PACKETBUF_ATTR_PACKET_TYPE_STREAM 2 -#define PACKETBUF_ATTR_PACKET_TYPE_STREAM_END 3 -#define PACKETBUF_ATTR_PACKET_TYPE_TIMESTAMP 4 - -/* Packet buffer attributes (indices into g_pktattrs) */ - -#define PACKETBUF_ATTR_NONE 0 - -/* Scope 0 attributes: used only on the local node. */ - -#define PACKETBUF_ATTR_CHANNEL 1 -#define PACKETBUF_ATTR_NETWORK_ID 2 -#define PACKETBUF_ATTR_LINK_QUALITY 3 -#define PACKETBUF_ATTR_RSSI 4 -#define PACKETBUF_ATTR_TIMESTAMP 5 -#define PACKETBUF_ATTR_RADIO_TXPOWER 6 -#define PACKETBUF_ATTR_LISTEN_TIME 7 -#define PACKETBUF_ATTR_TRANSMIT_TIME 8 -#define PACKETBUF_ATTR_MAX_MAC_TRANSMISSIONS 9 -#define PACKETBUF_ATTR_MAC_ACK 10 - -/* Scope 1 attributes: used between two neighbors only. */ - -#define PACKETBUF_ATTR_RELIABLE 11 -#define PACKETBUF_ATTR_PACKET_ID 12 -#define PACKETBUF_ATTR_PACKET_TYPE 13 -#define PACKETBUF_ATTR_REXMIT 14 -#define PACKETBUF_ATTR_MAX_REXMIT 15 -#define PACKETBUF_ATTR_NUM_REXMIT 16 -#define PACKETBUF_ATTR_PENDING 17 - -/* Scope 2 attributes: used between end-to-end nodes. */ - -#define PACKETBUF_ATTR_HOPS 18 -#define PACKETBUF_ATTR_TTL 19 -#define PACKETBUF_ATTR_EPACKET_ID 20 -#define PACKETBUF_ATTR_EPACKET_TYPE 21 -#define PACKETBUF_ATTR_ERELIABLE 22 - -#define PACKETBUF_NUM_ATTRS 23 +#define FRAME_ATTR_TYPE_DATA 0 +#define FRAME_ATTR_TYPE_ACK 1 +#define FRAME_ATTR_TYPE_STREAM 2 +#define FRAME_ATTR_TYPE_STREAM_END 3 +#define FRAME_ATTR_TYPE_TIMESTAMP 4 /* General helper macros ****************************************************/ @@ -208,8 +171,12 @@ struct ipv6icmp_hdr_s struct packet_metadata_s { + uint8_t type : 3; /* See FRAME_ATTR_TYPE_* definitons */ + uint8_t pending : 1; /* Pending attribute */ + uint8_t macack : 1; /* MAC ACK */ uint8_t sextended : 1; /* Extended source address */ uint8_t dextended : 1; /* Extended destination address */ + uint8_t xmits; /* Max MAC transmisstion */ union sixlowpan_anyaddr_u source; /* Source IEEE 802.15.4 address */ union sixlowpan_anyaddr_u dest; /* Destination IEEE 802.15.4 address */ }; @@ -240,7 +207,6 @@ extern uint8_t g_frame_hdrlen; /* Packet buffer metadata: Attributes and addresses */ -extern uint16_t g_pktattrs[PACKETBUF_NUM_ATTRS]; extern struct packet_metadata_s g_packet_meta; /**************************************************************************** From d385f461306a5977523e8a7447127d0bd55050d3 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 4 May 2017 13:19:11 -0600 Subject: [PATCH 133/183] 6loWPAN: The last vestiges of MAC header generate stripped out. --- .../wireless/ieee802154/ieee802154_mac.h | 2 +- net/sixlowpan/sixlowpan_framelist.c | 55 +++++++-- net/sixlowpan/sixlowpan_framer.c | 116 ++++++++---------- net/sixlowpan/sixlowpan_internal.h | 25 ++-- 4 files changed, 110 insertions(+), 88 deletions(-) diff --git a/include/nuttx/wireless/ieee802154/ieee802154_mac.h b/include/nuttx/wireless/ieee802154/ieee802154_mac.h index f91fbbceae4..93bd2ca76fe 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_mac.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_mac.h @@ -524,7 +524,7 @@ struct ieee802154_frame_meta_s uint8_t msdu_handle; /* Handle assoc. with MSDU */ /* Number of bytes contained in the MAC Service Data Unit (MSDU) - * to be transmitted by the MAC sublayer enitity + * to be transmitted by the MAC sublayer entity * Note: This could be a uint8_t but if anyone ever wants to use * non-standard frame lengths, they may want a length larger than * a uint8_t. diff --git a/net/sixlowpan/sixlowpan_framelist.c b/net/sixlowpan/sixlowpan_framelist.c index 048944d674f..9d5756ed8b2 100644 --- a/net/sixlowpan/sixlowpan_framelist.c +++ b/net/sixlowpan/sixlowpan_framelist.c @@ -218,7 +218,6 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, struct sixlowpan_addr_s bcastmac; uint16_t pktlen; uint16_t paysize; - uint16_t dest_panid; #ifdef CONFIG_NET_6LOWPAN_FRAG uint16_t outlen = 0; #endif @@ -238,6 +237,7 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, /* Set stream mode for all TCP packets, except FIN packets. */ +#if 0 /* Currently the frame type is always data */ if (destip->proto == IP_PROTO_TCP) { FAR const struct tcp_hdr_s *tcp = @@ -253,6 +253,7 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, g_packet_meta.type = FRAME_ATTR_TYPE_STREAM_END; } } +#endif /* The destination address will be tagged to each outbound packet. If the * argument destmac is NULL, we are sending a broadcast packet. @@ -312,14 +313,14 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, * PAN IDs are the same. */ - dest_panid = 0xffff; - (void)sixlowpan_src_panid(ieee, &dest_panid); + g_packet_meta.dpanid = 0xffff; + (void)sixlowpan_src_panid(ieee, &g_packet_meta.dpanid); /* Based on the collected attributes and addresses, construct the MAC meta * data structure that we need to interface with the IEEE802.15.4 MAC. */ - ret = sixlowpan_meta_data(dest_panid, &meta); + ret = sixlowpan_meta_data(ieee, &meta, 0); if (ret < 0) { nerr("ERROR: sixlowpan_meta_data() failed: %d\n", ret); @@ -528,14 +529,42 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, } /* Submit all of the fragments to the MAC. We send all frames back- - * to-back like this to eliminate any possible condition where some + * to-back like this to minimize any possible condition where some * frame which is not a fragment from this sequence from intervening. */ - ret = sixlowpan_frame_submit(ieee, &meta, qhead); - if (ret < 0) + paysize = 0; + for (iob = qhead; iob != NULL; iob = qhead) { - nerr("ERROR: sixlowpan_frame_submit() failed: %d\n", ret); + uint16_t newsize; + + /* Remove the IOB from the list */ + + qhead = iob->io_flink; + iob->io_flink = NULL; + + /* Re-construct the MAC meta data structure using the correct + * payload size for this frame (if it is different than the + * payload size of the previous frame). + */ + + newsize = iob->io_len - iob->io_offset; + if (newsize != paysize) + { + ret = sixlowpan_meta_data(ieee, &meta, newsize); + if (ret < 0) + { + nerr("ERROR: sixlowpan_meta_data() failed: %d\n", ret); + } + + paysize = newsize; + } + + ret = sixlowpan_frame_submit(ieee, &meta, iob); + if (ret < 0) + { + nerr("ERROR: sixlowpan_frame_submit() failed: %d\n", ret); + } } /* Update the datagram TAG value */ @@ -565,6 +594,16 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, sixlowpan_dumpbuffer("Outgoing frame", (FAR const uint8_t *)iob->io_data, iob->io_len); + /* Re-construct the MAC meta data structure using the correct payload + * size for this frame. + */ + + ret = sixlowpan_meta_data(ieee, &meta, iob->io_len - iob->io_offset); + if (ret < 0) + { + nerr("ERROR: sixlowpan_meta_data() failed: %d\n", ret); + } + /* Submit the frame to the MAC */ ret = sixlowpan_frame_submit(ieee, &meta, iob); diff --git a/net/sixlowpan/sixlowpan_framer.c b/net/sixlowpan/sixlowpan_framer.c index f5c5c259663..b750156d36c 100644 --- a/net/sixlowpan/sixlowpan_framer.c +++ b/net/sixlowpan/sixlowpan_framer.c @@ -147,9 +147,9 @@ static inline bool sixlowpan_eaddrnull(FAR uint8_t *eaddr) * data structure that we need to interface with the IEEE802.15.4 MAC. * * Input Parameters: - * dest_panid - PAN ID of the destination. May be 0xffff if the destination - * is not associated. - * meta - Location to return the corresponding meta data. + * ieee - IEEE 802.15.4 MAC driver state reference. + * meta - Location to return the corresponding meta data. + * paylen - The size of the data payload to be sent. * * Returned Value: * Ok is returned on success; Othewise a negated errno value is returned. @@ -159,105 +159,97 @@ static inline bool sixlowpan_eaddrnull(FAR uint8_t *eaddr) * ****************************************************************************/ -int sixlowpan_meta_data(uint16_t dest_panid, - FAR struct ieee802154_frame_meta_s *meta) +int sixlowpan_meta_data(FAR struct ieee802154_driver_s *ieee, + FAR struct ieee802154_frame_meta_s *meta, + uint16_t paylen) { -#if 0 /* To be provided */ - /* Set up the frame parameters */ - - uint16_t src_panid; bool rcvrnull; - /* Initialize all prameters to all zero */ + /* Initialize all settings to all zero */ memset(meta, 0, sizeof(struct ieee802154_frame_meta_s)); - /* Build the FCF (Only non-zero elements need to be initialized). */ + /* Source address mode */ - meta->fcf.frame_type = FRAME802154_DATAFRAME; - meta->fcf.frame_pending = g_packet_meta.pending; + meta->src_addr_mode = g_packet_meta.sextended != 0? + IEEE802154_ADDRMODE_EXTENDED : + IEEE802154_ADDRMODE_SHORT; - /* If the output address is NULL in the MAC header buf, then it is - * broadcast on the 802.15.4 network. - */ + /* Check for a broadcast destination address (all zero) */ if (g_packet_meta.dextended != 0) { + /* Extended destination address mode */ + rcvrnull = sixlowpan_eaddrnull(g_packet_meta.dest.eaddr.u8); } else { + /* Short destination address mode */ + rcvrnull = sixlowpan_saddrnull(g_packet_meta.dest.saddr.u8); } if (rcvrnull) { - meta->fcf.ack_required = g_packet_meta.macack; + meta->msdu_flags.ack_tx = TRUE; } - /* Insert IEEE 802.15.4 (2003) version bit. */ + /* Destination address */ - meta->fcf.frame_version = FRAME802154_IEEE802154_2003; - - /* Complete the addressing fields. */ - /* Get the source PAN ID from the IEEE802.15.4 radio driver */ - - src_panid = 0xffff; - (void)sixlowpan_src_panid(ieee, &src_panid); - - /* Set the source and destination PAN ID. */ - - meta->src_pid = src_panid; - meta->dest_pid = dest_panid; - - /* If the output address is NULL in the MAC header buf, then it is - * broadcast on the 802.15.4 network. + /* If the output address is NULL, then it is broadcast on the 802.15.4 + * network. */ if (rcvrnull) { /* Broadcast requires short address mode. */ - meta->fcf.dest_addr_mode = FRAME802154_SHORTADDRMODE; - meta->dest_addr[0] = 0xff; - meta->dest_addr[1] = 0xff; + meta->dest_addr.mode = IEEE802154_ADDRMODE_SHORT; + meta->dest_addr.saddr = 0; } else if (g_packet_meta.dextended != 0) { - meta->fcf.dest_addr_mode = FRAME802154_LONGADDRMODE; - sixlowpan_eaddrcopy((struct sixlowpan_addr_s *)&meta->dest_addr, - g_packet_meta.dest.eaddr.u8); + /* Extended destination address mode */ + + meta->dest_addr.mode = IEEE802154_ADDRMODE_EXTENDED; + sixlowpan_eaddrcopy(&meta->dest_addr.eaddr, g_packet_meta.dest.eaddr.u8); } else { - meta->fcf.dest_addr_mode = FRAME802154_SHORTADDRMODE; - sixlowpan_saddrcopy((struct sixlowpan_addr_s *)&meta->dest_addr, - g_packet_meta.dest.saddr.u8); + /* Short destination address mode */ + + meta->dest_addr.mode = IEEE802154_ADDRMODE_SHORT; + sixlowpan_saddrcopy(&meta->dest_addr.saddr, g_packet_meta.dest.saddr.u8); } -#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR - DEBUGASSERT(g_packet_meta.sextended != 0); - meta->fcf.src_addr_mode = FRAME802154_LONGADDRMODE; - sixlowpan_eaddrcopy((struct sixlowpan_addr_s *)&meta->src_addr, - g_packet_meta.source.eaddr.u8); -#else - DEBUGASSERT(g_packet_meta.sextended == 0); - meta->fcf.src_addr_mode = FRAME802154_SHORTADDRMODE; - sixlowpan_saddrcopy((struct sixlowpan_addr_s *)&meta->src_addr, - g_packet_meta.source.saddr.u8); + meta->dest_addr.panid = g_packet_meta.dpanid; + + /* Handle associated with MSDU. Will increment once per packet, not + * necesarily per frame: The MSDU handler will be used for each fragment + * of a disassembled packet. + */ + + meta->msdu_handle = ieee->i_msdu_handle++; + + /* Number of bytes contained in the MAC Service Data Unit (MSDU) */ + + meta->msdu_length = paylen; + + /* MSDU flags that may be non-zero */ + + +#ifdef CONFIG_IEEE802154_SECURITY +# warning CONFIG_IEEE802154_SECURITY not yet supported" +#endif + +#ifdef CONFIG_IEEE802154_UWB +# warning CONFIG_IEEE802154_UWB not yet supported" #endif - /* Use short soruce address mode if so configured */ + /* Ranging left zero */ -#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR - meta->fcf.src_addr_mode = FRAME802154_LONGADDRMODE; -#else - meta->fcf.src_addr_mode = FRAME802154_SHORTADDRMODE; -#endif -#endif /* 0 */ - -#warning Missing logic - return -ENOSYS; + return OK; } /**************************************************************************** diff --git a/net/sixlowpan/sixlowpan_internal.h b/net/sixlowpan/sixlowpan_internal.h index 7e3f45332a1..1e38d46b651 100644 --- a/net/sixlowpan/sixlowpan_internal.h +++ b/net/sixlowpan/sixlowpan_internal.h @@ -80,7 +80,7 @@ #define sixlowpan_saddrcopy(dest,src) \ sixlowpan_anyaddrcopy(dest,src,NET_6LOWPAN_SADDRSIZE) -#define sixlowpan_aeddrcopy(dest,src) \ +#define sixlowpan_eaddrcopy(dest,src) \ sixlowpan_anyaddrcopy(dest,src,NET_6LOWPAN_EADDRSIZE) #define sixlowpan_addrcopy(dest,src) \ @@ -100,14 +100,6 @@ #define sixlowpan_addrcmp(addr1,addr2) \ sixlowpan_anyaddrcmp(addr1,addr2,NET_6LOWPAN_ADDRSIZE) -/* Frame meta data definitions */ - -#define FRAME_ATTR_TYPE_DATA 0 -#define FRAME_ATTR_TYPE_ACK 1 -#define FRAME_ATTR_TYPE_STREAM 2 -#define FRAME_ATTR_TYPE_STREAM_END 3 -#define FRAME_ATTR_TYPE_TIMESTAMP 4 - /* General helper macros ****************************************************/ #define GETINT16(ptr,index) \ @@ -171,12 +163,10 @@ struct ipv6icmp_hdr_s struct packet_metadata_s { - uint8_t type : 3; /* See FRAME_ATTR_TYPE_* definitons */ - uint8_t pending : 1; /* Pending attribute */ - uint8_t macack : 1; /* MAC ACK */ uint8_t sextended : 1; /* Extended source address */ uint8_t dextended : 1; /* Extended destination address */ uint8_t xmits; /* Max MAC transmisstion */ + uint16_t dpanid; /* Destination PAN ID */ union sixlowpan_anyaddr_u source; /* Source IEEE 802.15.4 address */ union sixlowpan_anyaddr_u dest; /* Destination IEEE 802.15.4 address */ }; @@ -271,9 +261,9 @@ int sixlowpan_send(FAR struct net_driver_s *dev, * data structure that we need to interface with the IEEE802.15.4 MAC. * * Input Parameters: - * dest_panid - PAN ID of the destination. May be 0xffff if the destination - * is not associated. - * meta - Location to return the corresponding meta data. + * ieee - IEEE 802.15.4 MAC driver state reference. + * meta - Location to return the corresponding meta data. + * paylen - The size of the data payload to be sent. * * Returned Value: * Ok is returned on success; Othewise a negated errno value is returned. @@ -283,8 +273,9 @@ int sixlowpan_send(FAR struct net_driver_s *dev, * ****************************************************************************/ -int sixlowpan_meta_data(uint16_t dest_panid, - FAR struct ieee802154_frame_meta_s *meta); +int sixlowpan_meta_data(FAR struct ieee802154_driver_s *ieee, + FAR struct ieee802154_frame_meta_s *meta, + uint16_t paylen); /**************************************************************************** * Name: sixlowpan_frame_hdrlen From 128936d9a6f709fb055a3b17e660372b7a77cd50 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 4 May 2017 17:16:45 -0600 Subject: [PATCH 134/183] 6loWPAN: Design simplications; also remove unused utility function. --- net/sixlowpan/sixlowpan_framelist.c | 35 +++++++--------------------- net/sixlowpan/sixlowpan_hc06.c | 2 +- net/sixlowpan/sixlowpan_internal.h | 8 +------ net/sixlowpan/sixlowpan_utils.c | 36 ----------------------------- 4 files changed, 10 insertions(+), 71 deletions(-) diff --git a/net/sixlowpan/sixlowpan_framelist.c b/net/sixlowpan/sixlowpan_framelist.c index 9d5756ed8b2..9b522a5d719 100644 --- a/net/sixlowpan/sixlowpan_framelist.c +++ b/net/sixlowpan/sixlowpan_framelist.c @@ -317,7 +317,8 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, (void)sixlowpan_src_panid(ieee, &g_packet_meta.dpanid); /* Based on the collected attributes and addresses, construct the MAC meta - * data structure that we need to interface with the IEEE802.15.4 MAC. + * data structure that we need to interface with the IEEE802.15.4 MAC (we + * will update the MSDU payload size when the IOB has been setup). */ ret = sixlowpan_meta_data(ieee, &meta, 0); @@ -533,32 +534,18 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, * frame which is not a fragment from this sequence from intervening. */ - paysize = 0; for (iob = qhead; iob != NULL; iob = qhead) { - uint16_t newsize; - /* Remove the IOB from the list */ qhead = iob->io_flink; iob->io_flink = NULL; - /* Re-construct the MAC meta data structure using the correct - * payload size for this frame (if it is different than the - * payload size of the previous frame). - */ + /* Update the MSDU length in the metadata */ - newsize = iob->io_len - iob->io_offset; - if (newsize != paysize) - { - ret = sixlowpan_meta_data(ieee, &meta, newsize); - if (ret < 0) - { - nerr("ERROR: sixlowpan_meta_data() failed: %d\n", ret); - } + meta.msdu_length = iob->io_len - iob->io_offset; - paysize = newsize; - } + /* And submit the frame to the MAC */ ret = sixlowpan_frame_submit(ieee, &meta, iob); if (ret < 0) @@ -594,17 +581,11 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, sixlowpan_dumpbuffer("Outgoing frame", (FAR const uint8_t *)iob->io_data, iob->io_len); - /* Re-construct the MAC meta data structure using the correct payload - * size for this frame. - */ + /* Update the MSDU length in the metadata */ - ret = sixlowpan_meta_data(ieee, &meta, iob->io_len - iob->io_offset); - if (ret < 0) - { - nerr("ERROR: sixlowpan_meta_data() failed: %d\n", ret); - } + meta.msdu_length = iob->io_len - iob->io_offset; - /* Submit the frame to the MAC */ + /* And submit the frame to the MAC */ ret = sixlowpan_frame_submit(ieee, &meta, iob); if (ret < 0) diff --git a/net/sixlowpan/sixlowpan_hc06.c b/net/sixlowpan/sixlowpan_hc06.c index 0413e834c9d..8ee28332bc7 100644 --- a/net/sixlowpan/sixlowpan_hc06.c +++ b/net/sixlowpan/sixlowpan_hc06.c @@ -316,7 +316,7 @@ static void uncompress_addr(FAR net_ipv6addr_t ipaddr, uint8_t const prefix[], { /* No IID based configuration if no prefix and no data => unspec */ - nwarn("WARNING: No IID based configuration\n") + nwarn("WARNING: No IID based configuration\n"); } ninfo("Uncompressing %d + %d => %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n", diff --git a/net/sixlowpan/sixlowpan_internal.h b/net/sixlowpan/sixlowpan_internal.h index 1e38d46b651..276a4976521 100644 --- a/net/sixlowpan/sixlowpan_internal.h +++ b/net/sixlowpan/sixlowpan_internal.h @@ -511,13 +511,9 @@ int sixlowpan_uncompresshdr_hc1(uint16_t iplen, FAR struct iob_s *iob, #endif /**************************************************************************** - * Name: sixlowpan_islinklocal, sixlowpan_ipfromaddr, sixlowpan_addrfromip, - * and sixlowpan_ismacbased + * Name: sixlowpan_islinklocal, sixlowpan_addrfromip, and sixlowpan_ismacbased * * Description: - * sixlowpan_ipfromaddr: Create a link local IPv6 address from an IEEE - * 802.15.4 address. - * * sixlowpan_addrfromip: Extract the IEEE 802.15.14 address from a link * local IPv6 address. * @@ -533,8 +529,6 @@ int sixlowpan_uncompresshdr_hc1(uint16_t iplen, FAR struct iob_s *iob, #define sixlowpan_islinklocal(ipaddr) ((ipaddr)[0] == NTOHS(0xfe80)) -void sixlowpan_ipfromaddr(FAR const struct sixlowpan_addr_s *addr, - net_ipv6addr_t ipaddr); void sixlowpan_addrfromip(const net_ipv6addr_t ipaddr, FAR struct sixlowpan_addr_s *addr); bool sixlowpan_ismacbased(const net_ipv6addr_t ipaddr, diff --git a/net/sixlowpan/sixlowpan_utils.c b/net/sixlowpan/sixlowpan_utils.c index e194786e3b6..687a0bd7e4a 100644 --- a/net/sixlowpan/sixlowpan_utils.c +++ b/net/sixlowpan/sixlowpan_utils.c @@ -67,40 +67,6 @@ * Public Functions ****************************************************************************/ -/**************************************************************************** - * Name: sixlowpan_ipfromaddr - * - * Description: - * Create a link local IPv6 address from an IEEE 802.15.4 address: - * - * 128 112 96 80 64 48 32 16 - * ---- ---- ---- ---- ---- ---- ---- ---- - * fe80 0000 0000 0000 0000 00ff fe00 xxxx 2-byte address IEEE 48-bit MAC - * fe80 0000 0000 0000 xxxx xxxx xxxx xxxx 8-byte address IEEE EUI-64 - * - ****************************************************************************/ - -void sixlowpan_ipfromaddr(FAR const struct sixlowpan_addr_s *addr, - net_ipv6addr_t ipaddr) -{ - /* We consider only links with IEEE EUI-64 identifier or IEEE 48-bit MAC - * addresses. - */ - - memset(ipaddr, 0, sizeof(net_ipv6addr_t)); - ipaddr[0] = HTONS(0xfe80); - -#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR - memcpy(&ipaddr[4], addr, NET_6LOWPAN_ADDRSIZE); - ipaddr[4] ^= HTONS(0x0200); -#else - ipaddr[5] = HTONS(0x00ff); - ipaddr[6] = HTONS(0xfe00); - memcpy(&ipaddr[7], addr, NET_6LOWPAN_ADDRSIZE); - ipaddr[7] ^= HTONS(0x0200); -#endif -} - /**************************************************************************** * Name: sixlowpan_addrfromip * @@ -117,8 +83,6 @@ void sixlowpan_ipfromaddr(FAR const struct sixlowpan_addr_s *addr, void sixlowpan_addrfromip(const net_ipv6addr_t ipaddr, FAR struct sixlowpan_addr_s *addr) { - /* REVISIT: See notes about 2 byte addresses in sixlowpan_ipfromaddr() */ - DEBUGASSERT(ipaddr[0] == HTONS(0xfe80)); #ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR From 14fc1b2d390b0fca6b2cde837467994a0bee08b8 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 4 May 2017 19:17:38 -0600 Subject: [PATCH 135/183] 6loWPAN: Local MAC address is fixed by the configuration. The remote address be with short or extended. --- include/nuttx/net/ieee802154.h | 6 +++ include/nuttx/net/sixlowpan.h | 2 +- net/sixlowpan/sixlowpan_framelist.c | 37 +++++++------- net/sixlowpan/sixlowpan_hc06.c | 45 +++++++++++------ net/sixlowpan/sixlowpan_hc1.c | 2 +- net/sixlowpan/sixlowpan_input.c | 12 ++--- net/sixlowpan/sixlowpan_internal.h | 35 +++++++++---- net/sixlowpan/sixlowpan_send.c | 4 +- net/sixlowpan/sixlowpan_tcpsend.c | 4 +- net/sixlowpan/sixlowpan_udpsend.c | 2 +- net/sixlowpan/sixlowpan_utils.c | 77 ++++++++++++++++++++++------- 11 files changed, 151 insertions(+), 75 deletions(-) diff --git a/include/nuttx/net/ieee802154.h b/include/nuttx/net/ieee802154.h index b6771957158..736141a3515 100644 --- a/include/nuttx/net/ieee802154.h +++ b/include/nuttx/net/ieee802154.h @@ -100,6 +100,12 @@ union sixlowpan_anyaddr_u struct sixlowpan_eaddr_s eaddr; }; +struct sixlowpan_tagaddr_s +{ + bool extended; + union sixlowpan_anyaddr_u u; +}; + /* Represents the configured address size */ struct sixlowpan_addr_s diff --git a/include/nuttx/net/sixlowpan.h b/include/nuttx/net/sixlowpan.h index 48370a79e5a..591687bb1dc 100644 --- a/include/nuttx/net/sixlowpan.h +++ b/include/nuttx/net/sixlowpan.h @@ -228,7 +228,7 @@ #define SIXLOWPAN_IS_IID_16BIT_COMPRESSABLE(a) \ ((((a)[4]) == 0x0000) && (((a)[5]) == HTONS(0x00ff)) && \ - (((a)[6]) == 0xfe00)) + (((a)[6]) == HTONS(0xfe00))) /* Check whether the 9-bit group-id of the compressed multicast address is * known. It is true if the 9-bit group is the all nodes or all routers diff --git a/net/sixlowpan/sixlowpan_framelist.c b/net/sixlowpan/sixlowpan_framelist.c index 9b522a5d719..6f41a59210a 100644 --- a/net/sixlowpan/sixlowpan_framelist.c +++ b/net/sixlowpan/sixlowpan_framelist.c @@ -209,13 +209,13 @@ static void sixlowpan_compress_ipv6hdr(FAR const struct ipv6_hdr_s *ipv6hdr, int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, FAR const struct ipv6_hdr_s *destip, FAR const void *buf, size_t buflen, - FAR const struct sixlowpan_addr_s *destmac) + FAR const struct sixlowpan_tagaddr_s *destmac) { struct ieee802154_frame_meta_s meta; FAR struct iob_s *iob; FAR uint8_t *fptr; int framer_hdrlen; - struct sixlowpan_addr_s bcastmac; + struct sixlowpan_tagaddr_s bcastmac; uint16_t pktlen; uint16_t paysize; #ifdef CONFIG_NET_6LOWPAN_FRAG @@ -261,7 +261,7 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, if (destmac == NULL) { - memset(&bcastmac, 0, sizeof(struct sixlowpan_addr_s)); + memset(&bcastmac, 0, sizeof(struct sixlowpan_tagaddr_s)); destmac = &bcastmac; } @@ -296,16 +296,15 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, &ieee->i_dev.d_mac.ieee802154); #endif - /* REVISIT: Destination MAC address could be of different size than - * the source MAC address. - */ - -#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR - g_packet_meta.dextended = TRUE; - sixlowpan_addrcopy(g_packet_meta.dest.eaddr.u8, destmac); -#else - sixlowpan_addrcopy(g_packet_meta.dest.saddr.u8, destmac); -#endif + if (destmac->extended) + { + g_packet_meta.dextended = TRUE; + sixlowpan_eaddrcopy(g_packet_meta.dest.eaddr.u8, destmac->u.eaddr.u8); + } + else + { + sixlowpan_saddrcopy(g_packet_meta.dest.saddr.u8, destmac->u.saddr.u8); + } /* Get the destination PAN ID. * @@ -418,9 +417,9 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, */ pktlen = buflen + g_uncomp_hdrlen; - PUTINT16(fragptr, SIXLOWPAN_FRAG_DISPATCH_SIZE, - ((SIXLOWPAN_DISPATCH_FRAG1 << 8) | pktlen)); - PUTINT16(fragptr, SIXLOWPAN_FRAG_TAG, ieee->i_dgramtag); + PUTHOST16(fragptr, SIXLOWPAN_FRAG_DISPATCH_SIZE, + ((SIXLOWPAN_DISPATCH_FRAG1 << 8) | pktlen)); + PUTHOST16(fragptr, SIXLOWPAN_FRAG_TAG, ieee->i_dgramtag); g_frame_hdrlen += SIXLOWPAN_FRAG1_HDR_LEN; @@ -487,9 +486,9 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, /* Setup up the FRAGN header after the frame header. */ - PUTINT16(fragptr, SIXLOWPAN_FRAG_DISPATCH_SIZE, - ((SIXLOWPAN_DISPATCH_FRAGN << 8) | pktlen)); - PUTINT16(fragptr, SIXLOWPAN_FRAG_TAG, ieee->i_dgramtag); + PUTHOST16(fragptr, SIXLOWPAN_FRAG_DISPATCH_SIZE, + ((SIXLOWPAN_DISPATCH_FRAGN << 8) | pktlen)); + PUTHOST16(fragptr, SIXLOWPAN_FRAG_TAG, ieee->i_dgramtag); fragptr[SIXLOWPAN_FRAG_OFFSET] = outlen >> 3; fragn_hdrlen += SIXLOWPAN_FRAGN_HDR_LEN; diff --git a/net/sixlowpan/sixlowpan_hc06.c b/net/sixlowpan/sixlowpan_hc06.c index 8ee28332bc7..18d3ccf6969 100644 --- a/net/sixlowpan/sixlowpan_hc06.c +++ b/net/sixlowpan/sixlowpan_hc06.c @@ -220,7 +220,7 @@ static FAR struct sixlowpan_addrcontext_s * } /**************************************************************************** - * Name: compress_addr_64 + * Name: compress_tagaddr and compress_laddr * * Description: * Uncompress addresses based on a prefix and a postfix with zeroes in @@ -232,12 +232,12 @@ static FAR struct sixlowpan_addrcontext_s * * ****************************************************************************/ -static uint8_t compress_addr_64(FAR const net_ipv6addr_t ipaddr, - FAR const struct sixlowpan_addr_s *macaddr, +static uint8_t compress_tagaddr(FAR const net_ipv6addr_t ipaddr, + FAR const struct sixlowpan_tagaddr_s *macaddr, uint8_t bitpos) { - ninfo("ipaddr=%p macaddr=%p bitpos=%u g_hc06ptr=%p\n", - ipaddr, macaddr, bitpos, g_hc06ptr); + ninfo("ipaddr=%p macaddr=%p extended=%u bitpos=%u g_hc06ptr=%p\n", + ipaddr, macaddr, macaddr->extended, bitpos, g_hc06ptr); if (sixlowpan_ismacbased(ipaddr, macaddr)) { @@ -261,6 +261,23 @@ static uint8_t compress_addr_64(FAR const net_ipv6addr_t ipaddr, } } +static uint8_t compress_laddr(FAR const net_ipv6addr_t ipaddr, + FAR const struct sixlowpan_addr_s *macaddr, + uint8_t bitpos) +{ + struct sixlowpan_tagaddr_s tagaddr; + +#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR + tagaddr.extended = true; + sixlowpan_eaddrcopy(tagaddr.u.eaddr.u8, macaddr->u8); +#else + tagaddr.extended = false; + sixlowpan_saddrcopy(tagaddr.u.saddr.u8, macaddr->u8); +#endif + + return compress_tagaddr(ipaddr, &tagaddr, bitpos); +} + /**************************************************************************** * Name: uncompress_addr * @@ -446,7 +463,7 @@ void sixlowpan_hc06_initialize(void) void sixlowpan_compresshdr_hc06(FAR struct ieee802154_driver_s *ieee, FAR const struct ipv6_hdr_s *ipv6, - FAR const struct sixlowpan_addr_s *destmac, + FAR const struct sixlowpan_tagaddr_s *destmac, FAR uint8_t *fptr) { FAR uint8_t *iphc = fptr + g_frame_hdrlen; @@ -614,9 +631,9 @@ void sixlowpan_compresshdr_hc06(FAR struct ieee802154_driver_s *ieee, /* Compression compare with this nodes address (source) */ - iphc1 |= compress_addr_64(ipv6->srcipaddr, - &ieee->i_dev.d_mac.ieee802154, - SIXLOWPAN_IPHC_SAM_BIT); + iphc1 |= compress_laddr(ipv6->srcipaddr, + &ieee->i_dev.d_mac.ieee802154, + SIXLOWPAN_IPHC_SAM_BIT); } /* No address context found for this address */ @@ -625,9 +642,9 @@ void sixlowpan_compresshdr_hc06(FAR struct ieee802154_driver_s *ieee, ipv6->destipaddr[1] == 0 && ipv6->destipaddr[2] == 0 && ipv6->destipaddr[3] == 0) { - iphc1 |= compress_addr_64(ipv6->srcipaddr, - &ieee->i_dev.d_mac.ieee802154, - SIXLOWPAN_IPHC_SAM_BIT); + iphc1 |= compress_laddr(ipv6->srcipaddr, + &ieee->i_dev.d_mac.ieee802154, + SIXLOWPAN_IPHC_SAM_BIT); } else { @@ -701,7 +718,7 @@ void sixlowpan_compresshdr_hc06(FAR struct ieee802154_driver_s *ieee, /* Compession compare with link adress (destination) */ - iphc1 |= compress_addr_64(ipv6->destipaddr, destmac, + iphc1 |= compress_tagaddr(ipv6->destipaddr, destmac, SIXLOWPAN_IPHC_DAM_BIT); /* No address context found for this address */ @@ -710,7 +727,7 @@ void sixlowpan_compresshdr_hc06(FAR struct ieee802154_driver_s *ieee, ipv6->destipaddr[1] == 0 && ipv6->destipaddr[2] == 0 && ipv6->destipaddr[3] == 0) { - iphc1 |= compress_addr_64(ipv6->destipaddr, destmac, + iphc1 |= compress_tagaddr(ipv6->destipaddr, destmac, SIXLOWPAN_IPHC_DAM_BIT); } else diff --git a/net/sixlowpan/sixlowpan_hc1.c b/net/sixlowpan/sixlowpan_hc1.c index 88d7f724122..0168cb653b3 100644 --- a/net/sixlowpan/sixlowpan_hc1.c +++ b/net/sixlowpan/sixlowpan_hc1.c @@ -120,7 +120,7 @@ void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee, FAR const struct ipv6_hdr_s *ipv6, - FAR const struct sixlowpan_addr_s *destmac, + FAR const struct sixlowpan_tagaddr_s *destmac, FAR uint8_t *fptr) { FAR uint8_t *hc1 = fptr + g_frame_hdrlen; diff --git a/net/sixlowpan/sixlowpan_input.c b/net/sixlowpan/sixlowpan_input.c index 58ee8af571e..3c203d07a1b 100644 --- a/net/sixlowpan/sixlowpan_input.c +++ b/net/sixlowpan/sixlowpan_input.c @@ -291,7 +291,7 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, */ fragptr = fptr + hdrsize; - switch ((GETINT16(fragptr, SIXLOWPAN_FRAG_DISPATCH_SIZE) & 0xf800) >> 8) + switch ((GETHOST16(fragptr, SIXLOWPAN_FRAG_DISPATCH_SIZE) & 0xf800) >> 8) { /* First fragment of new reassembly */ @@ -299,8 +299,8 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, { /* Set up for the reassembly */ - fragsize = GETINT16(fragptr, SIXLOWPAN_FRAG_DISPATCH_SIZE) & 0x07ff; - fragtag = GETINT16(fragptr, SIXLOWPAN_FRAG_TAG); + fragsize = GETHOST16(fragptr, SIXLOWPAN_FRAG_DISPATCH_SIZE) & 0x07ff; + fragtag = GETHOST16(fragptr, SIXLOWPAN_FRAG_TAG); g_frame_hdrlen += SIXLOWPAN_FRAG1_HDR_LEN; ninfo("FRAG1: fragsize=%d fragtag=%d fragoffset=%d\n", @@ -318,8 +318,8 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, /* Set offset, tag, size. Offset is in units of 8 bytes. */ fragoffset = fragptr[SIXLOWPAN_FRAG_OFFSET]; - fragtag = GETINT16(fragptr, SIXLOWPAN_FRAG_TAG); - fragsize = GETINT16(fragptr, SIXLOWPAN_FRAG_DISPATCH_SIZE) & 0x07ff; + fragtag = GETHOST16(fragptr, SIXLOWPAN_FRAG_TAG); + fragsize = GETHOST16(fragptr, SIXLOWPAN_FRAG_DISPATCH_SIZE) & 0x07ff; g_frame_hdrlen += SIXLOWPAN_FRAGN_HDR_LEN; ninfo("FRAGN: fragsize=%d fragtag=%d fragoffset=%d\n", @@ -755,7 +755,7 @@ int sixlowpan_input(FAR struct ieee802154_driver_s *ieee, { FAR struct ipv6_hdr_s *ipv6hdr; FAR uint8_t *buffer; - struct sixlowpan_addr_s destmac; + struct sixlowpan_tagaddr_s destmac; size_t hdrlen; size_t buflen; diff --git a/net/sixlowpan/sixlowpan_internal.h b/net/sixlowpan/sixlowpan_internal.h index 276a4976521..c48b89929ff 100644 --- a/net/sixlowpan/sixlowpan_internal.h +++ b/net/sixlowpan/sixlowpan_internal.h @@ -102,9 +102,19 @@ /* General helper macros ****************************************************/ -#define GETINT16(ptr,index) \ +/* GET 16-bit data: source in network order, result in host order */ + +#define GETHOST16(ptr,index) \ ((((uint16_t)((ptr)[index])) << 8) | ((uint16_t)(((ptr)[(index) + 1])))) -#define PUTINT16(ptr,index,value) \ + +/* GET 16-bit data: source in network order, result in network order */ + +#define GETNET16(ptr,index) \ + ((((uint16_t)((ptr)[(index) + 1])) << 8) | ((uint16_t)(((ptr)[index])))) + +/* PUT 16-bit data: source in host order, result in newtwork order */ + +#define PUTHOST16(ptr,index,value) \ do \ { \ (ptr)[index] = ((uint16_t)(value) >> 8) & 0xff; \ @@ -211,7 +221,7 @@ struct net_driver_s; /* Forward reference */ struct ieee802154_driver_s; /* Forward reference */ struct devif_callback_s; /* Forward reference */ struct ipv6_hdr_s; /* Forward reference */ -struct sixlowpan_addr_s; /* Forward reference */ +struct sixlowpan_addr_s; /* Forward reference */ struct iob_s; /* Forward reference */ /**************************************************************************** @@ -232,7 +242,7 @@ struct iob_s; /* Forward reference */ * list - Head of callback list for send interrupt * ipv6hdr - IPv6 plus TCP or UDP headers. * buf - Data to send - * buflen - Length of data to send + * len - Length of data to send * raddr - The MAC address of the destination * timeout - Send timeout in deciseconds * @@ -250,7 +260,7 @@ struct iob_s; /* Forward reference */ int sixlowpan_send(FAR struct net_driver_s *dev, FAR struct devif_callback_s **list, FAR const struct ipv6_hdr_s *ipv6hdr, FAR const void *buf, - size_t buflen, FAR const struct sixlowpan_addr_s *raddr, + size_t len, FAR const struct sixlowpan_tagaddr_s *destmac, uint16_t timeout); /**************************************************************************** @@ -357,7 +367,7 @@ int sixlowpan_frame_submit(FAR struct ieee802154_driver_s *ieee, int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, FAR const struct ipv6_hdr_s *ipv6hdr, FAR const void *buf, size_t buflen, - FAR const struct sixlowpan_addr_s *destmac); + FAR const struct sixlowpan_tagaddr_s *destmac); /**************************************************************************** * Name: sixlowpan_hc06_initialize @@ -413,7 +423,7 @@ void sixlowpan_hc06_initialize(void); #ifdef CONFIG_NET_6LOWPAN_COMPRESSION_HC06 void sixlowpan_compresshdr_hc06(FAR struct ieee802154_driver_s *ieee, FAR const struct ipv6_hdr_s *ipv6, - FAR const struct sixlowpan_addr_s *destmac, + FAR const struct sixlowpan_tagaddr_s *destmac, FAR uint8_t *fptr); #endif @@ -474,7 +484,7 @@ void sixlowpan_uncompresshdr_hc06(uint16_t iplen, FAR struct iob_s *iob, #ifdef CONFIG_NET_6LOWPAN_COMPRESSION_HC1 void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee, FAR const struct ipv6_hdr_s *ipv6, - FAR const struct sixlowpan_addr_s *destmac, + FAR const struct sixlowpan_tagaddr_s *destmac, FAR uint8_t *fptr); #endif @@ -529,10 +539,15 @@ int sixlowpan_uncompresshdr_hc1(uint16_t iplen, FAR struct iob_s *iob, #define sixlowpan_islinklocal(ipaddr) ((ipaddr)[0] == NTOHS(0xfe80)) +void sixlowpan_saddrfromip(const net_ipv6addr_t ipaddr, + FAR struct sixlowpan_saddr_s *saddr); +void sixlowpan_eaddrfromip(const net_ipv6addr_t ipaddr, + FAR struct sixlowpan_eaddr_s *eaddr); void sixlowpan_addrfromip(const net_ipv6addr_t ipaddr, - FAR struct sixlowpan_addr_s *addr); + FAR struct sixlowpan_tagaddr_s *addr); + bool sixlowpan_ismacbased(const net_ipv6addr_t ipaddr, - FAR const struct sixlowpan_addr_s *addr); + FAR const struct sixlowpan_tagaddr_s *addr); /**************************************************************************** * Name: sixlowpan_src_panid diff --git a/net/sixlowpan/sixlowpan_send.c b/net/sixlowpan/sixlowpan_send.c index e742acfe7dc..db8337834cc 100644 --- a/net/sixlowpan/sixlowpan_send.c +++ b/net/sixlowpan/sixlowpan_send.c @@ -83,7 +83,7 @@ struct sixlowpan_send_s uint16_t s_timeout; /* Send timeout in deciseconds */ systime_t s_time; /* Last send time for determining timeout */ FAR const struct ipv6_hdr_s *s_ipv6hdr; /* IPv6 header, followed by UDP or TCP header. */ - FAR const struct sixlowpan_addr_s *s_destmac; /* Destination MAC address */ + FAR const struct sixlowpan_tagaddr_s *s_destmac; /* Destination MAC address */ FAR const void *s_buf; /* Data to send */ size_t s_len; /* Length of data in buf */ }; @@ -274,7 +274,7 @@ end_wait: int sixlowpan_send(FAR struct net_driver_s *dev, FAR struct devif_callback_s **list, FAR const struct ipv6_hdr_s *ipv6hdr, FAR const void *buf, - size_t len, FAR const struct sixlowpan_addr_s *destmac, + size_t len, FAR const struct sixlowpan_tagaddr_s *destmac, uint16_t timeout) { struct sixlowpan_send_s sinfo; diff --git a/net/sixlowpan/sixlowpan_tcpsend.c b/net/sixlowpan/sixlowpan_tcpsend.c index 5e5d07bdfb8..5ae5de0b81c 100644 --- a/net/sixlowpan/sixlowpan_tcpsend.c +++ b/net/sixlowpan/sixlowpan_tcpsend.c @@ -164,7 +164,7 @@ ssize_t psock_6lowpan_tcp_send(FAR struct socket *psock, FAR const void *buf, FAR struct tcp_conn_s *conn; FAR struct net_driver_s *dev; struct ipv6tcp_hdr_s ipv6tcp; - struct sixlowpan_addr_s destmac; + struct sixlowpan_tagaddr_s destmac; uint16_t timeout; uint16_t iplen; int ret; @@ -409,7 +409,7 @@ void sixlowpan_tcp_send(FAR struct net_driver_s *dev) } else { - struct sixlowpan_addr_s destmac; + struct sixlowpan_tagaddr_s destmac; FAR uint8_t *buf; uint16_t hdrlen; uint16_t buflen; diff --git a/net/sixlowpan/sixlowpan_udpsend.c b/net/sixlowpan/sixlowpan_udpsend.c index bbc39ef758a..7036589e097 100644 --- a/net/sixlowpan/sixlowpan_udpsend.c +++ b/net/sixlowpan/sixlowpan_udpsend.c @@ -162,7 +162,7 @@ ssize_t psock_6lowpan_udp_sendto(FAR struct socket *psock, FAR struct udp_conn_s *conn; FAR struct net_driver_s *dev; struct ipv6udp_hdr_s ipv6udp; - struct sixlowpan_addr_s destmac; + struct sixlowpan_tagaddr_s destmac; uint16_t iplen; uint16_t timeout; int ret; diff --git a/net/sixlowpan/sixlowpan_utils.c b/net/sixlowpan/sixlowpan_utils.c index 687a0bd7e4a..05b60e3d38a 100644 --- a/net/sixlowpan/sixlowpan_utils.c +++ b/net/sixlowpan/sixlowpan_utils.c @@ -80,17 +80,39 @@ * ****************************************************************************/ -void sixlowpan_addrfromip(const net_ipv6addr_t ipaddr, - FAR struct sixlowpan_addr_s *addr) +void sixlowpan_saddrfromip(const net_ipv6addr_t ipaddr, + FAR struct sixlowpan_saddr_s *saddr) { DEBUGASSERT(ipaddr[0] == HTONS(0xfe80)); -#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR - memcpy(addr, &ipaddr[4], NET_6LOWPAN_ADDRSIZE); -#else - memcpy(addr, &ipaddr[7], NET_6LOWPAN_ADDRSIZE); -#endif - addr->u8[0] ^= 0x02; + memcpy(saddr, &ipaddr[7], NET_6LOWPAN_SADDRSIZE); + saddr->u8[0] ^= 0x02; +} + +void sixlowpan_eaddrfromip(const net_ipv6addr_t ipaddr, + FAR struct sixlowpan_eaddr_s *eaddr) +{ + DEBUGASSERT(ipaddr[0] == HTONS(0xfe80)); + + memcpy(eaddr, &ipaddr[4], NET_6LOWPAN_EADDRSIZE); + eaddr->u8[0] ^= 0x02; +} + +void sixlowpan_addrfromip(const net_ipv6addr_t ipaddr, + FAR struct sixlowpan_tagaddr_s *addr) +{ + DEBUGASSERT(ipaddr[0] == HTONS(0xfe80)); + + if (SIXLOWPAN_IS_IID_16BIT_COMPRESSABLE(ipaddr)) + { + memset(addr, 0, sizeof(struct sixlowpan_tagaddr_s)); + sixlowpan_saddrfromip(ipaddr, &addr->u.saddr); + } + else + { + sixlowpan_eaddrfromip(ipaddr, &addr->u.eaddr); + addr->extended = true; + } } /**************************************************************************** @@ -106,20 +128,37 @@ void sixlowpan_addrfromip(const net_ipv6addr_t ipaddr, * ****************************************************************************/ -bool sixlowpan_ismacbased(const net_ipv6addr_t ipaddr, - FAR const struct sixlowpan_addr_s *addr) +bool sixlowpan_issaddrbased(const net_ipv6addr_t ipaddr, + FAR const struct sixlowpan_saddr_s *saddr) { - FAR const uint8_t *byteptr = addr->u8; + FAR const uint8_t *byteptr = saddr->u8; -#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR - return (ipaddr[4] == htons((GETINT16(byteptr, 0) ^ 0x0200)) && - ipaddr[5] == GETINT16(byteptr, 2) && - ipaddr[6] == GETINT16(byteptr, 4) && - ipaddr[7] == GETINT16(byteptr, 6)); -#else return (ipaddr[5] == HTONS(0x00ff) && ipaddr[6] == HTONS(0xfe00) && - ipaddr[7] == htons((GETINT16(byteptr, 0) ^ 0x0200))); -#endif + ipaddr[7] == (GETNET16(byteptr, 0) ^ HTONS(0x0200))); +} + +bool sixlowpan_iseaddrbased(const net_ipv6addr_t ipaddr, + FAR const struct sixlowpan_eaddr_s *eaddr) +{ + FAR const uint8_t *byteptr = eaddr->u8; + + return (ipaddr[4] == (GETNET16(byteptr, 0) ^ HTONS(0x0200)) && + ipaddr[5] == GETNET16(byteptr, 2) && + ipaddr[6] == GETNET16(byteptr, 4) && + ipaddr[7] == GETNET16(byteptr, 6)); +} + +bool sixlowpan_ismacbased(const net_ipv6addr_t ipaddr, + FAR const struct sixlowpan_tagaddr_s *addr) +{ + if (addr->extended) + { + return sixlowpan_iseaddrbased(ipaddr, &addr->u.eaddr); + } + else + { + return sixlowpan_issaddrbased(ipaddr, &addr->u.saddr); + } } /**************************************************************************** From 075a8b913cb9c682f5039e7cfde0bb930ddb0c08 Mon Sep 17 00:00:00 2001 From: Juha Niskanen Date: Fri, 5 May 2017 10:10:37 +0300 Subject: [PATCH 136/183] STM32L4: separate SYSCFG into product line specific files for clarity --- arch/arm/src/stm32l4/chip/stm32l4_syscfg.h | 163 ++------------- .../arm/src/stm32l4/chip/stm32l4x3xx_syscfg.h | 182 +++++++++++++++++ .../arm/src/stm32l4/chip/stm32l4x6xx_syscfg.h | 191 ++++++++++++++++++ 3 files changed, 386 insertions(+), 150 deletions(-) create mode 100644 arch/arm/src/stm32l4/chip/stm32l4x3xx_syscfg.h create mode 100644 arch/arm/src/stm32l4/chip/stm32l4x6xx_syscfg.h diff --git a/arch/arm/src/stm32l4/chip/stm32l4_syscfg.h b/arch/arm/src/stm32l4/chip/stm32l4_syscfg.h index 2cbffbc7f1e..c68c992296e 100644 --- a/arch/arm/src/stm32l4/chip/stm32l4_syscfg.h +++ b/arch/arm/src/stm32l4/chip/stm32l4_syscfg.h @@ -1,8 +1,8 @@ -/**************************************************************************************************** +/************************************************************************************ * arch/arm/src/stm32l4/chip/stm32l4_syscfg.h * - * Copyright (C) 2014-2015 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Copyright (C) 2015 Sebastien Lorquet. All rights reserved. + * Author: Sebastien Lorquet * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -31,162 +31,25 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ****************************************************************************************************/ + ************************************************************************************/ #ifndef __ARCH_ARM_SRC_STM32L4_CHIP_STM32L4_SYSCFG_H #define __ARCH_ARM_SRC_STM32L4_CHIP_STM32L4_SYSCFG_H -/**************************************************************************************************** +/************************************************************************************ * Included Files - ****************************************************************************************************/ + ************************************************************************************/ #include #include "chip.h" -#if defined(CONFIG_STM32L4_STM32L476XX) || defined(CONFIG_STM32L4_STM32L486XX) || \ - defined(CONFIG_STM32L4_STM32L496XX) +#if defined(CONFIG_STM32L4_STM32L4X6) +# include "chip/stm32l4x6xx_syscfg.h" +#elif defined(CONFIG_STM32L4_STM32L4X3) +# include "chip/stm32l4x3xx_syscfg.h" +#else +# error "Unsupported STM32 L4 chip" +#endif -/**************************************************************************************************** - * Pre-processor Definitions - ****************************************************************************************************/ - -/* Register Offsets *********************************************************************************/ - -#define STM32L4_SYSCFG_MEMRMP_OFFSET 0x0000 /* SYSCFG memory remap register */ -#define STM32L4_SYSCFG_CFGR1_OFFSET 0x0004 /* SYSCFG configuration register 1 */ -#define STM32L4_SYSCFG_EXTICR_OFFSET(p) (0x0008 + ((p) & 0x000c)) /* Registers are displaced by 4! */ -#define STM32L4_SYSCFG_EXTICR1_OFFSET 0x0008 /* SYSCFG external interrupt configuration register 1 */ -#define STM32L4_SYSCFG_EXTICR2_OFFSET 0x000c /* SYSCFG external interrupt configuration register 2 */ -#define STM32L4_SYSCFG_EXTICR3_OFFSET 0x0010 /* SYSCFG external interrupt configuration register 3 */ -#define STM32L4_SYSCFG_EXTICR4_OFFSET 0x0014 /* SYSCFG external interrupt configuration register 4 */ -#define STM32L4_SYSCFG_SCSR_OFFSET 0x0018 /* SYSCFG SRAM2 control and status register */ -#define STM32L4_SYSCFG_CFGR2_OFFSET 0x001c /* SYSCFG configuration register 2 */ -#define STM32L4_SYSCFG_SWPR_OFFSET 0x0020 /* SYSCFG SRAM2 write protection register */ -#define STM32L4_SYSCFG_SKR_OFFSET 0x0024 /* SYSCFG SRAM2 key register */ -#define STM32L4_SYSCFG_SWPR2_OFFSET 0x0028 /* SYSCFG SRAM2 write protection register 2 */ - -/* Register Addresses *******************************************************************************/ - -#define STM32L4_SYSCFG_MEMRMP (STM32L4_SYSCFG_BASE+STM32L4_SYSCFG_MEMRMP_OFFSET) -#define STM32L4_SYSCFG_CFGR1 (STM32L4_SYSCFG_BASE+STM32L4_SYSCFG_CFGR1_OFFSET) -#define STM32L4_SYSCFG_EXTICR(p) (STM32L4_SYSCFG_BASE+STM32L4_SYSCFG_EXTICR_OFFSET(p)) -#define STM32L4_SYSCFG_EXTICR1 (STM32L4_SYSCFG_BASE+STM32L4_SYSCFG_EXTICR1_OFFSET) -#define STM32L4_SYSCFG_EXTICR2 (STM32L4_SYSCFG_BASE+STM32L4_SYSCFG_EXTICR2_OFFSET) -#define STM32L4_SYSCFG_EXTICR3 (STM32L4_SYSCFG_BASE+STM32L4_SYSCFG_EXTICR3_OFFSET) -#define STM32L4_SYSCFG_EXTICR4 (STM32L4_SYSCFG_BASE+STM32L4_SYSCFG_EXTICR4_OFFSET) -#define STM32L4_SYSCFG_SCSR (STM32L4_SYSCFG_BASE+STM32L4_SYSCFG_SCSR_OFFSET) -#define STM32L4_SYSCFG_CFGR2 (STM32L4_SYSCFG_BASE+STM32L4_SYSCFG_CFGR2_OFFSET) -#define STM32L4_SYSCFG_SWPR (STM32L4_SYSCFG_BASE+STM32L4_SYSCFG_SWPR_OFFSET) -#define STM32L4_SYSCFG_SKR (STM32L4_SYSCFG_BASE+STM32L4_SYSCFG_SKR_OFFSET) - -/* Register Bitfield Definitions ********************************************************************/ - -/* SYSCFG memory remap register */ - -#define SYSCFG_MEMRMP_SHIFT (0) /* Bits 2:0 MEM_MODE: Memory mapping selection */ -#define SYSCFG_MEMRMP_MASK (7 << SYSCFG_MEMRMP_SHIFT) -# define SYSCFG_MEMRMP_FLASH (0 << SYSCFG_MEMRMP_SHIFT) /* 000: Main Flash memory mapped at 0x0000 0000 */ -# define SYSCFG_MEMRMP_SYSTEM (1 << SYSCFG_MEMRMP_SHIFT) /* 001: System Flash memory mapped at 0x0000 0000 */ -# define SYSCFG_MEMRMP_FMC (2 << SYSCFG_MEMRMP_SHIFT) /* 010: FSMC Bank1 (NOR/PSRAM 1 and 2) mapped at 0x0000 0000 */ -# define SYSCFG_MEMRMP_SRAM (3 << SYSCFG_MEMRMP_SHIFT) /* 011: SRAM1 (112kB) mapped at 0x0000 0000 */ -# define SYSCFG_MEMRMP_QSPI (6 << SYSCFG_MEMRMP_SHIFT) /* 110: QUADSPI mapped at 0x0000 0000 */ -#define SYSCFG_FBMODE (1 << 8) /* Bit 8: Flash Bank mode selection */ - -/* SYSCFG configuration register 1 */ - -#define SYSCFG_CFGR1_FWDIS (1 << 0) /* Bit 0: Firewall disable */ -#define SYSCFG_CFGR1_BOOSTEN (1 << 8) /* Bit 8: I/O analog switch voltage booster enable (use when vdd is low) */ -#define SYSCFG_CFGR1_I2C_PB6_FMP (1 << 16) /* Bit 16: Fast-mode Plus (Fm+) driving capability activation on PB6 */ -#define SYSCFG_CFGR1_I2C_PB7_FMP (1 << 17) /* Bit 17: Fast-mode Plus (Fm+) driving capability activation on PB7 */ -#define SYSCFG_CFGR1_I2C_PB8_FMP (1 << 18) /* Bit 18: Fast-mode Plus (Fm+) driving capability activation on PB8 */ -#define SYSCFG_CFGR1_I2C_PB9_FMP (1 << 19) /* Bit 19: Fast-mode Plus (Fm+) driving capability activation on PB9 */ -#define SYSCFG_CFGR1_I2C1_FMP (1 << 20) /* Bit 20: I2C1 Fast-mode Plus (Fm+) driving capability activation */ -#define SYSCFG_CFGR1_I2C2_FMP (1 << 21) /* Bit 21: I2C2 Fast-mode Plus (Fm+) driving capability activation */ -#define SYSCFG_CFGR1_I2C3_FMP (1 << 22) /* Bit 22: I2C3 Fast-mode Plus (Fm+) driving capability activation */ -#define SYSCFG_CFGR1_I2C4_FMP (1 << 23) /* Bit 23: I2C4 Fast-mode Plus (Fm+) driving capability activation */ -#define SYSCFG_CFGR1_FPU_IE0 (1 << 26) /* Bit 26: FPU Invalid operation interrupt enable */ -#define SYSCFG_CFGR1_FPU_IE1 (1 << 27) /* Bit 27: FPU Divide-by-zero interrupt enable */ -#define SYSCFG_CFGR1_FPU_IE2 (1 << 28) /* Bit 28: FPU Underflow interrupt enable */ -#define SYSCFG_CFGR1_FPU_IE3 (1 << 29) /* Bit 29: FPU Overflow interrupt enable */ -#define SYSCFG_CFGR1_FPU_IE4 (1 << 30) /* Bit 30: FPU Input denormal interrupt enable */ -#define SYSCFG_CFGR1_FPU_IE5 (1 << 31) /* Bit 31: FPU Inexact interrupt enable */ - -/* SYSCFG external interrupt configuration register 1-4 */ - -#define SYSCFG_EXTICR_PORTA (0) /* 0000: PA[x] pin */ -#define SYSCFG_EXTICR_PORTB (1) /* 0001: PB[x] pin */ -#define SYSCFG_EXTICR_PORTC (2) /* 0010: PC[x] pin */ -#define SYSCFG_EXTICR_PORTD (3) /* 0011: PD[x] pin */ -#define SYSCFG_EXTICR_PORTE (4) /* 0100: PE[x] pin */ -#define SYSCFG_EXTICR_PORTF (5) /* 0101: PF[C] pin */ -#define SYSCFG_EXTICR_PORTG (6) /* 0110: PG[x] pin */ -#define SYSCFG_EXTICR_PORTH (7) /* 0111: PH[x] pin (only on STM32L496xx/4A6xx) */ -#define SYSCFG_EXTICR_PORTI (8) /* 1000: PI[x] pin (only on STM32L496xx/4A6xx) */ - -#define SYSCFG_EXTICR_PORT_MASK (15) -#define SYSCFG_EXTICR_EXTI_SHIFT(g) (((g) & 3) << 2) -#define SYSCFG_EXTICR_EXTI_MASK(g) (SYSCFG_EXTICR_PORT_MASK << (SYSCFG_EXTICR_EXTI_SHIFT(g))) - -#define SYSCFG_EXTICR1_EXTI0_SHIFT (0) /* Bits 0-2: EXTI 0 configuration */ -#define SYSCFG_EXTICR1_EXTI0_MASK (SYSCFG_EXTICR_PORT_MASK << SYSCFG_EXTICR1_EXTI0_SHIFT) -#define SYSCFG_EXTICR1_EXTI1_SHIFT (4) /* Bits 4-6: EXTI 1 configuration */ -#define SYSCFG_EXTICR1_EXTI1_MASK (SYSCFG_EXTICR_PORT_MASK << SYSCFG_EXTICR1_EXTI1_SHIFT) -#define SYSCFG_EXTICR1_EXTI2_SHIFT (8) /* Bits 8-10: EXTI 2 configuration */ -#define SYSCFG_EXTICR1_EXTI2_MASK (SYSCFG_EXTICR_PORT_MASK << SYSCFG_EXTICR1_EXTI2_SHIFT) -#define SYSCFG_EXTICR1_EXTI3_SHIFT (12) /* Bits 12-14: EXTI 3 configuration */ -#define SYSCFG_EXTICR1_EXTI3_MASK (SYSCFG_EXTICR_PORT_MASK << SYSCFG_EXTICR1_EXTI3_SHIFT) - -#define SYSCFG_EXTICR2_EXTI4_SHIFT (0) /* Bits 0-2: EXTI 4 configuration */ -#define SYSCFG_EXTICR2_EXTI4_MASK (SYSCFG_EXTICR_PORT_MASK << SYSCFG_EXTICR2_EXTI4_SHIFT) -#define SYSCFG_EXTICR2_EXTI5_SHIFT (4) /* Bits 4-6: EXTI 5 configuration */ -#define SYSCFG_EXTICR2_EXTI5_MASK (SYSCFG_EXTICR_PORT_MASK << SYSCFG_EXTICR2_EXTI5_SHIFT) -#define SYSCFG_EXTICR2_EXTI6_SHIFT (8) /* Bits 8-10: EXTI 6 configuration */ -#define SYSCFG_EXTICR2_EXTI6_MASK (SYSCFG_EXTICR_PORT_MASK << SYSCFG_EXTICR2_EXTI6_SHIFT) -#define SYSCFG_EXTICR2_EXTI7_SHIFT (12) /* Bits 12-14: EXTI 7 configuration */ -#define SYSCFG_EXTICR2_EXTI7_MASK (SYSCFG_EXTICR_PORT_MASK << SYSCFG_EXTICR2_EXTI7_SHIFT) - -#define SYSCFG_EXTICR3_EXTI8_SHIFT (0) /* Bits 0-2: EXTI 8 configuration */ -#define SYSCFG_EXTICR3_EXTI8_MASK (SYSCFG_EXTICR_PORT_MASK << SYSCFG_EXTICR3_EXTI8_SHIFT) -#define SYSCFG_EXTICR3_EXTI9_SHIFT (4) /* Bits 4-6: EXTI 9 configuration */ -#define SYSCFG_EXTICR3_EXTI9_MASK (SYSCFG_EXTICR_PORT_MASK << SYSCFG_EXTICR3_EXTI9_SHIFT) -#define SYSCFG_EXTICR3_EXTI10_SHIFT (8) /* Bits 8-10: EXTI 10 configuration */ -#define SYSCFG_EXTICR3_EXTI10_MASK (SYSCFG_EXTICR_PORT_MASK << SYSCFG_EXTICR3_EXTI10_SHIFT) -#define SYSCFG_EXTICR3_EXTI11_SHIFT (12) /* Bits 12-14: EXTI 11 configuration */ -#define SYSCFG_EXTICR3_EXTI11_MASK (SYSCFG_EXTICR_PORT_MASK << SYSCFG_EXTICR3_EXTI11_SHIFT) - -#define SYSCFG_EXTICR4_EXTI12_SHIFT (0) /* Bits 0-2: EXTI 12 configuration */ -#define SYSCFG_EXTICR4_EXTI12_MASK (SYSCFG_EXTICR_PORT_MASK << SYSCFG_EXTICR4_EXTI12_SHIFT) -#define SYSCFG_EXTICR4_EXTI13_SHIFT (4) /* Bits 4-6: EXTI 13 configuration */ -#define SYSCFG_EXTICR4_EXTI13_MASK (SYSCFG_EXTICR_PORT_MASK << SYSCFG_EXTICR4_EXTI13_SHIFT) -#define SYSCFG_EXTICR4_EXTI14_SHIFT (8) /* Bits 8-10: EXTI 14 configuration */ -#define SYSCFG_EXTICR4_EXTI14_MASK (SYSCFG_EXTICR_PORT_MASK << SYSCFG_EXTICR4_EXTI14_SHIFT) -#define SYSCFG_EXTICR4_EXTI15_SHIFT (12) /* Bits 12-14: EXTI 15 configuration */ -#define SYSCFG_EXTICR4_EXTI15_MASK (SYSCFG_EXTICR_PORT_MASK << SYSCFG_EXTICR4_EXTI15_SHIFT) - -/* SYSCFG SRAM2 control and status register */ - -#define SYSCFG_SCSR_SRAM2ER (1 << 0) /* Bit 0: SRAM2 Erase */ -#define SYSCFG_SCSR_SRAM2BSY (1 << 1) /* Bit 1: SRAM2 busy in erase operation */ - -/* SYSCFG configuration register 2 */ - -#define SYSCFG_CFGR2_CLL (1 << 0) /* Bit 0: Cortex-M4 LOCKUP (Hardfault) output enable (TIMx break enable, see refman) */ -#define SYSCFG_CFGR2_SPL (1 << 1) /* Bit 1: SRAM2 parity lock enable (same) */ -#define SYSCFG_CFGR2_PVDL (1 << 2) /* Bit 2: PVD lock enable (same) */ -#define SYSCFG_CFGR2_ECCL (1 << 3) /* Bit 3: ECC lock enable (same) */ -#define SYSCFG_CFGR2_SPF (1 << 8) /* Bit 8: SRAM2 parity error flag */ - -/* SYSCFG SRAM2 write protection register */ -/* There is one bit per SRAM2 page (0 to 31) */ - -/* SYSCFG SRAM2 key register */ - -#define SYSCFG_SKR_SHIFT 0 -#define SYSCFG_SKR_MASK (0xFF << SYSCFG_SKR_SHIFT) - -/* SYSCFG SRAM2 write protection register 2 (only on STM32L496xx/4A6xx) */ -/* There is one bit per SRAM2 page (32 to 63) */ - -#endif /* CONFIG_STM32L4_STM32L476XX || CONFIG_STM32L4_STM32L486XX || CONFIG_STM32L4_STM32L496XX */ #endif /* __ARCH_ARM_SRC_STM32L4_CHIP_STM32L4_SYSCFG_H */ diff --git a/arch/arm/src/stm32l4/chip/stm32l4x3xx_syscfg.h b/arch/arm/src/stm32l4/chip/stm32l4x3xx_syscfg.h new file mode 100644 index 00000000000..446ce1811a1 --- /dev/null +++ b/arch/arm/src/stm32l4/chip/stm32l4x3xx_syscfg.h @@ -0,0 +1,182 @@ +/**************************************************************************************************** + * arch/arm/src/stm32l4/chip/stm32l4x3xx_syscfg.h + * + * Copyright (C) 2014-2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************************************/ + +#ifndef __ARCH_ARM_SRC_STM32L4_CHIP_STM32L4X3XX_SYSCFG_H +#define __ARCH_ARM_SRC_STM32L4_CHIP_STM32L4X3XX_SYSCFG_H + +/**************************************************************************************************** + * Included Files + ****************************************************************************************************/ + +#include +#include "chip.h" + +#if defined(CONFIG_STM32L4_STM32L4X3) + +/**************************************************************************************************** + * Pre-processor Definitions + ****************************************************************************************************/ + +/* Register Offsets *********************************************************************************/ + +#define STM32L4_SYSCFG_MEMRMP_OFFSET 0x0000 /* SYSCFG memory remap register */ +#define STM32L4_SYSCFG_CFGR1_OFFSET 0x0004 /* SYSCFG configuration register 1 */ +#define STM32L4_SYSCFG_EXTICR_OFFSET(p) (0x0008 + ((p) & 0x000c)) /* Registers are displaced by 4! */ +#define STM32L4_SYSCFG_EXTICR1_OFFSET 0x0008 /* SYSCFG external interrupt configuration register 1 */ +#define STM32L4_SYSCFG_EXTICR2_OFFSET 0x000c /* SYSCFG external interrupt configuration register 2 */ +#define STM32L4_SYSCFG_EXTICR3_OFFSET 0x0010 /* SYSCFG external interrupt configuration register 3 */ +#define STM32L4_SYSCFG_EXTICR4_OFFSET 0x0014 /* SYSCFG external interrupt configuration register 4 */ +#define STM32L4_SYSCFG_SCSR_OFFSET 0x0018 /* SYSCFG SRAM2 control and status register */ +#define STM32L4_SYSCFG_CFGR2_OFFSET 0x001c /* SYSCFG configuration register 2 */ +#define STM32L4_SYSCFG_SWPR_OFFSET 0x0020 /* SYSCFG SRAM2 write protection register */ +#define STM32L4_SYSCFG_SKR_OFFSET 0x0024 /* SYSCFG SRAM2 key register */ + +/* Register Addresses *******************************************************************************/ + +#define STM32L4_SYSCFG_MEMRMP (STM32L4_SYSCFG_BASE+STM32L4_SYSCFG_MEMRMP_OFFSET) +#define STM32L4_SYSCFG_CFGR1 (STM32L4_SYSCFG_BASE+STM32L4_SYSCFG_CFGR1_OFFSET) +#define STM32L4_SYSCFG_EXTICR(p) (STM32L4_SYSCFG_BASE+STM32L4_SYSCFG_EXTICR_OFFSET(p)) +#define STM32L4_SYSCFG_EXTICR1 (STM32L4_SYSCFG_BASE+STM32L4_SYSCFG_EXTICR1_OFFSET) +#define STM32L4_SYSCFG_EXTICR2 (STM32L4_SYSCFG_BASE+STM32L4_SYSCFG_EXTICR2_OFFSET) +#define STM32L4_SYSCFG_EXTICR3 (STM32L4_SYSCFG_BASE+STM32L4_SYSCFG_EXTICR3_OFFSET) +#define STM32L4_SYSCFG_EXTICR4 (STM32L4_SYSCFG_BASE+STM32L4_SYSCFG_EXTICR4_OFFSET) +#define STM32L4_SYSCFG_SCSR (STM32L4_SYSCFG_BASE+STM32L4_SYSCFG_SCSR_OFFSET) +#define STM32L4_SYSCFG_CFGR2 (STM32L4_SYSCFG_BASE+STM32L4_SYSCFG_CFGR2_OFFSET) +#define STM32L4_SYSCFG_SWPR (STM32L4_SYSCFG_BASE+STM32L4_SYSCFG_SWPR_OFFSET) +#define STM32L4_SYSCFG_SKR (STM32L4_SYSCFG_BASE+STM32L4_SYSCFG_SKR_OFFSET) + +/* Register Bitfield Definitions ********************************************************************/ + +/* SYSCFG memory remap register */ + +#define SYSCFG_MEMRMP_SHIFT (0) /* Bits 2:0 MEM_MODE: Memory mapping selection */ +#define SYSCFG_MEMRMP_MASK (7 << SYSCFG_MEMRMP_SHIFT) +# define SYSCFG_MEMRMP_FLASH (0 << SYSCFG_MEMRMP_SHIFT) /* 000: Main Flash memory mapped at 0x0000 0000 */ +# define SYSCFG_MEMRMP_SYSTEM (1 << SYSCFG_MEMRMP_SHIFT) /* 001: System Flash memory mapped at 0x0000 0000 */ +# define SYSCFG_MEMRMP_SRAM (3 << SYSCFG_MEMRMP_SHIFT) /* 011: SRAM1 (112kB) mapped at 0x0000 0000 */ +# define SYSCFG_MEMRMP_QSPI (6 << SYSCFG_MEMRMP_SHIFT) /* 110: QUADSPI mapped at 0x0000 0000 */ + +/* SYSCFG configuration register 1 */ + +#define SYSCFG_CFGR1_FWDIS (1 << 0) /* Bit 0: Firewall disable */ +#define SYSCFG_CFGR1_BOOSTEN (1 << 8) /* Bit 8: I/O analog switch voltage booster enable (use when vdd is low) */ +#define SYSCFG_CFGR1_I2C_PB6_FMP (1 << 16) /* Bit 16: Fast-mode Plus (Fm+) driving capability activation on PB6 */ +#define SYSCFG_CFGR1_I2C_PB7_FMP (1 << 17) /* Bit 17: Fast-mode Plus (Fm+) driving capability activation on PB7 */ +#define SYSCFG_CFGR1_I2C_PB8_FMP (1 << 18) /* Bit 18: Fast-mode Plus (Fm+) driving capability activation on PB8 */ +#define SYSCFG_CFGR1_I2C_PB9_FMP (1 << 19) /* Bit 19: Fast-mode Plus (Fm+) driving capability activation on PB9 */ +#define SYSCFG_CFGR1_I2C1_FMP (1 << 20) /* Bit 20: I2C1 Fast-mode Plus (Fm+) driving capability activation */ +#define SYSCFG_CFGR1_I2C2_FMP (1 << 21) /* Bit 21: I2C2 Fast-mode Plus (Fm+) driving capability activation */ +#define SYSCFG_CFGR1_I2C3_FMP (1 << 22) /* Bit 22: I2C3 Fast-mode Plus (Fm+) driving capability activation */ +#define SYSCFG_CFGR1_I2C4_FMP (1 << 23) /* Bit 23: I2C4 Fast-mode Plus (Fm+) driving capability activation */ +#define SYSCFG_CFGR1_FPU_IE0 (1 << 26) /* Bit 26: FPU Invalid operation interrupt enable */ +#define SYSCFG_CFGR1_FPU_IE1 (1 << 27) /* Bit 27: FPU Divide-by-zero interrupt enable */ +#define SYSCFG_CFGR1_FPU_IE2 (1 << 28) /* Bit 28: FPU Underflow interrupt enable */ +#define SYSCFG_CFGR1_FPU_IE3 (1 << 29) /* Bit 29: FPU Overflow interrupt enable */ +#define SYSCFG_CFGR1_FPU_IE4 (1 << 30) /* Bit 30: FPU Input denormal interrupt enable */ +#define SYSCFG_CFGR1_FPU_IE5 (1 << 31) /* Bit 31: FPU Inexact interrupt enable */ + +/* SYSCFG external interrupt configuration register 1-4 */ + +#define SYSCFG_EXTICR_PORTA (0) /* 0000: PA[x] pin */ +#define SYSCFG_EXTICR_PORTB (1) /* 0001: PB[x] pin */ +#define SYSCFG_EXTICR_PORTC (2) /* 0010: PC[x] pin */ +#define SYSCFG_EXTICR_PORTD (3) /* 0011: PD[x] pin */ +#define SYSCFG_EXTICR_PORTE (4) /* 0100: PE[x] pin */ +/* No PORTF or PORTG on these chips */ +#define SYSCFG_EXTICR_PORTH (7) /* 0111: PH[x] pin */ + +#define SYSCFG_EXTICR_PORT_MASK (7) +#define SYSCFG_EXTICR_EXTI_SHIFT(g) (((g) & 3) << 2) +#define SYSCFG_EXTICR_EXTI_MASK(g) (SYSCFG_EXTICR_PORT_MASK << (SYSCFG_EXTICR_EXTI_SHIFT(g))) + +#define SYSCFG_EXTICR1_EXTI0_SHIFT (0) /* Bits 0-2: EXTI 0 configuration */ +#define SYSCFG_EXTICR1_EXTI0_MASK (SYSCFG_EXTICR_PORT_MASK << SYSCFG_EXTICR1_EXTI0_SHIFT) +#define SYSCFG_EXTICR1_EXTI1_SHIFT (4) /* Bits 4-6: EXTI 1 configuration */ +#define SYSCFG_EXTICR1_EXTI1_MASK (SYSCFG_EXTICR_PORT_MASK << SYSCFG_EXTICR1_EXTI1_SHIFT) +#define SYSCFG_EXTICR1_EXTI2_SHIFT (8) /* Bits 8-10: EXTI 2 configuration */ +#define SYSCFG_EXTICR1_EXTI2_MASK (SYSCFG_EXTICR_PORT_MASK << SYSCFG_EXTICR1_EXTI2_SHIFT) +#define SYSCFG_EXTICR1_EXTI3_SHIFT (12) /* Bits 12-14: EXTI 3 configuration */ +#define SYSCFG_EXTICR1_EXTI3_MASK (SYSCFG_EXTICR_PORT_MASK << SYSCFG_EXTICR1_EXTI3_SHIFT) + +#define SYSCFG_EXTICR2_EXTI4_SHIFT (0) /* Bits 0-2: EXTI 4 configuration */ +#define SYSCFG_EXTICR2_EXTI4_MASK (SYSCFG_EXTICR_PORT_MASK << SYSCFG_EXTICR2_EXTI4_SHIFT) +#define SYSCFG_EXTICR2_EXTI5_SHIFT (4) /* Bits 4-6: EXTI 5 configuration */ +#define SYSCFG_EXTICR2_EXTI5_MASK (SYSCFG_EXTICR_PORT_MASK << SYSCFG_EXTICR2_EXTI5_SHIFT) +#define SYSCFG_EXTICR2_EXTI6_SHIFT (8) /* Bits 8-10: EXTI 6 configuration */ +#define SYSCFG_EXTICR2_EXTI6_MASK (SYSCFG_EXTICR_PORT_MASK << SYSCFG_EXTICR2_EXTI6_SHIFT) +#define SYSCFG_EXTICR2_EXTI7_SHIFT (12) /* Bits 12-14: EXTI 7 configuration */ +#define SYSCFG_EXTICR2_EXTI7_MASK (SYSCFG_EXTICR_PORT_MASK << SYSCFG_EXTICR2_EXTI7_SHIFT) + +#define SYSCFG_EXTICR3_EXTI8_SHIFT (0) /* Bits 0-2: EXTI 8 configuration */ +#define SYSCFG_EXTICR3_EXTI8_MASK (SYSCFG_EXTICR_PORT_MASK << SYSCFG_EXTICR3_EXTI8_SHIFT) +#define SYSCFG_EXTICR3_EXTI9_SHIFT (4) /* Bits 4-6: EXTI 9 configuration */ +#define SYSCFG_EXTICR3_EXTI9_MASK (SYSCFG_EXTICR_PORT_MASK << SYSCFG_EXTICR3_EXTI9_SHIFT) +#define SYSCFG_EXTICR3_EXTI10_SHIFT (8) /* Bits 8-10: EXTI 10 configuration */ +#define SYSCFG_EXTICR3_EXTI10_MASK (SYSCFG_EXTICR_PORT_MASK << SYSCFG_EXTICR3_EXTI10_SHIFT) +#define SYSCFG_EXTICR3_EXTI11_SHIFT (12) /* Bits 12-14: EXTI 11 configuration */ +#define SYSCFG_EXTICR3_EXTI11_MASK (SYSCFG_EXTICR_PORT_MASK << SYSCFG_EXTICR3_EXTI11_SHIFT) + +#define SYSCFG_EXTICR4_EXTI12_SHIFT (0) /* Bits 0-2: EXTI 12 configuration */ +#define SYSCFG_EXTICR4_EXTI12_MASK (SYSCFG_EXTICR_PORT_MASK << SYSCFG_EXTICR4_EXTI12_SHIFT) +#define SYSCFG_EXTICR4_EXTI13_SHIFT (4) /* Bits 4-6: EXTI 13 configuration */ +#define SYSCFG_EXTICR4_EXTI13_MASK (SYSCFG_EXTICR_PORT_MASK << SYSCFG_EXTICR4_EXTI13_SHIFT) +#define SYSCFG_EXTICR4_EXTI14_SHIFT (8) /* Bits 8-10: EXTI 14 configuration */ +#define SYSCFG_EXTICR4_EXTI14_MASK (SYSCFG_EXTICR_PORT_MASK << SYSCFG_EXTICR4_EXTI14_SHIFT) +#define SYSCFG_EXTICR4_EXTI15_SHIFT (12) /* Bits 12-14: EXTI 15 configuration */ +#define SYSCFG_EXTICR4_EXTI15_MASK (SYSCFG_EXTICR_PORT_MASK << SYSCFG_EXTICR4_EXTI15_SHIFT) + +/* SYSCFG SRAM2 control and status register */ + +#define SYSCFG_SCSR_SRAM2ER (1 << 0) /* Bit 0: SRAM2 Erase */ +#define SYSCFG_SCSR_SRAM2BSY (1 << 1) /* Bit 1: SRAM2 busy in erase operation */ + +/* SYSCFG configuration register 2 */ + +#define SYSCFG_CFGR2_CLL (1 << 0) /* Bit 0: Cortex-M4 LOCKUP (Hardfault) output enable (TIMx break enable, see refman) */ +#define SYSCFG_CFGR2_SPL (1 << 1) /* Bit 1: SRAM2 parity lock enable (same) */ +#define SYSCFG_CFGR2_PVDL (1 << 2) /* Bit 2: PVD lock enable (same) */ +#define SYSCFG_CFGR2_ECCL (1 << 3) /* Bit 3: ECC lock enable (same) */ +#define SYSCFG_CFGR2_SPF (1 << 8) /* Bit 8: SRAM2 parity error flag */ + +/* SYSCFG SRAM2 write protection register */ +/* There is one bit per SRAM2 page (0 to 31) */ + +/* SYSCFG SRAM2 key register */ + +#define SYSCFG_SKR_SHIFT 0 +#define SYSCFG_SKR_MASK (0xFF << SYSCFG_SKR_SHIFT) + +#endif /* CONFIG_STM32L4_STM32L4X3 */ +#endif /* __ARCH_ARM_SRC_STM32L4_CHIP_STM32L4X3XX_SYSCFG_H */ diff --git a/arch/arm/src/stm32l4/chip/stm32l4x6xx_syscfg.h b/arch/arm/src/stm32l4/chip/stm32l4x6xx_syscfg.h new file mode 100644 index 00000000000..e7446cfb29c --- /dev/null +++ b/arch/arm/src/stm32l4/chip/stm32l4x6xx_syscfg.h @@ -0,0 +1,191 @@ +/**************************************************************************************************** + * arch/arm/src/stm32l4/chip/stm32l4x6xx_syscfg.h + * + * Copyright (C) 2014-2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************************************/ + +#ifndef __ARCH_ARM_SRC_STM32L4_CHIP_STM32L4X6XX_SYSCFG_H +#define __ARCH_ARM_SRC_STM32L4_CHIP_STM32L4X6XX_SYSCFG_H + +/**************************************************************************************************** + * Included Files + ****************************************************************************************************/ + +#include +#include "chip.h" + +#if defined(CONFIG_STM32L4_STM32L4X6) + +/**************************************************************************************************** + * Pre-processor Definitions + ****************************************************************************************************/ + +/* Register Offsets *********************************************************************************/ + +#define STM32L4_SYSCFG_MEMRMP_OFFSET 0x0000 /* SYSCFG memory remap register */ +#define STM32L4_SYSCFG_CFGR1_OFFSET 0x0004 /* SYSCFG configuration register 1 */ +#define STM32L4_SYSCFG_EXTICR_OFFSET(p) (0x0008 + ((p) & 0x000c)) /* Registers are displaced by 4! */ +#define STM32L4_SYSCFG_EXTICR1_OFFSET 0x0008 /* SYSCFG external interrupt configuration register 1 */ +#define STM32L4_SYSCFG_EXTICR2_OFFSET 0x000c /* SYSCFG external interrupt configuration register 2 */ +#define STM32L4_SYSCFG_EXTICR3_OFFSET 0x0010 /* SYSCFG external interrupt configuration register 3 */ +#define STM32L4_SYSCFG_EXTICR4_OFFSET 0x0014 /* SYSCFG external interrupt configuration register 4 */ +#define STM32L4_SYSCFG_SCSR_OFFSET 0x0018 /* SYSCFG SRAM2 control and status register */ +#define STM32L4_SYSCFG_CFGR2_OFFSET 0x001c /* SYSCFG configuration register 2 */ +#define STM32L4_SYSCFG_SWPR_OFFSET 0x0020 /* SYSCFG SRAM2 write protection register */ +#define STM32L4_SYSCFG_SKR_OFFSET 0x0024 /* SYSCFG SRAM2 key register */ +#define STM32L4_SYSCFG_SWPR2_OFFSET 0x0028 /* SYSCFG SRAM2 write protection register 2 */ + +/* Register Addresses *******************************************************************************/ + +#define STM32L4_SYSCFG_MEMRMP (STM32L4_SYSCFG_BASE+STM32L4_SYSCFG_MEMRMP_OFFSET) +#define STM32L4_SYSCFG_CFGR1 (STM32L4_SYSCFG_BASE+STM32L4_SYSCFG_CFGR1_OFFSET) +#define STM32L4_SYSCFG_EXTICR(p) (STM32L4_SYSCFG_BASE+STM32L4_SYSCFG_EXTICR_OFFSET(p)) +#define STM32L4_SYSCFG_EXTICR1 (STM32L4_SYSCFG_BASE+STM32L4_SYSCFG_EXTICR1_OFFSET) +#define STM32L4_SYSCFG_EXTICR2 (STM32L4_SYSCFG_BASE+STM32L4_SYSCFG_EXTICR2_OFFSET) +#define STM32L4_SYSCFG_EXTICR3 (STM32L4_SYSCFG_BASE+STM32L4_SYSCFG_EXTICR3_OFFSET) +#define STM32L4_SYSCFG_EXTICR4 (STM32L4_SYSCFG_BASE+STM32L4_SYSCFG_EXTICR4_OFFSET) +#define STM32L4_SYSCFG_SCSR (STM32L4_SYSCFG_BASE+STM32L4_SYSCFG_SCSR_OFFSET) +#define STM32L4_SYSCFG_CFGR2 (STM32L4_SYSCFG_BASE+STM32L4_SYSCFG_CFGR2_OFFSET) +#define STM32L4_SYSCFG_SWPR (STM32L4_SYSCFG_BASE+STM32L4_SYSCFG_SWPR_OFFSET) +#define STM32L4_SYSCFG_SKR (STM32L4_SYSCFG_BASE+STM32L4_SYSCFG_SKR_OFFSET) +#define STM32L4_SYSCFG_SWPR2 (STM32L4_SYSCFG_BASE+STM32L4_SYSCFG_SWPR2_OFFSET) + +/* Register Bitfield Definitions ********************************************************************/ + +/* SYSCFG memory remap register */ + +#define SYSCFG_MEMRMP_SHIFT (0) /* Bits 2:0 MEM_MODE: Memory mapping selection */ +#define SYSCFG_MEMRMP_MASK (7 << SYSCFG_MEMRMP_SHIFT) +# define SYSCFG_MEMRMP_FLASH (0 << SYSCFG_MEMRMP_SHIFT) /* 000: Main Flash memory mapped at 0x0000 0000 */ +# define SYSCFG_MEMRMP_SYSTEM (1 << SYSCFG_MEMRMP_SHIFT) /* 001: System Flash memory mapped at 0x0000 0000 */ +# define SYSCFG_MEMRMP_FMC (2 << SYSCFG_MEMRMP_SHIFT) /* 010: FSMC Bank1 (NOR/PSRAM 1 and 2) mapped at 0x0000 0000 */ +# define SYSCFG_MEMRMP_SRAM (3 << SYSCFG_MEMRMP_SHIFT) /* 011: SRAM1 (112kB) mapped at 0x0000 0000 */ +# define SYSCFG_MEMRMP_QSPI (6 << SYSCFG_MEMRMP_SHIFT) /* 110: QUADSPI mapped at 0x0000 0000 */ +#define SYSCFG_FBMODE (1 << 8) /* Bit 8: Flash Bank mode selection */ + +/* SYSCFG configuration register 1 */ + +#define SYSCFG_CFGR1_FWDIS (1 << 0) /* Bit 0: Firewall disable */ +#define SYSCFG_CFGR1_BOOSTEN (1 << 8) /* Bit 8: I/O analog switch voltage booster enable (use when vdd is low) */ +#define SYSCFG_CFGR1_I2C_PB6_FMP (1 << 16) /* Bit 16: Fast-mode Plus (Fm+) driving capability activation on PB6 */ +#define SYSCFG_CFGR1_I2C_PB7_FMP (1 << 17) /* Bit 17: Fast-mode Plus (Fm+) driving capability activation on PB7 */ +#define SYSCFG_CFGR1_I2C_PB8_FMP (1 << 18) /* Bit 18: Fast-mode Plus (Fm+) driving capability activation on PB8 */ +#define SYSCFG_CFGR1_I2C_PB9_FMP (1 << 19) /* Bit 19: Fast-mode Plus (Fm+) driving capability activation on PB9 */ +#define SYSCFG_CFGR1_I2C1_FMP (1 << 20) /* Bit 20: I2C1 Fast-mode Plus (Fm+) driving capability activation */ +#define SYSCFG_CFGR1_I2C2_FMP (1 << 21) /* Bit 21: I2C2 Fast-mode Plus (Fm+) driving capability activation */ +#define SYSCFG_CFGR1_I2C3_FMP (1 << 22) /* Bit 22: I2C3 Fast-mode Plus (Fm+) driving capability activation */ +#define SYSCFG_CFGR1_I2C4_FMP (1 << 23) /* Bit 23: I2C4 Fast-mode Plus (Fm+) driving capability activation */ +#define SYSCFG_CFGR1_FPU_IE0 (1 << 26) /* Bit 26: FPU Invalid operation interrupt enable */ +#define SYSCFG_CFGR1_FPU_IE1 (1 << 27) /* Bit 27: FPU Divide-by-zero interrupt enable */ +#define SYSCFG_CFGR1_FPU_IE2 (1 << 28) /* Bit 28: FPU Underflow interrupt enable */ +#define SYSCFG_CFGR1_FPU_IE3 (1 << 29) /* Bit 29: FPU Overflow interrupt enable */ +#define SYSCFG_CFGR1_FPU_IE4 (1 << 30) /* Bit 30: FPU Input denormal interrupt enable */ +#define SYSCFG_CFGR1_FPU_IE5 (1 << 31) /* Bit 31: FPU Inexact interrupt enable */ + +/* SYSCFG external interrupt configuration register 1-4 */ + +#define SYSCFG_EXTICR_PORTA (0) /* 0000: PA[x] pin */ +#define SYSCFG_EXTICR_PORTB (1) /* 0001: PB[x] pin */ +#define SYSCFG_EXTICR_PORTC (2) /* 0010: PC[x] pin */ +#define SYSCFG_EXTICR_PORTD (3) /* 0011: PD[x] pin */ +#define SYSCFG_EXTICR_PORTE (4) /* 0100: PE[x] pin */ +#define SYSCFG_EXTICR_PORTF (5) /* 0101: PF[C] pin */ +#define SYSCFG_EXTICR_PORTG (6) /* 0110: PG[x] pin */ +#define SYSCFG_EXTICR_PORTH (7) /* 0111: PH[x] pin (only on STM32L496xx/4A6xx) */ +#define SYSCFG_EXTICR_PORTI (8) /* 1000: PI[x] pin (only on STM32L496xx/4A6xx) */ + +#define SYSCFG_EXTICR_PORT_MASK (15) +#define SYSCFG_EXTICR_EXTI_SHIFT(g) (((g) & 3) << 2) +#define SYSCFG_EXTICR_EXTI_MASK(g) (SYSCFG_EXTICR_PORT_MASK << (SYSCFG_EXTICR_EXTI_SHIFT(g))) + +#define SYSCFG_EXTICR1_EXTI0_SHIFT (0) /* Bits 0-2: EXTI 0 configuration */ +#define SYSCFG_EXTICR1_EXTI0_MASK (SYSCFG_EXTICR_PORT_MASK << SYSCFG_EXTICR1_EXTI0_SHIFT) +#define SYSCFG_EXTICR1_EXTI1_SHIFT (4) /* Bits 4-6: EXTI 1 configuration */ +#define SYSCFG_EXTICR1_EXTI1_MASK (SYSCFG_EXTICR_PORT_MASK << SYSCFG_EXTICR1_EXTI1_SHIFT) +#define SYSCFG_EXTICR1_EXTI2_SHIFT (8) /* Bits 8-10: EXTI 2 configuration */ +#define SYSCFG_EXTICR1_EXTI2_MASK (SYSCFG_EXTICR_PORT_MASK << SYSCFG_EXTICR1_EXTI2_SHIFT) +#define SYSCFG_EXTICR1_EXTI3_SHIFT (12) /* Bits 12-14: EXTI 3 configuration */ +#define SYSCFG_EXTICR1_EXTI3_MASK (SYSCFG_EXTICR_PORT_MASK << SYSCFG_EXTICR1_EXTI3_SHIFT) + +#define SYSCFG_EXTICR2_EXTI4_SHIFT (0) /* Bits 0-2: EXTI 4 configuration */ +#define SYSCFG_EXTICR2_EXTI4_MASK (SYSCFG_EXTICR_PORT_MASK << SYSCFG_EXTICR2_EXTI4_SHIFT) +#define SYSCFG_EXTICR2_EXTI5_SHIFT (4) /* Bits 4-6: EXTI 5 configuration */ +#define SYSCFG_EXTICR2_EXTI5_MASK (SYSCFG_EXTICR_PORT_MASK << SYSCFG_EXTICR2_EXTI5_SHIFT) +#define SYSCFG_EXTICR2_EXTI6_SHIFT (8) /* Bits 8-10: EXTI 6 configuration */ +#define SYSCFG_EXTICR2_EXTI6_MASK (SYSCFG_EXTICR_PORT_MASK << SYSCFG_EXTICR2_EXTI6_SHIFT) +#define SYSCFG_EXTICR2_EXTI7_SHIFT (12) /* Bits 12-14: EXTI 7 configuration */ +#define SYSCFG_EXTICR2_EXTI7_MASK (SYSCFG_EXTICR_PORT_MASK << SYSCFG_EXTICR2_EXTI7_SHIFT) + +#define SYSCFG_EXTICR3_EXTI8_SHIFT (0) /* Bits 0-2: EXTI 8 configuration */ +#define SYSCFG_EXTICR3_EXTI8_MASK (SYSCFG_EXTICR_PORT_MASK << SYSCFG_EXTICR3_EXTI8_SHIFT) +#define SYSCFG_EXTICR3_EXTI9_SHIFT (4) /* Bits 4-6: EXTI 9 configuration */ +#define SYSCFG_EXTICR3_EXTI9_MASK (SYSCFG_EXTICR_PORT_MASK << SYSCFG_EXTICR3_EXTI9_SHIFT) +#define SYSCFG_EXTICR3_EXTI10_SHIFT (8) /* Bits 8-10: EXTI 10 configuration */ +#define SYSCFG_EXTICR3_EXTI10_MASK (SYSCFG_EXTICR_PORT_MASK << SYSCFG_EXTICR3_EXTI10_SHIFT) +#define SYSCFG_EXTICR3_EXTI11_SHIFT (12) /* Bits 12-14: EXTI 11 configuration */ +#define SYSCFG_EXTICR3_EXTI11_MASK (SYSCFG_EXTICR_PORT_MASK << SYSCFG_EXTICR3_EXTI11_SHIFT) + +#define SYSCFG_EXTICR4_EXTI12_SHIFT (0) /* Bits 0-2: EXTI 12 configuration */ +#define SYSCFG_EXTICR4_EXTI12_MASK (SYSCFG_EXTICR_PORT_MASK << SYSCFG_EXTICR4_EXTI12_SHIFT) +#define SYSCFG_EXTICR4_EXTI13_SHIFT (4) /* Bits 4-6: EXTI 13 configuration */ +#define SYSCFG_EXTICR4_EXTI13_MASK (SYSCFG_EXTICR_PORT_MASK << SYSCFG_EXTICR4_EXTI13_SHIFT) +#define SYSCFG_EXTICR4_EXTI14_SHIFT (8) /* Bits 8-10: EXTI 14 configuration */ +#define SYSCFG_EXTICR4_EXTI14_MASK (SYSCFG_EXTICR_PORT_MASK << SYSCFG_EXTICR4_EXTI14_SHIFT) +#define SYSCFG_EXTICR4_EXTI15_SHIFT (12) /* Bits 12-14: EXTI 15 configuration */ +#define SYSCFG_EXTICR4_EXTI15_MASK (SYSCFG_EXTICR_PORT_MASK << SYSCFG_EXTICR4_EXTI15_SHIFT) + +/* SYSCFG SRAM2 control and status register */ + +#define SYSCFG_SCSR_SRAM2ER (1 << 0) /* Bit 0: SRAM2 Erase */ +#define SYSCFG_SCSR_SRAM2BSY (1 << 1) /* Bit 1: SRAM2 busy in erase operation */ + +/* SYSCFG configuration register 2 */ + +#define SYSCFG_CFGR2_CLL (1 << 0) /* Bit 0: Cortex-M4 LOCKUP (Hardfault) output enable (TIMx break enable, see refman) */ +#define SYSCFG_CFGR2_SPL (1 << 1) /* Bit 1: SRAM2 parity lock enable (same) */ +#define SYSCFG_CFGR2_PVDL (1 << 2) /* Bit 2: PVD lock enable (same) */ +#define SYSCFG_CFGR2_ECCL (1 << 3) /* Bit 3: ECC lock enable (same) */ +#define SYSCFG_CFGR2_SPF (1 << 8) /* Bit 8: SRAM2 parity error flag */ + +/* SYSCFG SRAM2 write protection register */ +/* There is one bit per SRAM2 page (0 to 31) */ + +/* SYSCFG SRAM2 key register */ + +#define SYSCFG_SKR_SHIFT 0 +#define SYSCFG_SKR_MASK (0xFF << SYSCFG_SKR_SHIFT) + +/* SYSCFG SRAM2 write protection register 2 (only on STM32L496xx/4A6xx) */ +/* There is one bit per SRAM2 page (32 to 63) */ + +#endif /* CONFIG_STM32L4_STM32L4X6 */ +#endif /* __ARCH_ARM_SRC_STM32L4_CHIP_STM32L4X6XX_SYSCFG_H */ From a5e972422406ebc6f96ed9fd8ce3c4e31f119f79 Mon Sep 17 00:00:00 2001 From: Juha Niskanen Date: Fri, 5 May 2017 10:15:09 +0300 Subject: [PATCH 137/183] STM32L4: firewall for stm32l4x3xx Not tested for any product family, but now it at least compiles. L496 devices can have one bit wider Volatile Data Segment. --- arch/arm/src/stm32l4/Make.defs | 4 + .../src/stm32l4/chip/stm32l4x3xx_firewall.h | 103 ++++++++++++++++++ .../src/stm32l4/chip/stm32l4x6xx_firewall.h | 8 ++ arch/arm/src/stm32l4/stm32l4_firewall.c | 4 + arch/arm/src/stm32l4/stm32l4_firewall.h | 11 +- 5 files changed, 125 insertions(+), 5 deletions(-) create mode 100644 arch/arm/src/stm32l4/chip/stm32l4x3xx_firewall.h diff --git a/arch/arm/src/stm32l4/Make.defs b/arch/arm/src/stm32l4/Make.defs index 49ee9725394..417d7c170d0 100644 --- a/arch/arm/src/stm32l4/Make.defs +++ b/arch/arm/src/stm32l4/Make.defs @@ -212,3 +212,7 @@ ifeq ($(CONFIG_STM32L4_CAN),y) CHIP_CSRCS += stm32l4_can.c endif +ifeq ($(CONFIG_STM32L4_FIREWALL),y) +CHIP_CSRCS += stm32l4_firewall.c +endif + diff --git a/arch/arm/src/stm32l4/chip/stm32l4x3xx_firewall.h b/arch/arm/src/stm32l4/chip/stm32l4x3xx_firewall.h new file mode 100644 index 00000000000..4e78b60102c --- /dev/null +++ b/arch/arm/src/stm32l4/chip/stm32l4x3xx_firewall.h @@ -0,0 +1,103 @@ +/************************************************************************************ + * arch/arm/src/stm32l4/chip/stm32l4x3xx_firewall.h + * + * Copyright (C) 2016 Sebastien Lorquet. All rights reserved. + * Author: Sebastien Lorquet + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ************************************************************************************/ + +#ifndef __ARCH_ARM_SRC_STM32L4_CHIP_STM32L4X3XX_FIREWALL_H +#define __ARCH_ARM_SRC_STM32L4_CHIP_STM32L4X3XX_FIREWALL_H + +/************************************************************************************ + * Included Files + ************************************************************************************/ + +#include +#include + +#include "chip.h" + +/************************************************************************************ + * Pre-processor Definitions + ************************************************************************************/ + +/* Register Offsets *****************************************************************/ + +#define STM32L4_FIREWALL_CSSA_OFFSET 0x0000 +#define STM32L4_FIREWALL_CSL_OFFSET 0x0004 +#define STM32L4_FIREWALL_NVDSSA_OFFSET 0x0008 +#define STM32L4_FIREWALL_NVDSL_OFFSET 0x000C +#define STM32L4_FIREWALL_VDSSA_OFFSET 0x0010 +#define STM32L4_FIREWALL_VDSL_OFFSET 0x0014 +#define STM32L4_FIREWALL_CR_OFFSET 0x0020 + +/* Register Addresses ***************************************************************/ + +#define STM32L4_FIREWALL_CSSA (STM32L4_FIREWALL_BASE+STM32L4_FIREWALL_CSSA_OFFSET) +#define STM32L4_FIREWALL_CSL (STM32L4_FIREWALL_BASE+STM32L4_FIREWALL_CSL_OFFSET) +#define STM32L4_FIREWALL_NVDSSA (STM32L4_FIREWALL_BASE+STM32L4_FIREWALL_NVDSSA_OFFSET) +#define STM32L4_FIREWALL_NVDSL (STM32L4_FIREWALL_BASE+STM32L4_FIREWALL_NVDSL_OFFSET) +#define STM32L4_FIREWALL_VDSSA (STM32L4_FIREWALL_BASE+STM32L4_FIREWALL_VDSSA_OFFSET) +#define STM32L4_FIREWALL_VDSL (STM32L4_FIREWALL_BASE+STM32L4_FIREWALL_VDSL_OFFSET) +#define STM32L4_FIREWALL_CR (STM32L4_FIREWALL_BASE+STM32L4_FIREWALL_CR_OFFSET) + +/* Register Bitfield Definitions ****************************************************/ + +/* Code Segment Start Address */ +#define FIREWALL_CSSADD_SHIFT 8 +#define FIREWALL_CSSADD_MASK (0xFFFF << FIREWALL_CSSADD_SHIFT) + +/* Code Segment Length */ +#define FIREWALL_CSSLENG_SHIFT 8 +#define FIREWALL_CSSLENG_MASK (0x3FFF << FIREWALL_CSSLENG_SHIFT) + +/* Non-volatile Data Segment Start Address */ +#define FIREWALL_NVDSADD_SHIFT 8 +#define FIREWALL_NVDSADD_MASK (0xFFFF << FIREWALL_NVDSADD_SHIFT) + +/* Non-volatile Data Segment Length */ +#define FIREWALL_NVDSLENG_SHIFT 8 +#define FIREWALL_NVDSLENG_MASK (0x3FFF << FIREWALL_NVDSLENG_SHIFT) + +/* Volatile Data Segment Start Address */ +#define FIREWALL_VDSADD_SHIFT 6 +#define FIREWALL_VDSADD_MASK (0x07FF << FIREWALL_VDSADD_SHIFT) + +/* Volatile Data Segment Length */ +#define FIREWALL_VDSLENG_SHIFT 6 +#define FIREWALL_VDSLENG_MASK (0x07FF << FIREWALL_VDSLENG_SHIFT) + +/* Configuration Register */ +#define FIREWALL_CR_FPA (1 << 0) /* Bit 0: Firewall prearm */ +#define FIREWALL_CR_VDS (1 << 1) /* Bit 1: Volatile data shared */ +#define FIREWALL_CR_VDE (1 << 2) /* Bit 2: Volatile data execution */ + +#endif /* __ARCH_ARM_SRC_STM32L4_CHIP_STM32L4X3XX_FIREWALL_H */ diff --git a/arch/arm/src/stm32l4/chip/stm32l4x6xx_firewall.h b/arch/arm/src/stm32l4/chip/stm32l4x6xx_firewall.h index e1531de5d03..55826d73f76 100644 --- a/arch/arm/src/stm32l4/chip/stm32l4x6xx_firewall.h +++ b/arch/arm/src/stm32l4/chip/stm32l4x6xx_firewall.h @@ -89,11 +89,19 @@ /* Volatile Data Segment Start Address */ #define FIREWALL_VDSADD_SHIFT 6 +#if defined(CONFIG_STM32L4_STM32L496XX) +#define FIREWALL_VDSADD_MASK (0x0FFF << FIREWALL_VDSADD_SHIFT) +#else #define FIREWALL_VDSADD_MASK (0x07FF << FIREWALL_VDSADD_SHIFT) +#endif /* Volatile Data Segment Length */ #define FIREWALL_VDSLENG_SHIFT 6 +#if defined(CONFIG_STM32L4_STM32L496XX) +#define FIREWALL_VDSLENG_MASK (0x0FFF << FIREWALL_VDSLENG_SHIFT) +#else #define FIREWALL_VDSLENG_MASK (0x07FF << FIREWALL_VDSLENG_SHIFT) +#endif /* Configuration Register */ #define FIREWALL_CR_FPA (1 << 0) /* Bit 0: Firewall prearm */ diff --git a/arch/arm/src/stm32l4/stm32l4_firewall.c b/arch/arm/src/stm32l4/stm32l4_firewall.c index 46cc3ff62de..27f948e43f7 100644 --- a/arch/arm/src/stm32l4/stm32l4_firewall.c +++ b/arch/arm/src/stm32l4/stm32l4_firewall.c @@ -38,6 +38,10 @@ ****************************************************************************/ #include +#include + +#include "up_arch.h" +#include "chip/stm32l4_syscfg.h" #include "stm32l4_firewall.h" diff --git a/arch/arm/src/stm32l4/stm32l4_firewall.h b/arch/arm/src/stm32l4/stm32l4_firewall.h index ec667fe5a7c..7b4a4dd0c45 100644 --- a/arch/arm/src/stm32l4/stm32l4_firewall.h +++ b/arch/arm/src/stm32l4/stm32l4_firewall.h @@ -47,9 +47,10 @@ /* Include the correct firewall register definitions for this STM32L4 family */ -#if defined(CONFIG_STM32L4_STM32L476XX) || defined(CONFIG_STM32L4_STM32L486XX) || \ - defined(CONFIG_STM32L4_STM32L496XX) +#if defined(CONFIG_STM32L4_STM32L4X6) # include "chip/stm32l4x6xx_firewall.h" +#elif defined(CONFIG_STM32L4_STM32L4X3) +# include "chip/stm32l4x3xx_firewall.h" #else # error "Unsupported STM32L4 chip" #endif @@ -60,11 +61,11 @@ struct stm32l4_firewall_t { - uintptr_t *codestart; + uintptr_t codestart; size_t codelen; - uintptr_t *nvdatastart; + uintptr_t nvdatastart; size_t nvdatalen; - uintptr_t *datastart; + uintptr_t datastart; size_t datalen; uint8_t datashared:1; uint8_t dataexec :1; From 71accfc57b71a4c2a8516b486f20752a1329383a Mon Sep 17 00:00:00 2001 From: Juha Niskanen Date: Fri, 5 May 2017 11:03:49 +0300 Subject: [PATCH 138/183] STM32L4: add more chips to Kconfig (This also removes DPFPU/DTCM/ITCM features again, fixing a recent git history hickup.) --- arch/arm/src/stm32l4/Kconfig | 71 +++++++++++++++++++++++++++++++++--- 1 file changed, 65 insertions(+), 6 deletions(-) diff --git a/arch/arm/src/stm32l4/Kconfig b/arch/arm/src/stm32l4/Kconfig index 74b3f9ae700..76d2dae6136 100644 --- a/arch/arm/src/stm32l4/Kconfig +++ b/arch/arm/src/stm32l4/Kconfig @@ -36,6 +36,70 @@ config ARCH_CHIP_STM32L442KC ---help--- STM32 L4 Cortex M4, AES, 256 Kb FLASH, 64 Kb SRAM +config ARCH_CHIP_STM32L433CB + bool "STM32L433CB" + select STM32L4_STM32L433XX + select STM32L4_FLASH_CONFIG_B + select STM32L4_IO_CONFIG_C + ---help--- + STM32 L4 Cortex M4, 128 Kb FLASH, 64 Kb SRAM + +config ARCH_CHIP_STM32L433CC + bool "STM32L433CC" + select STM32L4_STM32L433XX + select STM32L4_FLASH_CONFIG_C + select STM32L4_IO_CONFIG_C + ---help--- + STM32 L4 Cortex M4, 256 Kb FLASH, 64 Kb SRAM + +config ARCH_CHIP_STM32L433RB + bool "STM32L433RB" + select STM32L4_STM32L433XX + select STM32L4_FLASH_CONFIG_B + select STM32L4_IO_CONFIG_R + ---help--- + STM32 L4 Cortex M4, 128 Kb FLASH, 64 Kb SRAM + +config ARCH_CHIP_STM32L433RC + bool "STM32L433RC" + select STM32L4_STM32L433XX + select STM32L4_FLASH_CONFIG_C + select STM32L4_IO_CONFIG_R + ---help--- + STM32 L4 Cortex M4, 256 Kb FLASH, 64 Kb SRAM + +config ARCH_CHIP_STM32L433VC + bool "STM32L433VC" + select STM32L4_STM32L433XX + select STM32L4_FLASH_CONFIG_C + select STM32L4_IO_CONFIG_V + ---help--- + STM32 L4 Cortex M4, 256 Kb FLASH, 64 Kb SRAM + +config ARCH_CHIP_STM32L443CC + bool "STM32L443CC" + select STM32L4_STM32L443XX + select STM32L4_FLASH_CONFIG_C + select STM32L4_IO_CONFIG_C + ---help--- + STM32 L4 Cortex M4, AES, 256 Kb FLASH, 64 Kb SRAM + +config ARCH_CHIP_STM32L443RC + bool "STM32L443RC" + select STM32L4_STM32L443XX + select STM32L4_FLASH_CONFIG_C + select STM32L4_IO_CONFIG_R + ---help--- + STM32 L4 Cortex M4, AES, 256 Kb FLASH, 64 Kb SRAM + +config ARCH_CHIP_STM32L443VC + bool "STM32L443VC" + select STM32L4_STM32L443XX + select STM32L4_FLASH_CONFIG_C + select STM32L4_IO_CONFIG_V + ---help--- + STM32 L4 Cortex M4, AES, 256 Kb FLASH, 64 Kb SRAM + config ARCH_CHIP_STM32L451CC bool "STM32L451CC" select STM32L4_STM32L451XX @@ -221,9 +285,6 @@ config STM32L4_STM32L4X3 bool default n select ARCH_HAVE_FPU - select ARCH_HAVE_DPFPU # REVISIT - select ARMV7M_HAVE_ITCM - select ARMV7M_HAVE_DTCM select STM32L4_HAVE_USART1 select STM32L4_HAVE_USART2 select STM32L4_HAVE_USART3 if !(STM32L4_L432XX || STM32L4_L442XX) @@ -236,6 +297,7 @@ config STM32L4_STM32L4X3 config STM32L4_STM32L4X5 bool default n + select ARCH_HAVE_FPU select STM32L4_HAVE_USART1 select STM32L4_HAVE_USART2 select STM32L4_HAVE_USART3 @@ -264,9 +326,6 @@ config STM32L4_STM32L4X6 bool default n select ARCH_HAVE_FPU - select ARCH_HAVE_DPFPU # REVISIT - select ARMV7M_HAVE_ITCM - select ARMV7M_HAVE_DTCM select STM32L4_HAVE_USART1 select STM32L4_HAVE_USART2 select STM32L4_HAVE_USART3 From a7b452bc5bce39112c275f4faa8956b79a149ac6 Mon Sep 17 00:00:00 2001 From: Juha Niskanen Date: Fri, 5 May 2017 15:32:07 +0300 Subject: [PATCH 139/183] configs/nucleo-l496zg: Kconfig was copied from nucleo-144 Removed as most options have not been tested. --- configs/nucleo-l496zg/Kconfig | 219 +--------------------------------- 1 file changed, 2 insertions(+), 217 deletions(-) diff --git a/configs/nucleo-l496zg/Kconfig b/configs/nucleo-l496zg/Kconfig index af61775c0bb..713c28241c8 100644 --- a/configs/nucleo-l496zg/Kconfig +++ b/configs/nucleo-l496zg/Kconfig @@ -3,221 +3,6 @@ # see the file kconfig-language.txt in the NuttX tools repository. # -if ARCH_BOARD_NUCLEO_144 +if ARCH_BOARD_NUCLEO_L496ZG -choice - prompt "Select Console wiring." - default NUCLEO_ARDUINO - ---help--- - Select where you will connect the console. - - Virtual COM Port: - - Advantage: Use the ST-Link as a console. No Extra wiring - neded. - - Disdvantage: Not the best choice for initial bring up. - - ARDUINO Connector: - - Advantage: You have a shield so it is - easy. - - Disdvantage: You loose the use of the - other functions on PC6, PC7 - - STM32F7 - ARDUIONO FUNCTION GPIO - -- ----- --------- ---- - DO RX USART6_RX PG9 - D1 TX USART6_TX PG14 - -- ----- --------- --- - - OR - - Morpho Connector: - - STM32F7 - MORPHO FUNCTION GPIO - -------- --------- ----- - CN12-64 USART8_RX PE0 - CN11-61 USART8_TX PE1 - -------- --------- ----- - -config NUCLEO_CONSOLE_ARDUINO - bool "ARDUINO Connector" - select STM32F7_USART6 - select USART6_SERIALDRIVER - select USART6_SERIAL_CONSOLE - -config NUCLEO_CONSOLE_VIRTUAL - bool "Virtual Comport" - select STM32F7_USART3 - select USART3_SERIALDRIVER - select USART3_SERIAL_CONSOLE - -config NUCLEO_CONSOLE_MORPHO - bool "Morpho Connector" - select STM32F7_UART8 - select UART8_SERIALDRIVER - select UART8_SERIAL_CONSOLE - -config NUCLEO_CONSOLE_NONE - bool "No Console" - -endchoice # "Select Console wiring" - -config NUCLEO_SPI_TEST - bool "Enable SPI test" - default n - ---help--- - Enable Spi test - initalize and configure SPI to send - NUCLEO_SPI_TEST_MESSAGE text. The text is sent on the - selected SPI Buses with the configured parameters. - Note the CS lines will not be asserted. - -if NUCLEO_SPI_TEST - -config NUCLEO_SPI_TEST_MESSAGE - string "Text to Send on SPI Bus(es)" - default "Hello World" - depends on NUCLEO_SPI_TEST - ---help--- - Text to sent on SPI bus(es) - -config NUCLEO_SPI1_TEST - bool "Test SPI bus 1" - default n - depends on NUCLEO_SPI_TEST - ---help--- - Enable Spi test - on SPI BUS 1 - -if NUCLEO_SPI1_TEST - -config NUCLEO_SPI1_TEST_FREQ - int "SPI 1 Clock Freq in Hz" - default 1000000 - depends on NUCLEO_SPI1_TEST - ---help--- - Sets SPI 1 Clock Freq - -config NUCLEO_SPI1_TEST_BITS - int "SPI 1 number of bits" - default 8 - depends on NUCLEO_SPI1_TEST - ---help--- - Sets SPI 1 bit length - -choice - prompt "SPI BUS 1 Clock Mode" - default NUCLEO_SPI1_TEST_MODE3 - ---help--- - Sets SPI 1 clock mode - -config NUCLEO_SPI1_TEST_MODE0 - bool "CPOL=0 CHPHA=0" - -config NUCLEO_SPI1_TEST_MODE1 - bool "CPOL=0 CHPHA=1" - -config NUCLEO_SPI1_TEST_MODE2 - bool "CPOL=1 CHPHA=0" - -config NUCLEO_SPI1_TEST_MODE3 - bool "CPOL=1 CHPHA=1" - -endchoice # "SPI BUS 1 Clock Mode" - -endif # NUCLEO_SPI1_TEST - -config NUCLEO_SPI2_TEST - bool "Test SPI bus 2" - default n - depends on NUCLEO_SPI_TEST - ---help--- - Enable Spi test - on SPI BUS 2 - -if NUCLEO_SPI2_TEST - -config NUCLEO_SPI2_TEST_FREQ - int "SPI 2 Clock Freq in Hz" - default 12000000 - depends on NUCLEO_SPI2_TEST - ---help--- - Sets SPI 2 Clock Freq - -config NUCLEO_SPI2_TEST_BITS - int "SPI 2 number of bits" - default 8 - depends on NUCLEO_SPI2_TEST - ---help--- - Sets SPI 2 bit length - -choice - prompt "SPI BUS 2 Clock Mode" - default NUCLEO_SPI2_TEST_MODE3 - ---help--- - Sets SPI 2 clock mode - -config NUCLEO_SPI2_TEST_MODE0 - bool "CPOL=0 CHPHA=0" - -config NUCLEO_SPI2_TEST_MODE1 - bool "CPOL=0 CHPHA=1" - -config NUCLEO_SPI2_TEST_MODE2 - bool "CPOL=1 CHPHA=0" - -config NUCLEO_SPI2_TEST_MODE3 - bool "CPOL=1 CHPHA=1" - -endchoice # "SPI BUS 2 Clock Mode" - -endif # NUCLEO_SPI2_TEST - -config NUCLEO_SPI3_TEST - bool "Test SPI bus 3" - default n - depends on NUCLEO_SPI_TEST - ---help--- - Enable Spi test - on SPI BUS 3 - -if NUCLEO_SPI3_TEST - -config NUCLEO_SPI3_TEST_FREQ - int "SPI 3 Clock Freq in Hz" - default 40000000 - depends on NUCLEO_SPI3_TEST - ---help--- - Sets SPI 3 Clock Freq - -config NUCLEO_SPI3_TEST_BITS - int "SPI 3 number of bits" - default 8 - depends on NUCLEO_SPI3_TEST - ---help--- - Sets SPI 3 bit length - -choice - prompt "SPI BUS 3 Clock Mode" - default NUCLEO_SPI3_TEST_MODE3 - ---help--- - Sets SPI 3 clock mode - -config NUCLEO_SPI3_TEST_MODE0 - bool "CPOL=0 CHPHA=0" - -config NUCLEO_SPI3_TEST_MODE1 - bool "CPOL=0 CHPHA=1" - -config NUCLEO_SPI3_TEST_MODE2 - bool "CPOL=1 CHPHA=0" - -config NUCLEO_SPI3_TEST_MODE3 - bool "CPOL=1 CHPHA=1" - -endchoice # "SPI BUS 3 Clock Mode" - -endif # NUCLEO_SPI3_TEST -endif # NUCLEO_SPI_TEST -endif # ARCH_BOARD_NUCLEO_144 +endif # ARCH_BOARD_NUCLEO_L496ZG From 2ecaf33bb690aec30f1b9c54cdfac7cbc4fb3bf8 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 5 May 2017 06:48:53 -0600 Subject: [PATCH 140/183] nucleo-144: Default for choice in Kconfig was not one of the possible choices. --- configs/nucleo-144/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configs/nucleo-144/Kconfig b/configs/nucleo-144/Kconfig index 96427a9a5e2..a6ac8ffbed7 100644 --- a/configs/nucleo-144/Kconfig +++ b/configs/nucleo-144/Kconfig @@ -7,7 +7,7 @@ if ARCH_BOARD_NUCLEO_144 choice prompt "Select Console wiring." - default NUCLEO_ARDUINO + default NUCLEO_CONSOLE_ARDUINO ---help--- Select where you will connect the console. From 2171523f50c5d3ebb2d2ad8372bb0816afafbcd9 Mon Sep 17 00:00:00 2001 From: David Sidrane Date: Fri, 5 May 2017 07:12:52 -0600 Subject: [PATCH 141/183] Kinetis:Add TPM to K66 chip --- arch/arm/include/kinetis/chip.h | 5 +- arch/arm/src/kinetis/Kconfig | 32 +++- arch/arm/src/kinetis/chip/kinetis_kx6tpm.h | 211 +++++++++++++++++++++ arch/arm/src/kinetis/kinetis_tpm.h | 58 ++++++ 4 files changed, 303 insertions(+), 3 deletions(-) create mode 100644 arch/arm/src/kinetis/chip/kinetis_kx6tpm.h create mode 100644 arch/arm/src/kinetis/kinetis_tpm.h diff --git a/arch/arm/include/kinetis/chip.h b/arch/arm/include/kinetis/chip.h index 5c6cc76a082..cc50674e97d 100644 --- a/arch/arm/include/kinetis/chip.h +++ b/arch/arm/include/kinetis/chip.h @@ -1438,8 +1438,9 @@ # define KINETIS_NDAC6 4 /* Four 6-bit DAC */ # define KINETIS_NDAC12 2 /* Two 12-bit DAC */ # define KINETIS_NVREF 1 /* Voltage reference */ -# define KINETIS_NTIMERS8 2 /* ? Two 8 channel timers */ -# define KINETIS_NTIMERS2 2 /* ? Two 2 channel timers */ +# define KINETIS_NTIMERS8 2 /* Two 8 channel FTM timers */ +# define KINETIS_NTIMERS2 2 /* Two 2 channel FTM timers */ +# define KINETIS_NTPMTIMERS2 2 /* Two 2 channel TPM timers */ # define KINETIS_NRTC 1 /* Real time clock */ # define KINETIS_NRNG 1 /* Random number generator */ # define KINETIS_NMMCAU 1 /* Hardware encryption */ diff --git a/arch/arm/src/kinetis/Kconfig b/arch/arm/src/kinetis/Kconfig index 271921a9ef6..9920e3ce356 100644 --- a/arch/arm/src/kinetis/Kconfig +++ b/arch/arm/src/kinetis/Kconfig @@ -268,15 +268,23 @@ config ARCH_FAMILY_K60 config ARCH_FAMILY_K64 bool default n + select KINETIS_HAVE_FTM3 select KINETIS_HAVE_UART5 config ARCH_FAMILY_K66 bool default n + select KINETIS_HAVE_FTM3 select KINETIS_HAVE_LPUART0 + select KINETIS_HAVE_TPM1 + select KINETIS_HAVE_TPM2 menu "Kinetis Peripheral Support" +config KINETIS_HAVE_FTM3 + bool + default n + config KINETIS_HAVE_I2C1 bool default n @@ -297,6 +305,14 @@ config KINETIS_HAVE_SPI2 bool default n +config KINETIS_HAVE_TPM1 + bool + default n + +config KINETIS_HAVE_TPM2 + bool + default n + config KINETIS_TRACE bool "Trace" default n @@ -531,10 +547,24 @@ config KINETIS_FTM2 config KINETIS_FTM3 bool "FTM3" default n - depends on ARCH_FAMILY_K64 || ARCH_FAMILY_K66 + depends on KINETIS_HAVE_FTM3 ---help--- Support FlexTimer 3 +config KINETIS_TPM1 + bool "TPM1" + default n + depends on KINETIS_HAVE_TPM1 + ---help--- + Support TPM module 1 + +config KINETIS_TPM2 + bool "TPM2" + default n + depends on KINETIS_HAVE_TPM2 + ---help--- + Support TPM module 2 + config KINETIS_LPTIMER bool "Low power timer (LPTIMER)" default n diff --git a/arch/arm/src/kinetis/chip/kinetis_kx6tpm.h b/arch/arm/src/kinetis/chip/kinetis_kx6tpm.h new file mode 100644 index 00000000000..2dd103c6566 --- /dev/null +++ b/arch/arm/src/kinetis/chip/kinetis_kx6tpm.h @@ -0,0 +1,211 @@ +/**************************************************************************** + * arch/arm/src/kinetis/chip/kinetis_kx6tpm.h + * + * Copyright (C) 2017 Gregory Nutt. All rights reserved. + * Authors: Gregory Nutt + * David Sidrane + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __ARCH_ARM_SRC_KINETIS_CHIP_KINETIS_KX6TPM_H +#define __ARCH_ARM_SRC_KINETIS_CHIP_KINETIS_KX6TPM_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include "chip.h" + +/**************************************************************************** + * Pre-processor Declarations + ****************************************************************************/ + +#define KINETIS_TPM_SC_OFFSET 0x0000 /* Status and Control offset*/ +#define KINETIS_TPM_CNT_OFFSET 0x0004 /* Counter offset */ +#define KINETIS_TPM_MOD_OFFSET 0x0008 /* Modulo offset */ +#define KINETIS_TPM_C0SC_OFFSET 0x000C /* Channel 0 Status and Control offset */ +#define KINETIS_TPM_C0V_OFFSET 0x0010 /* Channel 0 Value offset */ +#define KINETIS_TPM_C1SC_OFFSET 0x0014 /* Channel 1 Status and Control offset */ +#define KINETIS_TPM_C1V_OFFSET 0x0018 /* Channel 1 Value offset */ +#define KINETIS_TPM_STATUS_OFFSET 0x0050 /* Capture and Compare Status offset */ +#define KINETIS_TPM_COMBINE_OFFSET 0x0064 /* Combine Channel Register offset */ +#define KINETIS_TPM_POL_OFFSET 0x0070 /* Channel Polarity offset */ +#define KINETIS_TPM_FILTER_OFFSET 0x0078 /* Filter Control offset */ +#define KINETIS_TPM_QDCTRL_OFFSET 0x0080 /* Quadrature Decoder Control and Status offset */ +#define KINETIS_TPM_CONF_OFFSET 0x0084 /* Configuration offset */ + +#define KINETIS_TPM1_SC (KINETIS_TPM1_BASE + KINETIS_TPM_SC_OFFSET) /* TPM1 Status and Control */ +#define KINETIS_TPM1_CNT (KINETIS_TPM1_BASE + KINETIS_TPM_CNT_OFFSET) /* TPM1 Counter */ +#define KINETIS_TPM1_MOD (KINETIS_TPM1_BASE + KINETIS_TPM_MOD_OFFSET) /* TPM1 Modulo */ +#define KINETIS_TPM1_C0SC (KINETIS_TPM1_BASE + KINETIS_TPM_C0SC_OFFSET) /* TPM1 Channel 0 Status and Control */ +#define KINETIS_TPM1_C0V (KINETIS_TPM1_BASE + KINETIS_TPM_C0V_OFFSET) /* TPM1 Channel 0 Value */ +#define KINETIS_TPM1_C1SC (KINETIS_TPM1_BASE + KINETIS_TPM_C1SC_OFFSET) /* TPM1 Channel 1 Status and Control */ +#define KINETIS_TPM1_C1V (KINETIS_TPM1_BASE + KINETIS_TPM_C1V_OFFSET) /* TPM1 Channel 1 Value */ +#define KINETIS_TPM1_C2SC (KINETIS_TPM1_BASE + KINETIS_TPM_C2SC_OFFSET) /* TPM1 Channel 2 Status and Control */ +#define KINETIS_TPM1_C2V (KINETIS_TPM1_BASE + KINETIS_TPM_C2V_OFFSET) /* TPM1 Channel 2 Value */ +#define KINETIS_TPM1_STATUS (KINETIS_TPM1_BASE + KINETIS_TPM_STATUS_OFFSET) /* TPM1 Capture and Compare Status */ +#define KINETIS_TPM1_COMBINE (KINETIS_TPM1_BASE + KINETIS_TPM_COMBINE_OFFSET) /* TPM1 Combine Channel Register offset */ +#define KINETIS_TPM1_POL (KINETIS_TPM1_BASE + KINETIS_TPM_POL_OFFSET) /* TPM1 Channel Polarity offset */ +#define KINETIS_TPM1_FILTER (KINETIS_TPM1_BASE + KINETIS_TPM_FILTER_OFFSET) /* TPM1 Filter Control offset */ +#define KINETIS_TPM1_QDCTRL (KINETIS_TPM1_BASE + KINETIS_TPM_QDCTRL_OFFSET) /* TPM1 Quadrature Decoder Control and Status offset */ +#define KINETIS_TPM1_CONF (KINETIS_TPM1_BASE + KINETIS_TPM_CONF_OFFSET) /* TPM1 Configuration */ + +#define KINETIS_TPM2_SC (KINETIS_TPM2_BASE + KINETIS_TPM_SC_OFFSET) /* TPM2 Status and Control */ +#define KINETIS_TPM2_CNT (KINETIS_TPM2_BASE + KINETIS_TPM_CNT_OFFSET) /* TPM2 Counter */ +#define KINETIS_TPM2_MOD (KINETIS_TPM2_BASE + KINETIS_TPM_MOD_OFFSET) /* TPM2 Modulo */ +#define KINETIS_TPM2_C0SC (KINETIS_TPM2_BASE + KINETIS_TPM_C0SC_OFFSET) /* TPM2 Channel 0 Status and Control */ +#define KINETIS_TPM2_C0V (KINETIS_TPM2_BASE + KINETIS_TPM_C0V_OFFSET) /* TPM2 Channel 0 Value */ +#define KINETIS_TPM2_C1SC (KINETIS_TPM2_BASE + KINETIS_TPM_C1SC_OFFSET) /* TPM2 Channel 1 Status and Control */ +#define KINETIS_TPM2_C1V (KINETIS_TPM2_BASE + KINETIS_TPM_C1V_OFFSET) /* TPM2 Channel 1 Value */ +#define KINETIS_TPM2_C2SC (KINETIS_TPM2_BASE + KINETIS_TPM_C2SC_OFFSET) /* TPM2 Channel 2 Status and Control */ +#define KINETIS_TPM2_C2V (KINETIS_TPM2_BASE + KINETIS_TPM_C2V_OFFSET) /* TPM2 Channel 2 Value */ +#define KINETIS_TPM2_STATUS (KINETIS_TPM2_BASE + KINETIS_TPM_STATUS_OFFSET) /* TPM2 Capture and Compare Status */ +#define KINETIS_TPM2_COMBINE (KINETIS_TPM2_BASE + KINETIS_TPM_COMBINE_OFFSET) /* TPM2 Combine Channel Register offset */ +#define KINETIS_TPM2_POL (KINETIS_TPM2_BASE + KINETIS_TPM_POL_OFFSET) /* TPM2 Channel Polarity offset */ +#define KINETIS_TPM2_FILTER (KINETIS_TPM2_BASE + KINETIS_TPM_FILTER_OFFSET) /* TPM2 Filter Control offset */ +#define KINETIS_TPM2_QDCTRL (KINETIS_TPM2_BASE + KINETIS_TPM_QDCTRL_OFFSET) /* TPM2 Quadrature Decoder Control and Status offset */ +#define KINETIS_TPM2_CONF (KINETIS_TPM2_BASE + KINETIS_TPM_CONF_OFFSET) /* TPM2 Configuration */ + +#define TPM_SC_PS_SHIFT 0 /* Bits 0-2: Prescale Factor Selection */ +#define TPM_SC_PS_MASK (7 << TPM_SC_PS_SHIFT) +# define TPM_SC_PS_DIV1 (0 << TPM_SC_PS_SHIFT) /* Divide Clock by 1 */ +# define TPM_SC_PS_DIV2 (1 << TPM_SC_PS_SHIFT) /* Divide Clock by 2 */ +# define TPM_SC_PS_DIV4 (2 << TPM_SC_PS_SHIFT) /* Divide Clock by 4 */ +# define TPM_SC_PS_DIV8 (3 << TPM_SC_PS_SHIFT) /* Divide Clock by 8 */ +# define TPM_SC_PS_DIV16 (4 << TPM_SC_PS_SHIFT) /* Divide Clock by 16 */ +# define TPM_SC_PS_DIV32 (5 << TPM_SC_PS_SHIFT) /* Divide Clock by 32 */ +# define TPM_SC_PS_DIV64 (6 << TPM_SC_PS_SHIFT) /* Divide Clock by 64 */ +# define TPM_SC_PS_DIV128 (7 << TPM_SC_PS_SHIFT) /* Divide Clock by 128 */ + +#define TPM_SC_CMOD_SHIFT 3 /* Bits 3-4: Clock Mode Selection */ +#define TPM_SC_CMOD_MASK (3 << TPM_SC_CMOD_SHIFT) +# define TPM_SC_CMOD_DIS (0 << TPM_SC_CMOD_SHIFT) /* TPM counter is disabled */ +# define TPM_SC_CMOD_LPTPM_CLK (1 << TPM_SC_CMOD_SHIFT) /* TPM increments on every counter clock */ +# define TPM_SC_CMOD_LPTPM_EXTCLK (2 << TPM_SC_CMOD_SHIFT) /* TPM increments on rising edge of EXTCLK */ + +#define TPM_SC_CPWMS (1 << 5) /* Bit 5: Center-aligned PWM Select */ +#define TPM_SC_TOIE (1 << 6) /* Bit 6: Timer Overflow Interrupt Enable */ +#define TPM_SC_TOF (1 << 7) /* Bit 7: Timer Overflow Flag*/ +#define TPM_SC_DMA (1 << 8) /* Bit 8: DMA Enable*/ + /* Bits 9-31: Reserved */ + +#define TPM_CNT_SHIFT 0 /* Bits 0-15: Counter value */ +#define TPM_CNT_MASK (0xffff << TPM_COUNT_SHIFT) /* Any write clears Count */ + /* Bits 16-31: Reserved */ + +#define TPM_MOD_SHIFT 0 /* Bits 0-15: Mod value */ +#define TPM_MOD_MASK (0xffff << TPM_MOD_SHIFT) /* This field must be written with single 16 or 32-bit access */ + /* Bits 16-31: Reserved */ + +#define TPM_CnSC_DMA (1 << 0) /* Bit 0: Enables DMA transfers for the channel */ + /* Bit 1: Reserved*/ +#define TPM_CnSC_ELSA (1 << 2) /* Bit 2: Edge or Level Select */ +#define TPM_CnSC_ELSB (1 << 3) /* Bit 3: Edge or Level Select */ +#define TPM_CnSC_MSA (1 << 4) /* Bit 4: Channel Mode Select */ +#define TPM_CnSC_MSB (1 << 5) /* Bit 5: Channel Mode Select */ +#define TPM_CnSC_CHIE (1 << 6) /* Bit 6: Channel Interrupt Enable */ +#define TPM_CnSC_CHF (1 << 7) /* Bit 7: Channel Flag */ + /* Bits 8-31: Reserved */ + +#define TPM_VAL_SHIFT 0 /* Bits 0-15: Channel value */ +#define TPM_VAL_MASK (0xffff << TPM_VAL_SHIFT) /* Captured TPM counter value of the input modes or + * the match value for the output modes. This field + * must be written with single 16 or 32-bit access.*/ + /* Bits 16-31: Reserved */ + +#define TPM_STATUS_CH0F (1 << 0) /* Bit 0: Channel 0 Flag */ +#define TPM_STATUS_CH1F (1 << 1) /* Bit 1: Channel 1 Flag */ + /* Bits 2-7: Reserved */ +#define TPM_STATUS_TOF (1 << 8) /* Bit 8: Timer Overflow Flag */ + /* Bits 9-31: Reserved */ + +#define TPM_COMBINE_COMBINE0 (1 << 0) /* Bit 0: Combine Channels 0 and 1 */ +#define TPM_COMBINE_COMSWAP0 (1 << 1) /* Bit 1: Combine Channel 0 and 1 Swap */ + /* Bits 2-7: Reserved */ + /* Bits 8-31: Reserved */ + +#define TPM_POL_POL0 (1 << 0) /* Bit 0: Channel 0 Polarity */ +#define TPM_POL_POL1 (1 << 1) /* Bit 1: Channel 1 Polarity */ + /* Bits 2-31: Reserved */ + +#define TPM_FILTER_CH0FVAL_SHIFT 0 /* Bits 0-3: Channel 0 Filter Value */ +#define TPM_FILTER_CH0FVAL_MASK (0xf << TPM_FILTER_CH0FVAL_SHIFT) +#define TPM_FILTER_CH1FVAL_SHIFT 4 /* Bits 4-7: Channel 1 Filter Value */ +#define TPM_FILTER_CH1FVAL_MASK (0xf << TPM_FILTER_CH1FVAL_SHIFT) + +#define TPM_QDCTRL_QDCTRL (1 << 0) /* Bit 0: Enables the quadrature decoder mode */ +#define TPM_QDCTRL_TOFDIR (1 << 1) /* Bit 1: Indicates if the TOF bit was set (Read Only) */ +#define TPM_QDCTRL_QUADIR (1 << 2) /* Bit 2: Counter Direction in Quadrature Decode Mode (Read Only) */ +#define TPM_QDCTRL_QUADMODE (1 << 3) /* Bit 3: Quadrature Decoder Mode */ + /* Bits 4-31: Reserved */ + +#define TPM_CONF_DOZEEN (1 << 5) /* Bit 5: Doze Enable */ +#define TPM_CONF_DBGMODE_SHIFT 6 /* Bits 6-7: Debug Mode */ +#define TPM_CONF_DBGMODE_MASK (3 << TPM_CONF_DBGMODE_SHIFT) +# define TPM_CONF_DBGMODE_PAUSE (0 << TPM_CONF_DBGMODE_SHIFT) /* TPM counter will pause during DEBUG mode */ +# define TPM_CONF_DBGMODE_CONT (3 << TPM_CONF_DBGMODE_SHIFT) /* TPM counter continue working in DEBUG mode */ +#define TPM_CONF_GTBSYNC (1 << 8) /* Bit 8: Global Time Base Synchronization */ +#define TPM_CONF_GTBEEN (1 << 9) /* Bit 9: Global Time Base Enable */ + /* Bits 10-15: Reserved */ +#define TPM_CONF_CSOT (1 << 16) /* Bit 16: Counter Start On Trigger */ +#define TPM_CONF_CSOO (1 << 17) /* Bit 17: Counter Stop On Overflow */ +#define TPM_CONF_CROT (1 << 18) /* Bit 18: Counter Reload On Trigger */ +#define TPM_CONF_CPOT (1 << 19) /* Bit 19: Counter Pause On Trigger */ + /* Bits 20-21: Reserved */ +#define TPM_CONF_TRGPOL (1 << 22) /* Bit 22: Trigger Polarity */ +#define TPM_CONF_TRGSRC (1 << 23) /* Bit 23: Trigger Source */ + +#define TPM_CONF_TRGSEL_SHIFT 24 /* Bits 24-27: Trigger Select */ +#define TPM_CONF_TRGSEL_MASK (0xf << TPM_CONF_TRGSEL_SHIFT) + /* Internal TPM_CONF_TRGSRC set */ +# define TPM_CONF_TRGSEL_INTC0 (0 << TPM_CONF_TRGSEL_SHIFT) /* Internal Channel 0 pin input capture */ +# define TPM_CONF_TRGSEL_INTC1 (2 << TPM_CONF_TRGSEL_SHIFT) /* Internal Channel 1 pin input capture */ +# define TPM_CONF_TRGSEL_INTC01 (3 << TPM_CONF_TRGSEL_SHIFT) /* Internal Channel 0 or 1 pin input capture */ + +# define TPM_CONF_TRGSEL_EXTRG_IN (0 << TPM_CONF_TRGSEL_SHIFT) /* External trigger pin input */ +# define TPM_CONF_TRGSEL_CMP0 (1 << TPM_CONF_TRGSEL_SHIFT) /* CPM0 output */ +# define TPM_CONF_TRGSEL_CMP1 (2 << TPM_CONF_TRGSEL_SHIFT) /* CPM1 output */ +# define TPM_CONF_TRGSEL_CMP2 (3 << TPM_CONF_TRGSEL_SHIFT) /* CPM2 output */ +# define TPM_CONF_TRGSEL_PIT0 (4 << TPM_CONF_TRGSEL_SHIFT) /* PIT trigger 0 */ +# define TPM_CONF_TRGSEL_PIT1 (5 << TPM_CONF_TRGSEL_SHIFT) /* PIT trigger 1 */ +# define TPM_CONF_TRGSEL_PIT2 (6 << TPM_CONF_TRGSEL_SHIFT) /* PIT trigger 2 */ +# define TPM_CONF_TRGSEL_PIT3 (7 << TPM_CONF_TRGSEL_SHIFT) /* PIT trigger 3 */ +# define TPM_CONF_TRGSEL_FTM0 (8 << TPM_CONF_TRGSEL_SHIFT) /* FTM0 initialization trigger and channel triggers */ +# define TPM_CONF_TRGSEL_FTM1 (9 << TPM_CONF_TRGSEL_SHIFT) /* FTM1 initialization trigger and channel triggers */ +# define TPM_CONF_TRGSEL_FTM2 (10 << TPM_CONF_TRGSEL_SHIFT) /* FTM2 initialization trigger and channel triggers */ +# define TPM_CONF_TRGSEL_FTM3 (11 << TPM_CONF_TRGSEL_SHIFT) /* FTM3 initialization trigger and channel triggers */ +# define TPM_CONF_TRGSEL_RTC_ALRM (12 << TPM_CONF_TRGSEL_SHIFT) /* RTC Alarm */ +# define TPM_CONF_TRGSEL_RTC_SECS (13 << TPM_CONF_TRGSEL_SHIFT) /* RTC Seconds */ +# define TPM_CONF_TRGSEL_LPTMR (14 << TPM_CONF_TRGSEL_SHIFT) /* LPTMR trigger */ +# define TPM_CONF_TRGSEL_SW (15 << TPM_CONF_TRGSEL_SHIFT) /* Software Trigger */ + +#endif /* __ARCH_ARM_SRC_KINETIS_CHIP_KINETIS_KX6TPM_H */ diff --git a/arch/arm/src/kinetis/kinetis_tpm.h b/arch/arm/src/kinetis/kinetis_tpm.h new file mode 100644 index 00000000000..03fe3b13627 --- /dev/null +++ b/arch/arm/src/kinetis/kinetis_tpm.h @@ -0,0 +1,58 @@ +/**************************************************************************** + * arch/arm/src/kinetis/kinetis_tpm.h + * + * Copyright (C) 2017 Gregory Nutt. All rights reserved. + * Authors: Gregory Nutt + * David Sidrane + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __ARCH_ARM_SRC_KINETIS_KINETIS_TPM_H +#define __ARCH_ARM_SRC_KINETIS_KINETIS_TPM_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include "chip.h" + +/* This file is just a wrapper around tmp header files for the Kinetis family + * selected by the logic in chip.h. + */ + +#if defined(KINETIS_K66) +# include "chip/kinetis_kx6tpm.h" +#else +# error "No TMP definitions for this Kinetis part" +#endif + +#endif /* __ARCH_ARM_SRC_KINETIS_KINETIS_TPM_H */ From f73e2aab8d8c956c10522dab068c1a9f6a998e73 Mon Sep 17 00:00:00 2001 From: David Sidrane Date: Fri, 5 May 2017 07:14:00 -0600 Subject: [PATCH 142/183] Kinetis:Fixed CLKSRC Bit Names --- arch/arm/src/kinetis/chip/kinetis_sim.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/arm/src/kinetis/chip/kinetis_sim.h b/arch/arm/src/kinetis/chip/kinetis_sim.h index 3e6cb6a6efb..a1ffe6721e3 100644 --- a/arch/arm/src/kinetis/chip/kinetis_sim.h +++ b/arch/arm/src/kinetis/chip/kinetis_sim.h @@ -328,7 +328,7 @@ divided by the PLLFLLCLK fractional divider as configured by SIM_CLKDIV3[PLLFLLFRAC, PLLFLLDIV] */ # define SIM_SOPT2_TPMSRC_OCSERCLK (2 << SIM_SOPT2_TPMSRC_SHIFT) /* OSCERCLK clock */ -# define SIM_SOPT2_TPMSRC_EXTBYP (3 << SIM_SOPT2_TPMSRC_SHIFT) /* MCGIRCLK clock */ +# define SIM_SOPT2_TPMSRC_MCGIRCLK (3 << SIM_SOPT2_TPMSRC_SHIFT) /* MCGIRCLK clock */ # endif # if defined(KINETIS_SIM_HAS_SOPT2_I2SSRC) # define SIM_SOPT2_I2SSRC_SHIFT (24) /* Bits 24-25: I2S master clock source select */ @@ -348,7 +348,7 @@ divided by the PLLFLLCLK fractional divider as configured by SIM_CLKDIV3[PLLFLLFRAC, PLLFLLDIV] */ # define SIM_SOPT2_LPUARTSRC_OCSERCLK (2 << SIM_SOPT2_LPUARTSRC_SHIFT) /* OSCERCLK clock */ -# define SIM_SOPT2_LPUARTSRC_EXTBYP (3 << SIM_SOPT2_LPUARTSRC_SHIFT) /* MCGIRCLK clock */ +# define SIM_SOPT2_LPUARTSRC_MCGIRCLK (3 << SIM_SOPT2_LPUARTSRC_SHIFT) /* MCGIRCLK clock */ # endif # if defined(KINETIS_SIM_HAS_SOPT2_SDHCSRC) # define SIM_SOPT2_SDHCSRC_SHIFT (28) /* Bits 28-29: SDHC clock source select */ From 29ef635e895e6fb8829acfef0924b54fabd4c94f Mon Sep 17 00:00:00 2001 From: David Sidrane Date: Fri, 5 May 2017 07:16:11 -0600 Subject: [PATCH 143/183] Kinetis:Add OSC_DIV to the kinetis_osc header --- arch/arm/src/kinetis/chip/kinetis_osc.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/arch/arm/src/kinetis/chip/kinetis_osc.h b/arch/arm/src/kinetis/chip/kinetis_osc.h index 69a7b8a30c8..e61f0a8c1c6 100644 --- a/arch/arm/src/kinetis/chip/kinetis_osc.h +++ b/arch/arm/src/kinetis/chip/kinetis_osc.h @@ -1,7 +1,7 @@ /******************************************************************************************** * arch/arm/src/kinetis/chip/kinetis_osc.h * - * Copyright (C) 2011, 2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2011, 2016-2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -51,10 +51,12 @@ /* Register Offsets *************************************************************************/ #define KINETIS_OSC_CR_OFFSET 0x0000 /* OSC Control Register */ +#define KINETIS_OSC_DIV_OFFSET 0x0002 /* OSC CLock divider register */ /* Register Addresses ***********************************************************************/ #define KINETIS_OSC_CR (KINETIS_OSC_BASE+KINETIS_OSC_CR_OFFSET) +#define KINETIS_OSC_DIV (KINETIS_OSC_BASE+KINETIS_OSC_DIV_OFFSET) /* Register Bit Definitions *****************************************************************/ @@ -69,6 +71,15 @@ #define OSC_CR_SC8P (1 << 1) /* Bit 1: Oscillator 8 pF Capacitor Load Configure */ #define OSC_CR_SC16P (1 << 0) /* Bit 0: Oscillator 16 pF Capacitor Load Configure */ +/* OSC Control Register (8-bit) */ + /* Bits 0-5: Reserved */ +#define OSC_DIV_ERPS_SHIFT 6 /* Bits 6-7: ERCLK prescaler */ +#define OSC_DIV_ERPS_MASK (3 << OSC_DIV_ERPS_SHIFT) +# define OSC_DIV_ERPS_DIV1 (0 << OSC_DIV_ERPS_SHIFT) /* The divisor ratio is 1 */ +# define OSC_DIV_ERPS_DIV2 (1 << OSC_DIV_ERPS_SHIFT) /* The divisor ratio is 2 */ +# define OSC_DIV_ERPS_DIV3 (2 << OSC_DIV_ERPS_SHIFT) /* The divisor ratio is 4 */ +# define OSC_DIV_ERPS_DIV8 (3 << OSC_DIV_ERPS_SHIFT) /* The divisor ratio is 8 */ + /******************************************************************************************** * Public Types ********************************************************************************************/ From b6a8db1b392961b0e5c4a5a4e307fdd70786bca6 Mon Sep 17 00:00:00 2001 From: David Sidrane Date: Fri, 5 May 2017 07:18:39 -0600 Subject: [PATCH 144/183] Kinetis: Use optional BOARD_OSC_CR and BOARD_OSC_DIV in clock configuration --- arch/arm/src/kinetis/kinetis_clockconfig.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/arch/arm/src/kinetis/kinetis_clockconfig.c b/arch/arm/src/kinetis/kinetis_clockconfig.c index b954f33be2e..28218fcd86c 100644 --- a/arch/arm/src/kinetis/kinetis_clockconfig.c +++ b/arch/arm/src/kinetis/kinetis_clockconfig.c @@ -49,6 +49,7 @@ #include "chip/kinetis_pmc.h" #include "chip/kinetis_llwu.h" #include "chip/kinetis_pinmux.h" +#include "chip/kinetis_osc.h" #include @@ -199,6 +200,18 @@ void kinetis_pllconfig(void) #endif uint8_t regval8; +#if defined(BOARD_OSC_CR) + /* Use complete BOARD_OSC_CR settings */ + + putreg8(BOARD_OSC_CR, KINETIS_OSC_CR); +#endif + +#if defined(BOARD_OSC_DIV) + /* Use complete BOARD_OSC_DIV settings */ + + putreg8(BOARD_OSC_DIV, KINETIS_OSC_DIV); +#endif + #if defined(BOARD_MCG_C2) /* Use complete BOARD_MCG_C2 settings */ From f29981e473292ad6bab5cd62064d673da55e842e Mon Sep 17 00:00:00 2001 From: David Sidrane Date: Fri, 5 May 2017 07:33:15 -0600 Subject: [PATCH 145/183] kinetis:Added HW flow control and termios --- arch/arm/src/kinetis/Kconfig | 57 ++++ arch/arm/src/kinetis/kinetis.h | 6 +- arch/arm/src/kinetis/kinetis_lowputc.c | 169 +++++++++- arch/arm/src/kinetis/kinetis_lpserial.c | 360 +++++++++++++++++++++- arch/arm/src/kinetis/kinetis_serial.c | 390 +++++++++++++++++++++++- 5 files changed, 948 insertions(+), 34 deletions(-) diff --git a/arch/arm/src/kinetis/Kconfig b/arch/arm/src/kinetis/Kconfig index 9920e3ce356..646e7254faa 100644 --- a/arch/arm/src/kinetis/Kconfig +++ b/arch/arm/src/kinetis/Kconfig @@ -239,6 +239,10 @@ config KINETIS_HAVE_LPUART1 # will automatically be selected and will represent the 'OR' of the # instances selected. +config KINETIS_SERIALDRIVER + bool + default n + config KINETIS_LPUART bool default n @@ -330,6 +334,8 @@ config KINETIS_UART0 default n select UART0_SERIALDRIVER select KINETIS_UART + select KINETIS_SERIALDRIVER + select ARCH_HAVE_SERIAL_TERMIOS ---help--- Support UART0 @@ -338,6 +344,8 @@ config KINETIS_UART1 default n select UART1_SERIALDRIVER select KINETIS_UART + select KINETIS_SERIALDRIVER + select ARCH_HAVE_SERIAL_TERMIOS ---help--- Support UART1 @@ -346,6 +354,8 @@ config KINETIS_UART2 default n select UART2_SERIALDRIVER select KINETIS_UART + select KINETIS_SERIALDRIVER + select ARCH_HAVE_SERIAL_TERMIOS ---help--- Support UART2 @@ -354,6 +364,8 @@ config KINETIS_UART3 default n select UART3_SERIALDRIVER select KINETIS_UART + select KINETIS_SERIALDRIVER + select ARCH_HAVE_SERIAL_TERMIOS ---help--- Support UART3 @@ -362,6 +374,8 @@ config KINETIS_UART4 default n select UART4_SERIALDRIVER select KINETIS_UART + select KINETIS_SERIALDRIVER + select ARCH_HAVE_SERIAL_TERMIOS ---help--- Support UART4 @@ -371,6 +385,8 @@ config KINETIS_UART5 depends on KINETIS_HAVE_UART5 select UART5_SERIALDRIVER select KINETIS_UART + select KINETIS_SERIALDRIVER + select ARCH_HAVE_SERIAL_TERMIOS ---help--- Support UART5 @@ -380,6 +396,8 @@ config KINETIS_LPUART0 depends on KINETIS_HAVE_LPUART0 select OTHER_UART_SERIALDRIVER select KINETIS_LPUART + select KINETIS_SERIALDRIVER + select ARCH_HAVE_SERIAL_TERMIOS ---help--- Support the low power UART0 @@ -389,6 +407,8 @@ config KINETIS_LPUART1 depends on KINETIS_HAVE_LPUART1 select OTHER_UART_SERIALDRIVER select KINETIS_LPUART + select KINETIS_SERIALDRIVER + select ARCH_HAVE_SERIAL_TERMIOS ---help--- Support the low power UART1 @@ -933,6 +953,43 @@ endmenu # Kinetis SDHC Configuration # menu "Kinetis UART Configuration" +if KINETIS_SERIALDRIVER || OTHER_SERIALDRIVER + +comment "Serial Driver Configuration" + +config KINETIS_UART_BREAKS + bool "Add TIOxSBRK to support sending Breaks" + depends on KINETIS_UART || KINETIS_LPUART + default n + ---help--- + Add TIOCxBRK routines to send a line break per the Kinetis manual, the + break will be a pulse based on the value M. This is not a BSD compatible + break. + +config KINETIS_UART_EXTEDED_BREAK + bool "Selects a longer transmitted break character length" + depends on KINETIS_UART_BREAKS + default n + ---help--- + Sets BRK13 to send a longer transmitted break character. + +config KINETIS_SERIALBRK_BSDCOMPAT + bool "BSD compatible break the break asserted until released" + depends on (KINETIS_UART || KINETIS_LPUART) && KINETIS_UART_BREAKS + default n + ---help--- + Enable using a BSD compatible break: TIOCSBRK will start the break + and TIOCCBRK will end the break. + +config KINETIS_UART_SINGLEWIRE + bool "Single Wire Support" + default n + depends on KINETIS_UART || KINETIS_LPUART + ---help--- + Enable single wire UART and LPUART support. The option enables support + for the TIOCSSINGLEWIRE ioctl in the Kineteis serial drivers. + +endif # KINETIS_SERIALDRIVER || OTHER_SERIALDRIVER config KINETIS_UARTFIFOS bool "Enable UART0 FIFO" diff --git a/arch/arm/src/kinetis/kinetis.h b/arch/arm/src/kinetis/kinetis.h index 3f171e223b5..89ab7917411 100644 --- a/arch/arm/src/kinetis/kinetis.h +++ b/arch/arm/src/kinetis/kinetis.h @@ -468,7 +468,8 @@ void kinetis_lpuartreset(uintptr_t uart_base); #ifdef HAVE_UART_DEVICE void kinetis_uartconfigure(uintptr_t uart_base, uint32_t baud, uint32_t clock, unsigned int parity, unsigned int nbits, - unsigned int stop2); + unsigned int stop2, + bool iflow, bool oflow); #endif /**************************************************************************** @@ -482,7 +483,8 @@ void kinetis_uartconfigure(uintptr_t uart_base, uint32_t baud, uint32_t clock, #ifdef HAVE_LPUART_DEVICE void kinetis_lpuartconfigure(uintptr_t uart_base, uint32_t baud, uint32_t clock, unsigned int parity, unsigned int nbits, - unsigned int stop2); + unsigned int stop2, + bool iflow, bool oflow); #endif /************************************************************************************ diff --git a/arch/arm/src/kinetis/kinetis_lowputc.c b/arch/arm/src/kinetis/kinetis_lowputc.c index 31bb32f697b..bfc56dd069f 100644 --- a/arch/arm/src/kinetis/kinetis_lowputc.c +++ b/arch/arm/src/kinetis/kinetis_lowputc.c @@ -41,6 +41,7 @@ #include #include +#include #include #include @@ -59,6 +60,58 @@ * Pre-processor Definitions ****************************************************************************/ +/* Default hardware flow control */ + +#if !defined(CONFIG_UART0_IFLOWCONTROL) +# define CONFIG_UART0_IFLOWCONTROL 0 +#endif +#if !defined(CONFIG_UART0_OFLOWCONTROL) +# define CONFIG_UART0_OFLOWCONTROL 0 +#endif +#if !defined(CONFIG_UART1_IFLOWCONTROL) +# define CONFIG_UART1_IFLOWCONTROL 0 +#endif +#if !defined(CONFIG_UART1_OFLOWCONTROL) +# define CONFIG_UART1_OFLOWCONTROL 0 +#endif +#if !defined(CONFIG_UART2_IFLOWCONTROL) +# define CONFIG_UART2_IFLOWCONTROL 0 +#endif +#if !defined(CONFIG_UART2_OFLOWCONTROL) +# define CONFIG_UART2_OFLOWCONTROL 0 +#endif +#if !defined(CONFIG_UART3_IFLOWCONTROL) +# define CONFIG_UART3_IFLOWCONTROL 0 +#endif +#if !defined(CONFIG_UART3_OFLOWCONTROL) +# define CONFIG_UART3_OFLOWCONTROL 0 +#endif +#if !defined(CONFIG_UART4_IFLOWCONTROL) +# define CONFIG_UART4_IFLOWCONTROL 0 +#endif +#if !defined(CONFIG_UART4_OFLOWCONTROL) +# define CONFIG_UART4_OFLOWCONTROL 0 +#endif +#if !defined(CONFIG_UART5_IFLOWCONTROL) +# define CONFIG_UART5_IFLOWCONTROL 0 +#endif +#if !defined(CONFIG_UART5_OFLOWCONTROL) +# define CONFIG_UART5_OFLOWCONTROL 0 +#endif + +#if !defined(CONFIG_LPUART0_IFLOWCONTROL) +# define CONFIG_LPUART0_IFLOWCONTROL 0 +#endif +#if !defined(CONFIG_LPUART0_OFLOWCONTROL) +# define CONFIG_LPUART0_OFLOWCONTROL 0 +#endif +#if !defined(CONFIG_LPUART1_IFLOWCONTROL) +# define CONFIG_LPUART1_IFLOWCONTROL 0 +#endif +#if !defined(CONFIG_LPUART1_OFLOWCONTROL) +# define CONFIG_LPUART1_OFLOWCONTROL 0 +#endif + /* Select UART parameters for the selected console */ #if defined(HAVE_UART_CONSOLE) @@ -69,6 +122,8 @@ # define CONSOLE_BITS CONFIG_UART0_BITS # define CONSOLE_2STOP CONFIG_UART0_2STOP # define CONSOLE_PARITY CONFIG_UART0_PARITY +# define CONSOLE_IFLOW CONFIG_UART0_IFLOWCONTROL +# define CONSOLE_OFLOW CONFIG_UART0_OFLOWCONTROL # elif defined(CONFIG_UART1_SERIAL_CONSOLE) # define CONSOLE_BASE KINETIS_UART1_BASE # define CONSOLE_FREQ BOARD_CORECLK_FREQ @@ -76,6 +131,8 @@ # define CONSOLE_BITS CONFIG_UART1_BITS # define CONSOLE_2STOP CONFIG_UART1_2STOP # define CONSOLE_PARITY CONFIG_UART1_PARITY +# define CONSOLE_IFLOW CONFIG_UART1_IFLOWCONTROL +# define CONSOLE_OFLOW CONFIG_UART1_OFLOWCONTROL # elif defined(CONFIG_UART2_SERIAL_CONSOLE) # define CONSOLE_BASE KINETIS_UART2_BASE # define CONSOLE_FREQ BOARD_BUS_FREQ @@ -83,6 +140,8 @@ # define CONSOLE_BITS CONFIG_UART2_BITS # define CONSOLE_2STOP CONFIG_UART2_2STOP # define CONSOLE_PARITY CONFIG_UART2_PARITY +# define CONSOLE_IFLOW CONFIG_UART2_IFLOWCONTROL +# define CONSOLE_OFLOW CONFIG_UART2_OFLOWCONTROL # elif defined(CONFIG_UART3_SERIAL_CONSOLE) # define CONSOLE_BASE KINETIS_UART3_BASE # define CONSOLE_FREQ BOARD_BUS_FREQ @@ -90,6 +149,8 @@ # define CONSOLE_BITS CONFIG_UART3_BITS # define CONSOLE_2STOP CONFIG_UART3_2STOP # define CONSOLE_PARITY CONFIG_UART3_PARITY +# define CONSOLE_IFLOW CONFIG_UART3_IFLOWCONTROL +# define CONSOLE_OFLOW CONFIG_UART3_OFLOWCONTROL # elif defined(CONFIG_UART4_SERIAL_CONSOLE) # define CONSOLE_BASE KINETIS_UART4_BASE # define CONSOLE_FREQ BOARD_BUS_FREQ @@ -97,6 +158,8 @@ # define CONSOLE_BITS CONFIG_UART4_BITS # define CONSOLE_2STOP CONFIG_UART4_2STOP # define CONSOLE_PARITY CONFIG_UART4_PARITY +# define CONSOLE_IFLOW CONFIG_UART4_IFLOWCONTROL +# define CONSOLE_OFLOW CONFIG_UART4_OFLOWCONTROL # elif defined(CONFIG_UART5_SERIAL_CONSOLE) # define CONSOLE_BASE KINETIS_UART5_BASE # define CONSOLE_FREQ BOARD_BUS_FREQ @@ -104,6 +167,8 @@ # define CONSOLE_BITS CONFIG_UART5_BITS # define CONSOLE_2STOP CONFIG_UART5_2STOP # define CONSOLE_PARITY CONFIG_UART5_PARITY +# define CONSOLE_IFLOW CONFIG_UART5_IFLOWCONTROL +# define CONSOLE_OFLOW CONFIG_UART5_OFLOWCONTROL # elif defined(HAVE_UART_CONSOLE) # error "No CONFIG_UARTn_SERIAL_CONSOLE Setting" # endif @@ -115,6 +180,8 @@ # define CONSOLE_PARITY CONFIG_LPUART0_PARITY # define CONSOLE_BITS CONFIG_LPUART0_BITS # define CONSOLE_2STOP CONFIG_LPUART0_2STOP +# define CONSOLE_IFLOW CONFIG_LPUART0_IFLOWCONTROL +# define CONSOLE_OFLOW CONFIG_LPUART0_OFLOWCONTROL # elif defined(CONFIG_LPUART1_SERIAL_CONSOLE) # define CONSOLE_BASE KINETIS_LPUART1_BASE # define CONSOLE_FREQ BOARD_LPUART1_FREQ @@ -122,6 +189,8 @@ # define CONSOLE_PARITY CONFIG_LPUART1_PARITY # define CONSOLE_BITS CONFIG_LPUART1_BITS # define CONSOLE_2STOP CONFIG_LPUART1_2STOP +# define CONSOLE_IFLOW CONFIG_LPUART1_IFLOWCONTROL +# define CONSOLE_OFLOW CONFIG_LPUART1_OFLOWCONTROL # else # error "No LPUART console is selected" # endif @@ -271,26 +340,62 @@ void kinetis_lowsetup(void) # ifdef CONFIG_KINETIS_UART0 kinetis_pinconfig(PIN_UART0_TX); kinetis_pinconfig(PIN_UART0_RX); +# if CONFIG_UART0_IFLOWCONTROL == 1 + kinetis_pinconfig(PIN_UART0_RTS); +# endif +# if CONFIG_UART0_OFLOWCONTROL == 1 + kinetis_pinconfig(PIN_UART0_CTS); +# endif # endif # ifdef CONFIG_KINETIS_UART1 kinetis_pinconfig(PIN_UART1_TX); kinetis_pinconfig(PIN_UART1_RX); +# if CONFIG_UART1_IFLOWCONTROL == 1 + kinetis_pinconfig(PIN_UART1_RTS); +# endif +# if CONFIG_UART1_OFLOWCONTROL == 1 + kinetis_pinconfig(PIN_UART1_CTS); +# endif # endif # ifdef CONFIG_KINETIS_UART2 kinetis_pinconfig(PIN_UART2_TX); kinetis_pinconfig(PIN_UART2_RX); +# if CONFIG_UART2_IFLOWCONTROL == 1 + kinetis_pinconfig(PIN_UART2_RTS); +# endif +# if CONFIG_UART2_OFLOWCONTROL == 1 + kinetis_pinconfig(PIN_UART2_CTS); +# endif # endif # ifdef CONFIG_KINETIS_UART3 kinetis_pinconfig(PIN_UART3_TX); kinetis_pinconfig(PIN_UART3_RX); +# if CONFIG_UART3_IFLOWCONTROL == 1 + kinetis_pinconfig(PIN_UART3_RTS); +# endif +# if CONFIG_UART3_OFLOWCONTROL == 1 + kinetis_pinconfig(PIN_UART3_CTS); +# endif # endif # ifdef CONFIG_KINETIS_UART4 kinetis_pinconfig(PIN_UART4_TX); kinetis_pinconfig(PIN_UART4_RX); +# if CONFIG_UART4_IFLOWCONTROL == 1 + kinetis_pinconfig(PIN_UART4_RTS); +# endif +# if CONFIG_UART4_OFLOWCONTROL == 1 + kinetis_pinconfig(PIN_UART4_CTS); +# endif # endif # ifdef CONFIG_KINETIS_UART5 kinetis_pinconfig(PIN_UART5_TX); kinetis_pinconfig(PIN_UART5_RX); +# if CONFIG_UART5_IFLOWCONTROL == 1 + kinetis_pinconfig(PIN_UART5_RTS); +# endif +# if CONFIG_UART5_OFLOWCONTROL == 1 + kinetis_pinconfig(PIN_UART5_CTS); +# endif # endif /* Configure the console (only) now. Other UARTs will be configured @@ -300,7 +405,8 @@ void kinetis_lowsetup(void) # if defined(HAVE_UART_CONSOLE) && !defined(CONFIG_SUPPRESS_UART_CONFIG) kinetis_uartconfigure(CONSOLE_BASE, CONSOLE_BAUD, CONSOLE_FREQ, \ - CONSOLE_PARITY, CONSOLE_BITS, CONSOLE_2STOP); + CONSOLE_PARITY, CONSOLE_BITS, CONSOLE_2STOP, \ + CONSOLE_IFLOW, CONSOLE_OFLOW); # endif #endif /* HAVE_UART_DEVICE */ @@ -327,17 +433,30 @@ void kinetis_lowsetup(void) # ifdef CONFIG_KINETIS_LPUART0 kinetis_pinconfig(PIN_LPUART0_TX); kinetis_pinconfig(PIN_LPUART0_RX); +# if CONFIG_LPUART0_IFLOWCONTROL == 1 + kinetis_pinconfig(PIN_LPUART0_RTS); +# endif +# if CONFIG_LPUART0_OFLOWCONTROL == 1 + kinetis_pinconfig(PIN_LOUART0_CTS); +# endif # endif # ifdef CONFIG_KINETIS_LPUART1 kinetis_pinconfig(PIN_LPUART1_TX); kinetis_pinconfig(PIN_LPUART1_RX); +# if CONFIG_LPUART1_IFLOWCONTROL == 1 + kinetis_pinconfig(PIN_LPUART1_RTS); +# endif +# if CONFIG_LPUART1_OFLOWCONTROL == 1 + kinetis_pinconfig(PIN_LOUART1_CTS); +# endif # endif # if defined(HAVE_LPUART_CONSOLE) && !defined(CONFIG_SUPPRESS_LPUART_CONFIG) kinetis_lpuartconfigure(CONSOLE_BASE, CONSOLE_BAUD, CONSOLE_FREQ, \ - CONSOLE_PARITY, CONSOLE_BITS, CONSOLE_2STOP); + CONSOLE_PARITY, CONSOLE_BITS, CONSOLE_2STOP, \ + CONSOLE_IFLOW, CONSOLE_OFLOW); # endif #endif /* HAVE_LPUART_DEVICE */ } @@ -395,7 +514,8 @@ void kinetis_lpuartreset(uintptr_t uart_base) #ifdef HAVE_UART_DEVICE void kinetis_uartconfigure(uintptr_t uart_base, uint32_t baud, uint32_t clock, unsigned int parity, - unsigned int nbits, unsigned int stop2) + unsigned int nbits, unsigned int stop2, + bool iflow, bool oflow) { uint32_t sbr; uint32_t brfa; @@ -542,6 +662,27 @@ void kinetis_uartconfigure(uintptr_t uart_base, uint32_t baud, putreg8(0, uart_base+KINETIS_UART_PFIFO_OFFSET); #endif + /* Hardware flow control */ + + regval = getreg8(uart_base+KINETIS_UART_MODEM_OFFSET); + regval &= ~(UART_MODEM_TXCTSE | UART_MODEM_RXRTSE); + +#ifdef CONFIG_SERIAL_IFLOWCONTROL + if (iflow) + { + regval |= UART_MODEM_RXRTSE; + } +#endif + +#ifdef CONFIG_SERIAL_OFLOWCONTROL + if (oflow) + { + regval |= UART_MODEM_TXCTSE; + } +#endif + + putreg8(regval, uart_base+KINETIS_UART_MODEM_OFFSET); + /* Now we can (re-)enable the transmitter and receiver */ regval = getreg8(uart_base+KINETIS_UART_C2_OFFSET); @@ -561,7 +702,8 @@ void kinetis_uartconfigure(uintptr_t uart_base, uint32_t baud, #ifdef HAVE_LPUART_DEVICE void kinetis_lpuartconfigure(uintptr_t uart_base, uint32_t baud, uint32_t clock, unsigned int parity, - unsigned int nbits, unsigned int stop2) + unsigned int nbits, unsigned int stop2, + bool iflow, bool oflow) { uint32_t sbrreg; uint32_t osrreg; @@ -711,6 +853,25 @@ void kinetis_lpuartconfigure(uintptr_t uart_base, uint32_t baud, DEBUGASSERT(nbits == 8); } + /* Hardware flow control */ + + regval = getreg32(uart_base+KINETIS_LPUART_MODIR_OFFSET); + regval &= ~(UART_MODEM_TXCTSE | UART_MODEM_RXRTSE); + +#ifdef CONFIG_SERIAL_IFLOWCONTROL + if (iflow) + { + regval |= LPUART_MODIR_RXRTSE; + } +#endif + #ifdef CONFIG_SERIAL_OFLOWCONTROL + if (oflow) + { + regval |= LPUART_MODIR_TXCTSE; + } +#endif + putreg32(regval, uart_base+KINETIS_LPUART_MODIR_OFFSET); + /* Now we can (re-)enable the transmitter and receiver */ regval |= (LPUART_CTRL_RE | LPUART_CTRL_TE); diff --git a/arch/arm/src/kinetis/kinetis_lpserial.c b/arch/arm/src/kinetis/kinetis_lpserial.c index 2980f18b8d4..5a70582d411 100644 --- a/arch/arm/src/kinetis/kinetis_lpserial.c +++ b/arch/arm/src/kinetis/kinetis_lpserial.c @@ -53,6 +53,11 @@ #include #include +#ifdef CONFIG_SERIAL_TERMIOS +# include +#endif + +#include #include #include "up_arch.h" @@ -61,6 +66,7 @@ #include "kinetis_config.h" #include "chip.h" #include "chip/kinetis_lpuart.h" +#include "chip/kinetis_pinmux.h" #include "kinetis.h" /**************************************************************************** @@ -153,6 +159,18 @@ struct kinetis_dev_s uint8_t parity; /* 0=none, 1=odd, 2=even */ uint8_t bits; /* Number of bits (8 or 9) */ uint8_t stop2; /* Use 2 stop bits */ +#ifdef CONFIG_SERIAL_IFLOWCONTROL + bool iflow; /* input flow control (RTS) enabled */ +#endif +#ifdef CONFIG_SERIAL_OFLOWCONTROL + bool oflow; /* output flow control (CTS) enabled */ +#endif +#ifdef CONFIG_SERIAL_IFLOWCONTROL + uint32_t rts_gpio; /* UART RTS GPIO pin configuration */ +#endif +#ifdef CONFIG_SERIAL_OFLOWCONTROL + uint32_t cts_gpio; /* UART CTS GPIO pin configuration */ +#endif }; /**************************************************************************** @@ -168,6 +186,10 @@ static int kinetis_ioctl(struct file *filep, int cmd, unsigned long arg); static int kinetis_receive(struct uart_dev_s *dev, uint32_t *status); static void kinetis_rxint(struct uart_dev_s *dev, bool enable); static bool kinetis_rxavailable(struct uart_dev_s *dev); +#ifdef CONFIG_SERIAL_IFLOWCONTROL +static bool kinetis_rxflowcontrol(struct uart_dev_s *dev, unsigned int nbuffered, + bool upper); +#endif static void kinetis_send(struct uart_dev_s *dev, int ch); static void kinetis_txint(struct uart_dev_s *dev, bool enable); static bool kinetis_txready(struct uart_dev_s *dev); @@ -187,7 +209,7 @@ static const struct uart_ops_s g_lpuart_ops = .rxint = kinetis_rxint, .rxavailable = kinetis_rxavailable, #ifdef CONFIG_SERIAL_IFLOWCONTROL - .rxflowcontrol = NULL, + .rxflowcontrol = kinetis_rxflowcontrol, #endif .send = kinetis_send, .txint = kinetis_txint, @@ -219,6 +241,14 @@ static struct kinetis_dev_s g_lpuart0priv = .parity = CONFIG_LPUART0_PARITY, .bits = CONFIG_LPUART0_BITS, .stop2 = CONFIG_LPUART0_2STOP, +#if defined(CONFIG_SERIAL_OFLOWCONTROL) && defined(CONFIG_LPUART0_OFLOWCONTROL) + .oflow = true, + .cts_gpio = PIN_LPUART0_CTS, +#endif +#if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_LPUART0_IFLOWCONTROL) + .iflow = true, + .rts_gpio = PIN_LPUART0_RTS, +#endif }; static uart_dev_t g_lpuart0port = @@ -251,6 +281,14 @@ static struct kinetis_dev_s g_lpuart1priv = .parity = CONFIG_LPUART1_PARITY, .bits = CONFIG_LPUART1_BITS, .stop2 = CONFIG_LPUART1_2STOP, +#if defined(CONFIG_SERIAL_OFLOWCONTROL) && defined(CONFIG_LPUART1_OFLOWCONTROL) + .oflow = true, + .cts_gpio = PIN_LPUART1_CTS, +#endif +#if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_LPUART1_IFLOWCONTROL) + .iflow = true, + .rts_gpio = PIN_LPUART1_RTS, +#endif }; static uart_dev_t g_lpuart1port = @@ -360,11 +398,22 @@ static int kinetis_setup(struct uart_dev_s *dev) { #ifndef CONFIG_SUPPRESS_LPUART_CONFIG struct kinetis_dev_s *priv = (struct kinetis_dev_s *)dev->priv; +#ifdef CONFIG_SERIAL_IFLOWCONTROL + bool iflow = priv->iflow; +#else + bool iflow = false; +#endif +#ifdef CONFIG_SERIAL_OFLOWCONTROL + bool oflow = priv->oflow; +#else + bool oflow = false; +#endif /* Configure the LPUART as an RS-232 UART */ kinetis_lpuartconfigure(priv->uartbase, priv->baud, priv->clock, - priv->parity, priv->bits, priv->stop2); + priv->parity, priv->bits, priv->stop2, + iflow, oflow); #endif /* Make sure that all interrupts are disabled */ @@ -564,23 +613,234 @@ static int kinetis_interrupt(int irq, void *context, void *arg) static int kinetis_ioctl(struct file *filep, int cmd, unsigned long arg) { -#if 0 /* Reserved for future growth */ - struct inode *inode; - struct uart_dev_s *dev; - struct kinetis_dev_s *priv; - int ret = OK; +#if defined(CONFIG_SERIAL_TERMIOS) || defined(CONFIG_SERIAL_TIOCSERGSTRUCT) || \ + defined(CONFIG_KINETIS_SERIALBRK_BSDCOMPAT) + struct inode *inode = filep->f_inode; + struct uart_dev_s *dev = inode->i_private; + uint8_t regval; +#endif +#if defined(CONFIG_SERIAL_TERMIOS) || defined(CONFIG_KINETIS_SERIALBRK_BSDCOMPAT) + struct kinetis_dev_s *priv = (struct kinetis_dev_s *)dev->priv; + bool iflow = false; + bool oflow = false; +#endif + int ret = OK; - DEBUGASSERT(filep, filep->f_inode); +#if defined(CONFIG_SERIAL_TERMIOS) || defined(CONFIG_SERIAL_TIOCSERGSTRUCT) || \ + defined(CONFIG_KINETIS_SERIALBRK_BSDCOMPAT) + DEBUGASSERT(filep != NULL && filep->f_inode != NULL); inode = filep->f_inode; dev = inode->i_private; - - DEBUGASSERT(dev, dev->priv); - priv = (struct kinetis_dev_s *)dev->priv; + DEBUGASSERT(dev != NULL && dev->priv != NULL); +#endif switch (cmd) { - case xxx: /* Add commands here */ +#ifdef CONFIG_SERIAL_TIOCSERGSTRUCT + case TIOCSERGSTRUCT: + { + struct kinetis_dev_s *user = (struct kinetis_dev_s *)arg; + if (!user) + { + ret = -EINVAL; + } + else + { + memcpy(user, dev, sizeof(struct kinetis_dev_s)); + } + } break; +#endif + +#ifdef CONFIG_KINETIS_UART_SINGLEWIRE + case TIOCSSINGLEWIRE: + { + /* Change to single-wire operation. the RXD pin is disconnected from + * the UART and the UART implements a half-duplex serial connection. + * The UART uses the TXD pin for both receiving and transmitting + */ + + regval = kinetis_serialin(priv, KINETIS_LPUART_CTRL_OFFSET); + + if (arg == SER_SINGLEWIRE_ENABLED) + { + regval |= (LPUART_CTRL_LOOPS | LPUART_CTRL_RSRC); + } + else + { + regval &= ~(LPUART_CTRL_LOOPS | LPUART_CTRL_RSRC); + } + kinetis_serialout(priv, KINETIS_LPUART_CTRL_OFFSET, regval); + } + break; +#endif + +#ifdef CONFIG_SERIAL_TERMIOS + case TCGETS: + { + struct termios *termiosp = (struct termios *)arg; + + if (!termiosp) + { + ret = -EINVAL; + break; + } + + cfsetispeed(termiosp, priv->baud); + + /* Note: CSIZE only supports 5-8 bits. The driver only support 8/9 bit + * modes and therefore is no way to report 9-bit mode, we always claim + * 8 bit mode. + */ + + termiosp->c_cflag = + ((priv->parity != 0) ? PARENB : 0) | + ((priv->parity == 1) ? PARODD : 0) | + ((priv->stop2) ? CSTOPB : 0) | +# ifdef CONFIG_SERIAL_OFLOWCONTROL + ((priv->oflow) ? CCTS_OFLOW : 0) | +# endif +# ifdef CONFIG_SERIAL_IFLOWCONTROL + ((priv->iflow) ? CRTS_IFLOW : 0) | +# endif + CS8; + + /* TODO: CCTS_IFLOW, CCTS_OFLOW */ + } + break; + + case TCSETS: + { + struct termios *termiosp = (struct termios *)arg; + + if (!termiosp) + { + ret = -EINVAL; + break; + } + + /* Perform some sanity checks before accepting any changes */ + + if (((termiosp->c_cflag & CSIZE) != CS8) +# ifdef CONFIG_SERIAL_IFLOWCONTROL + || ((termiosp->c_cflag & CCTS_OFLOW) && (priv->cts_gpio == 0)) +# endif +# ifdef CONFIG_SERIAL_IFLOWCONTROL + || ((termiosp->c_cflag & CRTS_IFLOW) && (priv->rts_gpio == 0)) +# endif + ) + { + ret = -EINVAL; + break; + } + + if (termiosp->c_cflag & PARENB) + { + priv->parity = (termiosp->c_cflag & PARODD) ? 1 : 2; + } + else + { + priv->parity = 0; + } + + priv->stop2 = (termiosp->c_cflag & CSTOPB) != 0; +# ifdef CONFIG_SERIAL_OFLOWCONTROL + priv->oflow = (termiosp->c_cflag & CCTS_OFLOW) != 0; + oflow = priv->oflow; +# endif +# ifdef CONFIG_SERIAL_IFLOWCONTROL + priv->iflow = (termiosp->c_cflag & CRTS_IFLOW) != 0; + iflow = priv->iflow; +# endif + + /* Note that since there is no way to request 9-bit mode + * and no way to support 5/6/7-bit modes, we ignore them + * all here. + */ + + /* Note that only cfgetispeed is used because we have knowledge + * that only one speed is supported. + */ + + priv->baud = cfgetispeed(termiosp); + + /* Effect the changes immediately - note that we do not implement + * TCSADRAIN / TCSAFLUSH + */ + + kinetis_uartconfigure(priv->uartbase, priv->baud, priv->clock, + priv->parity, priv->bits, priv->stop2, + iflow, oflow); + } + break; +#endif /* CONFIG_SERIAL_TERMIOS */ + +#ifdef CONFIG_KINETIS_UART_BREAKS + case TIOCSBRK: + { + irqstate_t flags; + + flags = enter_critical_section(); + + /* Send a longer break signal */ + + regval = kinetis_serialin(priv, KINETIS_LPUART_STAT_OFFSET); + regval &= ~LPUART_STAT_BRK13; +# ifdef CONFIG_KINETIS_UART_EXTEDED_BREAK + regval |= LPUART_STAT_BRK13; +# endif + kinetis_serialout(priv, LPUART_STAT_BRK13, regval); + + /* Send a break signal */ + + regval = kinetis_serialin(priv, KINETIS_LPUART_CTRL_OFFSET); + regval |= LPUART_CTRL_SBK; + kinetis_serialout(priv, KINETIS_LPUART_CTRL_OFFSET, regval); + +# ifdef CONFIG_KINETIS_SERIALBRK_BSDCOMPAT + /* BSD compatibility: Turn break on, and leave it on */ + + kinetis_txint(dev, false); +# else + /* Send a single break character + * Toggling SBK sends one break character. Per the manual + * Toggling implies clearing the SBK field before the break + * character has finished transmitting. + */ + + regval &= ~LPUART_CTRL_SBK; + kinetis_serialout(priv, KINETIS_LPUART_CTRL_OFFSET, regval); +#endif + + leave_critical_section(flags); + } + break; + + case TIOCCBRK: + { + irqstate_t flags; + + flags = enter_critical_section(); + + /* Configure TX back to UART + * If non BSD compatible: This code has no effect, the SBRK + * was already cleared. + * but for BSD compatibility: Turn break off + */ + + regval = kinetis_serialin(priv, KINETIS_LPUART_CTRL_OFFSET); + regval &= ~LPUART_CTRL_SBK; + kinetis_serialout(priv, KINETIS_LPUART_CTRL_OFFSET, regval); + +# ifdef CONFIG_KINETIS_SERIALBRK_BSDCOMPAT + /* Enable further tx activity */ + + kinetis_txint(dev, true); +# endif + leave_critical_section(flags); + } + break; +#endif /* CONFIG_KINETIS_UART_BREAKS */ default: ret = -ENOTTY; @@ -588,9 +848,6 @@ static int kinetis_ioctl(struct file *filep, int cmd, unsigned long arg) } return ret; -#else - return -ENOTTY; -#endif } /**************************************************************************** @@ -696,6 +953,79 @@ static bool kinetis_rxavailable(struct uart_dev_s *dev) return (kinetis_serialin(priv, KINETIS_LPUART_STAT_OFFSET) & LPUART_STAT_RDRF) != 0; } +/**************************************************************************** + * Name: kinetis_rxflowcontrol + * + * Description: + * Called when Rx buffer is full (or exceeds configured watermark levels + * if CONFIG_SERIAL_IFLOWCONTROL_WATERMARKS is defined). + * Return true if UART activated RX flow control to block more incoming + * data + * + * Input parameters: + * dev - UART device instance + * nbuffered - the number of characters currently buffered + * (if CONFIG_SERIAL_IFLOWCONTROL_WATERMARKS is + * not defined the value will be 0 for an empty buffer or the + * defined buffer size for a full buffer) + * upper - true indicates the upper watermark was crossed where + * false indicates the lower watermark has been crossed + * + * Returned Value: + * true if RX flow control activated. + * + ****************************************************************************/ + +#ifdef CONFIG_SERIAL_IFLOWCONTROL +static bool kinetis_rxflowcontrol(struct uart_dev_s *dev, + unsigned int nbuffered, bool upper) +{ +#if defined(CONFIG_SERIAL_IFLOWCONTROL_WATERMARKS) + struct kinetis_dev_s *priv = (struct kinetis_dev_s *)dev->priv; + uint16_t ie; + + if (priv->iflow) + { + /* Is the RX buffer full? */ + + if (upper) + { + /* Disable Rx interrupt to prevent more data being from + * peripheral. When hardware RTS is enabled, this will + * prevent more data from coming in. + * + * This function is only called when UART recv buffer is full, + * that is: "dev->recv.head + 1 == dev->recv.tail". + * + * Logic in "uart_read" will automatically toggle Rx interrupts + * when buffer is read empty and thus we do not have to re- + * enable Rx interrupts. + */ + + ie = priv->ie; + ie &= ~LPUART_CTRL_RX_INTS; + kinetis_restoreuartint(priv, ie); + return true; + } + + /* No.. The RX buffer is empty */ + + else + { + /* We might leave Rx interrupt disabled if full recv buffer was + * read empty. Enable Rx interrupt to make sure that more input is + * received. + */ + + kinetis_rxint(dev, true); + } + } +#endif + + return false; +} +#endif + /**************************************************************************** * Name: kinetis_send * diff --git a/arch/arm/src/kinetis/kinetis_serial.c b/arch/arm/src/kinetis/kinetis_serial.c index 79f0030b78d..b7c6aeebc76 100644 --- a/arch/arm/src/kinetis/kinetis_serial.c +++ b/arch/arm/src/kinetis/kinetis_serial.c @@ -53,6 +53,11 @@ #include #include +#ifdef CONFIG_SERIAL_TERMIOS +# include +#endif + +#include #include #include "up_arch.h" @@ -61,6 +66,7 @@ #include "kinetis_config.h" #include "chip.h" #include "chip/kinetis_uart.h" +#include "chip/kinetis_pinmux.h" #include "kinetis.h" /**************************************************************************** @@ -242,6 +248,18 @@ struct up_dev_s uint8_t parity; /* 0=none, 1=odd, 2=even */ uint8_t bits; /* Number of bits (8 or 9) */ uint8_t stop2; /* Use 2 stop bits */ +#ifdef CONFIG_SERIAL_IFLOWCONTROL + bool iflow; /* input flow control (RTS) enabled */ +#endif +#ifdef CONFIG_SERIAL_OFLOWCONTROL + bool oflow; /* output flow control (CTS) enabled */ +#endif +#ifdef CONFIG_SERIAL_IFLOWCONTROL + uint32_t rts_gpio; /* UART RTS GPIO pin configuration */ +#endif +#ifdef CONFIG_SERIAL_OFLOWCONTROL + uint32_t cts_gpio; /* UART CTS GPIO pin configuration */ +#endif }; /**************************************************************************** @@ -260,6 +278,10 @@ static int up_ioctl(struct file *filep, int cmd, unsigned long arg); static int up_receive(struct uart_dev_s *dev, uint32_t *status); static void up_rxint(struct uart_dev_s *dev, bool enable); static bool up_rxavailable(struct uart_dev_s *dev); +#ifdef CONFIG_SERIAL_IFLOWCONTROL +static bool up_rxflowcontrol(struct uart_dev_s *dev, unsigned int nbuffered, + bool upper); +#endif static void up_send(struct uart_dev_s *dev, int ch); static void up_txint(struct uart_dev_s *dev, bool enable); static bool up_txready(struct uart_dev_s *dev); @@ -282,7 +304,7 @@ static const struct uart_ops_s g_uart_ops = .rxint = up_rxint, .rxavailable = up_rxavailable, #ifdef CONFIG_SERIAL_IFLOWCONTROL - .rxflowcontrol = NULL, + .rxflowcontrol = up_rxflowcontrol, #endif .send = up_send, .txint = up_txint, @@ -337,6 +359,14 @@ static struct up_dev_s g_uart0priv = .parity = CONFIG_UART0_PARITY, .bits = CONFIG_UART0_BITS, .stop2 = CONFIG_UART0_2STOP, +#if defined(CONFIG_SERIAL_OFLOWCONTROL) && defined(CONFIG_UART0_OFLOWCONTROL) + .oflow = true, + .cts_gpio = PIN_UART0_CTS, +#endif +#if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_UART0_IFLOWCONTROL) + .iflow = true, + .rts_gpio = PIN_UART0_RTS, +#endif }; static uart_dev_t g_uart0port = @@ -372,6 +402,14 @@ static struct up_dev_s g_uart1priv = .parity = CONFIG_UART1_PARITY, .bits = CONFIG_UART1_BITS, .stop2 = CONFIG_UART1_2STOP, +#if defined(CONFIG_SERIAL_OFLOWCONTROL) && defined(CONFIG_UART1_OFLOWCONTROL) + .oflow = true, + .cts_gpio = PIN_UART1_CTS, +#endif +#if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_UART1_IFLOWCONTROL) + .iflow = true, + .rts_gpio = PIN_UART1_RTS, +#endif }; static uart_dev_t g_uart1port = @@ -407,6 +445,14 @@ static struct up_dev_s g_uart2priv = .parity = CONFIG_UART2_PARITY, .bits = CONFIG_UART2_BITS, .stop2 = CONFIG_UART2_2STOP, +#if defined(CONFIG_SERIAL_OFLOWCONTROL) && defined(CONFIG_UART2_OFLOWCONTROL) + .oflow = true, + .cts_gpio = PIN_UART2_CTS, +#endif +#if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_UART2_IFLOWCONTROL) + .iflow = true, + .rts_gpio = PIN_UART2_RTS, +#endif }; static uart_dev_t g_uart2port = @@ -442,6 +488,14 @@ static struct up_dev_s g_uart3priv = .parity = CONFIG_UART3_PARITY, .bits = CONFIG_UART3_BITS, .stop2 = CONFIG_UART3_2STOP, +#if defined(CONFIG_SERIAL_OFLOWCONTROL) && defined(CONFIG_UART3_OFLOWCONTROL) + .oflow = true, + .cts_gpio = PIN_UART3_CTS, +#endif +#if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_UART3_IFLOWCONTROL) + .iflow = true, + .rts_gpio = PIN_UART3_RTS, +#endif }; static uart_dev_t g_uart3port = @@ -477,6 +531,14 @@ static struct up_dev_s g_uart4priv = .parity = CONFIG_UART4_PARITY, .bits = CONFIG_UART4_BITS, .stop2 = CONFIG_UART4_2STOP, +#if defined(CONFIG_SERIAL_OFLOWCONTROL) && defined(CONFIG_UART4_OFLOWCONTROL) + .oflow = true, + .cts_gpio = PIN_UART4_CTS, +#endif +#if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_UART4_IFLOWCONTROL) + .iflow = true, + .rts_gpio = PIN_UART4_RTS, +#endif }; static uart_dev_t g_uart4port = @@ -512,6 +574,14 @@ static struct up_dev_s g_uart5priv = .parity = CONFIG_UART5_PARITY, .bits = CONFIG_UART5_BITS, .stop2 = CONFIG_UART5_2STOP, +#if defined(CONFIG_SERIAL_OFLOWCONTROL) && defined(CONFIG_UART5_OFLOWCONTROL) + .oflow = true, + .cts_gpio = PIN_UART5_CTS, +#endif +#if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_UART5_IFLOWCONTROL) + .iflow = true, + .rts_gpio = PIN_UART5_RTS, +#endif }; static uart_dev_t g_uart5port = @@ -621,11 +691,23 @@ static int up_setup(struct uart_dev_s *dev) { #ifndef CONFIG_SUPPRESS_UART_CONFIG struct up_dev_s *priv = (struct up_dev_s *)dev->priv; +#ifdef CONFIG_SERIAL_IFLOWCONTROL + bool iflow = priv->iflow; +#else + bool iflow = false; +#endif +#ifdef CONFIG_SERIAL_OFLOWCONTROL + bool oflow = priv->oflow; +#else + bool oflow = false; +#endif + /* Configure the UART as an RS-232 UART */ kinetis_uartconfigure(priv->uartbase, priv->baud, priv->clock, - priv->parity, priv->bits, priv->stop2); + priv->parity, priv->bits, priv->stop2, + iflow, oflow); #endif /* Make sure that all interrupts are disabled */ @@ -891,23 +973,235 @@ static int up_interrupts(int irq, void *context, FAR void *arg) static int up_ioctl(struct file *filep, int cmd, unsigned long arg) { -#if 0 /* Reserved for future growth */ +#if defined(CONFIG_SERIAL_TERMIOS) || defined(CONFIG_SERIAL_TIOCSERGSTRUCT) || \ + defined(CONFIG_KINETIS_SERIALBRK_BSDCOMPAT) struct inode *inode; struct uart_dev_s *dev; - struct up_dev_s *priv; - int ret = OK; + uint8_t regval; +#endif +#if defined(CONFIG_SERIAL_TERMIOS) || defined(CONFIG_KINETIS_SERIALBRK_BSDCOMPAT) + struct up_dev_s *priv = (struct up_dev_s *)dev->priv; + bool iflow = false; + bool oflow = false; +#endif + int ret = OK; - DEBUGASSERT(filep, filep->f_inode); +#if defined(CONFIG_SERIAL_TERMIOS) || defined(CONFIG_SERIAL_TIOCSERGSTRUCT) || \ + defined(CONFIG_KINETIS_SERIALBRK_BSDCOMPAT) + DEBUGASSERT(filep != NULL && filep->f_inode != NULL); inode = filep->f_inode; dev = inode->i_private; - - DEBUGASSERT(dev, dev->priv); - priv = (struct up_dev_s *)dev->priv; + DEBUGASSERT(dev != NULL && dev->priv != NULL); +#endif switch (cmd) { - case xxx: /* Add commands here */ +#ifdef CONFIG_SERIAL_TIOCSERGSTRUCT + case TIOCSERGSTRUCT: + { + struct up_dev_s *user = (struct up_dev_s *)arg; + if (!user) + { + ret = -EINVAL; + } + else + { + memcpy(user, dev, sizeof(struct up_dev_s)); + } + } break; +#endif + +#ifdef CONFIG_KINETIS_UART_SINGLEWIRE + case TIOCSSINGLEWIRE: + { + /* Change to single-wire operation. the RXD pin is disconnected from + * the UART and the UART implements a half-duplex serial connection. + * The UART uses the TXD pin for both receiving and transmitting + */ + + regval = up_serialin(priv, KINETIS_UART_C1_OFFSET); + + if (arg == SER_SINGLEWIRE_ENABLED) + { + regval |= (UART_C1_LOOPS | UART_C1_RSRC); + } + else + { + regval &= ~(UART_C1_LOOPS | UART_C1_RSRC); + } + + up_serialout(priv, KINETIS_UART_C1_OFFSET, regval); + } + break; +#endif + +#ifdef CONFIG_SERIAL_TERMIOS + case TCGETS: + { + struct termios *termiosp = (struct termios *)arg; + + if (!termiosp) + { + ret = -EINVAL; + break; + } + + cfsetispeed(termiosp, priv->baud); + + /* Note: CSIZE only supports 5-8 bits. The driver only support 8/9 bit + * modes and therefore is no way to report 9-bit mode, we always claim + * 8 bit mode. + */ + + termiosp->c_cflag = + ((priv->parity != 0) ? PARENB : 0) | + ((priv->parity == 1) ? PARODD : 0) | + ((priv->stop2) ? CSTOPB : 0) | +# ifdef CONFIG_SERIAL_OFLOWCONTROL + ((priv->oflow) ? CCTS_OFLOW : 0) | +# endif +# ifdef CONFIG_SERIAL_IFLOWCONTROL + ((priv->iflow) ? CRTS_IFLOW : 0) | +# endif + CS8; + + /* TODO: CCTS_IFLOW, CCTS_OFLOW */ + } + break; + + case TCSETS: + { + struct termios *termiosp = (struct termios *)arg; + + if (!termiosp) + { + ret = -EINVAL; + break; + } + + /* Perform some sanity checks before accepting any changes */ + + if (((termiosp->c_cflag & CSIZE) != CS8) +# ifdef CONFIG_SERIAL_IFLOWCONTROL + || ((termiosp->c_cflag & CCTS_OFLOW) && (priv->cts_gpio == 0)) +# endif +# ifdef CONFIG_SERIAL_IFLOWCONTROL + || ((termiosp->c_cflag & CRTS_IFLOW) && (priv->rts_gpio == 0)) +# endif + ) + { + ret = -EINVAL; + break; + } + + if (termiosp->c_cflag & PARENB) + { + priv->parity = (termiosp->c_cflag & PARODD) ? 1 : 2; + } + else + { + priv->parity = 0; + } + + priv->stop2 = (termiosp->c_cflag & CSTOPB) != 0; +# ifdef CONFIG_SERIAL_OFLOWCONTROL + priv->oflow = (termiosp->c_cflag & CCTS_OFLOW) != 0; + oflow = priv->oflow; +# endif +# ifdef CONFIG_SERIAL_IFLOWCONTROL + priv->iflow = (termiosp->c_cflag & CRTS_IFLOW) != 0; + iflow = priv->iflow; +# endif + + /* Note that since there is no way to request 9-bit mode + * and no way to support 5/6/7-bit modes, we ignore them + * all here. + */ + + /* Note that only cfgetispeed is used because we have knowledge + * that only one speed is supported. + */ + + priv->baud = cfgetispeed(termiosp); + + /* Effect the changes immediately - note that we do not implement + * TCSADRAIN / TCSAFLUSH + */ + + kinetis_uartconfigure(priv->uartbase, priv->baud, priv->clock, + priv->parity, priv->bits, priv->stop2, + iflow, oflow); + } + break; +#endif /* CONFIG_SERIAL_TERMIOS */ + +#ifdef CONFIG_KINETIS_UART_BREAKS + case TIOCSBRK: + { + irqstate_t flags; + + flags = enter_critical_section(); + + /* Send a longer break signal */ + + regval = up_serialin(priv, KINETIS_UART_S2_OFFSET); + regval &= ~UART_S2_BRK13; +# ifdef CONFIG_KINETIS_UART_EXTEDED_BREAK + regval |= UART_S2_BRK13; +# endif + up_serialout(priv, KINETIS_UART_S2_OFFSET, regval); + + /* Send a break signal */ + + regval = up_serialin(priv, KINETIS_UART_C2_OFFSET); + regval |= UART_C2_SBK; + up_serialout(priv, KINETIS_UART_C2_OFFSET, regval); + +# ifdef CONFIG_KINETIS_SERIALBRK_BSDCOMPAT + /* BSD compatibility: Turn break on, and leave it on */ + + up_txint(dev, false); +# else + /* Send a single break character + * Toggling SBK sends one break character. Per the manual + * Toggling implies clearing the SBK field before the break + * character has finished transmitting. + */ + + regval &= ~(UART_C2_SBK); + up_serialout(priv, KINETIS_UART_C2_OFFSET, regval); +#endif + + leave_critical_section(flags); + } + break; + + case TIOCCBRK: + { + irqstate_t flags; + + flags = enter_critical_section(); + + /* Configure TX back to UART + * If non BSD compatible: This code has no effect, the SBRK + * was already cleared. + * but for BSD compatibility: Turn break off + */ + + regval = up_serialin(priv, KINETIS_UART_C2_OFFSET); + regval &= ~UART_C2_SBK; + up_serialout(priv, KINETIS_UART_C2_OFFSET, regval); + +# ifdef CONFIG_KINETIS_SERIALBRK_BSDCOMPAT + /* Enable further tx activity */ + + up_txint(dev, true); +# endif + leave_critical_section(flags); + } + break; +#endif /* CONFIG_KINETIS_UART_BREAKS */ default: ret = -ENOTTY; @@ -915,9 +1209,6 @@ static int up_ioctl(struct file *filep, int cmd, unsigned long arg) } return ret; -#else - return -ENOTTY; -#endif } /**************************************************************************** @@ -1030,6 +1321,79 @@ static bool up_rxavailable(struct uart_dev_s *dev) #endif } +/**************************************************************************** + * Name: up_rxflowcontrol + * + * Description: + * Called when Rx buffer is full (or exceeds configured watermark levels + * if CONFIG_SERIAL_IFLOWCONTROL_WATERMARKS is defined). + * Return true if UART activated RX flow control to block more incoming + * data + * + * Input parameters: + * dev - UART device instance + * nbuffered - the number of characters currently buffered + * (if CONFIG_SERIAL_IFLOWCONTROL_WATERMARKS is + * not defined the value will be 0 for an empty buffer or the + * defined buffer size for a full buffer) + * upper - true indicates the upper watermark was crossed where + * false indicates the lower watermark has been crossed + * + * Returned Value: + * true if RX flow control activated. + * + ****************************************************************************/ + +#ifdef CONFIG_SERIAL_IFLOWCONTROL +static bool up_rxflowcontrol(struct uart_dev_s *dev, + unsigned int nbuffered, bool upper) +{ +#if defined(CONFIG_SERIAL_IFLOWCONTROL_WATERMARKS) + struct up_dev_s *priv = (struct up_dev_s *)dev->priv; + uint16_t ie; + + if (priv->iflow) + { + /* Is the RX buffer full? */ + + if (upper) + { + /* Disable Rx interrupt to prevent more data being from + * peripheral. When hardware RTS is enabled, this will + * prevent more data from coming in. + * + * This function is only called when UART recv buffer is full, + * that is: "dev->recv.head + 1 == dev->recv.tail". + * + * Logic in "uart_read" will automatically toggle Rx interrupts + * when buffer is read empty and thus we do not have to re- + * enable Rx interrupts. + */ + + ie = priv->ie; + ie &= ~UART_C2_RIE; + up_restoreuartint(priv, ie); + return true; + } + + /* No.. The RX buffer is empty */ + + else + { + /* We might leave Rx interrupt disabled if full recv buffer was + * read empty. Enable Rx interrupt to make sure that more input is + * received. + */ + + up_rxint(dev, true); + } + } +#endif + + return false; +} +#endif + /**************************************************************************** * Name: up_send * From 2c57c3f83ba1eacc49fc8ca587bc733d62789999 Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Wed, 3 May 2017 21:49:59 -0400 Subject: [PATCH 146/183] wireless/ieee802154: Changes rxenable at radio layer --- drivers/wireless/ieee802154/mrf24j40.c | 37 ++++++++++++------- .../wireless/ieee802154/ieee802154_radio.h | 2 +- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/drivers/wireless/ieee802154/mrf24j40.c b/drivers/wireless/ieee802154/mrf24j40.c index c703933acc2..9fb75cf03a7 100644 --- a/drivers/wireless/ieee802154/mrf24j40.c +++ b/drivers/wireless/ieee802154/mrf24j40.c @@ -224,7 +224,7 @@ static int mrf24j40_bind(FAR struct ieee802154_radio_s *radio, FAR struct ieee802154_radiocb_s *radiocb); static int mrf24j40_ioctl(FAR struct ieee802154_radio_s *radio, int cmd, unsigned long arg); -static int mrf24j40_rxenable(FAR struct ieee802154_radio_s *radio); +static int mrf24j40_rxenable(FAR struct ieee802154_radio_s *radio bool enable); static int mrf24j40_txnotify_csma(FAR struct ieee802154_radio_s *radio); static int mrf24j40_txnotify_gts(FAR struct ieee802154_radio_s *radio); @@ -1336,8 +1336,6 @@ static int mrf24j40_csma_setup(FAR struct mrf24j40_radio_s *dev, uint8_t reg; int ret; - mrf24j40_pacontrol(dev, MRF24J40_PA_AUTO); - /* Enable tx int */ reg = mrf24j40_getreg(dev->spi, MRF24J40_INTCON); @@ -1534,22 +1532,31 @@ static void mrf24j40_irqwork_txgts(FAR struct mrf24j40_radio_s *dev, * Name: mrf24j40_rxenable * * Description: - * Enable reception of a packet. The interrupt will signal the rx semaphore. + * Enable/Disable receiver. * ****************************************************************************/ -static int mrf24j40_rxenable(FAR struct ieee802154_radio_s *radio) +static int mrf24j40_rxenable(FAR struct ieee802154_radio_s *radio, bool enable) { FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)radio; uint8_t reg; - mrf24j40_pacontrol(dev, MRF24J40_PA_AUTO); + if (enable) + { + /* Enable rx int */ - /* Enable rx int */ + reg = mrf24j40_getreg(dev->spi, MRF24J40_INTCON); + reg &= ~MRF24J40_INTCON_RXIE; + mrf24j40_setreg(dev->spi, MRF24J40_INTCON, reg); + } + else + { + /* Disable rx int */ - reg = mrf24j40_getreg(dev->spi, MRF24J40_INTCON); - reg &= ~MRF24J40_INTCON_RXIE; - mrf24j40_setreg(dev->spi, MRF24J40_INTCON, reg); + reg = mrf24j40_getreg(dev->spi, MRF24J40_INTCON); + reg |= MRF24J40_INTCON_RXIE; + mrf24j40_setreg(dev->spi, MRF24J40_INTCON, reg); + } return OK; } @@ -1570,15 +1577,13 @@ static void mrf24j40_irqwork_rx(FAR struct mrf24j40_radio_s *dev) uint32_t index; uint8_t reg; - /* wlinfo("!\n"); */ - /* Disable rx int */ reg = mrf24j40_getreg(dev->spi, MRF24J40_INTCON); reg |= MRF24J40_INTCON_RXIE; mrf24j40_setreg(dev->spi, MRF24J40_INTCON, reg); - /* Disable packet reception */ + /* Disable packet reception. See pg. 109 of datasheet */ mrf24j40_setreg(dev->spi, MRF24J40_BBREG1, MRF24J40_BBREG1_RXDECINV); @@ -1597,7 +1602,6 @@ static void mrf24j40_irqwork_rx(FAR struct mrf24j40_radio_s *dev) addr = MRF24J40_RXBUF_BASE; iob->io_len= mrf24j40_getreg(dev->spi, addr++); - /* wlinfo("len %3d\n", dev->radio.rxbuf->len); */ /* TODO: This needs to be changed. It is inefficient to do the SPI read byte * by byte */ @@ -1633,6 +1637,11 @@ static void mrf24j40_irqwork_rx(FAR struct mrf24j40_radio_s *dev) mrf24j40_setreg(dev->spi, MRF24J40_BBREG1, 0); + /* Enable rx int */ + + reg = mrf24j40_getreg(dev->spi, MRF24J40_INTCON); + reg &= ~MRF24J40_INTCON_RXIE; + mrf24j40_setreg(dev->spi, MRF24J40_INTCON, reg); } /**************************************************************************** diff --git a/include/nuttx/wireless/ieee802154/ieee802154_radio.h b/include/nuttx/wireless/ieee802154/ieee802154_radio.h index 9a80658664c..50da1355675 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_radio.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_radio.h @@ -215,7 +215,7 @@ struct ieee802154_radioops_s FAR struct ieee802154_radiocb_s *radiocb); CODE int (*ioctl)(FAR struct ieee802154_radio_s *radio, int cmd, unsigned long arg); - CODE int (*rxenable)(FAR struct ieee802154_radio_s *radio); + CODE int (*rxenable)(FAR struct ieee802154_radio_s *radio, bool enable); CODE int (*txnotify_csma)(FAR struct ieee802154_radio_s *radio); CODE int (*txnotify_gts)(FAR struct ieee802154_radio_s *radio); }; From abc15c84292d470b00df4a271a559492d2f14b93 Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Wed, 3 May 2017 21:52:43 -0400 Subject: [PATCH 147/183] wireless/ieee802154: Finishes promiscuous mode IOCTL --- .../wireless/ieee802154/ieee802154_mac.h | 5 ++- wireless/ieee802154/mac802154.c | 36 +++++++++++++++---- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/include/nuttx/wireless/ieee802154/ieee802154_mac.h b/include/nuttx/wireless/ieee802154/ieee802154_mac.h index 87efa3662cc..9ab06ada2fa 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_mac.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_mac.h @@ -227,7 +227,10 @@ enum ieee802154_status_e IEEE802154_STATUS_TRANSACTION_OVERFLOW, IEEE802154_STATUS_TX_ACTIVE, IEEE802154_STATUS_UNAVAILABLE_KEY, - IEEE802154_STATUS_UNSUPPORTED_ATTRIBUTE + IEEE802154_STATUS_UNSUPPORTED_ATTRIBUTE, + IEEE802154_STATUS_FAILED /* This value is not outlined in the standard. It is + * a catch-all for any failures that are not outlined + * in the standard */ }; /* IEEE 802.15.4 PHY/MAC PIB attributes IDs */ diff --git a/wireless/ieee802154/mac802154.c b/wireless/ieee802154/mac802154.c index 2b373a51da0..be79dad0295 100644 --- a/wireless/ieee802154/mac802154.c +++ b/wireless/ieee802154/mac802154.c @@ -1493,17 +1493,39 @@ int mac802154_req_set(MACHANDLE mac, FAR struct ieee802154_set_req_s *req) { case IEEE802154_PIB_MAC_EXTENDED_ADDR: { - /* Set the attribute in the structure to the new value */ - - memcpy(&priv->addr.eaddr[0], &req->attr_value.eaddr[0], 8); - - - /* The radio device needs to be updated as well */ + /* Update the radio's extended address */ memcpy(&radio_arg.eaddr[0], &priv->addr.eaddr[0], 8); ret = priv->radio->ops->ioctl(priv->radio, PHY802154IOC_SET_EADDR, (unsigned long)&radio_arg); - + if (ret < 0) + { + return -IEEE802154_STATUS_FAILED; + } + + /* Set the attribute in the table */ + + memcpy(&priv->addr.eaddr[0], &req->attr_value.eaddr[0], 8); + + ret = IEEE802154_STATUS_SUCCESS; + } + break; + case IEEE802154_PIB_MAC_PROMISCUOUS_MODE: + { + /* Try and enable/disable promiscuous mode at the radio */ + + radio_arg.promisc = priv->promisc_mode; + ret = priv->radio->ops->ioctl(priv->radio, PHY802154IOC_SET_PROMISC, + (unsigned long)&radio_arg); + if (ret < 0) + { + return -IEEE802154_STATUS_FAILED; + } + + /* Set the attribute in the table */ + + priv->promisc_mode = req->attr_value.promics_mode; + ret = IEEE802154_STATUS_SUCCESS; } break; From dd40014279f2976f205f65e1eb7e64cae43f460a Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Fri, 5 May 2017 11:15:28 -0400 Subject: [PATCH 148/183] wireless/ieee802154: Removes radio IOCTL. Starts bringing radio and MAC closer with well-defined interface. --- configs/clicker2-stm32/src/stm32_mrf24j40.c | 14 - drivers/wireless/ieee802154/at86rf23x.c | 97 ---- drivers/wireless/ieee802154/mrf24j40.c | 314 +++++------ include/nuttx/fs/ioctl.h | 7 - .../wireless/ieee802154/ieee802154_mac.h | 105 +++- .../wireless/ieee802154/ieee802154_radio.h | 165 +----- include/sys/ioctl.h | 5 - net/netdev/netdev_ioctl.c | 18 +- net/sixlowpan/sixlowpan_utils.c | 13 +- wireless/ieee802154/Kconfig | 8 - wireless/ieee802154/Make.defs | 2 - wireless/ieee802154/mac802154.c | 114 ++-- wireless/ieee802154/mac802154.h | 3 +- wireless/ieee802154/mac802154_loopback.c | 27 - wireless/ieee802154/mac802154_netdev.c | 14 - wireless/ieee802154/radio802154_device.c | 512 ------------------ wireless/ieee802154/radio802154_ioctl.c | 487 ----------------- wireless/ieee802154/radio802154_ioctl.h | 255 --------- 18 files changed, 270 insertions(+), 1890 deletions(-) delete mode 100644 wireless/ieee802154/radio802154_device.c delete mode 100644 wireless/ieee802154/radio802154_ioctl.c delete mode 100644 wireless/ieee802154/radio802154_ioctl.h diff --git a/configs/clicker2-stm32/src/stm32_mrf24j40.c b/configs/clicker2-stm32/src/stm32_mrf24j40.c index 18751e27dc7..c92b93239b8 100644 --- a/configs/clicker2-stm32/src/stm32_mrf24j40.c +++ b/configs/clicker2-stm32/src/stm32_mrf24j40.c @@ -47,7 +47,6 @@ #include #include -#include #include #include @@ -84,8 +83,6 @@ # endif #endif -#define RADIO_DEVNAME "/dev/mrf24j40" - /**************************************************************************** * Private Types ****************************************************************************/ @@ -287,18 +284,7 @@ static int stm32_mrf24j40_devsetup(FAR struct stm32_priv_s *priv) return ret; } #endif -#elif defined(CONFIG_IEEE802154_DEV) - /* Register a character driver to access the IEEE 802.15.4 radio from - * user-space - */ - ret = radio802154dev_register(radio, RADIO_DEVNAME); - if (ret < 0) - { - wlerr("ERROR: Failed to register the radio device %s: %d\n", - RADIO_DEVNAME, ret); - return ret; - } #endif /* CONFIG_IEEE802154_MAC */ return OK; diff --git a/drivers/wireless/ieee802154/at86rf23x.c b/drivers/wireless/ieee802154/at86rf23x.c index 24a4d5ca391..90d99351baf 100644 --- a/drivers/wireless/ieee802154/at86rf23x.c +++ b/drivers/wireless/ieee802154/at86rf23x.c @@ -148,7 +148,6 @@ static void at86rf23x_irqwork_tx(FAR struct at86rf23x_dev_s *dev); static void at86rf23x_irqworker(FAR void *arg); static int at86rf23x_interrupt(int irq, FAR void *context, FAR void *arg); -/* IOCTL helpers */ static int at86rf23x_setchannel(FAR struct ieee802154_radio_s *ieee, uint8_t chan); @@ -187,8 +186,6 @@ static int at86rf23x_energydetect(FAR struct ieee802154_radio_s *ieee, /* Driver operations */ -static int at86rf23x_ioctl(FAR struct ieee802154_radio_s *ieee, int cmd, - unsigned long arg); static int at86rf23x_rxenable(FAR struct ieee802154_radio_s *ieee, bool state, FAR struct ieee802154_packet_s *packet); static int at86rf23x_transmit(FAR struct ieee802154_radio_s *ieee, @@ -1147,100 +1144,6 @@ static int at86rf23x_energydetect(FAR struct ieee802154_radio_s *ieee, return ERROR; } -/**************************************************************************** - * Name: at86rf23x_ioctl - * - * Description: - * Control operations for the radio. - * - ****************************************************************************/ - -static int at86rf23x_ioctl(FAR struct ieee802154_radio_s *ieee, int cmd, - unsigned long arg) -{ - FAR struct at86rf23x_dev_s *dev = - (FAR struct at86rf23x_dev_s *)ieee; - FAR union ieee802154_radioarg_u *u; = - (FAR union ieee802154_radioarg_u *)((uintptr_t)arg) - - switch (cmd) - { - case PHY802154IOC_SET_CHAN: - ret = at86rf23x_setchannel(ieee, u.channel); - break; - - case PHY802154IOC_GET_CHAN: - ret = at86rf23x_getchannel(ieee, &u.channel); - break; - - case PHY802154IOC_SET_PANID: - ret = at86rf23x_setpanid(ieee, u.panid); - break; - - case PHY802154IOC_GET_PANID: - ret = at86rf23x_getpanid(ieee, &u.panid); - break; - - case PHY802154IOC_SET_SADDR: - ret = at86rf23x_setsaddr(ieee, u.saddr); - break; - - case PHY802154IOC_GET_SADDR: - ret = at86rf23x_getsaddr(ieee, &u.saddr); - break; - - case PHY802154IOC_SET_EADDR: - ret = at86rf23x_seteaddr(ieee, u.eaddr); - break; - - case PHY802154IOC_GET_EADDR: - ret = at86rf23x_geteaddr(ieee, u.eaddr); - break; - - case PHY802154IOC_SET_PROMISC: - ret = at86rf23x_setpromisc(ieee, u.promisc); - break; - - case PHY802154IOC_GET_PROMISC: - ret = at86rf23x_getpromisc(ieee, &u.promisc); - break; - - case PHY802154IOC_SET_DEVMODE: - ret = at86rf23x_setdevmode(ieee, u.devmode); - break; - - case PHY802154IOC_GET_DEVMODE: - ret = at86rf23x_getdevmode(ieee, &u.devmode); - break; - - case PHY802154IOC_SET_TXPWR: - ret = at86rf23x_settxpower(ieee, u.txpwr); - break; - - case PHY802154IOC_GET_TXPWR: - ret = at86rf23x_gettxpower(ieee, &u.txpwr); - break; - - case PHY802154IOC_SET_CCA: - ret = at86rf23x_setcca(ieee, &u.cca); - break; - - case PHY802154IOC_GET_CCA: - ret = at86rf23x_getcca(ieee, &u.cca); - break; - - case PHY802154IOC_ENERGYDETECT: - ret = at86rf23x_energydetect(ieee, &u.energy); - break; - - case 1000: - return at86rf23x_regdump(dev); - - default: - return -ENOTTY; - } -} - /**************************************************************************** * Name: at86rf23x_initialize * diff --git a/drivers/wireless/ieee802154/mrf24j40.c b/drivers/wireless/ieee802154/mrf24j40.c index 9fb75cf03a7..366471cd9c3 100644 --- a/drivers/wireless/ieee802154/mrf24j40.c +++ b/drivers/wireless/ieee802154/mrf24j40.c @@ -2,6 +2,7 @@ * drivers/wireless/ieee802154/mrf24j40.c * * Copyright (C) 2015-2016 Sebastien Lorquet. All rights reserved. + * Copyright (C) 2017 Verge Inc. All rights reserved. * Author: Sebastien Lorquet * Author: Anthony Merlino * @@ -90,6 +91,10 @@ #define MRF24J40_RXMODE_PROMISC 1 #define MRF24J40_RXMODE_NOCRC 2 +#define MRF24J40_MODE_DEVICE 0 +#define MRF24J40_MODE_COORD 1 +#define MRF24J40_MODE_PANCOORD 2 + /* Definitions for PA control on high power modules */ #define MRF24J40_PA_AUTO 1 @@ -125,9 +130,8 @@ struct mrf24j40_radio_s struct work_s pollwork; /* For deferring poll work to the work queue */ sem_t exclsem; /* Exclusive access to this struct */ - uint16_t panid; /* PAN identifier, FFFF = not set */ - uint16_t saddr; /* short address, FFFF = not set */ - uint8_t eaddr[8]; /* extended address, FFFFFFFFFFFFFFFF = not set */ + struct ieee802154_addr_s addr; + uint8_t channel; /* 11 to 26 for the 2.4 GHz band */ uint8_t devmode; /* device mode: device, coord, pancoord */ uint8_t paenabled; /* enable usage of PA */ @@ -181,7 +185,6 @@ static int mrf24j40_gts_setup(FAR struct mrf24j40_radio_s *dev, uint8_t gts, static int mrf24j40_setup_fifo(FAR struct mrf24j40_radio_s *dev, FAR struct iob_s *frame, uint32_t fifo_addr); -/* IOCTL helpers */ static int mrf24j40_setchannel(FAR struct mrf24j40_radio_s *radio, uint8_t chan); @@ -196,7 +199,7 @@ static int mrf24j40_setsaddr(FAR struct mrf24j40_radio_s *radio, static int mrf24j40_getsaddr(FAR struct mrf24j40_radio_s *radio, FAR uint16_t *saddr); static int mrf24j40_seteaddr(FAR struct mrf24j40_radio_s *radio, - FAR uint8_t *eaddr); + FAR const uint8_t *eaddr); static int mrf24j40_geteaddr(FAR struct mrf24j40_radio_s *radio, FAR uint8_t *eaddr); static int mrf24j40_setpromisc(FAR struct mrf24j40_radio_s *radio, @@ -222,11 +225,14 @@ static int mrf24j40_energydetect(FAR struct mrf24j40_radio_s *radio, static int mrf24j40_bind(FAR struct ieee802154_radio_s *radio, FAR struct ieee802154_radiocb_s *radiocb); -static int mrf24j40_ioctl(FAR struct ieee802154_radio_s *radio, int cmd, - unsigned long arg); -static int mrf24j40_rxenable(FAR struct ieee802154_radio_s *radio bool enable); static int mrf24j40_txnotify_csma(FAR struct ieee802154_radio_s *radio); static int mrf24j40_txnotify_gts(FAR struct ieee802154_radio_s *radio); +static int mrf24j40_get_attr(FAR struct ieee802154_radio_s *radio, + enum ieee802154_pib_attr_e pib_attr, + FAR union ieee802154_attr_val_u *attr_value); +static int mrf24j40_set_attr(FAR struct ieee802154_radio_s *radio, + enum ieee802154_pib_attr_e pib_attr, + FAR const union ieee802154_attr_val_u *attr_value); /**************************************************************************** * Private Data @@ -242,14 +248,14 @@ static int mrf24j40_txnotify_gts(FAR struct ieee802154_radio_s *radio); static const struct ieee802154_radioops_s mrf24j40_devops = { mrf24j40_bind, - mrf24j40_ioctl, - mrf24j40_rxenable, mrf24j40_txnotify_csma, mrf24j40_txnotify_gts, + mrf24j40_get_attr, + mrf24j40_set_attr }; /**************************************************************************** - * Private Functions + * Radio Interface Functions ****************************************************************************/ static int mrf24j40_bind(FAR struct ieee802154_radio_s *radio, @@ -299,6 +305,103 @@ static int mrf24j40_txnotify_csma(FAR struct ieee802154_radio_s *radio) return OK; } +/**************************************************************************** + * Function: mrf24j40_txnotify_gts + * + * Description: + * Driver callback invoked when new TX data is available. This is a + * stimulus perform an out-of-cycle poll and, thereby, reduce the TX + * latency. + * + * Parameters: + * radio - Reference to the radio driver state structure + * + * Returned Value: + * None + * + * Assumptions: + * + ****************************************************************************/ + +static int mrf24j40_txnotify_gts(FAR struct ieee802154_radio_s *radio) +{ + FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)radio; + + /* Is our single work structure available? It may not be if there are + * pending interrupt actions and we will have to ignore the Tx + * availability action. + */ + + if (work_available(&dev->pollwork)) + { + /* Schedule to serialize the poll on the worker thread. */ + + work_queue(HPWORK, &dev->pollwork, mrf24j40_dopoll_gts, dev, 0); + } + + return OK; +} + +static int mrf24j40_get_attr(FAR struct ieee802154_radio_s *radio, + enum ieee802154_pib_attr_e pib_attr, + FAR union ieee802154_attr_val_u *attr_value) +{ + FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)radio; + int ret; + + switch (pib_attr) + { + case IEEE802154_PIB_MAC_EXTENDED_ADDR: + { + memcpy(&attr_value->mac.eaddr[0], &dev->addr.eaddr[0], 8); + ret = IEEE802154_STATUS_SUCCESS; + } + break; + default: + ret = IEEE802154_STATUS_UNSUPPORTED_ATTRIBUTE; + } + return ret; +} + +static int mrf24j40_set_attr(FAR struct ieee802154_radio_s *radio, + enum ieee802154_pib_attr_e pib_attr, + FAR const union ieee802154_attr_val_u *attr_value) +{ + FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)radio; + int ret; + + switch (pib_attr) + { + case IEEE802154_PIB_MAC_EXTENDED_ADDR: + { + mrf24j40_seteaddr(dev, &attr_value->mac.eaddr[0]); + ret = IEEE802154_STATUS_SUCCESS; + } + break; + case IEEE802154_PIB_MAC_PROMISCUOUS_MODE: + { + if (attr_value->mac.promisc_mode) + { + mrf24j40_setrxmode(dev, MRF24J40_RXMODE_PROMISC); + } + else + { + mrf24j40_setrxmode(dev, MRF24J40_RXMODE_NORMAL); + } + + ret = IEEE802154_STATUS_SUCCESS; + } + break; + default: + ret = IEEE802154_STATUS_UNSUPPORTED_ATTRIBUTE; + } + return ret; +} + +/**************************************************************************** + * Internal Functions + ****************************************************************************/ + /**************************************************************************** * Function: mrf24j40_dopoll_csma * @@ -353,43 +456,6 @@ static void mrf24j40_dopoll_csma(FAR void *arg) sem_post(&dev->exclsem); } -/**************************************************************************** - * Function: mrf24j40_txnotify_gts - * - * Description: - * Driver callback invoked when new TX data is available. This is a - * stimulus perform an out-of-cycle poll and, thereby, reduce the TX - * latency. - * - * Parameters: - * radio - Reference to the radio driver state structure - * - * Returned Value: - * None - * - * Assumptions: - * - ****************************************************************************/ - -static int mrf24j40_txnotify_gts(FAR struct ieee802154_radio_s *radio) -{ - FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)radio; - - /* Is our single work structure available? It may not be if there are - * pending interrupt actions and we will have to ignore the Tx - * availability action. - */ - - if (work_available(&dev->pollwork)) - { - /* Schedule to serialize the poll on the worker thread. */ - - work_queue(HPWORK, &dev->pollwork, mrf24j40_dopoll_gts, dev, 0); - } - - return OK; -} - /**************************************************************************** * Function: mrf24j40_dopoll_gts * @@ -772,7 +838,7 @@ static int mrf24j40_setpanid(FAR struct mrf24j40_radio_s *dev, mrf24j40_setreg(dev->spi, MRF24J40_PANIDH, (uint8_t)(panid>>8)); mrf24j40_setreg(dev->spi, MRF24J40_PANIDL, (uint8_t)(panid&0xFF)); - dev->panid = panid; + dev->addr.panid = panid; wlinfo("%04X\n", (unsigned)panid); return OK; @@ -789,7 +855,7 @@ static int mrf24j40_setpanid(FAR struct mrf24j40_radio_s *dev, static int mrf24j40_getpanid(FAR struct mrf24j40_radio_s *dev, FAR uint16_t *panid) { - *panid = dev->panid; + *panid = dev->addr.panid; return OK; } @@ -810,7 +876,7 @@ static int mrf24j40_setsaddr(FAR struct mrf24j40_radio_s *dev, mrf24j40_setreg(dev->spi, MRF24J40_SADRH, (uint8_t)(saddr>>8)); mrf24j40_setreg(dev->spi, MRF24J40_SADRL, (uint8_t)(saddr&0xFF)); - dev->saddr = saddr; + dev->addr.saddr = saddr; wlinfo("%04X\n", (unsigned)saddr); return OK; } @@ -826,7 +892,7 @@ static int mrf24j40_setsaddr(FAR struct mrf24j40_radio_s *dev, static int mrf24j40_getsaddr(FAR struct mrf24j40_radio_s *dev, FAR uint16_t *saddr) { - *saddr = dev->saddr; + *saddr = dev->addr.saddr; return OK; } @@ -841,14 +907,14 @@ static int mrf24j40_getsaddr(FAR struct mrf24j40_radio_s *dev, ****************************************************************************/ static int mrf24j40_seteaddr(FAR struct mrf24j40_radio_s *dev, - FAR uint8_t *eaddr) + FAR const uint8_t *eaddr) { int i; for (i = 0; i < 8; i++) { mrf24j40_setreg(dev->spi, MRF24J40_EADR0 + i, eaddr[i]); - dev->eaddr[i] = eaddr[i]; + dev->addr.eaddr[i] = eaddr[i]; } return OK; @@ -865,39 +931,7 @@ static int mrf24j40_seteaddr(FAR struct mrf24j40_radio_s *dev, static int mrf24j40_geteaddr(FAR struct mrf24j40_radio_s *dev, FAR uint8_t *eaddr) { - memcpy(eaddr, dev->eaddr, 8); - - return OK; -} - -/**************************************************************************** - * Name: mrf24j40_setpromisc - * - * Description: - * Set the device into promiscuous mode, e.g do not filter any incoming - * frame. - * - ****************************************************************************/ - -static int mrf24j40_setpromisc(FAR struct mrf24j40_radio_s *dev, - bool promisc) -{ - return mrf24j40_setrxmode(dev, promisc ? MRF24J40_RXMODE_PROMISC : - MRF24J40_RXMODE_NORMAL); -} - -/**************************************************************************** - * Name: mrf24j40_getpromisc - * - * Description: - * Get the device receive mode. - * - ****************************************************************************/ - -static int mrf24j40_getpromisc(FAR struct mrf24j40_radio_s *dev, - FAR bool *promisc) -{ - *promisc = (dev->rxmode == MRF24J40_RXMODE_PROMISC); + memcpy(eaddr, dev->addr.eaddr, 8); return OK; } @@ -927,17 +961,17 @@ static int mrf24j40_setdevmode(FAR struct mrf24j40_radio_s *dev, reg = mrf24j40_getreg(dev->spi, MRF24J40_RXMCR); - if (mode == IEEE802154_MODE_PANCOORD) + if (mode == MRF24J40_MODE_PANCOORD) { reg |= MRF24J40_RXMCR_PANCOORD; reg &= ~MRF24J40_RXMCR_COORD; } - else if (mode == IEEE802154_MODE_COORD) + else if (mode == MRF24J40_MODE_COORD) { reg |= MRF24J40_RXMCR_COORD; reg &= ~MRF24J40_RXMCR_PANCOORD; } - else if (mode == IEEE802154_MODE_DEVICE) + else if (mode == MRF24J40_MODE_DEVICE) { reg &= ~MRF24J40_RXMCR_PANCOORD; reg &= ~MRF24J40_RXMCR_COORD; @@ -1175,106 +1209,6 @@ static int mrf24j40_regdump(FAR struct mrf24j40_radio_s *dev) return 0; } -/**************************************************************************** - * Name: mrf24j40_ioctl - * - * Description: - * Misc/unofficial device controls. - * - ****************************************************************************/ - -static int mrf24j40_ioctl(FAR struct ieee802154_radio_s *radio, int cmd, - unsigned long arg) -{ - FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)radio; - FAR union ieee802154_radioarg_u *u = - (FAR union ieee802154_radioarg_u *)((uintptr_t)arg); - int ret; - - switch(cmd) - { - case PHY802154IOC_SET_CHAN: - ret = mrf24j40_setchannel(dev, u->channel); - break; - - case PHY802154IOC_GET_CHAN: - ret = mrf24j40_getchannel(dev, &u->channel); - break; - - case PHY802154IOC_SET_PANID: - ret = mrf24j40_setpanid(dev, u->panid); - break; - - case PHY802154IOC_GET_PANID: - ret = mrf24j40_getpanid(dev, &u->panid); - break; - - case PHY802154IOC_SET_SADDR: - ret = mrf24j40_setsaddr(dev, u->saddr); - break; - - case PHY802154IOC_GET_SADDR: - ret = mrf24j40_getsaddr(dev, &u->saddr); - break; - - case PHY802154IOC_SET_EADDR: - ret = mrf24j40_seteaddr(dev, u->eaddr); - break; - - case PHY802154IOC_GET_EADDR: - ret = mrf24j40_geteaddr(dev, u->eaddr); - break; - - case PHY802154IOC_SET_PROMISC: - ret = mrf24j40_setpromisc(dev, u->promisc); - break; - - case PHY802154IOC_GET_PROMISC: - ret = mrf24j40_getpromisc(dev, &u->promisc); - break; - - case PHY802154IOC_SET_DEVMODE: - ret = mrf24j40_setdevmode(dev, u->devmode); - break; - - case PHY802154IOC_GET_DEVMODE: - ret = mrf24j40_getdevmode(dev, &u->devmode); - break; - - case PHY802154IOC_SET_TXPWR: - ret = mrf24j40_settxpower(dev, u->txpwr); - break; - - case PHY802154IOC_GET_TXPWR: - ret = mrf24j40_gettxpower(dev, &u->txpwr); - break; - - case PHY802154IOC_SET_CCA: - ret = mrf24j40_setcca(dev, &u->cca); - break; - - case PHY802154IOC_GET_CCA: - ret = mrf24j40_getcca(dev, &u->cca); - break; - - case PHY802154IOC_ENERGYDETECT: - ret = mrf24j40_energydetect(dev, &u->energy); - break; - - case 1000: - return mrf24j40_regdump(dev); - - case 1001: dev->paenabled = (uint8_t)arg; - wlinfo("PA %sabled\n", arg ? "en" : "dis"); - return OK; - - default: - return -ENOTTY; - } - - return ret; -} - /**************************************************************************** * Name: mrf24j40_energydetect * diff --git a/include/nuttx/fs/ioctl.h b/include/nuttx/fs/ioctl.h index 9b0df767dc4..2d18dc217e8 100644 --- a/include/nuttx/fs/ioctl.h +++ b/include/nuttx/fs/ioctl.h @@ -89,7 +89,6 @@ #define _CLIOCBASE (0x2400) /* Contactless modules ioctl commands */ #define _USBCBASE (0x2500) /* USB-C controller ioctl commands */ #define _MAC802154BASE (0x2600) /* 802.15.4 MAC ioctl commands */ -#define _PHY802154BASE (0x2700) /* 802.15.4 Radio ioctl commands */ /* boardctl() commands share the same number space */ @@ -429,12 +428,6 @@ #define _MAC802154IOCVALID(c) (_IOC_TYPE(c)==_MAC802154BASE) #define _MAC802154IOC(nr) _IOC(_MAC802154BASE,nr) -/* 802.15.4 Radio driver ioctl definitions **********************************/ -/* (see nuttx/ieee802154/wireless/ieee802154_radio.h */ - -#define _PHY802154IOCVALID(c) (_IOC_TYPE(c)==_PHY802154BASE) -#define _PHY802154IOC(nr) _IOC(_PHY802154BASE,nr) - /* boardctl() command definitions *******************************************/ #define _BOARDIOCVALID(c) (_IOC_TYPE(c)==_BOARDBASE) diff --git a/include/nuttx/wireless/ieee802154/ieee802154_mac.h b/include/nuttx/wireless/ieee802154/ieee802154_mac.h index 9ab06ada2fa..407b6f6be73 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_mac.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_mac.h @@ -55,8 +55,6 @@ # include #endif -#include - #include /**************************************************************************** @@ -331,6 +329,8 @@ enum ieee802154_pib_attr_e IEEE802154_PIB_MAC_PANCOORD_SHORT_ADDR, }; +#define IEEE802154_EADDR_LEN 8 + /* IEEE 802.15.4 Device address * The addresses in ieee802154 have several formats: * No address : [none] @@ -351,9 +351,10 @@ struct ieee802154_addr_s enum ieee802154_addr_mode_e mode; - uint16_t panid; /* PAN identifier, can be IEEE802154_PAN_UNSPEC */ - uint16_t saddr; /* short address */ - uint8_t eaddr[8]; /* extended address */ + uint16_t panid; /* PAN identifier, can be + * IEEE802154_PAN_UNSPEC */ + uint16_t saddr; /* short address */ + uint8_t eaddr[IEEE802154_EADDR_LEN]; /* extended address */ }; #define IEEE802154_ADDRSTRLEN 22 /* (2*2+1+8*2, PPPP/EEEEEEEEEEEEEEEE) */ @@ -454,15 +455,54 @@ struct ieee802154_pend_addr_s struct ieee802154_addr_s addr[7]; /* Array of at most 7 addresses */ }; +#ifdef CONFIG_IEEE802154_RANGING +#define IEEE802154_TXDESC_FIELDS \ + uint8_t handle; \ + uint32_t timestamp; \ + uint8_t status; +#else +#define IEEE802154_TXDESC_FIELDS \ + uint8_t handle; \ + uint32_t timestamp; \ + uint8_t status; + bool rng_rcvd; \ + uint32_t rng_counter_start; \ + uint32_t rng_counter_stop; \ + uint32_t rng_tracking_interval; \ + uint32_t rng_offset;\ + uint8_t rng_fom; +#endif + +struct ieee802154_txdesc_s +{ + IEEE802154_TXDESC_FIELDS + + /* TODO: Add slotting information for GTS transactions */ +}; + +struct ieee802154_rxdesc_s +{ + uint8_t lqi; + uint8_t rssi; +}; + +struct ieee802154_cca_s +{ + uint8_t use_ed : 1; /* CCA using ED */ + uint8_t use_cs : 1; /* CCA using carrier sense */ + uint8_t edth; /* Energy detection threshold for CCA */ + uint8_t csth; /* Carrier sense threshold for CCA */ +}; + /* Primitive Support Types ***************************************************/ -union ieee802154_attr_val_u +union ieee802154_macattr_u { - uint8_t eaddr[8]; + uint8_t eaddr[IEEE802154_EADDR_LEN]; uint16_t saddr; - uint16_t pan_id; + uint16_t panid; - uint8_t coord_eaddr[8]; + uint8_t coord_eaddr[IEEE802154_EADDR_LEN]; uint16_t coord_saddr; bool is_assoc; @@ -503,6 +543,25 @@ union ieee802154_attr_val_u uint8_t dsn; }; +union ieee802154_phyattr_u +{ + uint8_t channel; + int32_t txpwr + /* TODO: Fill this out as we implement supported get/set commands */ +}; + +union ieee802154_secattr_u +{ + /* TODO: Fill this out as we implement supported get/set commands */ +}; + +union ieee802154_attr_val_u +{ + union ieee802154_macattr_u mac; + union ieee802154_phyattr_u phy; + union ieee802154_secattr_u sec; +}; + struct ieee802154_gts_info_s { uint8_t length : 4; /* Number of SF slots for GTS */ @@ -884,20 +943,6 @@ struct ieee802154_commstatus_ind_s #endif }; -/***************************************************************************** - * Primitive: MLME-GET.request - * - * Description: - * Requests information about a given PIB attribute. - * - *****************************************************************************/ - -struct ieee802154_get_req_s -{ - enum ieee802154_pib_attr_e pib_attr; - FAR union ieee802154_attr_val_u *attr_value; -}; - /***************************************************************************** * Primitive: MLME-GTS.request * @@ -1092,6 +1137,20 @@ struct ieee802154_scan_conf_s #warning Figure out how to handle missing primitive semantics. See standard. }; +/***************************************************************************** + * Primitive: MLME-GET.request + * + * Description: + * Requests information about a given PIB attribute. + * + *****************************************************************************/ + +struct ieee802154_get_req_s +{ + enum ieee802154_pib_attr_e pib_attr; + union ieee802154_attr_val_u attr_value; +}; + /***************************************************************************** * Primitive: MLME-SET.request * diff --git a/include/nuttx/wireless/ieee802154/ieee802154_radio.h b/include/nuttx/wireless/ieee802154/ieee802154_radio.h index 50da1355675..bfadc110237 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_radio.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_radio.h @@ -48,150 +48,18 @@ #include #include -#ifdef CONFIG_NET_6LOWPAN -# include -#endif - -#include +#include /**************************************************************************** * Pre-Processor Definitions ****************************************************************************/ -/* Configuration ************************************************************/ - -/* IEEE 802.15.4 Radio Interface **********************************************/ - -/* This layer only knows radio frames. There are no 802.15.4 specific bits - * at this layer. */ - -/* Device modes */ - -#define IEEE802154_MODE_DEVICE 0x00 -#define IEEE802154_MODE_COORD 0x01 /* avail in mrf24j40, but why? */ -#define IEEE802154_MODE_PANCOORD 0x02 - -/* IEEE 802.15.4 Radio Character Driver IOCTL ********************************/ - -#define PHY802154IOC_SET_CHAN _PHY802154IOC(0x0001) -#define PHY802154IOC_GET_CHAN _PHY802154IOC(0x0002) - -#define PHY802154IOC_SET_PANID _PHY802154IOC(0x0003) -#define PHY802154IOC_GET_PANID _PHY802154IOC(0x0004) - -#define PHY802154IOC_SET_SADDR _PHY802154IOC(0x0005) -#define PHY802154IOC_GET_SADDR _PHY802154IOC(0x0006) - -#define PHY802154IOC_SET_EADDR _PHY802154IOC(0x0007) -#define PHY802154IOC_GET_EADDR _PHY802154IOC(0x0008) - -#define PHY802154IOC_SET_PROMISC _PHY802154IOC(0x0009) -#define PHY802154IOC_GET_PROMISC _PHY802154IOC(0x000A) - -#define PHY802154IOC_SET_DEVMODE _PHY802154IOC(0x000B) -#define PHY802154IOC_GET_DEVMODE _PHY802154IOC(0x000C) - -#define PHY802154IOC_SET_TXPWR _PHY802154IOC(0x000D) -#define PHY802154IOC_GET_TXPWR _PHY802154IOC(0x000E) - -#define PHY802154IOC_SET_CCA _PHY802154IOC(0x000F) -#define PHY802154IOC_GET_CCA _PHY802154IOC(0x0010) - -#define PHY802154IOC_ENERGYDETECT _PHY802154IOC(0x0011) - -#define EADDR_SIZE 8 /* Extended address size */ - /**************************************************************************** * Public Types ****************************************************************************/ -/* Structures used with IEEE802.15.4 radio interface operations *************/ - -struct ieee802154_cca_s -{ - uint8_t use_ed : 1; /* CCA using ED */ - uint8_t use_cs : 1; /* CCA using carrier sense */ - uint8_t edth; /* Energy detection threshold for CCA */ - uint8_t csth; /* Carrier sense threshold for CCA */ -}; - -struct ieee802154_packet_s -{ - uint8_t len; - uint8_t data[127]; - uint8_t lqi; - uint8_t rssi; -}; - -/* IOCTL command data argument **********************************************/ - -/* A pointer to this structure is passed as the argument of each IOCTL - * command. - */ - -union ieee802154_radioarg_u -{ - uint8_t channel; /* PHY802154IOC_GET/SET_CHAN */ - uint16_t panid; /* PHY802154IOC_GET/SET_PANID */ - uint16_t saddr; /* PHY802154IOC_GET/SET_SADDR */ - uint8_t eaddr[EADDR_SIZE]; /* PHY802154IOC_GET/SET_EADDR */ - bool promisc; /* PHY802154IOC_GET/SET_EADDR */ - uint8_t devmode; /* PHY802154IOC_GET/SET_DEVMODE */ - int32_t txpwr; /* PHY802154IOC_GET/SET_TXPWR */ - bool energy; /* PHY802154IOC_ENERGYDETECT */ - struct ieee802154_cca_s cca; /* PHY802154IOC_GET/SET_CCA */ -}; - -#ifdef CONFIG_NET_6LOWPAN -/* For the case of network IOCTLs, the network IOCTL to the MAC network - * driver will include a device name like "wpan0" as the destination of - * the IOCTL command. The MAC layer will forward only the payload union - * to the radio IOCTL method. - */ - -struct ieee802154_netradio_s -{ - char ifr_name[IFNAMSIZ]; /* Interface name, e.g. "wpan0" */ - union ieee802154_radioarg_u u; /* Data payload */ -}; -#endif - /* IEEE802.15.4 Radio Interface Operations **********************************/ -/* This is a work-around to allow the MAC upper layer have a struct with - * identical members but with a different name. */ - -#ifdef CONFIG_IEEE802154_RANGING -#define IEEE802154_TXDESC_FIELDS \ - uint8_t handle; \ - uint32_t timestamp; \ - uint8_t status; -#else -#define IEEE802154_TXDESC_FIELDS \ - uint8_t handle; \ - uint32_t timestamp; \ - uint8_t status; - bool rng_rcvd; \ - uint32_t rng_counter_start; \ - uint32_t rng_counter_stop; \ - uint32_t rng_tracking_interval; \ - uint32_t rng_offset;\ - uint8_t rng_fom; -#endif - -struct ieee802154_txdesc_s -{ - IEEE802154_TXDESC_FIELDS - - /* TODO: Add slotting information for GTS transactions */ -}; - -struct ieee802154_rxdesc_s -{ - uint8_t lqi; - uint8_t rssi; -}; - struct ieee802154_radiocb_s { CODE int (*poll_csma) (FAR const struct ieee802154_radiocb_s *radiocb, @@ -213,11 +81,14 @@ struct ieee802154_radioops_s { CODE int (*bind) (FAR struct ieee802154_radio_s *radio, FAR struct ieee802154_radiocb_s *radiocb); - CODE int (*ioctl)(FAR struct ieee802154_radio_s *radio, int cmd, - unsigned long arg); - CODE int (*rxenable)(FAR struct ieee802154_radio_s *radio, bool enable); CODE int (*txnotify_csma)(FAR struct ieee802154_radio_s *radio); CODE int (*txnotify_gts)(FAR struct ieee802154_radio_s *radio); + CODE int (*get_attr) (FAR struct ieee802154_radio_s *radio, + enum ieee802154_pib_attr_e pib_attr, + FAR union ieee802154_attr_val_u *attr_value); + CODE int (*set_attr) (FAR struct ieee802154_radio_s *radio, + enum ieee802154_pib_attr_e pib_attr, + FAR const union ieee802154_attr_val_u *attr_value); }; struct ieee802154_radio_s @@ -237,28 +108,6 @@ extern "C" * Public Function Prototypes ****************************************************************************/ -/**************************************************************************** - * Name: radio802154dev_register - * - * Description: - * Register a character driver to access the IEEE 802.15.4 radio from - * user-space - * - * Input Parameters: - * radio - Pointer to the radio struct to be registerd. - * devname - The name of the IEEE 802.15.4 radio to be registered. - * - * Returned Values: - * Zero (OK) is returned on success. Otherwise a negated errno value is - * returned to indicate the nature of the failure. - * - ****************************************************************************/ - -#ifdef CONFIG_IEEE802154_DEV -int radio802154dev_register(FAR struct ieee802154_radio_s *radio, - FAR char *devname); -#endif - #undef EXTERN #ifdef __cplusplus } diff --git a/include/sys/ioctl.h b/include/sys/ioctl.h index e993a8d6b94..76abe7f01fb 100644 --- a/include/sys/ioctl.h +++ b/include/sys/ioctl.h @@ -65,11 +65,6 @@ #endif #ifdef CONFIG_WIRELESS_IEEE802154 -#ifdef CONFIG_IEEE802154_DEV -/* Include ieee802.15.4 radio IOCTL definitions */ - -# include -#endif #ifdef CONFIG_IEEE802154_MAC /* Include ieee802.15.4 MAC IOCTL definitions */ diff --git a/net/netdev/netdev_ioctl.c b/net/netdev/netdev_ioctl.c index 81bfe9a0b34..dae80646457 100644 --- a/net/netdev/netdev_ioctl.c +++ b/net/netdev/netdev_ioctl.c @@ -74,7 +74,6 @@ #if defined(CONFIG_NETDEV_IOCTL) && defined(CONFIG_NET_6LOWPAN) # include -# include #endif #include "arp/arp.h" @@ -353,22 +352,7 @@ static int netdev_iee802154_ioctl(FAR struct socket *psock, int cmd, if (arg != 0ul) { - /* Verify that this is either a valid IEEE802.15.4 radio IOCTL command - * or a valid IEEE802.15.4 MAC IOCTL command. - */ - - if (_PHY802154IOCVALID(cmd)) - { - /* Get the IEEE802.15.4 network device to receive the radio IOCTL - * commdand - */ - - FAR struct ieee802154_netradio_s *radio = - (FAR struct ieee802154_netradio_s *)((uintptr_t)arg); - - ifname = radio->ifr_name; - } - else if (_MAC802154IOCVALID(cmd)) + if (_MAC802154IOCVALID(cmd)) { /* Get the IEEE802.15.4 MAC device to receive the radio IOCTL * commdand diff --git a/net/sixlowpan/sixlowpan_utils.c b/net/sixlowpan/sixlowpan_utils.c index 05b60e3d38a..d392f0ef477 100644 --- a/net/sixlowpan/sixlowpan_utils.c +++ b/net/sixlowpan/sixlowpan_utils.c @@ -57,7 +57,6 @@ #include #include -#include #include "sixlowpan/sixlowpan_internal.h" @@ -165,7 +164,7 @@ bool sixlowpan_ismacbased(const net_ipv6addr_t ipaddr, * Name: sixlowpan_src_panid * * Description: - * Get the source PAN ID from the IEEE802.15.4 radio. + * Get the source PAN ID from the IEEE802.15.4 MAC layer. * * Input parameters: * ieee - A reference IEEE802.15.4 MAC network device structure. @@ -181,18 +180,20 @@ int sixlowpan_src_panid(FAR struct ieee802154_driver_s *ieee, FAR uint16_t *panid) { FAR struct net_driver_s *dev = &ieee->i_dev; - struct ieee802154_netradio_s arg; + struct ieee802154_netmac_s arg; int ret; memcpy(arg.ifr_name, ieee->i_dev.d_ifname, IFNAMSIZ); - ret = dev->d_ioctl(dev, PHY802154IOC_GET_PANID, (unsigned long)((uintptr_t)&arg)); + arg.u.getreq.pib_attr = IEEE802154_PIB_MAC_PAN_ID; + ret = dev->d_ioctl(dev, MAC802154IOC_MLME_GET_REQUEST, + (unsigned long)((uintptr_t)&arg)); if (ret < 0) { - wlerr("ERROR: PHY802154IOC_GET_PANID failed: %d\n", ret); + wlerr("ERROR: MAC802154IOC_MLME_GET_REQUEST failed: %d\n", ret); return ret; } - *panid = arg.u.panid; + *panid = arg.u.getreq.attr_value->panid; return OK; } diff --git a/wireless/ieee802154/Kconfig b/wireless/ieee802154/Kconfig index c1f7f828fa8..aa3f16219c8 100644 --- a/wireless/ieee802154/Kconfig +++ b/wireless/ieee802154/Kconfig @@ -60,14 +60,6 @@ config IEEE802154_NTXDESC endif # IEEE802154_MAC -config IEEE802154_DEV - bool "Debug character driver for ieee802.15.4 radio interfaces" - default n - depends on WIRELESS_IEEE802154 - ---help--- - Enables a device driver to expose ieee802.15.4 radio controls - to user space as IOCTLs. - config IEEE802154_NETDEV bool "IEEE802154 6loWPAN Network Device" default n diff --git a/wireless/ieee802154/Make.defs b/wireless/ieee802154/Make.defs index a2ec823d3b0..da84b153a7b 100644 --- a/wireless/ieee802154/Make.defs +++ b/wireless/ieee802154/Make.defs @@ -37,8 +37,6 @@ ifeq ($(CONFIG_WIRELESS_IEEE802154),y) # Include IEEE 802.15.4 support -CSRCS = radio802154_ioctl.c - # Include wireless devices build support ifeq ($(CONFIG_IEEE802154_MAC),y) diff --git a/wireless/ieee802154/mac802154.c b/wireless/ieee802154/mac802154.c index be79dad0295..0f548841c26 100644 --- a/wireless/ieee802154/mac802154.c +++ b/wireless/ieee802154/mac802154.c @@ -2,7 +2,9 @@ * wireless/ieee802154/mac802154.c * * Copyright (C) 2016 Sebastien Lorquet. All rights reserved. + * Copyright (C) 2017 Verge Inc. All rights reserved. * Author: Sebastien Lorquet + * Author: Anthony Merlino * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -51,6 +53,7 @@ #include #include +#include #include "mac802154.h" @@ -445,14 +448,15 @@ static int mac802154_defaultmib(FAR struct ieee802154_privmac_s *priv) priv->coord_addr.mode = IEEE802154_ADDRMODE_NONE; priv->coord_addr.saddr = IEEE802154_SADDR_UNSPEC; - memcpy(&priv->coord_addr.eaddr[0], IEEE802154_EADDR_UNSPEC, 8); + memcpy(&priv->coord_addr.eaddr[0], IEEE802154_EADDR_UNSPEC, + IEEE802154_EADDR_LEN); /* Reset the device's address */ priv->addr.mode = IEEE802154_ADDRMODE_NONE; priv->addr.panid = IEEE802154_PAN_UNSPEC; priv->addr.saddr = IEEE802154_SADDR_UNSPEC; - memcpy(&priv->addr.eaddr[0], IEEE802154_EADDR_UNSPEC, 8); + memcpy(&priv->addr.eaddr[0], IEEE802154_EADDR_UNSPEC, IEEE802154_EADDR_LEN); /* These attributes are effected and determined based on the PHY. Need to @@ -875,85 +879,78 @@ int mac802154_ioctl(MACHANDLE mac, int cmd, unsigned long arg) { case MAC802154IOC_MLME_ASSOC_REQUEST: { - mac802154_req_associate(mac, &macarg->assocreq); + ret = mac802154_req_associate(mac, &macarg->assocreq); } break; case MAC802154IOC_MLME_ASSOC_RESPONSE: { - mac802154_resp_associate(mac, &macarg->assocresp); + ret = mac802154_resp_associate(mac, &macarg->assocresp); } break; case MAC802154IOC_MLME_DISASSOC_REQUEST: { - mac802154_req_disassociate(mac, &macarg->disassocreq); + ret = mac802154_req_disassociate(mac, &macarg->disassocreq); } break; case MAC802154IOC_MLME_GET_REQUEST: { - mac802154_req_get(mac, macarg->getreq.pib_attr, - macarg->getreq.attr_value); + ret = mac802154_req_get(mac, macarg->getreq.pib_attr, + &macarg->getreq.attr_value); } break; case MAC802154IOC_MLME_GTS_REQUEST: { - mac802154_req_gts(mac, &macarg->gtsreq); + ret = mac802154_req_gts(mac, &macarg->gtsreq); } break; case MAC802154IOC_MLME_ORPHAN_RESPONSE: { - mac802154_resp_orphan(mac, &macarg->orphanresp); + ret = mac802154_resp_orphan(mac, &macarg->orphanresp); } break; case MAC802154IOC_MLME_RESET_REQUEST: { - mac802154_req_reset(mac, macarg->resetreq.rst_pibattr); + ret = mac802154_req_reset(mac, macarg->resetreq.rst_pibattr); } break; case MAC802154IOC_MLME_RXENABLE_REQUEST: { - mac802154_req_rxenable(mac, &macarg->rxenabreq); + ret = mac802154_req_rxenable(mac, &macarg->rxenabreq); } break; case MAC802154IOC_MLME_SCAN_REQUEST: { - mac802154_req_scan(mac, &macarg->scanreq); + ret = mac802154_req_scan(mac, &macarg->scanreq); } break; case MAC802154IOC_MLME_SET_REQUEST: { - mac802154_req_set(mac, &macarg->setreq); + ret = mac802154_req_set(mac, macarg->setreq.pib_attr, + &macarg->setreq.attr_value); } break; case MAC802154IOC_MLME_START_REQUEST: { - mac802154_req_start(mac, &macarg->startreq); + ret = mac802154_req_start(mac, &macarg->startreq); } break; case MAC802154IOC_MLME_SYNC_REQUEST: { - mac802154_req_sync(mac, &macarg->syncreq); + ret = mac802154_req_sync(mac, &macarg->syncreq); } break; case MAC802154IOC_MLME_POLL_REQUEST: { - mac802154_req_poll(mac, &macarg->pollreq); + ret = mac802154_req_poll(mac, &macarg->pollreq); } break; + default: + wlerr("ERROR: Unrecognized cmd: %d\n", cmd); + ret = -ENOTTY; + break; } } - - /* No, other IOCTLs must be aimed at the IEEE802.15.4 radio layer */ - - else - { - DEBUGASSERT(priv->radio != NULL && - priv->radio->ops != NULL && - priv->radio->ops->ioctl != NULL); - - ret = priv->radio->ops->ioctl(priv->radio, cmd, arg); - } - - return ret; + return ret; } /**************************************************************************** @@ -1109,8 +1106,10 @@ int mac802154_req_data(MACHANDLE mac, } else if (meta->dest_addr.mode == IEEE802154_ADDRMODE_EXTENDED) { - memcpy(&frame->io_data[mhr_len], &meta->dest_addr.eaddr, 8); - mhr_len += 8; + memcpy(&frame->io_data[mhr_len], &meta->dest_addr.eaddr, + IEEE802154_EADDR_LEN); + + mhr_len += IEEE802154_EADDR_LEN; } } @@ -1166,8 +1165,10 @@ int mac802154_req_data(MACHANDLE mac, } else if (meta->src_addr_mode == IEEE802154_ADDRMODE_EXTENDED) { - memcpy(&frame->io_data[mhr_len], &priv->addr.eaddr, 8); - mhr_len += 8; + memcpy(&frame->io_data[mhr_len], &priv->addr.eaddr, + IEEE802154_EADDR_LEN); + + mhr_len += IEEE802154_EADDR_LEN; } } @@ -1482,60 +1483,39 @@ int mac802154_req_get(MACHANDLE mac, enum ieee802154_pib_attr_e pib_attr, * ****************************************************************************/ -int mac802154_req_set(MACHANDLE mac, FAR struct ieee802154_set_req_s *req) +int mac802154_req_set(MACHANDLE mac, enum ieee802154_pib_attr_e pib_attr, + FAR const union ieee802154_attr_val_u *attr_value) { FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; - union ieee802154_radioarg_u radio_arg; int ret; - switch (req->pib_attr) + switch (pib_attr) { case IEEE802154_PIB_MAC_EXTENDED_ADDR: { - /* Update the radio's extended address */ + /* Set the MAC copy of the address in the table */ - memcpy(&radio_arg.eaddr[0], &priv->addr.eaddr[0], 8); - ret = priv->radio->ops->ioctl(priv->radio, PHY802154IOC_SET_EADDR, - (unsigned long)&radio_arg); - if (ret < 0) - { - return -IEEE802154_STATUS_FAILED; - } + memcpy(&priv->addr.eaddr[0], &attr_value->mac.eaddr[0], + IEEE802154_EADDR_LEN); - /* Set the attribute in the table */ + /* Tell the radio about the attribute */ - memcpy(&priv->addr.eaddr[0], &req->attr_value.eaddr[0], 8); + priv->radio->ops->set_attr(priv->radio, pib_attr, attr_value); ret = IEEE802154_STATUS_SUCCESS; } break; - case IEEE802154_PIB_MAC_PROMISCUOUS_MODE: - { - /* Try and enable/disable promiscuous mode at the radio */ - - radio_arg.promisc = priv->promisc_mode; - ret = priv->radio->ops->ioctl(priv->radio, PHY802154IOC_SET_PROMISC, - (unsigned long)&radio_arg); - if (ret < 0) - { - return -IEEE802154_STATUS_FAILED; - } - - /* Set the attribute in the table */ - - priv->promisc_mode = req->attr_value.promics_mode; - - ret = IEEE802154_STATUS_SUCCESS; - } - break; default: { - ret = -IEEE802154_STATUS_UNSUPPORTED_ATTRIBUTE; + /* The attribute may be handled soley in the radio driver, so pass + * it along. + */ + + ret = priv->radio->ops->set_attr(priv->radio, pib_attr, attr_value); } break; } - return ret; } diff --git a/wireless/ieee802154/mac802154.h b/wireless/ieee802154/mac802154.h index 883d0180ee9..b98fa0d3601 100644 --- a/wireless/ieee802154/mac802154.h +++ b/wireless/ieee802154/mac802154.h @@ -269,7 +269,8 @@ int mac802154_req_get(MACHANDLE mac, enum ieee802154_pib_attr_e pib_attr, * ****************************************************************************/ -int mac802154_req_set(MACHANDLE mac, FAR struct ieee802154_set_req_s *req); +int mac802154_req_set(MACHANDLE mac, enum ieee802154_pib_attr_e pib_attr, + FAR const union ieee802154_attr_val_u *attr_value); /**************************************************************************** * Name: mac802154_req_start diff --git a/wireless/ieee802154/mac802154_loopback.c b/wireless/ieee802154/mac802154_loopback.c index 8b0abaf5b5d..44cb4f0762b 100644 --- a/wireless/ieee802154/mac802154_loopback.c +++ b/wireless/ieee802154/mac802154_loopback.c @@ -54,7 +54,6 @@ #include #include #include -#include #include #include "mac802154.h" @@ -594,32 +593,6 @@ static int lo_ioctl(FAR struct net_driver_s *dev, int cmd, else #endif - if (_PHY802154IOCVALID(cmd)) - { - FAR struct ieee802154_netradio_s *netradio = - (FAR struct ieee802154_netradio_s *)arg; - - /* Pick out radio settings of interest. There is, of course, no - * radio in this loopback. - */ - - switch (cmd) - { - case PHY802154IOC_SET_PANID: - priv->lo_panid = netradio->u.panid; - ret = OK; - break; - - case PHY802154IOC_GET_PANID: - netradio->u.panid = priv->lo_panid; - ret = OK; - break; - - default: - break; - } - } - return ret; } #endif diff --git a/wireless/ieee802154/mac802154_netdev.c b/wireless/ieee802154/mac802154_netdev.c index bf4c9013cb0..7016cf71992 100644 --- a/wireless/ieee802154/mac802154_netdev.c +++ b/wireless/ieee802154/mac802154_netdev.c @@ -1381,20 +1381,6 @@ static int macnet_ioctl(FAR struct net_driver_s *dev, int cmd, } } - /* No, check for IOCTLs aimed at the IEEE802.15.4 radio layer */ - - else if (_PHY802154IOCVALID(cmd)) - { - FAR struct ieee802154_netradio_s *netradio = - (FAR struct ieee802154_netradio_s *)arg; - - if (netradio != NULL) - { - unsigned long radioarg = (unsigned int)((uintptr_t)&netradio->u); - ret = priv->md_mac.macops.ioctl(priv->md_mac, cmd, radioarg); - } - } - /* Okay, we have no idea what this command is.. just give to the * IEEE802.15.4 MAC layer without modification. */ diff --git a/wireless/ieee802154/radio802154_device.c b/wireless/ieee802154/radio802154_device.c deleted file mode 100644 index 2c48e107d0b..00000000000 --- a/wireless/ieee802154/radio802154_device.c +++ /dev/null @@ -1,512 +0,0 @@ -/**************************************************************************** - * wireless/ieee802154/radio802154_device.c - * - * Copyright (C) 2014-2015 Gregory Nutt. All rights reserved. - * Copyright (C) 2014-2015 Sebastien Lorquet. All rights reserved. - * Author: Sebastien Lorquet - * Author: Anthony Merlino - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "radio802154_ioctl.h" - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -struct radio802154_devwrapper_s -{ - FAR struct ieee802154_radio_s *child; - sem_t devsem; /* Device access serialization semaphore */ - bool opened; /* This device can only be opened once */ -}; - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static void radio802154dev_semtake(FAR struct radio802154_devwrapper_s *dev); -static int radio802154dev_open(FAR struct file *filep); -static int radio802154dev_close(FAR struct file *filep); -static ssize_t radio802154dev_read(FAR struct file *filep, FAR char *buffer, - size_t len); -static ssize_t radio802154dev_write(FAR struct file *filep, - FAR const char *buffer, size_t len); -static int radio802154dev_ioctl(FAR struct file *filep, int cmd, - unsigned long arg); - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static const struct file_operations radio802154dev_fops = -{ - radio802154dev_open , /* open */ - radio802154dev_close, /* close */ - radio802154dev_read , /* read */ - radio802154dev_write, /* write */ - NULL, /* seek */ - radio802154dev_ioctl /* ioctl */ -#ifndef CONFIG_DISABLE_POLL - , NULL /* poll */ -#endif -#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS - , NULL /* unlink */ -#endif -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: radio802154dev_semtake - * - * Description: - * Acquire the semaphore used for access serialization. - * - ****************************************************************************/ - -static void radio802154dev_semtake(FAR struct radio802154_devwrapper_s *dev) -{ - /* Take the semaphore (perhaps waiting) */ - - while (sem_wait(&dev->devsem) != 0) - { - /* The only case that an error should occur here is if - * the wait was awakened by a signal. - */ - - DEBUGASSERT(errno == EINTR); - } -} - -/**************************************************************************** - * Name: radio802154dev_semgive - * - * Description: - * Release the semaphore used for access serialization. - * - ****************************************************************************/ - -static inline void radio802154dev_semgive(FAR struct radio802154_devwrapper_s *dev) -{ - sem_post(&dev->devsem); -} - -/**************************************************************************** - * Name: radio802154dev_open - * - * Description: - * Open the 802.15.4 radio character device. - * - ****************************************************************************/ - -static int radio802154dev_open(FAR struct file *filep) -{ - FAR struct inode *inode; - FAR struct radio802154_devwrapper_s *dev; - - DEBUGASSERT(filep != NULL && filep->f_inode != NULL); - inode = filep->f_inode; - dev = inode->i_private; - DEBUGASSERT(dev != NULL); - - /* Get exclusive access to the driver data structures */ - - radio802154dev_semtake(dev); - - if (dev->opened) - { - /* Already opened */ - - return -EMFILE; - } - else - { - /* Enable interrupts (only rx for now)*/ - - //mrf24j40_setreg(dev->spi, MRF24J40_INTCON, ~(MRF24J40_INTCON_RXIE) ); - //dev->lower->enable(dev->lower, TRUE); - - dev->opened = true; - } - - radio802154dev_semgive(dev); - return OK; -} - -/**************************************************************************** - * Name: radio802154dev_close - * - * Description: - * Close the 802.15.4 radio character device. - * - ****************************************************************************/ - -static int radio802154dev_close(FAR struct file *filep) -{ - FAR struct inode *inode; - FAR struct radio802154_devwrapper_s *dev; - int ret = OK; - - DEBUGASSERT(filep != NULL && filep->f_inode != NULL); - inode = filep->f_inode; - dev = inode->i_private; - DEBUGASSERT(dev != NULL); - - /* Get exclusive access to the driver data structures */ - - radio802154dev_semtake(dev); - - if (!dev->opened) - { - /* Driver has not been opened */ - - ret = -EIO; - } - else - { - /* Disable interrupts */ - - //mrf24j40_setreg(dev->spi, MRF24J40_INTCON, 0xFF ); - //dev->lower->enable(dev->lower, FALSE); - - dev->opened = false; - } - - radio802154dev_semgive(dev); - return ret; -} - -/**************************************************************************** - * Name: radio802154dev_read - * - * Description: - * Return the last received packet. - * TODO: Return a packet from the receive queue. The buffer must be a pointer to a - * struct ieee802154_packet_s structure, with a correct length. - * - ****************************************************************************/ - -static ssize_t radio802154dev_read(FAR struct file *filep, FAR char *buffer, size_t len) -{ - FAR struct inode *inode; - FAR struct radio802154_devwrapper_s *dev; - FAR struct ieee802154_packet_s *buf; - int ret = OK; - - DEBUGASSERT(filep != NULL && filep->f_inode != NULL); - inode = filep->f_inode; - dev = inode->i_private; - DEBUGASSERT(dev != NULL && buffer != NULL); - buf = (FAR struct ieee802154_packet_s*)buffer; - - /* Get exclusive access to the driver data structures */ - - if (len < sizeof(struct ieee802154_packet_s)) - { - ret = -EINVAL; - goto done; - } - -#warning Receive needs to be redone! -#if 0 - ret = dev->child->ops->rxenable(dev->child, 1, buf); - if (ret < 0) - { - goto done; - } - - /* if no packet is received, this will produce -EAGAIN - * The user is responsible for sleeping until sth arrives - */ - -#if 0 - ret = sem_trywait(&dev->child->rxsem); -#else - ret = sem_wait(&dev->child->rxsem); -#endif - if (ret < 0) - { - ret = -errno; - goto done; - } - - /* Disable read until we have process the current read */ - - dev->child->ops->rxenable(dev->child, 0, NULL); - ret = buf->len; - -#endif - -done: - return ret; -} - -/**************************************************************************** - * Name: radio802154dev_write - * - * Description: - * Send a packet immediately. - * TODO: Put a packet in the send queue. The packet will be sent as soon - * as possible. The buffer must point to a struct radio802154_packet_s - * with the correct length. - * - ****************************************************************************/ - -static ssize_t radio802154dev_write(FAR struct file *filep, - FAR const char *buffer, size_t len) -{ - FAR struct inode *inode; - FAR struct radio802154_devwrapper_s *dev; - FAR struct ieee802154_packet_s *packet; - FAR struct timespec timeout; - int ret = OK; - - DEBUGASSERT(filep != NULL && filep->f_inode != NULL); - inode = filep->f_inode; - dev = inode->i_private; - DEBUGASSERT(dev != NULL); - - /* Get exclusive access to the driver data structures */ - - /* TODO: Make this an option or have a new method of doing timeout from - * ioctrl. - */ - - timeout.tv_sec = 1; - timeout.tv_nsec = 0; - - /* Sanity checks */ - - if (len < sizeof(struct ieee802154_packet_s)) - { - ret = -EINVAL; - //goto done; - - /* TODO Double check I like having assert here. It is a bigger problem - * if buffers are to small. - */ - - DEBUGASSERT(0); - } - - packet = (FAR struct ieee802154_packet_s*) buffer; - if (packet->len > 125) /* Max len 125, 2 FCS bytes auto added by mrf */ - { - ret = -EPERM; - //goto done; - DEBUGASSERT(0); - } - - /* Copy packet to normal device TX fifo. - * Beacons and GTS transmission will be handled via IOCTLs - */ - -#warning Fix this when transmit interface is complete -#if 0 - ret = dev->child->ops->transmit(dev->child, packet); - if (ret != packet->len) - { - ret = -EPERM; - goto done; - } - - if (sem_timedwait(&dev->child->txsem, &timeout)) - { - wlerr("Radio Device timedout on Tx\n"); - } -#endif - -done: - - /* Okay, tx interrupt received. check transmission status to decide success. */ - - return ret; -} - -/**************************************************************************** - * Name: radio802154dev_ioctl - * - * Description: - * Control the MRF24J40 device. This is where the real operations happen. - * - ****************************************************************************/ - -static int radio802154dev_ioctl(FAR struct file *filep, int cmd, - unsigned long arg) -{ - FAR struct inode *inode; - FAR struct radio802154_devwrapper_s *dev; - FAR struct ieee802154_radio_s *child; - int ret = OK; - - DEBUGASSERT(filep != NULL && filep->f_inode != NULL); - inode = filep->f_inode; - dev = inode->i_private; - DEBUGASSERT(dev != NULL && dev->child != NULL); - child = dev->child; - - /* Get exclusive access to the driver data structures */ - - switch (cmd) - { - case PHY802154IOC_SET_CHAN: - ret = radio802154_setchannel(child, (uint8_t)arg); - break; - - case PHY802154IOC_GET_CHAN: - ret = radio802154_getchannel(child, (FAR uint8_t*)arg); - break; - - case PHY802154IOC_SET_PANID: - ret = radio802154_setpanid(child, (uint16_t)arg); - break; - - case PHY802154IOC_GET_PANID: - ret = radio802154_getpanid(child, (FAR uint16_t*)arg); - break; - - case PHY802154IOC_SET_SADDR: - ret = radio802154_setsaddr(child, (uint16_t)arg); - break; - - case PHY802154IOC_GET_SADDR: - ret = radio802154_getsaddr(child, (FAR uint16_t*)arg); - break; - - case PHY802154IOC_SET_EADDR: - ret = radio802154_seteaddr(child, (FAR uint8_t*)arg); - break; - - case PHY802154IOC_GET_EADDR: - ret = radio802154_geteaddr(child, (FAR uint8_t*)arg); - break; - - case PHY802154IOC_SET_PROMISC: - ret = radio802154_setpromisc(child, (bool)arg); - break; - - case PHY802154IOC_GET_PROMISC: - ret = radio802154_getpromisc(child, (FAR bool*)arg); - break; - - case PHY802154IOC_SET_DEVMODE: - ret = radio802154_setdevmode(child, (uint8_t)arg); - break; - - case PHY802154IOC_GET_DEVMODE: - ret = radio802154_getdevmode(child, (FAR uint8_t*)arg); - break; - - case PHY802154IOC_SET_TXPWR: - ret = radio802154_settxpower(child, (int32_t)arg); - break; - - case PHY802154IOC_GET_TXPWR: - ret = radio802154_gettxpower(child, (FAR int32_t*)arg); - break; - - case PHY802154IOC_SET_CCA: - ret = radio802154_setcca(child, (FAR struct ieee802154_cca_s*)arg); - break; - - case PHY802154IOC_GET_CCA: - ret = radio802154_getcca(child, (FAR struct ieee802154_cca_s*)arg); - break; - - case PHY802154IOC_ENERGYDETECT: - ret = radio802154_energydetect(child, (FAR uint8_t*)arg); - break; - - default: - ret = child->ops->ioctl(child, cmd,arg); - break; - } - - return ret; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: radio802154dev_register - * - * Description: - * Register a character driver to access the IEEE 802.15.4 radio from - * user-space - * - * Input Parameters: - * radio - Pointer to the radio struct to be registerd. - * devname - The name of the IEEE 802.15.4 radio to be registered. - * - * Returned Values: - * Zero (OK) is returned on success. Otherwise a negated errno value is - * returned to indicate the nature of the failure. - * - ****************************************************************************/ - -int radio802154dev_register(FAR struct ieee802154_radio_s *radio, - FAR char *devname) -{ - FAR struct radio802154_devwrapper_s *dev; - - dev = kmm_zalloc(sizeof(struct radio802154_devwrapper_s)); - if (dev == NULL) - { - return -ENOMEM; - } - - dev->child = radio; - - sem_init(&dev->devsem, 0, 1); /* Allow the device to be opened once before blocking */ - - return register_driver(devname, &radio802154dev_fops, 0666, dev); -} diff --git a/wireless/ieee802154/radio802154_ioctl.c b/wireless/ieee802154/radio802154_ioctl.c deleted file mode 100644 index d86366c9872..00000000000 --- a/wireless/ieee802154/radio802154_ioctl.c +++ /dev/null @@ -1,487 +0,0 @@ -/**************************************************************************** - * wireless/ieee802154/radio802154_ioctl.c - * - * Copyright (C) 2017 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include - -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define RADIO_IOCTL(r,c,a) \ - (r)->ops->ioctl((r),(c),(unsigned long)((uintptr_t)(a))) - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: radio802154_setchannel - * - * Description: - * Define the current radio channel the device is operating on. - * In the 2.4 GHz, there are 16 channels, each 2 MHz wide, 5 MHz spacing: - * Chan MHz Chan MHz Chan MHz Chan MHz - * 11 2405 15 2425 19 2445 23 2465 - * 12 2410 16 2430 20 2450 24 2470 - * 13 2415 17 2435 21 2455 25 2475 - * 14 2420 18 2440 22 2460 26 2480 - * - ****************************************************************************/ - -int radio802154_setchannel(FAR struct ieee802154_radio_s *radio, - uint8_t chan) -{ - union ieee802154_radioarg_u arg; - int ret; - - arg.channel = chan; - - ret = RADIO_IOCTL(radio, PHY802154IOC_SET_CHAN, &arg); - if (ret < 0) - { - wlerr("ERROR: PHY802154IOC_SET_CHAN failed: %d\n", ret); - } - - return ret; -} - -/**************************************************************************** - * Name: radio802154_getchannel - * - * Description: - * Define the current radio channel the device is operating on. - * - ****************************************************************************/ - -int radio802154_getchannel(FAR struct ieee802154_radio_s *radio, - FAR uint8_t *chan) -{ - union ieee802154_radioarg_u arg; - int ret; - - ret = RADIO_IOCTL(radio, PHY802154IOC_GET_CHAN, &arg); - if (ret < 0) - { - wlerr("ERROR: PHY802154IOC_GET_CHAN failed: %d\n", ret); - } - - *chan = arg.channel; - return ret; -} - -/**************************************************************************** - * Name: radio802154_setpanid - * - * Description: - * Define the PAN ID the device is operating on. - * - ****************************************************************************/ - -int radio802154_setpanid(FAR struct ieee802154_radio_s *radio, - uint16_t panid) -{ - union ieee802154_radioarg_u arg; - int ret; - - arg.panid = panid; - - ret = RADIO_IOCTL(radio, PHY802154IOC_SET_PANID, &arg); - if (ret < 0) - { - wlerr("ERROR: PHY802154IOC_SET_PANID failed: %d\n", ret); - } - - return ret; -} - -/**************************************************************************** - * Name: radio802154_getpanid - * - * Description: - * Define the current PAN ID the device is operating on. - * - ****************************************************************************/ - -int radio802154_getpanid(FAR struct ieee802154_radio_s *radio, - FAR uint16_t *panid) -{ - union ieee802154_radioarg_u arg; - int ret; - - ret = RADIO_IOCTL(radio, PHY802154IOC_GET_PANID, &arg); - if (ret < 0) - { - wlerr("ERROR: PHY802154IOC_GET_PANID failed: %d\n", ret); - } - - *panid = arg.panid; - return ret; -} - -/**************************************************************************** - * Name: radio802154_setsaddr - * - * Description: - * Define the device short address. The following addresses are special: - * FFFEh : Broadcast - * FFFFh : Unspecified - * - ****************************************************************************/ - -int radio802154_setsaddr(FAR struct ieee802154_radio_s *radio, - uint16_t saddr) -{ - union ieee802154_radioarg_u arg; - int ret; - - arg.saddr = saddr; - - ret = RADIO_IOCTL(radio, PHY802154IOC_SET_SADDR, &arg); - if (ret < 0) - { - wlerr("ERROR: PHY802154IOC_SET_SADDR failed: %d\n", ret); - } - - return ret; -} - -/**************************************************************************** - * Name: radio802154_getsaddr - * - * Description: - * Define the current short address the device is using. - * - ****************************************************************************/ - -int radio802154_getsaddr(FAR struct ieee802154_radio_s *radio, - FAR uint16_t *saddr) -{ - union ieee802154_radioarg_u arg; - int ret; - - ret = RADIO_IOCTL(radio, PHY802154IOC_GET_SADDR, &arg); - if (ret < 0) - { - wlerr("ERROR: PHY802154IOC_GET_SADDR failed: %d\n", ret); - } - - *saddr = arg.saddr; - return ret; -} - -/**************************************************************************** - * Name: radio802154_seteaddr - * - * Description: - * Define the device extended address. The following addresses are special: - * FFFFFFFFFFFFFFFFh : Unspecified - * - ****************************************************************************/ - -int radio802154_seteaddr(FAR struct ieee802154_radio_s *radio, - FAR uint8_t *eaddr) -{ - union ieee802154_radioarg_u arg; - int ret; - - memcpy(arg.eaddr, eaddr, EADDR_SIZE); /* REVISIT */ - - ret = RADIO_IOCTL(radio, PHY802154IOC_SET_EADDR, &arg); - if (ret < 0) - { - wlerr("ERROR: PHY802154IOC_SET_EADDR failed: %d\n", ret); - } - - return ret; -} - -/**************************************************************************** - * Name: radio802154_geteaddr - * - * Description: - * Define the current extended address the device is using. - * - ****************************************************************************/ - -int radio802154_geteaddr(FAR struct ieee802154_radio_s *radio, - FAR uint8_t *eaddr) -{ - union ieee802154_radioarg_u arg; - int ret; - - ret = RADIO_IOCTL(radio, PHY802154IOC_GET_EADDR, &arg); - if (ret < 0) - { - wlerr("ERROR: PHY802154IOC_GET_EADDR failed: %d\n", ret); - } - - memcpy(eaddr, arg.eaddr, EADDR_SIZE); /* REVISIT */ - return ret; -} - -/**************************************************************************** - * Name: radio802154_setpromisc - * - * Description: - * Set the device into promiscuous mode, e.g do not filter any incoming - * frame. - * - ****************************************************************************/ - -int radio802154_setpromisc(FAR struct ieee802154_radio_s *radio, - bool promisc) -{ - union ieee802154_radioarg_u arg; - int ret; - - arg.promisc = promisc; - - ret = RADIO_IOCTL(radio, PHY802154IOC_SET_PROMISC, &arg); - if (ret < 0) - { - wlerr("ERROR: PHY802154IOC_SET_PROMISC failed: %d\n", ret); - } - - return ret; -} - -/**************************************************************************** - * Name: radio802154_getpromisc - * - * Description: - * Get the device receive mode. - * - ****************************************************************************/ - -int radio802154_getpromisc(FAR struct ieee802154_radio_s *radio, - FAR bool *promisc) -{ - union ieee802154_radioarg_u arg; - int ret; - - ret = RADIO_IOCTL(radio, PHY802154IOC_GET_PROMISC, &arg); - if (ret < 0) - { - wlerr("ERROR: PHY802154IOC_GET_PROMISC failed: %d\n", ret); - } - - *promisc = arg.promisc; - return ret; -} - -/**************************************************************************** - * Name: radio802154_setdevmode - * - * Description: - * Define the device behaviour: normal end device or coordinator - * - ****************************************************************************/ - -int radio802154_setdevmode(FAR struct ieee802154_radio_s *radio, - uint8_t mode) -{ - union ieee802154_radioarg_u arg; - int ret; - - arg.devmode = mode; - - ret = RADIO_IOCTL(radio, PHY802154IOC_SET_DEVMODE, &arg); - if (ret < 0) - { - wlerr("ERROR: PHY802154IOC_SET_DEVMODE failed: %d\n", ret); - } - - return ret; -} - -/**************************************************************************** - * Name: radio802154_setdevmode - * - * Description: - * Return the current device mode - * - ****************************************************************************/ - -int radio802154_getdevmode(FAR struct ieee802154_radio_s *radio, - FAR uint8_t *mode) -{ - union ieee802154_radioarg_u arg; - int ret; - - ret = RADIO_IOCTL(radio, PHY802154IOC_GET_DEVMODE, &arg); - if (ret < 0) - { - wlerr("ERROR: PHY802154IOC_GET_DEVMODE failed: %d\n", ret); - } - - *mode = arg.devmode; - return ret; -} - -/**************************************************************************** - * Name: radio802154_settxpower - * - * Description: - * Define the transmit power. Value is passed in mBm, it is rounded to - * the nearest value. Some MRF modules have a power amplifier, this routine - * does not care about this. We only change the CHIP output power. - * - ****************************************************************************/ - -int radio802154_settxpower(FAR struct ieee802154_radio_s *radio, - int32_t txpwr) -{ - union ieee802154_radioarg_u arg; - int ret; - - arg.txpwr = txpwr; - - ret = RADIO_IOCTL(radio, PHY802154IOC_SET_TXPWR, &arg); - if (ret < 0) - { - wlerr("ERROR: PHY802154IOC_SET_TXPWR failed: %d\n", ret); - } - - return ret; -} - -/**************************************************************************** - * Name: radio802154_gettxpower - * - * Description: - * Return the actual transmit power, in mBm. - * - ****************************************************************************/ - -int radio802154_gettxpower(FAR struct ieee802154_radio_s *radio, - FAR int32_t *txpwr) -{ - union ieee802154_radioarg_u arg; - int ret; - - ret = RADIO_IOCTL(radio, PHY802154IOC_GET_TXPWR, &arg); - if (ret < 0) - { - wlerr("ERROR: PHY802154IOC_GET_TXPWR failed: %d\n", ret); - } - - *txpwr = arg.txpwr; - return ret; -} - -/**************************************************************************** - * Name: radio802154_setcca - * - * Description: - * Define the Clear Channel Assessement method. - * - ****************************************************************************/ - -int radio802154_setcca(FAR struct ieee802154_radio_s *radio, - FAR struct ieee802154_cca_s *cca) -{ - union ieee802154_radioarg_u arg; - int ret; - - memcpy(&arg.cca, cca, sizeof(struct ieee802154_cca_s)); - - ret = RADIO_IOCTL(radio, PHY802154IOC_SET_CCA, &arg); - if (ret < 0) - { - wlerr("ERROR: PHY802154IOC_SET_CCA failed: %d\n", ret); - } - - return ret; -} - -/**************************************************************************** - * Name: radio802154_getcca - * - * Description: - * Return the Clear Channel Assessement method. - * - ****************************************************************************/ - -int radio802154_getcca(FAR struct ieee802154_radio_s *radio, - FAR struct ieee802154_cca_s *cca) -{ - union ieee802154_radioarg_u arg; - int ret; - - ret = RADIO_IOCTL(radio, PHY802154IOC_GET_CCA, &arg); - if (ret < 0) - { - wlerr("ERROR: PHY802154IOC_GET_CCA failed: %d\n", ret); - } - - memcpy(cca, &arg.cca, sizeof(struct ieee802154_cca_s)); - return ret; -} - -/**************************************************************************** - * Name: radio802154_energydetect - * - * Description: - * Measure the RSSI level for the current channel. - * - ****************************************************************************/ - -int radio802154_energydetect(FAR struct ieee802154_radio_s *radio, - FAR uint8_t *energy) - -{ - union ieee802154_radioarg_u arg; - int ret; - - ret = RADIO_IOCTL(radio, PHY802154IOC_ENERGYDETECT, &arg); - if (ret < 0) - { - wlerr("ERROR: PHY802154IOC_ENERGYDETECT failed: %d\n", ret); - } - - *energy = arg.energy; - return ret; -} diff --git a/wireless/ieee802154/radio802154_ioctl.h b/wireless/ieee802154/radio802154_ioctl.h deleted file mode 100644 index d09ad57103e..00000000000 --- a/wireless/ieee802154/radio802154_ioctl.h +++ /dev/null @@ -1,255 +0,0 @@ -/**************************************************************************** - * wireless/ieee802154/radio802154_ioctl.h - * - * Copyright (C) 2017 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -#ifndef __WIRELESS_IEEE802154_RADIO802154_IOCTL_H -#define __WIRELESS_IEEE802154_RADIO802154_IOCTL_H 1 - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include - -#include - -#include "radio802154_ioctl.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: radio802154_setchannel - * - * Description: - * Define the current radio channel the device is operating on. - * In the 2.4 GHz, there are 16 channels, each 2 MHz wide, 5 MHz spacing: - * Chan MHz Chan MHz Chan MHz Chan MHz - * 11 2405 15 2425 19 2445 23 2465 - * 12 2410 16 2430 20 2450 24 2470 - * 13 2415 17 2435 21 2455 25 2475 - * 14 2420 18 2440 22 2460 26 2480 - * - ****************************************************************************/ - -int radio802154_setchannel(FAR struct ieee802154_radio_s *radio, - uint8_t chan); - -/**************************************************************************** - * Name: radio802154_getchannel - * - * Description: - * Define the current radio channel the device is operating on. - * - ****************************************************************************/ - -int radio802154_getchannel(FAR struct ieee802154_radio_s *radio, - FAR uint8_t *chan); - -/**************************************************************************** - * Name: radio802154_setpanid - * - * Description: - * Define the PAN ID the device is operating on. - * - ****************************************************************************/ - -int radio802154_setpanid(FAR struct ieee802154_radio_s *radio, - uint16_t panid); - -/**************************************************************************** - * Name: radio802154_getpanid - * - * Description: - * Define the current PAN ID the device is operating on. - * - ****************************************************************************/ - -int radio802154_getpanid(FAR struct ieee802154_radio_s *radio, - FAR uint16_t *panid); - -/**************************************************************************** - * Name: radio802154_setsaddr - * - * Description: - * Define the device short address. The following addresses are special: - * FFFEh : Broadcast - * FFFFh : Unspecified - * - ****************************************************************************/ - -int radio802154_setsaddr(FAR struct ieee802154_radio_s *radio, - uint16_t saddr); - -/**************************************************************************** - * Name: radio802154_getsaddr - * - * Description: - * Define the current short address the device is using. - * - ****************************************************************************/ - -int radio802154_getsaddr(FAR struct ieee802154_radio_s *radio, - FAR uint16_t *saddr); - -/**************************************************************************** - * Name: radio802154_seteaddr - * - * Description: - * Define the device extended address. The following addresses are special: - * FFFFFFFFFFFFFFFFh : Unspecified - * - ****************************************************************************/ - -int radio802154_seteaddr(FAR struct ieee802154_radio_s *radio, - FAR uint8_t *eaddr); - -/**************************************************************************** - * Name: radio802154_geteaddr - * - * Description: - * Define the current extended address the device is using. - * - ****************************************************************************/ - -int radio802154_geteaddr(FAR struct ieee802154_radio_s *radio, - FAR uint8_t *eaddr); - -/**************************************************************************** - * Name: radio802154_setpromisc - * - * Description: - * Set the device into promiscuous mode, e.g do not filter any incoming - * frame. - * - ****************************************************************************/ - -int radio802154_setpromisc(FAR struct ieee802154_radio_s *radio, - bool promisc); - -/**************************************************************************** - * Name: radio802154_getpromisc - * - * Description: - * Get the device receive mode. - * - ****************************************************************************/ - -int radio802154_getpromisc(FAR struct ieee802154_radio_s *radio, - FAR bool *promisc); - -/**************************************************************************** - * Name: radio802154_setdevmode - * - * Description: - * Define the device behaviour: normal end device or coordinator - * - ****************************************************************************/ - -int radio802154_setdevmode(FAR struct ieee802154_radio_s *radio, - uint8_t mode); - -/**************************************************************************** - * Name: radio802154_setdevmode - * - * Description: - * Return the current device mode - * - ****************************************************************************/ - -int radio802154_getdevmode(FAR struct ieee802154_radio_s *radio, - FAR uint8_t *mode); - -/**************************************************************************** - * Name: radio802154_settxpower - * - * Description: - * Define the transmit power. Value is passed in mBm, it is rounded to - * the nearest value. Some MRF modules have a power amplifier, this routine - * does not care about this. We only change the CHIP output power. - * - ****************************************************************************/ - -int radio802154_settxpower(FAR struct ieee802154_radio_s *radio, - int32_t txpwr); - -/**************************************************************************** - * Name: radio802154_gettxpower - * - * Description: - * Return the actual transmit power, in mBm. - * - ****************************************************************************/ - -int radio802154_gettxpower(FAR struct ieee802154_radio_s *radio, - FAR int32_t *txpwr); - -/**************************************************************************** - * Name: radio802154_setcca - * - * Description: - * Define the Clear Channel Assessement method. - * - ****************************************************************************/ - -int radio802154_setcca(FAR struct ieee802154_radio_s *radio, - FAR struct ieee802154_cca_s *cca); - -/**************************************************************************** - * Name: radio802154_getcca - * - * Description: - * Return the Clear Channel Assessement method. - * - ****************************************************************************/ - -int radio802154_getcca(FAR struct ieee802154_radio_s *radio, - FAR struct ieee802154_cca_s *cca); - -/**************************************************************************** - * Name: radio802154_energydetect - * - * Description: - * Measure the RSSI level for the current channel. - * - ****************************************************************************/ - -int radio802154_energydetect(FAR struct ieee802154_radio_s *radio, - FAR uint8_t *energy); - -#endif /* __WIRELESS_IEEE802154_RADIO802154_IOCTL_H */ From 0e49db76263713974946c67cfbf7473dd179aee5 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 5 May 2017 09:35:22 -0600 Subject: [PATCH 149/183] Add a blank line. --- arch/arm/src/kinetis/kinetis_lpserial.c | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm/src/kinetis/kinetis_lpserial.c b/arch/arm/src/kinetis/kinetis_lpserial.c index 5a70582d411..117dd3de4a1 100644 --- a/arch/arm/src/kinetis/kinetis_lpserial.c +++ b/arch/arm/src/kinetis/kinetis_lpserial.c @@ -670,6 +670,7 @@ static int kinetis_ioctl(struct file *filep, int cmd, unsigned long arg) { regval &= ~(LPUART_CTRL_LOOPS | LPUART_CTRL_RSRC); } + kinetis_serialout(priv, KINETIS_LPUART_CTRL_OFFSET, regval); } break; From 95bacb6a34b526aa44c08706b156a776b1cbe340 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 5 May 2017 10:00:18 -0600 Subject: [PATCH 150/183] 6loWPAN: Some fixed to get a clean compile after last big changes to the radio IOCTLs. --- include/nuttx/fs/ioctl.h | 4 ++-- net/sixlowpan/sixlowpan_internal.h | 9 ++++++++- net/sixlowpan/sixlowpan_utils.c | 3 ++- wireless/ieee802154/mac802154_loopback.c | 14 +++++++------- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/include/nuttx/fs/ioctl.h b/include/nuttx/fs/ioctl.h index 2d18dc217e8..cfcc4507d60 100644 --- a/include/nuttx/fs/ioctl.h +++ b/include/nuttx/fs/ioctl.h @@ -425,8 +425,8 @@ /* 802.15.4 MAC driver ioctl definitions ************************************/ /* (see nuttx/include/wireless/ieee802154/ieee802154_mac.h */ -#define _MAC802154IOCVALID(c) (_IOC_TYPE(c)==_MAC802154BASE) -#define _MAC802154IOC(nr) _IOC(_MAC802154BASE,nr) +#define _MAC802154IOCVALID(c) (_IOC_TYPE(c)==_MAC802154BASE) +#define _MAC802154IOC(nr) _IOC(_MAC802154BASE,nr) /* boardctl() command definitions *******************************************/ diff --git a/net/sixlowpan/sixlowpan_internal.h b/net/sixlowpan/sixlowpan_internal.h index c48b89929ff..cf71100db15 100644 --- a/net/sixlowpan/sixlowpan_internal.h +++ b/net/sixlowpan/sixlowpan_internal.h @@ -134,7 +134,9 @@ * Public Types ****************************************************************************/ -/* IPv^ TCP/UDP Definitions *************************************************/ +/* IPv6 TCP/UDP/ICMPv6 Definitions ******************************************/ + +#ifdef CONFIG_NET_TCP /* IPv6 + TCP header. Cast compatible based on IPv6 protocol field. */ struct ipv6tcp_hdr_s @@ -142,7 +144,9 @@ struct ipv6tcp_hdr_s struct ipv6_hdr_s ipv6; struct tcp_hdr_s tcp; }; +#endif +#ifdef CONFIG_NET_UDP /* IPv6 + UDP header */ struct ipv6udp_hdr_s @@ -150,7 +154,9 @@ struct ipv6udp_hdr_s struct ipv6_hdr_s ipv6; struct udp_hdr_s udp; }; +#endif +#ifdef CONFIG_NET_ICMPv6 /* IPv6 + ICMPv6 header */ struct ipv6icmp_hdr_s @@ -158,6 +164,7 @@ struct ipv6icmp_hdr_s struct ipv6_hdr_s ipv6; struct icmpv6_iphdr_s icmp; }; +#endif /* In order to provide a customizable IEEE 802.15.4 MAC header, a structure * of meta data is passed to the MAC network driver, struct diff --git a/net/sixlowpan/sixlowpan_utils.c b/net/sixlowpan/sixlowpan_utils.c index d392f0ef477..a1d7892a3e3 100644 --- a/net/sixlowpan/sixlowpan_utils.c +++ b/net/sixlowpan/sixlowpan_utils.c @@ -57,6 +57,7 @@ #include #include +#include #include "sixlowpan/sixlowpan_internal.h" @@ -193,7 +194,7 @@ int sixlowpan_src_panid(FAR struct ieee802154_driver_s *ieee, return ret; } - *panid = arg.u.getreq.attr_value->panid; + *panid = arg.u.getreq.attr_value.mac.panid; return OK; } diff --git a/wireless/ieee802154/mac802154_loopback.c b/wireless/ieee802154/mac802154_loopback.c index 44cb4f0762b..f30953a3869 100644 --- a/wireless/ieee802154/mac802154_loopback.c +++ b/wireless/ieee802154/mac802154_loopback.c @@ -577,10 +577,9 @@ static int lo_rmmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac) static int lo_ioctl(FAR struct net_driver_s *dev, int cmd, unsigned long arg) { - FAR struct lo_driver_s *priv = (FAR struct lo_driver_s *)dev->d_private; - int ret = -ENOTTY; - #if 0 + FAR struct lo_driver_s *priv = (FAR struct lo_driver_s *)dev->d_private; + /* Check for IOCTLs aimed at the IEEE802.15.4 MAC layer */ if (_MAC802154IOCVALID(cmd)) @@ -588,12 +587,13 @@ static int lo_ioctl(FAR struct net_driver_s *dev, int cmd, FAR struct ieee802154_netmac_s *netmac = (FAR struct ieee802154_netmac_s *)arg; } - - /* No, check for IOCTLs aimed at the IEEE802.15.4 radio layer */ - else #endif - return ret; + { + /* Not a valid IEEE 802.15.4 MAC IOCTL command */ + + return -ENOTTY; + } } #endif From b98ba3b6fe6ea0c42df7a31110d835a0f4972c91 Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Fri, 5 May 2017 12:07:26 -0400 Subject: [PATCH 151/183] wireless/ieee802154: Fixes ieee802154_data_ind_s --- .../wireless/ieee802154/ieee802154_mac.h | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/include/nuttx/wireless/ieee802154/ieee802154_mac.h b/include/nuttx/wireless/ieee802154/ieee802154_mac.h index 407b6f6be73..d4046bccb26 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_mac.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_mac.h @@ -652,13 +652,34 @@ struct ieee802154_data_conf_s struct ieee802154_data_ind_s { - uint8_t msdu_handle; /* Handle assoc. with MSDU */ + struct ieee802154_addr_s src; /* Source addressing information */ + struct ieee802154_addr_s dest; /* Destination addressing infromation */ + uint8_t lqi; /* Link Quality Index */ + uint8_t dsn; /* Data Sequence Number */ + uint32_t timestamp; /* Time of received frame */ - /* The time, in symbols, at which the data were transmitted */ +#ifdef CONFIG_IEEE802154_SECURITY + /* Security information if enabled */ - uint32_t timestamp; + struct ieee802154_security_s security; +#endif /* CONFIG_IEEE802154_SECURITY */ - enum ieee802154_status_e status; /* The status of the MSDU transmission */ +#ifdef CONFIG_IEEE802154_UWB + /* The UWB Pulse Repetition Frequency to be used for the transmission */ + + enum ieee802154_uwbprf_e uwb_prf; + + /* The UWB preamble symbol repititions + * Should be one of: + * 0, 16, 64, 1024, 4096 + */ + + uint16_t uwb_presym_rep; + + /* The UWB Data Rate to be used for the transmission */ + + enum ieee802154_uwb_datarate_e data_rate; +#endif /* CONFIG_IEEE802154_UWB */ #ifdef CONFIG_IEEE802154_RANGING bool rng_rcvd; /* Ranging indicated by MSDU */ @@ -690,7 +711,7 @@ struct ieee802154_data_ind_s /* The Figure of Merit (FoM) characterizing the ranging measurement */ uint8_t rng_fom; -#endif +#endif /* CONFIG_IEEE802154_RANGING */ }; /***************************************************************************** From b87fac776f0a8b515a5b1cdbaed0a082f16b1b6f Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Fri, 5 May 2017 12:44:29 -0400 Subject: [PATCH 152/183] wireless/ieee802154: Removes msdu_length from meta-data since it is intrinsically in the IOB --- include/nuttx/wireless/ieee802154/ieee802154_ioctl.h | 1 + include/nuttx/wireless/ieee802154/ieee802154_mac.h | 9 --------- wireless/ieee802154/mac802154.c | 2 +- wireless/ieee802154/mac802154_device.c | 4 ++-- 4 files changed, 4 insertions(+), 12 deletions(-) diff --git a/include/nuttx/wireless/ieee802154/ieee802154_ioctl.h b/include/nuttx/wireless/ieee802154/ieee802154_ioctl.h index cd5550057c9..6171d0e3a34 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_ioctl.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_ioctl.h @@ -78,6 +78,7 @@ struct mac802154dev_txframe_s { struct ieee802154_frame_meta_s meta; FAR uint8_t *payload; + uint16_t length; }; #endif /* CONFIG_WIRELESS_IEEE802154 */ diff --git a/include/nuttx/wireless/ieee802154/ieee802154_mac.h b/include/nuttx/wireless/ieee802154/ieee802154_mac.h index d4046bccb26..8f8e0c22d52 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_mac.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_mac.h @@ -585,15 +585,6 @@ struct ieee802154_frame_meta_s uint8_t msdu_handle; /* Handle assoc. with MSDU */ - /* Number of bytes contained in the MAC Service Data Unit (MSDU) - * to be transmitted by the MAC sublayer entity - * Note: This could be a uint8_t but if anyone ever wants to use - * non-standard frame lengths, they may want a length larger than - * a uint8_t. - */ - - uint16_t msdu_length; - struct { uint8_t ack_tx : 1; /* Acknowledge TX? */ diff --git a/wireless/ieee802154/mac802154.c b/wireless/ieee802154/mac802154.c index 0f548841c26..23ed9db872e 100644 --- a/wireless/ieee802154/mac802154.c +++ b/wireless/ieee802154/mac802154.c @@ -1078,7 +1078,7 @@ int mac802154_req_data(MACHANDLE mac, * sublayer will set the Frame Version to one. [1] pg. 118. */ - if (meta->msdu_length > IEEE802154_MAX_SAFE_MAC_PAYLOAD_SIZE) + if ((frame->io_len - frame->io_offset) > IEEE802154_MAX_SAFE_MAC_PAYLOAD_SIZE) { *frame_ctrl |= IEEE802154_FRAMECTRL_VERSION; } diff --git a/wireless/ieee802154/mac802154_device.c b/wireless/ieee802154/mac802154_device.c index d78e7acfdc1..6ea212ae531 100644 --- a/wireless/ieee802154/mac802154_device.c +++ b/wireless/ieee802154/mac802154_device.c @@ -449,9 +449,9 @@ static ssize_t mac802154dev_write(FAR struct file *filep, iob->io_offset = ret; iob->io_len = iob->io_offset; - memcpy(&iob->io_data[iob->io_offset], tx->payload, tx->meta.msdu_length); + memcpy(&iob->io_data[iob->io_offset], tx->payload, tx->length); - iob->io_len += tx->meta.msdu_length; + iob->io_len += tx->length; /* If this is a blocking operation, we need to setup a wait struct so we * can unblock when the packet transmission has finished. If this is a From 0eb7ec046ed31b2831cd9958c8557f0845836db4 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 5 May 2017 11:36:16 -0600 Subject: [PATCH 153/183] 6loWPAN: Use information in struct ieee802154_data_ind_s when reassembling a packet --- include/nuttx/net/netdev.h | 8 +-- include/nuttx/net/sixlowpan.h | 6 +- net/sixlowpan/sixlowpan_input.c | 76 +++++++++++++++++++++--- wireless/ieee802154/mac802154_loopback.c | 5 +- 4 files changed, 78 insertions(+), 17 deletions(-) diff --git a/include/nuttx/net/netdev.h b/include/nuttx/net/netdev.h index 0b65d2afd3d..782c2e33990 100644 --- a/include/nuttx/net/netdev.h +++ b/include/nuttx/net/netdev.h @@ -436,12 +436,12 @@ int ipv6_input(FAR struct net_driver_s *dev); #endif #ifdef CONFIG_NET_6LOWPAN -struct ieee802154_driver_s; /* See sixlowpan.h */ -struct eee802154_data_ind_s; /* See sixlowpan.h */ -struct iob_s; /* See iob.h */ +struct ieee802154_driver_s; /* See sixlowpan.h */ +struct ieee802154_data_ind_s; /* See ieee8021454_mac.h */ +struct iob_s; /* See iob.h */ int sixlowpan_input(FAR struct ieee802154_driver_s *ieee, FAR struct iob_s *framelist, - FAR const struct eee802154_data_ind_s *ind); + FAR const struct ieee802154_data_ind_s *ind); #endif /**************************************************************************** diff --git a/include/nuttx/net/sixlowpan.h b/include/nuttx/net/sixlowpan.h index 591687bb1dc..a99f0e5e677 100644 --- a/include/nuttx/net/sixlowpan.h +++ b/include/nuttx/net/sixlowpan.h @@ -342,7 +342,7 @@ */ struct ieee802154_frame_meta_s; /* Forward reference */ -struct eee802154_data_ind_s; /* Forward reference */ +struct ieee802154_data_ind_s; /* Forward reference */ struct iob_s; /* Forward reference */ struct ieee802154_driver_s @@ -421,7 +421,7 @@ struct ieee802154_driver_s /* The source MAC address of the fragments being merged */ - union sixlowpan_anyaddr_u i_fragsrc; + struct sixlowpan_tagaddr_s i_fragsrc; /* That time at which reassembly was started. If the elapsed time * exceeds CONFIG_NET_6LOWPAN_MAXAGE, then the reassembly will @@ -540,7 +540,7 @@ struct ieee802154_driver_s int sixlowpan_input(FAR struct ieee802154_driver_s *ieee, FAR struct iob_s *framelist, - FAR const struct eee802154_data_ind_s *ind); + FAR const struct ieee802154_data_ind_s *ind); #endif /* CONFIG_NET_6LOWPAN */ #endif /* __INCLUDE_NUTTX_NET_SIXLOWPAN_H */ diff --git a/net/sixlowpan/sixlowpan_input.c b/net/sixlowpan/sixlowpan_input.c index 3c203d07a1b..9739ab7f610 100644 --- a/net/sixlowpan/sixlowpan_input.c +++ b/net/sixlowpan/sixlowpan_input.c @@ -61,6 +61,7 @@ #include "nuttx/net/netdev.h" #include "nuttx/net/ip.h" #include "nuttx/net/sixlowpan.h" +#include "nuttx/wireless/ieee802154/ieee802154_mac.h" #ifdef CONFIG_NET_PKT # include "pkt/pkt.h" @@ -129,6 +130,55 @@ static uint8_t g_bitbucket[UNCOMP_MAXHDR]; * Private Functions ****************************************************************************/ +/**************************************************************************** + * Name: sixlowpan_compare_fragsrc + * + * Description: + * Check if the fragment that we just received is from the same source as + * the previosly received fragements. + * + * Input Parameters: + * ieee - IEEE 802.15.4 MAC driver state reference + * ind - Characteristics of the newly received frame + * + * Returned Value: + * true if the sources are the same. + * + ****************************************************************************/ + +static bool sixlowpan_compare_fragsrc(FAR struct ieee802154_driver_s *ieee, + FAR const struct ieee802154_data_ind_s *ind) +{ + /* Check for an extended source address */ + + if (ind->src.mode == IEEE802154_ADDRMODE_EXTENDED) + { + /* Was the first source address also extended? */ + + if (ieee->i_fragsrc.extended) + { + /* Yes.. perform the extended address comparison */ + + return sixlowpan_eaddrcmp(ieee->i_fragsrc.u.eaddr.u8, ind->src.eaddr); + } + } + else + { + /* Short source address. Was the first source address also short? */ + + if (!ieee->i_fragsrc.extended) + { + /* Yes.. perform the extended short comparison */ + + return sixlowpan_saddrcmp(ieee->i_fragsrc.u.saddr.u8, &ind->src.saddr); + } + } + + /* Address are different size and, hence, cannot match */ + + return false; +} + /**************************************************************************** * Name: sixlowpan_compress_ipv6hdr * @@ -235,6 +285,7 @@ static void sixlowpan_uncompress_ipv6hdr(FAR uint8_t *fptr, FAR uint8_t *bptr) * * Input Parameters: * ieee - The IEEE802.15.4 MAC network driver interface. + * ind - Meta data characterizing the received frame. * iob - The IOB containing the frame. * * Returned Value: @@ -246,6 +297,7 @@ static void sixlowpan_uncompress_ipv6hdr(FAR uint8_t *fptr, FAR uint8_t *bptr) ****************************************************************************/ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, + FAR const struct ieee802154_data_ind_s *ind, FAR struct iob_s *iob) { FAR uint8_t *fptr; /* Convenience pointer to beginning of the frame */ @@ -401,8 +453,8 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, /* Verify that this fragment is part of that reassembly sequence */ - else if (fragsize != ieee->i_pktlen || ieee->i_reasstag != fragtag /* || - !sixlowpan_addrcmp(&ieee->i_fragsrc, &ind->???) */) + else if (fragsize != ieee->i_pktlen || ieee->i_reasstag != fragtag || + !sixlowpan_compare_fragsrc(ieee, ind)) { /* The packet is a fragment that does not belong to the packet * being reassembled or the packet is not a fragment. @@ -459,10 +511,16 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee, * address. */ -#warning Missing logic -#if 0 - sixlowpan_addrcopy(&ieee->i_fragsrc, ind->???]); -#endif + if (ind->src.mode == IEEE802154_ADDRMODE_EXTENDED) + { + ieee->i_fragsrc.extended = true; + sixlowpan_eaddrcopy(ieee->i_fragsrc.u.eaddr.u8, ind->src.eaddr); + } + else + { + memset(&ieee->i_fragsrc, 0, sizeof(struct sixlowpan_tagaddr_s)); + sixlowpan_saddrcopy(ieee->i_fragsrc.u.saddr.u8, &ind->src.saddr); + } } #endif /* CONFIG_NET_6LOWPAN_FRAG */ @@ -698,7 +756,7 @@ static int sixlowpan_dispatch(FAR struct ieee802154_driver_s *ieee) * framelist - The head of an incoming list of frames. Normally this * would be a single frame. A list may be provided if * appropriate, however. - * ind - Meta data characterizing the received packet. If there are + * ind - Meta data characterizing the received frame. If there are * multilple frames in the list, this meta data must apply to * all of the frames! * @@ -709,7 +767,7 @@ static int sixlowpan_dispatch(FAR struct ieee802154_driver_s *ieee) int sixlowpan_input(FAR struct ieee802154_driver_s *ieee, FAR struct iob_s *framelist, - FAR const struct eee802154_data_ind_s *ind) + FAR const struct ieee802154_data_ind_s *ind) { int ret = -EINVAL; @@ -730,7 +788,7 @@ int sixlowpan_input(FAR struct ieee802154_driver_s *ieee, /* Process the frame, decompressing it into the packet buffer */ - ret = sixlowpan_frame_process(ieee, iob); + ret = sixlowpan_frame_process(ieee, ind, iob); /* Free the IOB the held the consumed frame */ diff --git a/wireless/ieee802154/mac802154_loopback.c b/wireless/ieee802154/mac802154_loopback.c index f30953a3869..47940329c74 100644 --- a/wireless/ieee802154/mac802154_loopback.c +++ b/wireless/ieee802154/mac802154_loopback.c @@ -176,9 +176,12 @@ static int lo_req_data(FAR struct ieee802154_driver_s *netdev, static int lo_loopback(FAR struct net_driver_s *dev) { FAR struct lo_driver_s *priv = (FAR struct lo_driver_s *)dev->d_private; + struct ieee802154_data_ind_s ind; FAR struct iob_s *iob; int ret; + memset(&ind, 0, sizeof(struct ieee802154_data_ind_s)); + /* Loop while there framelist to be sent, i.e., while the freme list is not * emtpy. Sending, of course, just means relaying back through the network * for this driver. @@ -210,7 +213,7 @@ static int lo_loopback(FAR struct net_driver_s *dev) ninfo("Send frame %p to the network: Offset=%u Length=%u\n", iob, iob->io_offset, iob->io_len); - ret = sixlowpan_input(&priv->lo_ieee, iob, NULL); + ret = sixlowpan_input(&priv->lo_ieee, iob, &ind); /* Increment statistics */ From 3fcdc28a59a640bfe0482a381933694a40b271ac Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 5 May 2017 12:50:34 -0600 Subject: [PATCH 154/183] ieee 802.15.4: Add a pool-based memory allocator for RX frame meta-data. --- .../wireless/ieee802154/ieee802154_mac.h | 3 + wireless/ieee802154/Kconfig | 29 ++ wireless/ieee802154/Make.defs | 2 + wireless/ieee802154/mac802154.c | 65 ++++ wireless/ieee802154/mac802154.h | 2 + wireless/ieee802154/mac802154_indalloc.c | 367 ++++++++++++++++++ 6 files changed, 468 insertions(+) create mode 100644 wireless/ieee802154/mac802154_indalloc.c diff --git a/include/nuttx/wireless/ieee802154/ieee802154_mac.h b/include/nuttx/wireless/ieee802154/ieee802154_mac.h index d4046bccb26..bc3dfd3bced 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_mac.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_mac.h @@ -652,10 +652,13 @@ struct ieee802154_data_conf_s struct ieee802154_data_ind_s { + FAR struct ieee802154_data_ind_s *flink; + struct ieee802154_addr_s src; /* Source addressing information */ struct ieee802154_addr_s dest; /* Destination addressing infromation */ uint8_t lqi; /* Link Quality Index */ uint8_t dsn; /* Data Sequence Number */ + uint8_t pool; /* Memory pool (Needed for deallocation) */ uint32_t timestamp; /* Time of received frame */ #ifdef CONFIG_IEEE802154_SECURITY diff --git a/wireless/ieee802154/Kconfig b/wireless/ieee802154/Kconfig index aa3f16219c8..77f194d6efa 100644 --- a/wireless/ieee802154/Kconfig +++ b/wireless/ieee802154/Kconfig @@ -60,6 +60,35 @@ config IEEE802154_NTXDESC endif # IEEE802154_MAC +config IEEE802154_IND_PREALLOC + int "Number of pre-allocated meta-data structures" + default 20 + ---help--- + This specifies the total number of preallocated meta data structures + must be allocated with each incoming packet. These may be allocated + from either from tasking logic or from interrupt level logic. + +config IEEE802154_IND_IRQRESERVE + int "Rserved pre-allocated meta-data structures" + default 10 + ---help--- + If meta-data structures can be allocated from interrupt handlers, + then this specifies the number of pre-allocatd meta-data structures + that are reserved for for use only by interrupt handlers. This may + be zero to reserve no meta-data structures for interrupt handlers. + In that case, the allocation will fail if tasking logic has + allocated them all. + + Interrupt logic will first attempt to allocate fromt the general, + pre-allocated structure pool that will contain up to (size + CONFIG_IEEE802154_IND_PREALLOC - CONFIG_IEEE802154_IND_IRQRESERVE) + entries. If that fails, then it will try to take a structure from + the reserve (size CONFIG_IEEE802154_IND_IRQRESERVE). + + Non-interrupt logic will also first attempt to allocate fromt the + general, pre-allocated structure pool. If that fails, it will + dynamically allocate the meta data structure with an additional cost in performance. + config IEEE802154_NETDEV bool "IEEE802154 6loWPAN Network Device" default n diff --git a/wireless/ieee802154/Make.defs b/wireless/ieee802154/Make.defs index da84b153a7b..73354b2609b 100644 --- a/wireless/ieee802154/Make.defs +++ b/wireless/ieee802154/Make.defs @@ -37,6 +37,8 @@ ifeq ($(CONFIG_WIRELESS_IEEE802154),y) # Include IEEE 802.15.4 support +CSRCS += mac802154_indalloc.c + # Include wireless devices build support ifeq ($(CONFIG_IEEE802154_MAC),y) diff --git a/wireless/ieee802154/mac802154.c b/wireless/ieee802154/mac802154.c index 0f548841c26..46073765b6b 100644 --- a/wireless/ieee802154/mac802154.c +++ b/wireless/ieee802154/mac802154.c @@ -1605,3 +1605,68 @@ int mac802154_resp_orphan(MACHANDLE mac, (FAR struct ieee802154_privmac_s *)mac; return -ENOTTY; } + +/**************************************************************************** + * Name: ieee802154_indpool_initialize + * + * Description: + * This function initializes the meta-data allocator. This function must + * be called early in the initialization sequence before any radios + * begin operation. + * + * Inputs: + * None + * + * Return Value: + * None + * + ****************************************************************************/ + +void ieee802154_indpool_initialize(void); + +/**************************************************************************** + * Name: ieee802154_ind_allocate + * + * Description: + * The ieee802154_ind_allocate function will get a free meta-data + * structure for use by the IEEE 802.15.4 MAC. + * + * Interrupt handling logic will first attempt to allocate from the + * g_indfree list. If that list is empty, it will attempt to allocate + * from its reserve, g_indfree_irq. If that list is empty, then the + * allocation fails (NULL is returned). + * + * Non-interrupt handler logic will attempt to allocate from g_indfree + * list. If that the list is empty, then the meta-data structure will be + * allocated from the dynamic memory pool. + * + * Inputs: + * None + * + * Return Value: + * A reference to the allocated msg structure. All user fields in this + * structure have been zeroed. On a failure to allocate, NULL is + * returned. + * + ****************************************************************************/ + +FAR struct ieee802154_data_ind_s *ieee802154_ind_allocate(void); + +/**************************************************************************** + * Name: ieee802154_ind_free + * + * Description: + * The ieee802154_ind_free function will return a meta-data structure to + * the free pool of messages if it was a pre-allocated meta-data + * structure. If the meta-data structure was allocated dynamically it will + * be deallocated. + * + * Inputs: + * ind - meta-data structure to free + * + * Return Value: + * None + * + ****************************************************************************/ + +void ieee802154_ind_free(FAR struct ieee802154_data_ind_s *ind); diff --git a/wireless/ieee802154/mac802154.h b/wireless/ieee802154/mac802154.h index b98fa0d3601..152046b61fe 100644 --- a/wireless/ieee802154/mac802154.h +++ b/wireless/ieee802154/mac802154.h @@ -58,6 +58,8 @@ * Public Function Prototypes ****************************************************************************/ +struct iob_s; /* Forward reference */ + /**************************************************************************** * Name: mac802154_bind * diff --git a/wireless/ieee802154/mac802154_indalloc.c b/wireless/ieee802154/mac802154_indalloc.c new file mode 100644 index 00000000000..84ec3b131af --- /dev/null +++ b/wireless/ieee802154/mac802154_indalloc.c @@ -0,0 +1,367 @@ +/**************************************************************************** + * wireless/ieee802154_indalloc.c + * + * Copyright (C) 2017 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include +#include + +#include "mac802154.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#if !defined(CONFIG_IEEE802154_IND_PREALLOC) || CONFIG_IEEE802154_IND_PREALLOC < 0 +# undef CONFIG_IEEE802154_IND_PREALLOC +# define CONFIG_IEEE802154_IND_PREALLOC 20 +#endif + +#if !defined(CONFIG_IEEE802154_IND_IRQRESERVE) || CONFIG_IEEE802154_IND_IRQRESERVE < 0 +# undef CONFIG_IEEE802154_IND_IRQRESERVE +# define CONFIG_IEEE802154_IND_IRQRESERVE 10 +#endif + +#if CONFIG_IEEE802154_IND_IRQRESERVE > CONFIG_IEEE802154_IND_PREALLOC +# undef CONFIG_IEEE802154_IND_IRQRESERVE +# define CONFIG_IEEE802154_IND_IRQRESERVE CONFIG_IEEE802154_IND_PREALLOC +#endif + +/* Memory Pools */ + +#define POOL_IND_GENERAL 0 +#define POOL_IND_IRQ 1 +#define POOL_IND_DYNAMIC 2 + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +#if CONFIG_IEEE802154_IND_PREALLOC > 0 +#if CONFIG_IEEE802154_IND_PREALLOC > CONFIG_IEEE802154_IND_IRQRESERVE +/* The g_indfree is a list of meta-data structures that are available for + * general use. The number of messages in this list is a system configuration + * item. + */ + +static struct ieee802154_data_ind_s *g_indfree; +#endif + +#if CONFIG_IEEE802154_IND_IRQRESERVE > 0 +/* The g_indfree_irq is a list of meta-data structures that are reserved for + * use by only by interrupt handlers. + */ + +static struct ieee802154_data_ind_s *g_indfree_irq; +#endif + +/* Pool of pre-allocated meta-data stuctures */ + +static struct ieee802154_data_ind_s g_indpool[CONFIG_IEEE802154_IND_PREALLOC]; +#endif /* CONFIG_IEEE802154_IND_PREALLOC > 0 */ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: ieee802154_indpool_initialize + * + * Description: + * This function initializes the meta-data allocator. This function must + * be called early in the initialization sequence before any radios + * begin operation. + * + * Inputs: + * None + * + * Return Value: + * None + * + ****************************************************************************/ + +void ieee802154_indpool_initialize(void) +{ +#if CONFIG_IEEE802154_IND_PREALLOC > 0 + FAR struct ieee802154_data_ind_s *pool = g_indpool; + int remaining = CONFIG_IEEE802154_IND_PREALLOC; + +#if CONFIG_IEEE802154_IND_PREALLOC > CONFIG_IEEE802154_IND_IRQRESERVE + /* Initialize g_indfree, thelist of meta-data structures that are available + * for general use. + */ + + g_indfree = NULL; + while (remaining > CONFIG_IEEE802154_IND_IRQRESERVE) + { + FAR struct ieee802154_data_ind_s *ind = pool; + + /* Add the next meta data structure from the pool to the list of + * general structures. + */ + + ind->flink = g_indfree; + g_indfree = ind; + + /* Set up for the next structure from the pool */ + + pool++; + remaining--; + } +#endif + +#if CONFIG_IEEE802154_IND_IRQRESERVE > 0 + /* Initialize g_indfree_irq is a list of meta-data structures reserved for + * use by only by interrupt handlers. + */ + + g_indfree_irq = NULL; + while (remaining > 0) + { + FAR struct ieee802154_data_ind_s *ind = pool; + + /* Add the next meta data structure from the pool to the list of + * general structures. + */ + + ind->flink = g_indfree_irq; + g_indfree_irq = ind; + + /* Set up for the next structure from the pool */ + + pool++; + remaining--; + } +#endif +#endif /* CONFIG_IEEE802154_IND_PREALLOC > 0 */ +} + +/**************************************************************************** + * Name: ieee802154_ind_allocate + * + * Description: + * The ieee802154_ind_allocate function will get a free meta-data + * structure for use by the IEEE 802.15.4 MAC. + * + * Interrupt handling logic will first attempt to allocate from the + * g_indfree list. If that list is empty, it will attempt to allocate + * from its reserve, g_indfree_irq. If that list is empty, then the + * allocation fails (NULL is returned). + * + * Non-interrupt handler logic will attempt to allocate from g_indfree + * list. If that the list is empty, then the meta-data structure will be + * allocated from the dynamic memory pool. + * + * Inputs: + * None + * + * Return Value: + * A reference to the allocated msg structure. All user fields in this + * structure have been zeroed. On a failure to allocate, NULL is + * returned. + * + ****************************************************************************/ + +FAR struct ieee802154_data_ind_s *ieee802154_ind_allocate(void) +{ +#if CONFIG_IEEE802154_IND_PREALLOC > 0 + FAR struct ieee802154_data_ind_s *ind; + irqstate_t flags; + uint8_t pool; + + /* If we were called from an interrupt handler, then try to get the meta- + * data structure from generally available list of messages. If this fails, + * then try the list of messages reserved for interrupt handlers + */ + + flags = enter_critical_section(); /* Always necessary in SMP mode */ + if (up_interrupt_context()) + { +#if CONFIG_IEEE802154_IND_PREALLOC > CONFIG_IEEE802154_IND_IRQRESERVE + /* Try the general free list */ + + if (g_indfree != NULL) + { + ind = g_indfree; + g_indfree = ind->flink; + + leave_critical_section(flags); + pool = POOL_IND_GENERAL; + } + else +#endif +#if CONFIG_IEEE802154_IND_IRQRESERVE > 0 + /* Try the list list reserved for interrupt handlers */ + + if (g_indfree_irq != NULL) + { + ind = g_indfree_irq; + g_indfree_irq = ind->flink; + + leave_critical_section(flags); + pool = POOL_IND_IRQ; + } + else +#endif + { + leave_critical_section(flags); + return NULL; + } + } + + /* We were not called from an interrupt handler. */ + + else + { +#if CONFIG_IEEE802154_IND_PREALLOC > CONFIG_IEEE802154_IND_IRQRESERVE + /* Try the general free list */ + + if (g_indfree != NULL) + { + ind = g_indfree; + g_indfree = ind->flink; + + leave_critical_section(flags); + pool = POOL_IND_GENERAL; + } + else +#endif + { + /* If we cannot a meta-data structure from the free list, then we + * will have to allocate one from the kernal memory pool. + */ + + leave_critical_section(flags); + ind = (FAR struct ieee802154_data_ind_s *) + kmm_malloc((sizeof (struct ieee802154_data_ind_s))); + + /* Check if we allocated the meta-data structure */ + + if (ind != NULL) + { + /* Yes... remember that this meta-data structure was dynamically allocated */ + + pool = POOL_IND_DYNAMIC; + } + } + } + + /* We have successfully allocated memory from some source. + * Zero and tag the alloated meta-data structure. + */ + + memset(ind, 0, sizeof(struct ieee802154_data_ind_s)); + ind->pool = pool; + return ind; +#else + return NULL; +#endif +} + +/**************************************************************************** + * Name: ieee802154_ind_free + * + * Description: + * The ieee802154_ind_free function will return a meta-data structure to + * the free pool of messages if it was a pre-allocated meta-data + * structure. If the meta-data structure was allocated dynamically it will + * be deallocated. + * + * Inputs: + * ind - meta-data structure to free + * + * Return Value: + * None + * + ****************************************************************************/ + +void ieee802154_ind_free(FAR struct ieee802154_data_ind_s *ind) +{ +#if CONFIG_IEEE802154_IND_PREALLOC > 0 + irqstate_t flags; + +#if CONFIG_IEEE802154_IND_PREALLOC > CONFIG_IEEE802154_IND_IRQRESERVE + /* If this is a generally available pre-allocated meta-data structure, + * then just put it back in the free list. + */ + + if (ind->pool == POOL_IND_GENERAL) + { + /* Make sure we avoid concurrent access to the free + * list from interrupt handlers. + */ + + flags = enter_critical_section(); + ind->flink = g_indfree; + g_indfree = ind; + leave_critical_section(flags); + } + else +#endif + +#if CONFIG_IEEE802154_IND_IRQRESERVE > 0 + /* If this is a meta-data structure pre-allocated for interrupts, + * then put it back in the correct free list. + */ + + if (ind->pool == POOL_IND_IRQ) + { + /* Make sure we avoid concurrent access to the free + * list from interrupt handlers. + */ + + flags = enter_critical_section(); + ind->flink = g_indfree_irq; + g_indfree_irq = ind; + leave_critical_section(flags); + } + else +#endif + + { + /* Otherwise, deallocate it. */ + + DEBUGASSERT(ind->pool == POOL_IND_DYNAMIC); + sched_kfree(ind); + } +#endif +} From a1a68216a9d38b087462e468f984582f89f3d8dc Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 5 May 2017 14:43:44 -0600 Subject: [PATCH 155/183] Trivial changes to spacing --- wireless/ieee802154/mac802154_indalloc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wireless/ieee802154/mac802154_indalloc.c b/wireless/ieee802154/mac802154_indalloc.c index 84ec3b131af..86d8dcd0ef9 100644 --- a/wireless/ieee802154/mac802154_indalloc.c +++ b/wireless/ieee802154/mac802154_indalloc.c @@ -163,8 +163,8 @@ void ieee802154_indpool_initialize(void) * general structures. */ - ind->flink = g_indfree_irq; - g_indfree_irq = ind; + ind->flink = g_indfree_irq; + g_indfree_irq = ind; /* Set up for the next structure from the pool */ From 1cd3b3f590bf821e8f93e14f5c5318ebce16f982 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 5 May 2017 14:47:11 -0600 Subject: [PATCH 156/183] Fix errors introduced into Kinetis serial when I unsuccessfully tried to correct coding standard violations. Folks, things will be better for everyone if you just follow that standard. --- arch/arm/src/kinetis/kinetis_lpserial.c | 10 +++++++--- arch/arm/src/kinetis/kinetis_serial.c | 6 +++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/arch/arm/src/kinetis/kinetis_lpserial.c b/arch/arm/src/kinetis/kinetis_lpserial.c index 117dd3de4a1..515f1f370e0 100644 --- a/arch/arm/src/kinetis/kinetis_lpserial.c +++ b/arch/arm/src/kinetis/kinetis_lpserial.c @@ -615,12 +615,12 @@ static int kinetis_ioctl(struct file *filep, int cmd, unsigned long arg) { #if defined(CONFIG_SERIAL_TERMIOS) || defined(CONFIG_SERIAL_TIOCSERGSTRUCT) || \ defined(CONFIG_KINETIS_SERIALBRK_BSDCOMPAT) - struct inode *inode = filep->f_inode; - struct uart_dev_s *dev = inode->i_private; + struct inode *inode; + struct uart_dev_s *dev; uint8_t regval; #endif #if defined(CONFIG_SERIAL_TERMIOS) || defined(CONFIG_KINETIS_SERIALBRK_BSDCOMPAT) - struct kinetis_dev_s *priv = (struct kinetis_dev_s *)dev->priv; + struct kinetis_dev_s *priv; bool iflow = false; bool oflow = false; #endif @@ -634,6 +634,10 @@ static int kinetis_ioctl(struct file *filep, int cmd, unsigned long arg) DEBUGASSERT(dev != NULL && dev->priv != NULL); #endif +#if defined(CONFIG_SERIAL_TERMIOS) || defined(CONFIG_KINETIS_SERIALBRK_BSDCOMPAT) + priv = (struct kinetis_dev_s *)dev->priv; +#endif + switch (cmd) { #ifdef CONFIG_SERIAL_TIOCSERGSTRUCT diff --git a/arch/arm/src/kinetis/kinetis_serial.c b/arch/arm/src/kinetis/kinetis_serial.c index b7c6aeebc76..0f2a4b2ee46 100644 --- a/arch/arm/src/kinetis/kinetis_serial.c +++ b/arch/arm/src/kinetis/kinetis_serial.c @@ -980,7 +980,7 @@ static int up_ioctl(struct file *filep, int cmd, unsigned long arg) uint8_t regval; #endif #if defined(CONFIG_SERIAL_TERMIOS) || defined(CONFIG_KINETIS_SERIALBRK_BSDCOMPAT) - struct up_dev_s *priv = (struct up_dev_s *)dev->priv; + struct up_dev_s *priv; bool iflow = false; bool oflow = false; #endif @@ -994,6 +994,10 @@ static int up_ioctl(struct file *filep, int cmd, unsigned long arg) DEBUGASSERT(dev != NULL && dev->priv != NULL); #endif +#if defined(CONFIG_SERIAL_TERMIOS) || defined(CONFIG_KINETIS_SERIALBRK_BSDCOMPAT) + priv = (struct up_dev_s *)dev->priv; +#endif + switch (cmd) { #ifdef CONFIG_SERIAL_TIOCSERGSTRUCT From 979e671cf0e403540a2c20093417894d77db5a9d Mon Sep 17 00:00:00 2001 From: David Sidrane Date: Fri, 5 May 2017 15:02:55 -1000 Subject: [PATCH 157/183] kinetis:k20 Pin mux configure all I2C signals as Open Drain The output structure of the GPIO for I2C needs to be open drain. When left at the default, one can observe on a scope the slave contending with the push-pull during the ACK --- arch/arm/src/kinetis/chip/kinetis_k20pinmux.h | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/arch/arm/src/kinetis/chip/kinetis_k20pinmux.h b/arch/arm/src/kinetis/chip/kinetis_k20pinmux.h index ca708acfdf8..d77ea962704 100644 --- a/arch/arm/src/kinetis/chip/kinetis_k20pinmux.h +++ b/arch/arm/src/kinetis/chip/kinetis_k20pinmux.h @@ -1,8 +1,9 @@ /******************************************************************************************** * arch/arm/src/kinetis/chip/kinetis_k20pinmux.h * - * Copyright (C) 2015-2016 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Copyright (C) 2015-2017 Gregory Nutt. All rights reserved. + * Authors: Gregory Nutt + * David Sidrane * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -159,14 +160,14 @@ # define PIN_FTM2_QD_PHA (PIN_ALT6 | PIN_PORTB | PIN18) # define PIN_FTM2_QD_PHB (PIN_ALT6 | PIN_PORTB | PIN19) -# define PIN_I2C0_SCL_1 (PIN_ALT2 | PIN_PORTB | PIN0) -# define PIN_I2C0_SCL_2 (PIN_ALT2 | PIN_PORTB | PIN2) -# define PIN_I2C0_SDA_1 (PIN_ALT2 | PIN_PORTB | PIN1) -# define PIN_I2C0_SDA_2 (PIN_ALT2 | PIN_PORTB | PIN3) -# define PIN_I2C1_SCL_1 (PIN_ALT2 | PIN_PORTC | PIN10) -# define PIN_I2C1_SCL_2 (PIN_ALT6 | PIN_PORTE | PIN1) -# define PIN_I2C1_SDA_1 (PIN_ALT2 | PIN_PORTC | PIN11) -# define PIN_I2C1_SDA_2 (PIN_ALT6 | PIN_PORTE | PIN0) +# define PIN_I2C0_SCL_1 (PIN_ALT2_OPENDRAIN | PIN_PORTB | PIN0) +# define PIN_I2C0_SCL_2 (PIN_ALT2_OPENDRAIN | PIN_PORTB | PIN2) +# define PIN_I2C0_SDA_1 (PIN_ALT2_OPENDRAIN | PIN_PORTB | PIN1) +# define PIN_I2C0_SDA_2 (PIN_ALT2_OPENDRAIN | PIN_PORTB | PIN3) +# define PIN_I2C1_SCL_1 (PIN_ALT2_OPENDRAIN | PIN_PORTC | PIN10) +# define PIN_I2C1_SCL_2 (PIN_ALT6_OPENDRAIN | PIN_PORTE | PIN1) +# define PIN_I2C1_SDA_1 (PIN_ALT2_OPENDRAIN | PIN_PORTC | PIN11) +# define PIN_I2C1_SDA_2 (PIN_ALT6_OPENDRAIN | PIN_PORTE | PIN0) # define PIN_I2S0_MCLK_1 (PIN_ALT4 | PIN_PORTC | PIN8) # define PIN_I2S0_MCLK_2 (PIN_ALT6 | PIN_PORTC | PIN6) From 1d9d13c426d9463fb7c14d66329bb8d08e05789b Mon Sep 17 00:00:00 2001 From: David Sidrane Date: Fri, 5 May 2017 15:02:55 -1000 Subject: [PATCH 158/183] kinetis:k40 Pin mux configure all I2C signals as Open Drain The output structure of the GPIO for I2C needs to be open drain. When left at the default, one can observe on a scope the slave contending with the push-pull during the ACK --- arch/arm/src/kinetis/chip/kinetis_k40pinmux.h | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/arch/arm/src/kinetis/chip/kinetis_k40pinmux.h b/arch/arm/src/kinetis/chip/kinetis_k40pinmux.h index 7083b0caf7c..c7570edaf9a 100644 --- a/arch/arm/src/kinetis/chip/kinetis_k40pinmux.h +++ b/arch/arm/src/kinetis/chip/kinetis_k40pinmux.h @@ -1,8 +1,9 @@ /******************************************************************************************** * arch/arm/src/kinetis/chip/kinetis_k40pinmux.h * - * Copyright (C) 2011, 2016 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Copyright (C) 2011, 2016-2017 Gregory Nutt. All rights reserved. + * Authors: Gregory Nutt + * David Sidrane * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -160,7 +161,7 @@ #define PIN_ADC0_SE8 (PIN_ANALOG | PIN_PORTB | PIN0) #define PIN_ADC1_SE8 (PIN_ANALOG | PIN_PORTB | PIN0) #define PIN_TSI0_CH0 (PIN_ANALOG | PIN_PORTB | PIN0) -#define PIN_I2C0_SCL_1 (PIN_ALT2 | PIN_PORTB | PIN0) +#define PIN_I2C0_SCL_1 (PIN_ALT2_OPENDRAIN | PIN_PORTB | PIN0) #define PIN_FTM1_CH0_3 (PIN_ALT3 | PIN_PORTB | PIN0) #define PIN_FTM1_QD_PHA_3 (PIN_ALT6 | PIN_PORTB | PIN0) #define PIN_LCD_P0F (PIN_ALT7 | PIN_PORTB | PIN0) @@ -168,21 +169,21 @@ #define PIN_ADC0_SE9 (PIN_ANALOG | PIN_PORTB | PIN1) #define PIN_ADC1_SE9 (PIN_ANALOG | PIN_PORTB | PIN1) #define PIN_TSI0_CH6 (PIN_ANALOG | PIN_PORTB | PIN1) -#define PIN_I2C0_SDA_1 (PIN_ALT2 | PIN_PORTB | PIN1) +#define PIN_I2C0_SDA_1 (PIN_ALT2_OPENDRAIN | PIN_PORTB | PIN1) #define PIN_FTM1_CH1_3 (PIN_ALT3 | PIN_PORTB | PIN1) #define PIN_FTM1_QD_PHB (PIN_ALT6 | PIN_PORTB | PIN1) #define PIN_LCD_P1F (PIN_ALT7 | PIN_PORTB | PIN1) #define PIN_LCD_P2 (PIN_ANALOG | PIN_PORTB | PIN2) #define PIN_ADC0_SE12 (PIN_ANALOG | PIN_PORTB | PIN2) #define PIN_TSI0_CH7 (PIN_ANALOG | PIN_PORTB | PIN2) -#define PIN_I2C0_SCL_2 (PIN_ALT2 | PIN_PORTB | PIN2) +#define PIN_I2C0_SCL_2 (PIN_ALT2_OPENDRAIN| PIN_PORTB | PIN2) #define PIN_UART0_RTS_3 (PIN_ALT3 | PIN_PORTB | PIN2) #define PIN_FTM0_FLT3 (PIN_ALT6 | PIN_PORTB | PIN2) #define PIN_LCD_P2F (PIN_ALT7 | PIN_PORTB | PIN2) #define PIN_LCD_P3 (PIN_ANALOG | PIN_PORTB | PIN3) #define PIN_ADC0_SE13 (PIN_ANALOG | PIN_PORTB | PIN3) #define PIN_TSI0_CH8 (PIN_ANALOG | PIN_PORTB | PIN3) -#define PIN_I2C0_SDA_2 (PIN_ALT2 | PIN_PORTB | PIN3) +#define PIN_I2C0_SDA_2 (PIN_ALT2_OPENDRAIN | PIN_PORTB | PIN3) #define PIN_UART0_CTS_3 (PIN_ALT3 | PIN_PORTB | PIN3) #define PIN_FTM0_FLT0_1 (PIN_ALT6 | PIN_PORTB | PIN3) #define PIN_LCD_P3F (PIN_ALT7 | PIN_PORTB | PIN3) @@ -325,12 +326,12 @@ #define PIN_LCD_P30 (PIN_ANALOG | PIN_PORTC | PIN10) #define PIN_ADC1_SE6B (PIN_ANALOG | PIN_PORTC | PIN10) #define PIN_CMP0_IN4 (PIN_ANALOG | PIN_PORTC | PIN10) -#define PIN_I2C1_SCL_1 (PIN_ALT2 | PIN_PORTC | PIN10) +#define PIN_I2C1_SCL_1 (PIN_ALT2_OPENDRAIN | PIN_PORTC | PIN10) #define PIN_I2S0_RX_FS_2 (PIN_ALT4 | PIN_PORTC | PIN10) #define PIN_LCD_P30F (PIN_ALT7 | PIN_PORTC | PIN10) #define PIN_LCD_P31 (PIN_ANALOG | PIN_PORTC | PIN11) #define PIN_ADC1_SE7B (PIN_ANALOG | PIN_PORTC | PIN11) -#define PIN_I2C1_SDA_1 (PIN_ALT2 | PIN_PORTC | PIN11) +#define PIN_I2C1_SDA_1 (PIN_ALT2_OPENDRAIN | PIN_PORTC | PIN11) #define PIN_I2S0_RXD_2 (PIN_ALT4 | PIN_PORTC | PIN11) #define PIN_LCD_P31F (PIN_ALT7 | PIN_PORTC | PIN11) #define PIN_LCD_P32 (PIN_ANALOG | PIN_PORTC | PIN12) @@ -427,13 +428,13 @@ #define PIN_UART1_TX_2 (PIN_ALT3 | PIN_PORTE | PIN0) #define PIN_SDHC0_D1 (PIN_ALT4 | PIN_PORTE | PIN0) #define PIN_FB_AD27 (PIN_ALT5 | PIN_PORTE | PIN0) -#define PIN_I2C1_SDA_2 (PIN_ALT6 | PIN_PORTE | PIN0) +#define PIN_I2C1_SDA_2 (PIN_ALT6_OPENDRAIN | PIN_PORTE | PIN0) #define PIN_ADC1_SE5A (PIN_ANALOG | PIN_PORTE | PIN1) #define PIN_SPI1_SOUT_2 (PIN_ALT2 | PIN_PORTE | PIN1) #define PIN_UART1_RX_2 (PIN_ALT3 | PIN_PORTE | PIN1) #define PIN_SDHC0_D0 (PIN_ALT4 | PIN_PORTE | PIN1) #define PIN_FB_AD26 (PIN_ALT5 | PIN_PORTE | PIN1) -#define PIN_I2C1_SCL_2 (PIN_ALT6 | PIN_PORTE | PIN1) +#define PIN_I2C1_SCL_2 (PIN_ALT6_OPENDRAIN | PIN_PORTE | PIN1) #define PIN_ADC1_SE6A (PIN_ANALOG | PIN_PORTE | PIN2) #define PIN_SPI1_SCK_2 (PIN_ALT2 | PIN_PORTE | PIN2) #define PIN_UART1_CTS_2 (PIN_ALT3 | PIN_PORTE | PIN2) From af1f48c1c55f6ece27522f1082b554c6a246b9cc Mon Sep 17 00:00:00 2001 From: David Sidrane Date: Fri, 5 May 2017 15:02:56 -1000 Subject: [PATCH 159/183] kinetis:k60 Pin mux configure all I2C signals as Open Drain The output structure of the GPIO for I2C needs to be open drain. When left at the default, one can observe on a scope the slave contending with the push-pull during the ACK --- arch/arm/src/kinetis/chip/kinetis_k60pinmux.h | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/arch/arm/src/kinetis/chip/kinetis_k60pinmux.h b/arch/arm/src/kinetis/chip/kinetis_k60pinmux.h index 888a5955840..b1ca87746f3 100644 --- a/arch/arm/src/kinetis/chip/kinetis_k60pinmux.h +++ b/arch/arm/src/kinetis/chip/kinetis_k60pinmux.h @@ -1,8 +1,9 @@ /******************************************************************************************** * arch/arm/src/kinetis/chip/kinetis_k60pinset.h * - * Copyright (C) 2011, 2016 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Copyright (C) 2011, 2016-2017 Gregory Nutt. All rights reserved. + * Authors: Gregory Nutt + * David Sidrane * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -172,7 +173,7 @@ #define PIN_ADC0_SE8 (PIN_ANALOG | PIN_PORTB | PIN0) #define PIN_ADC1_SE8 (PIN_ANALOG | PIN_PORTB | PIN0) #define PIN_TSI0_CH0 (PIN_ANALOG | PIN_PORTB | PIN0) -#define PIN_I2C0_SCL_1 (PIN_ALT2 | PIN_PORTB | PIN0) +#define PIN_I2C0_SCL_1 (PIN_ALT2_OPENDRAIN | PIN_PORTB | PIN0) #define PIN_FTM1_CH0_3 (PIN_ALT3 | PIN_PORTB | PIN0) #ifdef CONFIG_KINETIS_ENET_MDIOPULLUP # define PIN_RMII0_MDIO (PIN_ALT4_PULLUP | PIN_PORTB | PIN0) @@ -184,20 +185,20 @@ #define PIN_ADC0_SE9 (PIN_ANALOG | PIN_PORTB | PIN1) #define PIN_ADC1_SE9 (PIN_ANALOG | PIN_PORTB | PIN1) #define PIN_TSI0_CH6 (PIN_ANALOG | PIN_PORTB | PIN1) -#define PIN_I2C0_SDA_1 (PIN_ALT2 | PIN_PORTB | PIN1) +#define PIN_I2C0_SDA_1 (PIN_ALT2_OPENDRAIN | PIN_PORTB | PIN1) #define PIN_FTM1_CH1_3 (PIN_ALT3 | PIN_PORTB | PIN1) #define PIN_RMII0_MDC (PIN_ALT4 | PIN_PORTB | PIN1) #define PIN_MII0_MDC (PIN_ALT4 | PIN_PORTB | PIN1) #define PIN_FTM1_QD_PHB_3 (PIN_ALT6 | PIN_PORTB | PIN1) #define PIN_ADC0_SE12 (PIN_ANALOG | PIN_PORTB | PIN2) #define PIN_TSI0_CH7 (PIN_ANALOG | PIN_PORTB | PIN2) -#define PIN_I2C0_SCL_2 (PIN_ALT2 | PIN_PORTB | PIN2) +#define PIN_I2C0_SCL_2 (PIN_ALT2_OPENDRAIN | PIN_PORTB | PIN2) #define PIN_UART0_RTS_3 (PIN_ALT3 | PIN_PORTB | PIN2) #define PIN_ENET0_1588_TMR0_1 (PIN_ALT4 | PIN_PORTB | PIN2) #define PIN_FTM0_FLT3 (PIN_ALT6 | PIN_PORTB | PIN2) #define PIN_ADC0_SE13 (PIN_ANALOG | PIN_PORTB | PIN3) #define PIN_TSI0_CH8 (PIN_ANALOG | PIN_PORTB | PIN3) -#define PIN_I2C0_SDA_2 (PIN_ALT2 | PIN_PORTB | PIN3) +#define PIN_I2C0_SDA_2 (PIN_ALT2_OPENDRAIN | PIN_PORTB | PIN3) #define PIN_UART0_CTS_3 (PIN_ALT3 | PIN_PORTB | PIN3) #define PIN_ENET0_1588_TMR1_1 (PIN_ALT4 | PIN_PORTB | PIN3) #define PIN_FTM0_FLT0_2 (PIN_ALT6 | PIN_PORTB | PIN3) @@ -313,11 +314,11 @@ #define PIN_FTM2_FLT0_2 (PIN_ALT6 | PIN_PORTC | PIN9) #define PIN_ADC1_SE6B (PIN_ANALOG | PIN_PORTC | PIN10) #define PIN_CMP0_IN4 (PIN_ANALOG | PIN_PORTC | PIN10) -#define PIN_I2C1_SCL_1 (PIN_ALT2 | PIN_PORTC | PIN10) +#define PIN_I2C1_SCL_1 (PIN_ALT2_OPENDRAIN | PIN_PORTC | PIN10) #define PIN_I2S0_RX_FS_2 (PIN_ALT4 | PIN_PORTC | PIN10) #define PIN_FB_AD5 (PIN_ALT5 | PIN_PORTC | PIN10) #define PIN_ADC1_SE7B (PIN_ANALOG | PIN_PORTC | PIN11) -#define PIN_I2C1_SDA_1 (PIN_ALT2 | PIN_PORTC | PIN11) +#define PIN_I2C1_SDA_1 (PIN_ALT2_OPENDRAIN | PIN_PORTC | PIN11) #define PIN_I2S0_RXD_2 (PIN_ALT4 | PIN_PORTC | PIN11) #define PIN_FB_RW (PIN_ALT5 | PIN_PORTC | PIN11) #define PIN_UART4_RTS_1 (PIN_ALT3 | PIN_PORTC | PIN12) @@ -387,10 +388,10 @@ #define PIN_UART0_TX_4 (PIN_ALT3 | PIN_PORTD | PIN7) #define PIN_FTM0_CH7_2 (PIN_ALT4 | PIN_PORTD | PIN7) #define PIN_FTM0_FLT1_2 (PIN_ALT6 | PIN_PORTD | PIN7) -#define PIN_I2C0_SCL_3 (PIN_ALT2 | PIN_PORTD | PIN8) +#define PIN_I2C0_SCL_3 (PIN_ALT2_OPENDRAIN | PIN_PORTD | PIN8) #define PIN_UART5_RX_1 (PIN_ALT3 | PIN_PORTD | PIN8) #define PIN_FB_A16 (PIN_ALT6 | PIN_PORTD | PIN8) -#define PIN_I2C0_SDA_3 (PIN_ALT2 | PIN_PORTD | PIN9) +#define PIN_I2C0_SDA_3 (PIN_ALT2_OPENDRAIN | PIN_PORTD | PIN9) #define PIN_UART5_TX_1 (PIN_ALT3 | PIN_PORTD | PIN9) #define PIN_FB_A17 (PIN_ALT6 | PIN_PORTD | PIN9) #define PIN_UART5_RTS_1 (PIN_ALT3 | PIN_PORTD | PIN10) @@ -416,12 +417,12 @@ #define PIN_SPI1_PCS1_2 (PIN_ALT2 | PIN_PORTE | PIN0) #define PIN_UART1_TX_2 (PIN_ALT3 | PIN_PORTE | PIN0) #define PIN_SDHC0_D1 (PIN_ALT4 | PIN_PORTE | PIN0) -#define PIN_I2C1_SDA_2 (PIN_ALT6 | PIN_PORTE | PIN0) +#define PIN_I2C1_SDA_2 (PIN_ALT6_OPENDRAIN | PIN_PORTE | PIN0) #define PIN_ADC1_SE5A (PIN_ANALOG | PIN_PORTE | PIN1) #define PIN_SPI1_SOUT_2 (PIN_ALT2 | PIN_PORTE | PIN1) #define PIN_UART1_RX_2 (PIN_ALT3 | PIN_PORTE | PIN1) #define PIN_SDHC0_D0 (PIN_ALT4 | PIN_PORTE | PIN1) -#define PIN_I2C1_SCL_2 (PIN_ALT6 | PIN_PORTE | PIN1) +#define PIN_I2C1_SCL_2 (PIN_ALT6_OPENDRAIN | PIN_PORTE | PIN1) #define PIN_ADC1_SE6A (PIN_ANALOG | PIN_PORTE | PIN2) #define PIN_SPI1_SCK_2 (PIN_ALT2 | PIN_PORTE | PIN2) #define PIN_UART1_CTS_2 (PIN_ALT3 | PIN_PORTE | PIN2) From ce98cedb17f0852eb93a08afb23447ef137848ff Mon Sep 17 00:00:00 2001 From: David Sidrane Date: Fri, 5 May 2017 15:02:56 -1000 Subject: [PATCH 160/183] kinetis:k64 Pin mux configure all I2C signals as Open Drain The output structure of the GPIO for I2C needs to be open drain. When left at the default, one can observe on a scope the slave contending with the push-pull during the ACK --- arch/arm/src/kinetis/chip/kinetis_k64pinmux.h | 41 ++++++++++--------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/arch/arm/src/kinetis/chip/kinetis_k64pinmux.h b/arch/arm/src/kinetis/chip/kinetis_k64pinmux.h index 3479099bf6c..d9894b3ff70 100644 --- a/arch/arm/src/kinetis/chip/kinetis_k64pinmux.h +++ b/arch/arm/src/kinetis/chip/kinetis_k64pinmux.h @@ -1,8 +1,9 @@ /******************************************************************************************** * arch/arm/src/kinetis/chip/kinetis_k64pinmux.h * - * Copyright (C) 2016 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt + * Copyright (C) 2016-2017 Gregory Nutt. All rights reserved. + * Authors: Gregory Nutt + * David Sidrane * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -305,26 +306,26 @@ /* I2C */ -#define PIN_I2C0_SCL_1 (PIN_ALT2 | PIN_PORTB | PIN0) -#define PIN_I2C0_SCL_2 (PIN_ALT2 | PIN_PORTB | PIN2) -#define PIN_I2C0_SCL_3 (PIN_ALT2 | PIN_PORTD | PIN8) -#define PIN_I2C0_SCL_4 (PIN_ALT5 | PIN_PORTE | PIN24) -#define PIN_I2C0_SCL_5 (PIN_ALT7 | PIN_PORTD | PIN2) -#define PIN_I2C0_SDA_1 (PIN_ALT2 | PIN_PORTB | PIN1) -#define PIN_I2C0_SDA_2 (PIN_ALT2 | PIN_PORTB | PIN3) -#define PIN_I2C0_SDA_3 (PIN_ALT2 | PIN_PORTD | PIN9) -#define PIN_I2C0_SDA_4 (PIN_ALT5 | PIN_PORTE | PIN25) -#define PIN_I2C0_SDA_5 (PIN_ALT7 | PIN_PORTD | PIN3) +#define PIN_I2C0_SCL_1 (PIN_ALT2_OPENDRAIN | PIN_PORTB | PIN0) +#define PIN_I2C0_SCL_2 (PIN_ALT2_OPENDRAIN | PIN_PORTB | PIN2) +#define PIN_I2C0_SCL_3 (PIN_ALT2_OPENDRAIN | PIN_PORTD | PIN8) +#define PIN_I2C0_SCL_4 (PIN_ALT5_OPENDRAIN | PIN_PORTE | PIN24) +#define PIN_I2C0_SCL_5 (PIN_ALT7_OPENDRAIN | PIN_PORTD | PIN2) +#define PIN_I2C0_SDA_1 (PIN_ALT2_OPENDRAIN | PIN_PORTB | PIN1) +#define PIN_I2C0_SDA_2 (PIN_ALT2_OPENDRAIN | PIN_PORTB | PIN3) +#define PIN_I2C0_SDA_3 (PIN_ALT2_OPENDRAIN | PIN_PORTD | PIN9) +#define PIN_I2C0_SDA_4 (PIN_ALT5_OPENDRAIN | PIN_PORTE | PIN25) +#define PIN_I2C0_SDA_5 (PIN_ALT7_OPENDRAIN | PIN_PORTD | PIN3) -#define PIN_I2C1_SCL_1 (PIN_ALT2 | PIN_PORTC | PIN10) -#define PIN_I2C1_SCL_2 (PIN_ALT6 | PIN_PORTE | PIN1) -#define PIN_I2C1_SDA_1 (PIN_ALT2 | PIN_PORTC | PIN11) -#define PIN_I2C1_SDA_2 (PIN_ALT6 | PIN_PORTE | PIN0) +#define PIN_I2C1_SCL_1 (PIN_ALT2_OPENDRAIN | PIN_PORTC | PIN10) +#define PIN_I2C1_SCL_2 (PIN_ALT6_OPENDRAIN | PIN_PORTE | PIN1) +#define PIN_I2C1_SDA_1 (PIN_ALT2_OPENDRAIN | PIN_PORTC | PIN11) +#define PIN_I2C1_SDA_2 (PIN_ALT6_OPENDRAIN | PIN_PORTE | PIN0) -#define PIN_I2C2_SCL_1 (PIN_ALT5 | PIN_PORTA | PIN12) -#define PIN_I2C2_SCL_2 (PIN_ALT5 | PIN_PORTA | PIN14) -#define PIN_I2C2_SDA_1 (PIN_ALT5 | PIN_PORTA | PIN11) -#define PIN_I2C2_SDA_2 (PIN_ALT5 | PIN_PORTA | PIN13) +#define PIN_I2C2_SCL_1 (PIN_ALT5_OPENDRAIN | PIN_PORTA | PIN12) +#define PIN_I2C2_SCL_2 (PIN_ALT5_OPENDRAIN | PIN_PORTA | PIN14) +#define PIN_I2C2_SDA_1 (PIN_ALT5_OPENDRAIN | PIN_PORTA | PIN11) +#define PIN_I2C2_SDA_2 (PIN_ALT5_OPENDRAIN | PIN_PORTA | PIN13) /* I2S */ From 97260321f2ef52407b6d5e6dc274a9e5945177da Mon Sep 17 00:00:00 2001 From: David Sidrane Date: Fri, 5 May 2017 15:02:57 -1000 Subject: [PATCH 161/183] kinetis:k66 Pin mux configure all I2C signals as Open Drain The output structure of the GPIO for I2C needs to be open drain. When left at the default, one can observe on a scope the slave contending with the push-pull during the ACK --- arch/arm/src/kinetis/chip/kinetis_k66pinmux.h | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/arch/arm/src/kinetis/chip/kinetis_k66pinmux.h b/arch/arm/src/kinetis/chip/kinetis_k66pinmux.h index b549f5c76d1..ad15c5ac024 100644 --- a/arch/arm/src/kinetis/chip/kinetis_k66pinmux.h +++ b/arch/arm/src/kinetis/chip/kinetis_k66pinmux.h @@ -317,31 +317,31 @@ /* I2C */ -#define PIN_I2C0_SCL_1 (PIN_ALT2 | PIN_PORTB | PIN0) -#define PIN_I2C0_SCL_2 (PIN_ALT2 | PIN_PORTB | PIN2) -#define PIN_I2C0_SCL_3 (PIN_ALT2 | PIN_PORTD | PIN8) -#define PIN_I2C0_SCL_4 (PIN_ALT5 | PIN_PORTE | PIN24) -#define PIN_I2C0_SCL_5 (PIN_ALT7 | PIN_PORTD | PIN2) -#define PIN_I2C0_SDA_1 (PIN_ALT2 | PIN_PORTB | PIN1) -#define PIN_I2C0_SDA_2 (PIN_ALT2 | PIN_PORTB | PIN3) -#define PIN_I2C0_SDA_3 (PIN_ALT2 | PIN_PORTD | PIN9) -#define PIN_I2C0_SDA_4 (PIN_ALT5 | PIN_PORTE | PIN25) -#define PIN_I2C0_SDA_5 (PIN_ALT7 | PIN_PORTD | PIN3) +#define PIN_I2C0_SCL_1 (PIN_ALT2_OPENDRAIN | PIN_PORTB | PIN0) +#define PIN_I2C0_SCL_2 (PIN_ALT2_OPENDRAIN | PIN_PORTB | PIN2) +#define PIN_I2C0_SCL_3 (PIN_ALT2_OPENDRAIN | PIN_PORTD | PIN8) +#define PIN_I2C0_SCL_4 (PIN_ALT5_OPENDRAIN | PIN_PORTE | PIN24) +#define PIN_I2C0_SCL_5 (PIN_ALT7_OPENDRAIN | PIN_PORTD | PIN2) +#define PIN_I2C0_SDA_1 (PIN_ALT2_OPENDRAIN | PIN_PORTB | PIN1) +#define PIN_I2C0_SDA_2 (PIN_ALT2_OPENDRAIN | PIN_PORTB | PIN3) +#define PIN_I2C0_SDA_3 (PIN_ALT2_OPENDRAIN | PIN_PORTD | PIN9) +#define PIN_I2C0_SDA_4 (PIN_ALT5_OPENDRAIN | PIN_PORTE | PIN25) +#define PIN_I2C0_SDA_5 (PIN_ALT7_OPENDRAIN | PIN_PORTD | PIN3) -#define PIN_I2C1_SCL_1 (PIN_ALT2 | PIN_PORTC | PIN10) -#define PIN_I2C1_SCL_2 (PIN_ALT6 | PIN_PORTE | PIN1) -#define PIN_I2C1_SDA_1 (PIN_ALT2 | PIN_PORTC | PIN11) -#define PIN_I2C1_SDA_2 (PIN_ALT6 | PIN_PORTE | PIN0) +#define PIN_I2C1_SCL_1 (PIN_ALT2_OPENDRAIN | PIN_PORTC | PIN10) +#define PIN_I2C1_SCL_2 (PIN_ALT6_OPENDRAIN | PIN_PORTE | PIN1) +#define PIN_I2C1_SDA_1 (PIN_ALT2_OPENDRAIN | PIN_PORTC | PIN11) +#define PIN_I2C1_SDA_2 (PIN_ALT6_OPENDRAIN | PIN_PORTE | PIN0) -#define PIN_I2C2_SCL_1 (PIN_ALT5 | PIN_PORTA | PIN12) -#define PIN_I2C2_SCL_2 (PIN_ALT5 | PIN_PORTA | PIN14) -#define PIN_I2C2_SDA_1 (PIN_ALT5 | PIN_PORTA | PIN11) -#define PIN_I2C2_SDA_2 (PIN_ALT5 | PIN_PORTA | PIN13) +#define PIN_I2C2_SCL_1 (PIN_ALT5_OPENDRAIN | PIN_PORTA | PIN12) +#define PIN_I2C2_SCL_2 (PIN_ALT5_OPENDRAIN | PIN_PORTA | PIN14) +#define PIN_I2C2_SDA_1 (PIN_ALT5_OPENDRAIN | PIN_PORTA | PIN11) +#define PIN_I2C2_SDA_2 (PIN_ALT5_OPENDRAIN | PIN_PORTA | PIN13) -#define PIN_I2C3_SCL_1 (PIN_ALT2 | PIN_PORTE | PIN11) -#define PIN_I2C3_SCL_2 (PIN_ALT4 | PIN_PORTA | PIN2) -#define PIN_I2C3_SDA_1 (PIN_ALT2 | PIN_PORTE | PIN10) -#define PIN_I2C3_SDA_2 (PIN_ALT4 | PIN_PORTA | PIN1) +#define PIN_I2C3_SCL_1 (PIN_ALT2_OPENDRAIN | PIN_PORTE | PIN11) +#define PIN_I2C3_SCL_2 (PIN_ALT4_OPENDRAIN | PIN_PORTA | PIN2) +#define PIN_I2C3_SDA_1 (PIN_ALT2_OPENDRAIN | PIN_PORTE | PIN10) +#define PIN_I2C3_SDA_2 (PIN_ALT4_OPENDRAIN | PIN_PORTA | PIN1) /* I2S */ From e072069e2d674e94fdcdd172eb19a9e93bdc61c2 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 6 May 2017 06:48:06 -0600 Subject: [PATCH 162/183] 6loWPAN: Remove usage of the now non-existent msdu_length field. --- net/sixlowpan/sixlowpan_framelist.c | 10 +--------- net/sixlowpan/sixlowpan_framer.c | 15 ++++----------- 2 files changed, 5 insertions(+), 20 deletions(-) diff --git a/net/sixlowpan/sixlowpan_framelist.c b/net/sixlowpan/sixlowpan_framelist.c index 6f41a59210a..3f208bb388f 100644 --- a/net/sixlowpan/sixlowpan_framelist.c +++ b/net/sixlowpan/sixlowpan_framelist.c @@ -535,15 +535,11 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, for (iob = qhead; iob != NULL; iob = qhead) { - /* Remove the IOB from the list */ + /* Remove the IOB containing the frame from the list */ qhead = iob->io_flink; iob->io_flink = NULL; - /* Update the MSDU length in the metadata */ - - meta.msdu_length = iob->io_len - iob->io_offset; - /* And submit the frame to the MAC */ ret = sixlowpan_frame_submit(ieee, &meta, iob); @@ -580,10 +576,6 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, sixlowpan_dumpbuffer("Outgoing frame", (FAR const uint8_t *)iob->io_data, iob->io_len); - /* Update the MSDU length in the metadata */ - - meta.msdu_length = iob->io_len - iob->io_offset; - /* And submit the frame to the MAC */ ret = sixlowpan_frame_submit(ieee, &meta, iob); diff --git a/net/sixlowpan/sixlowpan_framer.c b/net/sixlowpan/sixlowpan_framer.c index b750156d36c..9de555134d9 100644 --- a/net/sixlowpan/sixlowpan_framer.c +++ b/net/sixlowpan/sixlowpan_framer.c @@ -226,25 +226,18 @@ int sixlowpan_meta_data(FAR struct ieee802154_driver_s *ieee, meta->dest_addr.panid = g_packet_meta.dpanid; /* Handle associated with MSDU. Will increment once per packet, not - * necesarily per frame: The MSDU handler will be used for each fragment - * of a disassembled packet. + * necesarily per frame: The same MSDU handle will be used for each + * fragment of a disassembled packet. */ meta->msdu_handle = ieee->i_msdu_handle++; - /* Number of bytes contained in the MAC Service Data Unit (MSDU) */ - - meta->msdu_length = paylen; - - /* MSDU flags that may be non-zero */ - - #ifdef CONFIG_IEEE802154_SECURITY -# warning CONFIG_IEEE802154_SECURITY not yet supported" +# warning CONFIG_IEEE802154_SECURITY not yet supported #endif #ifdef CONFIG_IEEE802154_UWB -# warning CONFIG_IEEE802154_UWB not yet supported" +# warning CONFIG_IEEE802154_UWB not yet supported #endif /* Ranging left zero */ From 1490599b69ed7f99ee61c27f907d8b3e76b263fd Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Fri, 5 May 2017 17:12:26 -0400 Subject: [PATCH 163/183] wireless/ieee802154: Reworks data_ind allocation to include IOB allocation/deallocation. Hides private data. --- drivers/wireless/ieee802154/mrf24j40.c | 36 +++--- .../wireless/ieee802154/ieee802154_mac.h | 10 +- .../wireless/ieee802154/ieee802154_radio.h | 3 +- wireless/ieee802154/Kconfig | 4 +- wireless/ieee802154/mac802154.c | 105 +++--------------- wireless/ieee802154/mac802154.h | 65 +++++++++++ wireless/ieee802154/mac802154_indalloc.c | 86 ++++++++++---- 7 files changed, 172 insertions(+), 137 deletions(-) diff --git a/drivers/wireless/ieee802154/mrf24j40.c b/drivers/wireless/ieee802154/mrf24j40.c index 366471cd9c3..14c97827772 100644 --- a/drivers/wireless/ieee802154/mrf24j40.c +++ b/drivers/wireless/ieee802154/mrf24j40.c @@ -1505,8 +1505,7 @@ static int mrf24j40_rxenable(FAR struct ieee802154_radio_s *radio, bool enable) static void mrf24j40_irqwork_rx(FAR struct mrf24j40_radio_s *dev) { - FAR struct iob_s *iob; - struct ieee802154_rxdesc_s rxdesc; + FAR struct ieee802154_data_ind_s *ind; uint32_t addr; uint32_t index; uint8_t reg; @@ -1521,46 +1520,43 @@ static void mrf24j40_irqwork_rx(FAR struct mrf24j40_radio_s *dev) mrf24j40_setreg(dev->spi, MRF24J40_BBREG1, MRF24J40_BBREG1_RXDECINV); - /* Allocate an IOB to put the packet in */ + /* Allocate a data_ind to put the frame in */ - iob = iob_alloc(true); - DEBUGASSERT(iob != NULL); - - iob->io_flink = NULL; - iob->io_len = 0; - iob->io_offset = 0; - iob->io_pktlen = 0; + ind = ieee802154_ind_allocate(); + if (ind == NULL) + { + wlerr("ERROR: Unable to allocate data_ind. Discarding frame"); + goto done; + } /* Read packet */ addr = MRF24J40_RXBUF_BASE; - iob->io_len= mrf24j40_getreg(dev->spi, addr++); + ind->frame->io_len= mrf24j40_getreg(dev->spi, addr++); /* TODO: This needs to be changed. It is inefficient to do the SPI read byte * by byte */ - for (index = 0; index < iob->io_len; index++) + for (index = 0; index < ind->frame->io_len; index++) { - iob->io_data[index] = mrf24j40_getreg(dev->spi, addr++); + ind->frame->io_data[index] = mrf24j40_getreg(dev->spi, addr++); } - /* Copy meta-data into RX descriptor */ - - rxdesc.lqi = mrf24j40_getreg(dev->spi, addr++); - rxdesc.rssi = mrf24j40_getreg(dev->spi, addr++); + ind->lqi = mrf24j40_getreg(dev->spi, addr++); + ind->rssi = mrf24j40_getreg(dev->spi, addr++); /* Reduce len by 2, we only receive frames with correct crc, no check * required. */ - iob->io_len -= 2; + ind->frame->io_len -= 2; /* Callback the receiver in the next highest layer */ - dev->radiocb->rxframe(dev->radiocb, - (FAR const struct ieee802154_rxdesc_s *)&rxdesc, iob); + dev->radiocb->rxframe(dev->radiocb, ind); +done: /* Enable reception of next packet by flushing the fifo. * This is an MRF24J40 errata (no. 1). */ diff --git a/include/nuttx/wireless/ieee802154/ieee802154_mac.h b/include/nuttx/wireless/ieee802154/ieee802154_mac.h index b4583c2e3c4..fc9818212e1 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_mac.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_mac.h @@ -480,12 +480,6 @@ struct ieee802154_txdesc_s /* TODO: Add slotting information for GTS transactions */ }; -struct ieee802154_rxdesc_s -{ - uint8_t lqi; - uint8_t rssi; -}; - struct ieee802154_cca_s { uint8_t use_ed : 1; /* CCA using ED */ @@ -645,11 +639,13 @@ struct ieee802154_data_ind_s { FAR struct ieee802154_data_ind_s *flink; + FAR struct iob_s *frame; + struct ieee802154_addr_s src; /* Source addressing information */ struct ieee802154_addr_s dest; /* Destination addressing infromation */ uint8_t lqi; /* Link Quality Index */ + uint8_t rssi; /* Non-standard field */ uint8_t dsn; /* Data Sequence Number */ - uint8_t pool; /* Memory pool (Needed for deallocation) */ uint32_t timestamp; /* Time of received frame */ #ifdef CONFIG_IEEE802154_SECURITY diff --git a/include/nuttx/wireless/ieee802154/ieee802154_radio.h b/include/nuttx/wireless/ieee802154/ieee802154_radio.h index bfadc110237..fcbc7ec1b7e 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_radio.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_radio.h @@ -71,8 +71,7 @@ struct ieee802154_radiocb_s CODE void (*txdone) (FAR const struct ieee802154_radiocb_s *radiocb, FAR const struct ieee802154_txdesc_s *tx_desc); CODE void (*rxframe) (FAR const struct ieee802154_radiocb_s *radiocb, - FAR const struct ieee802154_rxdesc_s *rx_desc, - FAR struct iob_s *frame); + FAR struct ieee802154_data_ind_s *ind); }; struct ieee802154_radio_s; /* Forward reference */ diff --git a/wireless/ieee802154/Kconfig b/wireless/ieee802154/Kconfig index 77f194d6efa..ff64c06d843 100644 --- a/wireless/ieee802154/Kconfig +++ b/wireless/ieee802154/Kconfig @@ -79,13 +79,13 @@ config IEEE802154_IND_IRQRESERVE In that case, the allocation will fail if tasking logic has allocated them all. - Interrupt logic will first attempt to allocate fromt the general, + Interrupt logic will first attempt to allocate from the general, pre-allocated structure pool that will contain up to (size CONFIG_IEEE802154_IND_PREALLOC - CONFIG_IEEE802154_IND_IRQRESERVE) entries. If that fails, then it will try to take a structure from the reserve (size CONFIG_IEEE802154_IND_IRQRESERVE). - Non-interrupt logic will also first attempt to allocate fromt the + Non-interrupt logic will also first attempt to allocate from the general, pre-allocated structure pool. If that fails, it will dynamically allocate the meta data structure with an additional cost in performance. diff --git a/wireless/ieee802154/mac802154.c b/wireless/ieee802154/mac802154.c index f954fd9046b..127eae9d4f6 100644 --- a/wireless/ieee802154/mac802154.c +++ b/wireless/ieee802154/mac802154.c @@ -84,11 +84,11 @@ * Private Types ****************************************************************************/ -struct mac802154_trans_s +struct mac802154_txframe_s { /* Supports a singly linked list */ - FAR struct mac802154_trans_s *flink; + FAR struct mac802154_txframe_s *flink; FAR struct iob_s *frame; uint8_t msdu_handle; sem_t sem; @@ -132,8 +132,8 @@ struct ieee802154_privmac_s * during the CAP of the Coordinator's superframe. */ - FAR struct mac802154_trans_s *csma_head; - FAR struct mac802154_trans_s *csma_tail; + FAR struct mac802154_txframe_s *csma_head; + FAR struct mac802154_txframe_s *csma_tail; /* Support a singly linked list of transactions that will be sent indirectly. * This list should only be used by a MAC acting as a coordinator. These @@ -143,15 +143,15 @@ struct ieee802154_privmac_s * beacon frame. */ - FAR struct mac802154_trans_s *indirect_head; - FAR struct mac802154_trans_s *indirect_tail; + FAR struct mac802154_txframe_s *indirect_head; + FAR struct mac802154_txframe_s *indirect_tail; uint8_t txdesc_count; struct ieee802154_txdesc_s txdesc[CONFIG_IEEE802154_NTXDESC]; /* Support a singly linked list of frames received */ - FAR struct iob_s *rxframes_head; - FAR struct iob_s *rxframes_tail; + FAR struct ieee802154_data_ind_s *rxframes_head; + FAR struct ieee802154_data_ind_s *rxframes_tail; /* MAC PIB attributes, grouped to save memory */ @@ -297,8 +297,7 @@ static void mac802154_txdone(FAR const struct ieee802154_radiocb_s *radiocb, FAR const struct ieee802154_txdesc_s *tx_desc); static void mac802154_rxframe(FAR const struct ieee802154_radiocb_s *radiocb, - FAR const struct ieee802154_rxdesc_s *rx_desc, - FAR struct iob_s *frame); + FAR struct ieee802154_data_ind_s *ind); /**************************************************************************** * Private Data @@ -345,7 +344,7 @@ static inline int mac802154_takesem(sem_t *sem) ****************************************************************************/ static void mac802154_push_csma(FAR struct ieee802154_privmac_s *priv, - FAR struct mac802154_trans_s *trans) + FAR struct mac802154_txframe_s *trans) { /* Ensure the transactions forward link is NULL */ @@ -380,10 +379,10 @@ static void mac802154_push_csma(FAR struct ieee802154_privmac_s *priv, * ****************************************************************************/ -static FAR struct mac802154_trans_s * +static FAR struct mac802154_txframe_s * mac802154_pop_csma(FAR struct ieee802154_privmac_s *priv) { - FAR struct mac802154_trans_s *trans; + FAR struct mac802154_txframe_s *trans; if (priv->csma_head == NULL) { @@ -510,7 +509,7 @@ static int mac802154_poll_csma(FAR const struct ieee802154_radiocb_s *radiocb, FAR struct mac802154_radiocb_s *cb = (FAR struct mac802154_radiocb_s *)radiocb; FAR struct ieee802154_privmac_s *priv; - FAR struct mac802154_trans_s *trans; + FAR struct mac802154_txframe_s *trans; DEBUGASSERT(cb != NULL && cb->priv != NULL); priv = cb->priv; @@ -564,7 +563,7 @@ static int mac802154_poll_gts(FAR const struct ieee802154_radiocb_s *radiocb, FAR struct mac802154_radiocb_s *cb = (FAR struct mac802154_radiocb_s *)radiocb; FAR struct ieee802154_privmac_s *priv; - FAR struct mac802154_trans_s *trans; + FAR struct mac802154_txframe_s *trans; int ret = 0; DEBUGASSERT(cb != NULL && cb->priv != NULL); @@ -691,13 +690,11 @@ static void mac802154_txdone_worker(FAR void *arg) ****************************************************************************/ static void mac802154_rxframe(FAR const struct ieee802154_radiocb_s *radiocb, - FAR const struct ieee802154_rxdesc_s *rx_desc, - FAR struct iob_s *frame) + FAR struct ieee802154_data_ind_s *ind) { FAR struct mac802154_radiocb_s *cb = (FAR struct mac802154_radiocb_s *)radiocb; FAR struct ieee802154_privmac_s *priv; - FAR struct ieee802154_rxdesc_s *desc; DEBUGASSERT(cb != NULL && cb->priv != NULL); priv = cb->priv; @@ -708,12 +705,10 @@ static void mac802154_rxframe(FAR const struct ieee802154_radiocb_s *radiocb, while (mac802154_takesem(&priv->exclsem) != 0); - /* TODO: Copy the frame descriptor to some type of list */ - /* Push the iob onto the tail of the frame list for processing */ - priv->rxframes_tail->io_flink = frame; - priv->rxframes_tail = frame; + priv->rxframes_tail->flink = ind; + priv->rxframes_tail = ind; mac802154_givesem(&priv->exclsem); @@ -1050,7 +1045,7 @@ int mac802154_req_data(MACHANDLE mac, { FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)mac; - FAR struct mac802154_trans_s trans; + FAR struct mac802154_txframe_s trans; uint16_t *frame_ctrl; uint8_t mhr_len = 3; /* Start assuming frame control and seq. num */ int ret; @@ -1606,67 +1601,3 @@ int mac802154_resp_orphan(MACHANDLE mac, return -ENOTTY; } -/**************************************************************************** - * Name: ieee802154_indpool_initialize - * - * Description: - * This function initializes the meta-data allocator. This function must - * be called early in the initialization sequence before any radios - * begin operation. - * - * Inputs: - * None - * - * Return Value: - * None - * - ****************************************************************************/ - -void ieee802154_indpool_initialize(void); - -/**************************************************************************** - * Name: ieee802154_ind_allocate - * - * Description: - * The ieee802154_ind_allocate function will get a free meta-data - * structure for use by the IEEE 802.15.4 MAC. - * - * Interrupt handling logic will first attempt to allocate from the - * g_indfree list. If that list is empty, it will attempt to allocate - * from its reserve, g_indfree_irq. If that list is empty, then the - * allocation fails (NULL is returned). - * - * Non-interrupt handler logic will attempt to allocate from g_indfree - * list. If that the list is empty, then the meta-data structure will be - * allocated from the dynamic memory pool. - * - * Inputs: - * None - * - * Return Value: - * A reference to the allocated msg structure. All user fields in this - * structure have been zeroed. On a failure to allocate, NULL is - * returned. - * - ****************************************************************************/ - -FAR struct ieee802154_data_ind_s *ieee802154_ind_allocate(void); - -/**************************************************************************** - * Name: ieee802154_ind_free - * - * Description: - * The ieee802154_ind_free function will return a meta-data structure to - * the free pool of messages if it was a pre-allocated meta-data - * structure. If the meta-data structure was allocated dynamically it will - * be deallocated. - * - * Inputs: - * ind - meta-data structure to free - * - * Return Value: - * None - * - ****************************************************************************/ - -void ieee802154_ind_free(FAR struct ieee802154_data_ind_s *ind); diff --git a/wireless/ieee802154/mac802154.h b/wireless/ieee802154/mac802154.h index 152046b61fe..45f9c3a729d 100644 --- a/wireless/ieee802154/mac802154.h +++ b/wireless/ieee802154/mac802154.h @@ -336,6 +336,71 @@ int mac802154_resp_associate(MACHANDLE mac, int mac802154_resp_orphan(MACHANDLE mac, FAR struct ieee802154_orphan_resp_s *resp); +/**************************************************************************** + * Name: ieee802154_indpool_initialize + * + * Description: + * This function initializes the meta-data allocator. This function must + * be called early in the initialization sequence before any radios + * begin operation. + * + * Inputs: + * None + * + * Return Value: + * None + * + ****************************************************************************/ + +void ieee802154_indpool_initialize(void); + +/**************************************************************************** + * Name: ieee802154_ind_allocate + * + * Description: + * The ieee802154_ind_allocate function will get a free meta-data + * structure for use by the IEEE 802.15.4 MAC. + * + * Interrupt handling logic will first attempt to allocate from the + * g_indfree list. If that list is empty, it will attempt to allocate + * from its reserve, g_indfree_irq. If that list is empty, then the + * allocation fails (NULL is returned). + * + * Non-interrupt handler logic will attempt to allocate from g_indfree + * list. If that the list is empty, then the meta-data structure will be + * allocated from the dynamic memory pool. + * + * Inputs: + * None + * + * Return Value: + * A reference to the allocated msg structure. All user fields in this + * structure have been zeroed. On a failure to allocate, NULL is + * returned. + * + ****************************************************************************/ + +FAR struct ieee802154_data_ind_s *ieee802154_ind_allocate(void); + +/**************************************************************************** + * Name: ieee802154_ind_free + * + * Description: + * The ieee802154_ind_free function will return a meta-data structure to + * the free pool of messages if it was a pre-allocated meta-data + * structure. If the meta-data structure was allocated dynamically it will + * be deallocated. + * + * Inputs: + * ind - meta-data structure to free + * + * Return Value: + * None + * + ****************************************************************************/ + +void ieee802154_ind_free(FAR struct ieee802154_data_ind_s *ind); + #undef EXTERN #ifdef __cplusplus } diff --git a/wireless/ieee802154/mac802154_indalloc.c b/wireless/ieee802154/mac802154_indalloc.c index 86d8dcd0ef9..5e05c5c09ed 100644 --- a/wireless/ieee802154/mac802154_indalloc.c +++ b/wireless/ieee802154/mac802154_indalloc.c @@ -43,6 +43,9 @@ #include #include + +#include + #include #include "mac802154.h" @@ -72,6 +75,21 @@ #define POOL_IND_IRQ 1 #define POOL_IND_DYNAMIC 2 +/**************************************************************************** + * Private Data Types + ****************************************************************************/ + +/* Private data type that extends the ieee802154_data_ind_s struct */ + +struct ieee802154_priv_ind_s +{ + /* Must be first member so we can cast to/from */ + + struct ieee802154_data_ind_s pub; + FAR struct ieee802154_priv_ind_s *flink; + uint8_t pool; +}; + /**************************************************************************** * Private Data ****************************************************************************/ @@ -83,7 +101,7 @@ * item. */ -static struct ieee802154_data_ind_s *g_indfree; +static struct ieee802154_priv_ind_s *g_indfree; #endif #if CONFIG_IEEE802154_IND_IRQRESERVE > 0 @@ -91,12 +109,12 @@ static struct ieee802154_data_ind_s *g_indfree; * use by only by interrupt handlers. */ -static struct ieee802154_data_ind_s *g_indfree_irq; +static struct ieee802154_priv_ind_s *g_indfree_irq; #endif /* Pool of pre-allocated meta-data stuctures */ -static struct ieee802154_data_ind_s g_indpool[CONFIG_IEEE802154_IND_PREALLOC]; +static struct ieee802154_priv_ind_s g_indpool[CONFIG_IEEE802154_IND_PREALLOC]; #endif /* CONFIG_IEEE802154_IND_PREALLOC > 0 */ /**************************************************************************** @@ -122,7 +140,7 @@ static struct ieee802154_data_ind_s g_indpool[CONFIG_IEEE802154_IND_PREALLOC]; void ieee802154_indpool_initialize(void) { #if CONFIG_IEEE802154_IND_PREALLOC > 0 - FAR struct ieee802154_data_ind_s *pool = g_indpool; + FAR struct ieee802154_priv_ind_s *pool = g_indpool; int remaining = CONFIG_IEEE802154_IND_PREALLOC; #if CONFIG_IEEE802154_IND_PREALLOC > CONFIG_IEEE802154_IND_IRQRESERVE @@ -133,7 +151,7 @@ void ieee802154_indpool_initialize(void) g_indfree = NULL; while (remaining > CONFIG_IEEE802154_IND_IRQRESERVE) { - FAR struct ieee802154_data_ind_s *ind = pool; + FAR struct ieee802154_priv_ind_s *ind = pool; /* Add the next meta data structure from the pool to the list of * general structures. @@ -157,7 +175,7 @@ void ieee802154_indpool_initialize(void) g_indfree_irq = NULL; while (remaining > 0) { - FAR struct ieee802154_data_ind_s *ind = pool; + FAR struct ieee802154_priv_ind_s *ind = pool; /* Add the next meta data structure from the pool to the list of * general structures. @@ -204,7 +222,7 @@ void ieee802154_indpool_initialize(void) FAR struct ieee802154_data_ind_s *ieee802154_ind_allocate(void) { #if CONFIG_IEEE802154_IND_PREALLOC > 0 - FAR struct ieee802154_data_ind_s *ind; + FAR struct ieee802154_priv_ind_s *ind; irqstate_t flags; uint8_t pool; @@ -271,8 +289,8 @@ FAR struct ieee802154_data_ind_s *ieee802154_ind_allocate(void) */ leave_critical_section(flags); - ind = (FAR struct ieee802154_data_ind_s *) - kmm_malloc((sizeof (struct ieee802154_data_ind_s))); + ind = (FAR struct ieee802154_priv_ind_s *) + kmm_malloc((sizeof (struct ieee802154_priv_ind_s))); /* Check if we allocated the meta-data structure */ @@ -289,9 +307,27 @@ FAR struct ieee802154_data_ind_s *ieee802154_ind_allocate(void) * Zero and tag the alloated meta-data structure. */ - memset(ind, 0, sizeof(struct ieee802154_data_ind_s)); ind->pool = pool; - return ind; + memset(&ind->pub, 0, sizeof(struct ieee802154_data_ind_s)); + + /* Allocate the IOB for the frame */ + + ind->pub.frame = iob_alloc(true); + if (ind->pub.frame == NULL) + { + /* Deallocate the ind */ + + ieee802154_ind_free(&ind->pub); + + return NULL; + } + + ind->pub.frame->io_flink = NULL; + ind->pub.frame->io_len = 0; + ind->pub.frame->io_offset = 0; + ind->pub.frame->io_pktlen = 0; + + return &ind->pub; #else return NULL; #endif @@ -318,21 +354,33 @@ void ieee802154_ind_free(FAR struct ieee802154_data_ind_s *ind) { #if CONFIG_IEEE802154_IND_PREALLOC > 0 irqstate_t flags; + FAR struct ieee802154_priv_ind_s *priv = + (FAR struct ieee802154_priv_ind_s *)ind; + + /* Check if the IOB is not NULL. The only time it should be NULL is if we + * allocated the data_ind, but the IOB allocation failed so we now have to + * free the data_ind but not the IOB. This really should happen rarely if at all. + */ + + if (ind->frame != NULL) + { + iob_free(ind->frame); + } #if CONFIG_IEEE802154_IND_PREALLOC > CONFIG_IEEE802154_IND_IRQRESERVE /* If this is a generally available pre-allocated meta-data structure, * then just put it back in the free list. */ - if (ind->pool == POOL_IND_GENERAL) + if (priv->pool == POOL_IND_GENERAL) { /* Make sure we avoid concurrent access to the free * list from interrupt handlers. */ flags = enter_critical_section(); - ind->flink = g_indfree; - g_indfree = ind; + priv->flink = g_indfree; + g_indfree = priv; leave_critical_section(flags); } else @@ -343,15 +391,15 @@ void ieee802154_ind_free(FAR struct ieee802154_data_ind_s *ind) * then put it back in the correct free list. */ - if (ind->pool == POOL_IND_IRQ) + if (priv->pool == POOL_IND_IRQ) { /* Make sure we avoid concurrent access to the free * list from interrupt handlers. */ flags = enter_critical_section(); - ind->flink = g_indfree_irq; - g_indfree_irq = ind; + priv->flink = g_indfree_irq; + g_indfree_irq = priv; leave_critical_section(flags); } else @@ -360,8 +408,8 @@ void ieee802154_ind_free(FAR struct ieee802154_data_ind_s *ind) { /* Otherwise, deallocate it. */ - DEBUGASSERT(ind->pool == POOL_IND_DYNAMIC); - sched_kfree(ind); + DEBUGASSERT(priv->pool == POOL_IND_DYNAMIC); + sched_kfree(priv); } #endif } From a19a44ad3d12bc6b99fb006a09c043a363aaee78 Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Sat, 6 May 2017 10:20:10 -0400 Subject: [PATCH 164/183] wireless/ieee802154: Completes Rx data flow through MAC layer to callback --- .../wireless/ieee802154/ieee802154_mac.h | 2 +- wireless/ieee802154/mac802154.c | 227 +++++++++++++++++- 2 files changed, 221 insertions(+), 8 deletions(-) diff --git a/include/nuttx/wireless/ieee802154/ieee802154_mac.h b/include/nuttx/wireless/ieee802154/ieee802154_mac.h index fc9818212e1..0d10b532164 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_mac.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_mac.h @@ -1322,7 +1322,7 @@ union ieee802154_mlme_notify_u union ieee802154_mcps_notify_u { struct ieee802154_data_conf_s dataconf; - struct ieee802154_data_ind_s dataind; + struct ieee802154_data_ind_s *dataind; }; /* A pointer to this structure is passed as the argument of each IOCTL diff --git a/wireless/ieee802154/mac802154.c b/wireless/ieee802154/mac802154.c index 127eae9d4f6..cc6e4415b71 100644 --- a/wireless/ieee802154/mac802154.c +++ b/wireless/ieee802154/mac802154.c @@ -150,8 +150,8 @@ struct ieee802154_privmac_s struct ieee802154_txdesc_s txdesc[CONFIG_IEEE802154_NTXDESC]; /* Support a singly linked list of frames received */ - FAR struct ieee802154_data_ind_s *rxframes_head; - FAR struct ieee802154_data_ind_s *rxframes_tail; + FAR struct ieee802154_data_ind_s *dataind_head; + FAR struct ieee802154_data_ind_s *dataind_tail; /* MAC PIB attributes, grouped to save memory */ @@ -392,6 +392,7 @@ static FAR struct mac802154_txframe_s * /* Get the transaction from the head of the list */ trans = priv->csma_head; + trans->flink = NULL; /* Move the head pointer to the next transaction */ @@ -407,6 +408,79 @@ static FAR struct mac802154_txframe_s * return trans; } +/**************************************************************************** + * Name: mac802154_push_rxframe + * + * Description: + * Push a data indication onto the list to be processed + * + ****************************************************************************/ + +static void mac802154_push_dataind(FAR struct ieee802154_privmac_s *priv, + FAR struct ieee802154_data_ind_s *ind) +{ + /* Ensure the forward link is NULL */ + + ind->flink = NULL; + + /* If the tail is not empty, make the frame pointed to by the tail, + * point to the new data indication */ + + if (priv->dataind_tail != NULL) + { + priv->dataind_tail->flink = ind; + } + + /* Point the tail at the new frame */ + + priv->dataind_tail = ind; + + /* If the head is NULL, we need to point it at the data indication since there + * is only one indication in the list at this point */ + + if (priv->dataind_head == NULL) + { + priv->dataind_head = ind; + } +} + +/**************************************************************************** + * Name: mac802154_pop_dataind + * + * Description: + * Pop a data indication from the list + * + ****************************************************************************/ + +static FAR struct ieee802154_data_ind_s * + mac802154_pop_dataind(FAR struct ieee802154_privmac_s *priv) +{ + FAR struct ieee802154_data_ind_s *ind; + + if (priv->dataind_head == NULL) + { + return NULL; + } + + /* Get the data indication from the head of the list */ + + ind = priv->dataind_head; + ind->flink = NULL; + + /* Move the head pointer to the next data indication */ + + priv->dataind_head = ind->flink; + + /* If the head is now NULL, the list is empty, so clear the tail too */ + + if (priv->dataind_head == NULL) + { + priv->dataind_tail = NULL; + } + + return ind; +} + /**************************************************************************** * Name: mac802154_defaultmib * @@ -707,8 +781,7 @@ static void mac802154_rxframe(FAR const struct ieee802154_radiocb_s *radiocb, /* Push the iob onto the tail of the frame list for processing */ - priv->rxframes_tail->flink = ind; - priv->rxframes_tail = ind; + mac802154_push_dataind(priv, ind); mac802154_givesem(&priv->exclsem); @@ -736,10 +809,150 @@ static void mac802154_rxframe_worker(FAR void *arg) { FAR struct ieee802154_privmac_s *priv = (FAR struct ieee802154_privmac_s *)arg; + FAR struct ieee802154_data_ind_s *ind; + union ieee802154_mcps_notify_u mcps_notify; + FAR struct iob_s *frame; + uint16_t *frame_ctrl; + bool panid_comp; - /* The radio layer is responsible for handling all ACKs and retries. If for - * some reason an ACK gets here, just throw it out. - */ + while(1) + { + /* Get exclusive access to the driver structure. We don't care about any + * signals so if we see one, just go back to trying to get access again. + */ + + while (mac802154_takesem(&priv->exclsem) != 0); + + /* Push the iob onto the tail of the frame list for processing */ + + ind = mac802154_pop_dataind(priv); + + if (ind == NULL) + { + mac802154_givesem(&priv->exclsem); + break; + } + + /* Once we pop off the indication, we don't need to keep the mac locked */ + + mac802154_givesem(&priv->exclsem); + + /* Get a local copy of the frame to make it easier to access */ + + frame = iob->frame; + + /* Set a local pointer to the frame control then move the offset past + * the frame control field + */ + + frame_ctrl = (uint16_t *)&frame->io_data[frame->io_offset]; + frame->io_offset += 2; + + /* We use the data_ind_s as a container for the frame information even if + * this isn't a data frame + */ + + ind->src.mode = (frame_ctrl & IEEE802154_FRAMECTRL_SADDR) >> + IEEE802154_FRAMECTRL_SHIFT_SADDR; + + ind->dest.mode = (frame_ctrl & IEEE802154_FRAMECTRL_DADDR) >> + IEEE802154_FRAMECTRL_SHIFT_DADDR; + + panid_comp = (frame_ctrl & IEEE802154_FRAMECTRL_PANIDCOMP) >> + IEEE802154_FRAMECTRL_SHIFT_PANIDCOMP; + + ind->dsn = iob->frame->io_data[frame->io_offset++]; + + /* If the destination address is included */ + + if (ind->dest.mode != IEEE802154_ADDRMODE_NONE) + { + /* Get the destination PAN ID */ + + ind->dest.panid = frame->io_data[frame->io_offset]; + frame->io_offset += 2; + + if (ind->dest.mode == IEEE802154_ADDRMODE_SHORT) + { + ind->dest.saddr = frame->io_data[frame->io_offset]; + frame->io_offset += 2; + } + else if (ind->dest.mode == IEEE802154_ADDRMODE_EXTENDED) + { + memcpy(&ind->dest.eaddr[0], frame->io_data[frame->io_offset], + IEEE802154_EADDR_LEN); + frame->io_offset += 8; + } + } + + if (ind->src.mode != IEEE802154_ADDRMODE_NONE) + { + /* If the source address is included, and the PAN ID compression field + * is set, get the PAN ID from the header. + */ + + if (!panid_comp) + { + ind->src.panid = frame->io_data[frame->io_offset]; + frame->io_offset += 2; + } + + /* If the source address is included, and the PAN ID compression field + * is set, the source PAN ID is the same as the destination PAN ID + */ + + else + { + ind->src.panid = ind->dest.panid; + } + + if (ind->src.mode == IEEE802154_ADDRMODE_SHORT) + { + ind->src.saddr = frame->io_data[frame->io_offset]; + frame->io_offset += 2; + } + else if (ind->src.mode == IEEE802154_ADDRMODE_EXTENDED) + { + memcpy(&ind->src.eaddr[0], frame->io_data[frame->io_offset], + IEEE802154_EADDR_LEN); + frame->io_offset += 8; + } + } + + if (frame_ctrl & IEEE802154_FRAMECTRL_FTYPE == IEEE802154_FRAME_DATA) + { + /* If there is a registered MCPS callback receiver registered, send + * the frame, otherwise, throw it out. + */ + + if (priv->cb->mcps_notify != NULL) + { + mcps_notify.dataind = ind; + priv->cb->mcps_notify(priv->cb, IEEE802154_NOTIFY_IND_DATA, + mcps_notify); + } + else + { + /* Free the data indication struct from the pool */ + + ieee802154_ind_free(ind); + } + } + else if (frame_ctrl & IEEE802154_FRAMECTRL_FTYPE == IEEE802154_FRAME_COMMAND) + { + + } + else if (frame_ctrl & IEEE802154_FRAMECTRL_FTYPE == IEEE802154_FRAME_BEACON) + { + + } + else + { + /* The radio layer is responsible for handling all ACKs and retries. If for + * some reason an ACK gets here, just throw it out. + */ + } + } } /**************************************************************************** From 5d6da5f4bb3296c42fd0ebdc34639a8b756bff88 Mon Sep 17 00:00:00 2001 From: David Sidrane Date: Sat, 6 May 2017 04:52:48 -1000 Subject: [PATCH 165/183] kinetis:Add ARCH_HAVE_I2CRESET --- arch/arm/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index c71fc987736..c8964e3c813 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -76,6 +76,7 @@ config ARCH_CHIP_KINETIS select ARCH_HAVE_FPU select ARCH_HAVE_RAMFUNCS select ARCH_HAVE_CMNVECTOR + select ARCH_HAVE_I2CRESET ---help--- Freescale Kinetis Architectures (ARM Cortex-M4) From b62ef579c8f3b96b3939d6879dd4669089055f32 Mon Sep 17 00:00:00 2001 From: David Sidrane Date: Sat, 6 May 2017 05:16:21 -1000 Subject: [PATCH 166/183] stm32: serial Allow configuring Rx DMA buffer size --- arch/arm/src/stm32/Kconfig | 13 +++++++++++++ arch/arm/src/stm32/stm32_serial.c | 8 ++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/arch/arm/src/stm32/Kconfig b/arch/arm/src/stm32/Kconfig index e36b54673e4..a74bfafc593 100644 --- a/arch/arm/src/stm32/Kconfig +++ b/arch/arm/src/stm32/Kconfig @@ -6165,6 +6165,19 @@ if STM32_SERIALDRIVER comment "Serial Driver Configuration" +config STM32_SERIAL_RXDMA_BUFFER_SIZE + int "Rx DMA buffer size" + default 32 + range 32 4096 + depends on USART1_RXDMA || USART2_RXDMA || USART3_RXDMA || UART4_RXDMA || UART5_RXDMA || USART6_RXDMA || UART7_RXDMA || UART8_RXDMA + ---help--- + The DMA buffer size when using RX DMA to emulate a FIFO. + + When streaming data, the generic serial layer will be called + every time the FIFO receives half or this number of bytes. + + Value given here will be rounded up to next multiple of 4 bytes. + config SERIAL_DISABLE_REORDERING bool "Disable reordering of ttySx devices." depends on STM32_USART1 || STM32_USART2 || STM32_USART3 || STM32_UART4 || STM32_UART5 || STM32_USART6 || STM32_UART7 || STM32_UART8 diff --git a/arch/arm/src/stm32/stm32_serial.c b/arch/arm/src/stm32/stm32_serial.c index 6b6161f0ce4..04dcde479e6 100644 --- a/arch/arm/src/stm32/stm32_serial.c +++ b/arch/arm/src/stm32/stm32_serial.c @@ -182,8 +182,12 @@ * When streaming data, the generic serial layer will be called * every time the FIFO receives half this number of bytes. */ - -# define RXDMA_BUFFER_SIZE 32 +# if !defined(CONFIG_STM32_SERIAL_RXDMA_BUFFER_SIZE) +# define CONFIG_STM32_SERIAL_RXDMA_BUFFER_SIZE 32 +# endif +# define RXDMA_MUTIPLE 4 +# define RXDMA_BUFFER_SIZE ((CONFIG_STM32_SERIAL_RXDMA_BUFFER_SIZE \ + + RXDMA_MUTIPLE) & ~RXDMA_MUTIPLE) /* DMA priority */ From 606255374820059331aa35a128d5ef4ed539335d Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 6 May 2017 09:38:26 -0600 Subject: [PATCH 167/183] Refresh a configuration --- configs/photon/wlan/defconfig | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/configs/photon/wlan/defconfig b/configs/photon/wlan/defconfig index a616dd914f1..5f6b7e3ec79 100644 --- a/configs/photon/wlan/defconfig +++ b/configs/photon/wlan/defconfig @@ -16,7 +16,7 @@ CONFIG_HOST_LINUX=y # # Build Configuration # -CONFIG_APPS_DIR="../apps" +# CONFIG_APPS_DIR="../apps" CONFIG_BUILD_FLAT=y # CONFIG_BUILD_2PASS is not set @@ -1595,4 +1595,3 @@ CONFIG_WIRELESS_WAPI=y CONFIG_WIRELESS_WAPI_CMDTOOL=y CONFIG_WIRELESS_WAPI_STACKSIZE=2048 CONFIG_WIRELESS_WAPI_PRIORITY=100 -CONFIG_WIRELESS_WEXT=y From 5e81391d791d9e0d77941ab87c8a3b165df74052 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 6 May 2017 11:25:39 -0600 Subject: [PATCH 168/183] Update a configuration. --- configs/photon/wlan/defconfig | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/configs/photon/wlan/defconfig b/configs/photon/wlan/defconfig index 5f6b7e3ec79..1892e56c10d 100644 --- a/configs/photon/wlan/defconfig +++ b/configs/photon/wlan/defconfig @@ -1552,6 +1552,16 @@ CONFIG_NSH_DRIPADDR=0xc0a80001 CONFIG_NSH_NETMASK=0xffffff00 # CONFIG_NSH_DNS is not set # CONFIG_NSH_NOMAC is not set + +# +# WAPI Configuration +# +CONFIG_NSH_WAPI_STAMODE=2 +CONFIG_NSH_WAPI_AUTHWPA=0x00000004 +CONFIG_NSH_WAPI_CIPHERMODE=0x00000008 +CONFIG_NSH_WAPI_ALG=3 +CONFIG_NSH_WAPI_SSID="myApSSID" +CONFIG_NSH_WAPI_PASSPHRASE="mySSIDpassphrase" CONFIG_NSH_MAX_ROUNDTRIP=20 # CONFIG_NSH_LOGIN is not set # CONFIG_NSH_CONSOLE_LOGIN is not set From c3180720849c9b3338632e8fc95b402b6a1287e8 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 6 May 2017 14:24:06 -0600 Subject: [PATCH 169/183] 6loWPAN: Minor cleanup and re-verification of all compression modes after so menay recent changes. --- net/sixlowpan/sixlowpan_hc06.c | 65 ++++++++++++++++++------------ net/sixlowpan/sixlowpan_hc1.c | 2 +- net/sixlowpan/sixlowpan_internal.h | 35 ++++++++++++---- net/sixlowpan/sixlowpan_utils.c | 18 +++++++-- 4 files changed, 82 insertions(+), 38 deletions(-) diff --git a/net/sixlowpan/sixlowpan_hc06.c b/net/sixlowpan/sixlowpan_hc06.c index 18d3ccf6969..4de177e0a83 100644 --- a/net/sixlowpan/sixlowpan_hc06.c +++ b/net/sixlowpan/sixlowpan_hc06.c @@ -220,7 +220,7 @@ static FAR struct sixlowpan_addrcontext_s * } /**************************************************************************** - * Name: compress_tagaddr and compress_laddr + * Name: comporess_ipaddr, compress_tagaddr, and compress_laddr * * Description: * Uncompress addresses based on a prefix and a postfix with zeroes in @@ -230,20 +230,16 @@ static FAR struct sixlowpan_addrcontext_s * * prefpost takes a byte where the first nibble specify prefix count * and the second postfix count (NOTE: 15/0xf => 16 bytes copy). * + * compress_tagaddr() accepts a remote, variable length, taged MAC address; + * compress_laddr() accepts a local, fixed length MAC address. + * compress_ipaddr() is simply the common logic that does not depend on + * the size of the MAC address. + * ****************************************************************************/ -static uint8_t compress_tagaddr(FAR const net_ipv6addr_t ipaddr, - FAR const struct sixlowpan_tagaddr_s *macaddr, - uint8_t bitpos) +static uint8_t compress_ipaddr(FAR const net_ipv6addr_t ipaddr, uint8_t bitpos) { - ninfo("ipaddr=%p macaddr=%p extended=%u bitpos=%u g_hc06ptr=%p\n", - ipaddr, macaddr, macaddr->extended, bitpos, g_hc06ptr); - - if (sixlowpan_ismacbased(ipaddr, macaddr)) - { - return 3 << bitpos; /* 0-bits */ - } - else if (SIXLOWPAN_IS_IID_16BIT_COMPRESSABLE(ipaddr)) + if (SIXLOWPAN_IS_IID_16BIT_COMPRESSABLE(ipaddr)) { /* Compress IID to 16 bits: xxxx:xxxx:xxxx:xxxx:0000:00ff:fe00:XXXX */ @@ -261,21 +257,38 @@ static uint8_t compress_tagaddr(FAR const net_ipv6addr_t ipaddr, } } -static uint8_t compress_laddr(FAR const net_ipv6addr_t ipaddr, - FAR const struct sixlowpan_addr_s *macaddr, +static uint8_t compress_tagaddr(FAR const net_ipv6addr_t ipaddr, + FAR const struct sixlowpan_tagaddr_s *macaddr, uint8_t bitpos) { - struct sixlowpan_tagaddr_s tagaddr; + ninfo("ipaddr=%p macaddr=%p extended=%u bitpos=%u g_hc06ptr=%p\n", + ipaddr, macaddr, macaddr->extended, bitpos, g_hc06ptr); -#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR - tagaddr.extended = true; - sixlowpan_eaddrcopy(tagaddr.u.eaddr.u8, macaddr->u8); -#else - tagaddr.extended = false; - sixlowpan_saddrcopy(tagaddr.u.saddr.u8, macaddr->u8); -#endif + if (sixlowpan_ismacbased(ipaddr, macaddr)) + { + return 3 << bitpos; /* 0-bits */ + } + else + { + return compress_ipaddr(ipaddr, bitpos); + } +} - return compress_tagaddr(ipaddr, &tagaddr, bitpos); +static uint8_t compress_laddr(FAR const net_ipv6addr_t ipaddr, + FAR const struct sixlowpan_addr_s *macaddr, + uint8_t bitpos) +{ + ninfo("ipaddr=%p macaddr=%p bitpos=%u g_hc06ptr=%p\n", + ipaddr, macaddr, bitpos, g_hc06ptr); + + if (sixlowpan_isaddrbased(ipaddr, macaddr)) + { + return 3 << bitpos; /* 0-bits */ + } + else + { + return compress_ipaddr(ipaddr, bitpos); + } } /**************************************************************************** @@ -642,9 +655,9 @@ void sixlowpan_compresshdr_hc06(FAR struct ieee802154_driver_s *ieee, ipv6->destipaddr[1] == 0 && ipv6->destipaddr[2] == 0 && ipv6->destipaddr[3] == 0) { - iphc1 |= compress_laddr(ipv6->srcipaddr, - &ieee->i_dev.d_mac.ieee802154, - SIXLOWPAN_IPHC_SAM_BIT); + iphc1 |= compress_laddr(ipv6->srcipaddr, + &ieee->i_dev.d_mac.ieee802154, + SIXLOWPAN_IPHC_SAM_BIT); } else { diff --git a/net/sixlowpan/sixlowpan_hc1.c b/net/sixlowpan/sixlowpan_hc1.c index 0168cb653b3..c6b2f4a1379 100644 --- a/net/sixlowpan/sixlowpan_hc1.c +++ b/net/sixlowpan/sixlowpan_hc1.c @@ -129,7 +129,7 @@ void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee, if (ipv6->vtc != 0x60 || ipv6->tcf != 0 || ipv6->flow != 0 || !sixlowpan_islinklocal(ipv6->srcipaddr) || - !sixlowpan_ismacbased(ipv6->srcipaddr, &ieee->i_dev.d_mac.ieee802154) || + !sixlowpan_isaddrbased(ipv6->srcipaddr, &ieee->i_dev.d_mac.ieee802154) || !sixlowpan_islinklocal(ipv6->destipaddr) || !sixlowpan_ismacbased(ipv6->destipaddr, destmac) || (ipv6->proto != IP_PROTO_ICMP6 && ipv6->proto != IP_PROTO_UDP && diff --git a/net/sixlowpan/sixlowpan_internal.h b/net/sixlowpan/sixlowpan_internal.h index cf71100db15..ade3ae1809a 100644 --- a/net/sixlowpan/sixlowpan_internal.h +++ b/net/sixlowpan/sixlowpan_internal.h @@ -528,19 +528,27 @@ int sixlowpan_uncompresshdr_hc1(uint16_t iplen, FAR struct iob_s *iob, #endif /**************************************************************************** - * Name: sixlowpan_islinklocal, sixlowpan_addrfromip, and sixlowpan_ismacbased + * Name: sixlowpan_islinklocal, sixlowpan_addrfromip, and + * sixlowpan_ismacbased * * Description: - * sixlowpan_addrfromip: Extract the IEEE 802.15.14 address from a link - * local IPv6 address. + * sixlowpan_addrfromip(): Extract the IEEE 802.15.14 address from a MAC + * based IPv6 address. sixlowpan_addrfromip() is intended to handle a + * tagged address or any size; sixlowpan_saddrfromip() and + * sixlowpan_eaddrfromip() specifically handle short and extended + * addresses. * - * sixlowpan_islinklocal and sixlowpan_ismacbased will return true for - * address created in this fashion. + * sixlowpan_islinklocal() and sixlowpan_ismacbased() will return true for + * address created in this fashion. sixlowpan_addrfromip() is intended to + * handle a tagged address or any size; sixlowpan_issaddrbased() and + * sixlowpan_iseaddrbased() specifically handle short and extended + * addresses. Local addresses are of a fixed but configurable size and + * sixlowpan_isaddrbased() is for use with such local addresses. * * 128 112 96 80 64 48 32 16 * ---- ---- ---- ---- ---- ---- ---- ---- - * fe80 0000 0000 0000 xxxx 0000 0000 0000 2-byte short address (VALID?) - * fe80 0000 0000 0000 xxxx xxxx xxxx xxxx 8-byte extended address + * fe80 0000 0000 0000 0000 00ff fe00 xxxx 2-byte short address IEEE 48-bit MAC + * fe80 0000 0000 0000 xxxx xxxx xxxx xxxx 8-byte extended address IEEE EUI-64 * ****************************************************************************/ @@ -553,6 +561,19 @@ void sixlowpan_eaddrfromip(const net_ipv6addr_t ipaddr, void sixlowpan_addrfromip(const net_ipv6addr_t ipaddr, FAR struct sixlowpan_tagaddr_s *addr); +bool sixlowpan_issaddrbased(const net_ipv6addr_t ipaddr, + FAR const struct sixlowpan_saddr_s *saddr); +bool sixlowpan_iseaddrbased(const net_ipv6addr_t ipaddr, + FAR const struct sixlowpan_eaddr_s *eaddr); + +#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR +# define sixlowpan_isaddrbased(ipaddr,addr) \ + sixlowpan_iseaddrbased(ipaddr,(FAR struct sixlowpan_eaddr_s *)addr) +#else +# define sixlowpan_isaddrbased(ipaddr,addr) \ + sixlowpan_issaddrbased(ipaddr,(FAR struct sixlowpan_saddr_s *)addr) +#endif + bool sixlowpan_ismacbased(const net_ipv6addr_t ipaddr, FAR const struct sixlowpan_tagaddr_s *addr); diff --git a/net/sixlowpan/sixlowpan_utils.c b/net/sixlowpan/sixlowpan_utils.c index a1d7892a3e3..d04ce878c75 100644 --- a/net/sixlowpan/sixlowpan_utils.c +++ b/net/sixlowpan/sixlowpan_utils.c @@ -71,12 +71,16 @@ * Name: sixlowpan_addrfromip * * Description: - * Extract the IEEE 802.15.4 address from a link local IPv6 address: + * sixlowpan_addrfromip(): Extract the IEEE 802.15.14 address from a MAC + * based IPv6 address. sixlowpan_addrfromip() is intended to handle a + * tagged address or and size; sixlowpan_saddrfromip() and + * sixlowpan_eaddrfromip() specifically handler short and extended + * addresses. * * 128 112 96 80 64 48 32 16 * ---- ---- ---- ---- ---- ---- ---- ---- - * fe80 0000 0000 0000 0000 00ff fe00 xxxx 2-byte short address IEEE 48-bit MAC - * fe80 0000 0000 0000 xxxx xxxx xxxx xxxx 8-byte extended address IEEE EUI-64 + * xxxx 0000 0000 0000 0000 00ff fe00 xxxx 2-byte short address IEEE 48-bit MAC + * xxxx 0000 0000 0000 xxxx xxxx xxxx xxxx 8-byte extended address IEEE EUI-64 * ****************************************************************************/ @@ -119,7 +123,13 @@ void sixlowpan_addrfromip(const net_ipv6addr_t ipaddr, * Name: sixlowpan_ismacbased * * Description: - * Check if the MAC address is encoded in the IP address: + * sixlowpan_ismacbased() will return true for IP addresses formed from + * IEEE802.15.4 MAC addresses. sixlowpan_addrfromip() is intended to + * handle a tagged address or any size; sixlowpan_issaddrbased() and + * sixlowpan_iseaddrbased() specifically handle short and extended + * addresses. Local addresses are of a fixed but configurable size and + * sixlowpan_isaddrbased() is for use with such local addresses. + * * * 128 112 96 80 64 48 32 16 * ---- ---- ---- ---- ---- ---- ---- ---- From e4b71a06bba813396144c3af8639d3d965c650f0 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 6 May 2017 15:18:39 -0600 Subject: [PATCH 170/183] Update the C coding standard. --- Documentation/NuttXCCodingStandard.html | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/Documentation/NuttXCCodingStandard.html b/Documentation/NuttXCCodingStandard.html index f867fb3782a..7d65a766a26 100644 --- a/Documentation/NuttXCCodingStandard.html +++ b/Documentation/NuttXCCodingStandard.html @@ -12,7 +12,7 @@

NuttX C Coding Standard

-

Last Updated: April 18, 2017

+

Last Updated: May 6, 2017

@@ -405,8 +405,11 @@

Line Spacing A single blank line should precede and follow each comment. - The only exception is for the file header block comment that begins on line one; + The only exceptions are (1) for the file header block comment that begins on line one; there is no preceding blank line in that case. + And (2) for conditional compilation. + Conditional compilation should include the conditional logic and all comments associated with the conditional logic. + In this case, the blank line appears before the conditional, not after it.

@@ -416,6 +419,12 @@ a = b; /* set b equal to c */ b = c; + + /* Do the impossible */ + +#ifdef CONFIG_THE_IMPOSSIBLE + the_impossible(); +#endif
@@ -430,6 +439,11 @@ b = c; +#ifdef CONFIG_THE_IMPOSSIBLE + /* Do the impossible */ + + the_impossible(); +#endif
@@ -1611,7 +1625,7 @@ enum xyz_state_e
  • Lowercase Exceptions. - There are3 a few lower case values in NuttX macro names. Such as a lower-case p for a period or decimal point (such as VOLTAGE_3p3V). + There are a few lower case values in NuttX macro names. Such as a lower-case p for a period or decimal point (such as VOLTAGE_3p3V). I have also used lower-case v for a version number (such as CONFIG_NET_IPv6). However, these are exceptions to the rule rather than illustrating a rule.
  • From 47793aa8f8d47abe741ae3b4c27df144d1bf5744 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 7 May 2017 08:47:48 -0600 Subject: [PATCH 171/183] Update ieee802.15.4 network driver so that it compiles cleanly. --- .../wireless/ieee802154/ieee802154_mac.h | 12 +- wireless/ieee802154/mac802154_netdev.c | 557 +++--------------- 2 files changed, 93 insertions(+), 476 deletions(-) diff --git a/include/nuttx/wireless/ieee802154/ieee802154_mac.h b/include/nuttx/wireless/ieee802154/ieee802154_mac.h index 0d10b532164..ff9e2706215 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_mac.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_mac.h @@ -1405,13 +1405,13 @@ enum ieee802154_macnotify_e struct ieee802154_maccb_s { - CODE void (*mlme_notify) (FAR const struct ieee802154_maccb_s *maccb, - enum ieee802154_macnotify_e notif, - FAR const union ieee802154_mlme_notify_u *arg); + CODE void (*mlme_notify)(FAR const struct ieee802154_maccb_s *maccb, + enum ieee802154_macnotify_e notif, + FAR const union ieee802154_mlme_notify_u *arg); - CODE void (*mcps_notify) (FAR const struct ieee802154_maccb_s *maccb, - enum ieee802154_macnotify_e notif, - FAR const union ieee802154_mcps_notify_u *arg); + CODE void (*mcps_notify)(FAR const struct ieee802154_maccb_s *maccb, + enum ieee802154_macnotify_e notif, + FAR const union ieee802154_mcps_notify_u *arg); }; #ifdef __cplusplus diff --git a/wireless/ieee802154/mac802154_netdev.c b/wireless/ieee802154/mac802154_netdev.c index 7016cf71992..d1cd9c97a97 100644 --- a/wireless/ieee802154/mac802154_netdev.c +++ b/wireless/ieee802154/mac802154_netdev.c @@ -51,14 +51,14 @@ #include #include +#include #include #include -#include +#include #include #include #include -#include -#include +#include #include "mac802154.h" @@ -79,11 +79,11 @@ /* Use the selected work queue */ # if defined(CONFIG_IEEE802154_NETDEV_HPWORK) -# define ETHWORK HPWORK +# define WPANWORK HPWORK # elif defined(CONFIG_IEEE802154_NETDEV_LPWORK) -# define ETHWORK LPWORK +# define WPANWORK LPWORK # else -# error Neither CONFIG_IEEE802154_NETDEV_HPWORK nor CONFIG_IEEE802154_NETDEV_LPWORK defined +# error Neither CONFIG_IEEE802154_NETDEV_HPWORK nor CONFIG_IEEE802154_NETDEV_LPWORK defined # endif #endif @@ -97,15 +97,7 @@ /* TX poll delay = 1 seconds. CLK_TCK is the number of clock ticks per second */ -#define skeleton_WDDELAY (1*CLK_TCK) - -/* TX timeout = 1 minute */ - -#define skeleton_TXTIMEOUT (60*CLK_TCK) - -/* This is a helper pointer for accessing the contents of the Ethernet header */ - -#define BUF ((struct eth_hdr_s *)priv->md_dev.d_buf) +#define TXPOLL_WDDELAY (1*CLK_TCK) /**************************************************************************** * Private Types @@ -137,8 +129,6 @@ struct macnet_driver_s MACHANDLE md_mac; /* Contained MAC interface */ bool md_bifup; /* true:ifup false:ifdown */ WDOG_ID md_txpoll; /* TX poll timer */ - WDOG_ID md_txtimeout; /* TX timeout timer */ - struct work_s md_irqwork; /* Defer interupt work to the work queue */ struct work_s md_pollwork; /* Defer poll work to the work queue */ }; @@ -148,36 +138,27 @@ struct macnet_driver_s /* IEE802.15.4 MAC callback functions ***************************************/ -static void macnet_mlme_notify(FAR struct ieee802154_maccb_s *maccb, +static void macnet_mlme_notify(FAR const struct ieee802154_maccb_s *maccb, enum ieee802154_macnotify_e notif, - FAR union ieee802154_mlme_notify_u *arg); - -static void macnet_mcps_notify(FAR struct ieee802154_maccb_s *maccb, + FAR const union ieee802154_mlme_notify_u *arg); +static void macnet_mcps_notify(FAR const struct ieee802154_maccb_s *maccb, enum ieee802154_macnotify_e notif, - FAR union ieee802154_mcps_notify_u *arg); + FAR const union ieee802154_mcps_notify_u *arg); /* Asynchronous confirmations to requests */ static void macnet_conf_data(FAR struct macnet_driver_s *priv, - FAR struct ieee802154_data_conf_s *conf); -static void macnet_conf_purge(FAR struct macnet_driver_s *priv, - FAR struct ieee802154_purge_conf_s *conf); + FAR const struct ieee802154_data_conf_s *conf); static void macnet_conf_associate(FAR struct macnet_driver_s *priv, FAR struct ieee802154_assoc_conf_s *conf); static void macnet_conf_disassociate(FAR struct macnet_driver_s *priv, FAR struct ieee802154_disassoc_conf_s *conf); -static void macnet_conf_get(FAR struct macnet_driver_s *priv, - FAR struct ieee802154_get_conf_s *conf); static void macnet_conf_gts(FAR struct macnet_driver_s *priv, FAR struct ieee802154_gts_conf_s *conf); -static void macnet_conf_reset(FAR struct macnet_driver_s *priv, - FAR struct ieee802154_reset_conf_s *conf); static void macnet_conf_rxenable(FAR struct macnet_driver_s *priv, FAR struct ieee802154_rxenable_conf_s *conf); static void macnet_conf_scan(FAR struct macnet_driver_s *priv, FAR struct ieee802154_scan_conf_s *conf); -static void macnet_conf_set(FAR struct macnet_driver_s *priv, - FAR struct ieee802154_set_conf_s *conf); static void macnet_conf_start(FAR struct macnet_driver_s *priv, FAR struct ieee802154_start_conf_s *conf); static void macnet_conf_poll(FAR struct macnet_driver_s *priv, @@ -205,24 +186,9 @@ static void macnet_ind_syncloss(FAR struct macnet_driver_s *priv, /* Network interface support ************************************************/ /* Common TX logic */ -static int macnet_transmit(FAR struct macnet_driver_s *priv); -static int macnet_txpoll(FAR struct net_driver_s *dev); - -/* Frame transfer */ - -static void macnet_receive(FAR struct macnet_driver_s *priv); -static void macnet_txdone(FAR struct macnet_driver_s *priv); - -static void macnet_transfer_work(FAR void *arg); -static int macnet_transfer(int irq, FAR void *context, FAR void *arg); - -/* Watchdog timer expirations */ - -static void macnet_txtimeout_work(FAR void *arg); -static void macnet_txtimeout_expiry(int argc, wdparm_t arg, ...); - -static void macnet_poll_work(FAR void *arg); -static void macnet_poll_expiry(int argc, wdparm_t arg, ...); +static int macnet_txpoll_callback(FAR struct net_driver_s *dev); +static void macnet_txpoll_work(FAR void *arg); +static void macnet_txpoll_expiry(int argc, wdparm_t arg, ...); /* NuttX callback functions */ @@ -264,12 +230,12 @@ static int macnet_req_data(FAR struct ieee802154_driver_s *netdev, * ****************************************************************************/ -static void macnet_mlme_notify(FAR struct ieee802154_maccb_s *maccb, +static void macnet_mlme_notify(FAR const struct ieee802154_maccb_s *maccb, enum ieee802154_macnotify_e notif, - FAR union ieee802154_mlme_notify_u *arg) + FAR const union ieee802154_mlme_notify_u *arg) { - FAR struct macdev_callback_s *cb = - (FAR struct macdev_callback_s *)maccb; + FAR struct macnet_callback_s *cb = + (FAR struct macnet_callback_s *)maccb; FAR struct macnet_driver_s *priv; DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); @@ -290,13 +256,13 @@ static void macnet_mlme_notify(FAR struct ieee802154_maccb_s *maccb, * ****************************************************************************/ -static void macnet_mcps_notify(FAR struct ieee802154_maccb_s *maccb, +static void macnet_mcps_notify(FAR const struct ieee802154_maccb_s *maccb, enum ieee802154_macnotify_e notif, - FAR union ieee802154_mcps_notify_u *arg) + FAR const union ieee802154_mcps_notify_u *arg) { - FAR struct macdev_callback_s *cb = - (FAR struct macdev_callback_s *)maccb; - FAR struct macdev_driver_s *priv; + FAR struct macnet_callback_s *cb = + (FAR struct macnet_callback_s *)maccb; + FAR struct macnet_driver_s *priv; DEBUGASSERT(cb != NULL && cb->mc_priv != NULL); priv = cb->mc_priv; @@ -309,15 +275,9 @@ static void macnet_mcps_notify(FAR struct ieee802154_maccb_s *maccb, } break; - case IEEE802154_NOTIFY_CONF_PURGE: - { - macnet_conf_purge(priv, &arg->purgeconf); - } - break; - case IEEE802154_NOTIFY_IND_DATA: { - macnet_ind_data(priv, &arg->dataind); + macnet_ind_data(priv, arg->dataind); } break; @@ -335,21 +295,7 @@ static void macnet_mcps_notify(FAR struct ieee802154_maccb_s *maccb, ****************************************************************************/ static void macnet_conf_data(FAR struct macnet_driver_s *priv, - FAR struct ieee802154_data_conf_s *conf) -{ - -} - -/**************************************************************************** - * Name: macnet_conf_purge - * - * Description: - * Data frame was purged - * - ****************************************************************************/ - -static void macnet_conf_purge(FAR struct macnet_driver_s *priv, - FAR struct ieee802154_purge_conf_s *conf) + FAR const struct ieee802154_data_conf_s *conf) { } @@ -382,20 +328,6 @@ static void macnet_conf_disassociate(FAR struct macnet_driver_s *priv, } -/**************************************************************************** - * Name: macnet_conf_get - * - * Description: - * PIB data returned - * - ****************************************************************************/ - -static void macnet_conf_get(FAR struct macnet_driver_s *priv, - FAR struct ieee802154_get_conf_s *conf) -{ - -} - /**************************************************************************** * Name: macnet_conf_gts * @@ -410,20 +342,6 @@ static void macnet_conf_gts(FAR struct macnet_driver_s *priv, } -/**************************************************************************** - * Name: macnet_conf_reset - * - * Description: - * MAC reset completed - * - ****************************************************************************/ - -static void macnet_conf_reset(FAR struct macnet_driver_s *priv, - FAR struct ieee802154_reset_conf_s *conf) -{ - -} - /**************************************************************************** * Name: macnet_conf_rxenable * @@ -450,19 +368,6 @@ static void macnet_conf_scan(FAR struct macnet_driver_s *priv, } -/**************************************************************************** - * Name: macnet_conf_set - * - * Description: - * - ****************************************************************************/ - -static void macnet_conf_set(FAR struct macnet_driver_s *priv, - FAR struct ieee802154_set_conf_s *conf) -{ - -} - /**************************************************************************** * Name: macnet_conf_start * @@ -500,7 +405,23 @@ static void macnet_conf_poll(FAR struct macnet_driver_s *priv, static void macnet_ind_data(FAR struct macnet_driver_s *priv, FAR struct ieee802154_data_ind_s *ind) { + FAR struct iob_s *iob; + /* Extract the IOB containing the frame from the struct ieee802154_data_ind_s */ + + DEBUGASSERT(priv != NULL && ind != NULL && ind->frame != NULL); + iob = ind->frame; + ind->frame = NULL; + + /* Transfer the frame to the network logic */ + + sixlowpan_input(&priv->md_dev, iob, ind); + + /* sixlowpan_input() will free the IOB, but we must free the struct + * ieee802154_data_ind_s container here. + */ + + ieee802154_ind_free(ind); } /**************************************************************************** @@ -600,52 +521,7 @@ static void macnet_ind_syncloss(FAR struct macnet_driver_s *priv, } /**************************************************************************** - * Name: macnet_transmit - * - * Description: - * This function is called from the lower MAC layer when thre radio device - * is ready to accept another outgoing frame. It removes one of the - * previously queued fram IOBs and provides that to the MAC layer. - * - * Parameters: - * priv - Reference to the driver state structure - * - * Returned Value: - * OK on success; a negated errno on failure - * - * Assumptions: - * May or may not be called from an interrupt handler. - * - ****************************************************************************/ - -static int macnet_transmit(FAR struct macnet_driver_s *priv) -{ - /* Cancel the TX timeout watchdog - * - * REVISIT: Is there not a race condition here? Might the TX timeout - * already be queued?. - */ - - wd_cancel(priv->md_txtimeout); - - /* Increment statistics */ - - NETDEV_TXPACKETS(priv->md_dev); - - /* Provide the pre-formatted packet to the radio device (via the lower MAC - * layer). - */ -#warning Missing logic - - /* Setup the TX timeout watchdog (perhaps restarting the timer) */ - - (void)wd_start(priv->md_txtimeout, skeleton_TXTIMEOUT, - macnet_txtimeout_expiry, 1, (wdparm_t)priv); - return OK; -} - -/**************************************************************************** - * Name: macnet_txpoll + * Name: macnet_txpoll_callback * * Description: * The transmitter is available, check if the network has any outgoing @@ -667,7 +543,7 @@ static int macnet_transmit(FAR struct macnet_driver_s *priv) * ****************************************************************************/ -static int macnet_txpoll(FAR struct net_driver_s *dev) +static int macnet_txpoll_callback(FAR struct net_driver_s *dev) { /* If zero is returned, the polling will continue until all connections have * been examined. @@ -677,265 +553,7 @@ static int macnet_txpoll(FAR struct net_driver_s *dev) } /**************************************************************************** - * Name: macnet_receive - * - * Description: - * An interrupt was received indicating the availability of a new RX packet - * - * Parameters: - * priv - Reference to the driver state structure - * - * Returned Value: - * None - * - * Assumptions: - * The network is locked. - * - ****************************************************************************/ - -static void macnet_receive(FAR struct macnet_driver_s *priv) -{ - FAR struct iob_s *iob; - FAR struct iob_s *fptr; - - /* Allocate an IOB to hold the frame */ - - net_lock(); - iob = iob_alloc(false); -#warning Allocated by radio layer, right? - if (iob == NULL) - { - nerr("ERROR: Failed to allocate an IOB\n") - return; - } - - /* Copy the frame data into the IOB. - * REVISIT: Can a copy be avoided? - */ - - fptr = iob->io_data; -#warning Missing logic - - /* Transfer the frame to the network logic */ - - sixlowpan_input(&priv->md_dev, iob, NULL); -} - -/**************************************************************************** - * Name: macnet_txdone - * - * Description: - * An interrupt was received indicating that the last TX packet(s) is done - * - * Parameters: - * priv - Reference to the driver state structure - * - * Returned Value: - * None - * - * Assumptions: - * The network is locked. - * - ****************************************************************************/ - -static void macnet_txdone(FAR struct macnet_driver_s *priv) -{ - int delay; - - /* Check for errors and update statistics */ - - NETDEV_TXDONE(priv->md_dev); - - /* Check if there are pending transmissions */ - - /* If no further transmissions are pending, then cancel the TX timeout and - * disable further Tx interrupts. - */ - - wd_cancel(priv->md_txtimeout); - - /* And disable further TX interrupts. */ - - /* In any event, poll the network for new TX data */ - - (void)devif_poll(&priv->md_dev, macnet_txpoll); -} - -/**************************************************************************** - * Name: macnet_transfer_work - * - * Description: - * Perform interrupt related work from the worker thread - * - * Parameters: - * arg - The argument passed when work_queue() was called. - * - * Returned Value: - * OK on success - * - * Assumptions: - * The network is locked. - * - ****************************************************************************/ - -static void macnet_transfer_work(FAR void *arg) -{ - FAR struct macnet_driver_s *priv = (FAR struct macnet_driver_s *)arg; - - /* Lock the network and serialize driver operations if necessary. - * NOTE: Serialization is only required in the case where the driver work - * is performed on an LP worker thread and where more than one LP worker - * thread has been configured. - */ - - net_lock(); - - /* Process pending Ethernet interrupts */ - - /* Get and clear interrupt status bits */ - - /* Handle interrupts according to status bit settings */ - - /* Check if we received an incoming packet, if so, call macnet_receive() */ - - macnet_receive(priv); - - /* Check if a packet transmission just completed. If so, call macnet_txdone. - * This may disable further Tx interrupts if there are no pending - * transmissions. - */ - - macnet_txdone(priv); - net_unlock(); - - /* Re-enable Ethernet interrupts */ - - up_enable_irq(CONFIG_IEEE802154_NETDEV_IRQ); -} - -/**************************************************************************** - * Name: macnet_transfer - * - * Description: - * Hardware interrupt handler - * - * Parameters: - * irq - Number of the IRQ that generated the interrupt - * context - Interrupt register state save info (architecture-specific) - * - * Returned Value: - * OK on success - * - * Assumptions: - * - ****************************************************************************/ - -static int macnet_transfer(int irq, FAR void *context, FAR void *arg) -{ - FAR struct macnet_driver_s *priv = (FAR struct macnet_driver_s *)arg; - - /* Disable further Ethernet interrupts. Because Ethernet interrupts are - * also disabled if the TX timeout event occurs, there can be no race - * condition here. - */ - - up_disable_irq(CONFIG_IEEE802154_NETDEV_IRQ); - - /* TODO: Determine if a TX transfer just completed */ - - { - /* If a TX transfer just completed, then cancel the TX timeout so - * there will be no race condition between any subsequent timeout - * expiration and the deferred interrupt processing. - */ - - wd_cancel(priv->md_txtimeout); - } - - /* Schedule to perform the interrupt processing on the worker thread. */ - - work_queue(ETHWORK, &priv->md_irqwork, macnet_transfer_work, priv, 0); - return OK; -} - -/**************************************************************************** - * Name: macnet_txtimeout_work - * - * Description: - * Perform TX timeout related work from the worker thread - * - * Parameters: - * arg - The argument passed when work_queue() as called. - * - * Returned Value: - * OK on success - * - * Assumptions: - * The network is locked. - * - ****************************************************************************/ - -static void macnet_txtimeout_work(FAR void *arg) -{ - FAR struct macnet_driver_s *priv = (FAR struct macnet_driver_s *)arg; - - /* Lock the network and serialize driver operations if necessary. - * NOTE: Serialization is only required in the case where the driver work - * is performed on an LP worker thread and where more than one LP worker - * thread has been configured. - */ - - net_lock(); - - /* Increment statistics and dump debug info */ - - NETDEV_TXTIMEOUTS(priv->md_dev); - - /* Then reset the hardware */ - - /* Then poll the network for new XMIT data */ - - (void)devif_poll(&priv->md_dev, macnet_txpoll); - net_unlock(); -} - -/**************************************************************************** - * Name: macnet_txtimeout_expiry - * - * Description: - * Our TX watchdog timed out. Called from the timer interrupt handler. - * The last TX never completed. Reset the hardware and start again. - * - * Parameters: - * argc - The number of available arguments - * arg - The first argument - * - * Returned Value: - * None - * - * Assumptions: - * Global interrupts are disabled by the watchdog logic. - * - ****************************************************************************/ - -static void macnet_txtimeout_expiry(int argc, wdparm_t arg, ...) -{ - FAR struct macnet_driver_s *priv = (FAR struct macnet_driver_s *)arg; - - /* Disable further Ethernet interrupts. This will prevent some race - * conditions with interrupt work. There is still a potential race - * condition with interrupt work that is already queued and in progress. - */ - - up_disable_irq(CONFIG_IEEE802154_NETDEV_IRQ); - - /* Schedule to perform the TX timeout processing on the worker thread. */ - - work_queue(ETHWORK, &priv->md_irqwork, macnet_txtimeout_work, priv, 0); -} - -/**************************************************************************** - * Name: macnet_poll_process + * Name: macnet_txpoll_process * * Description: * Perform the periodic poll. This may be called either from watchdog @@ -951,12 +569,12 @@ static void macnet_txtimeout_expiry(int argc, wdparm_t arg, ...) * ****************************************************************************/ -static inline void macnet_poll_process(FAR struct macnet_driver_s *priv) +static inline void macnet_txpoll_process(FAR struct macnet_driver_s *priv) { } /**************************************************************************** - * Name: macnet_poll_work + * Name: macnet_txpoll_work * * Description: * Perform periodic polling from the worker thread @@ -972,7 +590,7 @@ static inline void macnet_poll_process(FAR struct macnet_driver_s *priv) * ****************************************************************************/ -static void macnet_poll_work(FAR void *arg) +static void macnet_txpoll_work(FAR void *arg) { FAR struct macnet_driver_s *priv = (FAR struct macnet_driver_s *)arg; @@ -995,17 +613,17 @@ static void macnet_poll_work(FAR void *arg) * progress, we will missing TCP time state updates? */ - (void)devif_timer(&priv->md_dev, macnet_txpoll); + (void)devif_timer(&priv->md_dev.i_dev, macnet_txpoll_callback); /* Setup the watchdog poll timer again */ - (void)wd_start(priv->md_txpoll, skeleton_WDDELAY, macnet_poll_expiry, 1, + (void)wd_start(priv->md_txpoll, TXPOLL_WDDELAY, macnet_txpoll_expiry, 1, (wdparm_t)priv); net_unlock(); } /**************************************************************************** - * Name: macnet_poll_expiry + * Name: macnet_txpoll_expiry * * Description: * Periodic timer handler. Called from the timer interrupt handler. @@ -1022,21 +640,21 @@ static void macnet_poll_work(FAR void *arg) * ****************************************************************************/ -static void macnet_poll_expiry(int argc, wdparm_t arg, ...) +static void macnet_txpoll_expiry(int argc, wdparm_t arg, ...) { FAR struct macnet_driver_s *priv = (FAR struct macnet_driver_s *)arg; /* Schedule to perform the interrupt processing on the worker thread. */ - work_queue(ETHWORK, &priv->md_pollwork, macnet_poll_work, priv, 0); + work_queue(WPANWORK, &priv->md_pollwork, macnet_txpoll_work, priv, 0); } /**************************************************************************** * Name: macnet_ifup * * Description: - * NuttX Callback: Bring up the Ethernet interface when an IP address is - * provided + * NuttX Callback: Bring up the IEEE 802.15.4 interface when an IP address + * is provided * * Parameters: * dev - Reference to the NuttX driver state structure @@ -1064,9 +682,10 @@ static int macnet_ifup(FAR struct net_driver_s *dev) dev->d_ipv6addr[6], dev->d_ipv6addr[7]); #endif - /* Initialize PHYs, the Ethernet interface, and setup up Ethernet interrupts */ + /* Initialize PHYs, the IEEE 802.15.4 interface, and setup up IEEE 802.15.4 interrupts */ +#warning Missing logic - /* Instantiate the MAC address from priv->md_dev.d_mac.ether_addr_octet */ + /* Instantiate the MAC address from priv->md_dev.i_dev.d_mac.ether_addr_octet */ #ifdef CONFIG_NET_ICMPv6 /* Set up IPv6 multicast address filtering */ @@ -1076,13 +695,12 @@ static int macnet_ifup(FAR struct net_driver_s *dev) /* Set and activate a timer process */ - (void)wd_start(priv->md_txpoll, skeleton_WDDELAY, macnet_poll_expiry, 1, + (void)wd_start(priv->md_txpoll, TXPOLL_WDDELAY, macnet_txpoll_expiry, 1, (wdparm_t)priv); - /* Enable the Ethernet interrupt */ + /* Enable the IEEE 802.15.4 radio */ priv->md_bifup = true; - up_enable_irq(CONFIG_IEEE802154_NETDEV_IRQ); return OK; } @@ -1107,15 +725,13 @@ static int macnet_ifdown(FAR struct net_driver_s *dev) FAR struct macnet_driver_s *priv = (FAR struct macnet_driver_s *)dev->d_private; irqstate_t flags; - /* Disable the Ethernet interrupt */ + /* Disable interruption */ flags = enter_critical_section(); - up_disable_irq(CONFIG_IEEE802154_NETDEV_IRQ); /* Cancel the TX poll timer and TX timeout timers */ wd_cancel(priv->md_txpoll); - wd_cancel(priv->md_txtimeout); /* Put the EMAC in its reset, non-operational state. This should be * a known configuration that will guarantee the macnet_ifup() always @@ -1166,7 +782,7 @@ static void macnet_txavail_work(FAR void *arg) /* If so, then poll the network for new XMIT data */ - (void)devif_poll(&priv->md_dev, macnet_txpoll); + (void)devif_poll(&priv->md_dev.i_dev, macnet_txpoll_callback); } net_unlock(); @@ -1204,7 +820,7 @@ static int macnet_txavail(FAR struct net_driver_s *dev) { /* Schedule to serialize the poll on the worker thread. */ - work_queue(ETHWORK, &priv->md_pollwork, macnet_txavail_work, priv, 0); + work_queue(WPANWORK, &priv->md_pollwork, macnet_txavail_work, priv, 0); } return OK; @@ -1293,10 +909,10 @@ static void macnet_ipv6multicast(FAR struct macnet_driver_s *priv) /* For ICMPv6, we need to add the IPv6 multicast address * - * For IPv6 multicast addresses, the Ethernet MAC is derived by + * For IPv6 multicast addresses, the IEEE 802.15.4 MAC is derived by * the four low-order octets OR'ed with the MAC 33:33:00:00:00:00, * so for example the IPv6 address FF02:DEAD:BEEF::1:3 would map - * to the Ethernet MAC address 33:33:00:01:00:03. + * to the IEEE 802.15.4 MAC address 33:33:00:01:00:03. * * NOTES: This appears correct for the ICMPv6 Router Solicitation * Message, but the ICMPv6 Neighbor Solicitation message seems to @@ -1321,7 +937,7 @@ static void macnet_ipv6multicast(FAR struct macnet_driver_s *priv) (void)macnet_addmac(dev, mac); #ifdef CONFIG_NET_ICMPv6_AUTOCONF - /* Add the IPv6 all link-local nodes Ethernet address. This is the + /* Add the IPv6 all link-local nodes IEEE 802.15.4 address. This is the * address that we expect to receive ICMPv6 Router Advertisement * packets. */ @@ -1331,7 +947,7 @@ static void macnet_ipv6multicast(FAR struct macnet_driver_s *priv) #endif /* CONFIG_NET_ICMPv6_AUTOCONF */ #ifdef CONFIG_NET_ICMPv6_ROUTER - /* Add the IPv6 all link-local routers Ethernet address. This is the + /* Add the IPv6 all link-local routers IEEE 802.15.4 address. This is the * address that we expect to receive ICMPv6 Router Solicitation * packets. */ @@ -1377,7 +993,8 @@ static int macnet_ioctl(FAR struct net_driver_s *dev, int cmd, if (netmac != NULL) { unsigned long macarg = (unsigned int)((uintptr_t)&netmac->u); - ret = priv->md_mac.macops.ioctl(priv->md_mac, cmd, macarg); + ret = mac802154_ioctl(priv->md_mac, cmd, macarg); + } } @@ -1387,8 +1004,10 @@ static int macnet_ioctl(FAR struct net_driver_s *dev, int cmd, else { - ret = priv->md_mac.macops.ioctl(priv->md_mac, cmd, arg); + ret = mac802154_ioctl(priv->md_mac, cmd, arg); } + + return ret; } #endif @@ -1413,7 +1032,7 @@ static int macnet_get_mhrlen(FAR struct ieee802154_driver_s *netdev, { FAR struct macnet_driver_s *priv; - DEBUGASSERT(netdev != NULL && netdev->i_dev.d_private != NULL && iob != NULL); + DEBUGASSERT(netdev != NULL && netdev->i_dev.d_private != NULL && meta != NULL); priv = (FAR struct macnet_driver_s *)netdev->i_dev.d_private; return mac802154_get_mhrlen(priv->md_mac, meta); @@ -1441,20 +1060,21 @@ static int macnet_req_data(FAR struct ieee802154_driver_s *netdev, FAR struct iob_s *framelist) { FAR struct macnet_driver_s *priv; - struct ieee802154_data_req_s req; FAR struct iob_s *iob; int ret; - DEBUGASSERT(netdev != NULL && netdev->i_dev.d_private != NULL && iob != NULL); + DEBUGASSERT(netdev != NULL && netdev->i_dev.d_private != NULL); priv = (FAR struct macnet_driver_s *)netdev->i_dev.d_private; + DEBUGASSERT(meta != NULL && framelist != NULL); + /* Add the incoming list of frames to the MAC's outgoing queue */ for (iob = framelist; iob != NULL; iob = framelist) { /* Increment statistics */ - NETDEV_RXPACKETS(&priv->lo_ieee.i_dev); + NETDEV_TXPACKETS(&priv->md_dev.i_dev); /* Remove the IOB from the queue */ @@ -1463,15 +1083,13 @@ static int macnet_req_data(FAR struct ieee802154_driver_s *netdev, /* Transfer the frame to the MAC */ - req.meta = mets; - req.frame = iob; - ret = mac802154_req_data(priv->md_mac, req); + ret = mac802154_req_data(priv->md_mac, meta, iob); if (ret < 0) { wlerr("ERROR: mac802154_req_data failed: %d\n", ret); iob_free(iob); - for (iob = framelist; ; iob != NULL; iob = framelist) + for (iob = framelist; iob != NULL; iob = framelist) { /* Remove the IOB from the queue and free */ @@ -1533,7 +1151,7 @@ int mac802154netdev_register(MACHANDLE mac) */ pktbuf = (FAR uint8_t *)kmm_malloc(CONFIG_NET_6LOWPAN_MTU + CONFIG_NET_GUARDSIZE); - if (pktbuf == NULL + if (pktbuf == NULL) { nerr("ERROR: Failed to allocate the packet buffer\n"); kmm_free(priv); @@ -1542,7 +1160,7 @@ int mac802154netdev_register(MACHANDLE mac) /* Initialize the driver structure */ - ieee = &priv->lo_ieee; + ieee = &priv->md_dev; dev = &ieee->i_dev; dev->d_buf = pktbuf; /* Single packet buffer */ dev->d_ifup = macnet_ifup; /* I/F up (new IP address) callback */ @@ -1561,9 +1179,8 @@ int mac802154netdev_register(MACHANDLE mac) priv->md_mac = mac; /* Save the MAC interface instance */ priv->md_txpoll = wd_create(); /* Create periodic poll timer */ - priv->md_txtimeout = wd_create(); /* Create TX timeout timer */ - DEBUGASSERT(priv->md_txpoll != NULL && priv->md_txtimeout != NULL); + DEBUGASSERT(priv->md_txpoll != NULL); /* Initialize the Network frame-related callbacks */ @@ -1575,22 +1192,22 @@ int mac802154netdev_register(MACHANDLE mac) priv->md_cb.mc_priv = priv; maccb = &priv->md_cb.mc_cb; - maccb->mlme_notify = macdev_mlme_notify; - maccb->mcps_notify = macdev_mcps_notify; + maccb->mlme_notify = macnet_mlme_notify; + maccb->mcps_notify = macnet_mcps_notify; /* Bind the callback structure */ ret = mac802154_bind(mac, maccb); - if (ret < 0 + if (ret < 0) { nerr("ERROR: Failed to bind the MAC callbacks: %d\n", ret); /* Release wdog timers */ wd_delete(priv->md_txpoll); - wd_delete(priv->md_txtimeout); /* Free memory and return the error */ + kmm_free(pktbuf); kmm_free(priv); return ret; @@ -1602,7 +1219,7 @@ int mac802154netdev_register(MACHANDLE mac) /* Register the device with the OS so that socket IOCTLs can be performed */ - (void)netdev_register(&priv->md_dev, NET_LL_IEEE802154); + (void)netdev_register(&priv->md_dev.i_dev, NET_LL_IEEE802154); return OK; } From d785893a65b3fa8435629bea6c554438412339b5 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 7 May 2017 16:58:49 -0600 Subject: [PATCH 172/183] Update some comments. --- net/sixlowpan/sixlowpan_framer.c | 44 ++++++++++---------------- wireless/ieee802154/mac802154_netdev.c | 9 ------ 2 files changed, 17 insertions(+), 36 deletions(-) diff --git a/net/sixlowpan/sixlowpan_framer.c b/net/sixlowpan/sixlowpan_framer.c index 9de555134d9..454d06c407f 100644 --- a/net/sixlowpan/sixlowpan_framer.c +++ b/net/sixlowpan/sixlowpan_framer.c @@ -4,18 +4,6 @@ * Copyright (C) 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * - * Derives from Contiki: - * - * Copyright (c) 2008, Swedish Institute of Computer Science. - * All rights reserved. - * Authors: Adam Dunkels - * Nicolas Tsiftes - * Niclas Finne - * Mathilde Durvy - * Julien Abeille - * Joakim Eriksson - * Joel Hoglund - * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -23,23 +11,25 @@ * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software * without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. * ****************************************************************************/ diff --git a/wireless/ieee802154/mac802154_netdev.c b/wireless/ieee802154/mac802154_netdev.c index d1cd9c97a97..2c53009507a 100644 --- a/wireless/ieee802154/mac802154_netdev.c +++ b/wireless/ieee802154/mac802154_netdev.c @@ -604,15 +604,6 @@ static void macnet_txpoll_work(FAR void *arg) /* Perform the poll */ - /* Check if there is room in the send another TX packet. We cannot perform - * the TX poll if he are unable to accept another packet for transmission. - */ - - /* If so, update TCP timing states and poll the network for new XMIT data. - * Hmmm.. might be bug here. Does this mean if there is a transmit in - * progress, we will missing TCP time state updates? - */ - (void)devif_timer(&priv->md_dev.i_dev, macnet_txpoll_callback); /* Setup the watchdog poll timer again */ From b8ef079951f23d2ea5d02cde2032b0c1dc8706da Mon Sep 17 00:00:00 2001 From: David Sidrane Date: Mon, 8 May 2017 03:43:36 +0000 Subject: [PATCH 173/183] stm32:stm32_serial Forgot the -1 on mask --- arch/arm/src/stm32/stm32_serial.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm/src/stm32/stm32_serial.c b/arch/arm/src/stm32/stm32_serial.c index 04dcde479e6..200c76c43bb 100644 --- a/arch/arm/src/stm32/stm32_serial.c +++ b/arch/arm/src/stm32/stm32_serial.c @@ -187,7 +187,7 @@ # endif # define RXDMA_MUTIPLE 4 # define RXDMA_BUFFER_SIZE ((CONFIG_STM32_SERIAL_RXDMA_BUFFER_SIZE \ - + RXDMA_MUTIPLE) & ~RXDMA_MUTIPLE) + + RXDMA_MUTIPLE) & ~(RXDMA_MUTIPLE-1)) /* DMA priority */ From b0b0c7ac490fe7a694931e5d43096ab391b0abe1 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 8 May 2017 08:34:21 -0600 Subject: [PATCH 174/183] IEEE 802.15.4 network driver. Remove support for multicast address filtering; doesn't work that way on an IEEE 802.15.4 network --- wireless/ieee802154/mac802154_netdev.c | 97 +++----------------------- 1 file changed, 9 insertions(+), 88 deletions(-) diff --git a/wireless/ieee802154/mac802154_netdev.c b/wireless/ieee802154/mac802154_netdev.c index 2c53009507a..f510cf7f5d3 100644 --- a/wireless/ieee802154/mac802154_netdev.c +++ b/wireless/ieee802154/mac802154_netdev.c @@ -205,9 +205,6 @@ static int macnet_addmac(FAR struct net_driver_s *dev, static int macnet_rmmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac); #endif -#ifdef CONFIG_NET_ICMPv6 -static void macnet_ipv6multicast(FAR struct macnet_driver_s *priv); -#endif #endif #ifdef CONFIG_NETDEV_IOCTL static int macnet_ioctl(FAR struct net_driver_s *dev, int cmd, @@ -676,13 +673,7 @@ static int macnet_ifup(FAR struct net_driver_s *dev) /* Initialize PHYs, the IEEE 802.15.4 interface, and setup up IEEE 802.15.4 interrupts */ #warning Missing logic - /* Instantiate the MAC address from priv->md_dev.i_dev.d_mac.ether_addr_octet */ - -#ifdef CONFIG_NET_ICMPv6 - /* Set up IPv6 multicast address filtering */ - - macnet_ipv6multicast(priv); -#endif + /* Setup up address filtering */ /* Set and activate a timer process */ @@ -840,9 +831,11 @@ static int macnet_addmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac) { FAR struct macnet_driver_s *priv = (FAR struct macnet_driver_s *)dev->d_private; - /* Add the MAC address to the hardware multicast routing table */ + /* Add the MAC address to the hardware multicast routing table. Not used + * with IEEE 802.15.4 radios. + */ - return OK; + return -ENOSYS; } #endif @@ -869,86 +862,14 @@ static int macnet_rmmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac) { FAR struct macnet_driver_s *priv = (FAR struct macnet_driver_s *)dev->d_private; - /* Add the MAC address to the hardware multicast routing table */ + /* Remove the MAC address from the hardware multicast routing table Not used + * with IEEE 802.15.4 radios. + */ - return OK; + return -ENOSYS; } #endif -/**************************************************************************** - * Name: macnet_ipv6multicast - * - * Description: - * Configure the IPv6 multicast MAC address. - * - * Parameters: - * priv - A reference to the private driver state structure - * - * Returned Value: - * OK on success; Negated errno on failure. - * - * Assumptions: - * - ****************************************************************************/ - -#ifdef CONFIG_NET_ICMPv6 -static void macnet_ipv6multicast(FAR struct macnet_driver_s *priv) -{ - FAR struct net_driver_s *dev; - uint16_t tmp16; - uint8_t mac[6]; - - /* For ICMPv6, we need to add the IPv6 multicast address - * - * For IPv6 multicast addresses, the IEEE 802.15.4 MAC is derived by - * the four low-order octets OR'ed with the MAC 33:33:00:00:00:00, - * so for example the IPv6 address FF02:DEAD:BEEF::1:3 would map - * to the IEEE 802.15.4 MAC address 33:33:00:01:00:03. - * - * NOTES: This appears correct for the ICMPv6 Router Solicitation - * Message, but the ICMPv6 Neighbor Solicitation message seems to - * use 33:33:ff:01:00:03. - */ - - mac[0] = 0x33; - mac[1] = 0x33; - - dev = &priv->dev; - tmp16 = dev->d_ipv6addr[6]; - mac[2] = 0xff; - mac[3] = tmp16 >> 8; - - tmp16 = dev->d_ipv6addr[7]; - mac[4] = tmp16 & 0xff; - mac[5] = tmp16 >> 8; - - ninfo("IPv6 Multicast: %02x:%02x:%02x:%02x:%02x:%02x\n", - mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); - - (void)macnet_addmac(dev, mac); - -#ifdef CONFIG_NET_ICMPv6_AUTOCONF - /* Add the IPv6 all link-local nodes IEEE 802.15.4 address. This is the - * address that we expect to receive ICMPv6 Router Advertisement - * packets. - */ - - (void)macnet_addmac(dev, g_ipv6_ethallnodes.ether_addr_octet); - -#endif /* CONFIG_NET_ICMPv6_AUTOCONF */ - -#ifdef CONFIG_NET_ICMPv6_ROUTER - /* Add the IPv6 all link-local routers IEEE 802.15.4 address. This is the - * address that we expect to receive ICMPv6 Router Solicitation - * packets. - */ - - (void)macnet_addmac(dev, g_ipv6_ethallrouters.ether_addr_octet); - -#endif /* CONFIG_NET_ICMPv6_ROUTER */ -} -#endif /* CONFIG_NET_ICMPv6 */ - /**************************************************************************** * Name: macnet_ioctl * From 546e7acb99ab2495866d1b0ad0e705a2b0c1ef49 Mon Sep 17 00:00:00 2001 From: David Sidrane Date: Mon, 8 May 2017 15:54:03 +0000 Subject: [PATCH 175/183] stm32:Serial DMA buffer round off not up --- arch/arm/src/stm32/stm32_serial.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/arm/src/stm32/stm32_serial.c b/arch/arm/src/stm32/stm32_serial.c index 200c76c43bb..6425cd2d911 100644 --- a/arch/arm/src/stm32/stm32_serial.c +++ b/arch/arm/src/stm32/stm32_serial.c @@ -186,8 +186,10 @@ # define CONFIG_STM32_SERIAL_RXDMA_BUFFER_SIZE 32 # endif # define RXDMA_MUTIPLE 4 +# define RXDMA_MUTIPLE_MASK (RXDMA_MUTIPLE -1) # define RXDMA_BUFFER_SIZE ((CONFIG_STM32_SERIAL_RXDMA_BUFFER_SIZE \ - + RXDMA_MUTIPLE) & ~(RXDMA_MUTIPLE-1)) + + RXDMA_MUTIPLE_MASK) \ + & ~RXDMA_MUTIPLE_MASK)) /* DMA priority */ From 18eaf52e352930f48b81461ffa9f1bcde5e87b69 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 8 May 2017 10:56:35 -0600 Subject: [PATCH 176/183] 6loWPAN: packet meta data does not need to be a global variable --- net/sixlowpan/sixlowpan_framelist.c | 27 ++++++++++++++------------- net/sixlowpan/sixlowpan_framer.c | 28 +++++++++++++++------------- net/sixlowpan/sixlowpan_globals.c | 14 -------------- net/sixlowpan/sixlowpan_internal.h | 12 +++++------- 4 files changed, 34 insertions(+), 47 deletions(-) diff --git a/net/sixlowpan/sixlowpan_framelist.c b/net/sixlowpan/sixlowpan_framelist.c index 3f208bb388f..697bec1a816 100644 --- a/net/sixlowpan/sixlowpan_framelist.c +++ b/net/sixlowpan/sixlowpan_framelist.c @@ -211,6 +211,7 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, FAR const void *buf, size_t buflen, FAR const struct sixlowpan_tagaddr_s *destmac) { + struct packet_metadata_s pktmeta; struct ieee802154_frame_meta_s meta; FAR struct iob_s *iob; FAR uint8_t *fptr; @@ -232,8 +233,8 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, /* Reset frame meta data */ - memset(&g_packet_meta, 0, sizeof(struct packet_metadata_s)); - g_packet_meta.xmits = CONFIG_NET_6LOWPAN_MAX_MACTRANSMITS; + memset(&pktmeta, 0, sizeof(struct packet_metadata_s)); + pktmeta.xmits = CONFIG_NET_6LOWPAN_MAX_MACTRANSMITS; /* Set stream mode for all TCP packets, except FIN packets. */ @@ -246,11 +247,11 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, if ((tcp->flags & TCP_FIN) == 0 && (tcp->flags & TCP_CTL) != TCP_ACK) { - g_packet_meta.type = FRAME_ATTR_TYPE_STREAM; + pktmeta.type = FRAME_ATTR_TYPE_STREAM; } else if ((tcp->flags & TCP_FIN) == TCP_FIN) { - g_packet_meta.type = FRAME_ATTR_TYPE_STREAM_END; + pktmeta.type = FRAME_ATTR_TYPE_STREAM_END; } } #endif @@ -288,22 +289,22 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, */ #ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR - g_packet_meta.sextended = TRUE; - sixlowpan_eaddrcopy(g_packet_meta.source.eaddr.u8, + pktmeta.sextended = TRUE; + sixlowpan_eaddrcopy(pktmeta.source.eaddr.u8, &ieee->i_dev.d_mac.ieee802154); #else - sixlowpan_saddrcopy(g_packet_meta.source.saddr.u8, + sixlowpan_saddrcopy(pktmeta.source.saddr.u8, &ieee->i_dev.d_mac.ieee802154); #endif if (destmac->extended) { - g_packet_meta.dextended = TRUE; - sixlowpan_eaddrcopy(g_packet_meta.dest.eaddr.u8, destmac->u.eaddr.u8); + pktmeta.dextended = TRUE; + sixlowpan_eaddrcopy(pktmeta.dest.eaddr.u8, destmac->u.eaddr.u8); } else { - sixlowpan_saddrcopy(g_packet_meta.dest.saddr.u8, destmac->u.saddr.u8); + sixlowpan_saddrcopy(pktmeta.dest.saddr.u8, destmac->u.saddr.u8); } /* Get the destination PAN ID. @@ -312,15 +313,15 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee, * PAN IDs are the same. */ - g_packet_meta.dpanid = 0xffff; - (void)sixlowpan_src_panid(ieee, &g_packet_meta.dpanid); + pktmeta.dpanid = 0xffff; + (void)sixlowpan_src_panid(ieee, &pktmeta.dpanid); /* Based on the collected attributes and addresses, construct the MAC meta * data structure that we need to interface with the IEEE802.15.4 MAC (we * will update the MSDU payload size when the IOB has been setup). */ - ret = sixlowpan_meta_data(ieee, &meta, 0); + ret = sixlowpan_meta_data(ieee, &pktmeta, &meta, 0); if (ret < 0) { nerr("ERROR: sixlowpan_meta_data() failed: %d\n", ret); diff --git a/net/sixlowpan/sixlowpan_framer.c b/net/sixlowpan/sixlowpan_framer.c index 454d06c407f..d52a5cd30ca 100644 --- a/net/sixlowpan/sixlowpan_framer.c +++ b/net/sixlowpan/sixlowpan_framer.c @@ -100,7 +100,7 @@ static bool sixlowpan_anyaddrnull(FAR uint8_t *addr, uint8_t addrlen) * ****************************************************************************/ -static inline bool sixlowpan_saddrnull(FAR uint8_t *saddr) +static inline bool sixlowpan_saddrnull(FAR const uint8_t *saddr) { return sixlowpan_anyaddrnull(saddr, NET_6LOWPAN_SADDRSIZE); } @@ -120,7 +120,7 @@ static inline bool sixlowpan_saddrnull(FAR uint8_t *saddr) * ****************************************************************************/ -static inline bool sixlowpan_eaddrnull(FAR uint8_t *eaddr) +static inline bool sixlowpan_eaddrnull(FAR const uint8_t *eaddr) { return sixlowpan_anyaddrnull(eaddr, NET_6LOWPAN_EADDRSIZE); } @@ -137,9 +137,10 @@ static inline bool sixlowpan_eaddrnull(FAR uint8_t *eaddr) * data structure that we need to interface with the IEEE802.15.4 MAC. * * Input Parameters: - * ieee - IEEE 802.15.4 MAC driver state reference. - * meta - Location to return the corresponding meta data. - * paylen - The size of the data payload to be sent. + * ieee - IEEE 802.15.4 MAC driver state reference. + * pktmeta - Meta-data specific to the current outgoing frame + * meta - Location to return the corresponding meta data. + * paylen - The size of the data payload to be sent. * * Returned Value: * Ok is returned on success; Othewise a negated errno value is returned. @@ -150,6 +151,7 @@ static inline bool sixlowpan_eaddrnull(FAR uint8_t *eaddr) ****************************************************************************/ int sixlowpan_meta_data(FAR struct ieee802154_driver_s *ieee, + FAR const struct packet_metadata_s *pktmeta, FAR struct ieee802154_frame_meta_s *meta, uint16_t paylen) { @@ -161,23 +163,23 @@ int sixlowpan_meta_data(FAR struct ieee802154_driver_s *ieee, /* Source address mode */ - meta->src_addr_mode = g_packet_meta.sextended != 0? + meta->src_addr_mode = pktmeta->sextended != 0? IEEE802154_ADDRMODE_EXTENDED : IEEE802154_ADDRMODE_SHORT; /* Check for a broadcast destination address (all zero) */ - if (g_packet_meta.dextended != 0) + if (pktmeta->dextended != 0) { /* Extended destination address mode */ - rcvrnull = sixlowpan_eaddrnull(g_packet_meta.dest.eaddr.u8); + rcvrnull = sixlowpan_eaddrnull(pktmeta->dest.eaddr.u8); } else { /* Short destination address mode */ - rcvrnull = sixlowpan_saddrnull(g_packet_meta.dest.saddr.u8); + rcvrnull = sixlowpan_saddrnull(pktmeta->dest.saddr.u8); } if (rcvrnull) @@ -198,22 +200,22 @@ int sixlowpan_meta_data(FAR struct ieee802154_driver_s *ieee, meta->dest_addr.mode = IEEE802154_ADDRMODE_SHORT; meta->dest_addr.saddr = 0; } - else if (g_packet_meta.dextended != 0) + else if (pktmeta->dextended != 0) { /* Extended destination address mode */ meta->dest_addr.mode = IEEE802154_ADDRMODE_EXTENDED; - sixlowpan_eaddrcopy(&meta->dest_addr.eaddr, g_packet_meta.dest.eaddr.u8); + sixlowpan_eaddrcopy(&meta->dest_addr.eaddr, pktmeta->dest.eaddr.u8); } else { /* Short destination address mode */ meta->dest_addr.mode = IEEE802154_ADDRMODE_SHORT; - sixlowpan_saddrcopy(&meta->dest_addr.saddr, g_packet_meta.dest.saddr.u8); + sixlowpan_saddrcopy(&meta->dest_addr.saddr, pktmeta->dest.saddr.u8); } - meta->dest_addr.panid = g_packet_meta.dpanid; + meta->dest_addr.panid = pktmeta->dpanid; /* Handle associated with MSDU. Will increment once per packet, not * necesarily per frame: The same MSDU handle will be used for each diff --git a/net/sixlowpan/sixlowpan_globals.c b/net/sixlowpan/sixlowpan_globals.c index 7c5740df9e9..6d52082df18 100644 --- a/net/sixlowpan/sixlowpan_globals.c +++ b/net/sixlowpan/sixlowpan_globals.c @@ -67,18 +67,4 @@ uint8_t g_uncomp_hdrlen; uint8_t g_frame_hdrlen; -/* In order to provide a customizable IEEE 802.15.4 MAC header, a structure - * of meta data is passed to the MAC network driver, struct - * ieee802154_frame_meta_s. Many of the settings in this meta data are - * fixed, deterimined by the 6loWPAN configuration. Other settings depend - * on the protocol used in the current packet or on chacteristics of the - * destination node. - * - * The following structure is used to summarize those per-packet - * customizations and, along, with the fixed configuratin settings, - * determines the full form of that meta data. - */ - -struct packet_metadata_s g_packet_meta; - #endif /* CONFIG_NET_6LOWPAN */ diff --git a/net/sixlowpan/sixlowpan_internal.h b/net/sixlowpan/sixlowpan_internal.h index ade3ae1809a..a4dd9b21d0b 100644 --- a/net/sixlowpan/sixlowpan_internal.h +++ b/net/sixlowpan/sixlowpan_internal.h @@ -212,10 +212,6 @@ extern uint8_t g_uncomp_hdrlen; extern uint8_t g_frame_hdrlen; -/* Packet buffer metadata: Attributes and addresses */ - -extern struct packet_metadata_s g_packet_meta; - /**************************************************************************** * Public Types ****************************************************************************/ @@ -278,9 +274,10 @@ int sixlowpan_send(FAR struct net_driver_s *dev, * data structure that we need to interface with the IEEE802.15.4 MAC. * * Input Parameters: - * ieee - IEEE 802.15.4 MAC driver state reference. - * meta - Location to return the corresponding meta data. - * paylen - The size of the data payload to be sent. + * ieee - IEEE 802.15.4 MAC driver state reference. + * pktmeta - Meta-data specific to the current outgoing frame + * meta - Location to return the corresponding meta data. + * paylen - The size of the data payload to be sent. * * Returned Value: * Ok is returned on success; Othewise a negated errno value is returned. @@ -291,6 +288,7 @@ int sixlowpan_send(FAR struct net_driver_s *dev, ****************************************************************************/ int sixlowpan_meta_data(FAR struct ieee802154_driver_s *ieee, + FAR const struct packet_metadata_s *pktmeta, FAR struct ieee802154_frame_meta_s *meta, uint16_t paylen); From aa11d637a88c640b8e970475f8535e1a248fe970 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 8 May 2017 12:33:15 -0600 Subject: [PATCH 177/183] STM32 TIM: Add method to get timer width. Freerun timer: Use timer width to get the correct clock rollover point. --- arch/arm/src/stm32/stm32_freerun.c | 6 ++-- arch/arm/src/stm32/stm32_freerun.h | 1 + arch/arm/src/stm32/stm32_tim.c | 57 ++++++++++++++++++++++++------ arch/arm/src/stm32/stm32_tim.h | 2 ++ 4 files changed, 54 insertions(+), 12 deletions(-) diff --git a/arch/arm/src/stm32/stm32_freerun.c b/arch/arm/src/stm32/stm32_freerun.c index 673b0412d78..f631aa0aa5e 100644 --- a/arch/arm/src/stm32/stm32_freerun.c +++ b/arch/arm/src/stm32/stm32_freerun.c @@ -137,6 +137,7 @@ int stm32_freerun_initialize(struct stm32_freerun_s *freerun, int chan, */ freerun->chan = chan; + freerun->width = STM32_TIM_GETWIDTH(freerun->tch); freerun->running = false; #ifdef CONFIG_CLOCK_TIMEKEEPING @@ -153,7 +154,7 @@ int stm32_freerun_initialize(struct stm32_freerun_s *freerun, int chan, /* Set timer period */ - STM32_TIM_SETPERIOD(freerun->tch, UINT32_MAX); + STM32_TIM_SETPERIOD(freerun->tch, (uint32_t)((1ull << freerun->width) - 1)); /* Start the counter */ @@ -248,7 +249,8 @@ int stm32_freerun_counter(struct stm32_freerun_s *freerun, * usecs = (ticks * USEC_PER_SEC) / frequency; */ - usec = ((((uint64_t)overflow << 32) + (uint64_t)counter) * USEC_PER_SEC) / + usec = ((((uint64_t)overflow << freerun->width) + + (uint64_t)counter) * USEC_PER_SEC) / freerun->frequency; /* And return the value of the timer */ diff --git a/arch/arm/src/stm32/stm32_freerun.h b/arch/arm/src/stm32/stm32_freerun.h index bc7609666cf..b263367d16c 100644 --- a/arch/arm/src/stm32/stm32_freerun.h +++ b/arch/arm/src/stm32/stm32_freerun.h @@ -63,6 +63,7 @@ struct stm32_freerun_s { uint8_t chan; /* The timer/counter in use */ + uint8_t width; /* Width of timer (16- or 32-bits) */ bool running; /* True: the timer is running */ FAR struct stm32_tim_dev_s *tch; /* Handle returned by stm32_tim_init() */ uint32_t frequency; diff --git a/arch/arm/src/stm32/stm32_tim.c b/arch/arm/src/stm32/stm32_tim.c index 55909928270..d4a4ed25599 100644 --- a/arch/arm/src/stm32/stm32_tim.c +++ b/arch/arm/src/stm32/stm32_tim.c @@ -334,22 +334,23 @@ static void stm32_tim_gpioconfig(uint32_t cfg, stm32_tim_channel_t mode); /* Timer methods */ -static int stm32_tim_setmode(FAR struct stm32_tim_dev_s *dev, stm32_tim_mode_t mode); -static int stm32_tim_setclock(FAR struct stm32_tim_dev_s *dev, uint32_t freq); +static int stm32_tim_setmode(FAR struct stm32_tim_dev_s *dev, stm32_tim_mode_t mode); +static int stm32_tim_setclock(FAR struct stm32_tim_dev_s *dev, uint32_t freq); static void stm32_tim_setperiod(FAR struct stm32_tim_dev_s *dev, uint32_t period); static uint32_t stm32_tim_getcounter(FAR struct stm32_tim_dev_s *dev); -static int stm32_tim_setchannel(FAR struct stm32_tim_dev_s *dev, uint8_t channel, - stm32_tim_channel_t mode); -static int stm32_tim_setcompare(FAR struct stm32_tim_dev_s *dev, uint8_t channel, - uint32_t compare); -static int stm32_tim_getcapture(FAR struct stm32_tim_dev_s *dev, uint8_t channel); -static int stm32_tim_setisr(FAR struct stm32_tim_dev_s *dev, xcpt_t handler, - void *arg, int source); +static int stm32_tim_getwidth(FAR struct stm32_tim_dev_s *dev); +static int stm32_tim_setchannel(FAR struct stm32_tim_dev_s *dev, uint8_t channel, + stm32_tim_channel_t mode); +static int stm32_tim_setcompare(FAR struct stm32_tim_dev_s *dev, uint8_t channel, + uint32_t compare); +static int stm32_tim_getcapture(FAR struct stm32_tim_dev_s *dev, uint8_t channel); +static int stm32_tim_setisr(FAR struct stm32_tim_dev_s *dev, xcpt_t handler, + void *arg, int source); static void stm32_tim_enableint(FAR struct stm32_tim_dev_s *dev, int source); static void stm32_tim_disableint(FAR struct stm32_tim_dev_s *dev, int source); static void stm32_tim_ackint(FAR struct stm32_tim_dev_s *dev, int source); -static int stm32_tim_checkint(FAR struct stm32_tim_dev_s *dev, int source); +static int stm32_tim_checkint(FAR struct stm32_tim_dev_s *dev, int source); /************************************************************************************ * Private Data @@ -361,6 +362,7 @@ static const struct stm32_tim_ops_s stm32_tim_ops = .setclock = stm32_tim_setclock, .setperiod = stm32_tim_setperiod, .getcounter = stm32_tim_getcounter, + .getwidth = stm32_tim_getwidth, .setchannel = stm32_tim_setchannel, .setcompare = stm32_tim_setcompare, .getcapture = stm32_tim_getcapture, @@ -904,6 +906,41 @@ static uint32_t stm32_tim_getcounter(FAR struct stm32_tim_dev_s *dev) return stm32_getreg32(dev, STM32_BTIM_CNT_OFFSET); } +/************************************************************************************ + * Name: stm32_tim_getwidth + ************************************************************************************/ + +static int stm32_tim_getwidth(FAR struct stm32_tim_dev_s *dev) +{ + /* Only TIM2 and TIM5 timers may be 32-bits in width + * + * Reference Table 2 of en.DM00042534.pdf + */ + + switch (((struct stm32_tim_priv_s *)dev)->base) + { + /* TIM2 is 32-bits on all except F10x, L0x, and L1x lines */ + +#if defined(CONFIG_STM32_TIM2) && !defined(STM32_STM32F10XX) && \ + !defined(STM32_STM32L15XX) + case STM32_TIM2_BASE: + return 32; +#endif + + /* TIM5 is 32-bits on all except F10x lines */ + +#if defined(CONFIG_STM32_TIM5) && !defined(STM32_STM32F10XX) + case STM32_TIM5_BASE: + return 32; +#endif + + /* All others are 16-bit times */ + + default: + return 16; + } +} + /************************************************************************************ * Name: stm32_tim_setchannel ************************************************************************************/ diff --git a/arch/arm/src/stm32/stm32_tim.h b/arch/arm/src/stm32/stm32_tim.h index 921baebc6c3..5b9422f3ee5 100644 --- a/arch/arm/src/stm32/stm32_tim.h +++ b/arch/arm/src/stm32/stm32_tim.h @@ -61,6 +61,7 @@ #define STM32_TIM_SETCLOCK(d,freq) ((d)->ops->setclock(d,freq)) #define STM32_TIM_SETPERIOD(d,period) ((d)->ops->setperiod(d,period)) #define STM32_TIM_GETCOUNTER(d) ((d)->ops->getcounter(d)) +#define STM32_TIM_GETWIDTH(d) ((d)->ops->getwidth(d)) #define STM32_TIM_SETCHANNEL(d,ch,mode) ((d)->ops->setchannel(d,ch,mode)) #define STM32_TIM_SETCOMPARE(d,ch,comp) ((d)->ops->setcompare(d,ch,comp)) #define STM32_TIM_GETCAPTURE(d,ch) ((d)->ops->getcapture(d,ch)) @@ -166,6 +167,7 @@ struct stm32_tim_ops_s /* General and Advanced Timers Adds */ + int (*getwidth)(FAR struct stm32_tim_dev_s *dev); int (*setchannel)(FAR struct stm32_tim_dev_s *dev, uint8_t channel, stm32_tim_channel_t mode); int (*setcompare)(FAR struct stm32_tim_dev_s *dev, uint8_t channel, From 13f1ba03d5e118cfae03c60361dac88e712e4051 Mon Sep 17 00:00:00 2001 From: Alan Carvalho de Assis Date: Mon, 8 May 2017 13:14:21 -0600 Subject: [PATCH 178/183] Photon: Add README file --- Documentation/README.html | 2 + README.txt | 2 + configs/photon/README.txt | 125 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 129 insertions(+) create mode 100644 configs/photon/README.txt diff --git a/Documentation/README.html b/Documentation/README.html index 727b2f36848..726f4aa3cfc 100644 --- a/Documentation/README.html +++ b/Documentation/README.html @@ -208,6 +208,8 @@ nuttx/ | | `- README.txt | |- pic32mz-starterkit/ | | `- README.txt + | |- photon/ + | | `- README.txt | |- qemu-i486/ | | `- README.txt | |- sabre-6quad/ diff --git a/README.txt b/README.txt index f06800339fe..334b501e514 100644 --- a/README.txt +++ b/README.txt @@ -1580,6 +1580,8 @@ nuttx/ | | `- README.txt | |- pic32mz-starterkit/ | | `- README.txt + | |- photon/ + | | `- README.txt | |- qemu-i486/ | | `- README.txt | |- sabre-6quad/ diff --git a/configs/photon/README.txt b/configs/photon/README.txt new file mode 100644 index 00000000000..779226e6325 --- /dev/null +++ b/configs/photon/README.txt @@ -0,0 +1,125 @@ +README +====== + + This README discusses issues unique to NuttX configurations for the + Particle.io Photon board featuring the STM32F205RG MCU. + The STM32F205RG is a 120 MHz Cortex-M3 operation with 1Mbit Flash + memory and 128kbytes. The board includes a Broadcom BCM43362 WiFi. + +Contents +======== + + - Selecting the Photon board on NuttX + - Configuring NuttX to use your Wireless Router (aka Access Point) + - Flashing NuttX in the Photon board + - Serial console configuration + +Selecting the Photon board on NuttX +=================================== + + NOTICE: We will not discuss about toolchains and environment configuration + here, please take a look at STM32F4Discory board README or other STM32 board + because it should work for Photon board as well. + + Let us to consider that you cloned the nuttx and apps repositories, then + follow these steps: + + 1) Clear your build system before to start: + + $ make apps_distclean + $ make distclean + + 2) Enter inside nuttx/tools and configure to use the Photon board: + + $ cd nuttx + $ cd tools + $ ./configure.sh photon/wlan + + Now please return to root of nuttx/ directory: + + $ cd .. + +Configuring NuttX to use your Wireless Router (aka Access Point) +================================================================ + + Since you are already in the root of nuttx/ repository, execute + make menuconfig to define your Wireless Router and your password: + + $ make menuconfig + + Browser the menus this way: + + Application Configuration ---> + NSH Library ---> + Networking Configuration ---> + WAPI Configuration ---> + (myApSSID) SSID + (mySSIDpassphrase) Passprhase + + Replace the SSID from myApSSID with your wireless router name and + the Passprhase with your WiFi password. + + Exit and save your configuration. + + Finally just compile NuttX: + + $ make + +Flashing NuttX in the Photon board +================================== + + Connect the Photon board in your computer using a MicroUSB cable. Press and + hold both board's buttons (SETUP and RESET), then release the RESET button, + the board will start blinking in the Purple color, waiting until it starts + blinking in Yellow color. Now you can release the SETUP button as well. + + 1) You can verify if DFU mode in your board is working, using this command: + + $ sudo dfu-util -l + dfu-util 0.8 + + Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc. + Copyright 2010-2014 Tormod Volden and Stefan Schmidt + This program is Free Software and has ABSOLUTELY NO WARRANTY + Please report bugs to dfu-util@lists.gnumonks.org + + Found DFU: [2b04:d006] ver=0200, devnum=15, cfg=1, intf=0, alt=1, name="@DCT Flash /0x00000000/01*016Kg", serial="00000000010C" + Found DFU: [2b04:d006] ver=0200, devnum=15, cfg=1, intf=0, alt=0, name="@Internal Flash /0x08000000/03*016Ka,01*016Kg,01*064Kg,07*128Kg", serial="00000000010C" + + 2) Flash the nuttx.bin inside the Internal Flash: + + $ sudo dfu-util -d 2b04:d006 -a 0 -s 0x08020000 -D nuttx.bin + + dfu-util 0.8 + + Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc. + Copyright 2010-2014 Tormod Volden and Stefan Schmidt + This program is Free Software and has ABSOLUTELY NO WARRANTY + Please report bugs to dfu-util@lists.gnumonks.org + + dfu-util: Invalid DFU suffix signature + dfu-util: A valid DFU suffix will be required in a future dfu-util release!!! + Opening DFU capable USB device... + ID 2b04:d006 + Run-time device DFU version 011a + Claiming USB DFU Interface... + Setting Alternate Setting #0 ... + Determining device status: state = dfuIDLE, status = 0 + dfuIDLE, continuing + DFU mode device DFU version 011a + Device returned transfer size 4096 + DfuSe interface name: "Internal Flash " + Downloading to address = 0x08020000, size = 331348 + Download [=========================] 100% 331348 bytes + Download done. + File downloaded successfully + + +Serial console configuration +============================ + + Connect a USB/Serial 3.3V dongle to GND, TX and RX pins of Photon board. + Then use some serial console client (minicom, picocom, teraterm, etc) confi- + gured to 115200 8n1 without software or hardware flow control. + + Reset the board and you should see NuttX starting in the serial. From 2ea6bb4dc13cca3ed61920ce9731f71caac4fd1a Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Mon, 8 May 2017 16:20:35 -0400 Subject: [PATCH 179/183] wireless/ieee802154: Moves ind allocator from mac802154.h to ieee802154_mac.h --- .../wireless/ieee802154/ieee802154_mac.h | 66 +++++++++++++++++++ wireless/ieee802154/mac802154.h | 64 ------------------ 2 files changed, 66 insertions(+), 64 deletions(-) diff --git a/include/nuttx/wireless/ieee802154/ieee802154_mac.h b/include/nuttx/wireless/ieee802154/ieee802154_mac.h index ff9e2706215..8352883acca 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_mac.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_mac.h @@ -1492,6 +1492,72 @@ int mac802154dev_register(MACHANDLE mac, int minor); int mac802154netdev_register(MACHANDLE mac); +/**************************************************************************** + * Name: ieee802154_indpool_initialize + * + * Description: + * This function initializes the meta-data allocator. This function must + * be called early in the initialization sequence before any radios + * begin operation. + * + * Inputs: + * None + * + * Return Value: + * None + * + ****************************************************************************/ + +void ieee802154_indpool_initialize(void); + +/**************************************************************************** + * Name: ieee802154_ind_allocate + * + * Description: + * The ieee802154_ind_allocate function will get a free meta-data + * structure for use by the IEEE 802.15.4 MAC. + * + * Interrupt handling logic will first attempt to allocate from the + * g_indfree list. If that list is empty, it will attempt to allocate + * from its reserve, g_indfree_irq. If that list is empty, then the + * allocation fails (NULL is returned). + * + * Non-interrupt handler logic will attempt to allocate from g_indfree + * list. If that the list is empty, then the meta-data structure will be + * allocated from the dynamic memory pool. + * + * Inputs: + * None + * + * Return Value: + * A reference to the allocated msg structure. All user fields in this + * structure have been zeroed. On a failure to allocate, NULL is + * returned. + * + ****************************************************************************/ + +FAR struct ieee802154_data_ind_s *ieee802154_ind_allocate(void); + +/**************************************************************************** + * Name: ieee802154_ind_free + * + * Description: + * The ieee802154_ind_free function will return a meta-data structure to + * the free pool of messages if it was a pre-allocated meta-data + * structure. If the meta-data structure was allocated dynamically it will + * be deallocated. + * + * Inputs: + * ind - meta-data structure to free + * + * Return Value: + * None + * + ****************************************************************************/ + +void ieee802154_ind_free(FAR struct ieee802154_data_ind_s *ind); + + #undef EXTERN #ifdef __cplusplus } diff --git a/wireless/ieee802154/mac802154.h b/wireless/ieee802154/mac802154.h index 45f9c3a729d..66fa5495cab 100644 --- a/wireless/ieee802154/mac802154.h +++ b/wireless/ieee802154/mac802154.h @@ -336,70 +336,6 @@ int mac802154_resp_associate(MACHANDLE mac, int mac802154_resp_orphan(MACHANDLE mac, FAR struct ieee802154_orphan_resp_s *resp); -/**************************************************************************** - * Name: ieee802154_indpool_initialize - * - * Description: - * This function initializes the meta-data allocator. This function must - * be called early in the initialization sequence before any radios - * begin operation. - * - * Inputs: - * None - * - * Return Value: - * None - * - ****************************************************************************/ - -void ieee802154_indpool_initialize(void); - -/**************************************************************************** - * Name: ieee802154_ind_allocate - * - * Description: - * The ieee802154_ind_allocate function will get a free meta-data - * structure for use by the IEEE 802.15.4 MAC. - * - * Interrupt handling logic will first attempt to allocate from the - * g_indfree list. If that list is empty, it will attempt to allocate - * from its reserve, g_indfree_irq. If that list is empty, then the - * allocation fails (NULL is returned). - * - * Non-interrupt handler logic will attempt to allocate from g_indfree - * list. If that the list is empty, then the meta-data structure will be - * allocated from the dynamic memory pool. - * - * Inputs: - * None - * - * Return Value: - * A reference to the allocated msg structure. All user fields in this - * structure have been zeroed. On a failure to allocate, NULL is - * returned. - * - ****************************************************************************/ - -FAR struct ieee802154_data_ind_s *ieee802154_ind_allocate(void); - -/**************************************************************************** - * Name: ieee802154_ind_free - * - * Description: - * The ieee802154_ind_free function will return a meta-data structure to - * the free pool of messages if it was a pre-allocated meta-data - * structure. If the meta-data structure was allocated dynamically it will - * be deallocated. - * - * Inputs: - * ind - meta-data structure to free - * - * Return Value: - * None - * - ****************************************************************************/ - -void ieee802154_ind_free(FAR struct ieee802154_data_ind_s *ind); #undef EXTERN #ifdef __cplusplus From 2da6f71e84e86b2948e1f8d97f840654887a1a7c Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Mon, 8 May 2017 16:21:29 -0400 Subject: [PATCH 180/183] wireless/ieee802154: Finishes MAC processing of received data frame --- wireless/ieee802154/mac802154.c | 34 ++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/wireless/ieee802154/mac802154.c b/wireless/ieee802154/mac802154.c index cc6e4415b71..1da758082c6 100644 --- a/wireless/ieee802154/mac802154.c +++ b/wireless/ieee802154/mac802154.c @@ -409,7 +409,7 @@ static FAR struct mac802154_txframe_s * } /**************************************************************************** - * Name: mac802154_push_rxframe + * Name: mac802154_push_dataind * * Description: * Push a data indication onto the list to be processed @@ -814,6 +814,7 @@ static void mac802154_rxframe_worker(FAR void *arg) FAR struct iob_s *frame; uint16_t *frame_ctrl; bool panid_comp; + uint8_t ftype; while(1) { @@ -839,7 +840,7 @@ static void mac802154_rxframe_worker(FAR void *arg) /* Get a local copy of the frame to make it easier to access */ - frame = iob->frame; + frame = ind->frame; /* Set a local pointer to the frame control then move the offset past * the frame control field @@ -852,16 +853,16 @@ static void mac802154_rxframe_worker(FAR void *arg) * this isn't a data frame */ - ind->src.mode = (frame_ctrl & IEEE802154_FRAMECTRL_SADDR) >> + ind->src.mode = (*frame_ctrl & IEEE802154_FRAMECTRL_SADDR) >> IEEE802154_FRAMECTRL_SHIFT_SADDR; - ind->dest.mode = (frame_ctrl & IEEE802154_FRAMECTRL_DADDR) >> + ind->dest.mode = (*frame_ctrl & IEEE802154_FRAMECTRL_DADDR) >> IEEE802154_FRAMECTRL_SHIFT_DADDR; - panid_comp = (frame_ctrl & IEEE802154_FRAMECTRL_PANIDCOMP) >> + panid_comp = (*frame_ctrl & IEEE802154_FRAMECTRL_PANIDCOMP) >> IEEE802154_FRAMECTRL_SHIFT_PANIDCOMP; - ind->dsn = iob->frame->io_data[frame->io_offset++]; + ind->dsn = frame->io_data[frame->io_offset++]; /* If the destination address is included */ @@ -879,7 +880,7 @@ static void mac802154_rxframe_worker(FAR void *arg) } else if (ind->dest.mode == IEEE802154_ADDRMODE_EXTENDED) { - memcpy(&ind->dest.eaddr[0], frame->io_data[frame->io_offset], + memcpy(&ind->dest.eaddr[0], &frame->io_data[frame->io_offset], IEEE802154_EADDR_LEN); frame->io_offset += 8; } @@ -913,13 +914,16 @@ static void mac802154_rxframe_worker(FAR void *arg) } else if (ind->src.mode == IEEE802154_ADDRMODE_EXTENDED) { - memcpy(&ind->src.eaddr[0], frame->io_data[frame->io_offset], + memcpy(&ind->src.eaddr[0], &frame->io_data[frame->io_offset], IEEE802154_EADDR_LEN); frame->io_offset += 8; } } + + ftype = (*frame_ctrl & IEEE802154_FRAMECTRL_FTYPE) >> + IEEE802154_FRAMECTRL_SHIFT_FTYPE; - if (frame_ctrl & IEEE802154_FRAMECTRL_FTYPE == IEEE802154_FRAME_DATA) + if (ftype == IEEE802154_FRAME_DATA) { /* If there is a registered MCPS callback receiver registered, send * the frame, otherwise, throw it out. @@ -929,7 +933,7 @@ static void mac802154_rxframe_worker(FAR void *arg) { mcps_notify.dataind = ind; priv->cb->mcps_notify(priv->cb, IEEE802154_NOTIFY_IND_DATA, - mcps_notify); + &mcps_notify); } else { @@ -938,11 +942,11 @@ static void mac802154_rxframe_worker(FAR void *arg) ieee802154_ind_free(ind); } } - else if (frame_ctrl & IEEE802154_FRAMECTRL_FTYPE == IEEE802154_FRAME_COMMAND) + else if (ftype == IEEE802154_FRAME_COMMAND) { } - else if (frame_ctrl & IEEE802154_FRAMECTRL_FTYPE == IEEE802154_FRAME_BEACON) + else if (ftype == IEEE802154_FRAME_BEACON) { } @@ -1023,6 +1027,10 @@ MACHANDLE mac802154_create(FAR struct ieee802154_radio_s *radiodev) radiodev->ops->bind(radiodev, &mac->radiocb.cb); + /* Initialize our data indication pool */ + + ieee802154_indpool_initialize(); + return (MACHANDLE)mac; } @@ -1360,7 +1368,7 @@ int mac802154_req_data(MACHANDLE mac, */ if ((meta->dest_addr.mode == IEEE802154_ADDRMODE_NONE) || - (*frame_ctrl & IEEE802154_FRAMECTRL_PANIDCOMP)) + (!(*frame_ctrl & IEEE802154_FRAMECTRL_PANIDCOMP))) { memcpy(&frame->io_data[mhr_len], &priv->addr.panid, 2); mhr_len += 2; From bbb85332fd766b60b31658da29e6abb1c67853f6 Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Mon, 8 May 2017 16:22:02 -0400 Subject: [PATCH 181/183] wireless/ieee802154: Finishes MAC char driver read functionality --- .../wireless/ieee802154/ieee802154_ioctl.h | 7 + wireless/ieee802154/mac802154_device.c | 234 +++++++++++++++++- 2 files changed, 232 insertions(+), 9 deletions(-) diff --git a/include/nuttx/wireless/ieee802154/ieee802154_ioctl.h b/include/nuttx/wireless/ieee802154/ieee802154_ioctl.h index 6171d0e3a34..5f14f2e2c6e 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_ioctl.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_ioctl.h @@ -81,5 +81,12 @@ struct mac802154dev_txframe_s uint16_t length; }; +struct mac802154dev_rxframe_s +{ + struct ieee802154_data_ind_s meta; + uint8_t payload[IEEE802154_MAX_MAC_PAYLOAD_SIZE]; + uint16_t length; +}; + #endif /* CONFIG_WIRELESS_IEEE802154 */ #endif /* __INCLUDE_NUTTX_WIRELESS_IEEE802154_IEEE802154_IOCTL_H */ diff --git a/wireless/ieee802154/mac802154_device.c b/wireless/ieee802154/mac802154_device.c index 6ea212ae531..a4eb93b6563 100644 --- a/wireless/ieee802154/mac802154_device.c +++ b/wireless/ieee802154/mac802154_device.c @@ -108,6 +108,9 @@ struct mac802154_chardevice_s struct mac802154dev_callback_s md_cb; /* Callback information */ sem_t md_exclsem; /* Exclusive device access */ + bool readpending; /* Is there a read using the semaphore? */ + sem_t readsem; /* Signaling semaphore for waiting read */ + /* The following is a singly linked list of open references to the * MAC device. */ @@ -115,6 +118,11 @@ struct mac802154_chardevice_s FAR struct mac802154dev_open_s *md_open; FAR struct mac802154dev_dwait_s *md_dwait; + /* Hold a list of transactions as a "readahead" buffer */ + + FAR struct ieee802154_data_ind_s *dataind_head; + FAR struct ieee802154_data_ind_s *dataind_tail; + #ifndef CONFIG_DISABLE_SIGNALS /* MCPS Service notification information */ @@ -137,6 +145,12 @@ struct mac802154_chardevice_s static inline int mac802154dev_takesem(sem_t *sem); #define mac802154dev_givesem(s) sem_post(s); +static void mac802154dev_push_dataind(FAR struct mac802154_chardevice_s *dev, + FAR struct ieee802154_data_ind_s *ind); +static FAR struct ieee802154_data_ind_s * + mac802154dev_pop_dataind(FAR struct mac802154_chardevice_s *dev); + + static void mac802154dev_mlme_notify(FAR const struct ieee802154_maccb_s *maccb, enum ieee802154_macnotify_e notif, FAR const union ieee802154_mlme_notify_u *arg); @@ -158,6 +172,8 @@ static int mac802154dev_ioctl(FAR struct file *filep, int cmd, static void mac802154dev_conf_data(FAR struct mac802154_chardevice_s *dev, FAR const struct ieee802154_data_conf_s *conf); +static void mac802154dev_ind_data(FAR struct mac802154_chardevice_s *dev, + FAR struct ieee802154_data_ind_s *ind); /**************************************************************************** * Private Data @@ -207,6 +223,79 @@ static inline int mac802154dev_takesem(sem_t *sem) return OK; } +/**************************************************************************** + * Name: mac802154dev_push_dataind + * + * Description: + * Push a data indication onto the list to be processed + * + ****************************************************************************/ + +static void mac802154dev_push_dataind(FAR struct mac802154_chardevice_s *dev, + FAR struct ieee802154_data_ind_s *ind) +{ + /* Ensure the forward link is NULL */ + + ind->flink = NULL; + + /* If the tail is not empty, make the frame pointed to by the tail, + * point to the new data indication */ + + if (dev->dataind_tail != NULL) + { + dev->dataind_tail->flink = ind; + } + + /* Point the tail at the new frame */ + + dev->dataind_tail = ind; + + /* If the head is NULL, we need to point it at the data indication since there + * is only one indication in the list at this point */ + + if (dev->dataind_head == NULL) + { + dev->dataind_head = ind; + } +} + +/**************************************************************************** + * Name: mac802154dev_pop_dataind + * + * Description: + * Pop a data indication from the list + * + ****************************************************************************/ + +static FAR struct ieee802154_data_ind_s * + mac802154dev_pop_dataind(FAR struct mac802154_chardevice_s *dev) +{ + FAR struct ieee802154_data_ind_s *ind; + + if (dev->dataind_head == NULL) + { + return NULL; + } + + /* Get the data indication from the head of the list */ + + ind = dev->dataind_head; + ind->flink = NULL; + + /* Move the head pointer to the next data indication */ + + dev->dataind_head = ind->flink; + + /* If the head is now NULL, the list is empty, so clear the tail too */ + + if (dev->dataind_head == NULL) + { + dev->dataind_tail = NULL; + } + + return ind; +} + /**************************************************************************** * Name: mac802154dev_open * @@ -368,6 +457,8 @@ static ssize_t mac802154dev_read(FAR struct file *filep, FAR char *buffer, { FAR struct inode *inode; FAR struct mac802154_chardevice_s *dev; + FAR struct mac802154dev_rxframe_s *rx; + FAR struct ieee802154_data_ind_s *ind; int ret; DEBUGASSERT(filep && filep->f_inode); @@ -375,20 +466,94 @@ static ssize_t mac802154dev_read(FAR struct file *filep, FAR char *buffer, DEBUGASSERT(inode->i_private); dev = (FAR struct mac802154_chardevice_s *)inode->i_private; - /* Get exclusive access to the driver structure */ + /* Check to make sure the buffer is the right size for the struct */ - ret = mac802154dev_takesem(&dev->md_exclsem); - if (ret < 0) + if (len != sizeof(struct mac802154dev_rxframe_s)) { - wlerr("ERROR: mac802154dev_takesem failed: %d\n", ret); - return ret; + wlerr("ERROR: buffer isn't a mac802154dev_rxframe_s: %lu\n", + (unsigned long)len); + return -EINVAL; } - /* TODO: Add code to read a packet and return it */ - ret = -ENOTSUP; + DEBUGASSERT(buffer != NULL); + rx = (FAR struct mac802154dev_rxframe_s *)buffer; - mac802154dev_givesem(&dev->md_exclsem); - return ret; + while (1) + { + /* Get exclusive access to the driver structure */ + + ret = mac802154dev_takesem(&dev->md_exclsem); + if (ret < 0) + { + wlerr("ERROR: mac802154dev_takesem failed: %d\n", ret); + return ret; + } + + /* Try popping a data indication off the list */ + + ind = mac802154dev_pop_dataind(dev); + + /* If the indication is not null, we can exit the loop and copy the data */ + + if (ind != NULL) + { + mac802154dev_givesem(&dev->md_exclsem); + break; + } + + /* If this is a non-blocking call, or if there is another read operation + * already pending, don't block. This driver returns EAGAIN even when + * configured as non-blocking if another read operation is already pending + * This situation should be rare. It will only occur when there are 2 calls + * to read from separate threads and there was no data in the rx list. + */ + + if ((filep->f_oflags & O_NONBLOCK) || dev->readpending) + { + mac802154dev_givesem(&dev->md_exclsem); + return -EAGAIN; + } + + dev->readpending = true; + mac802154dev_givesem(&dev->md_exclsem); + + /* Wait to be signaled when a frame is added to the list */ + + if (sem_wait(&dev->readsem) < 0) + { + DEBUGASSERT(errno == EINTR); + /* Need to get exclusive access again to change the pending bool */ + + ret = mac802154dev_takesem(&dev->md_exclsem); + dev->readpending = false; + mac802154dev_givesem(&dev->md_exclsem); + return -EINTR; + } + + /* Let the loop wrap back around, we will then pop a indication and this + * time, it should have a data indication + */ + } + + rx->length = (ind->frame->io_len - ind->frame->io_offset); + + /* Copy the data from the IOB to the user supplied struct */ + + memcpy(&rx->payload[0], &ind->frame->io_data[ind->frame->io_offset], + rx->length); + + memcpy(&rx->meta, ind, sizeof(struct ieee802154_data_ind_s)); + + /* Zero out the forward link and IOB reference */ + + rx->meta.flink = NULL; + rx->meta.frame = NULL; + + /* Deallocate the data indication */ + + ieee802154_ind_free(ind); + + return OK; } /**************************************************************************** @@ -649,6 +814,11 @@ static void mac802154dev_mcps_notify(FAR const struct ieee802154_maccb_s *maccb, mac802154dev_conf_data(dev, &arg->dataconf); } break; + case IEEE802154_NOTIFY_IND_DATA: + { + mac802154dev_ind_data(dev, arg->dataind); + } + break; default: break; } @@ -717,6 +887,48 @@ static void mac802154dev_conf_data(FAR struct mac802154_chardevice_s *dev, #endif } +static void mac802154dev_ind_data(FAR struct mac802154_chardevice_s *dev, + FAR struct ieee802154_data_ind_s *ind) +{ + /* Get exclusive access to the driver structure. We don't care about any + * signals so if we see one, just go back to trying to get access again */ + + while (mac802154dev_takesem(&dev->md_exclsem) != 0); + + /* Push the indication onto the list */ + + mac802154dev_push_dataind(dev, ind); + + /* Check if there is a read waiting for data */ + + if (dev->readpending) + { + /* Wake the thread waiting for the data transmission */ + + dev->readpending = false; + sem_post(&dev->readsem); + } + + /* Release the driver */ + + mac802154dev_givesem(&dev->md_exclsem); + +#ifndef CONFIG_DISABLE_SIGNALS + /* Send a signal to the registered application */ + +#ifdef CONFIG_CAN_PASS_STRUCTS + /* Copy the status as the signal data to be optionally used by app */ + + union sigval value; + value.sival_int = IEEE802154_STATUS_SUCCESS; + (void)sigqueue(dev->md_mcps_pid, dev->md_mcps_notify.mn_signo, value); +#else + (void)sigqueue(dev->md_mcps_pid, dev->md_mcps_notify.mn_signo, + value.sival_ptr); +#endif +#endif +} + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -758,6 +970,10 @@ int mac802154dev_register(MACHANDLE mac, int minor) dev->md_mac = mac; sem_init(&dev->md_exclsem, 0, 1); /* Allow the device to be opened once * before blocking */ + + sem_init(&dev->readsem, 0, 0); + sem_setprotocol(&dev->readsem, SEM_PRIO_NONE); + dev->readpending = false; /* Initialize the MAC callbacks */ From 3fa8e32e3664145a33cd695454dff54778166ae7 Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Mon, 8 May 2017 16:23:09 -0400 Subject: [PATCH 182/183] wireless/ieee802154: MRF24J40: Finishes receive functionality, supports promicuous mode, and rxonidle attributes --- drivers/wireless/ieee802154/mrf24j40.c | 59 +++++++++++-------- .../wireless/ieee802154/ieee802154_mac.h | 2 +- 2 files changed, 37 insertions(+), 24 deletions(-) diff --git a/drivers/wireless/ieee802154/mrf24j40.c b/drivers/wireless/ieee802154/mrf24j40.c index 14c97827772..8283278d3c9 100644 --- a/drivers/wireless/ieee802154/mrf24j40.c +++ b/drivers/wireless/ieee802154/mrf24j40.c @@ -121,6 +121,10 @@ struct mrf24j40_radio_s struct ieee802154_radio_s radio; /* The public device instance */ FAR struct ieee802154_radiocb_s *radiocb; /* Registered callbacks */ + /* MAC Attributes */ + + bool rxonidle : 1; + /* Low-level MCU-specific support */ FAR const struct mrf24j40_lower_s *lower; @@ -186,40 +190,41 @@ static int mrf24j40_setup_fifo(FAR struct mrf24j40_radio_s *dev, FAR struct iob_s *frame, uint32_t fifo_addr); -static int mrf24j40_setchannel(FAR struct mrf24j40_radio_s *radio, +static int mrf24j40_setchannel(FAR struct mrf24j40_radio_s *dev, uint8_t chan); -static int mrf24j40_getchannel(FAR struct mrf24j40_radio_s *radio, +static int mrf24j40_getchannel(FAR struct mrf24j40_radio_s *dev, FAR uint8_t *chan); -static int mrf24j40_setpanid(FAR struct mrf24j40_radio_s *radio, +static int mrf24j40_setpanid(FAR struct mrf24j40_radio_s *dev, uint16_t panid); -static int mrf24j40_getpanid(FAR struct mrf24j40_radio_s *radio, +static int mrf24j40_getpanid(FAR struct mrf24j40_radio_s *dev, FAR uint16_t *panid); -static int mrf24j40_setsaddr(FAR struct mrf24j40_radio_s *radio, +static int mrf24j40_setsaddr(FAR struct mrf24j40_radio_s *dev, uint16_t saddr); -static int mrf24j40_getsaddr(FAR struct mrf24j40_radio_s *radio, +static int mrf24j40_getsaddr(FAR struct mrf24j40_radio_s *dev, FAR uint16_t *saddr); -static int mrf24j40_seteaddr(FAR struct mrf24j40_radio_s *radio, +static int mrf24j40_seteaddr(FAR struct mrf24j40_radio_s *dev, FAR const uint8_t *eaddr); -static int mrf24j40_geteaddr(FAR struct mrf24j40_radio_s *radio, +static int mrf24j40_geteaddr(FAR struct mrf24j40_radio_s *dev, FAR uint8_t *eaddr); -static int mrf24j40_setpromisc(FAR struct mrf24j40_radio_s *radio, +static int mrf24j40_setpromisc(FAR struct mrf24j40_radio_s *dev, bool promisc); -static int mrf24j40_getpromisc(FAR struct mrf24j40_radio_s *radio, +static int mrf24j40_getpromisc(FAR struct mrf24j40_radio_s *dev, FAR bool *promisc); -static int mrf24j40_setdevmode(FAR struct mrf24j40_radio_s *radio, +static int mrf24j40_setdevmode(FAR struct mrf24j40_radio_s *dev, uint8_t mode); -static int mrf24j40_getdevmode(FAR struct mrf24j40_radio_s *radio, +static int mrf24j40_getdevmode(FAR struct mrf24j40_radio_s *dev, FAR uint8_t *mode); -static int mrf24j40_settxpower(FAR struct mrf24j40_radio_s *radio, +static int mrf24j40_settxpower(FAR struct mrf24j40_radio_s *dev, int32_t txpwr); -static int mrf24j40_gettxpower(FAR struct mrf24j40_radio_s *radio, +static int mrf24j40_gettxpower(FAR struct mrf24j40_radio_s *dev, FAR int32_t *txpwr); -static int mrf24j40_setcca(FAR struct mrf24j40_radio_s *radio, +static int mrf24j40_setcca(FAR struct mrf24j40_radio_s *dev, FAR struct ieee802154_cca_s *cca); -static int mrf24j40_getcca(FAR struct mrf24j40_radio_s *radio, +static int mrf24j40_getcca(FAR struct mrf24j40_radio_s *dev, FAR struct ieee802154_cca_s *cca); -static int mrf24j40_energydetect(FAR struct mrf24j40_radio_s *radio, +static int mrf24j40_energydetect(FAR struct mrf24j40_radio_s *dev, FAR uint8_t *energy); +static int mrf24j40_rxenable(FAR struct mrf24j40_radio_s *dev, bool enable); /* Driver operations */ @@ -392,6 +397,12 @@ static int mrf24j40_set_attr(FAR struct ieee802154_radio_s *radio, ret = IEEE802154_STATUS_SUCCESS; } break; + case IEEE802154_PIB_MAC_RX_ON_WHEN_IDLE: + { + dev->rxonidle = attr_value->mac.rxonidle; + mrf24j40_rxenable(dev, dev->rxonidle); + } + break; default: ret = IEEE802154_STATUS_UNSUPPORTED_ATTRIBUTE; } @@ -1470,9 +1481,8 @@ static void mrf24j40_irqwork_txgts(FAR struct mrf24j40_radio_s *dev, * ****************************************************************************/ -static int mrf24j40_rxenable(FAR struct ieee802154_radio_s *radio, bool enable) +static int mrf24j40_rxenable(FAR struct mrf24j40_radio_s *dev, bool enable) { - FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)radio; uint8_t reg; if (enable) @@ -1567,11 +1577,14 @@ done: mrf24j40_setreg(dev->spi, MRF24J40_BBREG1, 0); - /* Enable rx int */ + /* Only enable RX interrupt if we are to be listening when IDLE */ - reg = mrf24j40_getreg(dev->spi, MRF24J40_INTCON); - reg &= ~MRF24J40_INTCON_RXIE; - mrf24j40_setreg(dev->spi, MRF24J40_INTCON, reg); + if (dev->rxonidle) + { + reg = mrf24j40_getreg(dev->spi, MRF24J40_INTCON); + reg &= ~MRF24J40_INTCON_RXIE; + mrf24j40_setreg(dev->spi, MRF24J40_INTCON, reg); + } } /**************************************************************************** diff --git a/include/nuttx/wireless/ieee802154/ieee802154_mac.h b/include/nuttx/wireless/ieee802154/ieee802154_mac.h index 8352883acca..2c6a846af76 100644 --- a/include/nuttx/wireless/ieee802154/ieee802154_mac.h +++ b/include/nuttx/wireless/ieee802154/ieee802154_mac.h @@ -507,7 +507,7 @@ union ieee802154_macattr_u bool promisc_mode; bool rng_support; bool resp_wait_time; - bool rx_when_idle; + bool rxonidle; bool sec_enabled; bool timestamp_support; From 014b69e120c1e6aabd4785b1aff1a8e1e32ca8aa Mon Sep 17 00:00:00 2001 From: David Sidrane Date: Mon, 8 May 2017 22:56:05 +0000 Subject: [PATCH 183/183] removed stray paren. --- arch/arm/src/stm32/stm32_serial.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm/src/stm32/stm32_serial.c b/arch/arm/src/stm32/stm32_serial.c index 6425cd2d911..77c07ea68e0 100644 --- a/arch/arm/src/stm32/stm32_serial.c +++ b/arch/arm/src/stm32/stm32_serial.c @@ -189,7 +189,7 @@ # define RXDMA_MUTIPLE_MASK (RXDMA_MUTIPLE -1) # define RXDMA_BUFFER_SIZE ((CONFIG_STM32_SERIAL_RXDMA_BUFFER_SIZE \ + RXDMA_MUTIPLE_MASK) \ - & ~RXDMA_MUTIPLE_MASK)) + & ~RXDMA_MUTIPLE_MASK) /* DMA priority */