diff options
author | Sven Wegener <sven.wegener@stealer.net> | 2016-01-02 23:25:09 +0100 |
---|---|---|
committer | Sven Wegener <sven.wegener@stealer.net> | 2016-01-21 22:46:34 +0100 |
commit | 38606813f222e60e35b02119ae70cd517e10debb (patch) | |
tree | c8d014393634d331f1a004da6fcf5520dce0bd11 | |
parent | 21c9312a68a51d7eea892fa552ddb3c3f5a4a4ea (diff) |
Implement main timerinterrupts
Signed-off-by: Sven Wegener <sven.wegener@stealer.net>
-rw-r--r-- | stm8/main.c | 31 | ||||
-rw-r--r-- | stm8/stm8s.h | 8 |
2 files changed, 32 insertions, 7 deletions
diff --git a/stm8/main.c b/stm8/main.c index ec9325d..cf8af5c 100644 --- a/stm8/main.c +++ b/stm8/main.c @@ -552,6 +552,26 @@ void ensure_afr0_set(void) } } +void tick_init(void) +{ + TIM4_PSCR = 0x04; + TIM4_IER |= TIM_IER_UIE; + TIM4_CR1 |= 1; +} + +void tim4_isr(void) __interrupt(TIM4_IRQ) +{ + TIM4_SR &= ~1; + TIM4_CR1 &= ~1; + rim(); + display_refresh(); + read_state(); + if (read_newline) { + process_input(); + } + TIM4_CR1 |= 1; +} + int main() { unsigned long i = 0; @@ -561,6 +581,7 @@ int main() uart_init(); pwm_init(); adc_init(); + tick_init(); config_load(); @@ -575,12 +596,8 @@ int main() adc_start(4); commit_output(); - do { + while (1) { iwatchdog_tick(); - read_state(); - display_refresh(); - if (read_newline) { - process_input(); - } - } while(1); + wfi(); + } } diff --git a/stm8/stm8s.h b/stm8/stm8s.h index 8e95300..2f727d1 100644 --- a/stm8/stm8s.h +++ b/stm8/stm8s.h @@ -163,6 +163,14 @@ #define TIM2_CCR3H *(unsigned char*)0x5315 #define TIM2_CCR3L *(unsigned char*)0x5316 +#define TIM4_CR1 *(unsigned char*)0x005340 +#define TIM4_IER *(unsigned char*)0x005343 +#define TIM4_SR *(unsigned char*)0x005344 +#define TIM4_PSCR *(unsigned char*)0x005347 +#define TIM4_ARR *(unsigned char*)0x005348 + +#define TIM4_IRQ 23 + /* TIM_IER bits */ #define TIM_IER_BIE (1 << 7) #define TIM_IER_TIE (1 << 6) |