arch/arm/src/nrf52: add initial interface to work with on-chip radio

This commit is contained in:
raiden00pl 2020-04-03 17:12:41 +02:00 committed by patacongo
parent 952e7f6e17
commit df1eeb8e3f
5 changed files with 1526 additions and 18 deletions

View File

@ -160,6 +160,7 @@ config NRF52_WDT
config NRF52_RADIO
bool "RADIO"
depends on EXPERIMENTAL
default n
config NRF52_NFCT

View File

@ -128,3 +128,8 @@ endif
ifeq ($(CONFIG_NRF52_I2C_MASTER),y)
CHIP_CSRCS += nrf52_i2c.c
endif
ifeq ($(CONFIG_NRF52_RADIO),y)
CHIP_CSRCS += nrf52_radio.c
endif

View File

@ -428,6 +428,7 @@
#define RADIO_TXPOWER_SHIFT (0) /* Bits 0-7: RADIO output power */
#define RADIO_TXPOWER_MASK (0xff << RADIO_TXPOWER_SHIFT)
#define RADIO_TXPOWER_MAX (0xff)
/* MODE Register */
@ -445,34 +446,47 @@
#define RADIO_PCNF0_LFLEN_SHIFT (0) /* Bits 0-3: Length on air of LENGTH field in number of bits */
#define RADIO_PCNF0_LFLEN_MASK (0xf << RADIO_PCNF0_LFLEN_SHIFT)
#define RADIO_PCNF0_S0LEN (1 << 8) /* Bit 8: Length on air of S0 field in number of bytes */
#define RADIO_PCNF0_LFLEN_MAX (0xf)
#define RADIO_PCNF0_S0LEN_SHIFT (8) /* Bit 8: Length on air of S0 field in number of bytes */
#define RADIO_PCNF0_S0LEN_MASK (1 << RADIO_PCNF0_S0LEN_SHIFT)
#define RADIO_PCNF0_S0LEN_MAX (1)
#define RADIO_PCNF0_S1LEN_SHIFT (16) /* Bits 16-19: Length on air of S1 field in number of bits */
#define RADIO_PCNF0_S1LEN_MASK (0xf << RADIO_PCNF0_S1LEN_SHIFT)
#define RADIO_PCNF0_S1LEN_MAX (0xf)
#define RADIO_PCNF0_S1INCL (1 << 20) /* Bit 20: Include or exclude S1 field in RAM */
#define RADIO_PCNF0_CILEN_SHIFT (22) /* Bits 22-23: Length of code indicator - long range */
#define RADIO_PCNF0_CILEN_MASK (0x3 << RADIO_PCNF0_CILEN_SHIFT)
#define RADIO_PCNF0_CILEN_MAX (0x3)
#define RADIO_PCNF0_PLEN_SHIFT (24) /* Bits 24-25: Length of preamble on air */
#define RADIO_PCNF0_PLEN_MASK (0x3 << RADIO_PCNF0_PLEN_SHIFT)
# define RADIO_PCNF0_PLEN_8BIT (0 << RADIO_PCNF0_PLEN_SHIFT)
# define RADIO_PCNF0_PLEN_16BIT (1 << RADIO_PCNF0_PLEN_SHIFT)
# define RADIO_PCNF0_PLEN_32BITZ (2 << RADIO_PCNF0_PLEN_SHIFT)
# define RADIO_PCNF0_PLEN_LONGRANGE (3 << RADIO_PCNF0_PLEN_SHIFT)
#define RADIO_PCNF0_CRCINC (1 << 26) /* Bit 26: Indicates if LENGTH field contains CRC */
#define RADIO_PCNF0_CRCINC_SHIFT (26) /* Bit 26: Indicates if LENGTH field contains CRC */
#define RADIO_PCNF0_CRCINC (1 << RADIO_PCNF0_CRCINC_SHIFT)
#define RADIO_PCNF0_TERMLEN_SHIFT (29) /* Bits 29-30: Length of TERM field in Long Range operation */
#define RADIO_PCNF0_TERMLEN_MASK (0x3 << RADIO_PCNF0_TERMLEN_SHIFT)
#define RADIO_PCNF0_TERMLEN_MAX (0x3)
/* PCNF1 Register */
#define RADIO_PCNF1_MAXLEN_SHIFT (0) /* Bits 0-7: Maximum length of packet payload */
#define RADIO_PCNF1_MAXLEN_MASK (0xff << RADIO_PCNF1_MAXLEN_SHIFT)
#define RADIO_PCNF1_MAXLEN_MAX (0xff)
#define RADIO_PCNF1_STATLEN_SHIFT (8) /* Bits 8-15: Static length in number of bytes */
#define RADIO_PCNF1_STATLEN_MASK (0xff << RADIO_PCNF1_STATLEN_SHIFT)
#define RADIO_PCNF1_STATLEN_MAX (0xff)
#define RADIO_PCNF1_BALEN_SHIFT (16) /* Bits 16-18: Base address length in number of bytes */
#define RADIO_PCNF1_BALEN_MASK (0x7 << RADIO_PCNF1_BALEN_SHIFT)
#define RADIO_PCNF1_ENDIAN (1 << 24) /* Bit 24: On air endianness of packet */
#define RADIO_PCNF1_BALEN_MIN (0x2)
#define RADIO_PCNF1_BALEN_MAX (0x4)
#define RADIO_PCNF1_ENDIAN_SHIFT (24) /* Bit 24: On air endianness of packet */
#define RADIO_PCNF1_ENDIAN (1 << RADIO_PCNF1_ENDIAN_SHIFT)
# define RADIO_PCNF1_ENDIAN_LITTLE (0 << 24) /* Least significant bit on air first */
# define RADIO_PCNF1_ENDIAN_BITG (1 << 24) /* Most significant bit on air first */
#define RADIO_PCNF1_WHITEEN (1 << 25) /* Bit 25: Enable or disable packet whitening */
#define RADIO_PCNF1_WHITEEN_SHIFT (25) /* Bit 25: Enable or disable packet whitening */
#define RADIO_PCNF1_WHITEEN (1 << RADIO_PCNF1_WHITEEN_SHIFT)
/* TXADDRESS Register */
@ -492,10 +506,10 @@
# define RADIO_CRCCNF_LEN_2 (2 << RADIO_CRCCNF_LEN_SHIFT)
# define RADIO_CRCCNF_LEN_3 (3 << RADIO_CRCCNF_LEN_SHIFT)
#define RADIO_CRCCNF_SKIPADDR_SHIFT (8) /* Bit 8-9: Include or exclude packet address field out of CRC calculation */
#define RADIO_CRCCNF_SKIPADDR_MASK (0x3 << RADIO_CRCCNF_SKIPADDR_SHIFT)
# define RADIO_CRCCNF_SKIPADDR_INCL (0x3 << RADIO_CRCCNF_SKIPADDR_SHIFT)
# define RADIO_CRCCNF_SKIPADDR_SKIP (0x3 << RADIO_CRCCNF_SKIPADDR_SHIFT)
# define RADIO_CRCCNF_SKIPADDR_IEEE (0x3 << RADIO_CRCCNF_SKIPADDR_SHIFT)
#define RADIO_CRCCNF_SKIPADDR_MASK (0 << RADIO_CRCCNF_SKIPADDR_SHIFT)
# define RADIO_CRCCNF_SKIPADDR_INCL (1 << RADIO_CRCCNF_SKIPADDR_SHIFT)
# define RADIO_CRCCNF_SKIPADDR_SKIP (2 << RADIO_CRCCNF_SKIPADDR_SHIFT)
# define RADIO_CRCCNF_SKIPADDR_IEEE (3 << RADIO_CRCCNF_SKIPADDR_SHIFT)
/* CRCPOLY Register */
@ -511,6 +525,7 @@
#define RADIO_TIFS_SHIFT (0) /* Bits 0-9: Interframe spacing in μs */
#define RADIO_TIFS_MASK (0x3ff << RADIO_TIFS_SHIFT)
#define RADIO_TIFS_MAX (0x3ff)
/* RSSISAMPLE Register */
@ -520,21 +535,22 @@
/* STATE Register */
#define RADIO_STATE_SHIFT (0) /* Bits 0-2: Current radio state */
#define RADIO_STATE_MASK (0xf << RADIO_STATE_STATE_SHIFT)
# define RADIO_STATE_DISABLED (0 << RADIO_STATE_STATE_SHIFT)
# define RADIO_STATE_RXRU (1 << RADIO_STATE_STATE_SHIFT)
# define RADIO_STATE_RXIDLE (2 << RADIO_STATE_STATE_SHIFT)
# define RADIO_STATE_RX (3 << RADIO_STATE_STATE_SHIFT)
# define RADIO_STATE_RXDISABLE (4 << RADIO_STATE_STATE_SHIFT)
# define RADIO_STATE_TXRU (9 << RADIO_STATE_STATE_SHIFT)
# define RADIO_STATE_TXIDLE 10 << RADIO_STATE_STATE_SHIFT)
# define RADIO_STATE_TX (11 << RADIO_STATE_STATE_SHIFT)
# define RADIO_STATE_TXDISABLE (12 << RADIO_STATE_STATE_SHIFT)
#define RADIO_STATE_MASK (0xf << RADIO_STATE_SHIFT)
# define RADIO_STATE_DISABLED (0 << RADIO_STATE_SHIFT)
# define RADIO_STATE_RXRU (1 << RADIO_STATE_SHIFT)
# define RADIO_STATE_RXIDLE (2 << RADIO_STATE_SHIFT)
# define RADIO_STATE_RX (3 << RADIO_STATE_SHIFT)
# define RADIO_STATE_RXDISABLE (4 << RADIO_STATE_SHIFT)
# define RADIO_STATE_TXRU (9 << RADIO_STATE_SHIFT)
# define RADIO_STATE_TXIDLE (10 << RADIO_STATE_SHIFT)
# define RADIO_STATE_TX (11 << RADIO_STATE_SHIFT)
# define RADIO_STATE_TXDISABLE (12 << RADIO_STATE_SHIFT)
/* DATAWHITEIV Register */
#define RADIO_DATAWHITEIV_SHIFT (0) /* Bits 0-6: Data whitening initial value */
#define RADIO_DATAWHITEIV_MASK (0x3f << RADIO_DATAWHITEIV_SHIFT)
#define RADIO_DATAWHITEIV_MAX (0x3f)
/* DAP Register */
@ -583,5 +599,6 @@
/* POWER Register */
#define RADIO_POWER_ENABLE (1 << 0) /* Bit 0: Peripheral power control */
#define RADIO_POWER_DISABLE (0 << 0) /* Bit 0: Peripheral power control */
#endif /* __ARCH_ARM_SRC_NRF52_HARDWARE_NRF52_RADIO_H */

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,281 @@
/****************************************************************************
* arch/arm/src/nrf52/nrf52_radio.h
*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
*
****************************************************************************/
#ifndef __ARCH_ARM_SRC_NRF52_NRF52_RADIO_H
#define __ARCH_ARM_SRC_NRF52_NRF52_RADIO_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <nuttx/semaphore.h>
#include "chip.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define NRF52_RADIO_LOGICAL_ADDRESS_MAX (8)
/****************************************************************************
* Public Types
****************************************************************************/
/* Radio mode */
enum nrf52_radio_mode_e
{
NRF52_RADIO_MODE_NRF1MBIT = 0,
NRF52_RADIO_MODE_NRF2MBIT = 1,
NRF52_RADIO_MODE_BLE1MBIT = 2,
NRF52_RADIO_MODE_BLE2MBIT = 3,
NRF52_RADIO_MODE_BLELR125KBIT = 4,
NRF52_RADIO_MODE_BLELR500KBIT = 5,
NRF52_RADIO_MODE_IEEE802154 = 6
};
/* Radio state */
enum nrf52_radio_state_e
{
NRF52_RADIO_STATE_DISABLED = 0,
NRF52_RADIO_STATE_TX = 1,
NRF52_RADIO_STATE_RX = 2,
};
/* Preamble configuration */
enum nrf52_radio_preamble_e
{
NRF52_RADIO_PREAMBLE_8BIT = 0,
NRF52_RADIO_PREAMBLE_16BIT = 1,
NRF52_RADIO_PREAMBLE_32BITZERO = 2,
NRF52_RADIO_PREAMBLE_LONGRANGE = 3
};
/* Radio packet CRC length */
enum nrf52_radio_crc_len_e
{
NRF52_RADIO_CRC_LEN_DIS = 0,
NRF52_RADIO_CRC_LEN_1B = 1,
NRF52_RADIO_CRC_LEN_2B = 2,
NRF52_RADIO_CRC_LEN_3B = 3,
};
/* Radio packet CRC includes address */
enum nrf52_radio_crc_skipaddr_e
{
NRF52_RADIO_CRC_SKIPADDR_INCLUDE = 0,
NRF52_RADIO_CRC_SKIPADDR_SKIP = 1,
NRF52_RADIO_CRC_SKIPADDR_IEEE802154 = 2,
};
/* On air packet layout:
*
* +---------------------------------------+
* | FIRST |
* |----------+------+--------+----+-------+
* | PREAMBLE | BASE | PREFIX | CI | TERM1 |
* | LSB | LSB | LSB | | |
* | | ADDRESS | | |
* +----------+---------------+----+-------+
*
*
* +----------------------------+
* | Stored on RAM |
* |----+--------+----+---------|
* | S0 | LENGTH | S1 | PAYLOAD |
* | | | | |
* | | | | |
* +----+--------+----+---------+
*
* +---------------+
* | LAST |
* |-------+-------|
* | CRC32 | TERM2 |
* | MSB | |
* | | |
* +-------+-------+
*
*/
/* Radio packet configuration */
struct nrf52_radio_pktcfg_s
{
uint8_t max_len; /* Maximum length of payload */
uint8_t stat_len; /* Static payload length */
uint8_t bal_len; /* Base address length */
uint8_t lf_len; /* LENGTH length */
uint8_t s0_len; /* S0 length */
uint8_t s1_len; /* S1 length */
uint8_t ci_len; /* CI length */
uint8_t pl_len; /* Preable lenght */
uint8_t term_len; /* TERM length */
bool crcinc; /* LENGTH includes CRC */
bool endian; /* On air endianess of packet:
* 0 - little
* 1 - big
*/
bool whiteen; /* Whitening enabled */
};
/* Radio packet CRC configuration */
struct nrf52_radio_crc_s
{
uint8_t len; /* CRC length in number of bytes */
uint8_t skip; /* Include or exclude address field out of CRC */
uint32_t poly; /* CRC polynominal */
uint32_t init; /* CRC initial value */
};
/* NRF52 on air address */
struct nrf52_radio_addr_s
{
uint8_t a0; /* PREFIX */
uint8_t a1; /* BASE[0] */
uint8_t a2; /* BASE[1] */
uint8_t a3; /* BASE[2] */
uint8_t a4; /* BASE[3] */
};
/* NRF52 radio operations */
struct nrf52_radio_dev_s;
struct nrf52_radio_ops_s
{
/* Turn-on/turn-off radio power */
CODE int (*power)(FAR struct nrf52_radio_dev_s *dev, bool state);
/* Set radio mode */
CODE int (*mode_set)(FAR struct nrf52_radio_dev_s *dev, uint8_t mode);
/* Set radio frequency (in MHz) */
CODE int (*freq_set)(FAR struct nrf52_radio_dev_s *dev, uint32_t freq);
/* Get RSSI sample */
CODE int (*rssi_get)(FAR struct nrf52_radio_dev_s *dev, FAR int *rssi);
/* Set TX power */
CODE int (*txpower_set)(FAR struct nrf52_radio_dev_s *dev,
uint8_t txpower);
/* Set hardware interframe spacing time */
CODE int (*tifs_set)(FAR struct nrf52_radio_dev_s *dev, uint16_t us);
/* Configure radio packet */
CODE int (*pkt_cfg)(FAR struct nrf52_radio_dev_s *dev,
FAR struct nrf52_radio_pktcfg_s *cfg);
/* Configure packet CRC */
CODE int (*crc_cfg)(FAR struct nrf52_radio_dev_s *dev,
FAR struct nrf52_radio_crc_s *cfg);
/* Configure data whitening */
CODE int (*white_set)(FAR struct nrf52_radio_dev_s *dev,
uint8_t init);
/* Configure logical address */
CODE int (*addr_set)(FAR struct nrf52_radio_dev_s *dev, uint8_t i,
FAR struct nrf52_radio_addr_s *addr);
/* Read packet */
CODE int (*read)(FAR struct nrf52_radio_dev_s *dev,
FAR uint8_t *buf, int len);
/* Write packet */
CODE int (*write)(FAR struct nrf52_radio_dev_s *dev,
FAR uint8_t *buf, int len);
/* Dump radio registers */
CODE void (*dumpregs)(FAR struct nrf52_radio_dev_s *dev);
};
/* NRF52 radio board specific data */
struct nrf52_radio_board_s
{
/* TODO: PA/LNA interface */
uint32_t reserved;
};
/* NRF52 radio device */
struct nrf52_radio_dev_s
{
FAR struct nrf52_radio_ops_s *ops; /* Radio operations */
FAR struct nrf52_radio_board_s *board; /* Radio board-specific */
uint32_t base; /* Radio base */
uint32_t irq; /* Radio IRQ number */
uint8_t mode; /* Radio mode */
uint8_t state; /* Radio state */
struct nrf52_radio_pktcfg_s pktcfg; /* Current packet */
uint16_t rxbuf_len; /* RX buffer length */
uint16_t txbuf_len; /* TX buffer length */
FAR uint8_t *rxbuf; /* RX buffer */
FAR uint8_t *txbuf; /* TX buffer */
sem_t sem_excl; /* Mutual exclusion semaphore */
sem_t sem_isr; /* Interrupt wait semaphore */
uint16_t tifs; /* Interframe spacing time */
uint8_t txpower; /* TX power */
uint8_t txaddr; /* TX address */
uint8_t rxaddr; /* RX addresses */
struct nrf52_radio_addr_s addr[NRF52_RADIO_LOGICAL_ADDRESS_MAX];
};
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: nrf52_radio_initialize
*
* Description:
* Initialize NRF52 radio device
*
****************************************************************************/
FAR struct nrf52_radio_dev_s *
nrf52_radio_initialize(int intf, FAR struct nrf52_radio_board_s *board);
#endif /* __ARCH_ARM_SRC_NRF52_NRF52_RADIO_H */