/
transceiver.h
226 lines (199 loc) · 6.22 KB
/
transceiver.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
/**
* @defgroup sys_transceiver Transceiver
* @ingroup sys
* @{
*
* @file transceiver.h
* @brief Transceiver library
* @author Oliver Hahm <oliver.hahm@inria.fr>
*/
#ifndef TRANSCEIVER_H
#define TRANSCEIVER_H
#include "radio/types.h"
/* supported transceivers *
* NOTE: necessary to include here again due to
* https://github.com/RIOT-OS/RIOT/issues/117 */
#ifdef MODULE_CC110X
#include "cc110x.h"
#ifndef TRANSCEIVER_DEFAULT
#define TRANSCEIVER_DEFAULT TRANSCEIVER_CC1100
#endif
#endif
#ifdef MODULE_CC110X_NG
#include "cc110x_ng.h"
#ifndef TRANSCEIVER_DEFAULT
#define TRANSCEIVER_DEFAULT TRANSCEIVER_CC1100
#endif
#endif
#ifdef MODULE_CC11020
#include "cc1020.h"
#ifndef TRANSCEIVER_DEFAULT
#define TRANSCEIVER_DEFAULT TRANSCEIVER_CC1020
#endif
#endif
#ifdef MODULE_CC2420
#include "cc2420.h"
#ifndef TRANSCEIVER_DEFAULT
#define TRANSCEIVER_DEFAULT TRANSCEIVER_CC2420
#endif
#endif
#ifdef MODULE_MC1322X
#include "mc1322x.h"
#include "maca.h"
#include "maca_packet.h"
#ifndef TRANSCEIVER_DEFAULT
#define TRANSCEIVER_DEFAULT TRANSCEIVER_MC1322X
#endif
#endif
#ifdef MODULE_NATIVENET
#include "nativenet.h"
#include "nativenet_internal.h"
#ifndef TRANSCEIVER_DEFAULT
#define TRANSCEIVER_DEFAULT TRANSCEIVER_NATIVE
#endif
#endif
#ifdef MODULE_AT86RF231
#include "at86rf231.h"
#ifndef TRANSCEIVER_DEFAULT
#define TRANSCEIVER_DEFAULT TRANSCEIVER_AT86RF231
#endif
#endif
/* Stack size for transceiver thread */
#ifndef TRANSCEIVER_STACK_SIZE
#define TRANSCEIVER_STACK_SIZE (KERNEL_CONF_STACKSIZE_DEFAULT)
#endif
#ifndef PAYLOAD_SIZE
#define PAYLOAD_SIZE (0)
#endif
#ifdef MODULE_CC110X
#if (CC1100_MAX_DATA_LENGTH > PAYLOAD_SIZE)
#undef PAYLOAD_SIZE
#define PAYLOAD_SIZE (CC1100_MAX_DATA_LENGTH)
#endif
#endif
#ifdef MODULE_CC110X_NG
#if (CC1100_MAX_DATA_LENGTH > PAYLOAD_SIZE)
#undef PAYLOAD_SIZE
#define PAYLOAD_SIZE (CC1100_MAX_DATA_LENGTH)
#endif
#endif
#ifdef MODULE_CC2420
#if (CC2420_MAX_DATA_LENGTH > PAYLOAD_SIZE)
#undef PAYLOAD_SIZE
#define PAYLOAD_SIZE (CC2420_MAX_DATA_LENGTH)
#endif
#endif
#ifdef MODULE_AT86RF231
#if (AT86RF231_MAX_DATA_LENGTH > PAYLOAD_SIZE)
#undef PAYLOAD_SIZE
#define PAYLOAD_SIZE (AT86RF231_MAX_DATA_LENGTH)
#endif
#endif
#ifdef MODULE_MC1322X
#if (MACA_MAX_PAYLOAD_SIZE > PAYLOAD_SIZE)
#undef PAYLOAD_SIZE
#define PAYLOAD_SIZE (MACA_MAX_PAYLOAD_SIZE)
#endif
#endif
#ifdef MODULE_NATIVENET
#if (NATIVE_MAX_DATA_LENGTH > PAYLOAD_SIZE)
#undef PAYLOAD_SIZE
#define PAYLOAD_SIZE (NATIVE_MAX_DATA_LENGTH)
#endif
#endif
/* The maximum of threads to register */
#define TRANSCEIVER_MAX_REGISTERED (4)
/* The size of the message queue between driver and transceiver (must be power
* of two */
#define TRANSCEIVER_MSG_BUFFER_SIZE (32)
/**
* @brief All supported transceivers
*/
#define TRANSCEIVER_NONE (0x0) ///< Invalid
#define TRANSCEIVER_CC1100 (0x01) ///< CC110X transceivers
#define TRANSCEIVER_CC1020 (0x02) ///< CC1020 transceivers
#define TRANSCEIVER_CC2420 (0x04) ///< CC2420 transceivers
#define TRANSCEIVER_MC1322X (0x08) ///< MC1322X transceivers
#define TRANSCEIVER_NATIVE (0x10) ///< NATIVE transceivers
#define TRANSCEIVER_AT86RF231 (0x20) ///< AT86RF231 transceivers
/**
* @brief Data type for transceiver specification
*/
typedef uint16_t transceiver_type_t;
/**
* @brief Data type to represent the transceiver's EUI-64.
*/
typedef uint64_t transceiver_eui64_t;
/**
* @brief Message types for transceiver interface
*/
enum transceiver_msg_type_t {
/* Message types for driver <-> transceiver communication */
RCV_PKT_CC1020, ///< packet was received by CC1020 transceiver
RCV_PKT_CC1100, ///< packet was received by CC1100 transceiver
RCV_PKT_CC2420, ///< packet was received by CC2420 transceiver
RCV_PKT_MC1322X, ///< packet was received by mc1322x transceiver
RCV_PKT_NATIVE, ///< packet was received by native transceiver
RCV_PKT_AT86RF231, ///< packet was received by AT86RF231 transceiver
/* Message types for transceiver <-> upper layer communication */
PKT_PENDING, ///< packet pending in transceiver buffer
SND_PKT, ///< request for sending a packet
SND_ACK, ///< request for sending an acknowledgement
SWITCH_RX, ///< switch transceiver to RX sate
POWERDOWN, ///< power down transceiver
GET_CHANNEL, ///< Get current channel
SET_CHANNEL, ///< Set a new channel
GET_ADDRESS, ///< Get the radio address
SET_ADDRESS, ///< Set the radio address
GET_LONG_ADDR, ///< Get the long radio address, if existing
SET_LONG_ADDR, ///< Set the long radio address, if supported by hardware
SET_MONITOR, ///< Set transceiver to monitor mode (disable address checking)
GET_PAN, ///< Get current pan
SET_PAN, ///< Set a new pan
/* debug message types */
DBG_IGN, ///< add a physical address to the ignore list
/* Error messages */
ENOBUFFER, ///< No buffer left
/* reserve message types for higher layer notifications */
UPPER_LAYER_1, ///< reserved
UPPER_LAYER_2, ///< reserved
UPPER_LAYER_3, ///< reserved
UPPER_LAYER_4, ///< reserved
UPPER_LAYER_5, ///< reserved
};
/**
* @brief Manage registered threads per transceiver
*/
typedef struct {
transceiver_type_t transceivers; ///< the tranceivers the thread is registered for
int pid; ///< the thread's pid
} registered_t;
typedef struct {
transceiver_type_t transceivers;
void *data;
} transceiver_command_t;
/* The transceiver thread's pid */
extern int transceiver_pid;
/**
* @brief Initializes the transceiver module for certain transceiver types
*
* @param transceivers Specifies all transceivers to init
**/
void transceiver_init(transceiver_type_t transceivers);
/**
* @brief Runs the transceiver thread
*
* @return The transceiver thread's pid
*/
int transceiver_start(void);
/**
* @brief register a thread for events from certain transceivers
*
* @param transceivers The transceiver types to register for
* @param pid The pid of the thread to register
*
* @return 1 on success, 0 otherwise
*/
uint8_t transceiver_register(transceiver_type_t transceivers, int pid);
#endif /* TRANSCEIVER_H */
/** @} */