kw2xrf.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 Phytec Messtechnik GmbH
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
23 #ifndef KW2XRF_H
24 #define KW2XRF_H
25 
26 #include <stdint.h>
27 
28 #include "board.h"
29 #include "periph/spi.h"
30 #include "periph/gpio.h"
31 #include "net/netdev.h"
32 #include "net/netdev/ieee802154.h"
33 #include "net/gnrc/nettype.h"
34 #include "thread.h"
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
43 #define KW2XRF_MAX_PKT_LENGTH (IEEE802154_FRAME_LEN_MAX)
44 
53 #ifndef KW2XRF_DEFAULT_CHANNEL
54 #define KW2XRF_DEFAULT_CHANNEL (CONFIG_IEEE802154_DEFAULT_CHANNEL)
55 #endif
56 
63 #define KW2XRF_MIN_CHANNEL (11U)
64 #define KW2XRF_MAX_CHANNEL (26U)
65 
70 #define KW2XRF_DEFAULT_TX_POWER (CONFIG_IEEE802154_DEFAULT_TXPOWER)
71 
75 #define KW2XDRF_OUTPUT_POWER_MAX (8)
76 
80 #define KW2XDRF_OUTPUT_POWER_MIN (-35)
81 
90 #define KW2XRF_OPT_SRC_ADDR_LONG (NETDEV_IEEE802154_SRC_MODE_LONG)
91 #define KW2XRF_OPT_RAWDUMP (NETDEV_IEEE802154_RAW)
92 #define KW2XRF_OPT_ACK_REQ (NETDEV_IEEE802154_ACK_REQ)
94 #define KW2XRF_OPT_AUTOCCA (0x0100)
95 #define KW2XRF_OPT_PROMISCUOUS (0x0200)
97 #define KW2XRF_OPT_PRELOADING (0x0400)
98 #define KW2XRF_OPT_TELL_TX_START (0x0800)
100 #define KW2XRF_OPT_TELL_TX_END (0x1000)
102 #define KW2XRF_OPT_TELL_RX_START (0x2000)
104 #define KW2XRF_OPT_TELL_RX_END (0x4000)
106 #define KW2XRF_OPT_AUTOACK (0x8000)
113 typedef struct kw2xrf_params {
116  gpio_t cs_pin;
117  gpio_t int_pin;
119 
125 typedef struct {
133  uint8_t buf[KW2XRF_MAX_PKT_LENGTH];
134  uint8_t state;
135  uint8_t tx_frame_len;
136  uint8_t idle_state;
137  uint8_t pending_tx;
140  int16_t tx_power;
142 } kw2xrf_t;
143 
150 void kw2xrf_setup(kw2xrf_t *dev, const kw2xrf_params_t *params);
151 
160 int kw2xrf_init(kw2xrf_t *dev, gpio_cb_t cb);
161 
167 void kw2xrf_reset_phy(kw2xrf_t *dev);
168 
169 #ifdef __cplusplus
170 }
171 #endif
172 
173 #endif /* KW2XRF_H */
174 
kw2xrf_t::idle_state
uint8_t idle_state
state to return to after sending
Definition: kw2xrf.h:136
ieee802154.h
Definitions for netdev common IEEE 802.15.4 code.
kw2xrf_setup
void kw2xrf_setup(kw2xrf_t *dev, const kw2xrf_params_t *params)
Setup an KW2XRF based device state.
KW2XRF_MAX_PKT_LENGTH
#define KW2XRF_MAX_PKT_LENGTH
Maximum packet length.
Definition: kw2xrf.h:43
kw2xrf_params::spi
spi_t spi
SPI bus the device is connected to.
Definition: kw2xrf.h:114
spi.h
Low-level SPI peripheral driver interface definition.
kw2xrf_params::int_pin
gpio_t int_pin
GPIO pin connected to the interrupt pin.
Definition: kw2xrf.h:117
kw2xrf_init
int kw2xrf_init(kw2xrf_t *dev, gpio_cb_t cb)
Initialize the given KW2XRF device.
kw2xrf_t::tx_frame_len
uint8_t tx_frame_len
length of the current TX frame
Definition: kw2xrf.h:135
kw2xrf_reset_phy
void kw2xrf_reset_phy(kw2xrf_t *dev)
Configure radio with default values.
spi_clk_t
spi_clk_t
Available SPI clock speeds.
Definition: spi.h:173
netdev.h
Definitions low-level network driver interface.
kw2xrf_t::thread
thread_t * thread
device specific fields
Definition: kw2xrf.h:131
_thread
thread_t holds thread's context data.
Definition: thread.h:154
nettype.h
Protocol type definitions.
kw2xrf_params
Struct holding all params needed for device initialization.
Definition: kw2xrf.h:113
kw2xrf_params::cs_pin
gpio_t cs_pin
GPIO pin connected to chip select.
Definition: kw2xrf.h:116
gpio_cb_t
void(* gpio_cb_t)(void *arg)
Signature of event callback functions triggered from interrupts.
Definition: gpio.h:146
netdev_ieee802154_t
Extended structure to hold IEEE 802.15.4 driver state.
Definition: ieee802154.h:90
kw2xrf_t::params
kw2xrf_params_t params
parameters for initialization
Definition: kw2xrf.h:132
gpio.h
Low-level GPIO peripheral driver interface definitions.
kw2xrf_t::tx_power
int16_t tx_power
The current tx-power setting of the device.
Definition: kw2xrf.h:140
kw2xrf_t::state
uint8_t state
current state of the radio
Definition: kw2xrf.h:134
kw2xrf_params::spi_clk
spi_clk_t spi_clk
SPI clock speed to use.
Definition: kw2xrf.h:115
kw2xrf_t::netdev
netdev_ieee802154_t netdev
netdev parent struct
Definition: kw2xrf.h:126
kw2xrf_t
Device descriptor for KW2XRF radio devices.
Definition: kw2xrf.h:125
kw2xrf_params_t
struct kw2xrf_params kw2xrf_params_t
Struct holding all params needed for device initialization.
spi_t
unsigned int spi_t
Default type for SPI devices.
Definition: spi.h:118
kw2xrf_t::pending_tx
uint8_t pending_tx
keep track of pending TX calls this is required to know when to return to kw2xrf_t::idle_state
Definition: kw2xrf.h:137