From 998ac7e5c66ae7e5893e43b958183a138be1db10 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Wed, 24 Jul 2013 16:21:38 -0300 Subject: [PATCH] atusb/fw/mac.c (next_buf): dedicated function for incrementing buffer indices --- atusb/fw/mac.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/atusb/fw/mac.c b/atusb/fw/mac.c index 255ac6e..d4fd366 100644 --- a/atusb/fw/mac.c +++ b/atusb/fw/mac.c @@ -29,7 +29,6 @@ bool (*mac_irq)(void) = NULL; static uint8_t rx_buf[RX_BUFS][MAX_PSDU+2]; /* PHDR+payload+LQ */ -static bool rx_in = 0, rx_out = 0; static uint8_t tx_buf[MAX_PSDU]; static uint8_t tx_size = 0; static bool txing = 0; @@ -37,6 +36,18 @@ static bool queued_tx_ack = 0; static uint8_t next_seq, this_seq, queued_seq; +/* ----- Receive buffer management ----------------------------------------- */ + + +static uint8_t rx_in = 0, rx_out = 0; + + +static inline void next_buf(uint8_t *index) +{ + *index = (*index+1) % RX_BUFS; +} + + /* ----- Register access --------------------------------------------------- */ @@ -95,7 +106,7 @@ static void tx_ack_done(void *user) static void rx_done(void *user) { led(0); - rx_out = (rx_out+1) & (RX_BUFS-1); + next_buf(&rx_out); usb_next(); } @@ -122,7 +133,7 @@ static void receive_frame(void) spi_end(); buf[0] = size; - rx_in = (rx_in+1) & (RX_BUFS-1); + next_buf(&rx_in); if (eps[1].state == EP_IDLE) usb_next();