Subversion Repositories HomeAutomation

Rev

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

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