2016-06-01 12:12:21 +02:00
|
|
|
/****************************************************************************
|
2017-07-03 06:33:17 +02:00
|
|
|
* drivers/wireless/ieee802154/at86rf23x/at86rf23x.c
|
2016-06-01 12:12:21 +02:00
|
|
|
*
|
2021-09-01 13:36:03 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2016-06-01 12:12:21 +02:00
|
|
|
*
|
2021-09-01 13:36:03 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2016-06-01 12:12:21 +02:00
|
|
|
*
|
2021-09-01 13:36:03 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2016-06-01 12:12:21 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
2017-03-15 21:57:13 +01:00
|
|
|
|
2016-06-01 12:12:21 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
#include <nuttx/compiler.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include <nuttx/arch.h>
|
|
|
|
#include <nuttx/kmalloc.h>
|
|
|
|
#include <nuttx/wqueue.h>
|
|
|
|
#include <nuttx/fs/fs.h>
|
2020-02-01 08:17:32 +01:00
|
|
|
#include <nuttx/semaphore.h>
|
2016-06-01 12:12:21 +02:00
|
|
|
#include <nuttx/spi/spi.h>
|
|
|
|
|
|
|
|
#include <nuttx/wireless/ieee802154/at86rf23x.h>
|
2017-03-29 18:39:52 +02:00
|
|
|
|
2016-06-01 12:12:21 +02:00
|
|
|
#include <nuttx/wireless/ieee802154/ieee802154_radio.h>
|
|
|
|
|
|
|
|
#include "at86rf23x.h"
|
|
|
|
|
2019-02-27 15:41:08 +01:00
|
|
|
/****************************************************************************
|
2016-06-01 12:12:21 +02:00
|
|
|
* Pre-processor Definitions
|
2019-02-27 15:41:08 +01:00
|
|
|
****************************************************************************/
|
2016-06-01 12:12:21 +02:00
|
|
|
|
|
|
|
#ifndef CONFIG_SCHED_HPWORK
|
2017-03-15 21:16:19 +01:00
|
|
|
# error High priority work queue required in this driver
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_SPI_EXCHANGE
|
|
|
|
# error CONFIG_SPI_EXCHANGE required for this driver
|
2016-06-01 12:12:21 +02:00
|
|
|
#endif
|
|
|
|
|
2019-12-05 18:49:12 +01:00
|
|
|
#ifndef CONFIG_IEEE802154_AT86RF23X_SPIMODE
|
|
|
|
# define CONFIG_IEEE802154_AT86RF23X_SPIMODE SPIDEV_MODE0
|
2016-06-01 12:12:21 +02:00
|
|
|
#endif
|
|
|
|
|
2019-12-05 18:49:12 +01:00
|
|
|
#ifndef CONFIG_IEEE802154_AT86RF23X_FREQUENCY
|
|
|
|
# define CONFIG_IEEE802154_AT86RF23X_FREQUENCY 1000000
|
2016-06-01 12:12:21 +02:00
|
|
|
#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 */
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2016-06-01 12:12:21 +02:00
|
|
|
#define AT86RF23X_PA_AUTO 1
|
|
|
|
#define AT86RF23X_PA_ED 2
|
|
|
|
#define AT86RF23X_PA_SLEEP 3
|
|
|
|
|
2019-02-27 15:41:08 +01:00
|
|
|
/****************************************************************************
|
2016-06-01 12:12:21 +02:00
|
|
|
* Private Types
|
2019-02-27 15:41:08 +01:00
|
|
|
****************************************************************************/
|
2016-06-01 12:12:21 +02:00
|
|
|
|
2017-03-15 21:16:19 +01:00
|
|
|
/* AT86RF23x device instance
|
2016-06-01 12:12:21 +02:00
|
|
|
*
|
2019-02-27 15:41:08 +01:00
|
|
|
* Make sure that struct ieee802154_radio_s remains first. If not it will
|
|
|
|
* break the code
|
2016-06-01 12:12:21 +02:00
|
|
|
*/
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2016-06-01 12:12:21 +02:00
|
|
|
struct at86rf23x_dev_s
|
|
|
|
{
|
2017-03-15 21:16:19 +01:00
|
|
|
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 */
|
2017-06-19 11:55:28 +02:00
|
|
|
uint8_t panid[2]; /* PAN identifier, FFFF = not set */
|
2017-03-15 21:16:19 +01:00
|
|
|
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 */
|
2016-06-01 12:12:21 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* Internal operations */
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2016-06-01 12:12:21 +02:00
|
|
|
static void at86rf23x_lock(FAR struct spi_dev_s *spi);
|
|
|
|
static void at86rf23x_unlock(FAR struct spi_dev_s *spi);
|
2017-03-15 21:16:19 +01:00
|
|
|
static void at86rf23x_setreg(FAR struct spi_dev_s *spi, uint32_t addr,
|
|
|
|
uint8_t val);
|
2016-06-01 12:12:21 +02:00
|
|
|
static uint8_t at86rf23x_getreg(FAR struct spi_dev_s *spi, uint32_t addr);
|
2019-02-27 15:41:08 +01:00
|
|
|
static int at86rf23x_writeframe(FAR struct spi_dev_s *spi,
|
|
|
|
FAR uint8_t *frame, uint8_t len);
|
2017-03-15 21:16:19 +01:00
|
|
|
static uint8_t at86rf23x_readframe(FAR struct spi_dev_s *spi,
|
|
|
|
FAR uint8_t *frame_rx);
|
2019-12-05 18:49:12 +01:00
|
|
|
static int at86rf23x_set_trxstate(FAR struct at86rf23x_dev_s *dev,
|
2017-03-15 21:16:19 +01:00
|
|
|
uint8_t state, uint8_t force);
|
2019-12-05 18:49:12 +01:00
|
|
|
static uint8_t at86rf23x_get_trxstate(FAR struct at86rf23x_dev_s *dev);
|
2016-06-01 12:12:21 +02:00
|
|
|
static int at86rf23x_resetrf(FAR struct at86rf23x_dev_s *dev);
|
|
|
|
static int at86rf23x_initialize(FAR struct at86rf23x_dev_s *dev);
|
|
|
|
|
2017-03-15 21:16:19 +01:00
|
|
|
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);
|
2017-03-27 18:28:03 +02:00
|
|
|
static int at86rf23x_interrupt(int irq, FAR void *context, FAR void *arg);
|
2016-06-01 12:12:21 +02:00
|
|
|
|
2017-03-15 21:16:19 +01:00
|
|
|
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_energydetect(FAR struct ieee802154_radio_s *ieee,
|
|
|
|
FAR uint8_t *energy);
|
2017-04-13 19:14:02 +02:00
|
|
|
|
|
|
|
/* Driver operations */
|
|
|
|
|
2017-03-15 21:16:19 +01:00
|
|
|
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
|
|
|
|
****************************************************************************/
|
2016-06-01 12:12:21 +02:00
|
|
|
|
|
|
|
/* These are pointers to ALL registered at86rf23x devices.
|
2018-04-04 17:32:39 +02:00
|
|
|
* This table is used during interrupt handling to find the context.
|
2016-06-01 12:12:21 +02:00
|
|
|
* Only one device is supported for now.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static struct at86rf23x_dev_s g_at86rf23x_devices[1];
|
|
|
|
|
2016-06-01 13:11:49 +02:00
|
|
|
static const struct ieee802154_radioops_s at86rf23x_devops =
|
2016-06-01 12:12:21 +02:00
|
|
|
{
|
2017-03-15 21:16:19 +01:00
|
|
|
.ioctl = at86rf23x_ioctl,
|
|
|
|
.rxenable = at86rf23x_rxenable,
|
|
|
|
.transmit = at86rf23x_transmit
|
2016-06-01 12:12:21 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
2017-05-02 22:42:40 +02:00
|
|
|
|
2016-06-01 12:12:21 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: at86rf23x_lock
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Acquire exclusive access to the shared SPI bus.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void at86rf23x_lock(FAR struct spi_dev_s *spi)
|
|
|
|
{
|
2017-03-15 21:16:19 +01:00
|
|
|
SPI_LOCK(spi, 1);
|
|
|
|
SPI_SETBITS(spi, 8);
|
2019-12-05 18:49:12 +01:00
|
|
|
SPI_SETMODE(spi, CONFIG_IEEE802154_AT86RF23X_SPIMODE);
|
|
|
|
SPI_SETFREQUENCY(spi, CONFIG_IEEE802154_AT86RF23X_FREQUENCY);
|
2016-06-01 12:12:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: at86rf23x_unlock
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Release exclusive access to the shared SPI bus.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void at86rf23x_unlock(FAR struct spi_dev_s *spi)
|
|
|
|
{
|
2017-03-15 21:16:19 +01:00
|
|
|
SPI_LOCK(spi, 0);
|
2016-06-01 12:12:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: at86rf23x_setreg
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Define the value of an at86rf23x device register
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-03-15 21:16:19 +01:00
|
|
|
static void at86rf23x_setreg(FAR struct spi_dev_s *spi, uint32_t addr,
|
|
|
|
uint8_t val)
|
2016-06-01 12:12:21 +02:00
|
|
|
{
|
|
|
|
uint8_t reg[2];
|
|
|
|
|
|
|
|
reg[0] = addr;
|
|
|
|
reg[0] |= RF23X_SPI_REG_WRITE;
|
|
|
|
|
|
|
|
reg[1] = val;
|
|
|
|
at86rf23x_lock(spi);
|
2017-04-29 20:28:19 +02:00
|
|
|
SPI_SELECT(spi, SPIDEV_IEEE802154(0), true);
|
2016-06-01 12:12:21 +02:00
|
|
|
SPI_SNDBLOCK(spi, reg, 2);
|
2017-04-29 20:28:19 +02:00
|
|
|
SPI_SELECT(spi, SPIDEV_IEEE802154(0), false);
|
2016-06-01 12:12:21 +02:00
|
|
|
at86rf23x_unlock(spi);
|
|
|
|
|
2017-03-15 21:37:17 +01:00
|
|
|
wlinfo("0x%02X->r[0x%02X]\n", val, addr);
|
2016-06-01 12:12:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: at86rf23x_getreg
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Return the value of an at86rf23x device register
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2016-06-01 12:12:21 +02:00
|
|
|
static uint8_t at86rf23x_getreg(FAR struct spi_dev_s *spi, uint32_t addr)
|
|
|
|
{
|
2017-03-15 21:16:19 +01:00
|
|
|
uint8_t reg[2];
|
|
|
|
uint8_t val[2];
|
2016-06-01 12:12:21 +02:00
|
|
|
|
2017-03-15 21:16:19 +01:00
|
|
|
/* Add Read mask to desired register */
|
2016-06-01 12:12:21 +02:00
|
|
|
|
2017-03-15 21:16:19 +01:00
|
|
|
reg[0] = addr | RF23X_SPI_REG_READ;
|
2016-06-01 12:12:21 +02:00
|
|
|
|
2017-03-15 21:16:19 +01:00
|
|
|
at86rf23x_lock (spi);
|
2016-06-01 12:12:21 +02:00
|
|
|
|
2017-04-29 20:28:19 +02:00
|
|
|
SPI_SELECT(spi, SPIDEV_IEEE802154(0), true);
|
2017-03-15 21:16:19 +01:00
|
|
|
SPI_EXCHANGE(spi, reg, val, 2);
|
2017-04-29 20:28:19 +02:00
|
|
|
SPI_SELECT(spi, SPIDEV_IEEE802154(0), false);
|
2016-06-01 12:12:21 +02:00
|
|
|
|
2017-03-15 21:16:19 +01:00
|
|
|
at86rf23x_unlock(spi);
|
2016-06-01 12:12:21 +02:00
|
|
|
|
2019-02-27 15:41:08 +01:00
|
|
|
wlinfo("r[0x%02X]=0x%02X\n", addr, val[1]);
|
2017-03-15 21:16:19 +01:00
|
|
|
|
|
|
|
return val[1];
|
2016-06-01 12:12:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2017-03-15 21:16:19 +01:00
|
|
|
|
|
|
|
static void at86rf23x_setregbits(FAR struct spi_dev_s *spi, uint8_t addr,
|
|
|
|
uint8_t pos, uint8_t mask, uint8_t val)
|
2016-06-01 12:12:21 +02:00
|
|
|
{
|
2017-03-15 21:16:19 +01:00
|
|
|
uint8_t reg;
|
2016-06-01 12:12:21 +02:00
|
|
|
|
2017-03-15 21:16:19 +01:00
|
|
|
reg = at86rf23x_getreg(spi, addr);
|
|
|
|
reg = (reg & ~(mask << pos)) | (val << pos);
|
|
|
|
at86rf23x_setreg(spi, addr, reg);
|
2016-06-01 12:12:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: at86rf23x_getregbits
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Return the value of an section of the at86rf23x device register.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2017-03-15 21:16:19 +01:00
|
|
|
|
|
|
|
static uint8_t at86rf23x_getregbits(FAR struct spi_dev_s *spi, uint8_t addr,
|
|
|
|
uint8_t pos, uint8_t mask)
|
2016-06-01 12:12:21 +02:00
|
|
|
{
|
2017-03-15 21:16:19 +01:00
|
|
|
uint8_t val;
|
2016-06-01 12:12:21 +02:00
|
|
|
|
2017-03-15 21:16:19 +01:00
|
|
|
val = at86rf23x_getreg(spi, addr);
|
|
|
|
val = (val >> pos) & mask;
|
2016-06-01 12:12:21 +02:00
|
|
|
|
2017-03-15 21:16:19 +01:00
|
|
|
return val;
|
2016-06-01 12:12:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: at86rf23x_writebuffer
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Write frame to the transmit buffer of the radio. This does not
|
|
|
|
* initiate the transfer, just write to the buffer.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2021-04-04 11:58:11 +02:00
|
|
|
static int at86rf23x_writeframe(FAR struct spi_dev_s *spi,
|
|
|
|
FAR uint8_t *frame,
|
2017-03-15 21:16:19 +01:00
|
|
|
uint8_t len)
|
2016-06-01 12:12:21 +02:00
|
|
|
{
|
2017-03-15 21:16:19 +01:00
|
|
|
uint8_t reg = RF23X_SPI_FRAME_WRITE;
|
2016-06-01 12:12:21 +02:00
|
|
|
|
2019-02-27 15:41:08 +01:00
|
|
|
#if 0
|
|
|
|
report_packet(frame_wr, len);
|
|
|
|
#endif
|
|
|
|
|
2017-03-15 21:16:19 +01:00
|
|
|
at86rf23x_lock(spi);
|
2016-06-01 12:12:21 +02:00
|
|
|
|
2017-04-29 20:28:19 +02:00
|
|
|
SPI_SELECT(spi, SPIDEV_IEEE802154(0), true);
|
2016-06-01 12:12:21 +02:00
|
|
|
|
2017-03-15 21:16:19 +01:00
|
|
|
SPI_SNDBLOCK(spi, ®, 1);
|
|
|
|
SPI_SNDBLOCK(spi, &frame, len);
|
2016-06-01 12:12:21 +02:00
|
|
|
|
2017-04-29 20:28:19 +02:00
|
|
|
SPI_SELECT(spi, SPIDEV_IEEE802154(0), false);
|
2016-06-01 12:12:21 +02:00
|
|
|
|
2017-03-15 21:16:19 +01:00
|
|
|
at86rf23x_unlock(spi);
|
2016-06-01 12:12:21 +02:00
|
|
|
|
2017-03-15 21:16:19 +01:00
|
|
|
return len;
|
2016-06-01 12:12:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: at86rf23x_readframe
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Read the buffer memory of the radio. This is used when the radio
|
|
|
|
* indicates a frame has been received.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2017-03-15 21:16:19 +01:00
|
|
|
|
|
|
|
static uint8_t at86rf23x_readframe(FAR struct spi_dev_s *spi,
|
|
|
|
FAR uint8_t *frame_rx)
|
2016-06-01 12:12:21 +02:00
|
|
|
{
|
2019-02-27 15:41:08 +01:00
|
|
|
uint8_t len;
|
|
|
|
uint8_t reg;
|
2016-06-01 12:12:21 +02:00
|
|
|
|
2017-03-15 21:16:19 +01:00
|
|
|
reg = RF23X_SPI_FRAME_READ;
|
2016-06-01 12:12:21 +02:00
|
|
|
|
2017-03-15 21:16:19 +01:00
|
|
|
at86rf23x_lock(spi);
|
2017-04-29 20:28:19 +02:00
|
|
|
SPI_SELECT(spi, SPIDEV_IEEE802154(0), true);
|
2016-06-01 12:12:21 +02:00
|
|
|
|
2017-03-15 21:16:19 +01:00
|
|
|
SPI_SNDBLOCK(spi, ®, 1);
|
|
|
|
SPI_RECVBLOCK(spi, &len, 1);
|
2019-12-05 18:49:12 +01:00
|
|
|
SPI_RECVBLOCK(spi, frame_rx, len + 3);
|
2016-06-01 12:12:21 +02:00
|
|
|
|
2017-04-29 20:28:19 +02:00
|
|
|
SPI_SELECT(spi, SPIDEV_IEEE802154(0), false);
|
2017-03-15 21:16:19 +01:00
|
|
|
at86rf23x_unlock(spi);
|
2016-06-01 12:12:21 +02:00
|
|
|
|
2017-03-15 21:16:19 +01:00
|
|
|
return len;
|
2016-06-01 12:12:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2019-12-05 18:49:12 +01:00
|
|
|
* Name: at86rf23x_get_trxstate
|
2016-06-01 12:12:21 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Return the current status of the TRX state machine.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2019-12-05 18:49:12 +01:00
|
|
|
static uint8_t at86rf23x_get_trxstate(FAR struct at86rf23x_dev_s *dev)
|
2016-06-01 12:12:21 +02:00
|
|
|
{
|
2017-03-15 21:16:19 +01:00
|
|
|
return at86rf23x_getregbits(dev->spi, RF23X_TRXSTATUS_STATUS);
|
2016-06-01 12:12:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2019-12-05 18:49:12 +01:00
|
|
|
* Name: at86rf23x_set_trxstate
|
2016-06-01 12:12:21 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Set the TRX state machine to the desired state. If the state machine
|
2019-02-27 15:41:08 +01:00
|
|
|
* cannot move to the desired state an ERROR is returned. If the
|
2020-02-22 19:31:14 +01:00
|
|
|
* transition is successful an OK is returned. This is a long running
|
|
|
|
* function due to waiting for the transition delay between states. This
|
2019-02-27 15:41:08 +01:00
|
|
|
* can be as long as 510us.
|
2016-06-01 12:12:21 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2019-12-05 18:49:12 +01:00
|
|
|
static int at86rf23x_set_trxstate(FAR struct at86rf23x_dev_s *dev,
|
|
|
|
uint8_t state, uint8_t force)
|
2016-06-01 12:12:21 +02:00
|
|
|
{
|
|
|
|
/* Get the current state of the transceiver */
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2019-12-05 18:49:12 +01:00
|
|
|
uint8_t status = at86rf23x_get_trxstate(dev);
|
2016-06-01 12:12:21 +02:00
|
|
|
|
|
|
|
int ret = OK;
|
|
|
|
|
2021-04-04 11:58:11 +02:00
|
|
|
/* TODO
|
|
|
|
* I don't have every state included verify this will work with SLEEP
|
|
|
|
*/
|
2017-03-15 21:16:19 +01:00
|
|
|
|
|
|
|
if ((status != TRX_STATUS_TRXOFF) &&
|
2016-06-01 12:12:21 +02:00
|
|
|
(status != TRX_STATUS_RXON) &&
|
|
|
|
(status != TRX_STATUS_PLLON) &&
|
|
|
|
(status != TRX_STATUS_RXAACKON) &&
|
|
|
|
(status != TRX_STATUS_TXARETON) &&
|
|
|
|
(status != TRX_STATUS_PON))
|
|
|
|
{
|
2017-03-15 21:37:17 +01:00
|
|
|
wlerr("ERROR: Invalid State\n");
|
2016-06-01 12:12:21 +02:00
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
int8_t init_status = status;
|
|
|
|
|
|
|
|
/* Start the state change */
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2019-02-27 15:41:08 +01:00
|
|
|
switch (state)
|
2016-06-01 12:12:21 +02:00
|
|
|
{
|
|
|
|
case TRX_CMD_TRXOFF:
|
2017-03-15 21:16:19 +01:00
|
|
|
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)
|
|
|
|
{
|
2019-02-27 15:41:08 +01:00
|
|
|
at86rf23x_setregbits(dev->spi, RF23X_TRXCMD_STATE,
|
|
|
|
TRX_CMD_FORCETRXOFF);
|
2017-03-15 21:16:19 +01:00
|
|
|
up_udelay(RF23X_TIME_FORCE_TRXOFF);
|
|
|
|
}
|
2016-06-01 12:12:21 +02:00
|
|
|
|
|
|
|
status = at86rf23x_getregbits(dev->spi, RF23X_TRXSTATUS_STATUS);
|
2017-03-15 21:16:19 +01:00
|
|
|
if (status != TRX_STATUS_TRXOFF)
|
|
|
|
{
|
|
|
|
ret = ERROR;
|
|
|
|
}
|
2016-06-01 12:12:21 +02:00
|
|
|
|
2017-03-15 21:16:19 +01:00
|
|
|
break;
|
2016-06-01 12:12:21 +02:00
|
|
|
|
|
|
|
case TRX_CMD_RX_ON:
|
2017-03-15 21:16:19 +01:00
|
|
|
if (status == TRX_STATUS_RXON)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2016-06-01 12:12:21 +02:00
|
|
|
|
2017-03-15 21:16:19 +01:00
|
|
|
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;
|
2016-06-01 12:12:21 +02:00
|
|
|
|
2017-03-15 21:16:19 +01:00
|
|
|
/* Transition to PLL_ON */
|
|
|
|
|
|
|
|
case TRX_CMD_PLL_ON:
|
|
|
|
if (status == TRX_STATUS_PLLON)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2016-06-01 12:12:21 +02:00
|
|
|
|
|
|
|
if (status == TRX_STATUS_TRXOFF)
|
2017-03-15 21:16:19 +01:00
|
|
|
{
|
|
|
|
at86rf23x_setregbits(dev->spi, RF23X_TRXCMD_STATE, TRX_CMD_PLL_ON);
|
|
|
|
up_udelay(RF23X_TIME_TRXOFF_TO_PLL);
|
|
|
|
}
|
2016-06-01 12:12:21 +02:00
|
|
|
else
|
2017-03-15 21:16:19 +01:00
|
|
|
{
|
|
|
|
at86rf23x_setregbits(dev->spi, RF23X_TRXCMD_STATE, TRX_CMD_PLL_ON);
|
|
|
|
up_udelay(RF23X_TIME_TRANSITION_PLL_ACTIVE);
|
|
|
|
}
|
2016-06-01 12:12:21 +02:00
|
|
|
|
|
|
|
status = at86rf23x_getregbits(dev->spi, RF23X_TRXSTATUS_STATUS);
|
2017-03-15 21:16:19 +01:00
|
|
|
if (status != TRX_STATUS_PLLON)
|
|
|
|
{
|
|
|
|
ret = ERROR;
|
|
|
|
}
|
2016-06-01 12:12:21 +02:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TRX_CMD_RX_AACK_ON:
|
2017-03-15 21:16:19 +01:00
|
|
|
if (status == TRX_STATUS_RXAACKON)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2016-06-01 12:12:21 +02:00
|
|
|
|
|
|
|
if (status == TRX_STATUS_TRXOFF || status == TRX_STATUS_TXARETON)
|
2017-03-15 21:16:19 +01:00
|
|
|
{
|
|
|
|
at86rf23x_setregbits(dev->spi, RF23X_TRXCMD_STATE, TRX_CMD_RX_ON);
|
2016-06-01 12:12:21 +02:00
|
|
|
|
2019-02-27 15:41:08 +01:00
|
|
|
(status == TRX_STATUS_TRXOFF) ?
|
|
|
|
up_udelay(RF23X_TIME_TRXOFF_TO_PLL) :
|
|
|
|
up_udelay(RF23X_TIME_TRANSITION_PLL_ACTIVE);
|
2017-03-15 21:16:19 +01:00
|
|
|
}
|
2016-06-01 12:12:21 +02:00
|
|
|
|
2019-12-05 18:49:12 +01:00
|
|
|
status = at86rf23x_get_trxstate(dev);
|
2016-06-01 12:12:21 +02:00
|
|
|
if ((status == TRX_STATUS_RXON) || (status == TRX_STATUS_PLLON))
|
2017-03-15 21:16:19 +01:00
|
|
|
{
|
2019-02-27 15:41:08 +01:00
|
|
|
at86rf23x_setregbits(dev->spi, RF23X_TRXCMD_STATE,
|
|
|
|
TRX_CMD_RX_AACK_ON);
|
2017-03-15 21:16:19 +01:00
|
|
|
up_udelay(RF23X_TIME_TRANSITION_PLL_ACTIVE);
|
|
|
|
}
|
2016-06-01 12:12:21 +02:00
|
|
|
|
|
|
|
status = at86rf23x_getregbits(dev->spi, RF23X_TRXSTATUS_STATUS);
|
2017-03-15 21:16:19 +01:00
|
|
|
if (status != TRX_STATUS_RXAACKON)
|
|
|
|
{
|
|
|
|
ret = ERROR;
|
|
|
|
}
|
2016-06-01 12:12:21 +02:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TRX_STATUS_TXARETON:
|
2017-03-15 21:16:19 +01:00
|
|
|
if (status == TRX_STATUS_TXARETON)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2016-06-01 12:12:21 +02:00
|
|
|
|
|
|
|
if (status == TRX_STATUS_TRXOFF)
|
2017-03-15 21:16:19 +01:00
|
|
|
{
|
2019-02-27 15:41:08 +01:00
|
|
|
at86rf23x_setregbits(dev->spi, RF23X_TRXCMD_STATE,
|
|
|
|
TRX_CMD_RX_ON);
|
2017-03-15 21:16:19 +01:00
|
|
|
up_udelay(RF23X_TIME_TRXOFF_TO_PLL);
|
|
|
|
}
|
2016-06-01 12:12:21 +02:00
|
|
|
|
|
|
|
if ((status == TRX_STATUS_RXON) || (status == TRX_STATUS_PLLON))
|
2017-03-15 21:16:19 +01:00
|
|
|
{
|
2019-02-27 15:41:08 +01:00
|
|
|
at86rf23x_setregbits(dev->spi, RF23X_TRXCMD_STATE,
|
|
|
|
TRX_CMD_TX_ARET_ON);
|
2017-03-15 21:16:19 +01:00
|
|
|
up_udelay(RF23X_TIME_TRANSITION_PLL_ACTIVE);
|
|
|
|
}
|
2016-06-01 12:12:21 +02:00
|
|
|
else if (status == TRX_STATUS_RXAACKON)
|
2017-03-15 21:16:19 +01:00
|
|
|
{
|
2019-02-27 15:41:08 +01:00
|
|
|
at86rf23x_setregbits(dev->spi, RF23X_TRXCMD_STATE,
|
|
|
|
TRX_CMD_RX_ON);
|
2017-03-15 21:16:19 +01:00
|
|
|
up_udelay(RF23X_TIME_TRANSITION_PLL_ACTIVE);
|
2016-06-01 12:12:21 +02:00
|
|
|
|
2019-02-27 15:41:08 +01:00
|
|
|
at86rf23x_setregbits(dev->spi, RF23X_TRXCMD_STATE,
|
|
|
|
TRX_CMD_TX_ARET_ON);
|
2017-03-15 21:16:19 +01:00
|
|
|
up_udelay(RF23X_TIME_TRANSITION_PLL_ACTIVE);
|
|
|
|
}
|
2016-06-01 12:12:21 +02:00
|
|
|
|
|
|
|
status = at86rf23x_getregbits(dev->spi, RF23X_TRXSTATUS_STATUS);
|
2017-03-15 21:16:19 +01:00
|
|
|
if (status != TRX_STATUS_TXARETON)
|
|
|
|
{
|
|
|
|
ret = ERROR;
|
|
|
|
}
|
2016-06-01 12:12:21 +02:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TRX_STATUS_SLEEP:
|
2021-04-04 11:58:11 +02:00
|
|
|
at86rf23x_setregbits(dev->spi,
|
|
|
|
RF23X_TRXCMD_STATE,
|
|
|
|
TRX_CMD_FORCETRXOFF);
|
2016-06-01 12:12:21 +02:00
|
|
|
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:
|
2021-12-26 23:18:22 +01:00
|
|
|
wlerr("ERRPR: %s\n", EINVAL_STR);
|
2019-02-27 15:41:08 +01:00
|
|
|
init_status = 0; /* Placed this here to keep compiler if no debug */
|
2016-06-01 12:12:21 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2017-03-15 21:16:19 +01:00
|
|
|
|
|
|
|
if (ret == ERROR)
|
2016-06-01 12:12:21 +02:00
|
|
|
{
|
2020-02-22 19:31:14 +01:00
|
|
|
wlerr("ERROR: State Transition Error\n");
|
2016-06-01 12:12:21 +02:00
|
|
|
}
|
|
|
|
|
2019-02-27 15:41:08 +01:00
|
|
|
wlinfo("Radio state change state[0x%02x]->state[0x%02x]\n",
|
|
|
|
init_status, status);
|
2016-06-01 12:12:21 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2017-03-15 21:16:19 +01:00
|
|
|
|
|
|
|
static int at86rf23x_setchannel(FAR struct ieee802154_radio_s *ieee,
|
|
|
|
uint8_t chan)
|
2016-06-01 12:12:21 +02:00
|
|
|
{
|
|
|
|
FAR struct at86rf23x_dev_s *dev = (FAR struct at86rf23x_dev_s *)ieee;
|
|
|
|
uint8_t state;
|
|
|
|
|
|
|
|
/* Validate if chan is a valid channel */
|
2017-03-15 21:16:19 +01:00
|
|
|
|
|
|
|
if (chan < 11 || chan > 26)
|
2016-06-01 12:12:21 +02:00
|
|
|
{
|
2019-02-27 15:41:08 +01:00
|
|
|
wlerr("ERROR: Invalid requested chan: %d\n", chan);
|
2016-06-01 12:12:21 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Validate we are in an acceptable mode to change the channel */
|
|
|
|
|
2019-12-05 18:49:12 +01:00
|
|
|
state = at86rf23x_get_trxstate(dev);
|
2017-03-15 21:16:19 +01:00
|
|
|
|
|
|
|
if ((TRX_STATUS_SLEEP == state) || (TRX_STATUS_PON == state))
|
|
|
|
{
|
2019-02-27 15:41:08 +01:00
|
|
|
wlerr("ERROR: Radio in invalid mode [%02x] to set the channel\n",
|
|
|
|
state);
|
2017-03-15 21:16:19 +01:00
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
2016-06-01 12:12:21 +02:00
|
|
|
/* Set the Channel on the transceiver */
|
|
|
|
|
|
|
|
at86rf23x_setregbits(dev->spi, RF23X_CCA_BITS_CHANNEL, chan);
|
|
|
|
|
|
|
|
/* Set the channel within local device */
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2016-06-01 12:12:21 +02:00
|
|
|
dev->channel = chan;
|
|
|
|
|
2017-03-15 21:37:17 +01:00
|
|
|
wlinfo("CHANNEL Changed to %d\n", chan);
|
2016-06-01 12:12:21 +02:00
|
|
|
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.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2017-03-15 21:16:19 +01:00
|
|
|
|
|
|
|
static int at86rf23x_getchannel(FAR struct ieee802154_radio_s *ieee,
|
|
|
|
FAR uint8_t *chan)
|
2016-06-01 12:12:21 +02:00
|
|
|
{
|
|
|
|
FAR struct at86rf23x_dev_s *dev = (FAR struct at86rf23x_dev_s *)ieee;
|
|
|
|
|
|
|
|
/* Set the Channel on the transceiver */
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2016-06-01 12:12:21 +02:00
|
|
|
*chan = at86rf23x_getregbits(dev->spi, RF23X_CCA_BITS_CHANNEL);
|
|
|
|
|
|
|
|
/* Set the channel within local device */
|
|
|
|
|
2017-03-15 21:16:19 +01:00
|
|
|
dev->channel = *chan;
|
2016-06-01 12:12:21 +02:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: at86rf23x_setpanid
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Define the PAN ID for the network.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2017-03-15 21:16:19 +01:00
|
|
|
|
|
|
|
static int at86rf23x_setpanid(FAR struct ieee802154_radio_s *ieee,
|
|
|
|
uint16_t panid)
|
2016-06-01 12:12:21 +02:00
|
|
|
{
|
|
|
|
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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2017-03-15 21:16:19 +01:00
|
|
|
|
|
|
|
static int at86rf23x_getpanid(FAR struct ieee802154_radio_s *ieee,
|
|
|
|
FAR uint16_t *panid)
|
2016-06-01 12:12:21 +02:00
|
|
|
{
|
|
|
|
FAR struct at86rf23x_dev_s *dev = (struct at86rf23x_dev_s *)ieee;
|
|
|
|
uint8_t *pan = (uint8_t *)panid;
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2016-06-01 12:12:21 +02:00
|
|
|
/* TODO: Check if we need to pay attention to endianness */
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2016-06-01 12:12:21 +02:00
|
|
|
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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2017-03-15 21:16:19 +01:00
|
|
|
|
|
|
|
static int at86rf23x_setsaddr(FAR struct ieee802154_radio_s *ieee,
|
|
|
|
uint16_t saddr)
|
2016-06-01 12:12:21 +02:00
|
|
|
{
|
|
|
|
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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2017-03-15 21:16:19 +01:00
|
|
|
|
|
|
|
static int at86rf23x_getsaddr(FAR struct ieee802154_radio_s *ieee,
|
|
|
|
FAR uint16_t *saddr)
|
2016-06-01 12:12:21 +02:00
|
|
|
{
|
|
|
|
FAR struct at86rf23x_dev_s *dev = (struct at86rf23x_dev_s *)ieee;
|
|
|
|
uint8_t *addr = (uint8_t *)saddr;
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2016-06-01 12:12:21 +02:00
|
|
|
/* TODO: Check if we need to pay attention to endianness */
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2016-06-01 12:12:21 +02:00
|
|
|
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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2017-03-15 21:16:19 +01:00
|
|
|
|
|
|
|
static int at86rf23x_seteaddr(FAR struct ieee802154_radio_s *ieee,
|
|
|
|
FAR uint8_t *eaddr)
|
2016-06-01 12:12:21 +02:00
|
|
|
{
|
|
|
|
FAR struct at86rf23x_dev_s *dev = (struct at86rf23x_dev_s *)ieee;
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2016-06-01 12:12:21 +02:00
|
|
|
/* TODO: Check if we need to pay attention to endianness */
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2016-06-01 12:12:21 +02:00
|
|
|
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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2017-03-15 21:16:19 +01:00
|
|
|
|
|
|
|
static int at86rf23x_geteaddr(FAR struct ieee802154_radio_s *ieee,
|
|
|
|
FAR uint8_t *eaddr)
|
2016-06-01 12:12:21 +02:00
|
|
|
{
|
|
|
|
FAR struct at86rf23x_dev_s *dev = (struct at86rf23x_dev_s *)ieee;
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2016-06-01 12:12:21 +02:00
|
|
|
/* TODO: Check if we need to pay attention to endianness */
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2016-06-01 12:12:21 +02:00
|
|
|
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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2017-03-15 21:16:19 +01:00
|
|
|
|
|
|
|
static int at86rf23x_setpromisc(FAR struct ieee802154_radio_s *ieee,
|
|
|
|
bool promisc)
|
2016-06-01 12:12:21 +02:00
|
|
|
{
|
|
|
|
FAR struct at86rf23x_dev_s *dev = (struct at86rf23x_dev_s *)ieee;
|
|
|
|
|
|
|
|
/* TODO: Check what mode I should be in to activate promiscuous mode:
|
2019-02-27 15:41:08 +01:00
|
|
|
* 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
|
2017-03-15 21:16:19 +01:00
|
|
|
*/
|
2016-06-01 12:12:21 +02:00
|
|
|
|
2017-03-15 21:16:19 +01:00
|
|
|
at86rf23x_setregbits(dev->spi, RF23X_XAHCTRL1_BITS_PROM_MODE, promisc);
|
2016-06-01 12:12:21 +02:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: at86rf23x_getpromisc
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Check if the device is in promiscuous mode.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2017-03-15 21:16:19 +01:00
|
|
|
|
|
|
|
static int at86rf23x_getpromisc(FAR struct ieee802154_radio_s *ieee,
|
|
|
|
FAR bool *promisc)
|
2016-06-01 12:12:21 +02:00
|
|
|
{
|
|
|
|
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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2017-03-15 21:16:19 +01:00
|
|
|
|
|
|
|
static int at86rf23x_setdevmode(FAR struct ieee802154_radio_s *ieee,
|
|
|
|
uint8_t mode)
|
2016-06-01 12:12:21 +02:00
|
|
|
{
|
|
|
|
FAR struct at86rf23x_dev_s *dev = (struct at86rf23x_dev_s *)ieee;
|
|
|
|
|
2017-03-15 21:16:19 +01:00
|
|
|
/* Define dev mode */
|
2016-06-01 12:12:21 +02:00
|
|
|
|
2017-03-15 21:16:19 +01:00
|
|
|
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
|
|
|
|
{
|
2019-12-05 18:49:12 +01:00
|
|
|
return -EINVAL;
|
2017-03-15 21:16:19 +01:00
|
|
|
}
|
2016-06-01 12:12:21 +02:00
|
|
|
|
2017-03-15 21:16:19 +01:00
|
|
|
dev->devmode = mode;
|
|
|
|
return OK;
|
2016-06-01 12:12:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: at86rf23x_getdevmode
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* get the device mode type of the radio.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2017-03-15 21:16:19 +01:00
|
|
|
|
|
|
|
static int at86rf23x_getdevmode(FAR struct ieee802154_radio_s *ieee,
|
|
|
|
FAR uint8_t *mode)
|
2016-06-01 12:12:21 +02:00
|
|
|
{
|
|
|
|
FAR struct at86rf23x_dev_s *dev = (struct at86rf23x_dev_s *)ieee;
|
|
|
|
int val;
|
|
|
|
|
|
|
|
val = at86rf23x_getregbits(dev->spi, RF23X_CSMASEED1_IAMCOORD_BITS);
|
2017-03-15 21:16:19 +01:00
|
|
|
if (val == 1)
|
2016-06-01 12:12:21 +02:00
|
|
|
{
|
2016-06-01 13:11:49 +02:00
|
|
|
*mode = IEEE802154_MODE_PANCOORD;
|
2016-06-01 12:12:21 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-06-01 13:11:49 +02:00
|
|
|
*mode = IEEE802154_MODE_DEVICE;
|
2016-06-01 12:12:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: at86rf23x_settxpower
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* set the tx power attenuation or amplification
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2017-03-15 21:16:19 +01:00
|
|
|
|
|
|
|
static int at86rf23x_settxpower(FAR struct ieee802154_radio_s *ieee,
|
|
|
|
int32_t txpwr)
|
2016-06-01 12:12:21 +02:00
|
|
|
{
|
|
|
|
FAR struct at86rf23x_dev_s *dev = (struct at86rf23x_dev_s *)ieee;
|
|
|
|
|
2021-04-04 11:58:11 +02:00
|
|
|
/* TODO:
|
|
|
|
* this needs a lot of work to make sure all chips can share this function
|
|
|
|
*/
|
2016-06-01 12:12:21 +02:00
|
|
|
|
|
|
|
/* Right now we only set tx power to 0 */
|
|
|
|
|
2017-03-15 21:16:19 +01:00
|
|
|
at86rf23x_setreg(dev->spi, RF23X_REG_TXPWR, RF23X_TXPWR_0);
|
2016-06-01 12:12:21 +02:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: at86rf23x_gettxpower
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* get the tx power attenuation or amplification.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2017-03-15 21:16:19 +01:00
|
|
|
|
|
|
|
static int at86rf23x_gettxpower(FAR struct ieee802154_radio_s *ieee,
|
|
|
|
FAR int32_t *txpwr)
|
2016-06-01 12:12:21 +02:00
|
|
|
{
|
|
|
|
FAR struct at86rf23x_dev_s *dev = (struct at86rf23x_dev_s *)ieee;
|
|
|
|
uint8_t reg;
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2020-02-22 19:31:14 +01:00
|
|
|
/* TODO: this needs a lot of work to make sure all chips can share this
|
2017-03-15 21:16:19 +01:00
|
|
|
* function.
|
|
|
|
*/
|
2016-06-01 12:12:21 +02:00
|
|
|
|
|
|
|
/* Right now we only get negative values */
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2016-06-01 12:12:21 +02:00
|
|
|
reg = at86rf23x_getreg(dev->spi, RF23X_REG_TXPWR);
|
2017-03-15 21:16:19 +01:00
|
|
|
switch (reg)
|
|
|
|
{
|
2019-12-05 18:49:12 +01:00
|
|
|
case RF23X_TXPWR_POS_4:
|
|
|
|
*txpwr = 0;
|
|
|
|
break;
|
2017-07-03 06:33:17 +02:00
|
|
|
|
2019-12-05 18:49:12 +01:00
|
|
|
case RF23X_TXPWR_POS_3_7:
|
|
|
|
*txpwr = 0;
|
|
|
|
break;
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2019-12-05 18:49:12 +01:00
|
|
|
case RF23X_TXPWR_POS_3_4:
|
|
|
|
*txpwr = 0;
|
|
|
|
break;
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2019-12-05 18:49:12 +01:00
|
|
|
case RF23X_TXPWR_POS_3:
|
|
|
|
*txpwr = 0;
|
|
|
|
break;
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2019-12-05 18:49:12 +01:00
|
|
|
case RF23X_TXPWR_POS_2_5:
|
|
|
|
*txpwr = 0;
|
|
|
|
break;
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2019-12-05 18:49:12 +01:00
|
|
|
case RF23X_TXPWR_POS_2:
|
|
|
|
*txpwr = 0;
|
|
|
|
break;
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2019-12-05 18:49:12 +01:00
|
|
|
case RF23X_TXPWR_POS_1:
|
|
|
|
*txpwr = 0;
|
|
|
|
break;
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2019-12-05 18:49:12 +01:00
|
|
|
case RF23X_TXPWR_0:
|
|
|
|
*txpwr = 0;
|
|
|
|
break;
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2019-12-05 18:49:12 +01:00
|
|
|
case RF23X_TXPWR_NEG_1:
|
|
|
|
*txpwr = 1000;
|
|
|
|
break;
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2019-12-05 18:49:12 +01:00
|
|
|
case RF23X_TXPWR_NEG_2:
|
|
|
|
*txpwr = 2000;
|
|
|
|
break;
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2019-12-05 18:49:12 +01:00
|
|
|
case RF23X_TXPWR_NEG_3:
|
|
|
|
*txpwr = 3000;
|
|
|
|
break;
|
2016-06-01 12:12:21 +02:00
|
|
|
|
2019-12-05 18:49:12 +01:00
|
|
|
case RF23X_TXPWR_NEG_4:
|
|
|
|
*txpwr = 4000;
|
|
|
|
break;
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2019-12-05 18:49:12 +01:00
|
|
|
case RF23X_TXPWR_NEG_6:
|
|
|
|
*txpwr = 6000;
|
|
|
|
break;
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2019-12-05 18:49:12 +01:00
|
|
|
case RF23X_TXPWR_NEG_8:
|
|
|
|
*txpwr = 8000;
|
|
|
|
break;
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2019-12-05 18:49:12 +01:00
|
|
|
case RF23X_TXPWR_NEG_12:
|
|
|
|
*txpwr = 12000;
|
|
|
|
break;
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2019-12-05 18:49:12 +01:00
|
|
|
case RF23X_TXPWR_NEG_17:
|
|
|
|
*txpwr = 17000;
|
|
|
|
break;
|
2017-03-15 21:16:19 +01:00
|
|
|
}
|
2016-06-01 12:12:21 +02:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2017-07-03 18:08:49 +02:00
|
|
|
/****************************************************************************
|
2016-06-01 12:12:21 +02:00
|
|
|
* Name: at86rf23x_setcca
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Configures if energy detection is used or carrier sense. The base
|
|
|
|
* measurement is configured here as well
|
|
|
|
*
|
2017-07-03 18:08:49 +02:00
|
|
|
****************************************************************************/
|
2017-07-03 06:33:17 +02:00
|
|
|
|
|
|
|
static
|
2019-12-05 18:49:12 +01:00
|
|
|
int at86rf23x_setcca(FAR struct ieee802154_radio_s *ieee,
|
|
|
|
FAR struct ieee802154_cca_s *cca)
|
2016-06-01 12:12:21 +02:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2016-06-01 12:12:21 +02:00
|
|
|
if (cca->use_cs && cca->csth > 0x0f)
|
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cca->use_ed)
|
2017-07-03 18:08:49 +02:00
|
|
|
{
|
2017-03-15 21:16:19 +01:00
|
|
|
at86rf23x_setregbits(dev->spi, RF23X_CCA_BITS_MODE, RF23X_CCA_MODE_ED);
|
2016-06-01 12:12:21 +02:00
|
|
|
}
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2017-07-03 18:08:49 +02:00
|
|
|
if (cca->use_cs)
|
2016-06-01 12:12:21 +02:00
|
|
|
{
|
2017-07-03 18:08:49 +02:00
|
|
|
at86rf23x_setregbits(dev->spi, RF23X_CCA_BITS_MODE, RF23X_CCA_MODE_CS);
|
2016-06-01 12:12:21 +02:00
|
|
|
}
|
|
|
|
|
2017-07-03 18:08:49 +02:00
|
|
|
memcpy(&dev->cca, cca, sizeof(struct ieee802154_cca_s));
|
2016-06-01 12:12:21 +02:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: at86rf23x_getcca
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Get CCA for ???: TODO: need to implement
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2017-03-15 21:16:19 +01:00
|
|
|
|
|
|
|
static int at86rf23x_getcca(FAR struct ieee802154_radio_s *ieee,
|
|
|
|
FAR struct ieee802154_cca_s *cca)
|
2016-06-01 12:12:21 +02:00
|
|
|
{
|
|
|
|
FAR struct at86rf23x_dev_s *dev = (struct at86rf23x_dev_s *)ieee;
|
|
|
|
|
|
|
|
#warning at86rf23x_getcca not implemented.
|
|
|
|
|
|
|
|
UNUSED(dev);
|
|
|
|
UNUSED(cca);
|
|
|
|
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
2017-04-13 19:14:02 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
|
2016-06-01 12:12:21 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: at86rf23x_initialize
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Initialize the radio.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2016-06-01 12:12:21 +02:00
|
|
|
int at86rf23x_initialize(FAR struct at86rf23x_dev_s *dev)
|
|
|
|
{
|
2017-03-15 21:16:19 +01:00
|
|
|
uint8_t part;
|
|
|
|
uint8_t version;
|
2016-06-01 12:12:21 +02:00
|
|
|
|
2017-03-15 21:16:19 +01:00
|
|
|
at86rf23x_resetrf(dev);
|
2016-06-01 12:12:21 +02:00
|
|
|
|
2017-03-15 21:16:19 +01:00
|
|
|
part = at86rf23x_getreg(dev->spi, RF23X_REG_PART);
|
|
|
|
version = at86rf23x_getreg(dev->spi, RF23X_REG_VERSION);
|
2016-06-01 12:12:21 +02:00
|
|
|
|
2017-03-15 21:37:17 +01:00
|
|
|
wlinfo("Radio part: 0x%02x version: 0x%02x found\n", part, version);
|
2017-03-15 21:16:19 +01:00
|
|
|
return OK;
|
2016-06-01 12:12:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: at86rf23x_resetrf
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Hard Reset of the radio. The reset also brings the radio into the
|
|
|
|
* TRX_OFF state.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2016-06-01 12:12:21 +02:00
|
|
|
static int at86rf23x_resetrf(FAR struct at86rf23x_dev_s *dev)
|
|
|
|
{
|
|
|
|
FAR const struct at86rf23x_lower_s *lower = dev->lower;
|
2019-02-27 15:41:08 +01:00
|
|
|
uint8_t trx_status;
|
|
|
|
uint8_t retry_cnt = 0;
|
2016-06-01 12:12:21 +02:00
|
|
|
|
|
|
|
/* Reset the radio */
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2017-03-27 18:28:03 +02:00
|
|
|
lower->reset(lower, false);
|
|
|
|
lower->slptr(lower, false);
|
2016-06-01 12:12:21 +02:00
|
|
|
|
|
|
|
up_udelay(RF23X_TIME_RESET);
|
2017-03-27 18:28:03 +02:00
|
|
|
lower->reset(lower, true);
|
2016-06-01 12:12:21 +02:00
|
|
|
|
|
|
|
/* Dummy read of IRQ register */
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2016-06-01 12:12:21 +02:00
|
|
|
at86rf23x_getreg(dev->spi, RF23X_REG_IRQ_STATUS);
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2019-12-05 18:49:12 +01:00
|
|
|
trx_status = at86rf23x_set_trxstate(dev, TRX_CMD_TRXOFF, true);
|
2016-06-01 12:12:21 +02:00
|
|
|
|
2017-03-15 21:16:19 +01:00
|
|
|
if (retry_cnt == RF23X_MAX_RETRY_RESET_TO_TRX_OFF)
|
|
|
|
{
|
2017-03-15 21:37:17 +01:00
|
|
|
wlerr("ERROR: Reset of transceiver failed\n");
|
2017-03-15 21:16:19 +01:00
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
retry_cnt++;
|
|
|
|
}
|
|
|
|
while (trx_status != OK);
|
2016-06-01 12:12:21 +02:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: at86rf23x_rxenable
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* puts the radio into RX mode and brings in the buffer to handle
|
|
|
|
* RX messages.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2021-04-04 11:58:11 +02:00
|
|
|
static int
|
|
|
|
at86rf23x_rxenable(FAR struct ieee802154_radio_s *ieee, bool state,
|
|
|
|
FAR struct ieee802154_packet_s *packet)
|
2016-06-01 12:12:21 +02:00
|
|
|
{
|
|
|
|
FAR struct at86rf23x_dev_s *dev = (FAR struct at86rf23x_dev_s *)ieee;
|
|
|
|
|
|
|
|
/* Set the radio to the receive state */
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2019-12-05 18:49:12 +01:00
|
|
|
return at86rf23x_set_trxstate(dev, TRX_CMD_RX_ON, false);
|
2016-06-01 12:12:21 +02:00
|
|
|
|
|
|
|
/* 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 */
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2016-06-01 12:12:21 +02:00
|
|
|
ieee->rxbuf = packet;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: at86rf23x_interrupt
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Actual interrupt handler ran inside privileged space.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2017-03-27 18:28:03 +02:00
|
|
|
static int at86rf23x_interrupt(int irq, FAR void *context, FAR void *arg)
|
2016-06-01 12:12:21 +02:00
|
|
|
{
|
2017-03-27 18:28:03 +02:00
|
|
|
FAR struct at86rf23x_dev_s *dev = (FAR struct at86rf23x_dev_s *)arg;
|
2016-06-01 12:12:21 +02:00
|
|
|
|
2017-03-27 18:28:03 +02:00
|
|
|
DEBUGASSERT(dev != NULL);
|
2016-06-01 12:12:21 +02:00
|
|
|
|
|
|
|
/* 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.
|
|
|
|
*/
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2017-03-27 18:28:03 +02:00
|
|
|
dev->lower->enable(dev->lower, false);
|
2016-06-01 12:12:21 +02:00
|
|
|
|
2017-03-15 21:16:19 +01:00
|
|
|
return work_queue(HPWORK, &dev->irqwork, at86rf23x_irqworker,
|
|
|
|
(FAR void *)dev, 0);
|
2016-06-01 12:12:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2016-06-01 12:12:21 +02:00
|
|
|
static int at86rf23x_regdump(FAR struct at86rf23x_dev_s *dev)
|
|
|
|
{
|
|
|
|
uint32_t i;
|
2018-03-03 19:59:48 +01:00
|
|
|
char buf[4 + 16 * 3 + 2 + 1];
|
2019-02-27 15:41:08 +01:00
|
|
|
int len = 0;
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2018-03-03 19:59:48 +01:00
|
|
|
wlinfo("RF23X regs:\n");
|
2016-06-01 12:12:21 +02:00
|
|
|
|
2018-03-03 19:59:48 +01:00
|
|
|
for (i = 0; i < 0x30; i++)
|
2016-06-01 12:12:21 +02:00
|
|
|
{
|
2017-03-15 21:16:19 +01:00
|
|
|
/* First row and every 15 regs */
|
|
|
|
|
2016-06-01 12:12:21 +02:00
|
|
|
if ((i & 0x0f) == 0)
|
2019-12-05 18:49:12 +01:00
|
|
|
{
|
|
|
|
len = sprintf(buf, "%02x: ", i & 0xff);
|
|
|
|
}
|
2017-03-15 21:16:19 +01:00
|
|
|
|
|
|
|
/* Print the register value */
|
2016-06-01 12:12:21 +02:00
|
|
|
|
2019-12-05 18:49:12 +01:00
|
|
|
len += sprintf(buf + len, "%02x ", at86rf23x_getreg(dev->spi, i));
|
2016-06-01 12:12:21 +02:00
|
|
|
|
2017-03-15 21:37:17 +01:00
|
|
|
/* At the end of each 15 regs or end of rf233s regs and actually print
|
|
|
|
* debug message.
|
|
|
|
*/
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2018-03-03 19:59:48 +01:00
|
|
|
if ((i & 15) == 15 || i == 0x2f)
|
2017-03-15 21:16:19 +01:00
|
|
|
{
|
2018-03-03 19:59:48 +01:00
|
|
|
sprintf(buf + len, "\n");
|
2019-02-27 15:41:08 +01:00
|
|
|
wlinfo("%s", buf);
|
2017-03-15 21:16:19 +01:00
|
|
|
}
|
2016-06-01 12:12:21 +02:00
|
|
|
}
|
|
|
|
|
2021-04-04 11:58:11 +02:00
|
|
|
/* TODO:
|
|
|
|
* I have a few more regs that are not consecutive. Will print later
|
|
|
|
*/
|
2016-06-01 12:12:21 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: at86rf23x_irqworker
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Actual thread to handle the irq outside of privaleged mode.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2016-06-01 12:12:21 +02:00
|
|
|
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);
|
|
|
|
|
2017-03-15 21:37:17 +01:00
|
|
|
wlinfo("IRQ: 0x%02X\n", irq_status);
|
2016-06-01 12:12:21 +02:00
|
|
|
|
2019-02-27 15:41:08 +01:00
|
|
|
if ((irq_status & (1 << 3)) != 0)
|
2016-06-01 12:12:21 +02:00
|
|
|
{
|
2019-02-27 15:41:08 +01:00
|
|
|
if ((irq_status & (1 << 2)) != 0)
|
2017-03-15 21:16:19 +01:00
|
|
|
{
|
|
|
|
at86rf23x_irqwork_rx(dev);
|
|
|
|
}
|
2016-06-01 12:12:21 +02:00
|
|
|
else
|
2017-03-15 21:16:19 +01:00
|
|
|
{
|
|
|
|
at86rf23x_irqwork_tx(dev);
|
2019-12-05 18:49:12 +01:00
|
|
|
}
|
2016-06-01 12:12:21 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-03-15 21:37:17 +01:00
|
|
|
wlerr("ERROR: Unknown IRQ Status: %d\n", irq_status);
|
2016-06-01 12:12:21 +02:00
|
|
|
|
2017-03-27 18:28:03 +02:00
|
|
|
/* Re-enable the IRQ even if we don't know how to handle previous
|
2017-03-15 21:16:19 +01:00
|
|
|
* status.
|
|
|
|
*/
|
|
|
|
|
2017-03-27 18:28:03 +02:00
|
|
|
dev->lower->enable(dev->lower, true);
|
2016-06-01 12:12:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: at86rf23x_irqwork_rx
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Misc/unofficial device controls.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2016-06-01 12:12:21 +02:00
|
|
|
static void at86rf23x_irqwork_rx(FAR struct at86rf23x_dev_s *dev)
|
|
|
|
{
|
|
|
|
uint8_t rx_len;
|
|
|
|
|
2017-03-15 21:37:17 +01:00
|
|
|
wlinfo("6LOWPAN:Rx IRQ\n");
|
2016-06-01 12:12:21 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2017-10-03 23:35:24 +02:00
|
|
|
nxsem_post(&dev->ieee.rxsem);
|
2017-03-15 21:16:19 +01:00
|
|
|
|
|
|
|
/* TODO:
|
|
|
|
* Not to sure yet what I should do here. I will something
|
|
|
|
* soon.
|
2016-06-01 12:12:21 +02:00
|
|
|
*/
|
|
|
|
|
2017-03-27 18:28:03 +02:00
|
|
|
/* Re-enable the IRQ */
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2017-03-27 18:28:03 +02:00
|
|
|
dev->lower->enable(dev->lower, true);
|
2016-06-01 12:12:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: at86rf23x_irqwork_tx
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Misc/unofficial device controls.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2016-06-01 12:12:21 +02:00
|
|
|
static void at86rf23x_irqwork_tx(FAR struct at86rf23x_dev_s *dev)
|
|
|
|
{
|
2017-03-15 21:37:17 +01:00
|
|
|
wlinfo("6LOWPAN:Tx IRQ\n");
|
2016-06-01 12:12:21 +02:00
|
|
|
|
2017-03-15 21:16:19 +01:00
|
|
|
/* TODO:
|
|
|
|
* There needs to be more here but for now just alert the waiting
|
|
|
|
* thread. Maybe put it back into Rx mode
|
2016-06-01 12:12:21 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Re enable the IRQ */
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2017-03-27 18:28:03 +02:00
|
|
|
dev->lower->enable(dev->lower, true);
|
2016-06-01 12:12:21 +02:00
|
|
|
|
2017-10-03 23:35:24 +02:00
|
|
|
nxsem_post(&dev->ieee.txsem);
|
2016-06-01 12:12:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2017-03-15 21:16:19 +01:00
|
|
|
|
|
|
|
static int at86rf23x_transmit(FAR struct ieee802154_radio_s *ieee,
|
|
|
|
FAR struct ieee802154_packet_s *packet)
|
2016-06-01 12:12:21 +02:00
|
|
|
{
|
|
|
|
FAR struct at86rf23x_dev_s *dev = (FAR struct at86rf23x_dev_s *)ieee;
|
2017-03-15 21:16:19 +01:00
|
|
|
|
|
|
|
/* TODO:
|
2019-02-27 15:41:08 +01:00
|
|
|
* 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?
|
2016-06-01 12:12:21 +02:00
|
|
|
*/
|
|
|
|
|
2019-12-05 18:49:12 +01:00
|
|
|
if (at86rf23x_set_trxstate(dev, TRX_CMD_PLL_ON, false))
|
2017-03-15 21:16:19 +01:00
|
|
|
{
|
2016-06-01 12:12:21 +02:00
|
|
|
at86rf23x_writeframe(dev->spi, packet->data, packet->len);
|
2017-03-15 21:16:19 +01:00
|
|
|
}
|
2016-06-01 12:12:21 +02:00
|
|
|
else
|
2017-03-15 21:16:19 +01:00
|
|
|
{
|
2017-03-15 21:37:17 +01:00
|
|
|
wlerr("ERROR: Transmit could not put the radio in a Tx state\n");
|
2016-06-01 12:12:21 +02:00
|
|
|
return ERROR;
|
2017-03-15 21:16:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Put the thread that requested transfer to a waiting state */
|
2016-06-01 12:12:21 +02:00
|
|
|
|
2017-10-04 23:22:27 +02:00
|
|
|
nxsem_wait(&dev->ieee.txsem);
|
2017-03-15 21:16:19 +01:00
|
|
|
|
|
|
|
/* TODO Verify that I want to stay in the PLL state or if I want to roll
|
|
|
|
* back to RX_ON.
|
|
|
|
*/
|
|
|
|
|
2016-06-01 12:12:21 +02:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: at86rf23x_init
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Return an at86rf23x device for use by other drivers.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2019-02-27 15:41:08 +01:00
|
|
|
FAR struct ieee802154_radio_s *
|
|
|
|
at86rf23x_init(FAR struct spi_dev_s *spi,
|
|
|
|
FAR const struct at86rf23x_lower_s *lower)
|
2016-06-01 12:12:21 +02:00
|
|
|
{
|
|
|
|
FAR struct at86rf23x_dev_s *dev;
|
|
|
|
struct ieee802154_cca_s cca;
|
|
|
|
|
|
|
|
dev = &g_at86rf23x_devices[0];
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2016-06-01 12:12:21 +02:00
|
|
|
/* Attach the interface, lower driver, and devops */
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2016-06-01 12:12:21 +02:00
|
|
|
dev->spi = spi;
|
|
|
|
dev->lower = lower;
|
|
|
|
dev->ieee.ops = &at86rf23x_devops;
|
|
|
|
|
2017-03-15 21:16:19 +01:00
|
|
|
/* Attach irq */
|
|
|
|
|
2017-03-27 18:28:03 +02:00
|
|
|
if (lower->attach(lower, at86rf23x_interrupt, dev) != OK)
|
2016-06-01 12:12:21 +02:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-10-03 20:51:15 +02:00
|
|
|
nxsem_init(&dev->ieee.rxsem, 0, 0);
|
|
|
|
nxsem_init(&dev->ieee.txsem, 0, 0);
|
2016-06-01 12:12:21 +02:00
|
|
|
|
2017-03-15 21:16:19 +01:00
|
|
|
/* Initialize device */
|
|
|
|
|
2016-06-01 12:12:21 +02:00
|
|
|
at86rf23x_initialize(dev);
|
|
|
|
|
|
|
|
/* Configure the desired IRQs of the devices */
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2016-06-01 12:12:21 +02:00
|
|
|
at86rf23x_setreg(dev->spi, RF23X_REG_IRQ_MASK, RF23X_IRQ_MASK_DEFAULT);
|
|
|
|
|
|
|
|
/* Turn the PLL to the on state */
|
|
|
|
|
2019-12-05 18:49:12 +01:00
|
|
|
at86rf23x_set_trxstate(dev, TRX_CMD_PLL_ON, false);
|
2016-06-01 12:12:21 +02:00
|
|
|
|
2017-03-15 21:16:19 +01:00
|
|
|
/* SEED value of the CSMA backoff algorithm. */
|
2016-06-01 12:12:21 +02:00
|
|
|
|
|
|
|
#ifdef RF23X_ANTENNA_DIVERSITY
|
2017-03-15 21:16:19 +01:00
|
|
|
/* Use antenna diversity */
|
2016-06-01 12:12:21 +02:00
|
|
|
|
2017-03-15 21:16:19 +01:00
|
|
|
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);
|
2016-06-01 12:12:21 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef RF23X_TIMESTAMP
|
2017-03-15 21:16:19 +01:00
|
|
|
/* Enable timestamp init code goes here */
|
2016-06-01 12:12:21 +02:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef RF23X_RF_FRONTEND_CTRL
|
2017-03-15 21:16:19 +01:00
|
|
|
/* Init front end control code goes here */
|
2016-06-01 12:12:21 +02:00
|
|
|
|
|
|
|
#endif
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2016-06-01 12:12:21 +02:00
|
|
|
/* Set the channel of the radio */
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2016-06-01 12:12:21 +02:00
|
|
|
at86rf23x_setchannel(&dev->ieee, 12);
|
|
|
|
|
2019-02-27 15:41:08 +01:00
|
|
|
#if 0
|
2016-06-01 12:12:21 +02:00
|
|
|
/* Configure the Pan id */
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2019-02-27 15:41:08 +01:00
|
|
|
at86rf23x_setpanid(&dev->ieee, IEEE802154_PAN_DEFAULT);
|
|
|
|
#endif
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2019-02-27 15:41:08 +01:00
|
|
|
#if 0
|
2016-06-01 12:12:21 +02:00
|
|
|
/* Configure the Short Addr */
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2019-02-27 15:41:08 +01:00
|
|
|
at86rf23x_setsaddr(&dev->ieee, IEEE802154_SADDR_UNSPEC);
|
|
|
|
#endif
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2019-02-27 15:41:08 +01:00
|
|
|
#if 0
|
2016-06-01 12:12:21 +02:00
|
|
|
/* Configure the IEEE Addr */
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2019-02-27 15:41:08 +01:00
|
|
|
at86rf23x_seteaddr(&dev->ieee, IEEE802154_EADDR_UNSPEC);
|
|
|
|
#endif
|
2016-06-01 12:12:21 +02:00
|
|
|
|
|
|
|
/* Default device params at86rf23x defaults to energy detect only */
|
2017-03-15 21:16:19 +01:00
|
|
|
|
2016-06-01 12:12:21 +02:00
|
|
|
cca.use_ed = 1;
|
|
|
|
cca.use_cs = 0;
|
2017-06-21 21:43:40 +02:00
|
|
|
cca.edth = 0x60; /* CCA mode ED, no carrier sense, recommenced ED
|
|
|
|
* threshold -69 dBm */
|
2016-06-01 12:12:21 +02:00
|
|
|
at86rf23x_setcca(&dev->ieee, &cca);
|
|
|
|
|
2019-02-27 15:41:08 +01:00
|
|
|
#if 0
|
2016-06-01 12:12:21 +02:00
|
|
|
/* Put the Device to RX ON Mode */
|
2019-02-27 15:41:08 +01:00
|
|
|
|
2019-12-05 18:49:12 +01:00
|
|
|
at86rf23x_set_trxstate(dev, TRX_CMD_RX_ON, false);
|
2019-02-27 15:41:08 +01:00
|
|
|
#endif
|
2016-06-01 12:12:21 +02:00
|
|
|
|
|
|
|
/* Enable Radio IRQ */
|
|
|
|
|
2017-03-27 18:28:03 +02:00
|
|
|
lower->enable(lower, true);
|
2016-06-01 12:12:21 +02:00
|
|
|
return &dev->ieee;
|
|
|
|
}
|