@@ -17,9 +17,11 @@ LOG_MODULE_REGISTER(test, 1);
1717
1818#define GRTC_SLEW_TICKS 10
1919#define NUMBER_OF_TRIES 2000
20+ #define NUMBER_OF_INTERVAL_EVENTS 10
2021#define CYC_PER_TICK \
2122 ((uint64_t)sys_clock_hw_cycles_per_sec() / (uint64_t)CONFIG_SYS_CLOCK_TICKS_PER_SEC)
2223#define TIMER_COUNT_TIME_MS 10
24+ #define INTERVAL_COUNT_TIME_MS 50
2325#define WAIT_FOR_TIMER_EVENT_TIME_MS TIMER_COUNT_TIME_MS + 5
2426
2527static volatile uint8_t compare_isr_call_counter ;
@@ -32,6 +34,16 @@ static void timer_compare_interrupt_handler(int32_t id, uint64_t expire_time, vo
3234 TC_PRINT ("Call counter: %d\n" , compare_isr_call_counter );
3335}
3436
37+ /* GRTC timer interval interrupt handler */
38+ static void timer_interval_interrupt_handler (int32_t id , uint64_t expire_time , void * user_data )
39+ {
40+ (void )id ;
41+ (void )expire_time ;
42+ (void )user_data ;
43+
44+ compare_isr_call_counter ++ ;
45+ }
46+
3547ZTEST (nrf_grtc_timer , test_get_ticks )
3648{
3749 k_timeout_t t = K_MSEC (1 );
@@ -161,6 +173,41 @@ ZTEST(nrf_grtc_timer, test_timer_abort_in_compare_mode)
161173 z_nrf_grtc_timer_chan_free (channel );
162174}
163175
176+ ZTEST (nrf_grtc_timer , test_timer_interval_mode )
177+ {
178+ int err ;
179+ uint64_t test_ticks = 0 ;
180+ char user_data [] = "test_timer_interval_mode\n" ;
181+ int32_t channel = z_nrf_grtc_timer_special_chan_alloc ();
182+
183+ if (channel < 0 ) {
184+ if ((NRFX_GRTC_CONFIG_EXTENDED_CC_CHANNELS_MASK &
185+ NRFX_GRTC_CONFIG_ALLOWED_CC_CHANNELS_MASK ) == 0 ) {
186+ ztest_test_pass ();
187+ }
188+ TC_PRINT ("Failed to allocate GRTC channel, chan=%d\n" , channel );
189+ ztest_test_fail ();
190+ }
191+ TC_PRINT ("Allocated GRTC channel %d\n" , channel );
192+
193+ compare_isr_call_counter = 0 ;
194+ test_ticks = INTERVAL_COUNT_TIME_MS * 1000 ;
195+ err = z_nrf_grtc_timer_interval_set (channel , test_ticks , timer_interval_interrupt_handler ,
196+ (void * )user_data );
197+ zassert_equal (err , 0 , "z_nrf_grtc_timer_set raised an error: %d" , err );
198+
199+ k_busy_wait (NUMBER_OF_INTERVAL_EVENTS * test_ticks + test_ticks / 2 );
200+
201+ z_nrf_grtc_timer_interval_stop (channel );
202+ TC_PRINT ("Interval events count: %d\n" , compare_isr_call_counter );
203+ TC_PRINT ("Compare event register address: %X\n" ,
204+ z_nrf_grtc_timer_compare_evt_address_get (channel ));
205+
206+ zassert_equal (compare_isr_call_counter , NUMBER_OF_INTERVAL_EVENTS ,
207+ "Compare isr call counter: %d" , compare_isr_call_counter );
208+ z_nrf_grtc_timer_chan_free (channel );
209+ }
210+
164211enum test_timer_state {
165212 TIMER_IDLE ,
166213 TIMER_PREPARE ,
0 commit comments