From 34a40c8180bdd9bc9d70ad30e7e8ef1d0ba225cd Mon Sep 17 00:00:00 2001 From: Shawn Nock Date: Thu, 18 Jul 2019 12:23:04 -0400 Subject: [PATCH] Allows tx_thread to respond more quickly to state changes --- src/main.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/main.c b/src/main.c index c6a8dcf..fc5f26f 100644 --- a/src/main.c +++ b/src/main.c @@ -628,12 +628,9 @@ static void tx_thread(void) k_sleep(250); break; case ACTIVE: - buf = net_buf_get(&h5.controller_queue, K_MSEC(250)); - if (!buf) { - break; - } - //LOG_HEXDUMP_DBG(buf->data, buf->len, "TX_QUEUE -> CTRL"); - bt_send(buf); + while ((buf = net_buf_get(&h5.controller_queue, K_MSEC(100)))) { + bt_send(buf); + } /* buf is dequeued from tx_queue and queued to unack * queue. @@ -888,6 +885,14 @@ static linkstate_t do_active(struct net_buf *buf) { } } +void state_change(int old, int new) { + if (old == new) { + return; + } + h5.link_state = new; + k_wakeup(&tx_thread_data); +} + void main(void) { LOG_DBG("Start"); @@ -901,13 +906,13 @@ void main(void) switch (h5.link_state) { case UNINIT: - h5.link_state = do_uninit(buf); + state_change(h5.link_state, do_uninit(buf)); break; case INIT: - h5.link_state = do_init(buf); + state_change(h5.link_state, do_init(buf)); break; case ACTIVE: - h5.link_state = do_active(buf); + state_change(h5.link_state, do_active(buf)); break; } net_buf_unref(buf);