11
11
LOG_MODULE_REGISTER (ll_sys_if_adapt );
12
12
13
13
#include "ll_sys.h"
14
+ #include "ll_intf_cmn.h"
15
+ #if defined(CONFIG_BT_STM32WBA_USE_TEMP_BASED_CALIB )
16
+ #include <zephyr/drivers/sensor.h>
17
+ #endif /* defined(CONFIG_BT_STM32WBA_USE_TEMP_BASED_CALIB) */
14
18
15
19
extern struct k_mutex ble_ctrl_stack_mutex ;
16
20
extern struct k_work_q ll_work_q ;
17
21
struct k_work ll_sys_work ;
18
22
23
+ #if defined(CONFIG_BT_STM32WBA_USE_TEMP_BASED_CALIB )
24
+ static const struct device * dev_temp_sensor = DEVICE_DT_GET (DT_ALIAS (die_temp0 ));
25
+ static struct k_work temp_calibration_work ;
26
+ #endif /* defined(CONFIG_BT_STM32WBA_USE_TEMP_BASED_CALIB) */
27
+
19
28
static void ll_sys_bg_process_handler (struct k_work * work )
20
29
{
21
30
k_mutex_lock (& ble_ctrl_stack_mutex , K_FOREVER );
@@ -38,6 +47,76 @@ void ll_sys_bg_process_init(void)
38
47
k_work_init (& ll_sys_work , & ll_sys_bg_process_handler );
39
48
}
40
49
41
- /* TODO: Implement temperature measurement thread after
42
- * implementing temperature measurement request function
43
- **/
50
+ #if defined(CONFIG_BT_STM32WBA_USE_TEMP_BASED_CALIB )
51
+
52
+ /**
53
+ * @brief Link Layer temperature calibration function
54
+ * @param None
55
+ * @retval None
56
+ */
57
+ static void ll_sys_temperature_calibration_measurement (void )
58
+ {
59
+ struct sensor_value val ;
60
+
61
+ int rc = sensor_sample_fetch (dev_temp_sensor );
62
+
63
+ if (rc ) {
64
+ LOG_ERR ("Failed to fetch sample (%d)" , rc );
65
+ return ;
66
+ }
67
+
68
+ rc = sensor_channel_get (dev_temp_sensor , SENSOR_CHAN_DIE_TEMP , & val );
69
+ if (rc ) {
70
+ LOG_ERR ("Failed to get data (%d)" , rc );
71
+ return ;
72
+ }
73
+
74
+ LOG_DBG ("Radio calibration, temperature : %u °C" , val .val1 );
75
+ ll_intf_cmn_set_temperature_value (val .val1 );
76
+ }
77
+
78
+ /**
79
+ * @brief Link Layer temperature calibration work handler task
80
+ * @param work
81
+ * @retval None
82
+ */
83
+ void ll_sys_temperature_calibration_measurement_work_handler (struct k_work * work )
84
+ {
85
+ ll_sys_temperature_calibration_measurement ();
86
+ }
87
+
88
+ /**
89
+ * @brief Link Layer temperature request background process initialization
90
+ * @param None
91
+ * @retval None
92
+ */
93
+ void ll_sys_bg_temperature_measurement_init (void )
94
+ {
95
+ if (!device_is_ready (dev_temp_sensor )) {
96
+ LOG_ERR ("dev_temp_sensor: device %s not ready" , dev_temp_sensor -> name );
97
+ k_panic ();
98
+ } else {
99
+ /* Register Temperature Measurement task */
100
+ k_work_init (& temp_calibration_work ,
101
+ ll_sys_temperature_calibration_measurement_work_handler );
102
+ }
103
+ }
104
+
105
+ /**
106
+ * @brief Request background task processing for temperature measurement
107
+ * @param None
108
+ * @retval None
109
+ */
110
+ void ll_sys_bg_temperature_measurement (void )
111
+ {
112
+ static uint8_t initial_temperature_acquisition ;
113
+
114
+ if (initial_temperature_acquisition == 0 ) {
115
+ ll_sys_temperature_calibration_measurement ();
116
+ initial_temperature_acquisition = 1 ;
117
+ } else {
118
+ k_work_submit_to_queue (& ll_work_q , & temp_calibration_work );
119
+ }
120
+ }
121
+
122
+ #endif /* defined(CONFIG_BT_STM32WBA_USE_TEMP_BASED_CALIB) */
0 commit comments