From 9632d46ae793765ea948061b93945da5fa3d89db Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Thu, 11 Feb 2016 11:35:03 +0200 Subject: [PATCH] drivers/nble: Clean up & simplify IPC UART encoding We can take advantage of the net_buf headroom. At the same time move the necessary definition straight into uart.c and remove any unused definitions. Change-Id: I932bba2cfb11808aabce7bad09e41f94d073bb5b Signed-off-by: Johan Hedberg --- drivers/nble/uart.c | 38 +++++++++++++++++++------------------- drivers/nble/uart.h | 31 ------------------------------- 2 files changed, 19 insertions(+), 50 deletions(-) diff --git a/drivers/nble/uart.c b/drivers/nble/uart.c index 447992f9f0d..9f9b7c83d5a 100644 --- a/drivers/nble/uart.c +++ b/drivers/nble/uart.c @@ -31,6 +31,15 @@ #include "uart.h" #include "rpc.h" +/** + * @note this structure must be self-aligned and self-packed + */ +struct ipc_uart_header { + uint16_t len; /**< Length of IPC message. */ + uint8_t channel; /**< Channel number of IPC message. */ + uint8_t src_cpu_id; /**< CPU id of IPC sender. */ +} __packed; + /* TODO: check size */ #define NBLE_TX_BUF_COUNT 2 #define NBLE_RX_BUF_COUNT 8 @@ -70,7 +79,7 @@ struct net_buf *rpc_alloc_cb(uint16_t length) BT_DBG("length %u", length); - buf = net_buf_get(&tx, 0); + buf = net_buf_get(&tx, sizeof(struct ipc_uart_header)); if (!buf) { BT_ERR("Unable to get tx buffer"); return NULL; @@ -85,30 +94,21 @@ struct net_buf *rpc_alloc_cb(uint16_t length) return buf; } -static void poll_out(const void *buf, size_t length) -{ - const uint8_t *ptr = buf; - - while (length--) { - uart_poll_out(nble_dev, *ptr++); - } -} - void rpc_transmit_cb(struct net_buf *buf) { - struct ipc_uart_header hdr; + struct ipc_uart_header *hdr; BT_DBG("buf %p length %u", buf, buf->len); - hdr.len = buf->len; - hdr.channel = 0; - hdr.src_cpu_id = 0; + hdr = net_buf_push(buf, sizeof(*hdr)); + hdr->len = buf->len - sizeof(*hdr); + hdr->channel = 0; + hdr->src_cpu_id = 0; - /* Send header */ - poll_out(&hdr, sizeof(hdr)); - - /* Send data */ - poll_out(buf->data, buf->len); + while (buf->len) { + uart_poll_out(nble_dev, buf->data[0]); + net_buf_pull(buf, 1); + } net_buf_unref(buf); } diff --git a/drivers/nble/uart.h b/drivers/nble/uart.h index 346072bafbb..d4e5a7fc5a7 100644 --- a/drivers/nble/uart.h +++ b/drivers/nble/uart.h @@ -21,37 +21,6 @@ */ extern struct driver ipc_uart_ns16550_driver; -enum IPC_UART_RESULT_CODES { - IPC_UART_ERROR_OK = 0, - IPC_UART_ERROR_DATA_TO_BIG, - /**< A transmission is already ongoing, message is NOT sent */ - IPC_UART_TX_BUSY -}; - -/** - * Definitions valid for NONE sync IPC UART headers. - */ - -/** - * @note this structure must be self-aligned and self-packed - */ -struct ipc_uart_header { - uint16_t len; /**< Length of IPC message. */ - uint8_t channel; /**< Channel number of IPC message. */ - uint8_t src_cpu_id; /**< CPU id of IPC sender. */ -}; - -#define IPC_CHANNEL_STATE_CLOSED 0 -#define IPC_CHANNEL_STATE_OPEN 1 - -#define IPC_UART_MAX_CHANNEL 1 - -struct ipc_uart_channels { - uint16_t index; - uint16_t state; - int (*cb)(int chan, int request, int len, void *data); -}; - int nble_open(void); /**