diff options
author | Stefan Adolfsson <sadolfsson@chromium.org> | 2018-05-25 14:47:32 +0200 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-08-22 08:16:01 -0700 |
commit | e8252556d52f897f2ea443e1cdd1bb0ebf7174ab (patch) | |
tree | dabe6d6811a71f5839ef6590a389be47da1b44ce /include/cec.h | |
parent | 913a697b7b385f3b03ac16e9c96313139eab3578 (diff) | |
download | chrome-ec-e8252556d52f897f2ea443e1cdd1bb0ebf7174ab.tar.gz |
CEC: Make buffer handling code unit testable
Moving code to common/ to be able to write some unit test. The
API in cec.h will be refactored in a later commit since it does
not look so nice for a common API. However, it is better to do the
refactoring after the unit tests are in place
Signed-off-by: Stefan Adolfsson <sadolfsson@chromium.org>
BUG=b:80288314
BRANCH=none
TEST=emerge-fizz chromeos-ec
Change-Id: I2d675689cc40248d74bf812bd6c86125d681767d
Reviewed-on: https://chromium-review.googlesource.com/1073414
Commit-Ready: Stefan Adolfsson <sadolfsson@chromium.org>
Tested-by: Stefan Adolfsson <sadolfsson@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'include/cec.h')
-rw-r--r-- | include/cec.h | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/include/cec.h b/include/cec.h new file mode 100644 index 0000000000..d16378917f --- /dev/null +++ b/include/cec.h @@ -0,0 +1,55 @@ +/* Copyright 2018 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "ec_commands.h" + +/* Size of circular buffer used to store incoming CEC messages */ +#define CEC_CIRCBUF_SIZE 20 +#if CEC_CIRCBUF_SIZE < MAX_CEC_MSG_LEN + 1 +#error "Buffer must fit at least a CEC message and a length byte" +#endif +#if CEC_CIRCBUF_SIZE > 255 +#error "Buffer size must not exceed 255 since offsets are uint8_t" +#endif + +/* CEC message during transfer */ +struct cec_msg_transfer { + /* The CEC message */ + uint8_t buf[MAX_CEC_MSG_LEN]; + /* Bit offset */ + uint8_t bit; + /* Byte offset */ + uint8_t byte; +}; + +/* + * Circular buffer of completed incoming CEC messages + * ready to be read out by AP + */ +struct cec_rx_cb { + /* + * Write offset. Updated from interrupt context when we + * have received a complete message. + */ + uint8_t write_offset; + /* Read offset. Updated when AP sends CEC read command */ + uint8_t read_offset; + /* Cicular buffer data */ + uint8_t buf[CEC_CIRCBUF_SIZE]; +}; + +int msgt_get_bit(const struct cec_msg_transfer *msgt); + +void msgt_set_bit(struct cec_msg_transfer *msgt, int val); + +void msgt_inc_bit(struct cec_msg_transfer *msgt); + +int msgt_is_eom(const struct cec_msg_transfer *msgt, int len); + +void rx_circbuf_flush(struct cec_rx_cb *cb); + +int rx_circbuf_push(struct cec_rx_cb *cb, uint8_t *msg, uint8_t msg_len); + +int rx_circbuf_pop(struct cec_rx_cb *cb, uint8_t *msg, uint8_t *msg_len); |