summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@diac24.net>2012-09-20 05:18:03 +0200
committerDavid Lamparter <equinox@diac24.net>2012-09-20 05:18:52 +0200
commit82e31518b134cfd90eda8c096b971903a97708c0 (patch)
tree482e855d4ef5ab96a426f0d5a293712973ad3460
parent2bae1f8a73bdd5fca71fd3e60807d6b618e675d1 (diff)
lightctrl: 1 second system tick
-rw-r--r--can.c3
-rw-r--r--dali_ctl.c2
-rw-r--r--lightctrl.c4
-rw-r--r--tick.c37
4 files changed, 46 insertions, 0 deletions
diff --git a/can.c b/can.c
index 8e446d1..8969b7c 100644
--- a/can.c
+++ b/can.c
@@ -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);
diff --git a/dali_ctl.c b/dali_ctl.c
index b5eb66b..5db3c09 100644
--- a/dali_ctl.c
+++ b/dali_ctl.c
@@ -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 ");
diff --git a/tick.c b/tick.c
new file mode 100644
index 0000000..87dcbc6
--- /dev/null
+++ b/tick.c
@@ -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);
+}
+