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