nrf52/nrf52_radio: various changes to support IEEE802154

- remove read-write logic - this should be handled by radio protocol implementation
- remove EVENTS and TASKS bit definitions - we can just use a signle definition
- add more radio ops
- fix frequency configuration
- fix printf warnings
- fix radio reset
This commit is contained in:
raiden00pl
2024-01-20 15:07:43 +01:00
committed by Xiang Xiao
parent a99275ec1a
commit 3f763f5d69
5 changed files with 332 additions and 542 deletions
+22
View File
@@ -42,6 +42,8 @@ config ARCH_CHIP_NRF52840
select NRF52_HAVE_USBDEV
select NRF52_HAVE_PWM3
select NRF52_HAVE_CRYPTOCELL
select NRF52_HAVE_IEEE802154
select NRF52_HAVE_BLELR
endchoice # NRF52 Chip Selection
@@ -134,6 +136,14 @@ config NRF52_HAVE_CRYPTOCELL
bool
default n
config NRF52_HAVE_BLELE
bool
default n
config NRF52_HAVE_IEEE802154
bool
default n
# Peripheral Selection
config NRF52_I2C_MASTER
@@ -611,6 +621,18 @@ endif # NRF52_PWM
endmenu # PWM configuration
menu "RADIO Configuration"
if NRF52_RADIO
config NRF52_RADIO_CUSTOM
bool "RADIO uses custom IRQ handlers"
default n
endif #NRF52_RADIO
endmenu # "RADIO Configuration"
menu "SAADC Configuration"
if NRF52_SAADC
+6 -140
View File
@@ -206,146 +206,6 @@
/* Register Bitfield Definitions ********************************************/
/* TASKS_TXEN Register */
#define RADIO_TASKS_TXEN (1 << 0) /* Bit 0: Enable RADIO in TX mode */
/* TASKS_RXEN Register */
#define RADIO_TASKS_RXEN (1 << 0) /* Bit 0: Enable RADIO in RX mode */
/* TASKS_START Register */
#define RADIO_TASKS_START (1 << 0) /* Bit 0: Start RADIO */
/* TASKS_STOP Register */
#define RADIO_TASKS_STOP (1 << 0) /* Bit 0: Stop RADIO */
/* TASKS_DISABLE Register */
#define RADIO_TASKS_DISABLE (1 << 0) /* Bit 0: Disable RADIO */
/* TASKS_RSSISTART Register */
#define RADIO_TASKS_RSSISTART (1 << 0) /* Bit 0: Start the RSSI */
/* TASKS_RSSISTOP Register */
#define RADIO_TASKS_RSSISTOP (1 << 0) /* Bit 0: Stop the RSSI */
/* TASKS_BCSTART Register */
#define RADIO_TASKS_BCSTART (1 << 0) /* Bit 0: Start the bit counter */
/* TASKS_BCSTOP Register */
#define RADIO_TASKS_BCSTOP (1 << 0) /* Bit 0: Stop the bit counter */
/* TASKS_EDSTART Register */
#define RADIO_TASKS_EDSTART (1 << 0) /* Bit 0: Start the energy detect measurement (IEEE 802.15.4) */
/* TASKS_EDSTOP Register */
#define RADIO_TASKS_EDSTOP (1 << 0) /* Bit 0: Stop the energy detect measurement (IEEE 802.15.4) */
/* TASKS_CCASTART Register */
#define RADIO_TASKS_CCASTART (1 << 0) /* Bit 0: Start the channel assessment (IEEE 802.15.4) */
/* TASKS_CCASTOP Register */
#define RADIO_TASKS_CCASTOP (1 << 0) /* Bit 0: Stop the channel assessment (IEEE 802.15.4) */
/* EVENTS_READY Register */
#define RADIO_EVENTS_READY (1 << 0) /* Bit 0: RADIO has ramped up and is ready to be started */
/* EVENTS_ADDRESS Register */
#define RADIO_EVENTS_ADDRESS (1 << 0) /* Bit 0: Address sent or received */
/* EVENTS_PAYLOAD Register */
#define RADIO_EVENTS_PAYLOAD (1 << 0) /* Bit 0: Packet payload sent or received */
/* EVENTS_END Register */
#define RADIO_EVENTS_END (1 << 0) /* Bit 0: Packet sent or received */
/* EVENTS_DISABLED Register */
#define RADIO_EVENTS_DISABLED (1 << 0) /* Bit 0: RADIO has been disabled */
/* EVENTS_DEVMATCH Register */
#define RADIO_EVENTS_DEVMATCH (1 << 0) /* Bit 0: A device address match */
/* EVENTS_DEVMISS Register */
#define RADIO_EVENTS_DEVMISS (1 << 0) /* Bit 0: No device address match */
/* EVENTS_RSSIEND Register */
#define RADIO_EVENTS_RSSIEND (1 << 0) /* Bit 0: Sampling of receive signal strength complete */
/* EVENTS_BCMATCH Register */
#define RADIO_EVENTS_BCMATCH (1 << 0) /* Bit 0: Bit counter reached bit count value */
/* EVENTS_CRCOK Register */
#define RADIO_EVENTS_CRCOK (1 << 0) /* Bit 0: Packet received with CRC ok */
/* EVENTS_CRCERROR Register */
#define RADIO_EVENTS_CRCERROR (1 << 0) /* Bit 0: Packet received with CRC error */
/* EVENTS_FRAMESTART Register */
#define RADIO_EVENTS_FRAMESTART (1 << 0) /* Bit 0: IEEE 802.15.4 length field received*/
/* EVENTS_EDEND Register */
#define RADIO_EVENTS_EDEND (1 << 0) /* Bit 0: ampling of energy detection complete */
/* EVENTS_EDSTOPPED Register */
#define RADIO_EVENTS_EDSTOPPED (1 << 0) /* Bit 0: The sampling of energy detection has stopped */
/* EVENTS_CCAIDLE Register */
#define RADIO_EVENTS_CCAIDLE (1 << 0) /* Bit 0: Wireless medium in idle */
/* EVENTS_CCABUSY Register */
#define RADIO_EVENTS_CCABUSY (1 << 0) /* Bit 0: Wireless medium busy */
/* EVENTS_CCASTOPPED Register */
#define RADIO_EVENTS_CCASTOPPED (1 << 0) /* Bit 0: The CCA has stopped */
/* EVENTS_RATEBOOST Register */
#define RADIO_EVENTS_RATEBOOST (1 << 0) /* Bit 0: Ble_LR CI field received */
/* EVENTS_TXREADY Register */
#define RADIO_EVENTS_TXREADY (1 << 0) /* Bit 0: RADIO has ramped up and is ready to be started TX path */
/* EVENTS_RXREADY Register */
#define RADIO_EVENTS_RXREADY (1 << 0) /* Bit 0: RADIO has ramped up and is ready to be started RX path */
/* EVENTS_MHRMATCH Register */
#define RADIO_EVENTS_MHRMATCH (1 << 0) /* Bit 0: MAC header match found */
/* EVENTS_PHYEND Register */
#define RADIO_EVENTS_PHYEND (1 << 0) /* Bit 0: Last bit is sent on air */
/* SHORTS Register */
#define RADIO_SHORTS_READY_START (1 << 0) /* Bit 0: Shortcut between event READY and task START */
@@ -622,6 +482,12 @@
# define RADIO_CCACTRL_CCAMODE_CANDED (2 << RADIO_CCACTRL_CCAMODE_SHIFT)
# define RADIO_CCACTRL_CCAMODE_CORED (3 << RADIO_CCACTRL_CCAMODE_SHIFT)
# define RADIO_CCACTRL_CCAMODE_EDTST1 (4 << RADIO_CCACTRL_CCAMODE_SHIFT)
#define RADIO_CCACTRL_CCAEDTHRES_SHIFT (8)
#define RADIO_CCACTRL_CCAEDTHRES_MASK (0xff << RADIO_CCACTRL_CCAEDTHRES_SHIFT)
#define RADIO_CCACTRL_CCACORRTHRES_SHIFT (16)
#define RADIO_CCACTRL_CCACORRTHRES_MASK (0xff << RADIO_CCACTRL_CCACORRTHRES_SHIFT)
#define RADIO_CCACTRL_CCACORRCNT_SHIFT (24)
#define RADIO_CCACTRL_CCACORRCNT_MASK (0xff << RADIO_CCACTRL_CCACORRCNT_SHIFT)
/* POWER Register */
@@ -27,6 +27,8 @@
#include <nuttx/config.h>
#include "arm_internal.h"
/****************************************************************************
* Public Function Prototypes / Inline Functions
****************************************************************************/
File diff suppressed because it is too large Load Diff
+114 -34
View File
@@ -40,6 +40,29 @@
#define NRF52_RADIO_LOGICAL_ADDRESS_MAX (8)
/* Ops */
#define NRF52_RADIO_RESET(lower) lower->ops->reset(lower)
#define NRF52_RADIO_PUTREG(lower, o, v) lower->ops->putreg(lower, o, v)
#define NRF52_RADIO_GETREG(lower, o) lower->ops->getreg(lower, o)
#define NRF52_RADIO_INTEN(lower, i) lower->ops->inten(lower, i)
#define NRF52_RADIO_INTCLR(lower, i) lower->ops->intclr(lower, i)
#define NRF52_RADIO_SHRTSET(lower, s) lower->ops->shorts(lower, s)
#define NRF52_RADIO_PWRSET(lower, pwr) lower->ops->power(lower, pwr)
#define NRF52_RADIO_MODESET(lower, m) lower->ops->mode_set(lower, m)
#define NRF52_RADIO_FREQSET(lower, f) lower->ops->freq_set(lower, f)
#define NRF52_RADIO_RSSIGET(lower, r) lower->ops->rssi_get(lower, r)
#define NRF52_RADIO_TXPWRSET(lower, p) lower->ops->txpower_set(lower, p)
#define NRF52_RADIO_TIFSSET(lower, p) lower->ops->tifs_set(lower, t)
#define NRF52_RADIO_PKTCFG(lower, cfg) lower->ops->pkt_cfg(lower, cfg)
#define NRF52_RADIO_CRCCFG(lower, cfg) lower->ops->crc_cfg(lower, cfg)
#define NRF52_RADIO_WHITESET(lower, cfg) lower->ops->white_set(lower, c)
#define NRF52_RADIO_ADDRSET(lower, i, a) lower->ops->addr_set(lower, i, a)
#define NRF52_RADIO_DUMPREGS(lower) lower->ops->dumpregs(lower)
#define NRF52_RADIO_SFDSET(lower, sfd) lower->ops->sfd_set(lower, sfd)
#define NRF52_RADIO_EDCNTSET(lower, ec) lower->ops->edcnt_set(lower, ec)
#define NRF52_RADIO_CCACFG(lower, cca) lower->ops->cca_cfg(lower, cca)
/****************************************************************************
* Public Types
****************************************************************************/
@@ -50,20 +73,18 @@ 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
};
NRF52_RADIO_MODE_NRF250KBIT = 2,
NRF52_RADIO_MODE_BLE1MBIT = 3,
NRF52_RADIO_MODE_BLE2MBIT = 4,
#ifdef CONFIG_NRF52_HAVE_BLELR
NRF52_RADIO_MODE_BLELR125KBIT = 5,
NRF52_RADIO_MODE_BLELR500KBIT = 6,
#endif
NRF52_RADIO_MODE_LAST,
/* Radio state */
enum nrf52_radio_state_e
{
NRF52_RADIO_STATE_DISABLED = 0,
NRF52_RADIO_STATE_TX = 1,
NRF52_RADIO_STATE_RX = 2,
#ifdef CONFIG_NRF52_HAVE_IEEE802154
NRF52_RADIO_MODE_IEEE802154 = 15
#endif
};
/* Preamble configuration */
@@ -95,7 +116,18 @@ enum nrf52_radio_crc_skipaddr_e
NRF52_RADIO_CRC_SKIPADDR_IEEE802154 = 2,
};
/* On air packet layout:
/* CCA mode of operation */
enum nrf52_radio_cca_mode_e
{
NRF52_RADIO_CCA_ED = 0,
NRF52_RADIO_CCA_CARRIER = 1,
NRF52_RADIO_CCA_CARRIER_AND_ED = 2,
NRF52_RADIO_CCA_CARRIER_OR_ED = 2,
NRF52_RADIO_CCA_EDTEST1 = 4,
};
/* On air packet layout (no IEEE802154 mode):
*
* +---------------------------------------+
* | FIRST |
@@ -105,7 +137,6 @@ enum nrf52_radio_crc_skipaddr_e
* | | ADDRESS | | |
* +----------+---------------+----+-------+
*
*
* +----------------------------+
* | Stored on RAM |
* |----+--------+----+---------|
@@ -122,6 +153,20 @@ enum nrf52_radio_crc_skipaddr_e
* | | |
* +-------+-------+
*
* For IEEE802154 mode packet layout is different:
*
* +--------------------------------------------------------------------+
* | PHY protocol data unit (PPDU) |
* +--------------------+-----+---------+-------------------------------+
* | Preamble sequence | SFD | Lenght | PHY payload |
* |--------------------+-----+---------+-------------------------------+
* | 5 octets synchronization | 1 octet | Maximum 127 octets (PSDU) |
* | header (SHR) | (PHR) +-------------------------------+
* | | | MAC protocol data unit (MPDU) |
* +--------------------------+---------+-------------------------------+
* | Stored on RAM |
* +-----------------------------------------+
*
*/
/* Radio packet configuration */
@@ -166,11 +211,49 @@ struct nrf52_radio_addr_s
uint8_t a4; /* BASE[3] */
};
#ifdef CONFIG_NRF52_HAVE_IEEE802154
/* IEEE 802.15.4 clear channel assessment control */
struct nrf52_radio_cca_s
{
uint8_t mode; /* CCA mode of operation */
uint8_t edthres; /* CCA energy busy threshold */
uint8_t corrthres; /* CCA correlator busy threshold */
uint8_t corrcnt; /* Limit for occurances above CCACORRTHRES */
};
#endif
/* NRF52 radio operations */
struct nrf52_radio_dev_s;
struct nrf52_radio_ops_s
{
/* Reset radio */
void (*reset)(struct nrf52_radio_dev_s *dev);
/* Put register value */
void (*putreg)(struct nrf52_radio_dev_s *dev, uint32_t offset,
uint32_t value);
/* Get register value */
uint32_t (*getreg)(struct nrf52_radio_dev_s *dev, uint32_t offset);
/* Enable interrupts */
void (*inten)(struct nrf52_radio_dev_s *dev, uint32_t irq);
/* Disable interrupts */
void (*intclr)(struct nrf52_radio_dev_s *dev, uint32_t irq);
/* Configure shorts */
void (*shorts)(struct nrf52_radio_dev_s *dev, uint32_t irq);
/* Turn-on/turn-off radio power */
int (*power)(struct nrf52_radio_dev_s *dev, bool state);
@@ -185,7 +268,7 @@ struct nrf52_radio_ops_s
/* Get RSSI sample */
int (*rssi_get)(struct nrf52_radio_dev_s *dev, int *rssi);
int (*rssi_get)(struct nrf52_radio_dev_s *dev, int8_t *rssi);
/* Set TX power */
@@ -214,19 +297,24 @@ struct nrf52_radio_ops_s
int (*addr_set)(struct nrf52_radio_dev_s *dev, uint8_t i,
struct nrf52_radio_addr_s *addr);
/* Read packet */
int (*read)(struct nrf52_radio_dev_s *dev,
uint8_t *buf, int len);
/* Write packet */
int (*write)(struct nrf52_radio_dev_s *dev,
uint8_t *buf, int len);
/* Dump radio registers */
void (*dumpregs)(struct nrf52_radio_dev_s *dev);
#ifdef CONFIG_NRF52_HAVE_IEEE802154
/* IEEE 802.15.4 start of frame delimiter */
void (*sfd_set)(struct nrf52_radio_dev_s *dev, uint8_t sfd);
/* IEEE 802.15.4 energy detect level */
void (*edcnt_set)(struct nrf52_radio_dev_s *dev, uint32_t edcnt);
/* IEEE 802.15.4 clear channel assessment control */
void (*cca_cfg)(struct nrf52_radio_dev_s *dev,
struct nrf52_radio_cca_s *cca);
#endif
};
/* NRF52 radio board specific data */
@@ -247,18 +335,10 @@ struct nrf52_radio_dev_s
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 */
uint8_t *rxbuf; /* RX buffer */
uint8_t *txbuf; /* TX buffer */
mutex_t lock; /* Mutual exclusion mutex */
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];
};