at86rf2xx_internal.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2013 Alaeddine Weslati <alaeddine.weslati@inria.fr>
3  * Copyright (C) 2015 Freie Universität Berlin
4  * 2017 HAW Hamburg
5  *
6  * This file is subject to the terms and conditions of the GNU Lesser General
7  * Public License v2.1. See the file LICENSE in the top level directory for more
8  * details.
9  */
10 
11 #pragma once
12 
26 #include <stdint.h>
27 
28 #include "at86rf2xx.h"
29 
30 #if AT86RF2XX_IS_PERIPH
31 #include <string.h>
32 #include "irq.h"
33 #include "time_units.h"
34 #endif
35 #include "at86rf2xx_registers.h"
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
44 #ifdef MODULE_AT86RF212B
45 #define AT86RF2XX_TXPOWER_MAX (36)
46 #elif MODULE_AT86RF233
47 #define AT86RF2XX_TXPOWER_MAX (21)
48 #else
49 #define AT86RF2XX_TXPOWER_MAX (20)
50 #endif
51 
55 #ifdef MODULE_AT86RF212B
56 #define AT86RF2XX_TXPOWER_OFF (25)
57 #else
58 #define AT86RF2XX_TXPOWER_OFF (17)
59 #endif
60 
65 #define AT86RF2XX_WAKEUP_DELAY (306U)
66 
71 #define AT86RF2XX_RESET_PULSE_WIDTH (62U)
72 
79 #define AT86RF2XX_RESET_DELAY (62U)
80 
89 #if AT86RF2XX_IS_PERIPH
90 static inline uint8_t at86rf2xx_reg_read(const at86rf2xx_t *dev, volatile uint8_t *addr) {
91  (void) dev;
92  return *addr;
93 }
94 #else
95 uint8_t at86rf2xx_reg_read(const at86rf2xx_t *dev, uint8_t addr);
96 #endif
97 
105 #if AT86RF2XX_IS_PERIPH
106 static inline void at86rf2xx_reg_write(const at86rf2xx_t *dev, volatile uint8_t *addr,
107  const uint8_t value) {
108  (void) dev;
109  *addr = value;
110 }
111 #else
112 void at86rf2xx_reg_write(const at86rf2xx_t *dev, uint8_t addr, uint8_t value);
113 #endif
114 
123 #if AT86RF2XX_IS_PERIPH
124 static inline void at86rf2xx_sram_read(const at86rf2xx_t *dev, uint8_t offset,
125  uint8_t *data, size_t len) {
126  (void)dev;
127  memcpy(data, (void*)(AT86RF2XX_REG__TRXFBST + offset), len);
128 }
129 #else
130 void at86rf2xx_sram_read(const at86rf2xx_t *dev, uint8_t offset,
131  uint8_t *data, size_t len);
132 #endif
141 #if AT86RF2XX_IS_PERIPH
142 static inline void at86rf2xx_sram_write(const at86rf2xx_t *dev, uint8_t offset,
143  const uint8_t *data, size_t len) {
144  (void)dev;
145  memcpy((void*)(AT86RF2XX_REG__TRXFBST + offset), data, len);
146 }
147 #else
148 void at86rf2xx_sram_write(const at86rf2xx_t *dev, uint8_t offset,
149  const uint8_t *data, size_t len);
150 #endif
159 #if AT86RF2XX_IS_PERIPH
160 static inline void at86rf2xx_fb_start(const at86rf2xx_t *dev) {
161  (void) dev;
162 }
163 #else
165 #endif
175 #if AT86RF2XX_IS_PERIPH
176 static inline void at86rf2xx_fb_read(const at86rf2xx_t *dev, uint8_t *data, size_t len) {
177  (void)dev;
178  memcpy(data, (void*)AT86RF2XX_REG__TRXFBST, len);
179 }
180 #else
181 void at86rf2xx_fb_read(const at86rf2xx_t *dev, uint8_t *data, size_t len);
182 #endif
190 #if AT86RF2XX_IS_PERIPH
191 static inline void at86rf2xx_fb_stop(const at86rf2xx_t *dev) {
192  (void) dev;
193 }
194 #else
196 #endif
204 uint8_t at86rf2xx_get_status(const at86rf2xx_t *dev);
205 
212 
219 
228 void at86rf2xx_configure_phy(at86rf2xx_t *dev, uint8_t chan, uint8_t page, int16_t txpower);
229 
230 #if AT86RF2XX_RANDOM_NUMBER_GENERATOR || defined(DOXYGEN)
246 void at86rf2xx_get_random(at86rf2xx_t *dev, uint8_t *data, size_t len);
247 #endif
248 
255 void at86rf2xx_spi_init(at86rf2xx_t *dev, void (*irq_handler)(void *arg));
256 
264 static inline uint8_t at86rf2xx_get_rx_len(at86rf2xx_t *dev)
265 {
266  (void) dev;
267 #if AT86RF2XX_IS_PERIPH
268  return TST_RX_LENGTH;
269 #else
270  uint8_t phr;
271  at86rf2xx_fb_read(dev, &phr, 1);
272  return phr;
273 #endif
274 }
275 
284 static inline uint8_t at86rf2xx_get_irq_flags(at86rf2xx_t *dev)
285 {
286  (void) dev;
287 #if AT86RF2XX_IS_PERIPH
288  uint8_t irq_mask = dev->irq_status;
289  dev->irq_status = 0;
290  return irq_mask;
291 #else
292  return at86rf2xx_reg_read(dev, AT86RF2XX_REG__IRQ_STATUS);
293 #endif
294 
295 }
296 
297 #if AT86RF2XX_IS_PERIPH
298 /*
299  * Read a 32 bit register as described in section 10.3 of the datasheet: A read
300  * of the least significant byte causes the current value to be atomically
301  * captured in a temporary 32 bit registers. The remaining reads will access this
302  * register instead. Only a single 32 bit temporary register is used to provide
303  * means to atomically access them. Thus, interrupts must be disabled during the
304  * read sequence in order to prevent other threads (or ISRs) from updating the
305  * temporary 32 bit register before the reading sequence has completed.
306  */
307 static inline uint32_t reg32_read(volatile uint8_t *reg_ll)
308 {
309  le_uint32_t reg;
310  unsigned state = irq_disable();
311  reg.u8[0] = reg_ll[0];
312  reg.u8[1] = reg_ll[1];
313  reg.u8[2] = reg_ll[2];
314  reg.u8[3] = reg_ll[3];
315  irq_restore(state);
316  return reg.u32;
317 }
318 
326 static inline uint32_t at86rf2xx_get_sc(const at86rf2xx_t *dev)
327 {
328  (void) dev;
329  return reg32_read(&SCCNTLL);
330 }
331 
332 /* Symbol counter frequency is 62500Hz. One symbol counter tick is 16us = 16000 ns*/
333 #define SC_TO_NS (16000LU)
334 
335 #endif
336 
337 #ifdef __cplusplus
338 }
339 #endif
340 
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