Skip to content

Commit 8696cd8

Browse files
committed
nuttx/wireless/ioctl: Common IOCTL API for RF Modulation Technologies
Signed-off-by: Kevin Witteveen (MartiniMarter) <[email protected]>
1 parent e15f7b1 commit 8696cd8

File tree

1 file changed

+264
-44
lines changed

1 file changed

+264
-44
lines changed

include/nuttx/wireless/ioctl.h

Lines changed: 264 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -48,67 +48,214 @@
4848
* the open() interface.
4949
****************************************************************************/
5050

51-
#define WLIOC_SETRADIOFREQ _WLCIOC(0x0001) /* arg: Pointer to uint32_t, */
52-
/* frequency value (in MHz) */
53-
#define WLIOC_GETRADIOFREQ _WLCIOC(0x0002) /* arg: Pointer to uint32_t, */
54-
/* frequency value (in MHz) */
55-
#define WLIOC_SETADDR _WLCIOC(0x0003) /* arg: Pointer to address value, format
56-
* of the address is driver specific */
57-
#define WLIOC_GETADDR _WLCIOC(0x0004) /* arg: Pointer to address value, format
58-
* of the address is driver specific */
59-
#define WLIOC_SETTXPOWER _WLCIOC(0x0005) /* arg: Pointer to int32_t, */
60-
/* output power (in 0.01 dBm) */
61-
#define WLIOC_GETTXPOWER _WLCIOC(0x0006) /* arg: Pointer to int32_t, */
62-
/* output power (in 0.01 dBm) */
51+
/****************************************************************************
52+
* RF common IOCTL commands
53+
****************************************************************************/
54+
55+
/* Offsets */
56+
57+
#define _WLIOC_COM_OFFS 1
58+
#define _WLIOC_COM(x) _WLCIOC(_WLIOC_COM_OFFS+x)
59+
60+
/* Commands */
61+
62+
#define WLIOC_SETRADIOFREQ _WLIOC_COM(0) /* arg: Pointer to uint32_t, */
63+
/* frequency value (in Hz) */
64+
#define WLIOC_GETRADIOFREQ _WLIOC_COM(1) /* arg: Pointer to uint32_t, */
65+
/* frequency value (in Hz) */
66+
67+
#define WLIOC_SETADDR _WLIOC_COM(2) /* arg: Pointer to address value, format
68+
* of the address is driver specific */
69+
#define WLIOC_GETADDR _WLIOC_COM(3) /* arg: Pointer to address value, format
70+
* of the address is driver specific */
71+
72+
#define WLIOC_SETTXPOWER _WLIOC_COM(4) /* arg: Pointer to int32_t, */
73+
/* Set output power in dBm */
74+
#define WLIOC_GETTXPOWER _WLIOC_COM(5) /* arg: Pointer to int32_t, */
75+
/* Get output power in dBm */
76+
77+
#define WLIOC_SETFINEPOWER _WLIOC_COM(6) /* arg: Pointer to int32_t,
78+
* Set power in steps of 0.01 dBm */
79+
#define WLIOC_GETFINEPOWER _WLIOC_COM(7) /* arg: Pointer to int32_t,
80+
* Get power in steps of 0.01 dBm */
81+
82+
#define WLIOC_SETMODU _WLIOC_COM(8) /* arg: Pointer to enum wlioc_modulation_e.
83+
* This sets the modulation technology. */
84+
#define WLIOC_GETMODU _WLIOC_COM(9) /* arg: Pointer to enum wlioc_modulation_e.
85+
* Get current modulation technology. */
86+
87+
/* Number of commands */
88+
89+
#define _WLIOC_COM_COMMANDS 10 /* ! Must be corrected after changes to commands.
90+
* ! Equal to the amount of commands above. */
91+
92+
/****************************************************************************
93+
* LoRa common IOCTL commands
94+
****************************************************************************/
95+
96+
/* Offsets */
97+
98+
#define _WLIOC_LORA_OFFS _WLIOC_COM_OFFS+_WLIOC_COM_COMMANDS
99+
#define _WLIOC_LORA(x) _WLCIOC(_WLIOC_LORA_OFFS+x)
100+
101+
/* Commands */
102+
103+
#define WLIOC_LORA_SETSF _WLIOC_LORA(0) /* arg: Pointer to uint8_t */
104+
/* Spreading factor */
105+
#define WLIOC_LORA_GETSF _WLIOC_LORA(1) /* arg: Pointer to uint8_t */
106+
/* Spreading factor */
107+
108+
#define WLIOC_LORA_SETBW _WLIOC_LORA(2) /* arg: Pointer to uint32_t */
109+
/* Bandwidth Hz */
110+
#define WLIOC_LORA_GETBW _WLIOC_LORA(3) /* arg: Pointer to uint32_t */
111+
/* Bandwidth Hz */
112+
113+
#define WLIOC_LORA_SETCR _WLIOC_LORA(4) /* arg: Pointer to wlioc_lora_cr_e */
114+
/* Coding rate */
115+
#define WLIOC_LORA_GETCR _WLIOC_LORA(5) /* arg: Pointer to wlioc_lora_cr_e */
116+
/* Coding rate */
117+
118+
#define WLIOC_LORA_SETCRC _WLIOC_LORA(6) /* arg: Pointer to uint8_t */
119+
/* Enable/disable CRC */
120+
#define WLIOC_LORA_GETCRC _WLIOC_LORA(7) /* arg: Pointer to uint8_t */
121+
/* Enabled/disabled CRC */
122+
123+
#define WLIOC_LORA_SETFIXEDHDR _WLIOC_LORA(8) /* arg: Pointer to uint8_t */
124+
/* Enable/disable length byte */
125+
#define WLIOC_LORA_GETFIXEDHDR _WLIOC_LORA(9) /* arg: Pointer to uint8_t */
126+
/* Enabled/disabled length byte */
127+
128+
#define WLIOC_LORA_SETSYNCWORD _WLIOC_LORA(10) /* arg: Pointer to wlioc_lora_syncword_s */
129+
/* Sets custom length syncword */
130+
#define WLIOC_LORA_GETSYNCWORD _WLIOC_LORA(11) /* arg: Pointer to wlioc_lora_syncword_s */
131+
/* Gets custom length syncword */
132+
133+
/* Number of commands */
134+
135+
#define _WLIOC_LORA_COMMANDS 12 /* ! Must be corrected after changes to commands.
136+
* ! Equal to the amount of commands above. */
137+
138+
/****************************************************************************
139+
* FSK common IOCTL commands (Including GFSK and similar)
140+
****************************************************************************/
141+
142+
/* Offsets. Must follow WLIOC_LORA */
143+
144+
#define _WLIOC_FSK_OFFS _WLIOC_LORA_OFFS+_WLIOC_LORA_COMMANDS
145+
#define _WLIOC_FSK(x) _WLCIOC(_WLIOC_FSK_OFFS+x)
146+
147+
/* Commands */
148+
149+
#define WLIOC_FSK_SETBITRATE _WLIOC_FSK(0) /* arg: uint32_t ptr */
150+
/* In bits per second */
151+
#define WLIOC_FSK_GETBITRATE _WLIOC_FSK(1) /* arg: uint32_t ptr */
152+
/* In bits per second */
153+
154+
#define WLIOC_FSK_SETFDEV _WLIOC_FSK(2) /* arg: uint32_t ptr */
155+
/* Frequency deviation Hz */
156+
#define WLIOC_FSK_GETFDEV _WLIOC_FSK(3) /* arg: uint32_t ptr */
157+
/* Frequency deviation Hz */
158+
159+
/* Number of commands */
160+
161+
#define _WLIOC_FSK_COMMANDS 4 /* ! Must be corrected after changes to commands.
162+
* ! Equal to the amount of commands above. */
163+
164+
/****************************************************************************
165+
* OOK (Also called "binary" ASK) common IOCTL commands
166+
****************************************************************************/
167+
168+
/* Offsets. Must follow WLIOC_FSK */
169+
170+
#define _WLIOC_OOK_OFFS _WLIOC_FSK_OFFS+_WLIOC_FSK_COMMANDS
171+
#define _WLIOC_OOK(x) _WLCIOC(_WLIOC_OOK_OFFS+x)
172+
173+
/* Commands */
174+
175+
#define WLIOC_OOK_SETBITRATE _WLIOC_OOK(0) /* arg: uint32_t ptr */
176+
/* In bits per second */
177+
#define WLIOC_OOK_GETBITRATE _WLIOC_OOK(1) /* arg: uint32_t ptr */
178+
/* In bits per second */
179+
180+
/* Number of commands */
181+
182+
#define _WLIOC_OOK_COMMANDS 2 /* ! Must be corrected after changes to commands.
183+
* ! Equal to the amount of commands above. */
184+
185+
/****************************************************************************
186+
* Device-specific IOCTL commands
187+
****************************************************************************/
63188

