Rev 24 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 24 | Rev 25 | ||
|---|---|---|---|
| Line -... | Line 1... | ||
| - | 1 | /********************************************************************* |
|
| - | 2 | * |
|
| - | 3 | * CAN driver |
|
| - | 4 | * |
|
| - | 5 | ********************************************************************* |
|
| - | 6 | * FileName: CAN.c |
|
| - | 7 | * |
|
| - | 8 | * Author Date Comment |
|
| - | 9 | *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
| - | 10 | * Nilesh Rajbharti 8/20/01 Original (Rev 1.0) |
|
| - | 11 | ********************************************************************/ |
|
| - | 12 | ||
| 1 | #include "../Include/CANdefs.h" |
13 | #include "../Include/CANdefs.h" |
| 2 | #include "../Include/stackTasks.h" |
14 | #include "../Include/stackTasks.h" |
| 3 | #include "../Include/CAN.h" |
15 | #include "../Include/CAN.h" |
| 4 | #include "../Include/uart.h" |
16 | #include "../Include/uart.h" |
| 5 | 17 | ||
| Line 63... | Line 75... | ||
| 63 | 75 | ||
| 64 | 76 | ||
| 65 | // FILTERS AND MASKS |
77 | // FILTERS AND MASKS |
| 66 | RXB0CONbits.RXM1=1; |
78 | RXB0CONbits.RXM1=1; |
| 67 | RXB0CONbits.RXM0=0; |
79 | RXB0CONbits.RXM0=0; |
| 68 | 80 | ||
| 69 | 81 | ||
| 70 | // INTERRUPTS |
82 | // INTERRUPTS |
| 71 | 83 | ||
| 72 | // Diable transmit interrupt |
84 | // Diable transmit interrupt |
| 73 | TXBIE = 0; |
85 | TXBIE = 0; |
| 74 | 86 | ||
| 75 | //rx any interrupt |
87 | //rx any interrupt |
| 76 | PIR3 = 0; |
88 | PIR3 = 0; |
| 77 | PIE3 = 0b00000011; |
89 | PIE3 = 0b00000011; |
| 78 | 90 | ||
| 79 | // High interrupt |
91 | // High interrupt |
| 80 | IPR3 =0b00000011; |
92 | IPR3 =0b00000011; |
| 81 | 93 | ||
| 82 | // Programmable buffers interrupt |
94 | // Programmable buffers interrupt |
| 83 | BIE0 = 0xFF; |
95 | BIE0 = 0xFF; |
| Line 91... | Line 103... | ||
| 91 | CANCON = 0x00;//request normal mode |
103 | CANCON = 0x00;//request normal mode |
| 92 | while ((CANSTAT & 0xE0) != 0x00 );//wait for normal mode |
104 | while ((CANSTAT & 0xE0) != 0x00 );//wait for normal mode |
| 93 | #endif |
105 | #endif |
| 94 | 106 | ||
| 95 | } |
107 | } |
| 96 | 108 | ||
| 97 | 109 | ||
| 98 | /* |
110 | /* |
| 99 | * Function: canISR |
111 | * Function: canISR |
| 100 | * |
112 | * |
| 101 | * Input: none |
113 | * Input: none |
| 102 | * Output: none |
114 | * Output: none |
| 103 | * Pre-conditions: a call to canInit() |
115 | * Pre-conditions: a call to canInit() |
| 104 | * Affects: interrupt registers and receive data buffers |
116 | * Affects: interrupt registers and receive data buffers |
| 105 | * Depends: .. |
117 | * Depends: .. |
| 106 | */ |
118 | */ |
| 107 | void canISR() |
119 | void canISR() |
| 108 | { |
120 | { |
| 109 | if (PIR3bits.RXBnIF || PIR3bits.RXB1IF || PIR3bits.RXB0IF) |
121 | if (PIR3bits.RXBnIF || PIR3bits.RXB1IF || PIR3bits.RXB0IF) |
| 110 | { |
122 | { |
| Line 170... | Line 182... | ||
| 170 | 182 | ||
| 171 | //RXB0SIDH 10 09 08 07 06 05 04 03 |
183 | //RXB0SIDH 10 09 08 07 06 05 04 03 |
| 172 | //RXB0SIDL 02 01 00 xx xx xx xx xx |
184 | //RXB0SIDL 02 01 00 xx xx xx xx xx |
| 173 | 185 | ||
| 174 | cm.ident = (((DWORD)RXB0SIDH)<<3) + (((DWORD)RXB0SIDL)>>5); |
186 | cm.ident = (((DWORD)RXB0SIDH)<<3) + (((DWORD)RXB0SIDL)>>5); |
| 175 | } |
187 | } |
| 176 | 188 | ||
| 177 | // Data length |
189 | // Data length |
| 178 | cm.data_length=RXB0DLC; |
190 | cm.data_length=RXB0DLC; |
| 179 | 191 | ||
| 180 | // Data one bye one, for speed |
192 | // Data one bye one, for speed |
| 181 | cm.data[0]=RXB0D0; cm.data[1]=RXB0D1; |
193 | cm.data[0]=RXB0D0; cm.data[1]=RXB0D1; |
| 182 | cm.data[2]=RXB0D2; cm.data[3]=RXB0D3; |
194 | cm.data[2]=RXB0D2; cm.data[3]=RXB0D3; |
| Line 186... | Line 198... | ||
| 186 | // Clear ful status |
198 | // Clear ful status |
| 187 | RXB0CONbits.RXFUL=0; |
199 | RXB0CONbits.RXFUL=0; |
| 188 | 200 | ||
| 189 | //Call main parser |
201 | //Call main parser |
| 190 | canParse(cm); |
202 | canParse(cm); |
| 191 | } |
203 | } |
| 192 | 204 | ||
| 193 | 205 | ||
| 194 | /* |
206 | /* |
| 195 | * Function: canSendMessage |
207 | * Function: canSendMessage |
| 196 | * |
208 | * |
| Line 202... | Line 214... | ||
| 202 | */ |
214 | */ |
| 203 | BOOL canSendMessage(CAN_MESSAGE cm) |
215 | BOOL canSendMessage(CAN_MESSAGE cm) |
| 204 | { |
216 | { |
| 205 | 217 | ||
| 206 | 218 | ||
| 207 | if ( TXB0CONbits.TXREQ == 0 ) |
- | |
| 208 | { |
- | |
| 209 | uartPutrs("TXREQ not set."); |
- | |
| 210 | 219 | ||
| 211 | } |
- | |
| 212 | else { uartPutrs("TXREQ is set."); return FALSE;} |
- | |
| 213 | - | ||
| 214 | - | ||
| 215 | - | ||
| 216 | - | ||
| 217 | /* |
- | |
| 218 | if ( TXB0CONbits.TXREQ == 0 ) { ECANCON=(ECANCON&0b00000)|0b00011; } |
220 | if ( TXB0CONbits.TXREQ == 0 ) { ECANCON=(ECANCON&0b00000)|0b00011; } |
| 219 | if ( TXB1CONbits.TXREQ == 0 ) { ECANCON=(ECANCON&0b00000)|0b00100; } |
221 | if ( TXB1CONbits.TXREQ == 0 ) { ECANCON=(ECANCON&0b00000)|0b00100; } |
| 220 | if ( TXB2CONbits.TXREQ == 0 ) { ECANCON=(ECANCON&0b00000)|0b00101; } |
222 | if ( TXB2CONbits.TXREQ == 0 ) { ECANCON=(ECANCON&0b00000)|0b00101; } |
| 221 | // None of the transmit buffers were empty. |
223 | // None of the transmit buffers were empty. |
| 222 | else { return FALSE;} |
224 | else { return FALSE;} |
| 223 | 225 | ||
| 224 | |
226 | |
| 225 | // Set extended mode or not. |
227 | // Set extended mode or not. |
| 226 | RXB0SIDLbits.EXID=(cm.extended==TRUE?1:0); |
228 | RXB0SIDLbits.EXID=(cm.extended==TRUE?1:0); |
| 227 | 229 | ||
| 228 | 230 | ||
| Line 290... | Line 292... | ||
| 290 | bsf RXB0CON, 3, 0 |
292 | bsf RXB0CON, 3, 0 |
| 291 | _endasm |
293 | _endasm |
| 292 | 294 | ||
| 293 | 295 | ||
| 294 | return TRUE; |
296 | return TRUE; |
| 295 | */ |
297 | |
| 296 | } |
298 | } |
| 297 | 299 | ||
| 298 | 300 | ||
| 299 | 301 | ||
| 300 | #endif //USE_CAN |
302 | #endif //USE_CAN |