cc2538_rf.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 MUTEX NZ Ltd.
3  * Copyright (C) 2015 Loci Controls Inc.
4  *
5  * This file is subject to the terms and conditions of the GNU Lesser
6  * General Public License v2.1. See the file LICENSE in the top level
7  * directory for more details.
8  *
9  */
10 
22 #ifndef CC2538_RF_H
23 #define CC2538_RF_H
24 
25 #include <stdbool.h>
26 
27 #include "net/ieee802154.h"
28 #include "net/netdev.h"
29 #include "net/netdev/ieee802154.h"
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 #define CC2538_AUTOCRC_LEN (2)
36 #define CC2538_RF_FIFO_SIZE (128)
37 #define CC2538_PACKET_LENGTH_SIZE (1)
38 
39 #define CC2538_RF_MAX_DATA_LEN (CC2538_RF_FIFO_SIZE - CC2538_PACKET_LENGTH_SIZE)
40 
41 #define CC2538_EUI64_LOCATION_PRI (0x00280028)
42 #define CC2538_EUI64_LOCATION_SEC (0x0027FFCC)
44 /* TODO: Move these to sys/include/net/ieee802154.h somehow */
45 /* IEEE 802.15.4 defined constants (2.4 GHz logical channels) */
46 #define IEEE802154_MIN_FREQ (2405)
47 #define IEEE802154_MAX_FREQ (2480)
49 #define IEEE802154_CHANNEL_SPACING (5)
51 #define IEEE802154_CHAN2FREQ(chan) ( IEEE802154_MIN_FREQ + ((chan) - IEEE802154_CHANNEL_MIN) * IEEE802154_CHANNEL_SPACING )
52 #define IEEE802154_FREQ2CHAN(freq) ( IEEE802154_CHANNEL_MIN + ((freq) - IEEE802154_MIN_FREQ) / IEEE802154_CHANNEL_SPACING )
53 /* /TODO */
54 
55 #define CC2538_MIN_FREQ (2394)
56 #define CC2538_MAX_FREQ (2507)
57 
58 #define CC2538_RF_POWER_DEFAULT (IEEE802154_DEFAULT_TXPOWER)
59 #define CC2538_RF_CHANNEL_DEFAULT (IEEE802154_DEFAULT_CHANNEL)
60 #define CC2538_RF_PANID_DEFAULT (IEEE802154_DEFAULT_PANID)
61 
62 #define OUTPUT_POWER_MIN (-24)
63 #define OUTPUT_POWER_MAX (7)
64 #define NUM_POWER_LEVELS ( OUTPUT_POWER_MAX - OUTPUT_POWER_MIN + 1 )
65 
66 #define CC2538_CORR_VAL_MIN (50U)
67 #define CC2538_CORR_VAL_MAX (110U)
68 #define CC2538_CORR_VAL_MASK (0x7F)
69 
70 #define CC2538_RSSI_OFFSET (-73)
71 #define CC2538_RF_SENSITIVITY (-97)
73 #define RFCORE_ASSERT(expr) (void)( (expr) || RFCORE_ASSERT_failure(#expr, __FUNCTION__, __LINE__) )
74 
75 #if DEVELHELP
76 #define RFCORE_WAIT_UNTIL(expr) while (!(expr)) { \
77  DEBUG("RFCORE_WAIT_UNTIL(%s) at line %u in %s()\n", #expr, __LINE__, __FUNCTION__); \
78  thread_yield(); \
79 }
80 #else
81 #define RFCORE_WAIT_UNTIL(expr) while (!(expr)) thread_yield()
82 #endif
83 
84 #define RFCORE_FLUSH_RECEIVE_FIFO() rfcore_strobe(ISFLUSHRX)
85 
86 #define ABS_DIFF(x, y) ( ((x) < (y))? ((y) - (x)) : ((x) - (y)) )
87 #define BOOLEAN(x) ( (x) != 0 )
88 #define NOT(x) ( (x) == 0 )
89 #define GET_BYTE(buffer, index) ( (unsigned char*)(buffer) )[index]
90 
91 #define BIT(n) ( 1 << (n) )
92 
93 enum {
94  FSM_STATE_IDLE = 0,
95  FSM_STATE_RX_CALIBRATION = 2,
96  FSM_STATE_TX_CALIBRATION = 32,
97 };
98 
99 /*
100  * @brief RFCORE_XREG_RFERRM bits
101  */
102 enum {
103  STROBE_ERR = BIT(6),
104  TXUNDERF = BIT(5),
105  TXOVERF = BIT(4),
106  RXUNDERF = BIT(3),
107  RXOVERF = BIT(2),
108  RXABO = BIT(1),
109  NLOCK = BIT(0),
110 };
111 
112  /*
113  * @brief RFCORE_XREG_FRMCTRL0 bits
114  */
115 enum {
116  ENERGY_SCAN = BIT(4),
117  AUTOACK = BIT(5),
118  AUTOCRC = BIT(6),
119  APPEND_DATA_MODE = BIT(7),
120 };
121 
122 /*
123  * @brief RFCORE_XREG_RFIRQM0 / RFCORE_XREG_RFIRQF0 bits
124  */
125 enum {
126  ACT_UNUSED = BIT(0),
127  SFD = BIT(1),
128  FIFOP = BIT(2),
129  SRC_MATCH_DONE = BIT(3),
130  SRC_MATCH_FOUND = BIT(4),
131  FRAME_ACCEPTED = BIT(5),
132  RXPKTDONE = BIT(6),
133  RXMASKZERO = BIT(7),
134 };
135 
136 /* Values for use with CCTEST_OBSSELx registers: */
137 #define OBSSEL_EN BIT(7)
138 enum {
139  rfc_obs_sig0 = 0,
140  rfc_obs_sig1 = 1,
141  rfc_obs_sig2 = 2,
142 };
143 
144 /* Values for RFCORE_XREG_RFC_OBS_CTRLx registers: */
145 enum {
146  constant_value_0 = 0x00,
147  constant_value_1 = 0x01,
148  rfc_sniff_data = 0x08,
149  rfc_sniff_clk = 0x09,
150  rssi_valid = 0x0c,
151  demod_cca = 0x0d,
152  sampled_cca = 0x0e,
153  sfd_sync = 0x0f,
154  tx_active = 0x10,
155  rx_active = 0x11,
156  ffctrl_fifo = 0x12,
157  ffctrl_fifop = 0x13,
158  packet_done = 0x14,
159  rfc_xor_rand_i_q = 0x16,
160  rfc_rand_q = 0x17,
161  rfc_rand_i = 0x18,
162  lock_status = 0x19,
163  pa_pd = 0x20,
164  lna_pd = 0x2a,
165 };
166 
172 typedef struct {
174  uint8_t state;
175 } cc2538_rf_t;
176 
181 void _irq_handler(void);
182 
189 bool cc2538_channel_clear(void);
190 
196 uint64_t cc2538_get_addr_long(void);
197 
203 uint16_t cc2538_get_addr_short(void);
204 
210 uint64_t cc2538_get_eui64_primary(void);
211 
217 unsigned int cc2538_get_chan(void);
218 
225 bool cc2538_get_monitor(void);
226 
232 uint16_t cc2538_get_pan(void);
233 
239 int cc2538_get_tx_power(void);
240 
245 void cc2538_init(void);
246 
253 bool cc2538_is_on(void);
254 
259 void cc2538_off(void);
260 
265 bool cc2538_on(void);
266 
272 void cc2538_setup(cc2538_rf_t *dev);
273 
279 void cc2538_set_addr_short(uint16_t addr);
280 
286 void cc2538_set_addr_long(uint64_t addr);
287 
293 void cc2538_set_chan(unsigned int chan);
294 
300 void cc2538_set_freq(unsigned int MHz);
301 
307 void cc2538_set_monitor(bool mode);
308 
314 void cc2538_set_pan(uint16_t pan);
315 
323 
329 void cc2538_set_tx_power(int dBm);
330 
331 #ifdef __cplusplus
332 }
333 #endif
334 
335 #endif /* CC2538_RF_H */
336 
void cc2538_set_freq(unsigned int MHz)
Set the frequency of the device.
Start of frame event.
Definition: cc2538_rf.h:127
Definitions low-level network driver interface.
uint8_t state
current state of the radio
Definition: cc2538_rf.h:174
void _irq_handler(void)
IRQ handler for RF events.
void cc2538_set_pan(uint16_t pan)
Set the PAN ID of the device.
IEEE 802.15.4 header definitions.
uint64_t cc2538_get_addr_long(void)
Get the configured long address of the device.
bool cc2538_channel_clear(void)
Trigger a clear channel assessment.
netdev_ieee802154_t netdev
netdev parent struct
Definition: cc2538_rf.h:173
void cc2538_off(void)
Deactivate the CC2538 radio device.
netopt_state_t
Option parameter to be used with NETOPT_STATE to set or get the state of a network device or protocol...
Definition: netopt.h:265
void cc2538_set_addr_long(uint64_t addr)
Set the long address of the device.
void cc2538_set_addr_short(uint16_t addr)
Set the short address of the device.
void cc2538_init(void)
Initialise the CC2538 radio hardware.
End of frame event.
Definition: cc2538_rf.h:132
Definitions for netdev common IEEE 802.15.4 code.
void cc2538_set_monitor(bool mode)
Enable/disable monitor (promiscuous) mode for the device.
bool cc2538_get_monitor(void)
Check if device is in monitor (promiscuous) mode.
Device descriptor for CC2538 transceiver.
Definition: cc2538_rf.h:172
uint16_t cc2538_get_addr_short(void)
Get the configured short address of the device.
void cc2538_set_state(cc2538_rf_t *dev, netopt_state_t state)
Set the state of the device.
int cc2538_get_tx_power(void)
Get the configured transmission power of the device.
Extended structure to hold IEEE 802.15.4 driver state.
bool cc2538_on(void)
Activate the CC2538 radio device.
void cc2538_set_chan(unsigned int chan)
Set the channel number of the device.
bool cc2538_is_on(void)
Check if device is active.
uint64_t cc2538_get_eui64_primary(void)
Get the primary (burned-in) EUI-64 of the device.
void cc2538_set_tx_power(int dBm)
Set the transmission power for the device.
uint16_t cc2538_get_pan(void)
Get the configured PAN ID of the device.
void cc2538_setup(cc2538_rf_t *dev)
Setup a CC2538 radio device for use with netdev.
unsigned int cc2538_get_chan(void)
Get the configured channel number of the device.