Skip to content

Commit a1af2df

Browse files
austin1611sandeepmistry
authored andcommitted
Fixing millis() and micros() (sandeepmistry#87)
* change a bit shifting operation to reflect the fact the RTC is 24 bits, not 32. * enable the overflow interrupt correctly
1 parent 5103552 commit a1af2df

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

cores/nRF5/delay.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ static volatile uint32_t overflows = 0;
2929

3030
uint32_t millis( void )
3131
{
32-
uint64_t ticks = (uint64_t)((uint64_t)overflows << (uint64_t)32) | (uint64_t)(NRF_RTC1->COUNTER);
32+
uint64_t ticks = (uint64_t)((uint64_t)overflows << (uint64_t)24) | (uint64_t)(NRF_RTC1->COUNTER);
3333

3434
return (ticks * 1000) / 32768;
3535
}
3636

3737
uint32_t micros( void )
3838
{
39-
uint64_t ticks = (uint64_t)((uint64_t)overflows << (uint64_t)32) | (uint64_t)(NRF_RTC1->COUNTER);
39+
uint64_t ticks = (uint64_t)((uint64_t)overflows << (uint64_t)24) | (uint64_t)(NRF_RTC1->COUNTER);
4040

4141
return (ticks * 1000000) / 32768;
4242
}

cores/nRF5/wiring.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ void init( void )
3535
NRF_CLOCK->TASKS_LFCLKSTART = 1UL;
3636

3737
NRF_RTC1->PRESCALER = 0;
38-
NRF_RTC1->EVTENSET = offsetof(NRF_RTC_Type, EVENTS_OVRFLW);
39-
NRF_RTC1->INTENSET = offsetof(NRF_RTC_Type, EVENTS_OVRFLW);
38+
NRF_RTC1->EVTENSET = RTC_INTENSET_OVRFLW_Msk;
39+
NRF_RTC1->INTENSET = RTC_EVTEN_OVRFLW_Msk;
4040
NRF_RTC1->TASKS_START = 1;
4141
}
4242

4343
#ifdef __cplusplus
4444
}
45-
#endif
45+
#endif

0 commit comments

Comments
 (0)