Skip to content

Commit b3df7e5

Browse files
committed
extmod/zephyr_ble: Remove dead code from HAL shim files.
Cleanup unused functions, macros and debug helpers that were never called or only conditionally compiled behind disabled feature flags. Removes dead registry system, PSA crypto stubs, LIFO operations, and various unused helper functions and inlines from kernel/device/config headers. Also deletes gatt_pragma.h which is unreferenced. Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
1 parent 673bd99 commit b3df7e5

18 files changed

Lines changed: 8 additions & 400 deletions

extmod/zephyr_ble/gatt_pragma.h

Lines changed: 0 additions & 4 deletions
This file was deleted.

extmod/zephyr_ble/hal/zephyr_ble_fifo.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,6 @@ static inline sys_snode_t *item_to_snode(void *item) {
5454

5555
// --- k_queue API Implementation (underlying FIFO implementation) ---
5656

57-
// Enable debug output (called after boot to avoid interfering with initialization)
58-
void mp_bluetooth_zephyr_fifo_enable_debug(void) {
59-
debug_enabled = 1;
60-
mp_printf(&mp_plat_print, "[FIFO] Debug output enabled\n");
61-
}
62-
63-
void k_queue_init(struct k_queue *queue) {
64-
DEBUG_FIFO("k_queue_init(%p)", queue);
65-
queue->data_q.head = NULL;
66-
queue->data_q.tail = NULL;
67-
queue->lock.unused = 0; // Initialize spinlock for completeness
68-
}
6957

7058
void k_queue_append(struct k_queue *queue, void *data) {
7159
sys_snode_t *node = item_to_snode(data);

extmod/zephyr_ble/hal/zephyr_ble_kernel.h

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -46,36 +46,9 @@ static inline void k_yield(void) {
4646
// No-op in MicroPython scheduler
4747
}
4848

49-
// Busy wait for short delays (microseconds)
50-
static inline void k_busy_wait(uint32_t usec_to_wait) {
51-
mp_hal_delay_us(usec_to_wait);
52-
}
5349

5450
// --- Uptime and Timing ---
5551

56-
// Get system uptime in milliseconds
57-
static inline int64_t k_uptime_get(void) {
58-
return (int64_t)mp_hal_ticks_ms();
59-
}
60-
61-
// Get system uptime in 32-bit milliseconds (wraps at ~49 days)
62-
static inline uint32_t k_uptime_get_32(void) {
63-
return mp_hal_ticks_ms();
64-
}
65-
66-
// Convert uptime to ticks (1:1 mapping in MicroPython, both are milliseconds)
67-
static inline int64_t k_uptime_ticks(void) {
68-
return (int64_t)mp_hal_ticks_ms();
69-
}
70-
71-
// Get current cycle count (if available, otherwise return uptime in ms)
72-
static inline uint32_t k_cycle_get_32(void) {
73-
#ifdef mp_hal_ticks_cpu
74-
return mp_hal_ticks_cpu();
75-
#else
76-
return mp_hal_ticks_ms();
77-
#endif
78-
}
7952

8053
// --- Thread Info (No-op in MicroPython) ---
8154

@@ -105,10 +78,6 @@ static inline bool k_is_in_isr(void) {
10578
return false;
10679
}
10780

108-
// Check if pre-emptible (always returns false, no preemption in scheduler)
109-
static inline bool k_is_preempt_thread(void) {
110-
return false;
111-
}
11281

11382
// --- System State ---
11483

@@ -117,10 +86,6 @@ static inline bool k_is_preempt_thread(void) {
11786
#define KERNEL_VERSION_MINOR 7
11887
#define KERNEL_VERSION_PATCHLEVEL 0
11988

120-
// System state (always running in MicroPython)
121-
static inline bool k_is_pre_kernel(void) {
122-
return false;
123-
}
12489

12590
// --- Fatal Error Handlers ---
12691

extmod/zephyr_ble/hal/zephyr_ble_mem_slab.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,6 @@ static volatile int debug_enabled = 0;
4040
} \
4141
} while (0)
4242

43-
// Enable debug output
44-
void mp_bluetooth_zephyr_mem_slab_enable_debug(void) {
45-
debug_enabled = 1;
46-
mp_printf(&mp_plat_print, "[SLAB] Debug output enabled\n");
47-
}
4843

4944
// Initialize a memory slab (called by K_MEM_SLAB_DEFINE_STATIC macro)
5045
void k_mem_slab_init(struct k_mem_slab *slab, void *buffer, size_t block_size, uint32_t num_blocks) {

extmod/zephyr_ble/hal/zephyr_ble_poll.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,6 @@ void mp_bluetooth_zephyr_hci_uart_wfi(void) {
142142

143143
// --- Polling Functions ---
144144

145-
void mp_bluetooth_zephyr_poll_init(void) {
146-
// Currently nothing to initialize
147-
// Timers and work queues are initialized on first use
148-
}
149-
150-
void mp_bluetooth_zephyr_poll_deinit(void) {
151-
// Currently nothing to deinitialize
152-
// In the future, this might clean up global state
153-
}
154145

155146
void mp_bluetooth_zephyr_poll(void) {
156147
// Process HCI UART first (if implemented)

extmod/zephyr_ble/hal/zephyr_ble_psa_crypto.c

Lines changed: 0 additions & 111 deletions
This file was deleted.

extmod/zephyr_ble/hal/zephyr_ble_sem.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,3 @@ unsigned int k_sem_count_get(struct k_sem *sem) {
153153
return sem->count;
154154
}
155155

156-
void k_sem_reset(struct k_sem *sem) {
157-
DEBUG_SEM_printf("k_sem_reset(%p)\n", sem);
158-
sem->count = 0;
159-
}

extmod/zephyr_ble/hal/zephyr_ble_work.c

Lines changed: 1 addition & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333

3434
#include <stddef.h>
3535

36-
// Debug counter for tracking execution (avoids printf blocking issues)
37-
volatile int ble_work_debug_step = 0;
3836

3937
// Flag to indicate we're in the bt_enable() init phase
4038
// During this phase, mp_bluetooth_zephyr_init_work_get() will get work from k_sys_work_q
@@ -222,11 +220,6 @@ int k_work_cancel(struct k_work *work) {
222220
return 1;
223221
}
224222

225-
int k_work_cancel_sync(struct k_work *work, void *sync) {
226-
// sync parameter is for synchronization with other threads, not needed in MicroPython
227-
(void)sync;
228-
return k_work_cancel(work);
229-
}
230223

231224
bool k_work_is_pending(const struct k_work *work) {
232225
return work->pending;
@@ -286,19 +279,13 @@ int k_work_schedule(struct k_work_delayable *dwork, k_timeout_t delay) {
286279
return k_work_schedule_for_queue(&k_sys_work_q, dwork, delay);
287280
}
288281

289-
int k_work_reschedule_for_queue(struct k_work_q *queue, struct k_work_delayable *dwork, k_timeout_t delay) {
290-
DEBUG_WORK_printf("k_work_reschedule_for_queue(%p, %p, %u)\n", queue, dwork, delay.ticks);
291-
292-
// Reschedule is the same as schedule in our implementation
293-
return k_work_schedule_for_queue(queue, dwork, delay);
294-
}
295282

296283
int k_work_reschedule(struct k_work_delayable *dwork, k_timeout_t delay) {
297284
if (!k_sys_work_q.head && !k_sys_work_q.nextq) {
298285
k_work_queue_init(&k_sys_work_q);
299286
k_sys_work_q.name = "SYS WQ";
300287
}
301-
return k_work_reschedule_for_queue(&k_sys_work_q, dwork, delay);
288+
return k_work_schedule_for_queue(&k_sys_work_q, dwork, delay);
302289
}
303290

304291
int k_work_cancel_delayable(struct k_work_delayable *dwork) {
@@ -441,48 +428,6 @@ void mp_bluetooth_zephyr_work_process(void) {
441428
work_process_depth--;
442429
}
443430

444-
// Called by mp_bluetooth_init() wait loop to process initialization work synchronously
445-
void mp_bluetooth_zephyr_work_process_init(void) {
446-
// Prevent recursion (though unlikely since init work should be synchronous)
447-
if (init_work_processor_running) {
448-
DEBUG_WORK_printf("init_work_process: already running, skipping\n");
449-
return;
450-
}
451-
452-
init_work_processor_running = true;
453-
454-
// Process ONLY the initialization work queue
455-
struct k_work_q *q = &k_init_work_q;
456-
457-
while (q->head != NULL) {
458-
// Dequeue work item
459-
struct k_work *work = q->head;
460-
q->head = work->next;
461-
462-
if (q->head) {
463-
q->head->prev = NULL;
464-
}
465-
466-
work->next = NULL;
467-
work->prev = NULL;
468-
work->pending = false;
469-
470-
// Execute work handler
471-
DEBUG_WORK_printf("init_work_execute(%p, handler=%p)\n", work, work->handler);
472-
if (work->handler) {
473-
work->handler(work);
474-
}
475-
DEBUG_WORK_printf("init_work_execute(%p) done\n", work);
476-
477-
// Check if work was re-enqueued during execution
478-
if (work->pending) {
479-
DEBUG_WORK_printf(" --> init work re-enqueued, stopping queue processing\n");
480-
break;
481-
}
482-
}
483-
484-
init_work_processor_running = false;
485-
}
486431

487432
// --- Init Work Helper Functions ---
488433

@@ -543,74 +488,7 @@ struct k_work *mp_bluetooth_zephyr_init_work_get(void) {
543488
return work;
544489
}
545490

546-
// Debug function to report work processing statistics
547-
void mp_bluetooth_zephyr_work_debug_stats(void) {
548-
mp_printf(&mp_plat_print, "WORK STATS: process() called %d times, %d items processed\n",
549-
work_process_call_count, work_items_processed);
550-
}
551-
552-
// Process all pending work in all queues (except during init phase).
553-
// Used by the FreeRTOS work queue thread (added in zephyr_ble_freertos branch).
554-
#if MICROPY_BLUETOOTH_ZEPHYR_USE_FREERTOS
555-
static void ble_work_process_all(void) {
556-
ble_work_debug_step = 10; // Entered ble_work_process_all
557491

558-
// During init phase, main loop handles all work processing
559-
// to ensure proper sequencing of bt_enable() initialization
560-
if (mp_bluetooth_zephyr_in_init_phase()) {
561-
ble_work_debug_step = 11; // Skip due to init phase
562-
return;
563-
}
564-
ble_work_debug_step = 12; // Processing work
565-
566-
for (struct k_work_q *q = global_work_q; q != NULL; q = q->nextq) {
567-
// Skip initialization work queue (processed separately)
568-
if (q == &k_init_work_q) {
569-
continue;
570-
}
571-
572-
// Process all work items in this queue
573-
// Note: Must check q->head inside critical section to avoid race
574-
for (;;) {
575-
// Dequeue work item atomically
576-
MICROPY_PY_BLUETOOTH_ENTER
577-
struct k_work *work = q->head;
578-
if (work == NULL) {
579-
MICROPY_PY_BLUETOOTH_EXIT
580-
break; // Queue empty
581-
}
582-
q->head = work->next;
583-
if (q->head) {
584-
q->head->prev = NULL;
585-
}
586-
work->next = NULL;
587-
work->prev = NULL;
588-
work->pending = false;
589-
MICROPY_PY_BLUETOOTH_EXIT
590-
591-
// Execute work handler outside critical section
592-
work_items_processed++;
593-
ble_work_debug_step = 20; // About to execute work handler
594-
595-
if (work->handler) {
596-
// Set context flag if processing system work queue
597-
bool is_sys_wq = (q == &k_sys_work_q);
598-
if (is_sys_wq) {
599-
in_sys_work_q_context = true;
600-
}
601-
ble_work_debug_step = 21; // Calling handler
602-
work->handler(work);
603-
ble_work_debug_step = 22; // Handler returned
604-
if (is_sys_wq) {
605-
in_sys_work_q_context = false;
606-
}
607-
}
608-
609-
ble_work_debug_step = 23; // Work done
610-
}
611-
}
612-
}
613-
#endif // MICROPY_BLUETOOTH_ZEPHYR_USE_FREERTOS
614492

615493
// Stub implementations — work processed via cooperative polling, no dedicated work thread.
616494
void mp_bluetooth_zephyr_work_thread_start(void) {

0 commit comments

Comments
 (0)