Skip to content

Commit 2d30d81

Browse files
committed
trying to fix timers - better, but not perfect
1 parent 198e79d commit 2d30d81

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

targets/nrf5x/jshardware.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,23 +676,29 @@ bool jshSleep(JsSysTime timeUntilWake) {
676676
return true;
677677
}
678678

679+
bool utilTimerActive = false;
680+
679681
/// Reschedule the timer (it should already be running) to interrupt after 'period'
680682
void jshUtilTimerReschedule(JsSysTime period) {
681683
period = period * 1000000 / SYSCLK_FREQ;
682-
if (period < 5) period=5;
684+
if (period < 1) period=1;
683685
if (period > 0xFFFFFFFF) period=0xFFFFFFFF;
686+
if (utilTimerActive) nrf_timer_task_trigger(NRF_TIMER1, NRF_TIMER_TASK_STOP);
684687
nrf_timer_task_trigger(NRF_TIMER1, NRF_TIMER_TASK_CLEAR);
685688
nrf_timer_cc_write(NRF_TIMER1, NRF_TIMER_CC_CHANNEL0, (uint32_t)period);
689+
if (utilTimerActive) nrf_timer_task_trigger(NRF_TIMER1, NRF_TIMER_TASK_START);
686690
}
687691

688692
/// Start the timer and get it to interrupt after 'period'
689693
void jshUtilTimerStart(JsSysTime period) {
690694
jshUtilTimerReschedule(period);
695+
utilTimerActive = true;
691696
nrf_timer_task_trigger(NRF_TIMER1, NRF_TIMER_TASK_START);
692697
}
693698

694699
/// Stop the timer
695700
void jshUtilTimerDisable() {
701+
utilTimerActive = false;
696702
nrf_timer_task_trigger(NRF_TIMER1, NRF_TIMER_TASK_STOP);
697703
}
698704

0 commit comments

Comments
 (0)