64189
/* WARNING: The following WLIOC command are EXPERIMENTAL and unstable. They
65190
* may be removed or modified in upcoming changes that introduce a common
66191
* LoRa API. These commands are currently only used by the RN2XX3 driver.
67192
*/
68193

69-
#define WLIOC_SETBANDWIDTH _WLCIOC(0x0007) /* arg: Pointer to uint32_t, */
194+
/* Offsets. Must follow WLIOC_OOK */
195+
196+
#define _WLIOC_RN2XX3_OFFS _WLIOC_OOK_OFFS+_WLIOC_OOK_COMMANDS
197+
#define _WLIOC_RN2XX3(x) _WLCIOC(_WLIOC_RN2XX3_OFFS+x)
198+
199+
/* Commands */
200+
201+
#define WLIOC_SETBANDWIDTH _WLIOC_RN2XX3(0) /* arg: Pointer to uint32_t, */
70202
/* bandwidth in Hz */
71-
#define WLIOC_GETBANDWIDTH _WLCIOC(0x0008) /* arg: Pointer to uint32_t, */
203+
#define WLIOC_GETBANDWIDTH _WLIOC_RN2XX3(1) /* arg: Pointer to uint32_t, */
72204
/* bandwidth in Hz */
73-
#define WLIOC_SETSPREAD _WLCIOC(0x0009) /* arg: Pointer to uint8_t, */
205+
206+
#define WLIOC_SETSPREAD _WLIOC_RN2XX3(2) /* arg: Pointer to uint8_t, */
74207
/* spread factor */
75-
#define WLIOC_GETSPREAD _WLCIOC(0x000a) /* arg: Pointer to uint8_t, */
208+
#define WLIOC_GETSPREAD _WLIOC_RN2XX3(3) /* arg: Pointer to uint8_t, */
76209
/* spread factor */
77-
#define WLIOC_GETSNR _WLCIOC(0x000b) /* arg: Pointer to int8_t, */
210+
211+
#define WLIOC_GETSNR _WLIOC_RN2XX3(4) /* arg: Pointer to int8_t, */
78212
/* signal to noise ratio */
79-
#define WLIOC_SETPRLEN _WLCIOC(0x000c) /* arg: uint16_t, */
213+
214+
#define WLIOC_SETPRLEN _WLIOC_RN2XX3(5) /* arg: uint16_t, */
80215
/* preamble length */
81-
#define WLIOC_GETPRLEN _WLCIOC(0x000d) /* arg: Pointer to uint16_t, */
216+
#define WLIOC_GETPRLEN _WLIOC_RN2XX3(6) /* arg: Pointer to uint16_t, */
82217
/* preamble length */
83-
#define WLIOC_SETMOD _WLCIOC(0x000e) /* arg: enum, */
218+
219+
#define WLIOC_SETMOD _WLIOC_RN2XX3(7) /* arg: enum, */
84220
/* modulation type */
85-
#define WLIOC_GETMOD _WLCIOC(0x000f) /* arg: enum pointer, */
221+
#define WLIOC_GETMOD _WLIOC_RN2XX3(8) /* arg: enum pointer, */
86222
/* modulation type */
87-
#define WLIOC_RESET _WLCIOC(0x0010) /* arg: none */
88-
#define WLIOC_SETSYNC _WLCIOC(0x0011) /* arg: uint64_t pointer */
89-
/* sync word */
90-
#define WLIOC_GETSYNC _WLCIOC(0x0012) /* arg: uint64_t pointer, */
91-
/* sync word */
92-
#define WLIOC_SETBITRATE _WLCIOC(0x0013) /* arg: uint32_t */
93-
/* sync word */
94-
#define WLIOC_GETBITRATE _WLCIOC(0x0014) /* arg: uint32_t pointer, */
95-
/* sync word */
96-
#define WLIOC_IQIEN _WLCIOC(0x0015) /* arg: bool, enable invert IQ */
97-
#define WLIOC_CRCEN _WLCIOC(0x0016) /* arg: bool, enable CRC */
98-
#define WLIOC_SETCODERATE _WLCIOC(0x0017) /* arg: enum, coding rate */
99-
#define WLIOC_GETCODERATE _WLCIOC(0x0018) /* arg: enum pointer, */
100-
/* coding rate */
101-
#define WLIOC_SETTXPOWERF _WLCIOC(0x0019) /* arg: Pointer to flaot, */
102-
/* output power (in dBm) */
103-
#define WLIOC_GETTXPOWERF _WLCIOC(0x0020) /* arg: Pointer to float, */
104-
/* output power (in dBm) */
105223

