Mistake on this page?
Report an issue in GitHub or email us
ticker_api_tests.h
1 /* mbed Microcontroller Library
2  * Copyright (c) 2017-2017 ARM Limited
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 /** \addtogroup hal_ticker_tests */
18 /** @{*/
19 
20 #ifndef TICKER_API_TESTS_H
21 #define TICKER_API_TESTS_H
22 
23 #include "device.h"
24 
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 /** Test that ticker_init can be called multiple times and
31  * ticker_init resets the internal count and disables the ticker interrupt.
32  *
33  * Given ticker is initialised and interrupt is set.
34  * When ticker is re-initialised.
35  * Then ticker keeps counting and disables the ticker interrupt.
36  */
37 void ticker_init_test(void);
38 
39 /** Test that ticker frequency is non-zero and counter is at least 8 bits
40  *
41  * Given ticker is available.
42  * When ticker information data is obtained.
43  * Then ticker information indicate that frequency is non-zero and counter is at least 8 bits.
44  */
45 void ticker_info_test(void);
46 
47 /** Test that the ticker increments by one on each tick.
48  *
49  * We have the following assumption for the timer clock frequency:
50  *
51  * NOTE:
52  * high freq ticker: 250 KHz (1 tick per 4 us) - 8 Mhz (1 tick per 1/8 us)
53  * low power ticker: 8 KHz (1 tick per 125 us) - 64 KHz (1 tick per ~15.6 us)
54  *
55  * Lowest CPU speed is 16 MHz (1 tick per 1/16 us).
56  *
57  * For the boards with ticker clock freq less than or equal to 250 KHz we will try to prove that ticker is incremented by one
58  * straightforward by reading ticker count value in the loop in order to detect a single ticker value update (hopefully by one).
59  * For faster tickers we need to prove this indirectly using additional count_ticks() function which returns number of
60  * ticks needed to perform N cycles of the empty while loop. For the same number of cycles function result should be the same with
61  * accuracy +/- 1 tick. After the first test we will call count_ticks again with number of cycles equal N, N+1, N+2, ...
62  * until we get other ticks result.
63  *
64  * Given ticker is available.
65  * When ticker is initialised.
66  * Then ticker counter is incremented by one.
67  */
68 void ticker_increment_test(void);
69 
70 /** Test that ticker interrupt fires only when the ticker counter increments to the value set by ticker_set_interrupt.
71  *
72  * Given ticker is available, initialised.
73  * When ticker interrupt is set.
74  * Then ticker interrupt fires at the valid time.
75  */
76 void ticker_interrupt_test(void);
77 
78 /** Test that ticker interrupt is not triggered when ticker_set_interrupt is called with a time from the past
79  *
80  * Given ticker is available, initialised.
81  * When ticker interrupt is set to the time in the past.
82  * Then ticker interrupt is not triggered.
83  */
84 void ticker_past_test(void);
85 
86 /** Test that ticker can be rescheduled repeatedly before the handler has been called.
87  *
88  * Given ticker is available, initialised.
89  * When ticker interrupt is set and then rescheduled (interrupt time is modified).
90  * Then ticker interrupt is triggered according the rescheduled time.
91  */
93 
94 /** Test that ticker_fire_interrupt causes the interrupt to get fired immediately.
95  *
96  * Given ticker is available.
97  * When ticker_fire_interrupt is called.
98  * Then ticker interrupt is triggered.
99  */
100 void ticker_fire_now_test(void);
101 
102 /** Test that common ticker functions complete with the required amount of time.
103  *
104  * Given ticker is available.
105  * When ticker_read, ticker_clear_interrupt, ticker_set_interrupt, ticker_fire_interrupt or ticker_disable_interrupt function is called.
106  * Then its execution is not longer than 20 us.
107  */
108 void ticker_speed_test(void);
109 
110 /** Test that the ticker correctly handles overflow.
111  *
112  * Note that for high frequency timers we will only prove that ticker counter rollovers and
113  * continue counting (it is not possible to prove in deterministic way that after rollover next value is 0).
114  *
115  * Given ticker is available.
116  * When ticker has overflows.
117  * Then ticker continues counting from the beginning and interrupt scheduling works.
118  */
119 void ticker_overflow_test(void);
120 
121 /**@}*/
122 
123 #ifdef __cplusplus
124 }
125 #endif
126 
127 #endif
128 
129 /**@}*/
void ticker_increment_test(void)
Test that the ticker increments by one on each tick.
void ticker_speed_test(void)
Test that common ticker functions complete with the required amount of time.
void ticker_past_test(void)
Test that ticker interrupt is not triggered when ticker_set_interrupt is called with a time from the ...
void ticker_fire_now_test(void)
Test that ticker_fire_interrupt causes the interrupt to get fired immediately.
void ticker_interrupt_test(void)
Test that ticker interrupt fires only when the ticker counter increments to the value set by ticker_s...
void ticker_init_test(void)
Test that ticker_init can be called multiple times and ticker_init resets the internal count and disa...
void ticker_overflow_test(void)
Test that the ticker correctly handles overflow.
void ticker_info_test(void)
Test that ticker frequency is non-zero and counter is at least 8 bits.
void ticker_repeat_reschedule_test(void)
Test that ticker can be rescheduled repeatedly before the handler has been called.
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.