Skip to content

Commit 43c00e5

Browse files
benothmn-stkartben
authored andcommitted
soc: stm32wbax: hci_if: Clean code
Clean the code, rename some constants and variables for more consistency. Signed-off-by: Nidhal BEN OTHMEN <[email protected]>
1 parent 42c3a78 commit 43c00e5

File tree

4 files changed

+64
-45
lines changed

4 files changed

+64
-45
lines changed

drivers/flash/flash_stm32wba_fm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ LOG_MODULE_REGISTER(flash_stm32wba, CONFIG_FLASH_LOG_LEVEL);
2424
#define STM32_FLASH_TIMEOUT \
2525
(2 * DT_PROP(DT_INST(0, st_stm32_nv_flash), max_erase_time))
2626

27-
extern struct k_work_q ble_ctlr_work_q;
27+
extern struct k_work_q ble_ctrl_work_q;
2828
struct k_work fm_work;
2929

3030
static const struct flash_parameters flash_stm32_parameters = {
@@ -47,7 +47,7 @@ struct FM_CallbackNode cb_ptr = {
4747

4848
void FM_ProcessRequest(void)
4949
{
50-
k_work_submit_to_queue(&ble_ctlr_work_q, &fm_work);
50+
k_work_submit_to_queue(&ble_ctrl_work_q, &fm_work);
5151
}
5252

5353
void FM_BackgroundProcess_Entry(struct k_work *work)

soc/st/stm32/stm32wbax/hci_if/host_stack_if.c

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,38 +7,35 @@
77
#include <zephyr/kernel.h>
88
#include <zephyr/init.h>
99

10-
#include "app_conf.h"
1110
#include "blestack.h"
1211
#include "bpka.h"
1312
#include "ll_intf.h"
1413

15-
K_MUTEX_DEFINE(ble_ctlr_stack_mutex);
16-
struct k_work_q ble_ctlr_work_q, ll_work_q;
17-
struct k_work ble_ctlr_stack_work, bpka_work;
14+
K_MUTEX_DEFINE(ble_ctrl_stack_mutex);
15+
struct k_work_q ble_ctrl_work_q, ll_work_q;
16+
struct k_work ble_ctrl_stack_work, bpka_work;
1817

1918
uint8_t ll_state_busy;
2019

21-
#define BLE_CTLR_TASK_STACK_SIZE (256 * 7)
22-
#define LL_TASK_STACK_SIZE (256 * 7)
23-
#define BLE_CTLR_TASK_PRIO (14)
24-
#define LL_TASK_PRIO (14)
20+
/* TODO: More tests to be done to optimize thread stacks' sizes */
21+
#define BLE_CTRL_THREAD_STACK_SIZE (256 * 7)
22+
#define LL_THREAD_STACK_SIZE (256 * 7)
23+
#define BLE_CTRL_THREAD_PRIO (14)
24+
#define LL_THREAD_PRIO (14)
2525

26-
K_THREAD_STACK_DEFINE(ble_ctlr_work_area, BLE_CTLR_TASK_STACK_SIZE);
27-
K_THREAD_STACK_DEFINE(ll_work_area, LL_TASK_STACK_SIZE);
26+
K_THREAD_STACK_DEFINE(ble_ctrl_work_area, BLE_CTRL_THREAD_STACK_SIZE);
27+
K_THREAD_STACK_DEFINE(ll_work_area, LL_THREAD_STACK_SIZE);
2828

29-
void HostStack_Process(void)
30-
{
31-
k_work_submit_to_queue(&ble_ctlr_work_q, &ble_ctlr_stack_work);
32-
}
29+
void HostStack_Process(void);
3330

34-
static void ble_ctlr_stack_handler(struct k_work *work)
31+
static void ble_ctrl_stack_handler(struct k_work *work)
3532
{
36-
uint8_t running = 0x0;
33+
uint8_t running = 0x00;
3734
change_state_options_t options;
3835

39-
k_mutex_lock(&ble_ctlr_stack_mutex, K_FOREVER);
36+
k_mutex_lock(&ble_ctrl_stack_mutex, K_FOREVER);
4037
running = BleStack_Process();
41-
k_mutex_unlock(&ble_ctlr_stack_mutex);
38+
k_mutex_unlock(&ble_ctrl_stack_mutex);
4239

4340
if (ll_state_busy == 1) {
4441
options.combined_value = 0x0F;
@@ -51,32 +48,37 @@ static void ble_ctlr_stack_handler(struct k_work *work)
5148
}
5249
}
5350

54-
void BPKACB_Process(void)
55-
{
56-
k_work_submit_to_queue(&ble_ctlr_work_q, &bpka_work);
57-
}
58-
5951
static void bpka_work_handler(struct k_work *work)
6052
{
6153
BPKA_BG_Process();
6254
}
6355

64-
static int stm32wba_ble_ctlr_init(void)
56+
static int stm32wba_ble_ctrl_init(void)
6557
{
66-
k_work_queue_init(&ble_ctlr_work_q);
67-
k_work_queue_start(&ble_ctlr_work_q, ble_ctlr_work_area,
68-
K_THREAD_STACK_SIZEOF(ble_ctlr_work_area),
69-
BLE_CTLR_TASK_PRIO, NULL);
58+
k_work_queue_init(&ble_ctrl_work_q);
59+
k_work_queue_start(&ble_ctrl_work_q, ble_ctrl_work_area,
60+
K_THREAD_STACK_SIZEOF(ble_ctrl_work_area),
61+
BLE_CTRL_THREAD_PRIO, NULL);
7062

7163
k_work_queue_init(&ll_work_q);
7264
k_work_queue_start(&ll_work_q, ll_work_area,
73-
K_THREAD_STACK_SIZEOF(ll_work_area),
74-
LL_TASK_PRIO, NULL);
65+
K_THREAD_STACK_SIZEOF(ll_work_area),
66+
LL_THREAD_PRIO, NULL);
7567

76-
k_work_init(&ble_ctlr_stack_work, &ble_ctlr_stack_handler);
68+
k_work_init(&ble_ctrl_stack_work, &ble_ctrl_stack_handler);
7769
k_work_init(&bpka_work, &bpka_work_handler);
7870

7971
return 0;
8072
}
8173

82-
SYS_INIT(stm32wba_ble_ctlr_init, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);
74+
void HostStack_Process(void)
75+
{
76+
k_work_submit_to_queue(&ble_ctrl_work_q, &ble_ctrl_stack_work);
77+
}
78+
79+
void BPKACB_Process(void)
80+
{
81+
k_work_submit_to_queue(&ble_ctrl_work_q, &bpka_work);
82+
}
83+
84+
SYS_INIT(stm32wba_ble_ctrl_init, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);

soc/st/stm32/stm32wbax/hci_if/linklayer_plat_adapt.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ void LINKLAYER_PLAT_TriggerSwLowIT(uint8_t priority)
119119
{
120120
uint8_t low_isr_priority = RADIO_INTR_PRIO_LOW_Z;
121121

122-
LOG_DBG("Priotity: %d", priority);
122+
LOG_DBG("Priority: %d", priority);
123123

124124
/* Check if a SW low interrupt as already been raised.
125125
* Nested call far radio low isr are not supported
@@ -238,10 +238,23 @@ void LINKLAYER_PLAT_RCOStopClbr(void)
238238
/* Required only for RCO module usage in the context of LSI2 calibration */
239239
}
240240

241+
/* TODO: To do when porting the temperature measurement function and thread */
241242
void LINKLAYER_PLAT_RequestTemperature(void) {}
242243

243244
void LINKLAYER_PLAT_SCHLDR_TIMING_UPDATE_NOT(Evnt_timing_t *p_evnt_timing) {}
244245

245-
void LINKLAYER_PLAT_EnableOSContextSwitch(void) {}
246+
void LINKLAYER_PLAT_EnableOSContextSwitch(void)
247+
{
248+
/* No implementation is needed. However, this function may be used to notify
249+
* upper layers that the link layer has just finished a critical radio job
250+
* (radio channels' calibration).
251+
**/
252+
}
246253

247-
void LINKLAYER_PLAT_DisableOSContextSwitch(void) {}
254+
void LINKLAYER_PLAT_DisableOSContextSwitch(void)
255+
{
256+
/* No implementation is needed. However, this function may be used to notify upper layers
257+
* that the link layer is running a critical radio job (radio channels' calibration);
258+
* A sequence of radio ISRs will appear in the next few milli seconds.
259+
**/
260+
}

soc/st/stm32/stm32wbax/hci_if/ll_sys_if_adapt.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,32 @@ LOG_MODULE_REGISTER(ll_sys_if_adapt);
1212

1313
#include "ll_sys.h"
1414

15-
extern struct k_mutex ble_ctlr_stack_mutex;
15+
extern struct k_mutex ble_ctrl_stack_mutex;
1616
extern struct k_work_q ll_work_q;
1717
struct k_work ll_sys_work;
1818

19-
void ll_sys_schedule_bg_process(void)
19+
static void ll_sys_bg_process_handler(struct k_work *work)
2020
{
21-
k_work_submit_to_queue(&ll_work_q, &ll_sys_work);
21+
k_mutex_lock(&ble_ctrl_stack_mutex, K_FOREVER);
22+
ll_sys_bg_process();
23+
k_mutex_unlock(&ble_ctrl_stack_mutex);
2224
}
2325

24-
void ll_sys_schedule_bg_process_isr(void)
26+
void ll_sys_schedule_bg_process(void)
2527
{
2628
k_work_submit_to_queue(&ll_work_q, &ll_sys_work);
2729
}
2830

29-
static void ll_sys_bg_process_handler(struct k_work *work)
31+
void ll_sys_schedule_bg_process_isr(void)
3032
{
31-
k_mutex_lock(&ble_ctlr_stack_mutex, K_FOREVER);
32-
ll_sys_bg_process();
33-
k_mutex_unlock(&ble_ctlr_stack_mutex);
33+
k_work_submit_to_queue(&ll_work_q, &ll_sys_work);
3434
}
3535

3636
void ll_sys_bg_process_init(void)
3737
{
3838
k_work_init(&ll_sys_work, &ll_sys_bg_process_handler);
3939
}
40+
41+
/* TODO: Implement temperature measurement thread after
42+
* implementing temperature measurement request function
43+
**/

0 commit comments

Comments
 (0)