Subversion Repositories HomeAutomation

Rev

Rev 89 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 89 Rev 90
1
/*********************************************************************
1
/*********************************************************************
2
 *
2
 *
3
 *                  Main application
3
 *                  Main application
4
 *
4
 *
5
 *********************************************************************
5
 *********************************************************************
6
 * FileName:        $HeadURL: https://svn.auml.se/svn/HomeAutomation/trunk/EmbeddedSoftware/PIC/canBase/Source/Main.c $
6
 * FileName:        $HeadURL: https://svn.auml.se/svn/HomeAutomation/trunk/EmbeddedSoftware/PIC/canBase/Source/Main.c $
7
 * Last changed:    $LastChangedDate: 2006-11-14 11:44:48 +0100 (Tue, 14 Nov 2006) $
7
 * Last changed:    $LastChangedDate: 2006-11-14 12:49:56 +0100 (Tue, 14 Nov 2006) $
8
 * By:              $LastChangedBy: johboh $
8
 * By:              $LastChangedBy: johboh $
9
 * Revision:        $Revision: 89 $
9
 * Revision:        $Revision: 90 $
10
 ********************************************************************/
10
 ********************************************************************/
11
 
11
 
12
 
12
 
13
#include <compiler.h>
13
#include <compiler.h>
14
#include <stackTasks.h>
14
#include <stackTasks.h>
15
#include <Tick.h>
15
#include <Tick.h>
-
 
16
#include <funcdefs.h>
16
 
17
 
17
#ifdef USE_CAN
18
#ifdef USE_CAN
18
    #include <CAN.h>
19
    #include <CAN.h>
19
#endif
20
#endif
20
 
21
 
21
static void mainInit(void);
22
static void mainInit(void);
22
 
23
 
23
 
24
 
24
void main()
25
void main()
25
{
26
{
26
    static TICK t = 0;
27
    static TICK t = 0;
27
    CAN_MESSAGE cm2;
28
    CAN_MESSAGE cm2;
28
 
29
 
29
    // Inits
30
    // Inits
30
 
31
 
31
    mainInit();
32
    mainInit();
32
 
33
 
33
    #ifdef USE_CAN
34
    #ifdef USE_CAN
34
        canInit();
35
        canInit();
35
    #endif
36
    #endif
36
 
37
 
37
    tickInit();
38
    tickInit();
38
 
39
 
39
    // Dummy bootmessage
40
    // Dummy bootmessage
40
    cm2.data[0]=0x91;
41
    cm2.data[0]=0x91;
41
    cm2.data_length=1;
42
    cm2.data_length=1;
42
    canSendMessage(cm2,PRIO_HIGH);
43
    canSendMessage(cm2,PRIO_HIGH);
43
 
44
 
44
 
45
 
45
    while(1)
46
    while(1)
46
    {
47
    {
47
        static TICK t = 0;
48
        static TICK t = 0;
48
        if ((tickGet()-t)>TICK_SECOND)
49
        if ((tickGet()-t)>TICK_SECOND)
49
        {
50
        {
50
            LED0_IO=~LED0_IO;
51
            LED0_IO=~LED0_IO;
51
            t = tickGet();
52
            t = tickGet();
52
        }
53
        }
53
    }
54
    }
54
}
55
}
55
 
56
 
56
 
57
 
57
#pragma interrupt high_isr
58
#pragma interrupt high_isr
58
void high_isr(void)
59
void high_isr(void)
59
{
60
{
60
    ClrWdt();
61
    ClrWdt();
61
 
62
 
62
    #ifdef USE_CAN
63
    #ifdef USE_CAN
63
        canISR();
64
        canISR();
64
    #endif
65
    #endif
65
 
66
 
66
    tickUpdate();
67
    tickUpdate();
67
 
68
 
68
}
69
}
69
 
70
 
70
 
71
 
71
#pragma interrupt low_isr
72
#pragma interrupt low_isr
72
void low_isr(void)
73
void low_isr(void)
73
{
74
{
74
 
75
 
75
}
76
}
76
 
77
 
77
 
78
 
