Skip to content

Commit cbd9eb4

Browse files
committed
feat: added one shot mode support
1 parent f11d8dd commit cbd9eb4

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

raspberrypi/machine_timer.c

+14-10
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,6 @@ typedef struct _machine_timer_obj_t {
2626

2727
static machine_timer_obj_t timer_root;
2828

29-
void __attribute__((interrupt("IRQ"))) irq_timer(void) {
30-
if (IRQ_PEND1 & IRQ_SYSTIMER(SYST_NUM)) {
31-
if (timer_root.callback) {
32-
mp_sched_schedule(timer_root.callback, &timer_root);
33-
}
34-
systimer->C[SYST_NUM] += timer_root.period;
35-
systimer->CS |= (1 << SYST_NUM);
36-
}
37-
}
38-
3929
static void timer_enable(void) {
4030
if ((IRQ_ENABLE1 & IRQ_SYSTIMER(3)) == 0) {
4131
IRQ_ENABLE1 = IRQ_SYSTIMER(3);
@@ -47,6 +37,20 @@ static void timer_disable(void) {
4737
IRQ_DISABLE1 = IRQ_SYSTIMER(3);
4838
}
4939

40+
void __attribute__((interrupt("IRQ"))) irq_timer(void) {
41+
if (IRQ_PEND1 & IRQ_SYSTIMER(SYST_NUM)) {
42+
if (timer_root.callback) {
43+
mp_sched_schedule(timer_root.callback, &timer_root);
44+
}
45+
if (timer_root.mode == PERIODIC) {
46+
systimer->C[SYST_NUM] += timer_root.period;
47+
} else {
48+
timer_disable();
49+
}
50+
systimer->CS |= (1 << SYST_NUM);
51+
}
52+
}
53+
5054
STATIC mp_obj_t machine_timer_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
5155
mp_arg_check_num(n_args, n_kw, 1, 1, false);
5256
// machine_timer_obj_t *tim = m_new_obj(machine_timer_obj_t);

0 commit comments

Comments
 (0)