25
25
* Notes:
26
26
*
27
27
* This is timer driver dedicated to scheduler, an interrupt will be triggered to do scheduler task
28
- * when timer hits compare value. Timer1 is used here.
28
+ * when timer hits compare value. TIMER2 is used here.
29
29
*
30
- * Timer1 's compare/capture registers are assigned specific uses:
30
+ * TIMER2 's compare/capture registers are assigned specific uses:
31
31
* CC[0] - Compare value for timer expiry interrupt
32
32
* CC[1] - manual capture of current time
33
33
*
@@ -84,10 +84,10 @@ uint32_t PalTimerGetCurrentTime(void)
84
84
85
85
if (palTimerCb .state )
86
86
{
87
- /* Capture current TIMER1 count to capture register 1 */
88
- NRF_TIMER1 -> TASKS_CAPTURE [1 ] = 1 ;
87
+ /* Capture current TIMER2 count to capture register 1 */
88
+ NRF_TIMER2 -> TASKS_CAPTURE [1 ] = 1 ;
89
89
/* Read and return the captured count value from capture register 1 */
90
- return NRF_TIMER1 -> CC [1 ];
90
+ return NRF_TIMER2 -> CC [1 ];
91
91
}
92
92
93
93
return 0 ;
@@ -111,27 +111,27 @@ void PalTimerInit(PalTimerCompCback_t expCback)
111
111
PAL_TIMER_CHECK (expCback != NULL );
112
112
113
113
/* Give scheduler timer the highest priority. */
114
- NVIC_SetPriority (TIMER1_IRQn , 0 );
114
+ NVIC_SetPriority (TIMER2_IRQn , 0 );
115
115
116
116
/* stop timer if it was somehow running (timer must be stopped for configuration) */
117
- NRF_TIMER1 -> TASKS_STOP = 1 ;
117
+ NRF_TIMER2 -> TASKS_STOP = 1 ;
118
118
119
119
/* clear timer to zero count */
120
- NRF_TIMER1 -> TASKS_CLEAR = 1 ;
120
+ NRF_TIMER2 -> TASKS_CLEAR = 1 ;
121
121
122
122
/* configure timer */
123
- NRF_TIMER1 -> MODE = TIMER_MODE_MODE_Timer ;
124
- NRF_TIMER1 -> BITMODE = TIMER_BITMODE_BITMODE_32Bit ;
125
- NRF_TIMER1 -> PRESCALER = PAL_TIMER_1MHZ_PRESCALER ; /* f = 16MHz / (2 ^ TIMER_PRESCALER) */
123
+ NRF_TIMER2 -> MODE = TIMER_MODE_MODE_Timer ;
124
+ NRF_TIMER2 -> BITMODE = TIMER_BITMODE_BITMODE_32Bit ;
125
+ NRF_TIMER2 -> PRESCALER = PAL_TIMER_1MHZ_PRESCALER ; /* f = 16MHz / (2 ^ TIMER_PRESCALER) */
126
126
127
- /* timer1 is a free running clock. */
128
- NRF_TIMER1 -> TASKS_START = 1 ;
127
+ /* TIMER2 is a free running clock. */
128
+ NRF_TIMER2 -> TASKS_START = 1 ;
129
129
130
- /* Clear out and enable timer1 interrupt at system level. */
131
- NRF_TIMER1 -> INTENCLR = 0xFFFFFFFF ;
132
- NRF_TIMER1 -> EVENTS_COMPARE [0 ] = 0 ;
133
- NVIC_ClearPendingIRQ (TIMER1_IRQn );
134
- NVIC_EnableIRQ (TIMER1_IRQn );
130
+ /* Clear out and enable TIMER2 interrupt at system level. */
131
+ NRF_TIMER2 -> INTENCLR = 0xFFFFFFFF ;
132
+ NRF_TIMER2 -> EVENTS_COMPARE [0 ] = 0 ;
133
+ NVIC_ClearPendingIRQ (TIMER2_IRQn );
134
+ NVIC_EnableIRQ (TIMER2_IRQn );
135
135
136
136
palTimerCb .compareVal = 0 ;
137
137
palTimerCb .expCback = expCback ;
@@ -148,10 +148,10 @@ void PalTimerInit(PalTimerCompCback_t expCback)
148
148
void PalTimerDeInit (void )
149
149
{
150
150
151
- NVIC_DisableIRQ (TIMER1_IRQn );
151
+ NVIC_DisableIRQ (TIMER2_IRQn );
152
152
153
153
/* stop timer */
154
- NRF_TIMER1 -> TASKS_STOP = 1 ;
154
+ NRF_TIMER2 -> TASKS_STOP = 1 ;
155
155
156
156
palTimerCb .state = PAL_TIMER_STATE_UNINIT ;
157
157
}
@@ -186,13 +186,13 @@ void PalTimerStart(uint32_t expTimeUsec)
186
186
uint32_t startTimeTick = PalTimerGetCurrentTime () + PAL_TIMER_US_TO_TICKS (expTimeUsec );
187
187
188
188
/* Clear pending events. */
189
- NRF_TIMER1 -> EVENTS_COMPARE [0 ] = 0 ;
189
+ NRF_TIMER2 -> EVENTS_COMPARE [0 ] = 0 ;
190
190
191
191
/* Set compare value. */
192
- NRF_TIMER1 -> CC [0 ] = startTimeTick ;
192
+ NRF_TIMER2 -> CC [0 ] = startTimeTick ;
193
193
194
- /* Enable timer1 interrupt source for CC[0]. */
195
- NRF_TIMER1 -> INTENSET = TIMER_INTENSET_COMPARE0_Msk ;
194
+ /* Enable TIMER2 interrupt source for CC[0]. */
195
+ NRF_TIMER2 -> INTENSET = TIMER_INTENSET_COMPARE0_Msk ;
196
196
197
197
palTimerCb .compareVal = startTimeTick ;
198
198
palTimerCb .state = PAL_TIMER_STATE_BUSY ;
@@ -208,34 +208,34 @@ void PalTimerStart(uint32_t expTimeUsec)
208
208
void PalTimerStop ()
209
209
{
210
210
/* Disable this interrupt */
211
- NRF_TIMER1 -> INTENCLR = TIMER_INTENCLR_COMPARE0_Msk ;
211
+ NRF_TIMER2 -> INTENCLR = TIMER_INTENCLR_COMPARE0_Msk ;
212
212
213
213
palTimerCb .state = PAL_TIMER_STATE_READY ;
214
214
}
215
215
216
216
/*************************************************************************************************/
217
217
/*!
218
- * \brief TIMER1 interrupt handler dedicated to scheduler timer.
218
+ * \brief TIMER2 interrupt handler dedicated to scheduler timer.
219
219
*
220
220
* \return None.
221
221
*/
222
222
/*************************************************************************************************/
223
- void TIMER1_IRQHandler (void )
223
+ void TIMER2_IRQHandler_v (void )
224
224
{
225
225
#ifdef DEBUG
226
226
nrf_gpio_pin_set (PAL_TIMER_DEBUG_0_PIN );
227
227
#endif
228
228
229
229
PAL_TIMER_CHECK (palTimerCb .state == PAL_TIMER_STATE_BUSY );
230
230
/* Check hardware status */
231
- PAL_TIMER_CHECK (NRF_TIMER1 -> EVENTS_COMPARE [0 ]);
232
- PAL_TIMER_CHECK (NRF_TIMER1 -> CC [0 ] == palTimerCb .compareVal );
233
- PAL_TIMER_CHECK (NRF_TIMER1 -> INTENSET == TIMER_INTENSET_COMPARE0_Msk );
231
+ PAL_TIMER_CHECK (NRF_TIMER2 -> EVENTS_COMPARE [0 ]);
232
+ PAL_TIMER_CHECK (NRF_TIMER2 -> CC [0 ] == palTimerCb .compareVal );
233
+ PAL_TIMER_CHECK (NRF_TIMER2 -> INTENSET == TIMER_INTENSET_COMPARE0_Msk );
234
234
235
- /* Callback function could restart timer1 . However, we blindly stop timer1 first. */
236
- NRF_TIMER1 -> INTENCLR = TIMER_INTENCLR_COMPARE0_Msk ;
235
+ /* Callback function could restart TIMER2 . However, we blindly stop TIMER2 first. */
236
+ NRF_TIMER2 -> INTENCLR = TIMER_INTENCLR_COMPARE0_Msk ;
237
237
/* Clear event again just in case. */
238
- NRF_TIMER1 -> EVENTS_COMPARE [0 ] = 0 ;
238
+ NRF_TIMER2 -> EVENTS_COMPARE [0 ] = 0 ;
239
239
240
240
palTimerCb .state = PAL_TIMER_STATE_READY ;
241
241
0 commit comments