Subversion Repositories HomeAutomation

Rev

Rev 80 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 80 Rev 88
Line 1... Line 1...
1
/*********************************************************************
1
/*********************************************************************
2
 *
2
 *
3
 *                  Main application
3
 *                  Main application
4
 *
4
 *
5
 *********************************************************************
5
 *********************************************************************
6
 * FileName:        Main.c
6
 * FileName:        $HeadURL: https://svn.auml.se/svn/HomeAutomation/trunk/EmbeddedSoftware/PIC/canBoot/Source/Main.c $
7
 *
-
 
8
 * Author               Date    Comment
7
 * Last changed:    $LastChangedDate: 2006-11-14 11:44:27 +0100 (Tue, 14 Nov 2006) $
9
 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8
 * By:              $LastChangedBy: johboh $
10
 * Johan Böhlin     21-10-06    Original        (Rev 1.0)
9
 * Revision:        $Revision: 88 $
11
 ********************************************************************/
10
 ********************************************************************/
12
// $Id: Main.c 80 2006-11-11 20:22:39Z johboh $
-
 
13
 
11
 
14
#include <compiler.h>
12
#include <compiler.h>
15
#include <stackTasks.h>
13
#include <stackTasks.h>
16
#include <CANdefs.h>
14
#include <CANdefs.h>
17
#include <CAN.h>
15
#include <CAN.h>
Line 93... Line 91...
93
        tickSubCounter++;
91
        tickSubCounter++;
94
        if (tickSubCounter>TICK_SUB_COUNTER_10MS)
92
        if (tickSubCounter>TICK_SUB_COUNTER_10MS)
95
        {
93
        {
96
            tickCounter++;
94
            tickCounter++;
97
            tickSubCounter=0;
95
            tickSubCounter=0;
-
 
96
            ClrWdt();
98
        }
97
        }
99
 
98
 
100
        switch(pgs)
99
        switch(pgs)