106-
/****************************************************************************
107-
* Device-specific IOCTL commands
108-
****************************************************************************/
224+
#define WLIOC_RESET _WLIOC_RN2XX3(9) /* arg: none */
225+
226+
#define WLIOC_SETSYNC _WLIOC_RN2XX3(10) /* arg: uint64_t pointer */
227+
/* sync word */
228+
#define WLIOC_GETSYNC _WLIOC_RN2XX3(11) /* arg: uint64_t pointer, */
229+
/* sync word */
230+
231+
#define WLIOC_SETBITRATE _WLIOC_RN2XX3(12) /* arg: uint32_t */
232+
/* sync word */
233+
#define WLIOC_GETBITRATE _WLIOC_RN2XX3(13) /* arg: uint32_t pointer, */
234+
/* sync word */
235+
236+
#define WLIOC_IQIEN _WLIOC_RN2XX3(14) /* arg: bool, enable invert IQ */
237+
#define WLIOC_CRCEN _WLIOC_RN2XX3(15) /* arg: bool, enable CRC */
238+
239+
#define WLIOC_SETCODERATE _WLIOC_RN2XX3(16) /* arg: enum, coding rate */
240+
#define WLIOC_GETCODERATE _WLIOC_RN2XX3(17) /* arg: enum pointer, */
241+
/* coding rate */
242+
243+
#define WLIOC_SETTXPOWERF _WLIOC_RN2XX3(18) /* arg: Pointer to float, */
244+
/* output power (in dBm) */
245+
#define WLIOC_GETTXPOWERF _WLIOC_RN2XX3(19) /* arg: Pointer to float, */
246+
/* output power (in dBm) */
247+
248+
/* Number of commands */
249+
250+
#define _WLIOC_RN2XX3_COMMANDS 20 /* ! Must be corrected after changes to commands.
251+
* ! Equal to the amount of commands above. */
252+
253+
/* End of RN2XX3 experimental warning */
254+
255+
/* Offsets */
109256

