From 367c1abb0ee5fd16c8ac5be0a22052596f447f1a Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Mon, 1 Apr 2013 22:04:05 -0300 Subject: [PATCH] atusb/fw/: echo back TX ACK sequence number; don't panic if driver times out TX --- atusb/fw/ep0.c | 2 +- atusb/fw/include/atusb/atusb.h | 2 +- atusb/fw/mac.c | 17 ++++++++++------- atusb/fw/mac.h | 2 +- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/atusb/fw/ep0.c b/atusb/fw/ep0.c index 5c9fed4..04a7442 100644 --- a/atusb/fw/ep0.c +++ b/atusb/fw/ep0.c @@ -245,7 +245,7 @@ static bool my_setup(const struct setup_request *setup) case ATUSB_TO_DEV(ATUSB_RX_MODE): return mac_rx(setup->wValue); case ATUSB_TO_DEV(ATUSB_TX): - return mac_tx(setup->wValue, setup->wLength); + return mac_tx(setup->wValue, setup->wIndex, setup->wLength); default: error("Unrecognized SETUP: 0x%02x 0x%02x ...\n", diff --git a/atusb/fw/include/atusb/atusb.h b/atusb/fw/include/atusb/atusb.h index 311500c..a4f9651 100644 --- a/atusb/fw/include/atusb/atusb.h +++ b/atusb/fw/include/atusb/atusb.h @@ -76,7 +76,7 @@ enum atusb_requests { * ->host ATUSB_SPI_WRITE2_SYNC byte0 byte1 0/1 * * host-> ATUSB_RX_MODE on - 0 - * host-> ATUSB_TX flags 0 #bytes + * host-> ATUSB_TX flags ack_seq #bytes */ #define ATUSB_REQ_FROM_DEV (USB_TYPE_VENDOR | USB_DIR_IN) diff --git a/atusb/fw/mac.c b/atusb/fw/mac.c index 33ae848..33c891b 100644 --- a/atusb/fw/mac.c +++ b/atusb/fw/mac.c @@ -31,6 +31,7 @@ static uint8_t tx_size = 0; static bool txing = 0; static bool queued_tx_ack = 0; static bool queued_rx = 0; +static uint8_t next_seq, this_seq, queued_seq; static uint8_t reg_read(uint8_t reg) @@ -67,7 +68,7 @@ static void rx_done(void *user) return; } if (queued_tx_ack) { - usb_send(&eps[1], "", 1, rx_done, NULL); + usb_send(&eps[1], &queued_seq, 1, rx_done, NULL); queued_tx_ack = 0; } } @@ -114,12 +115,11 @@ static bool handle_irq(void) return 1; if (txing) { - if (eps[1].state == EP_IDLE) - usb_send(&eps[1], "", 1, rx_done, NULL); - else { - if (queued_tx_ack) - panic(); + if (eps[1].state == EP_IDLE) { + usb_send(&eps[1], &this_seq, 1, rx_done, NULL); + } else { queued_tx_ack = 1; + queued_seq = this_seq; } txing = 0; return 1; @@ -198,6 +198,7 @@ static void do_tx(void *user) slp_tr(); txing = 1; + this_seq = next_seq; /* * Wait until we reach BUSY_TX, so that we command the transition to @@ -207,11 +208,12 @@ static void do_tx(void *user) } -bool mac_tx(uint16_t flags, uint16_t len) +bool mac_tx(uint16_t flags, uint8_t seq, uint16_t len) { if (len > MAX_PSDU) return 0; tx_size = len; + next_seq = seq; usb_recv(&eps[0], tx_buf, len, do_tx, NULL); return 1; } @@ -223,6 +225,7 @@ void mac_reset(void) txing = 0; queued_tx_ack = 0; queued_rx = 0; + next_seq = this_seq = queued_seq = 0; /* enable CRC and PHY_RSSI (with RX_CRC_VALID) in SPI status return */ reg_write(REG_TRX_CTRL_1, diff --git a/atusb/fw/mac.h b/atusb/fw/mac.h index ca7caff..f3c92fb 100644 --- a/atusb/fw/mac.h +++ b/atusb/fw/mac.h @@ -20,7 +20,7 @@ extern bool (*mac_irq)(void); bool mac_rx(int on); -bool mac_tx(uint16_t flags, uint16_t len); +bool mac_tx(uint16_t flags, uint8_t seq, uint16_t len); void mac_reset(void); #endif /* !MAC_H */