Add NSRF42L01 driver. From Laurent Latil

This commit is contained in:
Gregory Nutt
2013-06-01 08:03:55 -06:00
parent 49fd78a70a
commit 0e37ec1bfc
16 changed files with 3410 additions and 757 deletions
+9
View File
@@ -4839,3 +4839,12 @@
avoid requests of exactly MAXPACKET size and, hence, avoid so many avoid requests of exactly MAXPACKET size and, hence, avoid so many
NULL packets. Also, fix the OUT request buffers size to exactly NULL packets. Also, fix the OUT request buffers size to exactly
the max packet size. It cannot be any other size (2013-5-29). the max packet size. It cannot be any other size (2013-5-29).
* .gitignore: Clean-up of most all .gitignore files: Make scope of
ignore to be only the current directory; Ignore .dSYM files in
directories where .exe's may be build. Also, in Makefiles,
clean .dSYM files in directories where .exe may be built (2013-5-30).
* drivers/wireless/nrf24101.c/.h and include/nuttx/wireless/nrf24101.h:
Add new driver for the wireless nRF24L01+ transceiver. From Laurent
Latil (2013-6-1).
* drivers/wireless/cc1101: Move files in the cc1101 up one directory.
From Laurent Latil (2013-6-1).
+1
View File
@@ -194,6 +194,7 @@ CONFIG_I2C=y
# Note: this has (at the moment) nothing to do with WIFI # Note: this has (at the moment) nothing to do with WIFI
# #
CONFIG_WIRELESS=y CONFIG_WIRELESS=y
CONFIG_WL_CC1101=y
# #
# OS support for hardware RTC # OS support for hardware RTC
+123
View File
@@ -0,0 +1,123 @@
/****************************************************************************
* drivers/wireless/ISM1_868MHzGFSK100kbps.c
*
* Copyright (C) 2011 Uros Platise. All rights reserved.
* Copyright (C) 2011 Ales Verbic. All rights reserved.
*
* Authors: Uros Platise <uros.platise@isotel.eu>
* Ales Verbic <ales.verbic@isotel.eu>
*
* 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 <nuttx/wireless/cc1101.h>
/****************************************************************************
* Public Data
****************************************************************************/
/** Settings for 868 MHz, GFSK at 100kbps
*
* ISM Region 1 (Europe) only, Band 868870 MHz
*
* Frequency ERP Duty Cycle Bandwidth Remarks
* 868 868.6 MHz +14 dBm < 1% No limits
* 868.7 869.2 MHz +14 dBm < 0.1% No limits
* 869.3 869.4 MHz +10 dBm No limits < 25 kHz Appropriate access protocol required
* 869.4 869.65 MHz +27 dBm < 10% < 25 kHz Channels may be combined to one high speed channel
* 869.7 -870 MHz +7 dBm No limits No limits
*
* Deviation = 46.142578
* Base frequency = 867.999985
* Carrier frequency = 867.999985
* Channel number = 0
* Carrier frequency = 867.999985
* Modulated = true
* Modulation format = GFSK
* Manchester enable = false
* Sync word qualifier mode = 30/32 sync word bits detected
* Preamble count = 4
* Channel spacing = 199.813843
* Carrier frequency = 867.999985
* Data rate = 99.9069
* RX filter BW = 210.937500
* Data format = Normal mode
* Length config = Fixed packet length mode. Length configured in PKTLEN register
* CRC enable = true
* Packet length = 62
* Device address = 00
* Address config = NO Address check, no broadcast
* CRC autoflush = true
* PA ramping = false
* TX power = 0
*/
const struct c1101_rfsettings_s cc1101_rfsettings_ISM1_868MHzGFSK100kbps =
{
.FSCTRL1 = 0x08, /* FSCTRL1 Frequency Synthesizer Control */
.FSCTRL0 = 0x00, /* FSCTRL0 Frequency Synthesizer Control */
.FREQ2 = 0x20, /* FREQ2 Frequency Control Word, High Byte */
.FREQ1 = 0x25, /* FREQ1 Frequency Control Word, Middle Byte */
.FREQ0 = 0xED, /* FREQ0 Frequency Control Word, Low Byte */
.MDMCFG4 = 0x8B, /* MDMCFG4 Modem Configuration */
.MDMCFG3 = 0xE5, /* MDMCFG3 Modem Configuration */
.MDMCFG2 = 0x13, /* MDMCFG2 Modem Configuration */
.MDMCFG1 = 0x22, /* MDMCFG1 Modem Configuration */
.MDMCFG0 = 0xE5, /* MDMCFG0 Modem Configuration */
.DEVIATN = 0x46, /* DEVIATN Modem Deviation Setting */
.FOCCFG = 0x1D, /* FOCCFG Frequency Offset Compensation Configuration */
.BSCFG = 0x1C, /* BSCFG Bit Synchronization Configuration */
.AGCCTRL2= 0xC7, /* AGCCTRL2 AGC Control */
.AGCCTRL1= 0x00, /* AGCCTRL1 AGC Control */
.AGCCTRL0= 0xB2, /* AGCCTRL0 AGC Control */
.FREND1 = 0xB6, /* FREND1 Front End RX Configuration */
.FREND0 = 0x10, /* FREND0 Front End TX Configuration */
.FSCAL3 = 0xEA, /* FSCAL3 Frequency Synthesizer Calibration */
.FSCAL2 = 0x2A, /* FSCAL2 Frequency Synthesizer Calibration */
.FSCAL1 = 0x00, /* FSCAL1 Frequency Synthesizer Calibration */
.FSCAL0 = 0x1F, /* FSCAL0 Frequency Synthesizer Calibration */
.CHMIN = 0, /* Fix at 9th channel: 869.80 MHz +- 100 kHz RF Bandwidth */
.CHMAX = 9, /* single channel */
.PAMAX = 8, /* 0 means power OFF, 8 represents PA[7] */
.PA = {0x03, 0x0F, 0x1E, 0x27, 0x67, 0x50, 0x81, 0xC2}
};
+121
View File
@@ -0,0 +1,121 @@
/****************************************************************************
* drivers/wireless/ISM2_905MHzGFSK250kbps.c
*
* Copyright (C) 2011 Uros Platise. All rights reserved.
* Copyright (C) 2011 Ales Verbic. All rights reserved.
*
* Authors: Uros Platise <uros.platise@isotel.eu>
* Ales Verbic <ales.verbic@isotel.eu>
*
* 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 <nuttx/wireless/cc1101.h>
/****************************************************************************
* Public Data
****************************************************************************/
/** Settings for 905 MHz, GFSK at 250kbps
*
* ISM Region 2 (America) only, Band 902928 MHz
*
* Cordless phones 1 W
* Microwave ovens 750 W
* Industrial heaters 100 kW
* Military radar 1000 kW
*
* Deviation = 126.953125
* Base frequency = 901.999969
* Carrier frequency = 905.998993
* Channel number = 20
* Carrier frequency = 905.998993
* Modulated = true
* Modulation format = GFSK
* Manchester enable = false
* Sync word qualifier mode = 30/32 sync word bits detected
* Preamble count = 4
* Channel spacing = 199.951172
* Carrier frequency = 905.998993
* Data rate = 249.939
* RX filter BW = 541.666667
* Data format = Normal mode
* Length config = Variable packet length mode. Packet length configured by the first byte after sync word
* CRC enable = true
* Packet length = 61
* Device address = 0
* Address config = No address check
* CRC autoflush = false
* PA ramping = false
* TX power = 0
*/
const struct c1101_rfsettings_s cc1101_rfsettings_ISM2_905MHzGFSK250kbps =
{
.FSCTRL1 = 0x0C, /* FSCTRL1 Frequency Synthesizer Control */
.FSCTRL0 = 0x00, /* FSCTRL0 Frequency Synthesizer Control */
.FREQ2 = 0x22, /* FREQ2 Frequency Control Word, High Byte */
.FREQ1 = 0xB1, /* FREQ1 Frequency Control Word, Middle Byte */
.FREQ0 = 0x3B, /* FREQ0 Frequency Control Word, Low Byte */
.MDMCFG4 = 0x2D, /* MDMCFG4 Modem Configuration */
.MDMCFG3 = 0x3B, /* MDMCFG3 Modem Configuration */
.MDMCFG2 = 0x13, /* MDMCFG2 Modem Configuration */
.MDMCFG1 = 0x22, /* MDMCFG1 Modem Configuration */
.MDMCFG0 = 0xF8, /* MDMCFG0 Modem Configuration */
.DEVIATN = 0x62, /* DEVIATN Modem Deviation Setting */
.FOCCFG = 0x1D, /* FOCCFG Frequency Offset Compensation Configuration */
.BSCFG = 0x1C, /* BSCFG Bit Synchronization Configuration */
.AGCCTRL2= 0xC7, /* AGCCTRL2 AGC Control */
.AGCCTRL1= 0x00, /* AGCCTRL1 AGC Control */
.AGCCTRL0= 0xB0, /* AGCCTRL0 AGC Control */
.FREND1 = 0xB6, /* FREND1 Front End RX Configuration */
.FREND0 = 0x10, /* FREND0 Front End TX Configuration */
.FSCAL3 = 0xEA, /* FSCAL3 Frequency Synthesizer Calibration */
.FSCAL2 = 0x2A, /* FSCAL2 Frequency Synthesizer Calibration */
.FSCAL1 = 0x00, /* FSCAL1 Frequency Synthesizer Calibration */
.FSCAL0 = 0x1F, /* FSCAL0 Frequency Synthesizer Calibration */
.CHMIN = 0, /* VERIFY REGULATIONS! */
.CHMAX = 0xFF,
.PAMAX = 8, /* 0 means power OFF, 8 represents PA[7] */
.PA = {0x03, 0x0E, 0x1E, 0x27, 0x39, 0x8E, 0xCD, 0xC0}
};
+52
View File
@@ -2,3 +2,55 @@
# For a description of the syntax of this configuration file, # For a description of the syntax of this configuration file,
# see misc/tools/kconfig-language.txt. # see misc/tools/kconfig-language.txt.
# #
config WL_CC1101
bool "CC1101 RF transceiver support"
default n
select SPI
config WL_NRF24L01
bool "nRF24l01+ transceiver support"
default n
select SPI
---help---
This options adds driver support for the Nordic nRF24L01+ chip.
if WL_NRF24L01
config WL_NRF24L01_DFLT_ADDR_WIDTH
int "Default address width"
default 5
range 3 5
---help---
Default address width to be used by the nRF24l01+ driver.
Note that this default can be changed through the driver API.
config WL_NRF24L01_CHECK_PARAMS
bool "Check call parameters"
default y
---help---
This option adds some sanity check code to parameters given in the
driver API functions. If this option is disabled, parameter
values are passed 'as is' to the module hardware registers.
config WL_NRF24L01_RXSUPPORT
bool "Support messages reception"
default y
---help---
If this opion is disabled the driver supports only the transmission of messages.
Reception of messages will be disabled (and corresponding functions removed).
Note: this option is intended to reduce driver code size for 'transmission
only' devices.
if WL_NRF24L01_RXSUPPORT
config WL_NRF24L01_RXFIFO_LEN
int "RX fifo length"
default 128
range 34 2048
---help---
Length of the software based fifo used to store content of
received messages.
endif
endif
+12 -6
View File
@@ -37,11 +37,17 @@ ifeq ($(CONFIG_WIRELESS),y)
# Include wireless drivers # Include wireless drivers
ifeq ($(CONFIG_WL_CC1101),y)
CSRCS += cc1101.c ISM1_868MHzGFSK100kbps.c ISM2_905MHzGFSK250kbps.c CSRCS += cc1101.c ISM1_868MHzGFSK100kbps.c ISM2_905MHzGFSK250kbps.c
endif
# Include wireless build support
ifeq ($(CONFIG_WL_NRF24L01),y)
DEPPATH += --dep-path wireless$(DELIM)cc1101 CSRCS += nrf24l01.c
VPATH += :wireless$(DELIM)cc1101 endif
CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)drivers$(DELIM)wireless$(DELIM)cc1101}
# Include wireless devices build support
DEPPATH += --dep-path wireless
VPATH += :wireless
CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)drivers$(DELIM)wireless}
endif endif
@@ -1,5 +1,5 @@
/**************************************************************************** /****************************************************************************
* drivers/wireless/cc1101/cc1101.c * drivers/wireless/cc1101.c
* *
* Copyright (C) 2011 Uros Platise. All rights reserved. * Copyright (C) 2011 Uros Platise. All rights reserved.
* *
@@ -34,11 +34,7 @@
* *
****************************************************************************/ ****************************************************************************/
/** \file /* Features:
* \author Uros Platise
* \brief Chipcon CC1101 Device Driver
*
* Features:
* - Maximum data length: 61 bytes CC1101_PACKET_MAXDATALEN * - Maximum data length: 61 bytes CC1101_PACKET_MAXDATALEN
* - Packet length includes two additional bytes: CC1101_PACKET_MAXTOTALLEN * - Packet length includes two additional bytes: CC1101_PACKET_MAXTOTALLEN
* - Requires one GDO to trigger end-of-packets in RX and TX modes. * - Requires one GDO to trigger end-of-packets in RX and TX modes.
@@ -56,7 +52,7 @@
* - Sequencing between states or add protection for correct termination of * - Sequencing between states or add protection for correct termination of
* various different state (so that CC1101 does not block in case of improper use) * various different state (so that CC1101 does not block in case of improper use)
* *
* \par RSSI and LQI value interpretation * RSSI and LQI value interpretation
* *
* The LQI can be read from the LQI status register or it can be appended * The LQI can be read from the LQI status register or it can be appended
* to the received packet in the RX FIFO. LQI is a metric of the current * to the received packet in the RX FIFO. LQI is a metric of the current
@@ -94,7 +90,11 @@
* *
* Note that both RSSI and LQI are best used as relative measurements since * Note that both RSSI and LQI are best used as relative measurements since
* the values are dependent on the modulation format. * the values are dependent on the modulation format.
**/ */
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h> #include <nuttx/config.h>
#include <assert.h> #include <assert.h>
@@ -106,9 +106,8 @@
#include <nuttx/kmalloc.h> #include <nuttx/kmalloc.h>
#include <nuttx/wireless/cc1101.h> #include <nuttx/wireless/cc1101.h>
/**************************************************************************** /****************************************************************************
* Declarations * Pre-rocessor Definitions
****************************************************************************/ ****************************************************************************/
#define CC1101_SPIFREQ_BURST 6500000 /* Hz, no delay */ #define CC1101_SPIFREQ_BURST 6500000 /* Hz, no delay */
@@ -221,7 +220,6 @@
#define CC1101_MCSM0_XOSC_FORCE_ON 0x01 #define CC1101_MCSM0_XOSC_FORCE_ON 0x01
/* /*
* Chip Status Byte * Chip Status Byte
*/ */
@@ -290,7 +288,8 @@
#define FLAGS_RXONLY 1 /* Indicates receive operation only */ #define FLAGS_RXONLY 1 /* Indicates receive operation only */
#define FLAGS_XOSCENABLED 2 /* Indicates that one pin is configured as XOSC/n */ #define FLAGS_XOSCENABLED 2 /* Indicates that one pin is configured as XOSC/n */
struct cc1101_dev_s { struct cc1101_dev_s
{
const struct c1101_rfsettings_s *rfsettings; const struct c1101_rfsettings_s *rfsettings;
struct spi_dev_s * spi; struct spi_dev_s * spi;
@@ -301,7 +300,6 @@ struct cc1101_dev_s {
uint8_t power; uint8_t power;
}; };
/**************************************************************************** /****************************************************************************
* Private Functions * Private Functions
****************************************************************************/ ****************************************************************************/
@@ -314,14 +312,12 @@ void cc1101_access_begin(struct cc1101_dev_s * dev)
SPI_SETBITS(dev->spi, 8); SPI_SETBITS(dev->spi, 8);
} }
void cc1101_access_end(struct cc1101_dev_s * dev) void cc1101_access_end(struct cc1101_dev_s * dev)
{ {
SPI_SELECT(dev->spi, SPIDEV_WIRELESS, false); SPI_SELECT(dev->spi, SPIDEV_WIRELESS, false);
(void)SPI_LOCK(dev->spi, false); (void)SPI_LOCK(dev->spi, false);
} }
/** CC1101 Access with Range Check /** CC1101 Access with Range Check
* *
* \param dev CC1101 Private Structure * \param dev CC1101 Private Structure
@@ -332,6 +328,7 @@ void cc1101_access_end(struct cc1101_dev_s * dev)
* however * however
* \return OK on success or errno is set. * \return OK on success or errno is set.
*/ */
int cc1101_access(struct cc1101_dev_s * dev, uint8_t addr, uint8_t *buf, int length) int cc1101_access(struct cc1101_dev_s * dev, uint8_t addr, uint8_t *buf, int length)
{ {
int stabyte; int stabyte;
@@ -505,7 +502,8 @@ struct cc1101_dev_s * cc1101_init(struct spi_dev_s * spi, uint8_t isrpin,
ASSERT(spi); ASSERT(spi);
if ( (dev = kmalloc( sizeof(struct cc1101_dev_s) )) == NULL) { if ((dev = kmalloc(sizeof(struct cc1101_dev_s))) == NULL)
{
errno = ENOMEM; errno = ENOMEM;
return NULL; return NULL;
} }
@@ -520,7 +518,8 @@ struct cc1101_dev_s * cc1101_init(struct spi_dev_s * spi, uint8_t isrpin,
/* Reset chip, check status bytes */ /* Reset chip, check status bytes */
if ( cc1101_reset(dev) < 0 ) { if (cc1101_reset(dev) < 0)
{
kfree(dev); kfree(dev);
errno = EFAULT; errno = EFAULT;
return NULL; return NULL;
@@ -528,7 +527,8 @@ struct cc1101_dev_s * cc1101_init(struct spi_dev_s * spi, uint8_t isrpin,
/* Check part compatibility */ /* Check part compatibility */
if ( cc1101_checkpart(dev) < 0 ) { if (cc1101_checkpart(dev) < 0)
{
kfree(dev); kfree(dev);
errno = ENODEV; errno = ENODEV;
return NULL; return NULL;
@@ -558,55 +558,56 @@ struct cc1101_dev_s * cc1101_init(struct spi_dev_s * spi, uint8_t isrpin,
/* Bind to external interrupt line */ /* Bind to external interrupt line */
// depends on STM32: TODO: Make that config within pinset and /* depends on STM32: TODO: Make that config within pinset and
// provide general gpio interface * provide general gpio interface
//stm32_gpiosetevent(pinset, false, true, true, cc1101_eventcb); * stm32_gpiosetevent(pinset, false, true, true, cc1101_eventcb);
*/
return dev; return dev;
} }
int cc1101_deinit(struct cc1101_dev_s * dev) int cc1101_deinit(struct cc1101_dev_s * dev)
{ {
ASSERT(dev); ASSERT(dev);
/* Release interrupt */ /* Release interrupt */
//stm32_gpiosetevent(pinset, false, false, false, NULL); /* stm32_gpiosetevent(pinset, false, false, false, NULL); */
/* Power down chip */ /* Power down chip */
cc1101_powerdown(dev); cc1101_powerdown(dev);
/* Release external interrupt line */ /* Release external interrupt line */
kfree(dev);
kfree(dev);
return 0; return 0;
} }
int cc1101_powerup(struct cc1101_dev_s * dev) int cc1101_powerup(struct cc1101_dev_s * dev)
{ {
ASSERT(dev); ASSERT(dev);
return 0; return 0;
} }
int cc1101_powerdown(struct cc1101_dev_s * dev) int cc1101_powerdown(struct cc1101_dev_s * dev)
{ {
ASSERT(dev); ASSERT(dev);
return 0; return 0;
} }
int cc1101_setgdo(struct cc1101_dev_s * dev, uint8_t pin, uint8_t function) int cc1101_setgdo(struct cc1101_dev_s * dev, uint8_t pin, uint8_t function)
{ {
ASSERT(dev); ASSERT(dev);
ASSERT(pin <= CC1101_IOCFG0); ASSERT(pin <= CC1101_IOCFG0);
if (function >= CC1101_GDO_CLK_XOSC1) { if (function >= CC1101_GDO_CLK_XOSC1)
{
/* Only one pin can be enabled at a time as XOSC/n */ /* Only one pin can be enabled at a time as XOSC/n */
if (dev->flags & FLAGS_XOSCENABLED) return -EPERM; if (dev->flags & FLAGS_XOSCENABLED)
{
return -EPERM;
}
/* Force XOSC to stay active even in sleep mode */ /* Force XOSC to stay active even in sleep mode */
@@ -615,8 +616,8 @@ int cc1101_setgdo(struct cc1101_dev_s * dev, uint8_t pin, uint8_t function)
dev->flags |= FLAGS_XOSCENABLED; dev->flags |= FLAGS_XOSCENABLED;
} }
else if (dev->flags & FLAGS_XOSCENABLED) { else if (dev->flags & FLAGS_XOSCENABLED)
{
/* Disable XOSC in sleep mode */ /* Disable XOSC in sleep mode */
int value = CC1101_MCSM0_VALUE; int value = CC1101_MCSM0_VALUE;
@@ -628,19 +629,32 @@ int cc1101_setgdo(struct cc1101_dev_s * dev, uint8_t pin, uint8_t function)
return cc1101_access(dev, pin, &function, -1); return cc1101_access(dev, pin, &function, -1);
} }
int cc1101_setrf(struct cc1101_dev_s * dev, const struct c1101_rfsettings_s *settings) int cc1101_setrf(struct cc1101_dev_s * dev, const struct c1101_rfsettings_s *settings)
{ {
ASSERT(dev); ASSERT(dev);
ASSERT(settings); ASSERT(settings);
if (cc1101_access(dev, CC1101_FSCTRL1, &settings->FSCTRL1, -11) < 0) return ERROR; if (cc1101_access(dev, CC1101_FSCTRL1, &settings->FSCTRL1, -11) < 0)
if (cc1101_access(dev, CC1101_FOCCFG, &settings->FOCCFG, -5) < 0) return ERROR; {
if (cc1101_access(dev, CC1101_FREND1, &settings->FREND1, -6) < 0) return ERROR; return ERROR;
}
if (cc1101_access(dev, CC1101_FOCCFG, &settings->FOCCFG, -5) < 0)
{
return ERROR;
}
if (cc1101_access(dev, CC1101_FREND1, &settings->FREND1, -6) < 0)
{
return ERROR;
}
/* Load Power Table */ /* Load Power Table */
if (cc1101_access(dev, CC1101_PATABLE, settings->PA, -8) < 0) return ERROR; if (cc1101_access(dev, CC1101_PATABLE, settings->PA, -8) < 0)
{
return ERROR;
}
/* If channel is out of valid range, mark that. Limit power. /* If channel is out of valid range, mark that. Limit power.
* We are not allowed to send any data, but are allowed to listen * We are not allowed to send any data, but are allowed to listen
@@ -653,7 +667,6 @@ int cc1101_setrf(struct cc1101_dev_s * dev, const struct c1101_rfsettings_s *set
return OK; return OK;
} }
int cc1101_setchannel(struct cc1101_dev_s * dev, uint8_t channel) int cc1101_setchannel(struct cc1101_dev_s * dev, uint8_t channel)
{ {
ASSERT(dev); ASSERT(dev);
@@ -665,29 +678,38 @@ int cc1101_setchannel(struct cc1101_dev_s * dev, uint8_t channel)
/* If channel is out of valid, we are allowed to listen and receive only */ /* If channel is out of valid, we are allowed to listen and receive only */
if (channel < dev->rfsettings->CHMIN || channel > dev->rfsettings->CHMAX) if (channel < dev->rfsettings->CHMIN || channel > dev->rfsettings->CHMAX)
{
dev->flags |= FLAGS_RXONLY; dev->flags |= FLAGS_RXONLY;
else dev->flags &= ~FLAGS_RXONLY; }
else
cc1101_access(dev, CC1101_CHANNR, &dev->channel, -1); {
dev->flags &= ~FLAGS_RXONLY;
return dev->flags & FLAGS_RXONLY;
} }
cc1101_access(dev, CC1101_CHANNR, &dev->channel, -1);
return dev->flags & FLAGS_RXONLY;
}
uint8_t cc1101_setpower(struct cc1101_dev_s * dev, uint8_t power) uint8_t cc1101_setpower(struct cc1101_dev_s * dev, uint8_t power)
{ {
ASSERT(dev); ASSERT(dev);
if (power > dev->rfsettings->PAMAX) if (power > dev->rfsettings->PAMAX)
{
power = dev->rfsettings->PAMAX; power = dev->rfsettings->PAMAX;
}
dev->power = power; dev->power = power;
if (power == 0) { if (power == 0)
{
dev->flags |= FLAGS_RXONLY; dev->flags |= FLAGS_RXONLY;
return 0; return 0;
} }
else dev->flags &= ~FLAGS_RXONLY; else
{
dev->flags &= ~FLAGS_RXONLY;
}
/* Add remaining part from RF table (to get rid of readback) */ /* Add remaining part from RF table (to get rid of readback) */
@@ -697,18 +719,22 @@ uint8_t cc1101_setpower(struct cc1101_dev_s * dev, uint8_t power)
/* On error, report that as zero power */ /* On error, report that as zero power */
if (cc1101_access(dev, CC1101_FREND0, &power, -1) < 0) if (cc1101_access(dev, CC1101_FREND0, &power, -1) < 0)
{
dev->power = 0; dev->power = 0;
}
return dev->power; return dev->power;
} }
int cc1101_calcRSSIdBm(int rssi) int cc1101_calcRSSIdBm(int rssi)
{ {
if (rssi >= 128) rssi -= 256; if (rssi >= 128)
return (rssi >> 1) - 74; {
rssi -= 256;
} }
return (rssi >> 1) - 74;
}
int cc1101_receive(struct cc1101_dev_s * dev) int cc1101_receive(struct cc1101_dev_s * dev)
{ {
@@ -723,24 +749,32 @@ int cc1101_receive(struct cc1101_dev_s * dev)
return 0; return 0;
} }
int cc1101_read(struct cc1101_dev_s * dev, uint8_t * buf, size_t size) int cc1101_read(struct cc1101_dev_s * dev, uint8_t * buf, size_t size)
{ {
ASSERT(dev); ASSERT(dev);
if (buf==NULL) { if (buf==NULL)
if (size==0) return 64; {
// else received packet size if (size==0)
{
return 64;
}
/* else received packet size */
return 0; return 0;
} }
if (cc1101_interrupt == 0) return 0; if (cc1101_interrupt == 0)
{
return 0;
}
int status = cc1101_strobe(dev, CC1101_SNOP | CC1101_READ_SINGLE); int status = cc1101_strobe(dev, CC1101_SNOP | CC1101_READ_SINGLE);
if (status & CC1101_STATUS_FIFO_BYTES_AVAILABLE_BM && if (status & CC1101_STATUS_FIFO_BYTES_AVAILABLE_BM &&
(status & CC1101_STATE_MASK) == CC1101_STATE_IDLE) { (status & CC1101_STATE_MASK) == CC1101_STATE_IDLE)
{
uint8_t nbytes; uint8_t nbytes;
cc1101_access(dev, CC1101_RXFIFO, &nbytes, 1); cc1101_access(dev, CC1101_RXFIFO, &nbytes, 1);
@@ -753,7 +787,8 @@ int cc1101_read(struct cc1101_dev_s * dev, uint8_t * buf, size_t size)
* or if there is a BAD CRC * or if there is a BAD CRC
*/ */
if (nbytes > size || (nbytes <= size && !(buf[nbytes-1]&0x80)) ) { if (nbytes > size || (nbytes <= size && !(buf[nbytes-1]&0x80)))
{
printf("Flushing RX FIFO\n"); printf("Flushing RX FIFO\n");
cc1101_strobe(dev, CC1101_SFRX); cc1101_strobe(dev, CC1101_SFRX);
} }
@@ -764,7 +799,6 @@ int cc1101_read(struct cc1101_dev_s * dev, uint8_t * buf, size_t size)
return 0; return 0;
} }
int cc1101_write(struct cc1101_dev_s * dev, const uint8_t * buf, size_t size) int cc1101_write(struct cc1101_dev_s * dev, const uint8_t * buf, size_t size)
{ {
uint8_t packetlen; uint8_t packetlen;
@@ -772,12 +806,21 @@ int cc1101_write(struct cc1101_dev_s * dev, const uint8_t * buf, size_t size)
ASSERT(dev); ASSERT(dev);
ASSERT(buf); ASSERT(buf);
if (dev->flags & FLAGS_RXONLY) return -EPERM; if (dev->flags & FLAGS_RXONLY)
{
return -EPERM;
}
/* Present limit */ /* Present limit */
if (size > CC1101_PACKET_MAXDATALEN) if (size > CC1101_PACKET_MAXDATALEN)
{
packetlen = CC1101_PACKET_MAXDATALEN; packetlen = CC1101_PACKET_MAXDATALEN;
else packetlen = size; }
else
{
packetlen = size;
}
cc1101_access(dev, CC1101_TXFIFO, &packetlen, -1); cc1101_access(dev, CC1101_TXFIFO, &packetlen, -1);
cc1101_access(dev, CC1101_TXFIFO, buf, -size); cc1101_access(dev, CC1101_TXFIFO, buf, -size);
@@ -785,12 +828,14 @@ int cc1101_write(struct cc1101_dev_s * dev, const uint8_t * buf, size_t size)
return 0; return 0;
} }
int cc1101_send(struct cc1101_dev_s * dev) int cc1101_send(struct cc1101_dev_s * dev)
{ {
ASSERT(dev); ASSERT(dev);
if (dev->flags & FLAGS_RXONLY) return -EPERM; if (dev->flags & FLAGS_RXONLY)
{
return -EPERM;
}
cc1101_interrupt = 0; cc1101_interrupt = 0;
@@ -803,7 +848,6 @@ int cc1101_send(struct cc1101_dev_s * dev)
return 0; return 0;
} }
int cc1101_idle(struct cc1101_dev_s * dev) int cc1101_idle(struct cc1101_dev_s * dev)
{ {
ASSERT(dev); ASSERT(dev);
@@ -1,113 +0,0 @@
/****************************************************************************
* drivers/wireless/cc1101/ISM1_868MHzGFSK100kbps.c
*
* Copyright (C) 2011 Uros Platise. All rights reserved.
* Copyright (C) 2011 Ales Verbic. All rights reserved.
*
* Authors: Uros Platise <uros.platise@isotel.eu>
* Ales Verbic <ales.verbic@isotel.eu>
*
* 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 <nuttx/wireless/cc1101.h>
/** Settings for 868 MHz, GFSK at 100kbps
*
* ISM Region 1 (Europe) only, Band 868870 MHz
*
* Frequency ERP Duty Cycle Bandwidth Remarks
* 868 868.6 MHz +14 dBm < 1% No limits
* 868.7 869.2 MHz +14 dBm < 0.1% No limits
* 869.3 869.4 MHz +10 dBm No limits < 25 kHz Appropriate access protocol required
* 869.4 869.65 MHz +27 dBm < 10% < 25 kHz Channels may be combined to one high speed channel
* 869.7 -870 MHz +7 dBm No limits No limits
*
* Deviation = 46.142578
* Base frequency = 867.999985
* Carrier frequency = 867.999985
* Channel number = 0
* Carrier frequency = 867.999985
* Modulated = true
* Modulation format = GFSK
* Manchester enable = false
* Sync word qualifier mode = 30/32 sync word bits detected
* Preamble count = 4
* Channel spacing = 199.813843
* Carrier frequency = 867.999985
* Data rate = 99.9069
* RX filter BW = 210.937500
* Data format = Normal mode
* Length config = Fixed packet length mode. Length configured in PKTLEN register
* CRC enable = true
* Packet length = 62
* Device address = 00
* Address config = NO Address check, no broadcast
* CRC autoflush = true
* PA ramping = false
* TX power = 0
*/
const struct c1101_rfsettings_s cc1101_rfsettings_ISM1_868MHzGFSK100kbps = {
.FSCTRL1 = 0x08, // FSCTRL1 Frequency Synthesizer Control
.FSCTRL0 = 0x00, // FSCTRL0 Frequency Synthesizer Control
.FREQ2 = 0x20, // FREQ2 Frequency Control Word, High Byte
.FREQ1 = 0x25, // FREQ1 Frequency Control Word, Middle Byte
.FREQ0 = 0xED, // FREQ0 Frequency Control Word, Low Byte
.MDMCFG4 = 0x8B, // MDMCFG4 Modem Configuration
.MDMCFG3 = 0xE5, // MDMCFG3 Modem Configuration
.MDMCFG2 = 0x13, // MDMCFG2 Modem Configuration
.MDMCFG1 = 0x22, // MDMCFG1 Modem Configuration
.MDMCFG0 = 0xE5, // MDMCFG0 Modem Configuration
.DEVIATN = 0x46, // DEVIATN Modem Deviation Setting
.FOCCFG = 0x1D, // FOCCFG Frequency Offset Compensation Configuration
.BSCFG = 0x1C, // BSCFG Bit Synchronization Configuration
.AGCCTRL2= 0xC7, // AGCCTRL2 AGC Control
.AGCCTRL1= 0x00, // AGCCTRL1 AGC Control
.AGCCTRL0= 0xB2, // AGCCTRL0 AGC Control
.FREND1 = 0xB6, // FREND1 Front End RX Configuration
.FREND0 = 0x10, // FREND0 Front End TX Configuration
.FSCAL3 = 0xEA, // FSCAL3 Frequency Synthesizer Calibration
.FSCAL2 = 0x2A, // FSCAL2 Frequency Synthesizer Calibration
.FSCAL1 = 0x00, // FSCAL1 Frequency Synthesizer Calibration
.FSCAL0 = 0x1F, // FSCAL0 Frequency Synthesizer Calibration
.CHMIN = 0, // Fix at 9th channel: 869.80 MHz +- 100 kHz RF Bandwidth
.CHMAX = 9, // single channel
.PAMAX = 8, // 0 means power OFF, 8 represents PA[7]
.PA = {0x03, 0x0F, 0x1E, 0x27, 0x67, 0x50, 0x81, 0xC2}
};
@@ -1,111 +0,0 @@
/****************************************************************************
* drivers/wireless/cc1101/ISM2_905MHzGFSK250kbps.c
*
* Copyright (C) 2011 Uros Platise. All rights reserved.
* Copyright (C) 2011 Ales Verbic. All rights reserved.
*
* Authors: Uros Platise <uros.platise@isotel.eu>
* Ales Verbic <ales.verbic@isotel.eu>
*
* 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 <nuttx/wireless/cc1101.h>
/** Settings for 905 MHz, GFSK at 250kbps
*
* ISM Region 2 (America) only, Band 902928 MHz
*
* Cordless phones 1 W
* Microwave ovens 750 W
* Industrial heaters 100 kW
* Military radar 1000 kW
*
* Deviation = 126.953125
* Base frequency = 901.999969
* Carrier frequency = 905.998993
* Channel number = 20
* Carrier frequency = 905.998993
* Modulated = true
* Modulation format = GFSK
* Manchester enable = false
* Sync word qualifier mode = 30/32 sync word bits detected
* Preamble count = 4
* Channel spacing = 199.951172
* Carrier frequency = 905.998993
* Data rate = 249.939
* RX filter BW = 541.666667
* Data format = Normal mode
* Length config = Variable packet length mode. Packet length configured by the first byte after sync word
* CRC enable = true
* Packet length = 61
* Device address = 0
* Address config = No address check
* CRC autoflush = false
* PA ramping = false
* TX power = 0
*/
const struct c1101_rfsettings_s cc1101_rfsettings_ISM2_905MHzGFSK250kbps = {
.FSCTRL1 = 0x0C, // FSCTRL1 Frequency Synthesizer Control
.FSCTRL0 = 0x00, // FSCTRL0 Frequency Synthesizer Control
.FREQ2 = 0x22, // FREQ2 Frequency Control Word, High Byte
.FREQ1 = 0xB1, // FREQ1 Frequency Control Word, Middle Byte
.FREQ0 = 0x3B, // FREQ0 Frequency Control Word, Low Byte
.MDMCFG4 = 0x2D, // MDMCFG4 Modem Configuration
.MDMCFG3 = 0x3B, // MDMCFG3 Modem Configuration
.MDMCFG2 = 0x13, // MDMCFG2 Modem Configuration
.MDMCFG1 = 0x22, // MDMCFG1 Modem Configuration
.MDMCFG0 = 0xF8, // MDMCFG0 Modem Configuration
.DEVIATN = 0x62, // DEVIATN Modem Deviation Setting
.FOCCFG = 0x1D, // FOCCFG Frequency Offset Compensation Configuration
.BSCFG = 0x1C, // BSCFG Bit Synchronization Configuration
.AGCCTRL2= 0xC7, // AGCCTRL2 AGC Control
.AGCCTRL1= 0x00, // AGCCTRL1 AGC Control
.AGCCTRL0= 0xB0, // AGCCTRL0 AGC Control
.FREND1 = 0xB6, // FREND1 Front End RX Configuration
.FREND0 = 0x10, // FREND0 Front End TX Configuration
.FSCAL3 = 0xEA, // FSCAL3 Frequency Synthesizer Calibration
.FSCAL2 = 0x2A, // FSCAL2 Frequency Synthesizer Calibration
.FSCAL1 = 0x00, // FSCAL1 Frequency Synthesizer Calibration
.FSCAL0 = 0x1F, // FSCAL0 Frequency Synthesizer Calibration
.CHMIN = 0, // VERIFY REGULATIONS!
.CHMAX = 0xFF,
.PAMAX = 8, // 0 means power OFF, 8 represents PA[7]
.PA = {0x03, 0x0E, 0x1E, 0x27, 0x39, 0x8E, 0xCD, 0xC0}
};
-4
View File
@@ -1,4 +0,0 @@
#
# For a description of the syntax of this configuration file,
# see misc/tools/kconfig-language.txt.
#
File diff suppressed because it is too large Load Diff
+183
View File
@@ -0,0 +1,183 @@
/****************************************************************************
* include/nuttx/drivers/wireless/nrf24l01.h
*
* Copyright (C) 2013 Laurent Latil
* Author: Laurent Latil <laurent@latil.nom.fr>
*
* 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 __DRIVERS_WIRELESS_NRF24L01_H
#define __DRIVERS_WIRELESS_NRF24L01_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/spi.h>
#include <nuttx/irq.h>
#include <nuttx/wireless/wireless.h>
#include <stdint.h>
#include <stdbool.h>
/****************************************************************************
* Pre-Processor Declarations
****************************************************************************/
/* nRF24L01 hardware definitions */
/* Commands */
#define NRF24L01_R_REGISTER 0x00
#define NRF24L01_W_REGISTER 0x20
#define NRF24L01_R_RX_PAYLOAD 0x61
#define NRF24L01_W_TX_PAYLOAD 0xA0
#define NRF24L01_FLUSH_TX 0xE1
#define NRF24L01_FLUSH_RX 0xE2
#define NRF24L01_REUSE_TX_PL 0xE3
#define NRF24L01_ACTIVATE 0x50
#define NRF24L01_R_RX_PL_WID 0x60
#define NRF24L01_W_TX_PAYLOAD_NOACK 0xB0
#define NRF24L01_W_ACK_PAYLOAD 0xA8
#define NRF24L01_NOP 0xFF
/* Registers */
#define NRF24L01_CONFIG 0x00
#define NRF24L01_EN_AA 0x01
#define NRF24L01_EN_RXADDR 0x02
#define NRF24L01_SETUP_AW 0x03
#define NRF24L01_SETUP_RETR 0x04
#define NRF24L01_RF_CH 0x05
#define NRF24L01_RF_SETUP 0x06
#define NRF24L01_STATUS 0x07
#define NRF24L01_OBSERVE_TX 0x08
#define NRF24L01_CD 0x09
#define NRF24L01_RX_ADDR_P0 0x0A
#define NRF24L01_RX_ADDR_P1 0x0B
#define NRF24L01_RX_ADDR_P2 0x0C
#define NRF24L01_RX_ADDR_P3 0x0D
#define NRF24L01_RX_ADDR_P4 0x0E
#define NRF24L01_RX_ADDR_P5 0x0F
#define NRF24L01_TX_ADDR 0x10
#define NRF24L01_RX_PW_P0 0x11
#define NRF24L01_RX_PW_P1 0x12
#define NRF24L01_RX_PW_P2 0x13
#define NRF24L01_RX_PW_P3 0x14
#define NRF24L01_RX_PW_P4 0x15
#define NRF24L01_RX_PW_P5 0x16
#define NRF24L01_FIFO_STATUS 0x17
#define NRF24L01_DYNPD 0x1C
#define NRF24L01_FEATURE 0x1D
/* STATUS register definitions */
#define NRF24L01_RX_DR (1 << 6)
#define NRF24L01_TX_DS (1 << 5)
#define NRF24L01_MAX_RT (1 << 4)
#define NRF24L01_RX_P_NO_SHIFT 1
#define NRF24L01_RX_P_NO_MASK (7 << NRF24L01_RX_P_NO_SHIFT)
#define NRF24L01_STAT_TX_FULL (1 << 0)
/* CONFIG register definitions */
#define NRF24L01_MASK_RX_DR (1 << 6)
#define NRF24L01_MASK_TX_DS (1 << 5)
#define NRF24L01_MASK_MAX_RT (1 << 4)
#define NRF24L01_EN_CRC (1 << 3)
#define NRF24L01_CRCO (1 << 2)
#define NRF24L01_PWR_UP (1 << 1)
#define NRF24L01_PRIM_RX (1 << 0)
/* RF_SETUP register definition */
#define NRF24L01_CONT_WAVE (1 << 7)
#define NRF24L01_RF_DR_LOW (1 << 5)
#define NRF24L01_PLL_LOCK (1 << 4)
#define NRF24L01_RF_DR_HIGH (1 << 3)
#define NRF24L01_RF_PWR_SHIFT 1
#define NRF24L01_RF_PWR_MASK (3 << NRF24L01_RF_PWR_SHIFT)
/* FIFO STATUS register definitions */
#define NRF24L01_TX_REUSE (1 << 6)
#define NRF24L01_TX_FULL (1 << 5)
#define NRF24L01_TX_EMPTY (1 << 4)
#define NRF24L01_RX_FULL (1 << 1)
#define NRF24L01_RX_EMPTY (1 << 0)
/* SETUP_RETR */
#define NRF24L01_ARC_SHIFT 0
#define NRF24L01_ARC_MASK (0xF << NRF24L01_ARC_SHIFT)
#define NRF24L01_ARD_SHIFT 4
#define NRF24L01_ARD_MASK (0xF << NRF24L01_ARD_SHIFT)
/* OBSERVE_TX register definitions */
#define NRF24L01_PLOS_CNT_SHIFT 4
#define NRF24L01_PLOS_CNT_MASK (0xF << NRF24L01_PLOS_CNT_SHIFT)
#define NRF24L01_ARC_CNT_SHIFT 0
#define NRF24L01_ARC_CNT_MASK (0xF << NRF24L01_ARC_CNT_SHIFT)
#define NRF24L01_RX_P_NO_SHIFT 1
#define NRF24L01_RX_P_NO_MASK (7 << NRF24L01_RX_P_NO_SHIFT)
/* FEATURE register definitions */
#define NRF24L01_EN_DPL (1 << 2)
#define NRF24L01_EN_ACK_PAY (1 << 1)
#define NRF24L01_EN_DYN_ACK (1 << 0)
/****************************************************************************
* Public Data Types
****************************************************************************/
#undef EXTERN
#if defined(__cplusplus)
# define EXTERN extern "C"
extern "C"
{
#else
# define EXTERN extern
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
#undef EXTERN
#if defined(__cplusplus)
}
#endif
#endif /* __DRIVERS_WIRELESS_NRF24L01_H */
+7
View File
@@ -68,6 +68,7 @@
#define _QEIOCBASE (0x0f00) /* Quadrature encoder ioctl commands */ #define _QEIOCBASE (0x0f00) /* Quadrature encoder ioctl commands */
#define _AUDIOIOCBASE (0x1000) /* Audio ioctl commands */ #define _AUDIOIOCBASE (0x1000) /* Audio ioctl commands */
#define _SLCDIOCBASE (0x1100) /* Segment LCD ioctl commands */ #define _SLCDIOCBASE (0x1100) /* Segment LCD ioctl commands */
#define _WLIOCBASE (0x1100) /* Wireless modules ioctl commands */
/* Macros used to manage ioctl commands */ /* Macros used to manage ioctl commands */
@@ -246,6 +247,12 @@
#define _SLCDIOCVALID(c) (_IOC_TYPE(c)==_SLCDIOCBASE) #define _SLCDIOCVALID(c) (_IOC_TYPE(c)==_SLCDIOCBASE)
#define _SLCDIOC(nr) _IOC(_SLCDIOCBASE,nr) #define _SLCDIOC(nr) _IOC(_SLCDIOCBASE,nr)
/* Wireless driver ioctl definitions ************************************/
/* (see nuttx/include/wireless/wireless.h */
#define _WLIOCVALID(c) (_IOC_TYPE(c)==_WLIOCBASE)
#define _WLIOC(nr) _IOC(_WLIOCBASE,nr)
/**************************************************************************** /****************************************************************************
* Public Type Definitions * Public Type Definitions
****************************************************************************/ ****************************************************************************/
+98 -53
View File
@@ -2,7 +2,6 @@
* include/nuttx/wireless/cc1101.h * include/nuttx/wireless/cc1101.h
* *
* Copyright (C) 2011 Uros Platise. All rights reserved. * Copyright (C) 2011 Uros Platise. All rights reserved.
*
* Authors: Uros Platise <uros.platise@isotel.eu> * Authors: Uros Platise <uros.platise@isotel.eu>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -34,14 +33,13 @@
* *
****************************************************************************/ ****************************************************************************/
/** \file
* \author Uros Platise
* \brief Chipcon CC1101 Device Driver
**/
#ifndef __INCLUDE_NUTTX_WIRELESS_CC1101_H #ifndef __INCLUDE_NUTTX_WIRELESS_CC1101_H
#define __INCLUDE_NUTTX_WIRELESS_CC1101_H #define __INCLUDE_NUTTX_WIRELESS_CC1101_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h> #include <nuttx/config.h>
#include <nuttx/spi.h> #include <nuttx/spi.h>
@@ -69,35 +67,49 @@
/* Associated to the RX FIFO: Asserts when RX FIFO is filled at or above /* Associated to the RX FIFO: Asserts when RX FIFO is filled at or above
* the RX FIFO threshold. De-asserts when RX FIFO is drained below the * the RX FIFO threshold. De-asserts when RX FIFO is drained below the
* same threshold. */ * same threshold.
*/
#define CC1101_GDO_RXFIFO_THR 0x00 #define CC1101_GDO_RXFIFO_THR 0x00
/* Associated to the RX FIFO: Asserts when RX FIFO is filled at or above /* Associated to the RX FIFO: Asserts when RX FIFO is filled at or above
* the RX FIFO threshold or the end of packet is reached. De-asserts when * the RX FIFO threshold or the end of packet is reached. De-asserts when
* the RX FIFO is empty. */ * the RX FIFO is empty.
*/
#define CC1101_GDO_RXFIFO_THREND 0x01 #define CC1101_GDO_RXFIFO_THREND 0x01
/* Associated to the TX FIFO: Asserts when the TX FIFO is filled at or /* Associated to the TX FIFO: Asserts when the TX FIFO is filled at or
* above the TX FIFO threshold. De-asserts when the TX FIFO is below the * above the TX FIFO threshold. De-asserts when the TX FIFO is below the
* same threshold. */ * same threshold.
*/
#define CC1101_GDO_TXFIFO_THR 0x02 #define CC1101_GDO_TXFIFO_THR 0x02
/* Associated to the TX FIFO: Asserts when TX FIFO is full. De-asserts /* Associated to the TX FIFO: Asserts when TX FIFO is full. De-asserts
* when the TX FIFO is drained below theTX FIFO threshold. */ * when the TX FIFO is drained below theTX FIFO threshold.
*/
#define CC1101_GDO_TXFIFO_FULL 0x03 #define CC1101_GDO_TXFIFO_FULL 0x03
/* Asserts when the RX FIFO has overflowed. De-asserts when the FIFO has /* Asserts when the RX FIFO has overflowed. De-asserts when the FIFO has
* been flushed. */ * been flushed.
*/
#define CC1101_GDO_RXFIFO_OVR 0x04 #define CC1101_GDO_RXFIFO_OVR 0x04
/* Asserts when the TX FIFO has underflowed. De-asserts when the FIFO is /* Asserts when the TX FIFO has underflowed. De-asserts when the FIFO is
* flushed. */ * flushed.
*/
#define CC1101_GDO_TXFIFO_UNR 0x05 #define CC1101_GDO_TXFIFO_UNR 0x05
/* Asserts when sync word has been sent / received, and de-asserts at the /* Asserts when sync word has been sent / received, and de-asserts at the
* end of the packet. In RX, the pin will de-assert when the optional * end of the packet. In RX, the pin will de-assert when the optional
* address check fails or the RX FIFO overflows. In TX the pin will * address check fails or the RX FIFO overflows. In TX the pin will
* de-assert if the TX FIFO underflows. */ * de-assert if the TX FIFO underflows.
*/
#define CC1101_GDO_SYNC 0x06 #define CC1101_GDO_SYNC 0x06
/* Asserts when a packet has been received with CRC OK. De-asserts when /* Asserts when a packet has been received with CRC OK. De-asserts when
@@ -105,60 +117,83 @@
#define CC1101_GDO_PKTRCV_CRCOK 0x07 #define CC1101_GDO_PKTRCV_CRCOK 0x07
/* Preamble Quality Reached. Asserts when the PQI is above the programmed /* Preamble Quality Reached. Asserts when the PQI is above the programmed
* PQT value. */ * PQT value.
*/
#define CC1101_GDO_PREAMBLE 0x08 #define CC1101_GDO_PREAMBLE 0x08
/* Clear channel assessment. High when RSSI level is below threshold /* Clear channel assessment. High when RSSI level is below threshold
* (dependent on the current CCA_MODE setting). */ * (dependent on the current CCA_MODE setting).
*/
#define CC1101_GDO_CHCLEAR 0x09 #define CC1101_GDO_CHCLEAR 0x09
/* Lock detector output. The PLL is in lock if the lock detector output /* Lock detector output. The PLL is in lock if the lock detector output
* has a positive transition or is constantly logic high. To check for * has a positive transition or is constantly logic high. To check for
* PLL lock the lock detector output should be used as an interrupt for * PLL lock the lock detector output should be used as an interrupt for
* the MCU. */ * the MCU.
*/
#define CC1101_GDO_LOCK 0x0A #define CC1101_GDO_LOCK 0x0A
/* Serial Clock. Synchronous to the data in synchronous serial mode. /* Serial Clock. Synchronous to the data in synchronous serial mode.
* In RX mode, data is set up on the falling edge by CC1101 when GDOx_INV=0. * In RX mode, data is set up on the falling edge by CC1101 when GDOx_INV=0.
* In TX mode, data is sampled by CC1101 on the rising edge of the serial * In TX mode, data is sampled by CC1101 on the rising edge of the serial
* clock when GDOx_INV=0. */ * clock when GDOx_INV=0.
*/
#define CC1101_GDO_SSCLK 0x0B #define CC1101_GDO_SSCLK 0x0B
/* Serial Synchronous Data Output. Used for synchronous serial mode. */ /* Serial Synchronous Data Output. Used for synchronous serial mode. */
#define CC1101_GDO_SSDO 0x0C #define CC1101_GDO_SSDO 0x0C
/* Serial Data Output. Used for asynchronous serial mode. */ /* Serial Data Output. Used for asynchronous serial mode. */
#define CC1101_GDO_ASDO 0x0D #define CC1101_GDO_ASDO 0x0D
/* Carrier sense. High if RSSI level is above threshold. */ /* Carrier sense. High if RSSI level is above threshold. */
#define CC1101_GDO_CARRIER 0x0E #define CC1101_GDO_CARRIER 0x0E
/* CRC_OK. The last CRC comparison matched. Cleared when entering or /* CRC_OK. The last CRC comparison matched. Cleared when entering or
* restarting RX mode. */ * restarting RX mode.
*/
#define CC1101_GDO_CRCOK 0x0F #define CC1101_GDO_CRCOK 0x0F
/* RX_HARD_DATA[1]. Can be used together with RX_SYMBOL_TICK for /* RX_HARD_DATA[1]. Can be used together with RX_SYMBOL_TICK for
* alternative serial RX output. */ * alternative serial RX output.
*/
#define CC1101_GDO_RXOUT1 0x16 #define CC1101_GDO_RXOUT1 0x16
/* RX_HARD_DATA[0]. Can be used together with RX_SYMBOL_TICK for /* RX_HARD_DATA[0]. Can be used together with RX_SYMBOL_TICK for
* alternative serial RX output. */ * alternative serial RX output.
*/
#define CC1101_GDO_RXOUT0 0x17 #define CC1101_GDO_RXOUT0 0x17
/* PA_PD. Note: PA_PD will have the same signal level in SLEEP and TX /* PA_PD. Note: PA_PD will have the same signal level in SLEEP and TX
* states. To control an external PA or RX/TX switch in applications * states. To control an external PA or RX/TX switch in applications
* where the SLEEP state is used it is recommended to use GDOx_CFGx=0x2F * where the SLEEP state is used it is recommended to use GDOx_CFGx=0x2F
* instead. */ * instead.
*/
#define CC1101_GDO_PA_PD 0x1B #define CC1101_GDO_PA_PD 0x1B
/* LNA_PD. Note: LNA_PD will have the same signal level in SLEEP and RX /* LNA_PD. Note: LNA_PD will have the same signal level in SLEEP and RX
* states. To control an external LNA or RX/TX switch in applications * states. To control an external LNA or RX/TX switch in applications
* where the SLEEP state is used it is recommended to use GDOx_CFGx=0x2F * where the SLEEP state is used it is recommended to use GDOx_CFGx=0x2F
* instead. */ * instead.
*/
#define CC1101_GDO_LNA_PD 0x1C #define CC1101_GDO_LNA_PD 0x1C
/* RX_SYMBOL_TICK. Can be used together with RX_HARD_DATA for alternative /* RX_SYMBOL_TICK. Can be used together with RX_HARD_DATA for alternative
* serial RX output. */ * serial RX output.
*/
#define CC1101_GDO_RXSYMTICK 0x1D #define CC1101_GDO_RXSYMTICK 0x1D
#define CC1101_GDO_WOR_EVNT0 0x24 #define CC1101_GDO_WOR_EVNT0 0x24
@@ -168,14 +203,19 @@
#define CC1101_GDO_XOSC_STABLE 0x2B #define CC1101_GDO_XOSC_STABLE 0x2B
/* GDO0_Z_EN_N. When this output is 0, GDO0 is configured as input /* GDO0_Z_EN_N. When this output is 0, GDO0 is configured as input
* (for serial TX data). */ * (for serial TX data).
*/
#define CC1101_GDO_GDO0_Z_EN_N 0x2D #define CC1101_GDO_GDO0_Z_EN_N 0x2D
/* High impedance (3-state). */ /* High impedance (3-state). */
#define CC1101_GDO_HIZ 0x2E #define CC1101_GDO_HIZ 0x2E
/* HW to 0 (HW1 achieved by setting GDOx_INV=1). Can be used to control /* HW to 0 (HW1 achieved by setting GDOx_INV=1). Can be used to control
* an external LNA/PA or RX/TX switch. */ * an external LNA/PA or RX/TX switch.
*/
#define CC1101_GDO_HW 0x2F #define CC1101_GDO_HW 0x2F
/* There are 3 GDO pins, but only one CLK_XOSC/n can be selected as an /* There are 3 GDO pins, but only one CLK_XOSC/n can be selected as an
@@ -183,7 +223,9 @@
* GDO pins, the other two GDO pins must be configured to values less * GDO pins, the other two GDO pins must be configured to values less
* than 0x30. The GDO0 default value is CLK_XOSC/192. To optimize RF * than 0x30. The GDO0 default value is CLK_XOSC/192. To optimize RF
* performance, these signals should not be used while the radio is * performance, these signals should not be used while the radio is
* in RX or TX mode. */ * in RX or TX mode.
*/
#define CC1101_GDO_CLK_XOSC1 0x30 #define CC1101_GDO_CLK_XOSC1 0x30
#define CC1101_GDO_CLK_XOSC1_5 0x31 #define CC1101_GDO_CLK_XOSC1_5 0x31
#define CC1101_GDO_CLK_XOSC2 0x32 #define CC1101_GDO_CLK_XOSC2 0x32
@@ -201,9 +243,11 @@
#define CC1101_GDO_CLK_XOSC128 0x3E #define CC1101_GDO_CLK_XOSC128 0x3E
#define CC1101_GDO_CLK_XOSC192 0x3F #define CC1101_GDO_CLK_XOSC192 0x3F
/****************************************************************************
* Public Data Types
****************************************************************************/
#ifndef __ASSEMBLY__ #ifndef __ASSEMBLY__
#undef EXTERN #undef EXTERN
#if defined(__cplusplus) #if defined(__cplusplus)
#define EXTERN extern "C" #define EXTERN extern "C"
@@ -212,17 +256,15 @@ extern "C" {
#define EXTERN extern #define EXTERN extern
#endif #endif
/****************************************************************************
* Public Data Types
****************************************************************************/
struct cc1101_dev_s; struct cc1101_dev_s;
/** The RF Settings includes only those fields required to configure /* The RF Settings includes only those fields required to configure
* the RF radio. Other configuration fields depended on this driver * the RF radio. Other configuration fields depended on this driver
* are configured by the cc1101_init(). * are configured by the cc1101_init().
*/ */
struct c1101_rfsettings_s {
struct c1101_rfsettings_s
{
uint8_t FSCTRL1; /* Frequency synthesizer control. */ uint8_t FSCTRL1; /* Frequency synthesizer control. */
uint8_t FSCTRL0; /* Frequency synthesizer control. */ uint8_t FSCTRL0; /* Frequency synthesizer control. */
@@ -268,16 +310,14 @@ struct c1101_rfsettings_s {
* output power values as: * output power values as:
* PA = {-30, -20, -15, -10, -5, 0, 5, 10} [dBm] * PA = {-30, -20, -15, -10, -5, 0, 5, 10} [dBm]
*/ */
uint8_t PA[8]; uint8_t PA[8];
}; };
/**************************************************************************** /****************************************************************************
* RF Configuration Database * RF Configuration Database
****************************************************************************/ ****************************************************************************/
EXTERN const struct c1101_rfsettings_s
// \todo Recalculate ERP in maximum power level // \todo Recalculate ERP in maximum power level
/* 868 MHz, GFSK, 100 kbps, ISM Region 1 (Europe only) /* 868 MHz, GFSK, 100 kbps, ISM Region 1 (Europe only)
@@ -312,8 +352,8 @@ EXTERN const struct c1101_rfsettings_s
* Reference: TI Application Report: swra048.pdf, May 2005 * Reference: TI Application Report: swra048.pdf, May 2005
* ISM-Band and Short Range Device Regulatory Compliance Overview * ISM-Band and Short Range Device Regulatory Compliance Overview
*/ */
cc1101_rfsettings_ISM1_868MHzGFSK100kbps,
EXTERN const struct c1101_rfsettings_s cc1101_rfsettings_ISM1_868MHzGFSK100kbps;
/* 905 MHz, GFSK, 250 kbps, ISM Region 2 (America only) /* 905 MHz, GFSK, 250 kbps, ISM Region 2 (America only)
* *
@@ -324,8 +364,8 @@ EXTERN const struct c1101_rfsettings_s
* Industrial heaters 100 kW * Industrial heaters 100 kW
* Military radar 1000 kW * Military radar 1000 kW
*/ */
cc1101_rfsettings_ISM2_905MHzGFSK250kbps;
EXTERN const struct c1101_rfsettings_s cc1101_rfsettings_ISM2_905MHzGFSK250kbps;
/**************************************************************************** /****************************************************************************
* Public Function Prototypes * Public Function Prototypes
@@ -346,9 +386,9 @@ EXTERN const struct c1101_rfsettings_s
* - ENOMEM: Out of kernel memory to allocate the device * - ENOMEM: Out of kernel memory to allocate the device
* - EBUSY: When device is already addressed by other device driver (not yet supported by low-level driver) * - EBUSY: When device is already addressed by other device driver (not yet supported by low-level driver)
**/ **/
EXTERN struct cc1101_dev_s * cc1101_init(struct spi_dev_s * spi, uint8_t isrpin,
uint32_t pinset, const struct c1101_rfsettings_s * rfsettings);
struct cc1101_dev_s * cc1101_init(struct spi_dev_s * spi, uint8_t isrpin,
uint32_t pinset, const struct c1101_rfsettings_s * rfsettings);
/** Deinitialize Chipcon CC1101 Chip /** Deinitialize Chipcon CC1101 Chip
* *
@@ -356,20 +396,24 @@ EXTERN struct cc1101_dev_s * cc1101_init(struct spi_dev_s * spi, uint8_t isrpin,
* \return OK On success * \return OK On success
* *
**/ **/
EXTERN int cc1101_deinit(struct cc1101_dev_s * dev);
int cc1101_deinit(struct cc1101_dev_s * dev);
/** Power up device, start conversion. \return Zero on success. */ /** Power up device, start conversion. \return Zero on success. */
EXTERN int cc1101_powerup(struct cc1101_dev_s * dev);
int cc1101_powerup(struct cc1101_dev_s * dev);
/** Power down device, stop conversion. \return Zero on success. */ /** Power down device, stop conversion. \return Zero on success. */
EXTERN int cc1101_powerdown(struct cc1101_dev_s * dev);
int cc1101_powerdown(struct cc1101_dev_s * dev);
/** Set Multi Purpose Output Function. \return Zero on success. */ /** Set Multi Purpose Output Function. \return Zero on success. */
EXTERN int cc1101_setgdo(struct cc1101_dev_s * dev, uint8_t pin, uint8_t function);
int cc1101_setgdo(struct cc1101_dev_s * dev, uint8_t pin, uint8_t function);
/** Set RF settings. Use one from the database above. */ /** Set RF settings. Use one from the database above. */
EXTERN int cc1101_setrf(struct cc1101_dev_s * dev, const struct c1101_rfsettings_s *settings);
int cc1101_setrf(struct cc1101_dev_s * dev, const struct c1101_rfsettings_s *settings);
/** Set Channel. /** Set Channel.
* Note that regulatory check is made and sending may be prohibited. * Note that regulatory check is made and sending may be prohibited.
@@ -378,8 +422,8 @@ EXTERN int cc1101_setrf(struct cc1101_dev_s * dev, const struct c1101_rfsettings
* \retval 1 Only receive mode is allowed. * \retval 1 Only receive mode is allowed.
* \retval <0 On error. * \retval <0 On error.
*/ */
EXTERN int cc1101_setchannel(struct cc1101_dev_s * dev, uint8_t channel);
int cc1101_setchannel(struct cc1101_dev_s * dev, uint8_t channel);
/** Set Output Power /** Set Output Power
* *
@@ -392,12 +436,12 @@ EXTERN int cc1101_setchannel(struct cc1101_dev_s * dev, uint8_t channel);
* *
* \return Actual output power in range from 0..8. * \return Actual output power in range from 0..8.
*/ */
EXTERN uint8_t cc1101_setpower(struct cc1101_dev_s * dev, uint8_t power);
uint8_t cc1101_setpower(struct cc1101_dev_s * dev, uint8_t power);
/** Convert RSSI as obtained from CC1101 to [dBm] */ /** Convert RSSI as obtained from CC1101 to [dBm] */
EXTERN int cc1101_calcRSSIdBm(int rssi);
int cc1101_calcRSSIdBm(int rssi);
/** Enter receive mode and wait for a packet. /** Enter receive mode and wait for a packet.
* If transmission is in progress, receive mode is entered upon its * If transmission is in progress, receive mode is entered upon its
@@ -407,8 +451,8 @@ EXTERN int cc1101_calcRSSIdBm(int rssi);
* \param dev Device to CC1101 structure * \param dev Device to CC1101 structure
* \return Zero on success. * \return Zero on success.
*/ */
EXTERN int cc1101_receive(struct cc1101_dev_s * dev);
int cc1101_receive(struct cc1101_dev_s * dev);
/** Read received packet /** Read received packet
* *
@@ -427,8 +471,8 @@ EXTERN int cc1101_receive(struct cc1101_dev_s * dev);
* NOTE: messages length are typically defined by the MAC, transmit/ * NOTE: messages length are typically defined by the MAC, transmit/
* receive windows at some rate. * receive windows at some rate.
*/ */
EXTERN int cc1101_read(struct cc1101_dev_s * dev, uint8_t * buf, size_t size);
int cc1101_read(struct cc1101_dev_s * dev, uint8_t * buf, size_t size);
/** Write data to be send, using the cc1101_send() /** Write data to be send, using the cc1101_send()
* *
@@ -438,27 +482,28 @@ EXTERN int cc1101_read(struct cc1101_dev_s * dev, uint8_t * buf, size_t size);
* Present driver limitation supports a single cc1101_write() * Present driver limitation supports a single cc1101_write()
* prioer cc1101_send() is called. * prioer cc1101_send() is called.
*/ */
EXTERN int cc1101_write(struct cc1101_dev_s * dev, const uint8_t * buf, size_t size);
int cc1101_write(struct cc1101_dev_s * dev, const uint8_t * buf, size_t size);
/** Send data previously writtenusing cc1101_write() /** Send data previously writtenusing cc1101_write()
* *
* \param dev Device to CC1101 structure * \param dev Device to CC1101 structure
* \return Zero on success. * \return Zero on success.
*/ */
EXTERN int cc1101_send(struct cc1101_dev_s * dev);
int cc1101_send(struct cc1101_dev_s * dev);
/** Enter idle state (after reception and transmission completes). /** Enter idle state (after reception and transmission completes).
* *
* \return Zero on success. * \return Zero on success.
*/ */
EXTERN int cc1101_idle(struct cc1101_dev_s * dev);
int cc1101_idle(struct cc1101_dev_s * dev);
#undef EXTERN #undef EXTERN
#if defined(__cplusplus) #if defined(__cplusplus)
} }
#endif #endif
#endif /* __ASSEMBLY__ */ #endif /* __ASSEMBLY__ */
#endif /* __INCLUDE_NUTTX_WIRELESS_CC1101_H */ #endif /* __INCLUDE_NUTTX_WIRELESS_CC1101_H */
+444
View File
@@ -0,0 +1,444 @@
/****************************************************************************
* include/nuttx/wireless/nrf24l01.h
*
* Copyright (C) 2013 Laurent Latil
* Author: Laurent Latil <laurent@latil.nom.fr>
*
* 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_NRF24L01_H
#define __INCLUDE_NUTTX_NRF24L01_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/spi.h>
#include <nuttx/irq.h>
#include <nuttx/wireless/wireless.h>
#include <stdint.h>
#include <stdbool.h>
/****************************************************************************
* Pre-Processor Declarations
****************************************************************************/
#define NRF24L01_MIN_ADDR_LEN 3 /* Minimal length (in bytes) of a pipe address */
#define NRF24L01_MAX_ADDR_LEN 5 /* Maximum length (in bytes) of a pipe address */
#define NRF24L01_MAX_PAYLOAD_LEN 32 /* Maximum length (in bytes) of a payload */
#define NRF24L01_MAX_XMIT_RETR 15 /* Maximum auto retransmit count (for AA transmissions) */
#define NRF24L01_PIPE_COUNT 6 /* Number of available pipes */
#define NRF24L01_MIN_FREQ 2400 /* Lower bound for RF frequency */
#define NRF24L01_MAX_FREQ 2525 /* Upper bound for RF frequency */
#define NRF24L01_DYN_LENGTH 33 /* Specific length value to use to enable dynamic packet length */
#define NRF24L01_XMIT_MAXRT 255 /* Specific value returned by Number of available pipes */
/* #define NRF24L01_DEBUG 1 */
/* IOCTL commands */
#define NRF24L01IOC_SETRETRCFG _WLIOC_USER(0x0001) /* arg: Pointer to nrf24l01_retrcfg_t structure */
#define NRF24L01IOC_GETRETRCFG _WLIOC_USER(0x0002) /* arg: Pointer to nrf24l01_retrcfg_t structure */
#define NRF24L01IOC_SETPIPESCFG _WLIOC_USER(0x0003) /* arg: Pointer to an array of nrf24l01_pipecfg_t pointers */
#define NRF24L01IOC_GETPIPESCFG _WLIOC_USER(0x0004) /* arg: Pointer to an array of nrf24l01_pipecfg_t pointers */
#define NRF24L01IOC_SETPIPESENABLED _WLIOC_USER(0x0005) /* arg: Pointer to a uint8_t value, bit field of enabled / disabled pipes */
#define NRF24L01IOC_GETPIPESENABLED _WLIOC_USER(0x0006) /* arg: Pointer to a uint8_t value, bit field of enabled / disabled pipes */
#define NRF24L01IOC_SETDATARATE _WLIOC_USER(0x0007) /* arg: Pointer to a nrf24l01_datarate_t value */
#define NRF24L01IOC_GETDATARATE _WLIOC_USER(0x0008) /* arg: Pointer to a nrf24l01_datarate_t value */
#define NRF24L01IOC_SETADDRWIDTH _WLIOC_USER(0x0009) /* arg: Pointer to an uint32_t value, width of the address */
#define NRF24L01IOC_GETADDRWIDTH _WLIOC_USER(0x000A) /* arg: Pointer to an uint32_t value, width of the address */
#define NRF24L01IOC_SETSTATE _WLIOC_USER(0x000B) /* arg: Pointer to a nrf24l01_state_t value */
#define NRF24L01IOC_GETSTATE _WLIOC_USER(0x000C) /* arg: Pointer to a nrf24l01_state_t value */
#define NRF24L01IOC_GETLASTXMITCOUNT _WLIOC_USER(0x000D) /* arg: Pointer to an uint32_t value, retransmission count of the last send operation (NRF24L01_XMIT_MAXRT if no ACK received)*/
#define NRF24L01IOC_GETLASTPIPENO _WLIOC_USER(0x000E) /* arg: Pointer to an uint32_t value, pipe # of the last received packet */
/* Aliased name for these commands */
#define NRF24L01IOC_SETTXADDR WLIOC_SETADDR
#define NRF24L01IOC_GETTXADDR WLIOC_GETADDR
/* NRF24L01 debug */
#ifdef NRF24L01_DEBUG
# define wdbg(format, arg...) dbg(format, ##arg)
# define wlldbg(format, arg...) lldbg(format, ##arg)
# define wvdbg(format, arg...) vdbg(format, ##arg)
# define wllvdbg(format, arg...) llvdbg(format, ##arg)
#else
# define wdbg(x...)
# define wlldbg(x...)
# define wvdbg(x...)
# define wllvdbg(x...)
#endif
/****************************************************************************
* Public Data Types
****************************************************************************/
#undef EXTERN
#if defined(__cplusplus)
# define EXTERN extern "C"
extern "C"
{
#else
# define EXTERN extern
#endif
/* Data rates available for transmission */
typedef enum
{
RATE_1Mbps,
RATE_2Mbps,
RATE_250kbps
} nrf24l01_datarate_t;
/* Definition of the different possible states of the module */
typedef enum
{
ST_UNKNOWN,
ST_POWER_DOWN,
ST_STANDBY,
#ifdef CONFIG_WL_NRF24L01_RXSUPPORT
ST_RX
#endif
} nrf24l01_state_t;
/* Re-transmission delay */
typedef enum
{
DELAY_250us,
DELAY_500us,
DELAY_750us,
DELAY_1000us,
DELAY_1250us,
DELAY_1500us,
DELAY_1750us,
DELAY_2000us,
DELAY_2250us,
DELAY_2500us,
DELAY_2750us,
DELAY_3000us,
DELAY_3250us,
DELAY_3500us,
DELAY_3750us,
DELAY_4000us
} nrf24l01_retransmit_delay_t;
/* Opaque definition of a nRF24L01 device */
struct nrf24l01_dev_s;
/* Configuration info for a RX pipe */
struct nrf24l01_pipecfg_s
{
bool en_aa; /* Enable auto-acknowledge */
uint8_t rx_addr[NRF24L01_MAX_ADDR_LEN]; /* Receive address for the data pipe (LSB first) */
uint8_t payload_length; /* Define packet size (NRF24L01_DYN_LENGTH : dynamic length payload ) */
};
typedef struct nrf24l01_pipecfg_s nrf24l01_pipecfg_t;
/* Configuration of the retransmission parameters (used when AA is enabled) */
struct nrf24l01_retrcfg_s
{
nrf24l01_retransmit_delay_t delay; /* Delay before retransmitting (when no ACK received) */
uint8_t count; /* Retransmit retries count */
};
typedef struct nrf24l01_retrcfg_s nrf24l01_retrcfg_t;
/* A reference to a structure of this type must be passed to the initialization
* method (nrf24l01_init() ). It provides some board-specific hooks used
* by driver to manage the GPIO lines (IRQ and CE).
*
* 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.
*/
struct nrf24l01_config_s
{
/* IRQ/GPIO access callbacks. These operations all hidden behind
* callbacks to isolate the ADS7843E 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.
*
* irqattach - Attach the driver interrupt handler to the GPIO interrupt
* chipenable - Enable or disable the chip (CE line)
*/
int (*irqattach)(xcpt_t isr);
void (*chipenable)(bool enable);
};
/************************************************************************************
* Public Functions
************************************************************************************/
/** Register the nRF24L01+ device.
*
* \param spi SPI Device structure
* \param cfg Board specific configuration info
* \return Pointer to newly allocated nrf24l01 device structure or NULL on error (errno is set accordingly in this case).
*
* Possible errors:
* - ENOMEM: Out of kernel memory to allocate the device
**/
int nrf24l01_register(FAR struct spi_dev_s *spi, FAR struct nrf24l01_config_s *cfg);
/** Initialize the nRF24L01+ chip to a default initial state.
*
* \param dev Pointer to a registered nRF24L01 device structure
**/
int nrf24l01_init(FAR struct nrf24l01_dev_s *dev);
/** Get a pointer to the registered device
*/
FAR struct nrf24l01_dev_s * nrf24l01_getinstance(void);
/** Set the default TX address.
*
* \param dev Pointer to an nRF24L01 device structure
* \param addr TX address (LSByte first)
*
* \return 0
**/
int nrf24l01_settxaddr(FAR struct nrf24l01_dev_s *dev, FAR const uint8_t *addr);
/** Get the default TX address.
*
* \param dev Pointer to an nRF24L01 device structure
* \param addr TX address (LSByte first)
*
* \return 0
**/
int nrf24l01_gettxaddr(FAR struct nrf24l01_dev_s *dev, FAR uint8_t *addr);
/** Configure auto-retransmit
*
* \param dev Pointer to an nRF24L01 device structure
* \param retrdelay Auto-retransmit delay
* \param retrcount Auto-retransmit count (0 - 15)
* \return 0
**/
int nrf24l01_setretransmit(FAR struct nrf24l01_dev_s *dev, nrf24l01_retransmit_delay_t retrdelay, uint8_t retrcount);
/** Configure a RX pipe.
*
* \param dev Pointer to an nRF24L01 device structure
* \param pipeno Pipe number to configure
* \param pipecfg Pointer to configuration data
*
* \return 0
**/
int nrf24l01_setpipeconfig(FAR struct nrf24l01_dev_s *dev, unsigned int pipeno,
FAR const nrf24l01_pipecfg_t *pipecfg);
/** Get pipe configuration.
*
* \param dev Pointer to an nRF24L01 device structure
* \param pipeno Pipe number to configure
* \param pipecfg Pointer to configuration data used to store the config
*
* \return 0
**/
int nrf24l01_getpipeconfig(FAR struct nrf24l01_dev_s *dev, unsigned int pipeno,
FAR nrf24l01_pipecfg_t *pipecfg);
/** Enable a RX pipe.
*
* \param dev Pointer to an nRF24L01 device structure
* \param pipeno Pipe number
* \param enable true to enable the pipe, false to disable it
*
* \return 0
**/
int nrf24l01_enablepipe(FAR struct nrf24l01_dev_s *dev, unsigned int pipeno, bool enable);
/** Configure RF.
*
* \param dev Pointer to an nRF24L01 device structure
* \param datarate Datarate
* \param outpower Output power
*
* \return 0
**/
int nrf24l01_setuprf(FAR struct nrf24l01_dev_s *dev, nrf24l01_datarate_t datarate,
int outpower);
/** Configure the TX output power.
*
* Note that hardware supports only -18, -12, -6 and 0 dBm values.
*
* \param dev Pointer to an nRF24L01 device structure
* \param outpower Output power (in dBm).
*
* \return 0
**/
int nrf24l01_settxpower(FAR struct nrf24l01_dev_s *dev, int outpower);
/** Get the current TX output power.
*
* Note that hardware supports only -18, -12, -6 and 0 dBm values.
*
* \param dev Pointer to an nRF24L01 device structure
* \return outpower Output power (in dBm)
**/
int nrf24l01_gettxpower(FAR struct nrf24l01_dev_s *dev);
/** Set transmission data rate
* \param dev Pointer to an nRF24L01 device structure
* \return datarate Data rate
**/
int nrf24l01_setdatarate(FAR struct nrf24l01_dev_s *dev, nrf24l01_datarate_t datarate);
/** Set radio frequency.
*
* \param dev Pointer to an nRF24L01 device structure
* \param freq New frequency value (in Mhz: 2400 to 2525)
*
* \return OK
**/
int nrf24l01_setradiofreq(FAR struct nrf24l01_dev_s *dev, uint32_t freq);
/** Get current radio frequency.
*
* \param dev Pointer to an nRF24L01 device structure
*
* \return Radio frequency (in Mhz)
**/
uint32_t nrf24l01_getradiofreq(FAR struct nrf24l01_dev_s *dev);
/** Configure address length.
*
* \param dev Pointer to an nRF24L01 device structure
* \param width Address width to use (3-5)
* \return 0
**/
int nrf24l01_setaddrwidth(FAR struct nrf24l01_dev_s *dev, uint32_t width);
/** Change the current lifecycle state of the nRF24L01+ chip.
*
* \param dev Pointer to an nRF24L01 device structure
* \param state New state to put the nRF24L01 module into
**/
int nrf24l01_changestate(FAR struct nrf24l01_dev_s *dev, nrf24l01_state_t state);
/** Send data to the default address.
*
* \param dev Pointer to an nRF24L01 device structure
* \param data Pointer on the data buffer
* \param datalen Length of the buffer (in bytes)
*
* \return
**/
int nrf24l01_send(FAR struct nrf24l01_dev_s *dev, FAR const uint8_t *data, size_t datalen);
/** Send data to the specified address.
*
* \param dev Pointer to an nRF24L01 device structure
* \param data Pointer on the data buffer
* \param datalen Length of the buffer (in bytes)
* \param destaddr Destination address
*
* \return
**/
int nrf24l01_sendto(FAR struct nrf24l01_dev_s *dev, FAR const uint8_t *data,
size_t datalen, FAR const uint8_t *destaddr);
/** Get the retransmits count of the last transmission.
* This value is meaningful only if auto-acknowledge is enabled.
*
* \param dev Pointer to an nRF24L01 device structure
* \return Retransmit count, or NRF24L01_XMIT_MAXRT if no ACK received (transmission failure)
*/
int nrf24l01_xmitcount(FAR struct nrf24l01_dev_s *dev);
#ifdef CONFIG_WL_NRF24L01_RXSUPPORT
/** Read the next received frame.
*
* \param dev Pointer to an nRF24L01 device structure
* \param buffer Pointer on buffer used to store the received frame bytes
* \param buflen Length of the buffer (in bytes)
* \param recvpipe Pointer to a byte value used to store the pipe number of the frame
* (use NULL if the pipe number info is not required)
*
* \return Length of the actual data
**/
ssize_t nrf24l01_recv(struct nrf24l01_dev_s *dev, uint8_t *buffer,
size_t buflen, uint8_t *recvpipe);
#endif
#ifdef NRF24L01_DEBUG
void nrf24l01_dumpregs(FAR struct nrf24l01_dev_s *dev);
void nrf24l01_dumprxfifo(FAR struct nrf24l01_dev_s *dev);
#endif
#undef EXTERN
#if defined(__cplusplus)
}
#endif
#endif /* __INCLUDE_NUTTX_NRF24L01_H */
+74
View File
@@ -0,0 +1,74 @@
/************************************************************************************
* include/nuttx/wireless/wireless.h
*
* Copyright (C) 2011-2013 Gregory Nutt. All rights reserved.
* Author: Laurent Latil <gnutt@nuttx.org>
*
* 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 drivers
* (when applicable).
*/
#ifndef __INCLUDE_NUTTX_WIRELESS_H
#define __INCLUDE_NUTTX_WIRELESS_H
/************************************************************************************
* Included Files
************************************************************************************/
#include <nuttx/config.h>
#include <nuttx/fs/ioctl.h>
#ifdef CONFIG_WIRELESS
/************************************************************************************
* Pre-Processor Definitions
************************************************************************************/
/* IOCTL Commands *******************************************************************/
#define WLIOC_SETRADIOFREQ _WLIOC(0x0001) /* arg: Pointer to uint32_t, frequency value (in Mhz) */
#define WLIOC_GETRADIOFREQ _WLIOC(0x0002) /* arg: Pointer to uint32_t, frequency value (in Mhz) */
#define WLIOC_SETADDR _WLIOC(0x0003) /* arg: Pointer to address value, format of the address is driver specific */
#define WLIOC_GETADDR _WLIOC(0x0004) /* arg: Pointer to address value, format of the address is driver specific */
#define WLIOC_SETTXPOWER _WLIOC(0x0005) /* arg: Pointer to int32_t, output power (in dBm) */
#define WLIOC_GETTXPOWER _WLIOC(0x0006) /* arg: Pointer to int32_t, output power (in dBm) */
/* Wireless drivers can provide additional, device specific ioctl
* commands, beginning with this value:
*/
#define WLIOC_USER 0x0007 /* Lowest, unused WL ioctl command */
#define _WLIOC_USER(nr) _WLIOC(nr + WLIOC_USER)
#endif
#endif /* __INCLUDE_NUTTX_WIRELESS_H */