Created
April 22, 2018 15:37
-
-
Save boochow/7b95d2e5e078c3d2baf97d9484ea723b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| typedef enum _timer_mode_t { | |
| ONE_SHOT = 0, | |
| PERIODIC = 1, | |
| } timer_mode_t; | |
| typedef struct _machine_timer_obj_t { | |
| mp_obj_base_t base; | |
| uint32_t id; | |
| uint32_t period; | |
| timer_mode_t mode; | |
| mp_obj_t callback; | |
| } machine_timer_obj_t; | |
| static machine_timer_obj_t timer_root; | |
| #define SYST_NUM (3) | |
| void __attribute__((interrupt("IRQ"))) irq_timer(void) { | |
| if (IRQ_PEND1 & IRQ_SYSTIMER(SYST_NUM)) { | |
| if (timer_root.callback) { | |
| mp_sched_schedule(timer_root.callback, &timer_root); | |
| } | |
| if (timer_root.mode == PERIODIC) { | |
| systimer->C[SYST_NUM] += timer_root.period; | |
| } else { | |
| timer_disable(); | |
| } | |
| systimer->CS |= (1 << SYST_NUM); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment