1111 * S3 - APB + XTAL clk
1212 */
1313
14- hw_timer_t * timer = NULL ;
15- hw_timer_t * timer_XTAL = NULL ;
14+ static hw_timer_t * timer = NULL ;
1615static volatile bool alarm_flag;
1716
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. */
1918void setUp (void ) {
2019 timer = timerBegin (TIMER_FREQUENCY);
20+ if (timer == NULL ){
21+ TEST_FAIL_MESSAGE (" Timer init failed in setUp()" );
22+ }
2123 timerStop (timer);
2224 timerRestart (timer);
2325}
2426
2527void tearDown (void ){
2628 timerEnd (timer);
27- timer = NULL ;
2829}
2930
30-
31-
3231void ARDUINO_ISR_ATTR onTimer (){
3332 alarm_flag = true ;
3433}
3534
36-
3735void timer_interrupt_test (void ){
38-
36+
3937 alarm_flag = false ;
4038 timerAttachInterrupt (timer, &onTimer);
4139 timerAlarm (timer, (1.2 * TIMER_FREQUENCY), true , 0 );
@@ -67,9 +65,11 @@ void timer_divider_test(void){
6765
6866 // compare divider 16 and 8, value should be double
6967 timerEnd (timer);
70- timer = NULL ;
7168
7269 timer = timerBegin (2 * TIMER_FREQUENCY);
70+ if (timer == NULL ){
71+ TEST_FAIL_MESSAGE (" Timer init failed!" );
72+ }
7373 timerRestart (timer);
7474 delay (1000 );
7575 comp_time_val = timerRead (timer);
@@ -79,9 +79,11 @@ void timer_divider_test(void){
7979
8080 // divider is 256, value should be 2^4
8181 timerEnd (timer);
82- timer = NULL ;
8382
8483 timer = timerBegin (TIMER_FREQUENCY / 16 );
84+ if (timer == NULL ){
85+ TEST_FAIL_MESSAGE (" Timer init failed!" );
86+ }
8587 timerRestart (timer);
8688 delay (1000 );
8789 comp_time_val = timerRead (timer);
@@ -103,13 +105,10 @@ void timer_read_test(void){
103105
104106void timer_clock_select_test (void ){
105107 // 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);
107109
108- uint32_t resolution = timerGetFrequency (timer_XTAL );
110+ uint32_t resolution = timerGetFrequency (timer );
109111 TEST_ASSERT_EQUAL (TIMER_FREQUENCY_XTAL_CLK,resolution);
110-
111- timerEnd (timer_XTAL);
112- timer_XTAL = NULL ;
113112}
114113
115114void setup (){
@@ -131,4 +130,4 @@ void setup(){
131130}
132131
133132void loop (){
134- }
133+ }
0 commit comments