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 (36)
43#elif MODULE_AT86RF233
44#define AT86RF2XX_TXPOWER_MAX (21)
45#else
46#define AT86RF2XX_TXPOWER_MAX (20)
47#endif
48
52#ifdef MODULE_AT86RF212B
53#define AT86RF2XX_TXPOWER_OFF (25)
54#else
55#define AT86RF2XX_TXPOWER_OFF (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
225void at86rf2xx_configure_phy(at86rf2xx_t *dev, uint8_t chan, uint8_t page, int16_t txpower);
226
227#if AT86RF2XX_RANDOM_NUMBER_GENERATOR || defined(DOXYGEN)
243void at86rf2xx_get_random(at86rf2xx_t *dev, uint8_t *data, size_t len);
244#endif
245
252void at86rf2xx_spi_init(at86rf2xx_t *dev, void (*irq_handler)(void *arg));
253
261static inline uint8_t at86rf2xx_get_rx_len(at86rf2xx_t *dev)
262{
263 (void) dev;
264#if AT86RF2XX_IS_PERIPH
265 return TST_RX_LENGTH;
266#else
267 uint8_t phr;
268 at86rf2xx_fb_read(dev, &phr, 1);
269 return phr;
270#endif
271}
272
281static inline uint8_t at86rf2xx_get_irq_flags(at86rf2xx_t *dev)
282{
283 (void) dev;
284#if AT86RF2XX_IS_PERIPH
285 uint8_t irq_mask = dev->irq_status;
286 dev->irq_status = 0;
287 return irq_mask;
288#else
289 return at86rf2xx_reg_read(dev, AT86RF2XX_REG__IRQ_STATUS);
290#endif
291
292}
293
294#if AT86RF2XX_IS_PERIPH
295/*
296 * Read a 32 bit register as described in section 10.3 of the datasheet: A read
297 * of the least significant byte causes the current value to be atomically
298 * captured in a temporary 32 bit registers. The remaining reads will access this
299 * register instead. Only a single 32 bit temporary register is used to provide
300 * means to atomically access them. Thus, interrupts must be disabled during the
301 * read sequence in order to prevent other threads (or ISRs) from updating the
302 * temporary 32 bit register before the reading sequence has completed.
303 */
304static inline uint32_t reg32_read(volatile uint8_t *reg_ll)
305{
306 le_uint32_t reg;
307 unsigned state = irq_disable();
308 reg.u8[0] = reg_ll[0];
309 reg.u8[1] = reg_ll[1];
310 reg.u8[2] = reg_ll[2];
311 reg.u8[3] = reg_ll[3];
312 irq_restore(state);
313 return reg.u32;
314}
315
323static inline uint32_t at86rf2xx_get_sc(const at86rf2xx_t *dev)
324{
325 (void) dev;
326 return reg32_read(&SCCNTLL);
327}
328
329/* Symbol counter frequency is 62500Hz. One symbol counter tick is 16us = 16000 ns*/
330#define SC_TO_NS (16000LU)
331
332#endif
333
334#ifdef __cplusplus
335}
336#endif
337
Interface definition for AT86RF2xx based drivers.
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_spi_init(at86rf2xx_t *dev, void(*irq_handler)(void *arg))
Initialize AT86RF2XX SPI communication.
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.
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.
static uint8_t at86rf2xx_get_irq_flags(at86rf2xx_t *dev)
Get the IRQ flags.
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.
void at86rf2xx_configure_phy(at86rf2xx_t *dev, uint8_t chan, uint8_t page, int16_t txpower)
Set PHY parameters based on channel and page number.
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.
IRQ driver interface.
Device descriptor for AT86RF2XX radio devices.
Definition at86rf2xx.h:282
Utility header providing time unit defines.
A 32 bit integer in little endian.
Definition byteorder.h:47
uint32_t u32
32 bit representation
Definition byteorder.h:48
uint8_t u8[4]
8 bit representation
Definition byteorder.h:49