summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@diac24.net>2012-06-20 14:22:16 +0200
committerDavid Lamparter <equinox@diac24.net>2012-06-20 14:22:16 +0200
commit0c7bebea1bd05a95d2bb3e04ecb2e44792d6f174 (patch)
tree021c0ffc52f7d9cf710975b8da37d338dfa8c9c7
parentd58959c353f8e70b4b057ce8ba2907b52f6d28b7 (diff)
light: CAN RX
-rw-r--r--can.c24
-rw-r--r--lightctrl.c26
2 files changed, 42 insertions, 8 deletions
diff --git a/can.c b/can.c
index 706fdb3..16b66a0 100644
--- a/can.c
+++ b/can.c
@@ -135,10 +135,15 @@ static void can_send(uint32_t daddr, uint8_t len, uint8_t *data)
}
#ifndef R0KET
+union {
+ uint8_t b[4];
+ uint32_t u;
+} can_rx_addr;
+uint8_t can_rx_dlc, can_rx_data[8];
+
static void can_rxh(uint8_t buffer)
{
- uint8_t dlc, c, rtr;
- uint32_t addr;
+ uint8_t c, byte;
if (buffer)
uart_puts("can: RX1IF\n");
@@ -146,17 +151,20 @@ static void can_rxh(uint8_t buffer)
uart_puts("can: RX0IF\n");
spi_ss(0);
spi_wrrd(0x90 + 0x04 * buffer);
- addr = 0;
-#define rdaddr() c = spi_wrrd(0xff); uart_puthex(c); addr <<= 8; addr |= c
+ c = 0;
+#define rdaddr() byte = spi_wrrd(0xff); uart_puthex(byte); can_rx_addr.b[c++] = byte
rdaddr();
rdaddr();
rdaddr();
rdaddr();
- dlc = spi_wrrd(0xff);
- uart_puthex(dlc);
+ can_rx_dlc = spi_wrrd(0xff);
+ uart_puthex(can_rx_dlc);
uart_puts("\n");
- for (c = 0; c < (dlc & 0x0f); c++)
- uart_puthex(spi_wrrd(0xff));
+ for (c = 0; c < (can_rx_dlc & 0x0f); c++) {
+ byte = spi_wrrd(0xff);
+ can_rx_data[c] = byte;
+ uart_puthex(byte);
+ }
uart_puts("\n");
spi_ss(1);
}
diff --git a/lightctrl.c b/lightctrl.c
index 464a0ae..404ca33 100644
--- a/lightctrl.c
+++ b/lightctrl.c
@@ -27,6 +27,27 @@ const uint8_t __signature[3] __attribute__((section (".signature"), used)) =
#include "dim.c"
#include "can.c"
+static void can_rx_exec(void)
+{
+ if (can_rx_addr.b[0] == 0xcc
+ && (can_rx_addr.b[1] & 0xfb) == 0x08
+ && can_rx_addr.b[2] == 0x04
+ && can_rx_addr.b[3] == 0x7f
+ && (can_rx_dlc & 0x4f) == 1) {
+ uart_puts("-- SET\n");
+
+ if (!can_rx_data[0]) {
+ dim_state = 0;
+ dali_send(DALI_ADDR | 0x100);
+ } else {
+ if (!dim_state && can_rx_data[0])
+ dali_send(DALI_ADDR | 0x108);
+ dim_state = can_rx_data[0];
+ dali_send(DALI_ADDR | dim_state);
+ }
+ }
+}
+
int main(void)
{
DDRD |= (1 << D_LED1) | (1 << D_LED2 ) | (1 << D_TXD) | (1 << D_DALIO);
@@ -51,6 +72,11 @@ int main(void)
if (canint) {
canint = false;
can_int();
+
+ if (can_rx_addr.b[0]) {
+ can_rx_exec();
+ can_rx_addr.u = 0;
+ }
}
_delay_ms(5);
do_tick();