aboutsummaryrefslogtreecommitdiffstats
path: root/firmware/usrp3/x300
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2017-01-30 09:40:02 +0100
committerMartin Braun <martin.braun@ettus.com>2017-01-30 09:40:02 +0100
commit211c590f594f83dc8b5fc724d49c1c8d7207d2f2 (patch)
tree16b03b97da7c61930053a0b8699a36d36e9857b2 /firmware/usrp3/x300
parent207903d343f6cb520d86e62c2ebee2e847546f7b (diff)
parent75e6ae59b3f4832372c08d7da390c5fdcc283067 (diff)
downloaduhd-211c590f594f83dc8b5fc724d49c1c8d7207d2f2.tar.gz
uhd-211c590f594f83dc8b5fc724d49c1c8d7207d2f2.tar.bz2
uhd-211c590f594f83dc8b5fc724d49c1c8d7207d2f2.zip
Merge branch 'maint'
Diffstat (limited to 'firmware/usrp3/x300')
-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;