-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathll_ifc.h
471 lines (429 loc) · 11.4 KB
/
ll_ifc.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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
#ifndef __LL_IFC_H
#define __LL_IFC_H
#include <stdint.h>
#include <time.h>
#include "ll_ifc_consts.h"
#include "ifc_struct_defs.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @defgroup Link_Labs_Interface_Library ll_ifc
*
* @brief External host library which simplifies communication to an RF
* network using a Link Labs module.
*
* This library runs on an <b>external host</b> which can be nearly any
* microcontroller or PC with a UART interface. The library
* is written in standard ANSI C (C89) which is supported by nearly every
* C compiler. In addition to the standard C library, the external host
* must implement a handful of functions. See @ref HAL_Interface
* for the list of required functions.
*
* Link Labs modules can support different modes of operation,
* and the external host can dynamically select the operating mode using
* ll_mac_mode_set(). The available operating modes are:
* - @ref Symphony_Interface (915 MHz)
* - @ref LoRaWAN_Interface (868 MHz and 915 MHz)
* - @ref NoMac_Interface (868 MHz and 915 MHz)
* - @ref Ensemble_Interface (868 MHz and 915 MHz)
*
* In addition to the functions unique to each operating mode, the API
* includes a number of common management functions. The
* \ref Module_Interface API provides these common functions.
*
* @{
*/
/**
* @defgroup HAL_Interface HAL
*
* @brief The hardware abstraction layer (HAL) for ll_ifc.
*
* All functions in the HAL are used by the Link Lab's Interface library
* (ll_ifc). These functions must be defined by the program using the
* Link Lab's Interface Library.
*
* @{
*/
/**
* @brief Write data to the Link Lab's module.
*
* @param[in] buff
* The buffer containing the data to write to the module. The size of
* buff must be at least len bytes.
*
* @param[in] len
* The number of bytes to write.
*
* @return
* 0 - success, negative otherwise
*
* This function is usually a simple UART wrapper.
*/
int32_t transport_write(uint8_t *buff, uint16_t len);
/**
* @brief Read data from the Link Lab's module.
*
* @param[inout] buff
* The buffer that will be modified with the data read from the module.
* The size of buff must be at least len bytes.
*
* @param[in] len
* The number of bytes to read.
*
* @return
* 0 - success, negative otherwise
*
* This function is usually a simple UART wrapper.
*/
int32_t transport_read(uint8_t *buff, uint16_t len);
/**
* @brief The structure used to store time.
*/
struct time
{
long tv_sec;
long tv_nsec;
};
/**
* @brief
* Get the current time.
*
* @param[out] tp
* Current value of the clock which
*
* @return
* 0 - success, negative otherwise
*/
int32_t gettime(struct time *tp);
/**
* @brief
* Sleep for a number of milliseconds
*
* @param[in] millis
* number of milliseconds
*
* @return
* 0 - success, negative otherwise
*/
int32_t sleep_ms(int32_t millis);
/** @} (end defgroup HAL_Interface) */
/**
* @addtogroup Module_Interface Core
* @brief Core functions and data structures used to communicate with the
* module across different MAC modes.
*
* @{
*/
/**
* @brief
* Convert an return code into a short name string.
*
* @param[in] return_code
* The return code.
*
* @return
* The short name string.
*/
char const * ll_return_code_name(int32_t return_code);
/**
* @brief
* Convert an return code into a description.
*
* @param[in] return_code
* The return code.
*
* @return
* The user-meaningful return code description.
*/
char const * ll_return_code_description(int32_t return_code);
/**
* @brief
* Get the module firmware type
*
* @param[out] t
* pointer to a firmware type struct
*
* @return
* 0 - success, negative otherwise
*/
int32_t ll_firmware_type_get(ll_firmware_type_t *t);
/**
* @brief
* Get the module hardware type
*
* @param[out] t
* pointer to a hardware type enum
*
* @return
* 0 - success, negative otherwise
*/
int32_t ll_hardware_type_get(ll_hardware_type_t *t);
/**
* @brief
* Get the string for the module hardware type
*
* @param[in] t
* The hardware type enum, usually from ll_hardware_type_get().
*
* @return
* The string describing the hardware type.
*/
const char * ll_hardware_type_string(ll_hardware_type_t t);
/**
* @brief
* Get the host interface version number
*
* @param[out] version
* pointer to a version struct
*
* @return
* 0 - success, negative otherwise
*/
int32_t ll_interface_version_get(ll_version_t *version);
/**
* @brief
* Get the module firmware version number
*
* @param[out] version
* pointer to a version struct
*
* @return
* 0 - success, negative otherwise
*/
int32_t ll_version_get(ll_version_t *version);
/**
* @brief
* Block any sleep mode.
*
* @details
* This function blocks any sleep mode. ll_sleep_unblock() allows the
* module to enter into the sleep mode again.
*
* @return
* 0 - success, negative otherwise
*/
int32_t ll_sleep_block(void);
/**
* @brief
* Unblock sleep modes
*
* @details
* This function unblocks sleep mode regardless of how many times
* ll_sleep_block() has been called.
*
* @return
* 0 - success, negative otherwise
*/
int32_t ll_sleep_unblock(void);
/**
* @brief
* Set the MAC Mode
*
* @param[in] mac_mode
* 0 = No MAC (Pass through mode)
* 1 = LoRaMAC (EU version)
* 2 = LoRaMAC (US version)
* 3 = Symphony Link
* 4 = Link Labs Ensemble
*
* @return
* 0 - success, negative otherwise
*/
int32_t ll_mac_mode_set(ll_mac_type_t mac_mode);
/**
* @brief
* Get the MAC Mode
*
* @param[out] mac_mode The current MAC operating mode.
*
* @return
* 0 - success, negative otherwise
*/
int32_t ll_mac_mode_get(ll_mac_type_t *mac_mode);
/**
* @brief
* Get the module unique identifier
*
* @param[out] unique_id
* pointer to a unsigned 64-bit integer
*
* @return
* 0 - success, negative otherwise
*/
int32_t ll_unique_id_get(uint64_t *unique_id);
/**
* @brief
* Get the antenna configuration
*
* @param[out] ant
* Antenna configuration.
*
* @return
* 0 - success, negative otherwise
*/
int32_t ll_antenna_get(uint8_t *ant);
/**
* @brief
* Set the antenna configuration
*
* @param[in] ant
* Antenna configuration. (1=>U.FL, 2=>trace)
*
* @return
* 0 - success, negative otherwise
*/
int32_t ll_antenna_set(uint8_t ant);
/**
* @brief
* Store the current radio parameters to flash:
* - mode
* - frequency
* - bandwidth
* - spreading factor
* - coding rate
* - low_rate_opt
* - tx power
*
* @details
* This function stores settings to flash.
*
* @return
* 0 - success, negative otherwise
*/
int32_t ll_settings_store(void);
/**
* @brief
* Delete all settings from flash storage.
*
* @details
* This function stores settings to flash.
*
* @return
* 0 - success, negative otherwise
*/
int32_t ll_settings_delete(void);
/**
* @brief
* Restore the default radio parameters:
* - frequency
* - bandwidth
* - spreading factor
* - coding rate
* - low_rate_opt
* - tx power
*
* @details
* This function stores settings to flash.
*
* @return
* 0 - success, negative otherwise
*/
int32_t ll_restore_defaults(void);
/**
* @brief
* Force the module to enter sleep.
*
* @details
* This function puts the module into the sleep mode. The wakeup
* signal is issued with a logic high pulse of at least 60 us duration.
* Alternatively, the module will enter the idle state in response to a received
* byte on the host UART.
*
* @return
* 0 - success, negative otherwise
*/
int32_t ll_sleep(void);
/**
* @brief
* Force the module to reset (takes a few seconds).
*
* @details
* This function forces the module to reset.
*
* @return
* 0 - success, negative otherwise
*/
int32_t ll_reset_mcu(void);
/**
* @brief
* Force the module to reset and enter bootloader mode (takes a few seconds).
*
* @details
* This function forces the module to reset and enter bootloader mode.
*
* @return
* 0 - success, negative otherwise
*/
int32_t ll_bootloader_mode(void);
/**
* @brief
* Read (and optionally clear) IRQ flags in module
*
* @details
* This function allows the external host to check whether an event has occurred in the
* module that has latched a bit in the "IRQ Flags" vector.
*
* @param[in] flags_to_clear
* A uint32_t bit vector containing flags that should be cleared if they are set. This can be
* 0 if the host interface just wants to read without clearing. If a bit is set, this function
* performs a clear-on-read of the irq_flags bits passed in.
*
* @param[out] flags
* A uint32_t bit vector - the value of the irq_flags in the module. Note that if the flags_to_clear
* argument is non-zero, this argument is the value of the flags before the clear operation.
*
* @return
* 0 - success, negative otherwise
*/
int32_t ll_irq_flags(uint32_t flags_to_clear, uint32_t *flags);
#if 0
/**
* @brief
* Set IRQ flags in module
*
* @details
*
* @param[in] none
*
* @param[out] flags mask
*
* @return
* 0 - success, negative otherwise
*/
int8_t ll_irq_flags_mask_get(uint32_t flags_to_clear, uint32_t *flags);
/**
* @brief
* Set IRQ flags in module
*
* @details
*
* @param[in] none
*
* @param[out] flags mask
*
* @return
* 0 - success, negative otherwise
*/
int8_t ll_irq_flags_mask_set(uint32_t flags_to_clear, uint32_t *flags);
#endif
/**
* @brief
* Reset the host-side state maintained by the interface.
*
* @details
* The host implementation maintains a very small amount of state
* including the current message identifier. This function resets
* this internal state and is intended to allow for controlled
* testing. This function is not normally used in production code.
*
* @return
* 0 - success, negative otherwise.
*/
int32_t ll_reset_state( void );
/** @} (end defgroup Module_Interface) */
/** @} (end defgroup Link_Labs_Interface_Library) */
#ifdef __cplusplus
}
#endif
#endif /* __LL_IFC_H */