Rev 97 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 97 | Rev 260 | ||
|---|---|---|---|
| 1 | /********************************************************************* |
1 | /********************************************************************* |
| 2 | * |
2 | * |
| 3 | * CAN driver |
3 | * CAN driver |
| 4 | * |
4 | * |
| 5 | ********************************************************************* |
5 | ********************************************************************* |
| 6 | * FileName: $HeadURL: https://svn.auml.se/svn/HomeAutomation/trunk/EmbeddedSoftware/PIC/canToSerial/Source/CAN.c $ |
6 | * FileName: $HeadURL: https://svn.auml.se/svn/HomeAutomation/trunk/EmbeddedSoftware/PIC/canToSerial/Source/CAN.c $ |
| 7 | * Last changed: $LastChangedDate: |
7 | * Last changed: $LastChangedDate: 2007-01-28 14:58:11 +0100 (Sun, 28 Jan 2007) $ |
| 8 | * By: $LastChangedBy: johboh $ |
8 | * By: $LastChangedBy: johboh $ |
| 9 | * Revision: $Revision: |
9 | * Revision: $Revision: 260 $ |
| 10 | ********************************************************************/ |
10 | ********************************************************************/ |
| 11 | 11 | ||
| 12 | #include <CANdefs.h> |
12 | #include <CANdefs.h> |
| 13 | #include <stackTasks.h> |
13 | #include <stackTasks.h> |
| 14 | #include <CAN.h> |
14 | #include <CAN.h> |
| 15 | 15 | ||
| 16 | static void canGetPacket(void); |
16 | static void canGetPacket(void); |
| 17 | 17 | ||
| 18 | #ifdef USE_CAN |
18 | #ifdef USE_CAN |
| 19 | 19 | ||
| 20 | 20 | ||
| 21 | /* |
21 | /* |
| 22 | * Function: canInit |
22 | * Function: canInit |
| 23 | * |
23 | * |
| 24 | * Input: none |
24 | * Input: none |
| 25 | * Output: none |
25 | * Output: none |
| 26 | * Pre-conditions: none |
26 | * Pre-conditions: none |
| 27 | * Affects: Changes can registers. |
27 | * Affects: Changes can registers. |
| 28 | * Depends: none. |
28 | * Depends: none. |
| 29 | */ |
29 | */ |
| 30 | void canInit() |
30 | void canInit() |
| 31 | { |
31 | { |
| 32 | CANCON = 0x80; //request config mode |
32 | CANCON = 0x80; //request config mode |
| 33 | while ((CANSTAT & 0xE0) != 0x80 ); //wait for config mode request |
33 | while ((CANSTAT & 0xE0) != 0x80 ); //wait for config mode request |
| 34 | 34 | ||
| 35 | // BAUD AND TQS |
35 | // BAUD AND TQS |
| 36 | 36 | ||
| - | 37 | //BRGCON1 = 0x03; //500Kbit@40MHz 1TQ Sync, 2TQ Prop, 4TQ Phase1, 3TQ Phase2 |
|
| - | 38 | //BRGCON2 = 0x99; |
|
| - | 39 | //BRGCON3 = 0x02; |
|
| - | 40 | ||
| - | 41 | //75%, 250Kbps @40MHz |
|
| - | 42 | //BRGCON1 = 0x09; |
|
| - | 43 | //BRGCON2 = 0xDB; |
|
| - | 44 | //BRGCON3 = 0x01; |
|
| - | 45 | ||
| - | 46 | //75% ,1 , 500Kbps @40MHz |
|
| - | 47 | //BRGCON1 = 0x01; |
|
| - | 48 | //BRGCON2 = (0xB6 | 0x80); |
|
| - | 49 | //BRGCON3 = 0x04; |
|
| - | 50 | ||
| - | 51 | //75% ,1 , 500Kbps @80MHz |
|
| - | 52 | //BRGCON1 = 0x03; |
|
| - | 53 | //BRGCON2 = (0xB6 | 0x80); |
|
| - | 54 | //BRGCON3 = 0x04; |
|
| - | 55 | ||
| - | 56 | // 500Khz@40Mhz (new by the book) |
|
| - | 57 | BRGCON1 = 0x04; |
|
| - | 58 | BRGCON2 = 0xD1; |
|
| - | 59 | BRGCON3 = 0x81; |
|
| - | 60 | ||
| - | 61 | ||
| 37 |
|
62 | //BRGCON1=0; |
| 38 | 63 | ||
| 39 | // Sync_Seq = 2 x TQ = 1 |
64 | // Sync_Seq = 2 x TQ = 1 |
| 40 | BRGCON1bits. |
65 | //BRGCON1bits.SJW1=0; |
| 41 | BRGCON1bits. |
66 | //BRGCON1bits.SJW0=1; |
| 42 | 67 | ||
| 43 | // Setting BRP. |
68 | // Setting BRP. |
| 44 |
|
69 | //BRGCON1=BRGCON1|CAN_BRP; |
| 45 | 70 | ||
| 46 | // Maximum PHEG1 |
71 | // Maximum PHEG1 |
| 47 | BRGCON2bits. |
72 | //BRGCON2bits.SEG2PHTS = 1; |
| 48 | 73 | ||
| 49 | // Phase_Seg1 = 2 x TQ = 1 |
74 | // Phase_Seg1 = 2 x TQ = 1 |
| 50 | BRGCON2bits. |
75 | //BRGCON2bits.SEG1PH2 = 0; |
| 51 | BRGCON2bits. |
76 | //BRGCON2bits.SEG1PH1 = 0; |
| 52 | BRGCON2bits. |
77 | //BRGCON2bits.SEG1PH0 = 1; |
| 53 | 78 | ||
| 54 | // Prop_Seq = 2 x TQ = 1 |
79 | // Prop_Seq = 2 x TQ = 1 |
| 55 | BRGCON2bits. |
80 | //BRGCON2bits.PRSEG2 = 0; |
| 56 | BRGCON2bits. |
81 | //BRGCON2bits.PRSEG1 = 0; |
| 57 | BRGCON2bits. |
82 | //BRGCON2bits.PRSEG0 = 1; |
| 58 | 83 | ||
| 59 | // Enableing bus wake-up |
84 | // Enableing bus wake-up |
| 60 | BRGCON3bits. |
85 | //BRGCON3bits.WAKDIS = 0; |
| 61 | 86 | ||
| 62 | // Dont use filter when wakeup |
87 | // Dont use filter when wakeup |
| 63 | BRGCON3bits. |
88 | //BRGCON3bits.WAKFIL = 0; |
| 64 | 89 | ||
| 65 | // Phase_Seg2 = 2 x TQ = 1 |
90 | // Phase_Seg2 = 2 x TQ = 1 |
| 66 | BRGCON3bits. |
91 | //BRGCON3bits.SEG2PH2 = 0; |
| 67 | BRGCON3bits. |
92 | //BRGCON3bits.SEG2PH1 = 0; |
| 68 | BRGCON3bits. |
93 | //BRGCON3bits.SEG2PH0 = 1; |
| 69 | 94 | ||
| 70 | ECANCON=0; |
95 | ECANCON=0; |
| 71 | ECANCONbits.MDSEL1 = 1; |
96 | ECANCONbits.MDSEL1 = 1; |
| 72 | ECANCONbits.MDSEL0 = 0; |
97 | ECANCONbits.MDSEL0 = 0; |
| 73 | 98 | ||
| 74 | 99 | ||
| 75 | // FILTERS AND MASKS |
100 | // FILTERS AND MASKS |
| 76 | RXB0CONbits.RXM1=1; |
101 | RXB0CONbits.RXM1=1; |
| 77 | RXB0CONbits.RXM0=0; |
102 | RXB0CONbits.RXM0=0; |
| 78 | 103 | ||
| - | 104 | // Set ressesive VDD |
|
| - | 105 | CIOCONbits.ENDRHI = 1; |
|
| 79 | 106 | ||
| 80 | // INTERRUPTS |
107 | // INTERRUPTS |
| 81 | 108 | ||
| 82 | // Diable transmit interrupt |
109 | // Diable transmit interrupt |
| 83 | TXBIE = 0; |
110 | TXBIE = 0; |
| 84 | 111 | ||
| 85 | //rx any interrupt |
112 | //rx any interrupt |
| 86 | PIR3 = 0; |
113 | PIR3 = 0; |
| 87 | PIE3 = 0b00000011; |
114 | PIE3 = 0b00000011; |
| 88 | 115 | ||
| 89 | // High interrupt |
116 | // High interrupt |
| 90 | IPR3 =0b00000011; |
117 | IPR3 =0b00000011; |
| 91 | 118 | ||
| 92 | // Programmable buffers interrupt |
119 | // Programmable buffers interrupt |
| 93 | BIE0 = 0xFF; |
120 | BIE0 = 0xFF; |
| 94 | 121 | ||
| 95 | 122 | ||
| 96 | //loopback mode or not |
123 | //loopback mode or not |
| 97 | #ifdef CAN_LOOPBACK_MODE |
124 | #ifdef CAN_LOOPBACK_MODE |
| 98 | CANCON = 0x40;//request loopback mode |
125 | CANCON = 0x40;//request loopback mode |
| 99 | while ((CANSTAT & 0xE0) != 0x40 );//wait for loopback mode |
126 | while ((CANSTAT & 0xE0) != 0x40 );//wait for loopback mode |
| 100 | #else |
127 | #else |
| 101 | CANCON = 0x00;//request normal mode |
128 | CANCON = 0x00;//request normal mode |
| 102 | while ((CANSTAT & 0xE0) != 0x00 );//wait for normal mode |
129 | while ((CANSTAT & 0xE0) != 0x00 );//wait for normal mode |
| 103 | #endif |
130 | #endif |
| 104 | 131 | ||
| 105 | } |
132 | } |
| 106 | 133 | ||
| 107 | 134 | ||
| 108 | /* |
135 | /* |
| 109 | * Function: canISR |
136 | * Function: canISR |
| 110 | * |
137 | * |
| 111 | * Input: none |
138 | * Input: none |
| 112 | * Output: none |
139 | * Output: none |
| 113 | * Pre-conditions: a call to canInit() |
140 | * Pre-conditions: a call to canInit() |
| 114 | * Affects: interrupt registers and receive data buffers |
141 | * Affects: interrupt registers and receive data buffers |
| 115 | * Depends: .. |
142 | * Depends: .. |
| 116 | */ |
143 | */ |
| 117 | void canISR() |
144 | void canISR() |
| 118 | { |
145 | { |
| 119 | if (PIR3bits.RXBnIF || PIR3bits.RXB1IF || PIR3bits.RXB0IF) |
146 | if (PIR3bits.RXBnIF || PIR3bits.RXB1IF || PIR3bits.RXB0IF) |
| 120 | { |
147 | { |
| 121 | ECANCON=(ECANCON&0b00000)|(0b10000|(CANCON&0x0F)); |
148 | ECANCON=(ECANCON&0b00000)|(0b10000|(CANCON&0x0F)); |
| 122 | if (RXB0CONbits.RXFUL) canGetPacket(); |
149 | if (RXB0CONbits.RXFUL) canGetPacket(); |
| 123 | 150 | ||
| 124 | if (PIR3bits.RXBnIF) {PIR3bits.RXBnIF = 0; return;} |
151 | if (PIR3bits.RXBnIF) {PIR3bits.RXBnIF = 0; return;} |
| 125 | if (PIR3bits.RXB1IF) {PIR3bits.RXB1IF = 0; return;} |
152 | if (PIR3bits.RXB1IF) {PIR3bits.RXB1IF = 0; return;} |
| 126 | if (PIR3bits.RXB0IF) {PIR3bits.RXB0IF = 0; return;} |
153 | if (PIR3bits.RXB0IF) {PIR3bits.RXB0IF = 0; return;} |
| 127 | } |
154 | } |
| 128 | } |
155 | } |
| 129 | 156 | ||
| 130 | 157 | ||
| 131 | /* |
158 | /* |
| 132 | * Function: canGetPacket |
159 | * Function: canGetPacket |
| 133 | * |
160 | * |
| 134 | * Input: none |
161 | * Input: none |
| 135 | * Output: none |
162 | * Output: none |
| 136 | * Pre-conditions: a call to canISR and an packet is available and banked to RXB0 |
163 | * Pre-conditions: a call to canISR and an packet is available and banked to RXB0 |
| 137 | * Affects: Calls canParse() function in main for parsing received packet. |
164 | * Affects: Calls canParse() function in main for parsing received packet. |
| 138 | * Depends: none. |
165 | * Depends: none. |
| 139 | */ |
166 | */ |
| 140 | void canGetPacket() |
167 | void canGetPacket() |
| 141 | { |
168 | { |
| 142 | CAN_MESSAGE cm; |
169 | CAN_MESSAGE cm; |
| 143 | 170 | ||
| 144 | // Set extended mode or not. |
171 | // Set extended mode or not. |
| 145 | cm.extended=(RXB0SIDLbits.EXID==0?FALSE:TRUE); |
172 | cm.extended=(RXB0SIDLbits.EXID==0?FALSE:TRUE); |
| 146 | 173 | ||
| 147 | // Clear |
174 | // Clear |
| 148 | cm.ident=0; |
175 | cm.ident=0; |
| 149 | 176 | ||
| 150 | 177 | ||
| 151 | if (cm.extended==TRUE) |
178 | if (cm.extended==TRUE) |
| 152 | { |
179 | { |
| 153 | //Read extended ident. |
180 | //Read extended ident. |
| 154 | 181 | ||
| 155 | //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 |
182 | //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 |
| 156 | 183 | ||
| 157 | //RXB0SIDH 28 27 26 25 24 23 22 21 |
184 | //RXB0SIDH 28 27 26 25 24 23 22 21 |
| 158 | //RXB0SIDL 20 19 18 xx xx xx 17 16 |
185 | //RXB0SIDL 20 19 18 xx xx xx 17 16 |
| 159 | //RXB0EIDH 15 14 13 12 11 10 09 08 |
186 | //RXB0EIDH 15 14 13 12 11 10 09 08 |
| 160 | //RXB0EIDL 07 06 05 04 03 02 01 00 |
187 | //RXB0EIDL 07 06 05 04 03 02 01 00 |
| 161 | 188 | ||
| 162 | 189 | ||
| 163 | cm.ident = (((DWORD)RXB0SIDH)<<21) + (((DWORD)(RXB0SIDL & 0xE0))<<13) + (((DWORD)(RXB0SIDL & 0x03))<<16) + (((DWORD)RXB0EIDH)<<8) + (BYTE)RXB0EIDL; |
190 | cm.ident = (((DWORD)RXB0SIDH)<<21) + (((DWORD)(RXB0SIDL & 0xE0))<<13) + (((DWORD)(RXB0SIDL & 0x03))<<16) + (((DWORD)RXB0EIDH)<<8) + (BYTE)RXB0EIDL; |
| 164 | 191 | ||
| 165 | } |
192 | } |
| 166 | else |
193 | else |
| 167 | { |
194 | { |
| 168 | //Read standard ident. |
195 | //Read standard ident. |
| 169 | 196 | ||
| 170 | //xx xx xx xx xx 10 09 08 07 06 05 04 03 02 01 00 |
197 | //xx xx xx xx xx 10 09 08 07 06 05 04 03 02 01 00 |
| 171 | 198 | ||
| 172 | //RXB0SIDH 10 09 08 07 06 05 04 03 |
199 | //RXB0SIDH 10 09 08 07 06 05 04 03 |
| 173 | //RXB0SIDL 02 01 00 xx xx xx xx xx |
200 | //RXB0SIDL 02 01 00 xx xx xx xx xx |
| 174 | 201 | ||
| 175 | cm.ident = (((DWORD)RXB0SIDH)<<3) + (((DWORD)RXB0SIDL)>>5); |
202 | cm.ident = (((DWORD)RXB0SIDH)<<3) + (((DWORD)RXB0SIDL)>>5); |
| 176 | } |
203 | } |
| 177 | 204 | ||
| 178 | // Data length |
205 | // Data length |
| 179 | cm.data_length=(RXB0DLCbits.DLC3<<3)+(RXB0DLCbits.DLC2<<2)+(RXB0DLCbits.DLC1<<1)+RXB0DLCbits.DLC0; |
206 | cm.data_length=(RXB0DLCbits.DLC3<<3)+(RXB0DLCbits.DLC2<<2)+(RXB0DLCbits.DLC1<<1)+RXB0DLCbits.DLC0; |
| 180 | 207 | ||
| 181 | // Remote request |
208 | // Remote request |
| 182 | cm.remote_request=(RXB0DLCbits.RXRTR==0?FALSE:TRUE); |
209 | cm.remote_request=(RXB0DLCbits.RXRTR==0?FALSE:TRUE); |
| 183 | 210 | ||
| 184 | // Data one bye one, for speed |
211 | // Data one bye one, for speed |
| 185 | cm.data[0]=RXB0D0; cm.data[1]=RXB0D1; |
212 | cm.data[0]=RXB0D0; cm.data[1]=RXB0D1; |
| 186 | cm.data[2]=RXB0D2; cm.data[3]=RXB0D3; |
213 | cm.data[2]=RXB0D2; cm.data[3]=RXB0D3; |
| 187 | cm.data[4]=RXB0D4; cm.data[5]=RXB0D5; |
214 | cm.data[4]=RXB0D4; cm.data[5]=RXB0D5; |
| 188 | cm.data[6]=RXB0D6; cm.data[7]=RXB0D7; |
215 | cm.data[6]=RXB0D6; cm.data[7]=RXB0D7; |
| 189 | 216 | ||
| 190 | // Clear ful status |
217 | // Clear ful status |
| 191 | RXB0CONbits.RXFUL=0; |
218 | RXB0CONbits.RXFUL=0; |
| 192 | 219 | ||
| 193 | //Call main parser |
220 | //Call main parser |
| 194 | canParse(cm); |
221 | canParse(cm); |
| 195 | } |
222 | } |
| 196 | 223 | ||
| 197 | 224 | ||
| 198 | /* |
225 | /* |
| 199 | * Function: canSendMessage |
226 | * Function: canSendMessage |
| 200 | * |
227 | * |
| 201 | * Input: CAN_MESSAGE to send |
228 | * Input: CAN_MESSAGE to send |
| 202 | * Output: True if packet scheduled sucess, false otherwise. |
229 | * Output: True if packet scheduled sucess, false otherwise. |
| 203 | * Pre-conditions: canInit |
230 | * Pre-conditions: canInit |
| 204 | * Affects: .. |
231 | * Affects: .. |
| 205 | * Depends: .. |
232 | * Depends: .. |
| 206 | */ |
233 | */ |
| 207 | BOOL canSendMessage(CAN_MESSAGE cm,CAN_PRIORITY prio) |
234 | BOOL canSendMessage(CAN_MESSAGE cm,CAN_PRIORITY prio) |
| 208 | { |
235 | { |
| 209 | 236 | ||
| 210 | if ( TXB0CONbits.TXREQ == 0 ) { ECANCON=(ECANCON&0b00000)|0b00011; } |
237 | if ( TXB0CONbits.TXREQ == 0 ) { ECANCON=(ECANCON&0b00000)|0b00011; } |
| 211 | if ( TXB1CONbits.TXREQ == 0 ) { ECANCON=(ECANCON&0b00000)|0b00100; } |
238 | if ( TXB1CONbits.TXREQ == 0 ) { ECANCON=(ECANCON&0b00000)|0b00100; } |
| 212 | if ( TXB2CONbits.TXREQ == 0 ) { ECANCON=(ECANCON&0b00000)|0b00101; } |
239 | if ( TXB2CONbits.TXREQ == 0 ) { ECANCON=(ECANCON&0b00000)|0b00101; } |
| 213 | // None of the transmit buffers were empty. |
240 | // None of the transmit buffers were empty. |
| 214 | else { return FALSE;} |
241 | else { return FALSE;} |
| 215 | 242 | ||
| 216 | if (prio<0 || prio>3) prio = 0; |
243 | if (prio<0 || prio>3) prio = 0; |
| 217 | 244 | ||
| 218 | 245 | ||
| 219 | if (cm.extended==TRUE) |
246 | if (cm.extended==TRUE) |
| 220 | { |
247 | { |
| 221 | //Write extended ident. |
248 | //Write extended ident. |
| 222 | 249 | ||
| 223 | //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 |
250 | //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 |
| 224 | 251 | ||
| 225 | //RXB0SIDH 28 27 26 25 24 23 22 21 |
252 | //RXB0SIDH 28 27 26 25 24 23 22 21 |
| 226 | //RXB0SIDL 20 19 18 xx xx xx 17 16 |
253 | //RXB0SIDL 20 19 18 xx xx xx 17 16 |
| 227 | //RXB0EIDH 15 14 13 12 11 10 09 08 |
254 | //RXB0EIDH 15 14 13 12 11 10 09 08 |
| 228 | //RXB0EIDL 07 06 05 04 03 02 01 00 |
255 | //RXB0EIDL 07 06 05 04 03 02 01 00 |
| 229 | 256 | ||
| 230 | 257 | ||
| 231 | RXB0SIDH = (BYTE)((cm.ident>>21)); |
258 | RXB0SIDH = (BYTE)((cm.ident>>21)); |
| 232 | RXB0SIDL = ((BYTE)(cm.ident>>16) & 0x03) + ((BYTE)(cm.ident>>13) & 0xE0); |
259 | RXB0SIDL = ((BYTE)(cm.ident>>16) & 0x03) + ((BYTE)(cm.ident>>13) & 0xE0); |
| 233 | RXB0EIDH = (BYTE)(cm.ident>>8); |
260 | RXB0EIDH = (BYTE)(cm.ident>>8); |
| 234 | RXB0EIDL = (BYTE)cm.ident; |
261 | RXB0EIDL = (BYTE)cm.ident; |
| 235 | 262 | ||
| 236 | } |
263 | } |
| 237 | else |
264 | else |
| 238 | { |
265 | { |
| 239 | //Write standard ident. |
266 | //Write standard ident. |
| 240 | 267 | ||
| 241 | //xx xx xx xx xx 10 09 08 07 06 05 04 03 02 01 00 |
268 | //xx xx xx xx xx 10 09 08 07 06 05 04 03 02 01 00 |
| 242 | 269 | ||
| 243 | //RXB0SIDH 10 09 08 07 06 05 04 03 |
270 | //RXB0SIDH 10 09 08 07 06 05 04 03 |
| 244 | //RXB0SIDL 02 01 00 xx xx xx xx xx |
271 | //RXB0SIDL 02 01 00 xx xx xx xx xx |
| 245 | 272 | ||
| 246 | RXB0SIDH= (BYTE)(cm.ident>>3); |
273 | RXB0SIDH= (BYTE)(cm.ident>>3); |
| 247 | RXB0SIDL= ((BYTE)(cm.ident<<5) & 0xE0); |
274 | RXB0SIDL= ((BYTE)(cm.ident<<5) & 0xE0); |
| 248 | 275 | ||
| 249 | } |
276 | } |
| 250 | 277 | ||
| 251 | // Data length |
278 | // Data length |
| 252 | RXB0DLC = 0; |
279 | RXB0DLC = 0; |
| 253 | if (cm.data_length>8) RXB0DLC=8; else RXB0DLC=cm.data_length; |
280 | if (cm.data_length>8) RXB0DLC=8; else RXB0DLC=cm.data_length; |
| 254 | 281 | ||
| 255 | // Remote request |
282 | // Remote request |
| 256 | if (cm.remote_request==TRUE) |
283 | if (cm.remote_request==TRUE) |
| 257 | { |
284 | { |
| 258 | _asm |
285 | _asm |
| 259 | bsf RXB0DLC, 6, 0 |
286 | bsf RXB0DLC, 6, 0 |
| 260 | _endasm |
287 | _endasm |
| 261 | } |
288 | } |
| 262 | else |
289 | else |
| 263 | { |
290 | { |
| 264 | _asm |
291 | _asm |
| 265 | bcf RXB0DLC, 6, 0 |
292 | bcf RXB0DLC, 6, 0 |
| 266 | _endasm |
293 | _endasm |
| 267 | } |
294 | } |
| 268 | 295 | ||
| 269 | // Data one bye one, for speed |
296 | // Data one bye one, for speed |
| 270 | RXB0D0=cm.data[0]; RXB0D1=cm.data[1]; |
297 | RXB0D0=cm.data[0]; RXB0D1=cm.data[1]; |
| 271 | RXB0D2=cm.data[2]; RXB0D3=cm.data[3]; |
298 | RXB0D2=cm.data[2]; RXB0D3=cm.data[3]; |
| 272 | RXB0D4=cm.data[4]; RXB0D5=cm.data[5]; |
299 | RXB0D4=cm.data[4]; RXB0D5=cm.data[5]; |
| 273 | RXB0D6=cm.data[6]; RXB0D7=cm.data[7]; |
300 | RXB0D6=cm.data[6]; RXB0D7=cm.data[7]; |
| 274 | 301 | ||
| 275 | // set extended or not |
302 | // set extended or not |
| 276 | RXB0SIDLbits.EXID=(cm.extended==TRUE?1:0); |
303 | RXB0SIDLbits.EXID=(cm.extended==TRUE?1:0); |
| 277 | 304 | ||
| 278 | // Priority |
305 | // Priority |
| 279 | RXB0CON = (RXB0CON & 0b11111100) | prio; |
306 | RXB0CON = (RXB0CON & 0b11111100) | prio; |
| 280 | 307 | ||
| 281 | // mark as redy to transmit |
308 | // mark as redy to transmit |
| 282 | _asm |
309 | _asm |
| 283 | bsf RXB0CON, 3, 0 |
310 | bsf RXB0CON, 3, 0 |
| 284 | _endasm |
311 | _endasm |
| 285 | 312 | ||
| 286 | return TRUE; |
313 | return TRUE; |
| 287 | 314 | ||
| 288 | } |
315 | } |
| 289 | 316 | ||
| 290 | 317 | ||
| 291 | 318 | ||
| 292 | #endif //USE_CAN |
319 | #endif //USE_CAN |
| 293 | 320 | ||