Rose-Hulman Robotics Team

Changeset 566 for trunk/electronics/avr

Show
Ignore:
Timestamp:
10/15/09 03:01:48 (2 years ago)
Author:
auchtemm
Message:

changed the way the ID field works, so instead of mapping directly to the MCP2515, it's a 29-bit value (so eid can be between 0x00000000 and 0x1FFFFFFF)

Location:
trunk/electronics/avr/can-bridge
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/electronics/avr/can-bridge/main.c

    r565 r566  
    4242      READ_DATA, 
    4343      ERROR, 
     44      VALID, 
    4445      END_OF_FRAME, 
    4546      SEND_FRAME, 
     
    6869      case READ_EID: 
    6970         next_state = ERROR; 
    70          if ((tmp = read_ascii_byte()) == -1) break; 
    71          msg.sidh = tmp; 
    72          if ((tmp = read_ascii_byte()) == -1) break; 
    73          msg.sidl = tmp; 
    74          if ((tmp = read_ascii_byte()) == -1) break; 
    75          msg.eid8 = tmp; 
    76          if ((tmp = read_ascii_byte()) == -1) break; 
    77          msg.eid0 = tmp; 
     71         for (int i = 0; i < 4; i++) { 
     72            if ((tmp = read_ascii_byte()) == -1) goto reerror; 
     73            msg.addr[i] = tmp; 
     74         } 
    7875         next_state = READ_DLC; 
    79         break; 
     76reerror: break; 
    8077      case READ_DLC: 
    8178         next_state = ERROR; 
     
    111108         //can_print(&msg); 
    112109         can_send_message(&msg); 
     110         next_state = VALID; 
     111         break; 
     112      case VALID: 
     113         usart_put('Z'); 
     114         usart_put('\r'); 
    113115         next_state = WAIT_TAG; 
    114116         CANMSG_ZERO(&msg); 
  • trunk/electronics/avr/can-bridge/mcp.c

    r564 r566  
    138138{ 
    139139   uint8_t i; 
     140   uint8_t tmp; 
    140141   _setcs(kCSLow); 
    141142   spi_send(kCmdReadRXBuffer | rxbuf); 
    142143 
    143    msg->sidh = spi_recv(); 
    144    msg->sidl = spi_recv(); 
    145    msg->sidl &= ~0x18; 
    146    msg->eid8 = spi_recv(); 
    147    msg->eid0 = spi_recv(); 
     144   tmp = spi_recv(); 
     145   msg->addr[0] = tmp >> 3; 
     146   msg->addr[1] = ((tmp & 0x07) << 5); 
     147   tmp = spi_recv(); 
     148   msg->addr[1] |= ((tmp & 0xE0) >> 3) | (tmp & 0x03); 
     149   msg->addr[2] = spi_recv(); 
     150   msg->addr[3] = spi_recv(); 
     151 
     152    
     153   //msg->sidh = spi_recv(); 
     154   //msg->sidl = spi_recv(); 
     155   //msg->sidl &= ~0x18; 
     156   //msg->eid8 = spi_recv(); 
     157   //msg->eid0 = spi_recv(); 
    148158 
    149159   msg->dlc = spi_recv() & 0x0F; 
     
    159169   uint8_t i; 
    160170   usart_put('T'); 
    161    usart_print_hex(msg->sidh); 
    162    usart_print_hex(msg->sidl); 
    163    usart_print_hex(msg->eid8); 
    164    usart_print_hex(msg->eid0); 
     171 
     172   for (i = 0; i < 4; i++) 
     173      usart_print_hex(msg->addr[i]); 
     174 
     175   //usart_print_hex(msg->sidh); 
     176   //usart_print_hex(msg->sidl); 
     177   //usart_print_hex(msg->eid8); 
     178   //usart_print_hex(msg->eid0); 
     179 
    165180   usart_print_hex_nibble(msg->dlc); 
    166181   for (i = 0; i < (msg->dlc & 0x0F); i++) 
     
    178193   spi_send(kCmdLoadTXBuffer | txbuf); 
    179194 
    180    spi_send(msg->sidh); 
    181    spi_send(msg->sidl | ((msg->flags & mCANMSG_EX) ? 0x08 : 0x00)); 
    182    spi_send(msg->eid8); 
    183    spi_send(msg->eid0); 
     195   spi_send((msg->addr[0] << 3) | (msg->addr[1] >> 5)); 
     196   spi_send( ((msg->addr[1] & 0x1C) << 3) | (msg->addr[1] & 0x03) 
     197         | ((msg->flags & mCANMSG_EX) ? 0x08 : 0x00)); 
     198   spi_send(msg->addr[2]); 
     199   spi_send(msg->addr[3]); 
     200 
     201 
     202   //spi_send(msg->sidh); 
     203   //spi_send(msg->sidl | ((msg->flags & mCANMSG_EX) ? 0x08 : 0x00)); 
     204   //spi_send(msg->eid8); 
     205   //spi_send(msg->eid0); 
     206 
    184207   spi_send(msg->dlc); 
    185208 
  • trunk/electronics/avr/can-bridge/mcp.h

    r564 r566  
    8585 
    8686typedef struct { 
    87    uint8_t sidh; 
    88    uint8_t sidl; 
    89    uint8_t eid8; 
    90    uint8_t eid0; 
     87   uint8_t addr[4]; 
    9188   uint8_t dlc; 
    9289   uint8_t data[8]; 
     
    107104 
    108105#define CANMSG_ZERO(msg) do { \ 
    109    (msg)->sidh = 0;    \ 
    110    (msg)->sidl = 0;    \ 
    111    (msg)->eid8 = 0;    \ 
    112    (msg)->eid0 = 0;    \ 
    113106   (msg)->dlc = 0;     \ 
    114107   (msg)->data[0] = 0; \ 
     
    120113   (msg)->data[6] = 0; \ 
    121114   (msg)->data[7] = 0; \ 
     115   (msg)->addr[0] = 0; \ 
     116   (msg)->addr[1] = 0; \ 
     117   (msg)->addr[2] = 0; \ 
     118   (msg)->addr[3] = 0; \ 
    122119   (msg)->flags = 0; \ 
    123120} while (0);