diff options
-rw-r--r-- | chip/npcx/cec.c | 106 | ||||
-rw-r--r-- | common/cec.c | 93 | ||||
-rw-r--r-- | include/cec.h | 70 | ||||
-rw-r--r-- | test/cec.c | 55 |
4 files changed, 185 insertions, 139 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); 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; } diff --git a/include/cec.h b/include/cec.h index f5d7b01ebe..b1ac6dbbb0 100644 --- a/include/cec.h +++ b/include/cec.h @@ -5,12 +5,12 @@ #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 +/* Size of the buffer inside the rx queue */ +#define CEC_RX_BUFFER_SIZE 20 +#if CEC_RX_BUFFER_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 +#if CEC_RX_BUFFER_SIZE > 255 #error "Buffer size must not exceed 255 since offsets are uint8_t" #endif @@ -25,10 +25,10 @@ struct cec_msg_transfer { }; /* - * Circular buffer of completed incoming CEC messages + * Queue of completed incoming CEC messages * ready to be read out by AP */ -struct cec_rx_cb { +struct cec_rx_queue { /* * Write offset. Updated from interrupt context when we * have received a complete message. @@ -36,20 +36,60 @@ struct cec_rx_cb { 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]; + /* Data buffer */ + uint8_t buf[CEC_RX_BUFFER_SIZE]; }; -int msgt_get_bit(const struct cec_msg_transfer *msgt); +/** + * Get the current bit of a CEC message transfer + * + * @param queue Queue to flush + */ +int cec_transfer_get_bit(const struct cec_msg_transfer *transfer); -void msgt_set_bit(struct cec_msg_transfer *msgt, int val); +/** + * Set the current bit of a CEC message transfer + * + * @param transfer Message transfer to set current bit of + * @param val New bit value + */ +void cec_transfer_set_bit(struct cec_msg_transfer *transfer, int val); -void msgt_inc_bit(struct cec_msg_transfer *msgt); +/** + * Make the current bit the next bit in the transfer buffer + * + * @param transfer Message transfer to change current bit of + */ +void cec_transfer_inc_bit(struct cec_msg_transfer *transfer); -int msgt_is_eom(const struct cec_msg_transfer *msgt, int len); +/** + * Check if current bit is an end-of-message bit and if it is set + * + * @param transfer Message transfer to check for end-of-message + */ +int cec_transfer_is_eom(const struct cec_msg_transfer *transfer, int len); -void rx_circbuf_flush(struct cec_rx_cb *cb); +/** + * Flush all messages from a CEC receive queue + * + * @param queue Queue to flush + */ +void cec_rx_queue_flush(struct cec_rx_queue *queue); -int rx_circbuf_push(struct cec_rx_cb *cb, uint8_t *msg, uint8_t msg_len); +/** + * Push a CEC message to a CEC receive queue + * + * @param queue Queue to add message to + */ +int cec_rx_queue_push(struct cec_rx_queue *queue, const uint8_t *msg, + uint8_t msg_len); -int rx_circbuf_pop(struct cec_rx_cb *cb, uint8_t *msg, uint8_t *msg_len); +/** + * Pop a CEC message from a CEC receive queue + * + * @param queue Queue to retrieve message from + * @param msg Buffer to store retrieved message in + * @param msg_len Number of data bytes in msg + */ +int cec_rx_queue_pop(struct cec_rx_queue *queue, uint8_t *msg, + uint8_t *msg_len); diff --git a/test/cec.c b/test/cec.c index 3487ec1df4..64b230e509 100644 --- a/test/cec.c +++ b/test/cec.c @@ -19,16 +19,15 @@ BUILD_ASSERT(offsetof(struct overflow_msg, overflow_detector) == offsetof(struct cec_msg_transfer, buf) + MAX_CEC_MSG_LEN); -struct overflow_circbuf { - struct cec_rx_cb circbuf; - uint8_t overflow_detector[CEC_CIRCBUF_SIZE]; -} overflow_circbuf; +struct overflow_queue { + struct cec_rx_queue queue; + uint8_t overflow_detector[CEC_RX_BUFFER_SIZE]; +} overflow_queue; /* Ensure the overflow detector is located directly after the buffer */ -BUILD_ASSERT(offsetof(struct overflow_circbuf, overflow_detector) == - offsetof(struct cec_rx_cb, buf) + CEC_CIRCBUF_SIZE); +BUILD_ASSERT(offsetof(struct overflow_queue, overflow_detector) == + offsetof(struct cec_rx_queue, buf) + CEC_RX_BUFFER_SIZE); - -static struct cec_rx_cb *circbuf; +static struct cec_rx_queue *queue; /* Tests */ static int test_msg_overflow(void) @@ -37,8 +36,8 @@ static int test_msg_overflow(void) /* Overwrite the buffer by 1 byte */ for (i = 0; i < (MAX_CEC_MSG_LEN+1)*8; i++) { - msgt_set_bit(&overflow_msg.transfer, 1); - msgt_inc_bit(&overflow_msg.transfer); + cec_transfer_set_bit(&overflow_msg.transfer, 1); + cec_transfer_inc_bit(&overflow_msg.transfer); } /* Make sure we actually wrote the whole buffer with ones */ @@ -53,8 +52,8 @@ static int test_msg_overflow(void) /* Check that the indicator stays the same if we write another byte */ for (i = 0; i < 8; i++) { - msgt_set_bit(&overflow_msg.transfer, 1); - msgt_inc_bit(&overflow_msg.transfer); + cec_transfer_set_bit(&overflow_msg.transfer, 1); + cec_transfer_inc_bit(&overflow_msg.transfer); } TEST_ASSERT(overflow_msg.transfer.byte == MAX_CEC_MSG_LEN); @@ -63,21 +62,21 @@ static int test_msg_overflow(void) -static int verify_no_circbuf_overflow(void) +static int verify_no_queue_overflow(void) { int i; - for (i = 0; i < CEC_CIRCBUF_SIZE; i++) { - if (overflow_circbuf.overflow_detector[i] != 0) + for (i = 0; i < CEC_RX_BUFFER_SIZE; i++) { + if (overflow_queue.overflow_detector[i] != 0) return EC_ERROR_OVERFLOW; } return EC_SUCCESS; } -static void clear_circbuf(void) +static void clear_queue(void) { - memset(circbuf, 0, sizeof(struct cec_rx_cb)); + memset(queue, 0, sizeof(struct cec_rx_queue)); } @@ -88,27 +87,27 @@ static int fill_queue(uint8_t *msg, int msg_size) /* * Fill the queue. Every push adds the message and one extra byte for * the length field. The maximum data we can add is one less than - * CEC_CIRCBUF_SIZE since write_pointer==read_pointer is used to + * CEC_RX_BUFFER_SIZE since write_pointer==read_pointer is used to * indicate an empty buffer */ - clear_circbuf(); + clear_queue(); - for (i = 0; i < (CEC_CIRCBUF_SIZE - 1)/(msg_size + 1); i++) - TEST_ASSERT(rx_circbuf_push(circbuf, msg, msg_size) == 0); + for (i = 0; i < (CEC_RX_BUFFER_SIZE - 1)/(msg_size + 1); i++) + TEST_ASSERT(cec_rx_queue_push(queue, msg, msg_size) == 0); /* Now the queue should be full */ - TEST_ASSERT(rx_circbuf_push(circbuf, msg, msg_size) - == EC_ERROR_OVERFLOW); + TEST_ASSERT(cec_rx_queue_push(queue, msg, msg_size) == + EC_ERROR_OVERFLOW); /* Verify nothing was written outside of the queue */ - TEST_ASSERT(verify_no_circbuf_overflow() == EC_SUCCESS); + TEST_ASSERT(verify_no_queue_overflow() == EC_SUCCESS); return EC_SUCCESS; } -static int test_circbuf_overflow(void) +static int test_queue_overflow(void) { - uint8_t msg[CEC_CIRCBUF_SIZE]; + uint8_t msg[CEC_RX_BUFFER_SIZE]; memset(msg, 0xff, sizeof(msg)); @@ -122,11 +121,11 @@ static int test_circbuf_overflow(void) void run_test(void) { - circbuf = &overflow_circbuf.circbuf; + queue = &overflow_queue.queue; RUN_TEST(test_msg_overflow); - RUN_TEST(test_circbuf_overflow); + RUN_TEST(test_queue_overflow); test_print_result(); } |