diff options
author | Stefan Adolfsson <sadolfsson@chromium.org> | 2018-05-25 14:47:04 +0200 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-08-22 08:16:02 -0700 |
commit | f724479c5b3a3e394b4e6f7c16ed1054815daa44 (patch) | |
tree | eddf24c9473842b5ec1b2c717d9edefe5fa0c828 /chip | |
parent | e7bff8f8804e23680ff1fe57062c70debe856d21 (diff) | |
download | chrome-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 'chip')
-rw-r--r-- | chip/npcx/cec.c | 106 |
1 files changed, 55 insertions, 51 deletions
diff --git a/chip/npcx/cec.c b/chip/npcx/cec.c index 7d4fc3be78..60864bef56 100644 --- a/chip/npcx/cec.c +++ b/chip/npcx/cec.c @@ -186,9 +186,9 @@ enum cap_edge { struct cec_rx { /* * The current incoming message being parsed. Copied to - * circular buffer upon completion + * receive queue upon completion */ - struct cec_msg_transfer msgt; + struct cec_msg_transfer transfer; /* End of Message received from source? */ uint8_t eom; /* A follower NAK:ed a broadcast transfer */ @@ -205,7 +205,7 @@ struct cec_rx { /* Transfer buffer and states */ struct cec_tx { /* Outgoing message */ - struct cec_msg_transfer msgt; + struct cec_msg_transfer transfer; /* Message length */ uint8_t len; /* Number of resends attempted in current send */ @@ -225,8 +225,8 @@ static enum cec_state cec_state; /* Parameters and buffers for follower (receiver) state */ static struct cec_rx cec_rx; -/* Circular buffer of completed incoming */ -static struct cec_rx_cb cec_rx_cb; +/* Queue of completed incoming CEC messages */ +static struct cec_rx_queue cec_rx_queue; /* Parameters and buffer for initiator (sender) state */ static struct cec_tx cec_tx; @@ -346,16 +346,16 @@ void enter_state(enum cec_state new_state) gpio = 1; memset(&cec_rx, 0, sizeof(struct cec_rx)); memset(&cec_tx, 0, sizeof(struct cec_tx)); - memset(&cec_rx_cb, 0, sizeof(struct cec_rx_cb)); + memset(&cec_rx_queue, 0, sizeof(struct cec_rx_queue)); cap_charge = 0; cap_delay = 0; cec_events = 0; break; case CEC_STATE_IDLE: - cec_tx.msgt.bit = 0; - cec_tx.msgt.byte = 0; - cec_rx.msgt.bit = 0; - cec_rx.msgt.byte = 0; + cec_tx.transfer.bit = 0; + cec_tx.transfer.byte = 0; + cec_rx.transfer.bit = 0; + cec_rx.transfer.byte = 0; if (cec_tx.len > 0) { /* Execute a postponed send */ enter_state(CEC_STATE_INITIATOR_FREE_TIME); @@ -378,8 +378,8 @@ void enter_state(enum cec_state new_state) break; case CEC_STATE_INITIATOR_START_LOW: cec_tx.present_initiator = 1; - cec_tx.msgt.bit = 0; - cec_tx.msgt.byte = 0; + cec_tx.transfer.bit = 0; + cec_tx.transfer.byte = 0; gpio = 0; timeout = START_BIT_LOW_TICKS; break; @@ -392,25 +392,27 @@ void enter_state(enum cec_state new_state) case CEC_STATE_INITIATOR_HEADER_DEST_LOW: case CEC_STATE_INITIATOR_DATA_LOW: gpio = 0; - timeout = DATA_LOW(msgt_get_bit(&cec_tx.msgt)); + timeout = DATA_LOW(cec_transfer_get_bit(&cec_tx.transfer)); break; case CEC_STATE_INITIATOR_HEADER_INIT_HIGH: gpio = 1; cap_edge = CAP_EDGE_FALLING; - timeout = DATA_HIGH(msgt_get_bit(&cec_tx.msgt)); + timeout = DATA_HIGH(cec_transfer_get_bit(&cec_tx.transfer)); break; case CEC_STATE_INITIATOR_HEADER_DEST_HIGH: case CEC_STATE_INITIATOR_DATA_HIGH: gpio = 1; - timeout = DATA_HIGH(msgt_get_bit(&cec_tx.msgt)); + timeout = DATA_HIGH(cec_transfer_get_bit(&cec_tx.transfer)); break; case CEC_STATE_INITIATOR_EOM_LOW: gpio = 0; - timeout = DATA_LOW(msgt_is_eom(&cec_tx.msgt, cec_tx.len)); + timeout = DATA_LOW(cec_transfer_is_eom(&cec_tx.transfer, + cec_tx.len)); break; case CEC_STATE_INITIATOR_EOM_HIGH: gpio = 1; - timeout = DATA_HIGH(msgt_is_eom(&cec_tx.msgt, cec_tx.len)); + timeout = DATA_HIGH(cec_transfer_is_eom(&cec_tx.transfer, + cec_tx.len)); break; case CEC_STATE_INITIATOR_ACK_LOW: gpio = 0; @@ -424,7 +426,7 @@ void enter_state(enum cec_state new_state) break; case CEC_STATE_INITIATOR_ACK_VERIFY: cec_tx.ack = !gpio_get_level(CEC_GPIO_OUT); - if ((cec_tx.msgt.buf[0] & 0x0f) == CEC_BROADCAST_ADDR) { + if ((cec_tx.transfer.buf[0] & 0x0f) == CEC_BROADCAST_ADDR) { /* * We are sending a broadcast. Any follower can * can NAK a broadcast message the same way they @@ -469,7 +471,7 @@ void enter_state(enum cec_state new_state) timeout = CAP_DATA_HIGH_TICKS; break; case CEC_STATE_FOLLOWER_ACK_LOW: - addr = cec_rx.msgt.buf[0] & 0x0f; + addr = cec_rx.transfer.buf[0] & 0x0f; if (addr == cec_addr) { /* Destination is our address */ gpio = 0; @@ -486,7 +488,7 @@ void enter_state(enum cec_state new_state) * We are at safe sample time. A broadcast frame is considered * lost if any follower pulls the line low */ - if ((cec_rx.msgt.buf[0] & 0x0f) == CEC_BROADCAST_ADDR) + if ((cec_rx.transfer.buf[0] & 0x0f) == CEC_BROADCAST_ADDR) cec_rx.broadcast_nak = !gpio_get_level(CEC_GPIO_OUT); else cec_rx.broadcast_nak = 0; @@ -499,8 +501,8 @@ void enter_state(enum cec_state new_state) break; case CEC_STATE_FOLLOWER_ACK_FINISH: gpio = 1; - if (cec_rx.eom || cec_rx.msgt.byte >= MAX_CEC_MSG_LEN) { - addr = cec_rx.msgt.buf[0] & 0x0f; + if (cec_rx.eom || cec_rx.transfer.byte >= MAX_CEC_MSG_LEN) { + addr = cec_rx.transfer.buf[0] & 0x0f; if (addr == cec_addr || addr == CEC_BROADCAST_ADDR) { task_set_event(TASK_ID_CEC, TASK_EVENT_RECEIVED_DATA, 0); @@ -551,8 +553,8 @@ static void cec_event_timeout(void) enter_state(CEC_STATE_INITIATOR_HEADER_INIT_HIGH); break; case CEC_STATE_INITIATOR_HEADER_INIT_HIGH: - msgt_inc_bit(&cec_tx.msgt); - if (cec_tx.msgt.bit == 4) + cec_transfer_inc_bit(&cec_tx.transfer); + if (cec_tx.transfer.bit == 4) enter_state(CEC_STATE_INITIATOR_HEADER_DEST_LOW); else enter_state(CEC_STATE_INITIATOR_HEADER_INIT_LOW); @@ -561,8 +563,8 @@ static void cec_event_timeout(void) enter_state(CEC_STATE_INITIATOR_HEADER_DEST_HIGH); break; case CEC_STATE_INITIATOR_HEADER_DEST_HIGH: - msgt_inc_bit(&cec_tx.msgt); - if (cec_tx.msgt.byte == 1) + cec_transfer_inc_bit(&cec_tx.transfer); + if (cec_tx.transfer.byte == 1) enter_state(CEC_STATE_INITIATOR_EOM_LOW); else enter_state(CEC_STATE_INITIATOR_HEADER_DEST_LOW); @@ -581,7 +583,8 @@ static void cec_event_timeout(void) break; case CEC_STATE_INITIATOR_ACK_VERIFY: if (cec_tx.ack) { - if (!msgt_is_eom(&cec_tx.msgt, cec_tx.len)) { + if (!cec_transfer_is_eom(&cec_tx.transfer, + cec_tx.len)) { /* More data in this frame */ enter_state(CEC_STATE_INITIATOR_DATA_LOW); } else { @@ -609,8 +612,8 @@ static void cec_event_timeout(void) enter_state(CEC_STATE_INITIATOR_DATA_HIGH); break; case CEC_STATE_INITIATOR_DATA_HIGH: - msgt_inc_bit(&cec_tx.msgt); - if (cec_tx.msgt.bit == 0) + cec_transfer_inc_bit(&cec_tx.transfer); + if (cec_tx.transfer.bit == 0) enter_state(CEC_STATE_INITIATOR_EOM_LOW); else enter_state(CEC_STATE_INITIATOR_DATA_LOW); @@ -659,8 +662,8 @@ static void cec_event_cap(void) * A falling edge during free-time, postpone * this send and listen */ - cec_tx.msgt.bit = 0; - cec_tx.msgt.byte = 0; + cec_tx.transfer.bit = 0; + cec_tx.transfer.byte = 0; enter_state(CEC_STATE_FOLLOWER_START_LOW); break; case CEC_STATE_FOLLOWER_START_LOW: @@ -688,11 +691,11 @@ static void cec_event_cap(void) t = tmr_cap_get(); if (VALID_LOW(DATA_ZERO, t)) { cec_rx.low_ticks = t; - msgt_set_bit(&cec_rx.msgt, 0); + cec_transfer_set_bit(&cec_rx.transfer, 0); enter_state(cec_state + 1); } else if (VALID_LOW(DATA_ONE, t)) { cec_rx.low_ticks = t; - msgt_set_bit(&cec_rx.msgt, 1); + cec_transfer_set_bit(&cec_rx.transfer, 1); enter_state(cec_state + 1); } else { enter_state(CEC_STATE_IDLE); @@ -700,10 +703,10 @@ static void cec_event_cap(void) break; case CEC_STATE_FOLLOWER_HEADER_INIT_HIGH: t = tmr_cap_get(); - data = msgt_get_bit(&cec_rx.msgt); + data = cec_transfer_get_bit(&cec_rx.transfer); if (VALID_DATA_HIGH(data, cec_rx.low_ticks, t)) { - msgt_inc_bit(&cec_rx.msgt); - if (cec_rx.msgt.bit == 4) + cec_transfer_inc_bit(&cec_rx.transfer); + if (cec_rx.transfer.bit == 4) enter_state(CEC_STATE_FOLLOWER_HEADER_DEST_LOW); else enter_state(CEC_STATE_FOLLOWER_HEADER_INIT_LOW); @@ -713,10 +716,10 @@ static void cec_event_cap(void) break; case CEC_STATE_FOLLOWER_HEADER_DEST_HIGH: t = tmr_cap_get(); - data = msgt_get_bit(&cec_rx.msgt); + data = cec_transfer_get_bit(&cec_rx.transfer); if (VALID_DATA_HIGH(data, cec_rx.low_ticks, t)) { - msgt_inc_bit(&cec_rx.msgt); - if (cec_rx.msgt.bit == 0) + cec_transfer_inc_bit(&cec_rx.transfer); + if (cec_rx.transfer.bit == 0) enter_state(CEC_STATE_FOLLOWER_EOM_LOW); else enter_state(CEC_STATE_FOLLOWER_HEADER_DEST_LOW); @@ -754,10 +757,10 @@ static void cec_event_cap(void) break; case CEC_STATE_FOLLOWER_DATA_HIGH: t = tmr_cap_get(); - data = msgt_get_bit(&cec_rx.msgt); + data = cec_transfer_get_bit(&cec_rx.transfer); if (VALID_DATA_HIGH(data, cec_rx.low_ticks, t)) { - msgt_inc_bit(&cec_rx.msgt); - if (cec_rx.msgt.bit == 0) + cec_transfer_inc_bit(&cec_rx.transfer); + if (cec_rx.transfer.bit == 0) enter_state(CEC_STATE_FOLLOWER_EOM_LOW); else enter_state(CEC_STATE_FOLLOWER_DATA_LOW); @@ -825,7 +828,7 @@ static int cec_send(const uint8_t *msg, uint8_t len) for (i = 0; i < len && i < MAX_CEC_MSG_LEN; i++) CPRINTS(" 0x%02x", msg[i]); - memcpy(cec_tx.msgt.buf, msg, len); + memcpy(cec_tx.transfer.buf, msg, len); /* Elevate to interrupt context */ tmr2_start(0); @@ -973,7 +976,7 @@ static int cec_get_next_msg(uint8_t *out) int rv; uint8_t msg_len, msg[MAX_CEC_MSG_LEN]; - rv = rx_circbuf_pop(&cec_rx_cb, msg, &msg_len); + rv = cec_rx_queue_pop(&cec_rx_queue, msg, &msg_len); if (rv != 0) return EC_RES_UNAVAILABLE; @@ -1014,14 +1017,15 @@ void cec_task(void *unused) while (1) { events = task_wait_event(-1); if (events & TASK_EVENT_RECEIVED_DATA) { - rv = rx_circbuf_push(&cec_rx_cb, cec_rx.msgt.buf, - cec_rx.msgt.byte); + rv = cec_rx_queue_push(&cec_rx_queue, + cec_rx.transfer.buf, + cec_rx.transfer.byte); if (rv == EC_ERROR_OVERFLOW) { - /* Buffer full, prefer the most recent msg */ - rx_circbuf_flush(&cec_rx_cb); - rv = rx_circbuf_push(&cec_rx_cb, - cec_rx.msgt.buf, - cec_rx.msgt.byte); + /* Queue full, prefer the most recent msg */ + cec_rx_queue_flush(&cec_rx_queue); + rv = cec_rx_queue_push(&cec_rx_queue, + cec_rx.transfer.buf, + cec_rx.transfer.byte); } if (rv == EC_SUCCESS) mkbp_send_event(EC_MKBP_EVENT_CEC_MESSAGE); |