Rose-Hulman Robotics Team

Changeset 236

Show
Ignore:
Timestamp:
10/17/08 01:02:27 (3 years ago)
Author:
auchtemm
Message:

added hdr2buf and buf2hdr functions, changed send_canmsg to use them

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/electronics/avr/can/cannet.c

    r235 r236  
    55 
    66 
    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 */ 
     10static void hdr2buf(canhdr_t *hdr, uint8_t *buf) 
    911{ 
    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); 
    1917} 
    2018 
     19static 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} 
    2127 
    2228 
     
    3036        uint8_t i; 
    3137        uint8_t reg; 
     38        uint8_t hdrbuf[4]; 
    3239 
     40        /* TODO: rewrite this to use load tx buffer */ 
    3341        for (i = TXB0CTRL; i <= TXB0CTRL + 0x20; i += 0x10) { 
    3442                mcp_read(i, &reg, 1); 
    3543                if ((reg & (1 << 3)) == 0) { 
    36                         send_canmsg1(msg, i); 
     44 
     45                        hdr2buf(&msg->hdr, hdrbuf); 
     46                        mcp_write(i + 1, hdrbuf, 4); 
    3747                        reg |= 1 << 3; 
    3848                        mcp_write_byte(i, reg); 
     49                        mcp_write_byte(i + 5, msg->dlc); 
     50                        mcp_write(i + 6, msg->data, msg->dlc); 
    3951                        return 0; 
    4052                } 
     
    4355        return -1; 
    4456} 
     57 
     58/* rxbuf is the address of RXBnCTRL */ 
     59int8_t recv_canmsg(uint8_t rxbuf, canmsg_t *msg) 
     60{ 
     61 
     62 
     63 
     64 
     65        return -1; 
     66}