summaryrefslogtreecommitdiff
path: root/common/usb_pd_tcpc.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/usb_pd_tcpc.c')
-rw-r--r--common/usb_pd_tcpc.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/common/usb_pd_tcpc.c b/common/usb_pd_tcpc.c
index 152775bbc0..11bc399b5e 100644
--- a/common/usb_pd_tcpc.c
+++ b/common/usb_pd_tcpc.c
@@ -261,7 +261,12 @@ static struct pd_port_controller {
static int rx_buf_is_full(int port)
{
- /* Buffer is full if the tail is 1 ahead of head */
+ /*
+ * TODO: Refactor these to use the incrementing-counter idiom instead of
+ * the wrapping-counter idiom to reclaim the last buffer entry.
+ *
+ * Buffer is full if the tail is 1 ahead of head.
+ */
int diff = pd[port].rx_buf_tail - pd[port].rx_buf_head;
return (diff == 1) || (diff == -RX_BUFFER_SIZE);
}
@@ -272,6 +277,11 @@ int rx_buf_is_empty(int port)
return pd[port].rx_buf_tail == pd[port].rx_buf_head;
}
+void rx_buf_clear(int port)
+{
+ pd[port].rx_buf_tail = pd[port].rx_buf_head;
+}
+
static void rx_buf_increment(int port, int *buf_ptr)
{
*buf_ptr = *buf_ptr == RX_BUFFER_SIZE ? 0 : *buf_ptr + 1;