Skip to content

Commit 00bd959

Browse files
paul-szczepanek-arm0xc0170
authored andcommitted
use TIMER2 instead
1 parent 5025022 commit 00bd959

File tree

1 file changed

+33
-33
lines changed
  • features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_CORDIO/TARGET_NRF5x/stack/sources

1 file changed

+33
-33
lines changed

features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_CORDIO/TARGET_NRF5x/stack/sources/pal_timer.c

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
* Notes:
2626
*
2727
* 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.
2929
*
30-
* Timer1's compare/capture registers are assigned specific uses:
30+
* TIMER2's compare/capture registers are assigned specific uses:
3131
* CC[0] - Compare value for timer expiry interrupt
3232
* CC[1] - manual capture of current time
3333
*
@@ -84,10 +84,10 @@ uint32_t PalTimerGetCurrentTime(void)
8484

8585
if (palTimerCb.state)
8686
{
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;
8989
/* Read and return the captured count value from capture register 1 */
90-
return NRF_TIMER1->CC[1];
90+
return NRF_TIMER2->CC[1];
9191
}
9292

9393
return 0;
@@ -111,27 +111,27 @@ void PalTimerInit(PalTimerCompCback_t expCback)
111111
PAL_TIMER_CHECK(expCback != NULL);
112112

113113
/* Give scheduler timer the highest priority. */
114-
NVIC_SetPriority(TIMER1_IRQn, 0);
114+
NVIC_SetPriority(TIMER2_IRQn, 0);
115115

116116
/* 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;
118118

119119
/* clear timer to zero count */
120-
NRF_TIMER1->TASKS_CLEAR = 1;
120+
NRF_TIMER2->TASKS_CLEAR = 1;
121121

122122
/* 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) */
126126

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;
129129

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);
135135

136136
palTimerCb.compareVal = 0;
137137
palTimerCb.expCback = expCback;
@@ -148,10 +148,10 @@ void PalTimerInit(PalTimerCompCback_t expCback)
148148
void PalTimerDeInit(void)
149149
{
150150

151-
NVIC_DisableIRQ(TIMER1_IRQn);
151+
NVIC_DisableIRQ(TIMER2_IRQn);
152152

153153
/* stop timer */
154-
NRF_TIMER1->TASKS_STOP = 1;
154+
NRF_TIMER2->TASKS_STOP = 1;
155155

156156
palTimerCb.state = PAL_TIMER_STATE_UNINIT;
157157
}
@@ -186,13 +186,13 @@ void PalTimerStart(uint32_t expTimeUsec)
186186
uint32_t startTimeTick = PalTimerGetCurrentTime() + PAL_TIMER_US_TO_TICKS(expTimeUsec);
187187

188188
/* Clear pending events. */
189-
NRF_TIMER1->EVENTS_COMPARE[0] = 0;
189+
NRF_TIMER2->EVENTS_COMPARE[0] = 0;
190190

191191
/* Set compare value. */
192-
NRF_TIMER1->CC[0] = startTimeTick;
192+
NRF_TIMER2->CC[0] = startTimeTick;
193193

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;
196196

197197
palTimerCb.compareVal = startTimeTick;
198198
palTimerCb.state = PAL_TIMER_STATE_BUSY;
@@ -208,34 +208,34 @@ void PalTimerStart(uint32_t expTimeUsec)
208208
void PalTimerStop()
209209
{
210210
/* Disable this interrupt */
211-
NRF_TIMER1->INTENCLR = TIMER_INTENCLR_COMPARE0_Msk;
211+
NRF_TIMER2->INTENCLR = TIMER_INTENCLR_COMPARE0_Msk;
212212

213213
palTimerCb.state = PAL_TIMER_STATE_READY;
214214
}
215215

216216
/*************************************************************************************************/
217217
/*!
218-
* \brief TIMER1 interrupt handler dedicated to scheduler timer.
218+
* \brief TIMER2 interrupt handler dedicated to scheduler timer.
219219
*
220220
* \return None.
221221
*/
222222
/*************************************************************************************************/
223-
void TIMER1_IRQHandler(void)
223+
void TIMER2_IRQHandler_v(void)
224224
{
225225
#ifdef DEBUG
226226
nrf_gpio_pin_set(PAL_TIMER_DEBUG_0_PIN);
227227
#endif
228228

229229
PAL_TIMER_CHECK(palTimerCb.state == PAL_TIMER_STATE_BUSY);
230230
/* 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);
234234

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;
237237
/* Clear event again just in case. */
238-
NRF_TIMER1->EVENTS_COMPARE[0] = 0;
238+
NRF_TIMER2->EVENTS_COMPARE[0] = 0;
239239

240240
palTimerCb.state = PAL_TIMER_STATE_READY;
241241

0 commit comments

Comments
 (0)