aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32-wpan/src/wba/ll_sys_if.rs
diff options
context:
space:
mode:
Diffstat (limited to 'embassy-stm32-wpan/src/wba/ll_sys_if.rs')
-rw-r--r--embassy-stm32-wpan/src/wba/ll_sys_if.rs416
1 files changed, 416 insertions, 0 deletions
diff --git a/embassy-stm32-wpan/src/wba/ll_sys_if.rs b/embassy-stm32-wpan/src/wba/ll_sys_if.rs
new file mode 100644
index 000000000..7218b69c4
--- /dev/null
+++ b/embassy-stm32-wpan/src/wba/ll_sys_if.rs
@@ -0,0 +1,416 @@
1#![cfg(feature = "wba")]
2// /* USER CODE BEGIN Header */
3// /**
4// ******************************************************************************
5// * @file ll_sys_if.c
6// * @author MCD Application Team
7// * @brief Source file for initiating system
8// ******************************************************************************
9// * @attention
10// *
11// * Copyright (c) 2022 STMicroelectronics.
12// * All rights reserved.
13// *
14// * This software is licensed under terms that can be found in the LICENSE file
15// * in the root directory of this software component.
16// * If no LICENSE file comes with this software, it is provided AS-IS.
17// *
18// ******************************************************************************
19// */
20// /* USER CODE END Header */
21//
22// #include "main.h"
23// #include "app_common.h"
24// #include "app_conf.h"
25// #include "log_module.h"
26// #include "ll_intf_cmn.h"
27// #include "ll_sys.h"
28// #include "ll_sys_if.h"
29// #include "stm32_rtos.h"
30// #include "utilities_common.h"
31// #if (USE_TEMPERATURE_BASED_RADIO_CALIBRATION == 1)
32// #include "temp_measurement.h"
33// #endif /* (USE_TEMPERATURE_BASED_RADIO_CALIBRATION == 1) */
34// #if (CFG_LPM_STANDBY_SUPPORTED == 0)
35// extern void profile_reset(void);
36// #endif
37// /* Private defines -----------------------------------------------------------*/
38// /* Radio event scheduling method - must be set at 1 */
39// #define USE_RADIO_LOW_ISR (1)
40// #define NEXT_EVENT_SCHEDULING_FROM_ISR (1)
41//
42// /* USER CODE BEGIN PD */
43//
44// /* USER CODE END PD */
45//
46// /* Private macros ------------------------------------------------------------*/
47// /* USER CODE BEGIN PM */
48//
49// /* USER CODE END PM */
50//
51// /* Private constants ---------------------------------------------------------*/
52// /* USER CODE BEGIN PC */
53//
54// /* USER CODE END PC */
55//
56// /* Private variables ---------------------------------------------------------*/
57// /* USER CODE BEGIN PV */
58//
59// /* USER CODE END PV */
60//
61// /* Global variables ----------------------------------------------------------*/
62//
63// /* USER CODE BEGIN GV */
64//
65// /* USER CODE END GV */
66//
67// /* Private functions prototypes-----------------------------------------------*/
68// #if (USE_TEMPERATURE_BASED_RADIO_CALIBRATION == 1)
69// static void ll_sys_bg_temperature_measurement_init(void);
70// #endif /* USE_TEMPERATURE_BASED_RADIO_CALIBRATION */
71// static void ll_sys_sleep_clock_source_selection(void);
72// static uint8_t ll_sys_BLE_sleep_clock_accuracy_selection(void);
73// void ll_sys_reset(void);
74//
75// /* USER CODE BEGIN PFP */
76//
77// /* USER CODE END PFP */
78//
79// /* External variables --------------------------------------------------------*/
80//
81// /* USER CODE BEGIN EV */
82//
83// /* USER CODE END EV */
84//
85// /* Functions Definition ------------------------------------------------------*/
86//
87// /**
88// * @brief Link Layer background process initialization
89// * @param None
90// * @retval None
91// */
92// void ll_sys_bg_process_init(void)
93// {
94// /* Register Link Layer task */
95// UTIL_SEQ_RegTask(1U << CFG_TASK_LINK_LAYER, UTIL_SEQ_RFU, ll_sys_bg_process);
96// }
97//
98// /**
99// * @brief Link Layer background process next iteration scheduling
100// * @param None
101// * @retval None
102// */
103// void ll_sys_schedule_bg_process(void)
104// {
105// UTIL_SEQ_SetTask(1U << CFG_TASK_LINK_LAYER, TASK_PRIO_LINK_LAYER);
106// }
107//
108// /**
109// * @brief Link Layer background process next iteration scheduling from ISR
110// * @param None
111// * @retval None
112// */
113// void ll_sys_schedule_bg_process_isr(void)
114// {
115// UTIL_SEQ_SetTask(1U << CFG_TASK_LINK_LAYER, TASK_PRIO_LINK_LAYER);
116// }
117//
118// /**
119// * @brief Link Layer configuration phase before application startup.
120// * @param None
121// * @retval None
122// */
123// void ll_sys_config_params(void)
124// {
125// /* USER CODE BEGIN ll_sys_config_params_0 */
126//
127// /* USER CODE END ll_sys_config_params_0 */
128//
129// /* Configure link layer behavior for low ISR use and next event scheduling method:
130// * - SW low ISR is used.
131// * - Next event is scheduled from ISR.
132// */
133// ll_intf_cmn_config_ll_ctx_params(USE_RADIO_LOW_ISR, NEXT_EVENT_SCHEDULING_FROM_ISR);
134// /* Apply the selected link layer sleep timer source */
135// ll_sys_sleep_clock_source_selection();
136//
137// /* USER CODE BEGIN ll_sys_config_params_1 */
138//
139// /* USER CODE END ll_sys_config_params_1 */
140//
141// #if (USE_TEMPERATURE_BASED_RADIO_CALIBRATION == 1)
142// /* Initialize link layer temperature measurement background task */
143// ll_sys_bg_temperature_measurement_init();
144//
145// /* Link layer IP uses temperature based calibration instead of periodic one */
146// ll_intf_cmn_set_temperature_sensor_state();
147// #endif /* USE_TEMPERATURE_BASED_RADIO_CALIBRATION */
148//
149// /* Link Layer power table */
150// ll_intf_cmn_select_tx_power_table(CFG_RF_TX_POWER_TABLE_ID);
151//
152// #if (USE_CTE_DEGRADATION == 1u)
153// /* Apply CTE degradation */
154// ll_sys_apply_cte_settings ();
155// #endif /* (USE_CTE_DEGRADATION == 1u) */
156//
157// /* USER CODE BEGIN ll_sys_config_params_2 */
158//
159// /* USER CODE END ll_sys_config_params_2 */
160// }
161//
162// #if (USE_TEMPERATURE_BASED_RADIO_CALIBRATION == 1)
163//
164// /**
165// * @brief Link Layer temperature request background process initialization
166// * @param None
167// * @retval None
168// */
169// void ll_sys_bg_temperature_measurement_init(void)
170// {
171// /* Register Temperature Measurement task */
172// UTIL_SEQ_RegTask(1U << CFG_TASK_TEMP_MEAS, UTIL_SEQ_RFU, TEMPMEAS_RequestTemperatureMeasurement);
173// }
174//
175// /**
176// * @brief Request backroud task processing for temperature measurement
177// * @param None
178// * @retval None
179// */
180// void ll_sys_bg_temperature_measurement(void)
181// {
182// static uint8_t initial_temperature_acquisition = 0;
183//
184// if(initial_temperature_acquisition == 0)
185// {
186// TEMPMEAS_RequestTemperatureMeasurement();
187// initial_temperature_acquisition = 1;
188// }
189// else
190// {
191// UTIL_SEQ_SetTask(1U << CFG_TASK_TEMP_MEAS, CFG_SEQ_PRIO_0);
192// }
193// }
194//
195// #endif /* USE_TEMPERATURE_BASED_RADIO_CALIBRATION */
196//
197// uint8_t ll_sys_BLE_sleep_clock_accuracy_selection(void)
198// {
199// uint8_t BLE_sleep_clock_accuracy = 0;
200// #if (CFG_RADIO_LSE_SLEEP_TIMER_CUSTOM_SCA_RANGE == 0)
201// uint32_t RevID = LL_DBGMCU_GetRevisionID();
202// #endif
203// uint32_t linklayer_slp_clk_src = LL_RCC_RADIO_GetSleepTimerClockSource();
204//
205// if(linklayer_slp_clk_src == LL_RCC_RADIOSLEEPSOURCE_LSE)
206// {
207// /* LSE selected as Link Layer sleep clock source.
208// Sleep clock accuracy is different regarding the WBA device ID and revision
209// */
210// #if (CFG_RADIO_LSE_SLEEP_TIMER_CUSTOM_SCA_RANGE == 0)
211// #if defined(STM32WBA52xx) || defined(STM32WBA54xx) || defined(STM32WBA55xx)
212// if(RevID == REV_ID_A)
213// {
214// BLE_sleep_clock_accuracy = STM32WBA5x_REV_ID_A_SCA_RANGE;
215// }
216// else if(RevID == REV_ID_B)
217// {
218// BLE_sleep_clock_accuracy = STM32WBA5x_REV_ID_B_SCA_RANGE;
219// }
220// else
221// {
222// /* Revision ID not supported, default value of 500ppm applied */
223// BLE_sleep_clock_accuracy = STM32WBA5x_DEFAULT_SCA_RANGE;
224// }
225// #elif defined(STM32WBA65xx)
226// BLE_sleep_clock_accuracy = STM32WBA6x_SCA_RANGE;
227// UNUSED(RevID);
228// #else
229// UNUSED(RevID);
230// #endif /* defined(STM32WBA52xx) || defined(STM32WBA54xx) || defined(STM32WBA55xx) */
231// #else /* CFG_RADIO_LSE_SLEEP_TIMER_CUSTOM_SCA_RANGE */
232// BLE_sleep_clock_accuracy = CFG_RADIO_LSE_SLEEP_TIMER_CUSTOM_SCA_RANGE;
233// #endif /* CFG_RADIO_LSE_SLEEP_TIMER_CUSTOM_SCA_RANGE */
234// }
235// else
236// {
237// /* LSE is not the Link Layer sleep clock source, sleep clock accurcay default value is 500 ppm */
238// BLE_sleep_clock_accuracy = STM32WBA5x_DEFAULT_SCA_RANGE;
239// }
240//
241// return BLE_sleep_clock_accuracy;
242// }
243//
244// void ll_sys_sleep_clock_source_selection(void)
245// {
246// uint16_t freq_value = 0;
247// uint32_t linklayer_slp_clk_src = LL_RCC_RADIOSLEEPSOURCE_NONE;
248//
249// linklayer_slp_clk_src = LL_RCC_RADIO_GetSleepTimerClockSource();
250// switch(linklayer_slp_clk_src)
251// {
252// case LL_RCC_RADIOSLEEPSOURCE_LSE:
253// linklayer_slp_clk_src = RTC_SLPTMR;
254// break;
255//
256// case LL_RCC_RADIOSLEEPSOURCE_LSI:
257// linklayer_slp_clk_src = RCO_SLPTMR;
258// break;
259//
260// case LL_RCC_RADIOSLEEPSOURCE_HSE_DIV1000:
261// linklayer_slp_clk_src = CRYSTAL_OSCILLATOR_SLPTMR;
262// break;
263//
264// case LL_RCC_RADIOSLEEPSOURCE_NONE:
265// /* No Link Layer sleep clock source selected */
266// assert_param(0);
267// break;
268// }
269// ll_intf_cmn_le_select_slp_clk_src((uint8_t)linklayer_slp_clk_src, &freq_value);
270// }
271//
272// void ll_sys_reset(void)
273// {
274// uint8_t bsca = 0;
275// /* Link layer timings */
276// uint8_t drift_time = DRIFT_TIME_DEFAULT;
277// uint8_t exec_time = EXEC_TIME_DEFAULT;
278//
279// /* USER CODE BEGIN ll_sys_reset_0 */
280//
281// /* USER CODE END ll_sys_reset_0 */
282//
283// /* Apply the selected link layer sleep timer source */
284// ll_sys_sleep_clock_source_selection();
285//
286// /* Configure the link layer sleep clock accuracy */
287// bsca = ll_sys_BLE_sleep_clock_accuracy_selection();
288// ll_intf_le_set_sleep_clock_accuracy(bsca);
289//
290// /* Update link layer timings depending on selected configuration */
291// if(LL_RCC_RADIO_GetSleepTimerClockSource() == LL_RCC_RADIOSLEEPSOURCE_LSI)
292// {
293// drift_time += DRIFT_TIME_EXTRA_LSI2;
294// exec_time += EXEC_TIME_EXTRA_LSI2;
295// }
296// else
297// {
298// #if defined(__GNUC__) && defined(DEBUG)
299// drift_time += DRIFT_TIME_EXTRA_GCC_DEBUG;
300// exec_time += EXEC_TIME_EXTRA_GCC_DEBUG;
301// #endif
302// }
303//
304// /* USER CODE BEGIN ll_sys_reset_1 */
305//
306// /* USER CODE END ll_sys_reset_1 */
307//
308// if((drift_time != DRIFT_TIME_DEFAULT) || (exec_time != EXEC_TIME_DEFAULT))
309// {
310// ll_sys_config_BLE_schldr_timings(drift_time, exec_time);
311// }
312// /* USER CODE BEGIN ll_sys_reset_2 */
313//
314// /* USER CODE END ll_sys_reset_2 */
315// }
316// #if defined(STM32WBA52xx) || defined(STM32WBA54xx) || defined(STM32WBA55xx) || defined(STM32WBA65xx)
317// void ll_sys_apply_cte_settings(void)
318// {
319// ll_intf_apply_cte_degrad_change();
320// }
321// #endif /* defined(STM32WBA52xx) || defined(STM32WBA54xx) || defined(STM32WBA55xx) || defined(STM32WBA65xx) */
322//
323// #if (CFG_LPM_STANDBY_SUPPORTED == 0)
324// void ll_sys_get_ble_profile_statistics(uint32_t* exec_time, uint32_t* drift_time, uint32_t* average_drift_time, uint8_t reset)
325// {
326// if (reset != 0U)
327// {
328// profile_reset();
329// }
330// ll_intf_get_profile_statistics(exec_time, drift_time, average_drift_time);
331// }
332// #endif
333//
334use super::bindings::{link_layer, mac};
335use super::util_seq;
336
337const UTIL_SEQ_RFU: u32 = 0;
338const TASK_LINK_LAYER_MASK: u32 = 1 << mac::CFG_TASK_ID_T_CFG_TASK_LINK_LAYER;
339const TASK_PRIO_LINK_LAYER: u32 = mac::CFG_SEQ_PRIO_ID_T_CFG_SEQ_PRIO_0 as u32;
340
341/**
342 * @brief Link Layer background process initialization
343 * @param None
344 * @retval None
345 */
346#[unsafe(no_mangle)]
347pub unsafe extern "C" fn ll_sys_bg_process_init() {
348 util_seq::UTIL_SEQ_RegTask(TASK_LINK_LAYER_MASK, UTIL_SEQ_RFU, Some(link_layer::ll_sys_bg_process));
349}
350
351/**
352 * @brief Link Layer background process next iteration scheduling
353 * @param None
354 * @retval None
355 */
356#[unsafe(no_mangle)]
357pub unsafe extern "C" fn ll_sys_schedule_bg_process() {
358 util_seq::UTIL_SEQ_SetTask(TASK_LINK_LAYER_MASK, TASK_PRIO_LINK_LAYER);
359}
360
361/**
362 * @brief Link Layer background process next iteration scheduling from ISR
363 * @param None
364 * @retval None
365 */
366#[unsafe(no_mangle)]
367pub unsafe extern "C" fn ll_sys_schedule_bg_process_isr() {
368 util_seq::UTIL_SEQ_SetTask(TASK_LINK_LAYER_MASK, TASK_PRIO_LINK_LAYER);
369}
370
371/**
372 * @brief Link Layer configuration phase before application startup.
373 * @param None
374 * @retval None
375 */
376#[unsafe(no_mangle)]
377pub unsafe extern "C" fn ll_sys_config_params() {
378 let allow_low_isr = mac::USE_RADIO_LOW_ISR as u8;
379 let run_from_isr = mac::NEXT_EVENT_SCHEDULING_FROM_ISR as u8;
380 let _ = link_layer::ll_intf_cmn_config_ll_ctx_params(allow_low_isr, run_from_isr);
381
382 ll_sys_sleep_clock_source_selection();
383 let _ = link_layer::ll_intf_cmn_select_tx_power_table(mac::CFG_RF_TX_POWER_TABLE_ID as u8);
384}
385
386/**
387 * @brief Reset Link Layer timing parameters to their default configuration.
388 * @param None
389 * @retval None
390 */
391#[unsafe(no_mangle)]
392pub unsafe extern "C" fn ll_sys_reset() {
393 ll_sys_sleep_clock_source_selection();
394
395 let sleep_accuracy = ll_sys_BLE_sleep_clock_accuracy_selection();
396 let _ = link_layer::ll_intf_le_set_sleep_clock_accuracy(sleep_accuracy);
397}
398
399/// Select the sleep-clock source used by the Link Layer.
400/// Defaults to the crystal oscillator when no explicit configuration is available.
401#[unsafe(no_mangle)]
402pub unsafe extern "C" fn ll_sys_sleep_clock_source_selection() {
403 let mut frequency: u16 = 0;
404 let _ = link_layer::ll_intf_cmn_le_select_slp_clk_src(
405 link_layer::_SLPTMR_SRC_TYPE_E_CRYSTAL_OSCILLATOR_SLPTMR as u8,
406 &mut frequency as *mut u16,
407 );
408}
409
410/// Determine the BLE sleep-clock accuracy used by the stack.
411/// Returns zero when board-specific calibration data is unavailable.
412#[unsafe(no_mangle)]
413pub unsafe extern "C" fn ll_sys_BLE_sleep_clock_accuracy_selection() -> u8 {
414 // TODO: derive the board-specific sleep clock accuracy once calibration data is available.
415 0
416}