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