fix(ble_audio): Miscellaneous fixes for ISO & LE Audio (stage 2)

This commit is contained in:
Liu Linyan
2026-09-04 09:26:24 +08:00
parent 30fd193df0
commit d4133e9751
113 changed files with 4547 additions and 2104 deletions
+42 -19
View File
@@ -28,11 +28,11 @@ static void iso_timer_cb(void *arg)
struct k_work *work = arg;
int err;
assert(work);
assert(work->timer);
assert(work->handler);
BT_LE_ASSERT(work);
BT_LE_ASSERT(work->timer);
BT_LE_ASSERT(work->handler);
err = bt_le_iso_task_post(ISO_QUEUE_ITEM_TYPE_TIMER_EVENT, work, 0);
err = bt_le_iso_task_post(ISO_QUEUE_ITEM_TYPE_TIMER_EVENT, work, work->gen);
if (err) {
LOG_ERR("TimerCbPostFail[%d]", err);
}
@@ -40,7 +40,7 @@ static void iso_timer_cb(void *arg)
int k_work_submit(struct k_work *work)
{
assert(work);
BT_LE_ASSERT(work);
if (work->handler == NULL) {
LOG_WRN("TimerSubmitHdlrNull");
@@ -65,7 +65,7 @@ bool k_work_is_pending(struct k_work *work)
{
bool is_pending;
assert(work);
BT_LE_ASSERT(work);
if (work->handler == NULL) {
LOG_WRN("TimerIsPendingHdlrNull");
@@ -81,20 +81,24 @@ bool k_work_is_pending(struct k_work *work)
void k_work_init(struct k_work *work, k_work_handler_t handler)
{
assert(work);
BT_LE_ASSERT(work);
/* Clear timer/timeout_us/gen too: callers must not have to zero-init */
memset(work, 0, sizeof(*work));
work->handler = handler;
}
struct k_work_delayable *k_work_delayable_from_work(struct k_work *work)
{
assert(work);
BT_LE_ASSERT(work);
return (struct k_work_delayable *)work;
}
void k_work_init_delayable(struct k_work_delayable *dwork,
k_work_handler_t handler)
{
assert(dwork);
BT_LE_ASSERT(dwork);
const esp_timer_create_args_t timer_args = {
.callback = &iso_timer_cb,
@@ -123,13 +127,18 @@ void k_work_deinit_delayable(struct k_work_delayable *dwork)
{
int err;
assert(dwork);
BT_LE_ASSERT(dwork);
if (dwork->work.timer == NULL) {
LOG_INF("TimerDeinitNotCreated");
return;
}
dwork->work.gen++;
/* esp_timer_delete rejects a running timer */
esp_timer_stop(dwork->work.timer);
err = esp_timer_delete(dwork->work.timer);
if (err) {
LOG_ERR("TimerDeinitDelFail[%d]", err);
@@ -141,7 +150,7 @@ void k_work_deinit_delayable(struct k_work_delayable *dwork)
int k_work_cancel_delayable(struct k_work_delayable *dwork)
{
assert(dwork);
BT_LE_ASSERT(dwork);
if (dwork->work.timer == NULL) {
LOG_INF("TimerCancelNotCreated");
@@ -149,6 +158,7 @@ int k_work_cancel_delayable(struct k_work_delayable *dwork)
}
esp_timer_stop(dwork->work.timer);
dwork->work.gen++;
return 0;
}
@@ -156,7 +166,7 @@ int k_work_cancel_delayable(struct k_work_delayable *dwork)
bool k_work_cancel_delayable_sync(struct k_work_delayable *dwork,
struct k_work_sync *sync)
{
assert(dwork);
BT_LE_ASSERT(dwork);
ARG_UNUSED(sync);
@@ -167,6 +177,8 @@ bool k_work_cancel_delayable_sync(struct k_work_delayable *dwork,
esp_timer_stop(dwork->work.timer);
dwork->work.gen++;
/* TODO: check the return result */
return false;
}
@@ -175,7 +187,7 @@ int k_work_schedule(struct k_work_delayable *dwork, k_timeout_t ms)
{
int err;
assert(dwork);
BT_LE_ASSERT(dwork);
if (dwork->work.timer == NULL) {
LOG_WRN("TimerSchNotCreated");
@@ -184,6 +196,8 @@ int k_work_schedule(struct k_work_delayable *dwork, k_timeout_t ms)
esp_timer_stop(dwork->work.timer);
dwork->work.gen++;
dwork->work.timeout_us = esp_timer_get_time() + (int64_t)ms * 1000;
if (ms == K_NO_WAIT) {
@@ -204,7 +218,7 @@ int k_work_reschedule(struct k_work_delayable *dwork, k_timeout_t ms)
{
int err;
assert(dwork);
BT_LE_ASSERT(dwork);
if (dwork->work.timer == NULL) {
LOG_WRN("TimerReschNotCreated");
@@ -213,6 +227,8 @@ int k_work_reschedule(struct k_work_delayable *dwork, k_timeout_t ms)
esp_timer_stop(dwork->work.timer);
dwork->work.gen++;
dwork->work.timeout_us = esp_timer_get_time() + (int64_t)ms * 1000;
if (ms == K_NO_WAIT) {
@@ -233,8 +249,8 @@ int k_work_schedule_periodic_us(struct k_work_delayable *dwork, uint64_t period_
{
int err;
assert(dwork);
assert(period_us > 0);
BT_LE_ASSERT(dwork);
BT_LE_ASSERT(period_us > 0);
if (dwork->work.timer == NULL) {
LOG_WRN("TimerPeriodicNotCreated");
@@ -243,6 +259,8 @@ int k_work_schedule_periodic_us(struct k_work_delayable *dwork, uint64_t period_
esp_timer_stop(dwork->work.timer);
dwork->work.gen++;
err = esp_timer_start_periodic(dwork->work.timer, period_us);
if (err) {
LOG_ERR("TimerPeriodicStartFail[%d]", err);
@@ -265,7 +283,7 @@ k_timeout_t k_work_delayable_remaining_get(struct k_work_delayable *dwork)
k_timeout_t timeout;
int64_t delta_us;
assert(dwork);
BT_LE_ASSERT(dwork);
if (dwork->work.timer == NULL) {
LOG_WRN("TimerRemainingNotCreated");
@@ -286,9 +304,14 @@ k_timeout_t k_work_delayable_remaining_get(struct k_work_delayable *dwork)
return timeout;
}
void bt_le_timer_handle_event(void *arg)
void bt_le_timer_handle_event(void *arg, size_t gen)
{
struct k_work *work = arg;
k_work_submit_safe(work);
bt_le_host_lock();
/* Drop the event if the work was re-armed or cancelled after it fired */
if ((uint32_t)gen == work->gen) {
k_work_submit(work);
}
bt_le_host_unlock();
}