aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormichael-west <michael.west@ettus.com>2017-01-25 12:09:50 -0800
committerMartin Braun <martin.braun@ettus.com>2017-01-30 09:37:44 +0100
commita7d7c9d520ea59912e7cf7d22bbfd42cc96003ee (patch)
tree5cb0795271ba88680ce7a38949a2b9f50f886c65
parentc613c7edb41de76a667e106c0b31684ac890da03 (diff)
downloaduhd-a7d7c9d520ea59912e7cf7d22bbfd42cc96003ee.tar.gz
uhd-a7d7c9d520ea59912e7cf7d22bbfd42cc96003ee.tar.bz2
uhd-a7d7c9d520ea59912e7cf7d22bbfd42cc96003ee.zip
X300: Made claim status update with every loop of the firmware to make it atomic from the host perspective
-rw-r--r--firmware/usrp3/x300/x300_main.c37
1 files changed, 20 insertions, 17 deletions
diff --git a/firmware/usrp3/x300/x300_main.c b/firmware/usrp3/x300/x300_main.c
index c5e4fc88a..459f7b0b1 100644
--- a/firmware/usrp3/x300/x300_main.c
+++ b/firmware/usrp3/x300/x300_main.c
@@ -217,30 +217,28 @@ void handle_udp_mtu_detect(
/***********************************************************************
* Deal with host claims and claim timeout
**********************************************************************/
-static void handle_claim(void)
+static void handle_claim(uint32_t ticks_now)
{
+ static const uint32_t CLAIM_TIMEOUT = 2*CPU_CLOCK; // 2 seconds
+ static uint32_t ticks_last_claim = 0;
static uint32_t last_time = 0;
- static size_t timeout = 0;
- //time is 0 if the claim was forfeit
- if (shmem[X300_FW_SHMEM_CLAIM_TIME] == 0)
+ // Claim status can only change if the claim is active or the claim is renewed.
+ if (shmem[X300_FW_SHMEM_CLAIM_STATUS] != 0 &&
+ (shmem[X300_FW_SHMEM_CLAIM_TIME] == 0 ||
+ ticks_now - ticks_last_claim > CLAIM_TIMEOUT))
{
- shmem[X300_FW_SHMEM_CLAIM_STATUS] = 0;
+ // the claim was released or timed out
+ shmem[X300_FW_SHMEM_CLAIM_STATUS] = 0;
+ last_time = shmem[X300_FW_SHMEM_CLAIM_TIME];
}
- //if the time changes, reset timeout
else if (last_time != shmem[X300_FW_SHMEM_CLAIM_TIME])
{
+ // claim was renewed
shmem[X300_FW_SHMEM_CLAIM_STATUS] = 1;
- timeout = 0;
+ last_time = shmem[X300_FW_SHMEM_CLAIM_TIME];
+ ticks_last_claim = ticks_now;
}
- //otherwise increment for timeout
- else timeout++;
-
- //always stash the last seen time
- last_time = shmem[X300_FW_SHMEM_CLAIM_TIME];
-
- //the claim has timed out after 2 seconds
- if (timeout > 200) shmem[X300_FW_SHMEM_CLAIM_STATUS] = 0;
}
/***********************************************************************
@@ -419,8 +417,14 @@ int main(void)
while(true)
{
- //jobs that happen once every 10ms
const uint32_t ticks_now = wb_peek32(SR_ADDR(RB0_BASE, RB_COUNTER));
+
+ // handle the claim every time because any packet processed could
+ // have claimed or released the device and we want the claim status
+ // to be updated immediately to make it atomic from the host perspective
+ handle_claim(ticks_now);
+
+ //jobs that happen once every 10ms
const uint32_t ticks_passed = ticks_now - last_cronjob;
static const uint32_t tick_delta = CPU_CLOCK/100;
if (ticks_passed > tick_delta)
@@ -428,7 +432,6 @@ int main(void)
poll_sfpp_status(0); // Every so often poll XGE Phy to look for SFP+ hotplug events.
poll_sfpp_status(1); // Every so often poll XGE Phy to look for SFP+ hotplug events.
//handle_link_state(); //deal with router table update
- handle_claim(); //deal with the host claim register
update_leds(); //run the link and activity leds
garp(); //send periodic garps
last_cronjob = ticks_now;