diff options
-rw-r--r-- | dali2.c | 18 | ||||
-rw-r--r-- | lightctrl.c | 24 |
2 files changed, 27 insertions, 15 deletions
@@ -22,7 +22,13 @@ static volatile bool dali_rx_avail; static volatile uint16_t dali_tx; static volatile bool dali_tx_rq; -static uint16_t dalistat_falsestart, dalistat_noise, dalistat_manchester, dalistat_rxok; +struct dalistat { + uint16_t + rxok, + falsestart, + noise, + manchester; +} dalistat; #undef DEBUG @@ -105,7 +111,7 @@ ISR(TIMER0_COMPA_vect) case DALI_RX_SBIT: if (!hist_majority_0()) { - dalistat_falsestart++; + dalistat.falsestart++; dali_state = rx_prevstate_errs; return; } @@ -118,7 +124,7 @@ ISR(TIMER0_COMPA_vect) case DALI_RX_DATA: if (!(hist_majority_1() || hist_majority_0())) { rx_prevstate_errs++; - dalistat_noise++; + dalistat.noise++; bit = 0; } else bit = hist_majority_1(); @@ -126,7 +132,7 @@ ISR(TIMER0_COMPA_vect) if (bitpos & 1) { if (bit == (rx_data & 1)) { rx_prevstate_errs++; - dalistat_manchester++; + dalistat.manchester++; } } else { rx_data <<= 1; @@ -139,7 +145,7 @@ ISR(TIMER0_COMPA_vect) if (!rx_prevstate_errs) { dali_rx = rx_data; dali_rx_avail = 1; - dalistat_rxok++; + dalistat.rxok++; } } break; @@ -257,7 +263,7 @@ static void dali_init(void) dali_tx_rq = 0; dali_rx_avail = 0; - dalistat_falsestart = dalistat_noise = dalistat_manchester = dalistat_rxok = 0; + dalistat.falsestart = dalistat.noise = dalistat.manchester = dalistat.rxok = 0; TIFR0 = (1 << OCF0A); TCNT0 = 0; diff --git a/lightctrl.c b/lightctrl.c index 404ca33..5c70c90 100644 --- a/lightctrl.c +++ b/lightctrl.c @@ -67,7 +67,8 @@ int main(void) dali_search(); - uint8_t ctr = 0; + uint16_t ctr = 0; + while (1) { if (canint) { canint = false; @@ -82,26 +83,31 @@ int main(void) do_tick(); ctr++; - if (ctr % 64 == 0) { + switch (ctr) { + case 2048: + ctr = 0; + break; + case 512: dali_send(0xffa0); if (dali_rx_avail) { uart_puts("ll "); uart_puthex(dali_rx); uart_puts("\n"); - can_send(0xaa800000, 1, (uint8_t *)&dali_rx); + can_send(0xe608047f, 1, (uint8_t *)&dali_rx); } else uart_puts("ll noans\n"); - } + break; + case 1024: + can_send(0xe7000000, 8, (uint8_t *)&dalistat); - if (ctr == 255) { uart_puts("dali stats: "); - uart_puthex16(dalistat_rxok); + uart_puthex16(dalistat.rxok); uart_puts(" ok "); - uart_puthex16(dalistat_falsestart); + uart_puthex16(dalistat.falsestart); uart_puts(" f-start "); - uart_puthex16(dalistat_noise); + uart_puthex16(dalistat.noise); uart_puts(" noise "); - uart_puthex16(dalistat_manchester); + uart_puthex16(dalistat.manchester); uart_puts(" mch-err\n"); } } |