From: IanR778 Date: Wed, 8 Oct 2014 00:11:04 +0000 (+0100) Subject: Firmware sometimes returns erroneous timestamps X-Git-Tag: 1.4.0~1^2~3 X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=666302581d93fe7f7c5d56d1ff05c670c37077a0;p=open-ath9k-htc-firmware.git Firmware sometimes returns erroneous timestamps Added proper synchronization while handling lower 32 bit and upper 32 bit parts in ar5416GetTsf64(). --- diff --git a/target_firmware/wlan/ar5416_hw.c b/target_firmware/wlan/ar5416_hw.c index 3f3c4bc..4d2a9f4 100644 --- a/target_firmware/wlan/ar5416_hw.c +++ b/target_firmware/wlan/ar5416_hw.c @@ -275,14 +275,23 @@ ar5416SetInterrupts(struct ath_hal *ah, HAL_INT ints) /* TSF Handling */ /****************/ +#define ATH9K_HTC_MAX_TSF_READ 3 + u_int64_t ar5416GetTsf64(struct ath_hal *ah) { - u_int64_t tsf; - - tsf = ioread32_mac(AR_TSF_U32); - tsf = (tsf << 32) | ioread32_mac(AR_TSF_L32); + a_uint32_t tsf_lower, tsf_upper1, tsf_upper2; + a_int32_t i; + + tsf_upper1 = ioread32_mac(AR_TSF_U32); + for (i = 0; i < ATH9K_HTC_MAX_TSF_READ; i++) { + tsf_lower = ioread32_mac(AR_TSF_L32); + tsf_upper2 = ioread32_mac(AR_TSF_U32); + if (tsf_upper2 == tsf_upper1) + break; + tsf_upper1 = tsf_upper2; + } - return tsf; + return (((u_int64_t)tsf_upper2 << 32) | tsf_lower); } /******/