summaryrefslogtreecommitdiff
path: root/common/cec.c
diff options
context:
space:
mode:
authorStefan Adolfsson <sadolfsson@chromium.org>2018-05-25 14:47:04 +0200
committerchrome-bot <chrome-bot@chromium.org>2018-08-22 08:16:02 -0700
commitf724479c5b3a3e394b4e6f7c16ed1054815daa44 (patch)
treeeddf24c9473842b5ec1b2c717d9edefe5fa0c828 /common/cec.c
parente7bff8f8804e23680ff1fe57062c70debe856d21 (diff)
downloadchrome-ec-f724479c5b3a3e394b4e6f7c16ed1054815daa44.tar.gz
CEC: Cleanup the API for the CEC buffer handlers
Since this now lives in common/, make it look a bit nicer. Signed-off-by: Stefan Adolfsson <sadolfsson@chromium.org> BUG=b:80288314 BRANCH=none TEST=emerge-fizz chromeos-ec && make -j runtests Change-Id: I2fb10e2524af13c776ea067d8a24b4cd552c9ecb Reviewed-on: https://chromium-review.googlesource.com/1073416 Commit-Ready: Stefan Adolfsson <sadolfsson@chromium.org> Tested-by: Stefan Adolfsson <sadolfsson@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'common/cec.c')
-rw-r--r--common/cec.c93
1 files changed, 48 insertions, 45 deletions
diff --git a/common/cec.c b/common/cec.c
index 27df7a22d8..1bc3273c1d 100644
--- a/common/cec.c
+++ b/common/cec.c
@@ -11,57 +11,58 @@
#define CPRINTS(format, args...) cprints(CC_CEC, format, ## args)
/*
- * Mutex for the read-offset of the circular buffer. Needed since the
- * buffer is read and flushed from different contexts
+ * Mutex for the read-offset of the rx queue. Needed since the
+ * queue is read and flushed from different contexts
*/
-static struct mutex circbuf_readoffset_mutex;
+static struct mutex rx_queue_readoffset_mutex;
-int msgt_get_bit(const struct cec_msg_transfer *msgt)
+int cec_transfer_get_bit(const struct cec_msg_transfer *transfer)
{
- if (msgt->byte >= MAX_CEC_MSG_LEN)
+ if (transfer->byte >= MAX_CEC_MSG_LEN)
return 0;
- return msgt->buf[msgt->byte] & (0x80 >> msgt->bit);
+ return transfer->buf[transfer->byte] & (0x80 >> transfer->bit);
}
-void msgt_set_bit(struct cec_msg_transfer *msgt, int val)
+void cec_transfer_set_bit(struct cec_msg_transfer *transfer, int val)
{
uint8_t bit_flag;
- if (msgt->byte >= MAX_CEC_MSG_LEN)
+ if (transfer->byte >= MAX_CEC_MSG_LEN)
return;
- bit_flag = 0x80 >> msgt->bit;
- msgt->buf[msgt->byte] &= ~bit_flag;
+ bit_flag = 0x80 >> transfer->bit;
+ transfer->buf[transfer->byte] &= ~bit_flag;
if (val)
- msgt->buf[msgt->byte] |= bit_flag;
+ transfer->buf[transfer->byte] |= bit_flag;
}
-void msgt_inc_bit(struct cec_msg_transfer *msgt)
+void cec_transfer_inc_bit(struct cec_msg_transfer *transfer)
{
- if (++(msgt->bit) == 8) {
- if (msgt->byte >= MAX_CEC_MSG_LEN)
+ if (++(transfer->bit) == 8) {
+ if (transfer->byte >= MAX_CEC_MSG_LEN)
return;
- msgt->bit = 0;
- msgt->byte++;
+ transfer->bit = 0;
+ transfer->byte++;
}
}
-int msgt_is_eom(const struct cec_msg_transfer *msgt, int len)
+int cec_transfer_is_eom(const struct cec_msg_transfer *transfer, int len)
{
- if (msgt->bit)
+ if (transfer->bit)
return 0;
- return (msgt->byte == len);
+ return (transfer->byte == len);
}
-void rx_circbuf_flush(struct cec_rx_cb *cb)
+void cec_rx_queue_flush(struct cec_rx_queue *queue)
{
- mutex_lock(&circbuf_readoffset_mutex);
- cb->read_offset = 0;
- mutex_unlock(&circbuf_readoffset_mutex);
- cb->write_offset = 0;
+ mutex_lock(&rx_queue_readoffset_mutex);
+ queue->read_offset = 0;
+ mutex_unlock(&rx_queue_readoffset_mutex);
+ queue->write_offset = 0;
}
-int rx_circbuf_push(struct cec_rx_cb *cb, uint8_t *msg, uint8_t msg_len)
+int cec_rx_queue_push(struct cec_rx_queue *queue, const uint8_t *msg,
+ uint8_t msg_len)
{
int i;
uint32_t offset;
@@ -69,66 +70,68 @@ int rx_circbuf_push(struct cec_rx_cb *cb, uint8_t *msg, uint8_t msg_len)
if (msg_len > MAX_CEC_MSG_LEN || msg_len == 0)
return EC_ERROR_INVAL;
- offset = cb->write_offset;
+ offset = queue->write_offset;
/* Fill in message length last, if successful. Set to zero for now */
- cb->buf[offset] = 0;
- offset = (offset + 1) % CEC_CIRCBUF_SIZE;
+ queue->buf[offset] = 0;
+ offset = (offset + 1) % CEC_RX_BUFFER_SIZE;
for (i = 0 ; i < msg_len; i++) {
- if (offset == cb->read_offset) {
+ if (offset == queue->read_offset) {
/* Buffer full */
return EC_ERROR_OVERFLOW;
}
- cb->buf[offset] = msg[i];
- offset = (offset + 1) % CEC_CIRCBUF_SIZE;
+ queue->buf[offset] = msg[i];
+ offset = (offset + 1) % CEC_RX_BUFFER_SIZE;
}
/*
* Don't commit if we caught up with read-offset
* since that would indicate an empty buffer
*/
- if (offset == cb->read_offset) {
+ if (offset == queue->read_offset) {
/* Buffer full */
return EC_ERROR_OVERFLOW;
}
/* Commit the push */
- cb->buf[cb->write_offset] = msg_len;
- cb->write_offset = offset;
+ queue->buf[queue->write_offset] = msg_len;
+ queue->write_offset = offset;
return EC_SUCCESS;
}
-int rx_circbuf_pop(struct cec_rx_cb *cb, uint8_t *msg, uint8_t *msg_len)
+int cec_rx_queue_pop(struct cec_rx_queue *queue, uint8_t *msg,
+ uint8_t *msg_len)
{
int i;
- mutex_lock(&circbuf_readoffset_mutex);
- if (cb->read_offset == cb->write_offset) {
- /* Circular buffer empty */
- mutex_unlock(&circbuf_readoffset_mutex);
+ mutex_lock(&rx_queue_readoffset_mutex);
+ if (queue->read_offset == queue->write_offset) {
+ /* Queue empty */
+ mutex_unlock(&rx_queue_readoffset_mutex);
*msg_len = 0;
return -1;
}
/* The first byte in the buffer is the message length */
- *msg_len = cb->buf[cb->read_offset];
+ *msg_len = queue->buf[queue->read_offset];
if (*msg_len == 0 || *msg_len > MAX_CEC_MSG_LEN) {
- mutex_unlock(&circbuf_readoffset_mutex);
+ mutex_unlock(&rx_queue_readoffset_mutex);
*msg_len = 0;
CPRINTF("Invalid CEC msg size: %u\n", *msg_len);
return -1;
}
- cb->read_offset = (cb->read_offset + 1) % CEC_CIRCBUF_SIZE;
+ queue->read_offset = (queue->read_offset + 1) % CEC_RX_BUFFER_SIZE;
for (i = 0; i < *msg_len; i++) {
- msg[i] = cb->buf[cb->read_offset];
- cb->read_offset = (cb->read_offset + 1) % CEC_CIRCBUF_SIZE;
+ msg[i] = queue->buf[queue->read_offset];
+ queue->read_offset = (queue->read_offset + 1) %
+ CEC_RX_BUFFER_SIZE;
}
- mutex_unlock(&circbuf_readoffset_mutex);
+ mutex_unlock(&rx_queue_readoffset_mutex);
return 0;
}