From: Ivan Grokhotkov <ivan@espressif.com>
Date: Thu, 7 Sep 2017 17:33:20 +0000 (+0800)
Subject: unit tests: fix ref_clock value obtained due to overflow
X-Git-Tag: v3.1-dev~144^2~20
X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2b3325b1abc58221f48bf809d24274e3ef24ad25;p=esp-idf

unit tests: fix ref_clock value obtained due to overflow
---

diff --git a/tools/unit-test-app/components/unity/ref_clock.c b/tools/unit-test-app/components/unity/ref_clock.c
index 696bd0a4d3..94afe01bd7 100644
--- a/tools/unit-test-app/components/unity/ref_clock.c
+++ b/tools/unit-test-app/components/unity/ref_clock.c
@@ -159,6 +159,8 @@ uint64_t ref_clock_get()
     uint32_t microseconds = PCNT.cnt_unit[REF_CLOCK_PCNT_UNIT].cnt_val;
     uint32_t milliseconds = s_milliseconds;
     if (PCNT.int_st.val & BIT(REF_CLOCK_PCNT_UNIT)) {
+        // refresh counter value, in case the overflow has happened after reading cnt_val
+        microseconds = PCNT.cnt_unit[REF_CLOCK_PCNT_UNIT].cnt_val;
         milliseconds += REF_CLOCK_PRESCALER_MS;
     }
     portEXIT_CRITICAL(&s_lock);