11
11
* S3 - APB + XTAL clk
12
12
*/
13
13
14
- hw_timer_t * timer = NULL ;
15
- hw_timer_t * timer_XTAL = NULL ;
14
+ static hw_timer_t * timer = NULL ;
16
15
static volatile bool alarm_flag;
17
16
18
- /* These functions are intended to be called before and after each test. */
17
+ /* setUp / tearDown functions are intended to be called before / after each test. */
19
18
void setUp (void ) {
20
19
timer = timerBegin (TIMER_FREQUENCY);
20
+ if (timer == NULL ){
21
+ TEST_FAIL_MESSAGE (" Timer init failed in setUp()" );
22
+ }
21
23
timerStop (timer);
22
24
timerRestart (timer);
23
25
}
24
26
25
27
void tearDown (void ){
26
28
timerEnd (timer);
27
- timer = NULL ;
28
29
}
29
30
30
-
31
-
32
31
void ARDUINO_ISR_ATTR onTimer (){
33
32
alarm_flag = true ;
34
33
}
35
34
36
-
37
35
void timer_interrupt_test (void ){
38
-
36
+
39
37
alarm_flag = false ;
40
38
timerAttachInterrupt (timer, &onTimer);
41
39
timerAlarm (timer, (1.2 * TIMER_FREQUENCY), true , 0 );
@@ -67,9 +65,11 @@ void timer_divider_test(void){
67
65
68
66
// compare divider 16 and 8, value should be double
69
67
timerEnd (timer);
70
- timer = NULL ;
71
68
72
69
timer = timerBegin (2 * TIMER_FREQUENCY);
70
+ if (timer == NULL ){
71
+ TEST_FAIL_MESSAGE (" Timer init failed!" );
72
+ }
73
73
timerRestart (timer);
74
74
delay (1000 );
75
75
comp_time_val = timerRead (timer);
@@ -79,9 +79,11 @@ void timer_divider_test(void){
79
79
80
80
// divider is 256, value should be 2^4
81
81
timerEnd (timer);
82
- timer = NULL ;
83
82
84
83
timer = timerBegin (TIMER_FREQUENCY / 16 );
84
+ if (timer == NULL ){
85
+ TEST_FAIL_MESSAGE (" Timer init failed!" );
86
+ }
85
87
timerRestart (timer);
86
88
delay (1000 );
87
89
comp_time_val = timerRead (timer);
@@ -103,13 +105,10 @@ void timer_read_test(void){
103
105
104
106
void timer_clock_select_test (void ){
105
107
// Set timer frequency that can be achieved using XTAL clock source (autoselected)
106
- timer_XTAL = timerBegin (TIMER_FREQUENCY_XTAL_CLK);
108
+ timer = timerBegin (TIMER_FREQUENCY_XTAL_CLK);
107
109
108
- uint32_t resolution = timerGetFrequency (timer_XTAL );
110
+ uint32_t resolution = timerGetFrequency (timer );
109
111
TEST_ASSERT_EQUAL (TIMER_FREQUENCY_XTAL_CLK,resolution);
110
-
111
- timerEnd (timer_XTAL);
112
- timer_XTAL = NULL ;
113
112
}
114
113
115
114
void setup (){
@@ -131,4 +130,4 @@ void setup(){
131
130
}
132
131
133
132
void loop (){
134
- }
133
+ }
0 commit comments