Caches buf->len for use in loop condition
This commit is contained in:
parent
3a48b0b825
commit
84c42f5605
35
src/main.c
35
src/main.c
|
@ -100,10 +100,10 @@ reliable_packet(h5_pkt_t type)
|
|||
#define H5_RX_ACK_TIMEOUT K_MSEC(250)
|
||||
#define H5_TX_ACK_TIMEOUT K_MSEC(250)
|
||||
|
||||
#define SLIP_DELIMITER 0xc0
|
||||
#define SLIP_ESC 0xdb
|
||||
#define SLIP_ESC_DELIM 0xdc
|
||||
#define SLIP_ESC_ESC 0xdd
|
||||
#define SLIP_DELIMITER 0xc0
|
||||
#define SLIP_ESC 0xdb
|
||||
#define SLIP_ESC_DELIM 0xdc
|
||||
#define SLIP_ESC_ESC 0xdd
|
||||
|
||||
#define H5_RX_ESC 1
|
||||
#define H5_TX_ACK_PEND 2
|
||||
|
@ -307,7 +307,7 @@ h5_send(const u8_t *payload, h5_pkt_t type, int len)
|
|||
|
||||
struct net_buf *buf = net_buf_alloc(&uart_tx_pool, K_MSEC(250));
|
||||
if (!buf) {
|
||||
LOG_WRN("Waited to long for a UART tx buffer, dropping");
|
||||
LOG_WRN("Waited too long for a UART tx buffer, dropping");
|
||||
return;
|
||||
}
|
||||
net_buf_add_mem(buf, &hdr, sizeof(h5_hdr_t));
|
||||
|
@ -645,10 +645,8 @@ unproc_thread(void)
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
h5_send_sync(void);
|
||||
static void
|
||||
h5_send_config(void);
|
||||
static void h5_send_sync(void);
|
||||
static void h5_send_config(void);
|
||||
|
||||
static void
|
||||
tx_thread(void)
|
||||
|
@ -697,7 +695,7 @@ event_thread(void)
|
|||
while (true) {
|
||||
buf = net_buf_get(&h5.event_queue, K_MSEC(1000));
|
||||
if (!buf) {
|
||||
LOG_WRN("event_queue is empty");
|
||||
//LOG_WRN("event_queue is empty");
|
||||
continue;
|
||||
}
|
||||
net_buf_put(&h5.host_queue, buf);
|
||||
|
@ -709,9 +707,13 @@ uart_tx_thread()
|
|||
{
|
||||
while (true) {
|
||||
struct net_buf *buf = net_buf_get(&h5.uart_tx_queue, K_FOREVER);
|
||||
if (!buf) {
|
||||
LOG_ERR("uart_tx_queue buf is NULL");
|
||||
continue;
|
||||
}
|
||||
uart_poll_out(hci_uart_dev, SLIP_DELIMITER);
|
||||
|
||||
for (size_t i = 0; i < buf->len; i++) {
|
||||
for (size_t i = 0, j = buf->len; i < j; i++) {
|
||||
h5_slip_byte(net_buf_pull_u8(buf));
|
||||
}
|
||||
uart_poll_out(hci_uart_dev, SLIP_DELIMITER);
|
||||
|
@ -944,13 +946,13 @@ do_uninit(struct net_buf const *buf)
|
|||
h5_send_sync_response();
|
||||
return UNINIT;
|
||||
case H5_SYNC_RESPONSE:
|
||||
//h5_send_config();
|
||||
h5_send_config();
|
||||
LOG_DBG("RX'd SYNC RESPONSE: UNINIT -> INIT");
|
||||
return INIT;
|
||||
default:
|
||||
LOG_DBG("RX'd Incorrect Type: UNINIT -> UNINIT");
|
||||
/* SYNC is the answer to any non-SYNC_RESP packets in UNINIT state */
|
||||
//h5_send_sync();
|
||||
h5_send_sync();
|
||||
return UNINIT;
|
||||
}
|
||||
}
|
||||
|
@ -986,11 +988,11 @@ do_active(struct net_buf *buf)
|
|||
switch (packet_get_type(buf)) {
|
||||
case H5_SYNC:
|
||||
LOG_WRN("SYNC in ACTIVE state, peer reset: ACTIVE -> UNINIT");
|
||||
//h5_send_sync();
|
||||
h5_send_sync();
|
||||
return UNINIT;
|
||||
case H5_SYNC_RESPONSE:
|
||||
LOG_DBG("SYNC_RESPONSE in ACTIVE state: ACTIVE -> UNINIT");
|
||||
//h5_send_sync();
|
||||
h5_send_sync();
|
||||
return UNINIT;
|
||||
case H5_CONFIG:
|
||||
h5_send_config_response();
|
||||
|
@ -1037,9 +1039,8 @@ main(void)
|
|||
h5_init();
|
||||
|
||||
while (true) {
|
||||
buf = net_buf_get(&h5.host_queue, K_MSEC(1000));
|
||||
buf = net_buf_get(&h5.host_queue, K_MSEC(250));
|
||||
if (!buf) {
|
||||
LOG_WRN("host_queue is empty");
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue