Rev 56 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 56 | Rev 64 | ||
|---|---|---|---|
| Line 148... | Line 148... | ||
| 148 | * Affects: Calls canParse() function in main for parsing received packet. |
148 | * Affects: Calls canParse() function in main for parsing received packet. |
| 149 | * Depends: none. |
149 | * Depends: none. |
| 150 | */ |
150 | */ |
| 151 | void canGetPacket() |
151 | void canGetPacket() |
| 152 | { |
152 | { |
| 153 | CAN_MESSAGE cm; |
- | |
| 154 | 153 | ||
| 155 |
|
154 | CAN_PROTO_MESSAGE cm; |
| 156 | cm.extended=(RXB0SIDLbits.EXID==0?FALSE:TRUE); |
- | |
| 157 | 155 | ||
| - | 156 | //RXB0SIDH 28 27 26 25 24 23 22 21 |
|
| - | 157 | //RXB0SIDL 20 19 18 xx xx xx 17 16 |
|
| - | 158 | //RXB0EIDH 15 14 13 12 11 10 09 08 |
|
| - | 159 | //RXB0EIDL 07 06 05 04 03 02 01 00 |
|
| - | 160 | ||
| 158 | // |
161 | //funct xx xx xx xx 28 27 26 25 |
| - | 162 | //funcc xx xx xx xx xx xx 24 23 22 21 20 19 18 17 16 15 |
|
| - | 163 | //nid xx xx 14 13 12 11 10 09 |
|
| - | 164 | //sid xx xx xx xx xx xx xx 08 07 06 05 04 03 02 01 00 |
|
| - | 165 | ||
| - | 166 | ||
| - | 167 | cm.funct=((RXB0SIDH & 0xF0)>>4); |
|
| - | 168 | cm.funcc=(((WORD)(RXB0SIDH & 0x0F))<<6)+(((WORD)(RXB0SIDL & 0xE0))>>2)+(((WORD)(RXB0SIDL & 0x03))<<1)+(((WORD)(RXB0EIDH & 0x80))>>7); |
|
| 159 | cm. |
169 | cm.nid=((RXB0EIDH & 0x7E)>>1); |
| - | 170 | cm.sid=(((WORD)(RXB0EIDH & 0x01))<<8)+RXB0EIDL; |
|
| 160 | 171 | ||
| 161 | - | ||
| 162 | if (cm.extended==TRUE) |
- | |
| 163 | { |
- | |
| 164 | //Read extended ident. |
- | |
| 165 | - | ||
| 166 | //xx xx xx 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00 |
- | |
| 167 | - | ||
| 168 | //RXB0SIDH 28 27 26 25 24 23 22 21 |
- | |
| 169 | //RXB0SIDL 20 19 18 xx xx xx 17 16 |
- | |
| 170 | //RXB0EIDH 15 14 13 12 11 10 09 08 |
- | |
| 171 | //RXB0EIDL 07 06 05 04 03 02 01 00 |
- | |
| 172 | - | ||
| 173 | - | ||
| 174 | cm.ident = (((DWORD)RXB0SIDH)<<21) + (((DWORD)(RXB0SIDL & 0xE0))<<13) + (((DWORD)(RXB0SIDL & 0x03))<<16) + (((DWORD)RXB0EIDH)<<8) + (BYTE)RXB0EIDL; |
- | |
| 175 | - | ||
| 176 | } |
- | |
| 177 | else |
- | |
| 178 | { |
- | |
| 179 | //Read standard ident. |
- | |
| 180 | - | ||
| 181 | //xx xx xx xx xx 10 09 08 07 06 05 04 03 02 01 00 |
- | |
| 182 | - | ||
| 183 | //RXB0SIDH 10 09 08 07 06 05 04 03 |
- | |
| 184 | //RXB0SIDL 02 01 00 xx xx xx xx xx |
- | |
| 185 | - | ||
| 186 | cm.ident = (((DWORD)RXB0SIDH)<<3) + (((DWORD)RXB0SIDL)>>5); |
- | |
| 187 | } |
- | |
| 188 | 172 | ||
| 189 | // Data length |
173 | // Data length |
| 190 | cm.data_length=(RXB0DLCbits.DLC3<<3)+(RXB0DLCbits.DLC2<<2)+(RXB0DLCbits.DLC1<<1)+RXB0DLCbits.DLC0; |
174 | cm.data_length=(RXB0DLCbits.DLC3<<3)+(RXB0DLCbits.DLC2<<2)+(RXB0DLCbits.DLC1<<1)+RXB0DLCbits.DLC0; |
| 191 | 175 | ||
| 192 | // Remote request |
176 | // Remote request |
| 193 | cm.remote_request=(RXB0DLCbits.RXRTR==0?FALSE:TRUE); |
177 | cm.remote_request=(RXB0DLCbits.RXRTR==0?FALSE:TRUE); |
| 194 | 178 | ||
| 195 | // Data one bye one, for speed |
179 | // Data one bye one, for speed |
| 196 | cm.data[0]=RXB0D0; cm.data[1]=RXB0D1; |
180 | cm.data[0]=RXB0D0; cm.data[1]=RXB0D1; |
| 197 | cm.data[2]=RXB0D2; cm.data[3]=RXB0D3; |
181 | cm.data[2]=RXB0D2; cm.data[3]=RXB0D3; |
| 198 | cm.data[4]=RXB0D4; cm.data[5]=RXB0D5; |
182 | cm.data[4]=RXB0D4; cm.data[5]=RXB0D5; |
| 199 | cm.data[6]=RXB0D6; cm.data[7]=RXB0D7; |
183 | cm.data[6]=RXB0D6; cm.data[7]=RXB0D7; |
| 200 | 184 | ||
| 201 | // Clear ful status |
185 | // Clear ful status |
| 202 | RXB0CONbits.RXFUL=0; |
186 | RXB0CONbits.RXFUL=0; |
| 203 | 187 | ||
| 204 | //Call main parser |
188 | //Call main parser |
| 205 | canParse(cm); |
189 | canParse(cm); |
| 206 | } |
190 | } |
| 207 | 191 | ||
| 208 | 192 | ||
| 209 | /* |
193 | /* |
| 210 | * Function: canSendMessage |
194 | * Function: canSendMessage |
| 211 | * |
195 | * |
| 212 | * Input: CAN_MESSAGE to send |
196 | * Input: CAN_MESSAGE to send |
| 213 | * Output: True if packet scheduled sucess, false otherwise. |
197 | * Output: True if packet scheduled sucess, false otherwise. |
| 214 | * Pre-conditions: canInit |
198 | * Pre-conditions: canInit |
| 215 | * Affects: .. |
199 | * Affects: .. |
| 216 | * Depends: .. |
200 | * Depends: .. |
| 217 | */ |
201 | */ |
| 218 | BOOL canSendMessage( |
202 | BOOL canSendMessage(CAN_PROTO_MESSAGE cm,CAN_PRIORITY prio) |
| 219 | { |
203 | { |
| 220 | 204 | ||
| 221 | if ( TXB0CONbits.TXREQ == 0 ) { ECANCON=(ECANCON&0b00000)|0b00011; } |
205 | if ( TXB0CONbits.TXREQ == 0 ) { ECANCON=(ECANCON&0b00000)|0b00011; } |
| 222 | if ( TXB1CONbits.TXREQ == 0 ) { ECANCON=(ECANCON&0b00000)|0b00100; } |
206 | if ( TXB1CONbits.TXREQ == 0 ) { ECANCON=(ECANCON&0b00000)|0b00100; } |
| 223 | if ( TXB2CONbits.TXREQ == 0 ) { ECANCON=(ECANCON&0b00000)|0b00101; } |
207 | if ( TXB2CONbits.TXREQ == 0 ) { ECANCON=(ECANCON&0b00000)|0b00101; } |
| 224 | // None of the transmit buffers were empty. |
208 | // None of the transmit buffers were empty. |
| 225 | else { return FALSE;} |
209 | else { return FALSE;} |
| 226 | 210 | ||
| 227 | if (prio<0 || prio>3) prio = 0; |
211 | if (prio<0 || prio>3) prio = 0; |
| 228 | - | ||
| 229 | 212 | ||
| 230 | if (cm.extended==TRUE) |
- | |
| 231 | { |
- | |
| 232 | //Write extended ident. |
- | |
| 233 | - | ||
| 234 | //xx xx xx 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00 |
- | |
| 235 | 213 | ||
| 236 | //RXB0SIDH 28 27 26 25 24 23 22 21 |
214 | //RXB0SIDH 28 27 26 25 24 23 22 21 |
| 237 | //RXB0SIDL 20 19 18 xx xx xx 17 16 |
215 | //RXB0SIDL 20 19 18 xx xx xx 17 16 |
| 238 | //RXB0EIDH 15 14 13 12 11 10 09 08 |
216 | //RXB0EIDH 15 14 13 12 11 10 09 08 |
| 239 | //RXB0EIDL 07 06 05 04 03 02 01 00 |
217 | //RXB0EIDL 07 06 05 04 03 02 01 00 |
| 240 | 218 | ||
| 241 | - | ||
| 242 |
|
219 | //funct xx xx xx xx 28 27 26 25 |
| 243 | RXB0SIDL = ((BYTE)(cm.ident>>16) & 0x03) + ((BYTE)(cm.ident>>13) & 0xE0); |
- | |
| 244 |
|
220 | //funcc xx xx xx xx xx xx 24 23 22 21 20 19 18 17 16 15 |
| 245 |
|
221 | //nid xx xx 14 13 12 11 10 09 |
| 246 | - | ||
| 247 | } |
- | |
| 248 | else |
- | |
| 249 | { |
- | |
| 250 | //Write standard ident. |
- | |
| 251 | - | ||
| 252 |
|
222 | //sid xx xx xx xx xx xx xx 08 07 06 05 04 03 02 01 00 |
| 253 | 223 | ||
| 254 |
|
224 | RXB0SIDH = (BYTE)((cm.funct & 0x0F)<<4)+(BYTE)((cm.funcc & 0x03C0)>>6); |
| 255 |
|
225 | RXB0SIDL = (BYTE)((cm.funcc & 0x003F)<<2)+(BYTE)((cm.funcc & 0x0006)>>1); |
| 256 | - | ||
| 257 |
|
226 | RXB0EIDH = (BYTE)((cm.funcc & 0x0001)<<7)+(BYTE)((cm.nid & 0x3F)<<1)+(BYTE)((cm.sid & 0x0100)>>8); |
| 258 |
|
227 | RXB0EIDL = (BYTE)((cm.sid & 0x00FF)); |
| 259 | - | ||
| 260 | } |
- | |
| 261 | 228 | ||
| 262 | // Data length |
229 | // Data length |
| 263 | RXB0DLC = 0; |
230 | RXB0DLC = 0; |
| 264 | if (cm.data_length>8) RXB0DLC=8; else RXB0DLC=cm.data_length; |
231 | if (cm.data_length>8) RXB0DLC=8; else RXB0DLC=cm.data_length; |
| 265 | 232 | ||
| Line 282... | Line 249... | ||
| 282 | RXB0D2=cm.data[2]; RXB0D3=cm.data[3]; |
249 | RXB0D2=cm.data[2]; RXB0D3=cm.data[3]; |
| 283 | RXB0D4=cm.data[4]; RXB0D5=cm.data[5]; |
250 | RXB0D4=cm.data[4]; RXB0D5=cm.data[5]; |
| 284 | RXB0D6=cm.data[6]; RXB0D7=cm.data[7]; |
251 | RXB0D6=cm.data[6]; RXB0D7=cm.data[7]; |
| 285 | 252 | ||
| 286 | // set extended or not |
253 | // set extended or not |
| 287 | RXB0SIDLbits.EXID= |
254 | RXB0SIDLbits.EXID=1; |
| 288 | 255 | ||
| 289 | // Priority |
256 | // Priority |
| 290 | RXB0CON = (RXB0CON & 0b11111100) | prio; |
257 | RXB0CON = (RXB0CON & 0b11111100) | prio; |
| 291 | 258 | ||
| 292 | // mark as redy to transmit |
259 | // mark as redy to transmit |