@@ -64,16 +64,6 @@ STATIC_ASSERT(RTC1_IRQ_PRI == SWI_IRQ_PRI);
6464
6565#define MAX_RTC_TASKS_DELAY 47 /**< Maximum delay until an RTC task is executed. */
6666
67- #if (APP_TIMER_CONFIG_SWI_NUMBER == 0 )
68- #define SWI_IRQn SWI0_IRQn
69- #define SWI_IRQHandler SWI0_IRQHandler
70- #elif (APP_TIMER_CONFIG_SWI_NUMBER == 1 )
71- #define SWI_IRQn SWI1_IRQn
72- #define SWI_IRQHandler SWI1_IRQHandler
73- #else
74- #error "Unsupported SWI number."
75- #endif
76-
7767#define MODULE_INITIALIZED (m_op_queue.size != 0) /**< Macro designating whether the module has been initialized properly. */
7868
7969/**@brief Timer node type. The nodes will be used form a linked list of running timers. */
@@ -151,6 +141,10 @@ static bool m_rtc1_reset;
151141static uint8_t m_max_user_op_queue_utilization ; /**< Maximum observed timer user operations queue utilization. */
152142#endif
153143
144+ /**@brief Function for handling changes to the timer list.
145+ */
146+ static void timer_list_handler (void );
147+
154148/**@brief Function for initializing the RTC1 counter.
155149 *
156150 * @param[in] prescaler Value of the RTC1 PRESCALER register. Set to 0 for no prescaling.
@@ -198,6 +192,25 @@ static void rtc1_stop(void)
198192 m_rtc1_running = false;
199193}
200194
195+ /**@brief Function suspends RTC1 timer.
196+ */
197+ static void rtc1_suspend (void )
198+ {
199+ if (m_rtc1_running == true)
200+ {
201+ NRF_RTC1 -> TASKS_STOP = 1 ;
202+ }
203+ }
204+
205+ /**@brief Function resumes RTC1 timer.
206+ */
207+ static void rtc1_resume (void )
208+ {
209+ if (m_rtc1_running == true)
210+ {
211+ NRF_RTC1 -> TASKS_START = 1 ;
212+ }
213+ }
201214
202215/**@brief Function for returning the current value of the RTC1 counter.
203216 *
@@ -352,14 +365,6 @@ static void timer_timeouts_check_sched(void)
352365 NVIC_SetPendingIRQ (RTC1_IRQn );
353366}
354367
355-
356- /**@brief Function for scheduling a timer list update by generating a SWI interrupt.
357- */
358- static void timer_list_handler_sched (void )
359- {
360- NVIC_SetPendingIRQ (SWI_IRQn );
361- }
362-
363368#if APP_TIMER_CONFIG_USE_SCHEDULER
364369static void timeout_handler_scheduled_exec (void * p_event_data , uint16_t event_size )
365370{
@@ -455,7 +460,7 @@ static void timer_timeouts_check(void)
455460 // Queue the ticks expired.
456461 m_ticks_elapsed [m_ticks_elapsed_q_write_ind ] = ticks_expired ;
457462
458- timer_list_handler_sched ();
463+ timer_list_handler ();
459464 }
460465}
461466
@@ -727,6 +732,8 @@ static void timer_list_handler(void)
727732 bool compare_update = false;
728733 timer_node_t * p_timer_id_head_old ;
729734
735+ rtc1_suspend ();
736+
730737#if APP_TIMER_WITH_PROFILER
731738 {
732739 uint8_t size = m_op_queue .size ;
@@ -768,6 +775,8 @@ static void timer_list_handler(void)
768775 compare_reg_update (p_timer_id_head_old );
769776 }
770777 m_rtc1_reset = false;
778+
779+ rtc1_resume ();
771780}
772781
773782
@@ -850,7 +859,7 @@ static uint32_t timer_start_op_schedule(timer_node_t * p_node,
850859
851860 if (err_code == NRF_SUCCESS )
852861 {
853- timer_list_handler_sched ();
862+ timer_list_handler ();
854863 }
855864
856865 return err_code ;
@@ -888,7 +897,7 @@ static uint32_t timer_stop_op_schedule(timer_node_t * p_node,
888897
889898 if (err_code == NRF_SUCCESS )
890899 {
891- timer_list_handler_sched ();
900+ timer_list_handler ();
892901 }
893902
894903 return err_code ;
@@ -941,10 +950,6 @@ ret_code_t app_timer_init(void)
941950 m_max_user_op_queue_utilization = 0 ;
942951#endif
943952
944- NVIC_ClearPendingIRQ (SWI_IRQn );
945- NVIC_SetPriority (SWI_IRQn , SWI_IRQ_PRI );
946- NVIC_EnableIRQ (SWI_IRQn );
947-
948953 rtc1_init (APP_TIMER_CONFIG_RTC_FREQUENCY );
949954
950955 m_ticks_latest = rtc1_counter_get ();
0 commit comments