78
 
79
 
79
/*
80
/*
80
*   Function: mainInit
81
*   Function: mainInit
81
*
82
*
82
*   Input:  none
83
*   Input:  none
83
*   Output: none
84
*   Output: none
84
*   Pre-conditions: none
85
*   Pre-conditions: none
85
*   Affects: Se code
86
*   Affects: Se code
86
*   Depends: none.
87
*   Depends: none.
87
*/
88
*/
88
void mainInit()
89
void mainInit()
89
{
90
{
90
    LED0_TRIS=0;   
91
    LED0_TRIS=0;   
91
 
92
 
92
    // Enable Interrupts
93
    // Enable Interrupts
93
    INTCONbits.GIEH = 1;
94
    INTCONbits.GIEH = 1;
94
    INTCONbits.GIEL = 1;
95
    INTCONbits.GIEL = 1;
95
 
96
 
96
    // Enable interrupt prirority
97
    // Enable interrupt prirority
97
    RCONbits.IPEN=1;
98
    RCONbits.IPEN=1;
98
   
99
   
99
 
100
 
100
}
101
}
101
 
102
 
102
/*
103
/*
103
*   Function: canParse
104
*   Function: canParse
104
*
105
*
105
*   Input:  Received can message
106
*   Input:  Received can message
106
*   Output: none
107
*   Output: none
107
*   Pre-conditions: canInit and received packet.
108
*   Pre-conditions: canInit and received packet.
108
*   Affects: Sensors/actuators/etc. See code.
109
*   Affects: Sensors/actuators/etc. See code.
109
*   Depends: none.
110
*   Depends: none.
110
*/
111
*/
111
#ifdef USE_CAN
112
#ifdef USE_CAN
112
void canParse(CAN_MESSAGE cm)
113
void canParse(CAN_MESSAGE cm)
113
{
114
{
114
    ClrWdt();
115
    ClrWdt();
115
 
116
 
116
    switch(cm.funct)
117
    switch(cm.funct)
117
    {
118
    {
118
        case FUNCT_BOOTLOADER:
119
        case FUNCT_BOOTLOADER:
119
            if (cm.funcc==FUNCC_BOOT_INIT) { Reset(); }
120
            if (cm.funcc==FUNCC_BOOT_INIT) { Reset(); }
120
        break;
121
        break;
121
    }
122
    }
122
}
123
}
123
#endif
124
#endif
124
 
125
 
125
 
126
 
126
// Below are mandantory when using bootloader
127
// Below are mandantory when using bootloader
127
// define DEBUG_MODE to use without bootloader.
128
// define DEBUG_MODE to use without bootloader.
128
 
129
 
129
#ifndef DEBUG_MODE
130
#ifndef DEBUG_MODE
130
extern void _startup (void);
131
extern void _startup (void);
131
#pragma code _RESET_INTERRUPT_VECTOR = 0x001000
132
#pragma code _RESET_INTERRUPT_VECTOR = 0x001000
132
void _reset (void)
133
void _reset (void)
133
{
134
{
134
    _asm goto _startup _endasm
135
    _asm goto _startup _endasm
135
}
136
}
136
#pragma code
137
#pragma code
137
#endif
138
#endif
138
 
139
 
139
#pragma code _HIGH_INTERRUPT_VECTOR = 0x001008
140
#pragma code _HIGH_INTERRUPT_VECTOR = 0x001008
140
void _high_ISR (void)
141
void _high_ISR (void)
141
{
142
{
142
    _asm GOTO high_isr _endasm
143
    _asm GOTO high_isr _endasm
143
}
144
}
144
#pragma code
145
#pragma code
145
 
146
 
146
#pragma code _LOW_INTERRUPT_VECTOR = 0x001018
147
#pragma code _LOW_INTERRUPT_VECTOR = 0x001018
147
void _low_ISR (void)
148
void _low_ISR (void)
148
{
149
{
149
    _asm GOTO low_isr _endasm
150
    _asm GOTO low_isr _endasm
150
}
151
}
151
#pragma code
152
#pragma code
152
 
153