diff options
author | David Lamparter <equinox@diac24.net> | 2012-09-20 05:18:03 +0200 |
---|---|---|
committer | David Lamparter <equinox@diac24.net> | 2012-09-20 05:18:52 +0200 |
commit | 82e31518b134cfd90eda8c096b971903a97708c0 (patch) | |
tree | 482e855d4ef5ab96a426f0d5a293712973ad3460 | |
parent | 2bae1f8a73bdd5fca71fd3e60807d6b618e675d1 (diff) |
lightctrl: 1 second system tick
-rw-r--r-- | can.c | 3 | ||||
-rw-r--r-- | dali_ctl.c | 2 | ||||
-rw-r--r-- | lightctrl.c | 4 | ||||
-rw-r--r-- | tick.c | 37 |
4 files changed, 46 insertions, 0 deletions
@@ -172,6 +172,9 @@ static void can_int(void) { uint8_t canintf, eflg, canstat; +#ifdef HAVE_TICK + uart_puttick(); +#endif uart_puts("can: irqh<"); spi_ss(0); @@ -96,6 +96,7 @@ static void dali_search(void) if (!dali_s_notfound) { wdt_reset(); + uart_puttick(); uart_puts("dali scan found\t\t"); uart_puthex(dali_sh); uart_puthex(dali_sm); @@ -143,6 +144,7 @@ static void dali_search(void) wdt_reset(); dali_twice(DALI_C_TERMINATE); + uart_puttick(); uart_puts("dali scan end\n"); eeprom_write_byte(&dali_nextaddr, dali_assign); diff --git a/lightctrl.c b/lightctrl.c index 659ac26..0a46805 100644 --- a/lightctrl.c +++ b/lightctrl.c @@ -24,6 +24,7 @@ const uint8_t __signature[3] __attribute__((section (".signature"), used)) = #define D_TAST 7 #include "uart.c" +#include "tick.c" #include "dali2.c" #include "dali_ctl.c" #include "dim.c" @@ -74,6 +75,7 @@ int main(void) PORTD &= ~(1 << D_LED1); uart_init(); + tick_init(); can_preinit(); dali_init(); dim_init(); @@ -138,6 +140,7 @@ int main(void) uint8_t buffer[8] = {0, 0, 0, 0, 0, 0, 0, 0}; uint8_t base = (ctr << 1) & 070, map = dali_map[(ctr >> 2) & 7], dlc = 0; + uart_puttick(); uart_puts("ll"); uart_puthex(base); uart_puts("> "); @@ -161,6 +164,7 @@ int main(void) case 1024: can_send(0xe7000000, 8, (uint8_t *)&dalistat); + uart_puttick(); uart_puts("dali stats: "); uart_puthex16(dalistat.rxok); uart_puts(" ok "); @@ -0,0 +1,37 @@ +#define HAVE_TICK + +static union { + uint32_t u32; + uint8_t u8[4]; +} systick = { .u32 = 0 }; + +ISR(TIMER1_COMPA_vect) +{ + systick.u32++; +} + +static void uart_puttick(void) +{ + uint16_t frac = TCNT1; + _uart_putch('@'); + uart_puthex(systick.u8[3]); + uart_puthex(systick.u8[2]); + uart_puthex(systick.u8[1]); + uart_puthex(systick.u8[0]); + _uart_putch('.'); + uart_puthex16(frac); + _uart_putch(' '); +} + +static void tick_init(void) +{ + TCCR1A = 0; + TCCR1B = (1 << WGM12) | (1 << CS12) | (0 << CS11) | (0 << CS10); // 8 MHz / 256 = 31250 Hz + asm volatile ("" ::: "memory"); + TCNT1 = 0; + OCR1A = 31249; // 1 Hz + asm volatile ("" ::: "memory"); + TIFR1 = (1 << OCF1A); + TIMSK1 = (1 << OCIE1A); +} + |