From de8bcc19255656094f80fb81087c0b41741a3fa2 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Wed, 20 Feb 2013 13:05:33 -0300 Subject: [PATCH] atusb/fw/mac.c: always wait for stability before changing transceiver state --- atusb/fw/mac.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/atusb/fw/mac.c b/atusb/fw/mac.c index 7a63dbc..7a42759 100644 --- a/atusb/fw/mac.c +++ b/atusb/fw/mac.c @@ -106,15 +106,23 @@ static int handle_irq(void) } +static void change_state(uint8_t new) +{ + while ((reg_read(REG_TRX_STATUS) & TRX_STATUS_MASK) == + TRX_STATUS_TRANSITION); + reg_write(REG_TRX_STATE, new); +} + + int mac_rx(int on) { if (on) { mac_irq = handle_irq; reg_read(REG_IRQ_STATUS); - reg_write(REG_TRX_STATE, TRX_CMD_RX_ON); + change_state(TRX_CMD_RX_ON); } else { mac_irq = NULL; - reg_write(REG_TRX_STATE, TRX_CMD_FORCE_TRX_OFF); + change_state(TRX_CMD_FORCE_TRX_OFF); txing = 0; } return 1; @@ -153,9 +161,7 @@ static void do_tx(void *user) * Wait until we reach BUSY_TX, so that we command the transition to * RX_ON which will be executed upon TX completion. */ - while ((reg_read(REG_TRX_STATUS) & TRX_STATUS_MASK) == - TRX_STATUS_TRANSITION); - reg_write(REG_TRX_STATE, TRX_CMD_RX_ON); + change_state(TRX_CMD_RX_ON); }