-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathral_sx128x_bsp.c
More file actions
332 lines (302 loc) · 11.6 KB
/
ral_sx128x_bsp.c
File metadata and controls
332 lines (302 loc) · 11.6 KB
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
/**
* @file ral_sx128x_bsp.c
*
* @brief Board Support Package for the SX128x-specific Radio Abstraction Layer.
*
* The Clear BSD License
* Copyright Semtech Corporation 2021. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted (subject to the limitations in the disclaimer
* below) provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the Semtech corporation nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY
* THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* -----------------------------------------------------------------------------
* --- DEPENDENCIES ------------------------------------------------------------
*/
#include <stdint.h>
#include "smtc_modem_hal.h"
#include "ral_sx128x_bsp.h"
#include "radio_utilities.h"
/*
* -----------------------------------------------------------------------------
* --- PRIVATE MACROS-----------------------------------------------------------
*/
#define SX128X_CONVERT_TABLE_INDEX_OFFSET 18
#define SX128X_LORA_RX_CONSUMPTION_BW_200_DCDC 5500
#define SX128X_LORA_RX_BOOSTED_CONSUMPTION_BW_200_DCDC 6200
#define SX128X_LORA_RX_CONSUMPTION_BW_400_DCDC 6000
#define SX128X_LORA_RX_BOOSTED_CONSUMPTION_BW_400_DCDC 6700
#define SX128X_LORA_RX_CONSUMPTION_BW_800_DCDC 7000
#define SX128X_LORA_RX_BOOSTED_CONSUMPTION_BW_800_DCDC 7700
#define SX128X_LORA_RX_CONSUMPTION_BW_1600_DCDC 7500
#define SX128X_LORA_RX_BOOSTED_CONSUMPTION_BW_1600_DCDC 8200
#define SX128X_LORA_RX_CONSUMPTION_BW_200_LDO 10800
#define SX128X_LORA_RX_BOOSTED_CONSUMPTION_BW_200_LDO 12200
#define SX128X_LORA_RX_CONSUMPTION_BW_400_LDO 11800
#define SX128X_LORA_RX_BOOSTED_CONSUMPTION_BW_400_LDO 13200
#define SX128X_LORA_RX_CONSUMPTION_BW_800_LDO 13700
#define SX128X_LORA_RX_BOOSTED_CONSUMPTION_BW_800_LDO 15200
#define SX128X_LORA_RX_CONSUMPTION_BW_1600_LDO 14800
#define SX128X_LORA_RX_BOOSTED_CONSUMPTION_BW_1600_LDO 16300
/*
* -----------------------------------------------------------------------------
* --- PRIVATE CONSTANTS -------------------------------------------------------
*/
static const uint32_t ral_sx128x_convert_tx_dbm_to_ua_reg_mode_dcdc[] = {
6200, // -18 dBm
6300, // -17 dBm
6400, // -16 dBm
6500, // -15 dBm
6600, // -14 dBm
6700, // -13 dBm
6800, // -12 dBm
7000, // -11 dBm
7100, // -10 dBm
7300, // -9 dBm
7400, // -8 dBm
7700, // -7 dBm
7900, // -6 dBm
8100, // -5 dBm
8500, // -4 dBm
8800, // -3 dBm
9200, // -2 dBm
9700, // -1 dBm
10100, // 0 dBm
10700, // 1 dBm
11300, // 2 dBm
12000, // 3 dBm
12700, // 4 dBm
13600, // 5 dBm
14500, // 6 dBm
15500, // 7 dBm
16800, // 8 dBm
17700, // 9 dBm
18600, // 10 dBm
20300, // 11 dBm
22000, // 12 dBm
24000, // 13 dBm
};
static const uint32_t ral_sx128x_convert_tx_dbm_to_ua_reg_mode_ldo[] = {
11800, // -18 dBm
12000, // -17 dBm
12200, // -16 dBm
12400, // -15 dBm
12600, // -14 dBm
12800, // -13 dBm
13000, // -12 dBm
13300, // -11 dBm
13500, // -10 dBm
14000, // -9 dBm
14200, // -8 dBm
14700, // -7 dBm
15200, // -6 dBm
15600, // -5 dBm
16300, // -4 dBm
17000, // -3 dBm
17700, // -2 dBm
18600, // -1 dBm
19600, // 0 dBm
20700, // 1 dBm
21900, // 2 dBm
23200, // 3 dBm
24600, // 4 dBm
26300, // 5 dBm
28000, // 6 dBm
30000, // 7 dBm
32200, // 8 dBm
34500, // 9 dBm
36800, // 10 dBm
39200, // 11 dBm
41900, // 12 dBm
45500, // 13 dBm
};
/*
* -----------------------------------------------------------------------------
* --- PRIVATE TYPES -----------------------------------------------------------
*/
/*
* -----------------------------------------------------------------------------
* --- PRIVATE VARIABLES -------------------------------------------------------
*/
/*
* -----------------------------------------------------------------------------
* --- PRIVATE FUNCTIONS DECLARATION -------------------------------------------
*/
/*
* -----------------------------------------------------------------------------
* --- PUBLIC FUNCTIONS DEFINITION ---------------------------------------------
*/
void ral_sx128x_bsp_get_reg_mode( const void* context, sx128x_reg_mod_t* reg_mode )
{
*reg_mode = SX128X_REG_MODE_DCDC;
}
void ral_sx128x_bsp_get_tx_cfg( const void* context, const ral_sx128x_bsp_tx_cfg_input_params_t* input_params,
ral_sx128x_bsp_tx_cfg_output_params_t* output_params )
{
// get board tx power offset
int8_t board_tx_pwr_offset_db = radio_utilities_get_tx_power_offset( );
int16_t power = input_params->system_output_pwr_in_dbm + board_tx_pwr_offset_db;
if( power > 13 )
{
output_params->chip_output_pwr_in_dbm_configured = 13;
output_params->chip_output_pwr_in_dbm_expected = 13;
}
else if( power < -18 )
{
output_params->chip_output_pwr_in_dbm_configured = -18;
output_params->chip_output_pwr_in_dbm_expected = -18;
}
else
{
output_params->chip_output_pwr_in_dbm_configured = ( int8_t ) power;
output_params->chip_output_pwr_in_dbm_expected = ( int8_t ) power;
}
output_params->pa_ramp_time = SX128X_RAMP_20_US;
}
void ral_sx128x_bsp_get_lora_cad_det_peak( const void *context, ral_lora_sf_t sf, ral_lora_bw_t bw,
ral_lora_cad_symbs_t nb_symbol, uint8_t* in_out_cad_det_peak )
{
// Function used to fine tune the cad detection peak, update if needed
}
ral_status_t ral_sx128x_bsp_get_instantaneous_tx_power_consumption( const void *context,
ral_sx128x_bsp_tx_cfg_output_params_t tx_cfg_output_params_local, sx128x_reg_mod_t reg_mode,
uint32_t* pwr_consumption_in_ua )
{
const ral_sx128x_bsp_tx_cfg_output_params_t tx_cfg_output_params = tx_cfg_output_params_local;
uint8_t index = 0;
if( tx_cfg_output_params.chip_output_pwr_in_dbm_expected > SX128X_PWR_MAX )
{
index = SX128X_PWR_MAX + SX128X_CONVERT_TABLE_INDEX_OFFSET;
}
else if( tx_cfg_output_params.chip_output_pwr_in_dbm_expected < SX128X_PWR_MIN )
{
index = SX128X_PWR_MIN + SX128X_CONVERT_TABLE_INDEX_OFFSET;
}
else
{
index = tx_cfg_output_params.chip_output_pwr_in_dbm_expected + SX128X_CONVERT_TABLE_INDEX_OFFSET;
}
if( reg_mode == SX128X_REG_MODE_DCDC )
{
*pwr_consumption_in_ua = ral_sx128x_convert_tx_dbm_to_ua_reg_mode_dcdc[index];
}
else if( reg_mode == SX128X_REG_MODE_LDO )
{
*pwr_consumption_in_ua = ral_sx128x_convert_tx_dbm_to_ua_reg_mode_ldo[index];
}
else
{
return RAL_STATUS_UNKNOWN_VALUE;
}
return RAL_STATUS_OK;
}
ral_status_t ral_sx128x_bsp_get_instantaneous_gfsk_rx_power_consumption( const void *context,
sx128x_reg_mod_t radio_reg_mode,
bool rx_boosted,
uint32_t* pwr_consumption_in_ua )
{
return RAL_STATUS_UNSUPPORTED_FEATURE;
}
ral_status_t ral_sx128x_bsp_get_instantaneous_lora_rx_power_consumption( const void *context,
sx128x_reg_mod_t reg_mode, ral_lora_bw_t bw,
bool rx_boosted,
uint32_t* pwr_consumption_in_ua )
{
switch( reg_mode )
{
case SX128X_REG_MODE_DCDC:
{
switch( bw )
{
case RAL_LORA_BW_200_KHZ:
{
*pwr_consumption_in_ua = ( rx_boosted ) ? SX128X_LORA_RX_BOOSTED_CONSUMPTION_BW_200_DCDC
: SX128X_LORA_RX_CONSUMPTION_BW_200_DCDC;
return RAL_STATUS_OK;
}
case RAL_LORA_BW_400_KHZ:
{
*pwr_consumption_in_ua = ( rx_boosted ) ? SX128X_LORA_RX_BOOSTED_CONSUMPTION_BW_400_DCDC
: SX128X_LORA_RX_CONSUMPTION_BW_400_DCDC;
return RAL_STATUS_OK;
}
case RAL_LORA_BW_800_KHZ:
{
*pwr_consumption_in_ua = ( rx_boosted ) ? SX128X_LORA_RX_BOOSTED_CONSUMPTION_BW_800_DCDC
: SX128X_LORA_RX_CONSUMPTION_BW_800_DCDC;
return RAL_STATUS_OK;
}
case RAL_LORA_BW_1600_KHZ:
{
*pwr_consumption_in_ua = ( rx_boosted ) ? SX128X_LORA_RX_BOOSTED_CONSUMPTION_BW_1600_DCDC
: SX128X_LORA_RX_CONSUMPTION_BW_1600_DCDC;
return RAL_STATUS_OK;
}
default:
return RAL_STATUS_UNKNOWN_VALUE;
}
break;
}
case SX128X_REG_MODE_LDO:
{
switch( bw )
{
case RAL_LORA_BW_200_KHZ:
{
*pwr_consumption_in_ua =
( rx_boosted ) ? SX128X_LORA_RX_BOOSTED_CONSUMPTION_BW_200_LDO : SX128X_LORA_RX_CONSUMPTION_BW_200_LDO;
return RAL_STATUS_OK;
}
case RAL_LORA_BW_400_KHZ:
{
*pwr_consumption_in_ua =
( rx_boosted ) ? SX128X_LORA_RX_BOOSTED_CONSUMPTION_BW_400_LDO : SX128X_LORA_RX_CONSUMPTION_BW_400_LDO;
return RAL_STATUS_OK;
}
case RAL_LORA_BW_800_KHZ:
{
*pwr_consumption_in_ua =
( rx_boosted ) ? SX128X_LORA_RX_BOOSTED_CONSUMPTION_BW_800_LDO : SX128X_LORA_RX_CONSUMPTION_BW_800_LDO;
return RAL_STATUS_OK;
}
case RAL_LORA_BW_1600_KHZ:
{
*pwr_consumption_in_ua = ( rx_boosted ) ? SX128X_LORA_RX_BOOSTED_CONSUMPTION_BW_1600_LDO
: SX128X_LORA_RX_CONSUMPTION_BW_1600_LDO;
return RAL_STATUS_OK;
}
default:
{
return RAL_STATUS_UNKNOWN_VALUE;
}
}
break;
}
default:
{
return RAL_STATUS_UNKNOWN_VALUE;
}
}
}