Rose-Hulman Robotics Team

Changeset 570 for trunk/electronics/avr

Show
Ignore:
Timestamp:
10/15/09 12:51:15 (2 years ago)
Author:
auchtemm
Message:

added support for extended RTR frames

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

Legend:

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

    r566 r570  
    140140   uint8_t tmp; 
    141141   _setcs(kCSLow); 
     142   CANMSG_ZERO(msg); 
    142143   spi_send(kCmdReadRXBuffer | rxbuf); 
    143  
    144    tmp = spi_recv(); 
     144   tmp = spi_recv(); //RXBnSIDH 
    145145   msg->addr[0] = tmp >> 3; 
    146146   msg->addr[1] = ((tmp & 0x07) << 5); 
    147    tmp = spi_recv(); 
     147   tmp = spi_recv(); // RXBnSIDL 
     148   if (tmp & mRXBSIDL_IDE) 
     149      CANMSG_SET_FLAG(msg, mCANMSG_EX); 
     150   else if (tmp & mRXBSIDL_SRR) 
     151      CANMSG_SET_FLAG(msg, mCANMSG_RTR); 
    148152   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(); 
    158  
    159    msg->dlc = spi_recv() & 0x0F; 
    160  
    161    for (i = 0; i < msg->dlc; i++) 
    162       msg->data[i] = spi_recv(); 
     153   msg->addr[2] = spi_recv(); // RXBnEID8 
     154   msg->addr[3] = spi_recv(); // RXBnEID0 
     155 
     156   tmp = spi_recv(); //DLC 
     157   msg->dlc = tmp & 0x0F; 
     158   if (CANMSG_TST_FLAG(msg, mCANMSG_EX) && (tmp & mRXBDLC_RTR)) 
     159      CANMSG_SET_FLAG(msg, mCANMSG_RTR); 
     160 
     161   // data bytes are meaningless for RTR frames 
     162   if (!CANMSG_TST_FLAG(msg, mCANMSG_RTR)) { 
     163      for (i = 0; i < msg->dlc; i++) 
     164         msg->data[i] = spi_recv(); 
     165   } 
    163166 
    164167   _setcs(kCSHigh); 
     
    168171{ 
    169172   uint8_t i; 
    170    usart_put('T'); 
     173   //usart_put('T'); 
     174   switch (msg->flags & (mCANMSG_EX|mCANMSG_RTR)) { 
     175      case mCANMSG_EX: 
     176         usart_put('T'); break; 
     177      case mCANMSG_EX|mCANMSG_RTR: 
     178         usart_put('R'); break; 
     179   } 
    171180 
    172181   for (i = 0; i < 4; i++) 
    173182      usart_print_hex(msg->addr[i]); 
    174183 
    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  
    180184   usart_print_hex_nibble(msg->dlc); 
    181    for (i = 0; i < (msg->dlc & 0x0F); i++) 
    182       usart_print_hex(msg->data[i]); 
     185 
     186   if (!CANMSG_TST_FLAG(msg, mCANMSG_RTR)) { 
     187      for (i = 0; i < (msg->dlc & 0x0F); i++) 
     188         usart_print_hex(msg->data[i]); 
     189   } 
    183190 
    184191   usart_put('\r'); 
     
    199206   spi_send(msg->addr[3]); 
    200207 
    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  
    207    spi_send(msg->dlc); 
    208  
    209    for (i = 0; i < msg->dlc; i++) 
    210       spi_send(msg->data[i]); 
     208   spi_send(msg->dlc | (CANMSG_TST_FLAG(msg, mCANMSG_RTR) ? mTXBDLC_RTR : 0)); 
     209 
     210   if (!CANMSG_TST_FLAG(msg, mCANMSG_RTR)) { 
     211      for (i = 0; i < msg->dlc; i++) 
     212         spi_send(msg->data[i]); 
     213   } 
    211214 
    212215   _setcs(kCSHigh); 
  • trunk/electronics/avr/can-bridge/mcp.h

    r566 r570  
    7373#define mCANMSG_EX    (1<<0) 
    7474#define mCANMSG_RTR   (1<<1) 
     75 
     76#define mTXBDLC_RTR (1<<6) 
     77 
     78#define mRXBDLC_RTR (1<<6) 
     79#define mRXBSIDL_IDE (1<<3) 
     80#define mRXBSIDL_SRR (1<<4) 
     81 
    7582/* 
    7683typedef struct { 
     
    94101void can_send_message(canmsg_t *msg); 
    95102 
    96 #define CAN_EID_ADDR(_sid, _eid) .sidh = (((_sid) >> 3) & 0xFF), .sidl = (((_sid) & 0x07) << 5) \ 
    97                                      | (((_eid) >> 16) & 0x03), \ 
    98                              .eid8 = (((_eid) >> 8) & 0xFF), .eid0 = ((_eid) & 0xFF), .flags = mCANMSG_EXIDE 
    99  
    100103#define CANMSG_SET_FLAG(msg, flag_mask) (msg)->flags |= (flag_mask) 
    101104#define CANMSG_CLR_FLAG(msg, flag_mask) (msg)->flags &= (flag_mask) 
    102105#define CANMSG_TST_FLAG(msg, flag_mask) ((msg)->flags & (flag_mask)) 
    103  
    104106 
    105107#define CANMSG_ZERO(msg) do { \