@@ -29,8 +29,36 @@ using namespace utest::v1;
29
29
30
30
volatile int intFlag = 0 ;
31
31
32
- #define TICKER_INT_VAL 5000
33
- #define TICKER_DELTA 50
32
+ #define TICKER_GLITCH_TEST_TICKS 1000
33
+
34
+ #define TICKER_INT_VAL 500
35
+ #define TICKER_DELTA 10
36
+
37
+ #define LP_TICKER_OV_LIMIT 4000
38
+
39
+ /* Since according to the ticker requirements min acceptable counter size is
40
+ * - 12 bits for low power timer - max count = 4095,
41
+ * then all test cases must be executed in this time windows.
42
+ * HAL ticker layer handles counter overflow and it is not handled in the target
43
+ * ticker drivers. Ensure we have enough time to execute test case without overflow.
44
+ */
45
+ void overflow_protect ()
46
+ {
47
+ uint32_t time_window;
48
+
49
+ time_window = LP_TICKER_OV_LIMIT;
50
+
51
+ const uint32_t ticks_now = lp_ticker_read ();
52
+ const ticker_info_t * p_ticker_info = lp_ticker_get_info ();
53
+
54
+ const uint32_t max_count = ((1 << p_ticker_info->bits ) - 1 );
55
+
56
+ if ((max_count - ticks_now) > time_window) {
57
+ return ;
58
+ }
59
+
60
+ while (lp_ticker_read () > ticks_now);
61
+ }
34
62
35
63
void ticker_event_handler_stub (const ticker_data_t * const ticker)
36
64
{
@@ -71,6 +99,8 @@ void lp_ticker_deepsleep_test()
71
99
/* Wait for green tea UART transmission before entering deep-sleep mode. */
72
100
wait_cycles (400000 );
73
101
102
+ overflow_protect ();
103
+
74
104
const uint32_t tick_count = lp_ticker_read ();
75
105
76
106
/* Set interrupt. Interrupt should be fired when tick count is equal to:
@@ -91,13 +121,12 @@ void lp_ticker_glitch_test()
91
121
{
92
122
lp_ticker_init ();
93
123
94
- const ticker_info_t * p_ticker_info = lp_ticker_get_info ();
124
+ overflow_protect ();
95
125
96
126
uint32_t last = lp_ticker_read ();
97
127
const uint32_t start = last;
98
128
99
- /* Set test time to 2 sec. */
100
- while (last < (start + p_ticker_info->frequency * 2 )) {
129
+ while (last < (start + TICKER_GLITCH_TEST_TICKS)) {
101
130
const uint32_t cur = lp_ticker_read ();
102
131
TEST_ASSERT (cur >= last);
103
132
last = cur;
0 commit comments