110-
#define WL_FIRST 0x0001 /* First common command */
111-
#define WL_NCMDS 0x0020 /* Number of common commands */
257+
#define WL_FIRST 0x0001 /* First common command */
258+
#define WL_NCMDS _WLIOC_RN2XX3_OFFS+_WLIOC_RN2XX3_COMMANDS
112259

113260
/* User defined ioctl commands are also supported. These will be forwarded
114261
* by the upper-half driver to the lower-half driver via the ioctl()
@@ -141,5 +288,78 @@
141288
* Public Types
142289
****************************************************************************/
143290

291+
/* wlioc_mod_type_e is the RF modualtion technology to be used. */
292+
293+
enum wlioc_modulation_e
294+
{
295+
WLIOC_LORA,
296+
WLIOC_FSK,
297+
WLIOC_GFSK,
298+
WLIOC_OOK
299+
};
300+
301+
/* LoRa common types ********************************************************/
302+
303+
/* wlioc_lora_cr_e is the coding rate, which is commonly
304+
* supported by LoRa devices to correct errors.
305+
*/
306+
307+
enum wlioc_lora_cr_e
308+
{
309+
WLIOC_LORA_CR_4_5 = 0x01,
310+
WLIOC_LORA_CR_4_6 = 0x02,
311+
WLIOC_LORA_CR_4_7 = 0x03,
312+
WLIOC_LORA_CR_4_8 = 0x04
313+
};
314+
315+
/* wlioc_lora_syncword_s is used to seperate lora networks.
316+
* Radios will try to catch only packets with the specified syncword.
317+
*/
318+
319+
struct wlioc_lora_syncword_s
320+
{
321+
size_t syncword_length;
322+
uint8_t *syncword;
323+
};
324+
325+
/* Common RF types **********************************************************/
326+
327+
/* wlioc_rx_hdr_s gets written to by reading the character device.
328+
* Contains information about the payload.
329+
*/
330+
331+
struct wlioc_rx_hdr_s
332+
{
333+
/* Length of payload in bytes.
334+
* The amount written to the
335+
* payload buffer
336+
*/
337+
338+
size_t payload_length;
339+
340+
/* Pointer to user buffer
341+
* This will be filled in with
342+
* the payload
343+
*/
344+
345+
uint8_t *payload_buffer;
346+
347+
/* When error detection is supported and enabled,
348+
* this will be greater than 0 when an error is
349+
* detected. The payload is still returned which
350+
* allows the user to reconstruct the payload
351+
*/
352+
353+
uint8_t error;
354+
355+
/* RSSI dBm in 1/100 dBm */
356+
357+
int32_t rssi_dbm;
358+
359+
/* SNR dB in 1/100 dB */
360+
361+
int32_t snr_db;
362+
};
363+
144364
#endif /* CONFIG_DRIVERS_WIRELESS */
145365
#endif /* __INCLUDE_NUTTX_WIRELESS_IOCTL_H */

0 commit comments

Comments
 (0)