Rev 342 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 342 | Rev 353 | ||
|---|---|---|---|
| Line 2... | Line 2... | ||
| 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: 2007- |
7 | * Last changed: $LastChangedDate: 2007-03-03 19:07:14 +0100 (Sat, 03 Mar 2007) $ |
| 8 | * By: $LastChangedBy: johboh $ |
8 | * By: $LastChangedBy: johboh $ |
| 9 | * Revision: $Revision: |
9 | * Revision: $Revision: 353 $ |
| 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> |
15 | #include <EEaccess.h> |
| 16 | #include <funcdefs.h> |
16 | #include <funcdefs.h> |
| 17 | #include <Tick.h> |
17 | #include <Tick.h> |
| 18 | 18 | ||
| 19 | TICK heartbeat; |
19 | static TICK heartbeat; |
| 20 | static int MY_ID = DEFAULT_ID; |
20 | static int MY_ID = DEFAULT_ID; |
| 21 | static CAN_PACKET outCp; |
21 | static CAN_PACKET outCp; |
| 22 | 22 | ||
| 23 | static void canGetPacket(void); |
23 | static void canGetPacket(void); |
| 24 | 24 | ||
| Line 144... | Line 144... | ||
| 144 | * Depends: .. |
144 | * Depends: .. |
| 145 | */ |
145 | */ |
| 146 | void canISR() |
146 | void canISR() |
| 147 | { |
147 | { |
| 148 | ClrWdt(); |
148 | ClrWdt(); |
| - | 149 | ||
| - | 150 | tickUpdate(); |
|
| 149 | 151 | ||
| 150 | if (PIR3bits.RXBnIF || PIR3bits.RXB1IF || PIR3bits.RXB0IF) |
152 | if (PIR3bits.RXBnIF || PIR3bits.RXB1IF || PIR3bits.RXB0IF) |
| 151 | { |
153 | { |
| 152 | ECANCON=(ECANCON&0b00000)|(0b10000|(CANCON&0x0F)); |
154 | ECANCON=(ECANCON&0b00000)|(0b10000|(CANCON&0x0F)); |
| 153 | if (RXB0CONbits.RXFUL) canGetPacket(); |
155 | if (RXB0CONbits.RXFUL) canGetPacket(); |
| 154 | 156 | ||
| 155 | if (PIR3bits.RXBnIF) {PIR3bits.RXBnIF = 0; return;} |
157 | if (PIR3bits.RXBnIF) {PIR3bits.RXBnIF = 0; return;} |
| 156 | if (PIR3bits.RXB1IF) {PIR3bits.RXB1IF = 0; return;} |
158 | if (PIR3bits.RXB1IF) {PIR3bits.RXB1IF = 0; return;} |
| 157 | if (PIR3bits.RXB0IF) {PIR3bits.RXB0IF = 0; return;} |
159 | if (PIR3bits.RXB0IF) {PIR3bits.RXB0IF = 0; return;} |
| 158 | } |
160 | } |
| 159 | 161 | ||
| 160 | tickUpdate(); |
- | |
| 161 | 162 | ||
| - | 163 | ||
| 162 | if ((tickGet()-heartbeat)> |
164 | if ((tickGet()-heartbeat)>TICK_1S*5) |
| 163 | { |
165 | { |
| 164 | // Send alive heartbeat |
166 | // Send alive heartbeat |
| 165 | outCp.type=ptPGM; |
167 | outCp.type=ptPGM; |
| 166 | outCp.pgm.class=pcCTRL; |
168 | outCp.pgm.class=pcCTRL; |
| 167 | outCp.pgm.id=pctHEARTBEAT; |
169 | outCp.pgm.id=pctHEARTBEAT; |
| Line 264... | Line 266... | ||
| 264 | */ |
266 | */ |
| 265 | BOOL canSendMessage(CAN_PACKET cp, CAN_PRIORITY prio) |
267 | BOOL canSendMessage(CAN_PACKET cp, CAN_PRIORITY prio) |
| 266 | { |
268 | { |
| 267 | 269 | ||
| 268 | if ( TXB0CONbits.TXREQ == 0 ) { ECANCON=(ECANCON&0b00000)|0b00011; } |
270 | if ( TXB0CONbits.TXREQ == 0 ) { ECANCON=(ECANCON&0b00000)|0b00011; } |
| 269 | if ( TXB1CONbits.TXREQ == 0 ) { ECANCON=(ECANCON&0b00000)|0b00100; } |
271 | else if ( TXB1CONbits.TXREQ == 0 ) { ECANCON=(ECANCON&0b00000)|0b00100; } |
| 270 | if ( TXB2CONbits.TXREQ == 0 ) { ECANCON=(ECANCON&0b00000)|0b00101; } |
272 | else if ( TXB2CONbits.TXREQ == 0 ) { ECANCON=(ECANCON&0b00000)|0b00101; } |
| 271 | // None of the transmit buffers were empty. |
273 | else { return FALSE;} // None of the transmit buffers were empty. |
| 272 | else { return FALSE;} |
- | |
| 273 | 274 | ||
| 274 | if (prio<0 || prio>3) prio = 0; |
275 | if (prio<0 || prio>3) prio = 0; |
| 275 | 276 | ||
| 276 | 277 | ||
| 277 | //RXB0SIDH 28 27 26 25 24 23 22 21 |
278 | //RXB0SIDH 28 27 26 25 24 23 22 21 |