Changeset 236
- Timestamp:
- 10/17/08 01:02:27 (3 years ago)
- Files:
-
- 1 modified
-
trunk/electronics/avr/can/cannet.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/electronics/avr/can/cannet.c
r235 r236 5 5 6 6 7 /* txbuf is the address of TXBnCTRL */ 8 static void send_canmsg1(canmsg_t *msg, uint8_t txbuf) 7 /* Maps canhdr_t to SIDH, SIDL, EID8 and EID0 8 * buf must be large enough to hold 4 bytes 9 */ 10 static void hdr2buf(canhdr_t *hdr, uint8_t *buf) 9 11 { 10 /* I'm on my 4th espresso in the past half hour, the following 11 * is likely riddled with errors. 12 */ 13 mcp_write_byte(txbuf + 1, (msg->hdr.pri << 5) | (msg->hdr.class >> 3)); 14 mcp_write_byte(txbuf + 2, (msg->hdr.class << 5) | (msg->hdr.dst >> 6) | (1 << 3)); 15 mcp_write_byte(txbuf + 3, (msg->hdr.dst << 2) | ((msg->hdr.src >> 6) & 0x03)); 16 mcp_write_byte(txbuf + 4, (msg->hdr.src << 3) | (msg->hdr.cmd & 0x07)); 17 mcp_write_byte(txbuf + 5, msg->dlc); 18 mcp_write(txbuf + 6, msg->data, msg->dlc); 12 buf[0] = (hdr->pri << 5) | (hdr->class >> 3); 13 /* SIDL is a tricky bastard: 0bxxx0x0xx */ 14 buf[1] = (hdr->class << 5) | (hdr->dst >> 6) | (1 << 3); 15 buf[2] = (hdr->dst << 2) | ((hdr->src >> 5) & 0x03); 16 buf[3] = (hdr->src << 3) | (hdr->cmd & 0x07); 19 17 } 20 18 19 static void buf2hdr(uint8_t *buf, canhdr_t *hdr) 20 { 21 hdr->pri = buf[0] >> 5; 22 hdr->class = (buf[0] << 3) | (buf[1] >> 5); 23 hdr->dst = (buf[1] << 6) | (buf[2] >> 2); 24 hdr->src = ((buf[2] & 0x03) << 5) | (buf[3] >> 3); 25 hdr->cmd = buf[3] & 0x07; 26 } 21 27 22 28 … … 30 36 uint8_t i; 31 37 uint8_t reg; 38 uint8_t hdrbuf[4]; 32 39 40 /* TODO: rewrite this to use load tx buffer */ 33 41 for (i = TXB0CTRL; i <= TXB0CTRL + 0x20; i += 0x10) { 34 42 mcp_read(i, ®, 1); 35 43 if ((reg & (1 << 3)) == 0) { 36 send_canmsg1(msg, i); 44 45 hdr2buf(&msg->hdr, hdrbuf); 46 mcp_write(i + 1, hdrbuf, 4); 37 47 reg |= 1 << 3; 38 48 mcp_write_byte(i, reg); 49 mcp_write_byte(i + 5, msg->dlc); 50 mcp_write(i + 6, msg->data, msg->dlc); 39 51 return 0; 40 52 } … … 43 55 return -1; 44 56 } 57 58 /* rxbuf is the address of RXBnCTRL */ 59 int8_t recv_canmsg(uint8_t rxbuf, canmsg_t *msg) 60 { 61 62 63 64 65 return -1; 66 }

