Changeset 570 for trunk/electronics/avr
- Timestamp:
- 10/15/09 12:51:15 (2 years ago)
- Location:
- trunk/electronics/avr/can-bridge
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/electronics/avr/can-bridge/mcp.c
r566 r570 140 140 uint8_t tmp; 141 141 _setcs(kCSLow); 142 CANMSG_ZERO(msg); 142 143 spi_send(kCmdReadRXBuffer | rxbuf); 143 144 tmp = spi_recv(); 144 tmp = spi_recv(); //RXBnSIDH 145 145 msg->addr[0] = tmp >> 3; 146 146 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); 148 152 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 } 163 166 164 167 _setcs(kCSHigh); … … 168 171 { 169 172 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 } 171 180 172 181 for (i = 0; i < 4; i++) 173 182 usart_print_hex(msg->addr[i]); 174 183 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 180 184 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 } 183 190 184 191 usart_put('\r'); … … 199 206 spi_send(msg->addr[3]); 200 207 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 } 211 214 212 215 _setcs(kCSHigh); -
trunk/electronics/avr/can-bridge/mcp.h
r566 r570 73 73 #define mCANMSG_EX (1<<0) 74 74 #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 75 82 /* 76 83 typedef struct { … … 94 101 void can_send_message(canmsg_t *msg); 95 102 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_EXIDE99 100 103 #define CANMSG_SET_FLAG(msg, flag_mask) (msg)->flags |= (flag_mask) 101 104 #define CANMSG_CLR_FLAG(msg, flag_mask) (msg)->flags &= (flag_mask) 102 105 #define CANMSG_TST_FLAG(msg, flag_mask) ((msg)->flags & (flag_mask)) 103 104 106 105 107 #define CANMSG_ZERO(msg) do { \