101
        {
100
        {
102
            case pgsWATING_START:
101
            case pgsWATING_START:
Line 126... Line 125...
126
                outCm.funct             = FUNCT_BOOTLOADER;
125
                outCm.funct             = FUNCT_BOOTLOADER;
127
                outCm.funcc             = FUNCC_BOOT_ACK;
126
                outCm.funcc             = FUNCC_BOOT_ACK;
128
                outCm.nid               = MY_NID;
127
                outCm.nid               = MY_NID;
129
                outCm.sid               = MY_ID;
128
                outCm.sid               = MY_ID;
130
                outCm.data_length       = 8;
129
                outCm.data_length       = 8;
131
                outCm.remote_request    = FALSE;
-
 
132
                outCm.data[ERR_INDEX]   = errMsg;
130
                outCm.data[ERR_INDEX]   = errMsg;
133
                t                       = tickGet();
131
                t                       = tickGet();
134
                pgs                     = afterAckPgs;
132
                pgs                     = afterAckPgs;
135
 
133
 
136
                while(!canSendMessage(outCm,PRIO_HIGH));
134
                while(!canSendMessage(outCm,PRIO_HIGH));
Line 230... Line 228...
230
            break;
228
            break;
231
 
229
 
232
 
230
 
233
            case pgsWRITE_PROGRAM:
231
            case pgsWRITE_PROGRAM:
234
 
232
 
-
 
233
                ClrWdt();
235
 
234
 
236
                // Write program and send ack.
235
                // Write program and send ack.
237
 
236
 
238
                // Check addr limit
237
                // Check addr limit
239
                if (pgmAddress<RM_RESET_VECTOR)
238
                if (pgmAddress<RM_RESET_VECTOR)
Line 490... Line 489...
490
        cm.sid=(((WORD)(RXB0EIDH & 0x01))<<8)+RXB0EIDL;
489
        cm.sid=(((WORD)(RXB0EIDH & 0x01))<<8)+RXB0EIDL;
491
 
490
 
492
 
491
 
493
        // Data length
492
        // Data length
494
        cm.data_length=(RXB0DLCbits.DLC3<<3)+(RXB0DLCbits.DLC2<<2)+(RXB0DLCbits.DLC1<<1)+RXB0DLCbits.DLC0;
493
        cm.data_length=(RXB0DLCbits.DLC3<<3)+(RXB0DLCbits.DLC2<<2)+(RXB0DLCbits.DLC1<<1)+RXB0DLCbits.DLC0;
495
 
-
 
496
        // Remote request
-
 
497
        cm.remote_request=(RXB0DLCbits.RXRTR==0?FALSE:TRUE);
-
 
498
 
494
 
499
        // Data one bye one, for speed
495
        // Data one bye one, for speed
500
        cm.data[0]=RXB0D0;  cm.data[1]=RXB0D1;
496
        cm.data[0]=RXB0D0;  cm.data[1]=RXB0D1;
501
        cm.data[2]=RXB0D2;  cm.data[3]=RXB0D3;
497
        cm.data[2]=RXB0D2;  cm.data[3]=RXB0D3;
502
        cm.data[4]=RXB0D4;  cm.data[5]=RXB0D5;
498
        cm.data[4]=RXB0D4;  cm.data[5]=RXB0D5;
Line 526... Line 522...
526
    if ( TXB2CONbits.TXREQ == 0 )  { ECANCON=(ECANCON&0b00000)|0b00101; }
522
    if ( TXB2CONbits.TXREQ == 0 )  { ECANCON=(ECANCON&0b00000)|0b00101; }
527
    // None of the transmit buffers were empty. 
523
    // None of the transmit buffers were empty. 
528
    else { return FALSE;}
524
    else { return FALSE;}
529
 
525
 
530
    if (prio<0 || prio>3) prio = 0;
526
    if (prio<0 || prio>3) prio = 0;
531
 
527
 
532
 
528
 
533
        //RXB0SIDH 28 27 26 25 24 23 22 21
529
        //RXB0SIDH 28 27 26 25 24 23 22 21
534
        //RXB0SIDL 20 19 18 xx xx xx 17 16
530
        //RXB0SIDL 20 19 18 xx xx xx 17 16
535
        //RXB0EIDH 15 14 13 12 11 10 09 08
531
        //RXB0EIDH 15 14 13 12 11 10 09 08
536
        //RXB0EIDL 07 06 05 04 03 02 01 00
532
        //RXB0EIDL 07 06 05 04 03 02 01 00
537
 
533
 
Line 547... Line 543...
547
 
543
 
548
        // Data length
544
        // Data length
549
        RXB0DLC = 0;
545
        RXB0DLC = 0;
550
        if (cm.data_length>8) RXB0DLC=8; else RXB0DLC=cm.data_length;
546
        if (cm.data_length>8) RXB0DLC=8; else RXB0DLC=cm.data_length;
551
       
547
       
552
        // Remote request
548
        // NOT Remote request
553
        if (cm.remote_request==TRUE)
-
 
554
        {
-
 
555
            _asm
-
 
556
                bsf RXB0DLC, 6, 0
-
 
557
            _endasm
-
 
558
        }
-
 
559
        else
-
 
560
        {
-
 
561
            _asm
549
        _asm
562
                bcf RXB0DLC, 6, 0
550
            bcf RXB0DLC, 6, 0
563
            _endasm
551
        _endasm
564
        }
552
 
565
 
553
 
566
        // Data one bye one, for speed
554
        // Data one bye one, for speed
567
        RXB0D0=cm.data[0];  RXB0D1=cm.data[1];
555
        RXB0D0=cm.data[0];  RXB0D1=cm.data[1];
568
        RXB0D2=cm.data[2];  RXB0D3=cm.data[3];
556
        RXB0D2=cm.data[2];  RXB0D3=cm.data[3];
569
        RXB0D4=cm.data[4];  RXB0D5=cm.data[5];
557
        RXB0D4=cm.data[4];  RXB0D5=cm.data[5];