Loading...
Searching...
No Matches
at86rf2xx_internal.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2013 Alaeddine Weslati <alaeddine.weslati@inria.fr>
3 * SPDX-FileCopyrightText: 2015 Freie Universität Berlin
4 * SPDX-FileCopyrightText: 2017 HAW Hamburg
5 * SPDX-License-Identifier: LGPL-2.1-only
6 */
7
8#pragma once
9
22
23#include <stdint.h>
24
25#include "at86rf2xx.h"
26
27#if AT86RF2XX_IS_PERIPH
28# include <string.h>
29# include "irq.h"
30# include "time_units.h"
31#endif
32#include "at86rf2xx_registers.h"
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
41#ifdef MODULE_AT86RF212B
42# define AT86RF2XX_TXPOWER_MAX_INDEX (36)
43#elif MODULE_AT86RF233
44# define AT86RF2XX_TXPOWER_MAX_INDEX (21)
45#else
46# define AT86RF2XX_TXPOWER_MAX_INDEX (20)
47#endif
48
52#ifdef MODULE_AT86RF212B
53# define AT86RF2XX_TXPOWER_OFF_OFFSET (25)
54#else
55# define AT86RF2XX_TXPOWER_OFF_OFFSET (17)
56#endif
57
62#define AT86RF2XX_WAKEUP_DELAY (306U)
63
68#define AT86RF2XX_RESET_PULSE_WIDTH (62U)
69
76#define AT86RF2XX_RESET_DELAY (62U)
77
86#if AT86RF2XX_IS_PERIPH
87static inline uint8_t at86rf2xx_reg_read(const at86rf2xx_t *dev, volatile uint8_t *addr) {
88 (void) dev;
89 return *addr;
90}
91#else
92uint8_t at86rf2xx_reg_read(const at86rf2xx_t *dev, uint8_t addr);
93#endif
94
102#if AT86RF2XX_IS_PERIPH
103static inline void at86rf2xx_reg_write(const at86rf2xx_t *dev, volatile uint8_t *addr,
104 const uint8_t value) {
105 (void) dev;
106 *addr = value;
107}
108#else
109void at86rf2xx_reg_write(const at86rf2xx_t *dev, uint8_t addr, uint8_t value);
110#endif
111
120#if AT86RF2XX_IS_PERIPH
121static inline void at86rf2xx_sram_read(const at86rf2xx_t *dev, uint8_t offset,
122 uint8_t *data, size_t len) {
123 (void)dev;
124 memcpy(data, (void*)(AT86RF2XX_REG__TRXFBST + offset), len);
125}
126#else
127void at86rf2xx_sram_read(const at86rf2xx_t *dev, uint8_t offset,
128 uint8_t *data, size_t len);
129#endif
138#if AT86RF2XX_IS_PERIPH
139static inline void at86rf2xx_sram_write(const at86rf2xx_t *dev, uint8_t offset,
140 const uint8_t *data, size_t len) {
141 (void)dev;
142 memcpy((void*)(AT86RF2XX_REG__TRXFBST + offset), data, len);
143}
144#else
145void at86rf2xx_sram_write(const at86rf2xx_t *dev, uint8_t offset,
146 const uint8_t *data, size_t len);
147#endif
156#if AT86RF2XX_IS_PERIPH
157static inline void at86rf2xx_fb_start(const at86rf2xx_t *dev) {
158 (void) dev;
159}
160#else
162#endif
172#if AT86RF2XX_IS_PERIPH
173static inline void at86rf2xx_fb_read(const at86rf2xx_t *dev, uint8_t *data, size_t len) {
174 (void)dev;
175 memcpy(data, (void*)AT86RF2XX_REG__TRXFBST, len);
176}
177#else
178void at86rf2xx_fb_read(const at86rf2xx_t *dev, uint8_t *data, size_t len);
179#endif
187#if AT86RF2XX_IS_PERIPH
188static inline void at86rf2xx_fb_stop(const at86rf2xx_t *dev) {
189 (void) dev;
190}
191#else
193#endif
202
209
216
226 int16_t txpower);
227
228#if AT86RF2XX_RANDOM_NUMBER_GENERATOR || defined(DOXYGEN)
244void at86rf2xx_get_random(at86rf2xx_t *dev, uint8_t *data, size_t len);
245#endif
246
254void at86rf2xx_spi_init(at86rf2xx_t *dev, void (*irq_handler)(void *arg), void *ctx);
255
265static inline uint8_t at86rf2xx_get_rx_len(at86rf2xx_t *dev)
266{
267 (void) dev;
268#if AT86RF2XX_IS_PERIPH
269 return TST_RX_LENGTH;
270#else
271 uint8_t phr;
272 at86rf2xx_fb_read(dev, &phr, 1);
273 return phr;
274#endif
275}
276
284static inline uint8_t at86rf2xx_peek_rx_len(at86rf2xx_t *dev)
285{
286 (void) dev;
287#if AT86RF2XX_IS_PERIPH
288 return TST_RX_LENGTH;
289#else
290 uint8_t phr;
292 phr = at86rf2xx_get_rx_len(dev);
294 return phr;
295#endif
296}
297
298#if AT86RF2XX_IS_PERIPH
299/*
300 * Read a 32 bit register as described in section 10.3 of the datasheet: A read
301 * of the least significant byte causes the current value to be atomically
302 * captured in a temporary 32 bit registers. The remaining reads will access this
303 * register instead. Only a single 32 bit temporary register is used to provide
304 * means to atomically access them. Thus, interrupts must be disabled during the
305 * read sequence in order to prevent other threads (or ISRs) from updating the
306 * temporary 32 bit register before the reading sequence has completed.
307 */
308static inline uint32_t reg32_read(volatile uint8_t *reg_ll)
309{
310 le_uint32_t reg;
311 unsigned state = irq_disable();
312 reg.u8[0] = reg_ll[0];
313 reg.u8[1] = reg_ll[1];
314 reg.u8[2] = reg_ll[2];
315 reg.u8[3] = reg_ll[3];
316 irq_restore(state);
317 return reg.u32;
318}
319
327static inline uint32_t at86rf2xx_get_sc(const at86rf2xx_t *dev)
328{
329 (void) dev;
330 return reg32_read(&SCCNTLL);
331}
332
333/* Symbol counter frequency is 62500Hz. One symbol counter tick is 16us = 16000 ns*/
334#define SC_TO_NS (16000LU)
335
336#endif
337
338#ifdef __cplusplus
339}
340#endif
341
Interface definition for AT86RF2xx based drivers.
void at86rf2xx_spi_init(at86rf2xx_t *dev, void(*irq_handler)(void *arg), void *ctx)
Initialize AT86RF2XX SPI communication.
void at86rf2xx_fb_stop(const at86rf2xx_t *dev)
Stop a read transaction internal frame buffer of the given device.
void at86rf2xx_sram_read(const at86rf2xx_t *dev, uint8_t offset, uint8_t *data, size_t len)
Read a chunk of data from the SRAM of the given device.
void at86rf2xx_assert_awake(at86rf2xx_t *dev)
Make sure that device is not sleeping.
void at86rf2xx_hardware_reset(at86rf2xx_t *dev)
Trigger a hardware reset.
void at86rf2xx_fb_read(const at86rf2xx_t *dev, uint8_t *data, size_t len)
Read the internal frame buffer of the given device.
void at86rf2xx_configure_phy(at86rf2xx_t *dev, uint8_t chan, ieee802154_phy_mode_t mode, int16_t txpower)
Set PHY parameters based on channel and page number.
uint8_t at86rf2xx_reg_read(const at86rf2xx_t *dev, uint8_t addr)
Read from a register at address addr from device dev.
void at86rf2xx_sram_write(const at86rf2xx_t *dev, uint8_t offset, const uint8_t *data, size_t len)
Write a chunk of data into the SRAM of the given device.
void at86rf2xx_fb_start(const at86rf2xx_t *dev)
Start a read transaction internal frame buffer of the given device.
static uint8_t at86rf2xx_get_rx_len(at86rf2xx_t *dev)
Get the PSDU length of the received frame.
void at86rf2xx_get_random(at86rf2xx_t *dev, uint8_t *data, size_t len)
Read random data from the RNG.
void at86rf2xx_reg_write(const at86rf2xx_t *dev, uint8_t addr, uint8_t value)
Write to a register at address addr from device dev.
uint8_t at86rf2xx_get_status(const at86rf2xx_t *dev)
Convenience function for reading the status of the given device.
static uint8_t at86rf2xx_peek_rx_len(at86rf2xx_t *dev)
Peek the PSDU length of the received frame.
Register and command definitions for AT86RF2xx devices.
MAYBE_INLINE void irq_restore(unsigned state)
This function restores the IRQ disable bit in the status register to the value contained within passe...
MAYBE_INLINE unsigned irq_disable(void)
This function sets the IRQ disable bit in the status register.
ieee802154_phy_mode_t
802.15.4 PHY modes
Definition ieee802154.h:192
IRQ driver interface.
Device descriptor for AT86RF2XX radio devices.
Definition at86rf2xx.h:277
Utility header providing time unit defines.
A 32 bit integer in little endian.
Definition byteorder.h:44
uint32_t u32
32 bit representation
Definition byteorder.h:45
uint8_t u8[4]
8 bit representation
Definition byteorder.h:46