Subversion Repositories HomeAutomation

Rev

Rev 25 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 25 Rev 26
Line 5... Line 5...
5
 *********************************************************************
5
 *********************************************************************
6
 * FileName:        CAN.c
6
 * FileName:        CAN.c
7
 *
7
 *
8
 * Author               Date    Comment
8
 * Author               Date    Comment
9
 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9
 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10
 * Nilesh Rajbharti     8/20/01 Original        (Rev 1.0)
10
 * Johan Böhlin     21-10-06    Original        (Rev 1.0)
11
 ********************************************************************/
11
 ********************************************************************/
12
 
12
 
13
#include "../Include/CANdefs.h"
13
#include "../Include/CANdefs.h"
14
#include "../Include/stackTasks.h"
14
#include "../Include/stackTasks.h"
15
#include "../Include/CAN.h"
15
#include "../Include/CAN.h"
Line 212... Line 212...
212
*   Affects: ..
212
*   Affects: ..
213
*   Depends: ..
213
*   Depends: ..
214
*/
214
*/
215
BOOL canSendMessage(CAN_MESSAGE cm)
215
BOOL canSendMessage(CAN_MESSAGE cm)
216
{
216
{
217
 
-
 
218
 
-
 
219
 
-
 
220
    if ( TXB0CONbits.TXREQ == 0 )  { ECANCON=(ECANCON&0b00000)|0b00011; }
217
    if ( TXB0CONbits.TXREQ == 0 )  { ECANCON=(ECANCON&0b00000)|0b00011; }
221
    if ( TXB1CONbits.TXREQ == 0 )  { ECANCON=(ECANCON&0b00000)|0b00100; }
218
    if ( TXB1CONbits.TXREQ == 0 )  { ECANCON=(ECANCON&0b00000)|0b00100; }
222
    if ( TXB2CONbits.TXREQ == 0 )  { ECANCON=(ECANCON&0b00000)|0b00101; }
219
    if ( TXB2CONbits.TXREQ == 0 )  { ECANCON=(ECANCON&0b00000)|0b00101; }
223
    // None of the transmit buffers were empty. 
220
    // None of the transmit buffers were empty. 
224
    else { return FALSE;}
221
    else { return FALSE;}
225
 
222
 
226
   
-
 
227
    // Set extended mode or not.
-
 
228
    RXB0SIDLbits.EXID=(cm.extended==TRUE?1:0);
-
 
229
 
-
 
230
 
-
 
231
        if (cm.extended==TRUE)
-
 
232
        {
-
 
233
            RXB0SIDL=RXB0SIDL|0b00001000;
-
 
234
        //  _asm 
-
 
235
        //      bsf RXB0SIDL, 3, 0
-
 
236
        //  _endasm 
-
 
237
        }
-
 
238
        else
-
 
239
        {
-
 
240
            RXB0SIDL=RXB0SIDL&0b11110111;
-
 
241
        //  _asm 
-
 
242
        //      bcf RXB0SIDL, 3, 0
-
 
243
        //  _endasm 
-
 
244
        }
-
 
245
 
-
 
246
       
-
 
247
 
-
 
248
 
223
 
249
        if (cm.extended==TRUE)
224
        if (cm.extended==TRUE)
250
        {
225
        {
251
            //Write extended ident.
226
            //Write extended ident.
252
   
227
   
253
            //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
228
            //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
254
 
229
 
255
            //RXB0SIDH 28 27 26 25 24 23 22 21
230
            //RXB0SIDH 28 27 26 25 24 23 22 21
256
            //RXB0SIDL 20 19 18 xx xx xx 17 16
231
            //RXB0SIDL 20 19 18 xx xx xx 17 16
257
            //RXB0EIDH 15 14 13 12 11 10 09 08
232
            //RXB0EIDH 15 14 13 12 11 10 09 08
258
            //RXB0EIDL 07 06 05 04 03 02 01 00
233
            //RXB0EIDL 07 06 05 04 03 02 01 00
259
 
234
 
260
 
235
 
261
            RXB0SIDH =  (BYTE)((cm.ident>>21));
236
            RXB0SIDH =  (BYTE)((cm.ident>>21));
262
            RXB0SIDL = ((BYTE)(cm.ident>>16) & 0x03) + ((BYTE)(cm.ident>>13) & 0xE0);
237
            RXB0SIDL = ((BYTE)(cm.ident>>16) & 0x03) + ((BYTE)(cm.ident>>13) & 0xE0);
263
            RXB0EIDH =  (BYTE)(cm.ident>>8);
238
            RXB0EIDH =  (BYTE)(cm.ident>>8);
264
            RXB0EIDL =  (BYTE)cm.ident;
239
            RXB0EIDL =  (BYTE)cm.ident;
265
 
240
 
266
        }
241
        }
267
        else
242
        else
268
        {
243
        {
269
            //Write standard ident.
244
            //Write standard ident.
270
       
245
       
271
            //xx xx xx xx xx 10 09 08   07 06 05 04 03 02 01 00
246
            //xx xx xx xx xx 10 09 08   07 06 05 04 03 02 01 00
Line 284... Line 259...
284
        // Data one bye one, for speed
259
        // Data one bye one, for speed
285
        RXB0D0=cm.data[0];  RXB0D1=cm.data[1];
260
        RXB0D0=cm.data[0];  RXB0D1=cm.data[1];
286
        RXB0D2=cm.data[2];  RXB0D3=cm.data[3];
261
        RXB0D2=cm.data[2];  RXB0D3=cm.data[3];
287
        RXB0D4=cm.data[4];  RXB0D5=cm.data[5];
262
        RXB0D4=cm.data[4];  RXB0D5=cm.data[5];
288
        RXB0D6=cm.data[6];  RXB0D7=cm.data[7];
263
        RXB0D6=cm.data[6];  RXB0D7=cm.data[7];
-
 
264
 
-
 
265
        // set extended or not
-
 
266
        RXB0SIDLbits.EXID=(cm.extended==TRUE?1:0);
-
 
267
 
289
 
268
 
290
        // mark as redy to transmit
269
        // mark as redy to transmit
291
        _asm
270
        _asm
292
            bsf RXB0CON, 3, 0
271
            bsf RXB0CON, 3, 0
293
        _endasm
272
        _endasm