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 
24 #ifndef AT86RF2XX_INTERNAL_H
25 #define AT86RF2XX_INTERNAL_H
26 
27 #include <stdint.h>
28 
29 #include "at86rf2xx.h"
30 
31 #if AT86RF2XX_IS_PERIPH
32 #include <string.h>
33 #include "irq.h"
34 #include "time_units.h"
35 #endif
36 #include "at86rf2xx_registers.h"
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
45 #ifdef MODULE_AT86RF212B
46 #define AT86RF2XX_TXPOWER_MAX (36)
47 #elif MODULE_AT86RF233
48 #define AT86RF2XX_TXPOWER_MAX (21)
49 #else
50 #define AT86RF2XX_TXPOWER_MAX (20)
51 #endif
52 
56 #ifdef MODULE_AT86RF212B
57 #define AT86RF2XX_TXPOWER_OFF (25)
58 #else
59 #define AT86RF2XX_TXPOWER_OFF (17)
60 #endif
61 
66 #define AT86RF2XX_WAKEUP_DELAY (306U)
67 
72 #define AT86RF2XX_RESET_PULSE_WIDTH (62U)
73 
80 #define AT86RF2XX_RESET_DELAY (62U)
81 
90 #if AT86RF2XX_IS_PERIPH
91 static inline uint8_t at86rf2xx_reg_read(const at86rf2xx_t *dev, volatile uint8_t *addr) {
92  (void) dev;
93  return *addr;
94 }
95 #else
96 uint8_t at86rf2xx_reg_read(const at86rf2xx_t *dev, uint8_t addr);
97 #endif
98 
106 #if AT86RF2XX_IS_PERIPH
107 static inline void at86rf2xx_reg_write(const at86rf2xx_t *dev, volatile uint8_t *addr,
108  const uint8_t value) {
109  (void) dev;
110  *addr = value;
111 }
112 #else
113 void at86rf2xx_reg_write(const at86rf2xx_t *dev, uint8_t addr, uint8_t value);
114 #endif
115 
124 #if AT86RF2XX_IS_PERIPH
125 static inline void at86rf2xx_sram_read(const at86rf2xx_t *dev, uint8_t offset,
126  uint8_t *data, size_t len) {
127  (void)dev;
128  memcpy(data, (void*)(AT86RF2XX_REG__TRXFBST + offset), len);
129 }
130 #else
131 void at86rf2xx_sram_read(const at86rf2xx_t *dev, uint8_t offset,
132  uint8_t *data, size_t len);
133 #endif
142 #if AT86RF2XX_IS_PERIPH
143 static inline void at86rf2xx_sram_write(const at86rf2xx_t *dev, uint8_t offset,
144  const uint8_t *data, size_t len) {
145  (void)dev;
146  memcpy((void*)(AT86RF2XX_REG__TRXFBST + offset), data, len);
147 }
148 #else
149 void at86rf2xx_sram_write(const at86rf2xx_t *dev, uint8_t offset,
150  const uint8_t *data, size_t len);
151 #endif
160 #if AT86RF2XX_IS_PERIPH
161 static inline void at86rf2xx_fb_start(const at86rf2xx_t *dev) {
162  (void) dev;
163 }
164 #else
166 #endif
176 #if AT86RF2XX_IS_PERIPH
177 static inline void at86rf2xx_fb_read(const at86rf2xx_t *dev, uint8_t *data, size_t len) {
178  (void)dev;
179  memcpy(data, (void*)AT86RF2XX_REG__TRXFBST, len);
180 }
181 #else
182 void at86rf2xx_fb_read(const at86rf2xx_t *dev, uint8_t *data, size_t len);
183 #endif
191 #if AT86RF2XX_IS_PERIPH
192 static inline void at86rf2xx_fb_stop(const at86rf2xx_t *dev) {
193  (void) dev;
194 }
195 #else
197 #endif
205 uint8_t at86rf2xx_get_status(const at86rf2xx_t *dev);
206 
213 
220 
229 void at86rf2xx_configure_phy(at86rf2xx_t *dev, uint8_t chan, uint8_t page, int16_t txpower);
230 
231 #if AT86RF2XX_RANDOM_NUMBER_GENERATOR || defined(DOXYGEN)
247 void at86rf2xx_get_random(at86rf2xx_t *dev, uint8_t *data, size_t len);
248 #endif
249 
256 void at86rf2xx_spi_init(at86rf2xx_t *dev, void (*irq_handler)(void *arg));
257 
265 static 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 
285 static inline uint8_t at86rf2xx_get_irq_flags(at86rf2xx_t *dev)
286 {
287  (void) dev;
288 #if AT86RF2XX_IS_PERIPH
289  uint8_t irq_mask = dev->irq_status;
290  dev->irq_status = 0;
291  return irq_mask;
292 #else
293  return at86rf2xx_reg_read(dev, AT86RF2XX_REG__IRQ_STATUS);
294 #endif
295 
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  */
308 static 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 
327 static 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 
342 #endif /* AT86RF2XX_INTERNAL_H */
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:283
Utility header providing time unit defines.
A 32 bit integer in little endian.
Definition: byteorder.h:48
uint32_t u32
32 bit representation
Definition: byteorder.h:49
uint8_t u8[4]
8 bit representation
Definition: byteorder.h:50