summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@diac24.net>2012-05-19 05:51:26 +0200
committerDavid Lamparter <equinox@diac24.net>2012-05-19 05:51:26 +0200
commitf1b8dfc0087d545140984f028a52585d384ad878 (patch)
tree6f5e216057ecd62336080e03f54cdb5052052eab
parent5eabc7da65b07e5915e19c31112754eabf76853c (diff)
can: extend (send + r0ket)
-rw-r--r--can.c95
-rw-r--r--lightctrl.c1
2 files changed, 70 insertions, 26 deletions
diff --git a/can.c b/can.c
index c764d9b..b5c328d 100644
--- a/can.c
+++ b/can.c
@@ -1,3 +1,15 @@
+ /* addrs: SSSEEEEE
+ * 8 -> extended addr
+ * 14 -> unused
+ */
+#define CANA_TIME 0x10080000
+#define CANA_DISCOVERY 0x4c080000
+#define CANA_LIGHT 0xcc080000
+#define CANA_LIGHT_F(src,dst) (CANA_LIGHT | (((src) << 12) & 0x3f) | ((dst) & 0xfff))
+#define CANA_SENSOR 0xe6080000
+#define CANA_SENSOR_F(src) (CANA_SENSOR | ((src) & 0xfff))
+
+#ifndef R0KET
#define spi_ss(x) PORTB = ((x) << B_SS) | 0x3;
static volatile bool canint = false;
@@ -29,6 +41,7 @@ static void spi_performpgm(const uint8_t * PROGMEM cmds, uint8_t len)
}
spi_ss(1);
}
+#endif
#define spi_perform(...) do { \
static const uint8_t _mycmds[] PROGMEM = { __VA_ARGS__ }; \
spi_performpgm(_mycmds, sizeof(_mycmds)); } while (0)
@@ -51,6 +64,11 @@ static void spi_performpgm(const uint8_t * PROGMEM cmds, uint8_t len)
#define MCP2515_WRITE 0x02
#define MCP2515_READ 0x03
#define MCP2515_RTS 0x80
+#define MCP2515_WRTXB 0x40
+#define MCP2515_WRTXB_DATA 0x01
+#define MCP2515_WRTXB_TXB0 0x00
+#define MCP2515_WRTXB_TXB1 0x02
+#define MCP2515_WRTXB_TXB2 0x04
#define A_CNF3 0x28
#define A_CANINTF 0x2c
@@ -66,8 +84,12 @@ static void can_init(void)
spi_perform(MCP2515_WRITE, A_CNF3,
0x01, /* CNF3 */
0x81, /* CNF2 */
+#ifdef R0KET
+ 0x05,
+#else
0x0b, /* CNF1 */
- 0xa4 /* CANINTE: MERRE, ERRIE, TX0IE */
+#endif
+ 0xa7 /* CANINTE: MERRE, ERRIE, TX0IE, RX1IE, RX0IE */
);
spi_perform(MCP2515_WRITE, A_RXB1CTRL,
0x60); /* x, RXM, x, RXRTR, FILHIT */
@@ -90,18 +112,50 @@ static uint8_t can_CANSTAT(void)
return canstat;
}
-static void can_send(void)
+/* daddr:
+ * 31-24 ID 10:3
+ * 23-16 ID 2:0, x, EXIDE, x, EID17:16
+ * 15- 8 EID 15:8
+ * 7- 0 EID 7:0
+ */
+static void can_send(uint32_t daddr, uint8_t len, uint8_t *data)
{
uart_puts("can: transmit\n");
- spi_perform(MCP2515_WRITE, A_TXB0SIDH,
- 0x55, /* ID 10:3 */
- 0x40, /* ID 2:0, x, EXIDE, x, EID 17:16 */
- 0x00, /* EID 15:8 */
- 0x00, /* EID 7:0 */
- 0x00); /* x, RTR, xx, DLC */
+ spi_ss(0);
+ spi_wrrd(MCP2515_WRTXB | MCP2515_WRTXB_TXB0);
+ spi_wrrd((daddr >> 24) & 0xff);
+ spi_wrrd((daddr >> 16) & 0xff);
+ spi_wrrd((daddr >> 8) & 0xff);
+ spi_wrrd((daddr >> 0) & 0xff);
+ spi_wrrd(len);
+ while (len--)
+ spi_wrrd(*data++);
+ spi_ss(1);
spi_perform(MCP2515_RTS | 0x01);
}
+static void can_rxh(uint8_t buffer)
+{
+ uint8_t dlc, c;
+ if (buffer)
+ uart_puts("can: RX1IF\n");
+ else
+ uart_puts("can: RX0IF\n");
+ spi_ss(0);
+ spi_wrrd(0x90 + 0x04 * buffer);
+ uart_puthex(spi_wrrd(0xff));
+ uart_puthex(spi_wrrd(0xff));
+ uart_puthex(spi_wrrd(0xff));
+ uart_puthex(spi_wrrd(0xff));
+ dlc = spi_wrrd(0xff);
+ uart_puthex(dlc);
+ uart_puts("\n");
+ for (c = 0; c < (dlc & 0x0f); c++)
+ uart_puthex(spi_wrrd(0xff));
+ uart_puts("\n");
+ spi_ss(1);
+}
+
static void can_int(void)
{
uint8_t canintf, eflg, canstat;
@@ -132,30 +186,18 @@ static void can_int(void)
uart_puthex(txb0ctrl);
uart_puts("\n");
}
- if (canintf & 0x02) {
- uint8_t rxb1dlc, c;
- uart_puts("can: RX1IF\n");
- spi_ss(0);
- spi_wrrd(0x94);
- uart_puthex(spi_wrrd(0xff));
- uart_puthex(spi_wrrd(0xff));
- uart_puthex(spi_wrrd(0xff));
- uart_puthex(spi_wrrd(0xff));
- rxb1dlc = spi_wrrd(0xff);
- uart_puthex(rxb1dlc);
- uart_puts("\n");
- for (c = 0; c < rxb1dlc; c++)
- uart_puthex(spi_wrrd(0xff));
- uart_puts("\n");
- spi_ss(1);
- }
+ if (canintf & 0x01)
+ can_rxh(0);
+ if (canintf & 0x02)
+ can_rxh(1);
- spi_perform(MCP2515_WRITE, A_CANINTF, 0x00);
+ spi_perform(MCP2515_WRITE, A_CANINTF, 0x00, 0x00);
}
static void can_preinit(void)
{
spi_ss(1);
+#ifndef R0KET
DDRB = (1 << B_SCK) | (1 << B_MOSI) | (1 << B_SS);
/* divisor: 0 0 0 = fosc / 4 = 2 MHz */
@@ -166,6 +208,7 @@ static void can_preinit(void)
EIMSK = (1 << INT0);
_delay_ms(5);
+#endif
/* chip reset */
spi_ss(0);
diff --git a/lightctrl.c b/lightctrl.c
index c36f035..464a0ae 100644
--- a/lightctrl.c
+++ b/lightctrl.c
@@ -62,6 +62,7 @@ int main(void)
uart_puts("ll ");
uart_puthex(dali_rx);
uart_puts("\n");
+ can_send(0xaa800000, 1, (uint8_t *)&dali_rx);
} else
uart_puts("ll noans\n");
}