Subversion Repositories HomeAutomation

Rev

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

Rev 260 Rev 341
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/canIR/Source/Main.c $
6
 * FileName:        $HeadURL: https://svn.auml.se/svn/HomeAutomation/trunk/EmbeddedSoftware/PIC/canIR/Source/Main.c $
7
 * Last changed:    $LastChangedDate: 2007-01-28 14:58:11 +0100 (Sun, 28 Jan 2007) $
7
 * Last changed:    $LastChangedDate: 2007-02-25 21:15:41 +0100 (Sun, 25 Feb 2007) $
8
 * By:              $LastChangedBy: johboh $
8
 * By:              $LastChangedBy: johboh $
9
 * Revision:        $Revision: 260 $
9
 * Revision:        $Revision: 341 $
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
#include <funcdefs.h>
17
#include <CAN.h>
17
#include <CAN.h>
-
 
18
#include "..\canBoot\Include\boot.h"
18
 
19
 
19
 
20
 
20
#ifdef USE_IREC
21
#ifdef USE_IREC
21
    #include <IRec.h>
22
    #include <IRec.h>
22
#endif
23
#endif
23
 
24
 
24
static void mainInit(void);
25
static void mainInit(void);
25
 
26
 
26
 
27
 
27
void main()
28
void main()
28
{
29
{
29
    static TICK t = 0;
30
    static TICK t = 0;
30
    CAN_MESSAGE outCm;
31
    CAN_PACKET outCp;
31
 
32
 
32
    // Inits
33
    // Inits
33
 
34
 
34
    mainInit();
35
    mainInit();
35
    canInit();
36
    canInit();
36
 
37
 
37
    #ifdef USE_IREC
38
    #ifdef USE_IREC
38
        irecInit();
39
        irecInit();
39
    #endif
40
    #endif
40
 
41
 
41
 
42
 
42
    while(1)
43
    while(1)
43
    {
44
    {
44
        static TICK t = 0;
45
        static TICK t = 0;
45
 
46
 
46
        if ((tickGet()-t)>TICK_SECOND)
47
        if ((tickGet()-t)>TICK_SECOND)
47
        {
48
        {
48
            LED0_IO=~LED0_IO;
49
            LED0_IO=~LED0_IO;
49
            t = tickGet();
50
            t = tickGet();
50
        }
51
        }
51
    }
52
    }
52
}
53
}
53
 
54
 
54
 
55
 
55
#pragma interrupt high_isr
56
#pragma interrupt high_isr
56
void high_isr(void)
57
void high_isr(void)
57
{
58
{
58
    canISR();
59
    canISR();
59
 
60
 
60
    #ifdef USE_IREC
61
    #ifdef USE_IREC
61
        irecISR();
62
        irecISR();
62
    #endif
63
    #endif
63
 
64
 
64
}
65
}
65
 
66
 
66
 
67
 
67
#pragma interrupt low_isr
68
#pragma interrupt low_isr
68
void low_isr(void)
69
void low_isr(void)
69
{
70
{
70
 
71
 
71
}
72
}
72
 
73
 
73
 
74
 
74
 
75
 
75
/*
76
/*
76
*   Function: mainInit
77
*   Function: mainInit
77
*
78
*
78
*   Input:  none
79
*   Input:  none
79
*   Output: none
80
*   Output: none
80
*   Pre-conditions: none
81
*   Pre-conditions: none
81
*   Affects: Se code
82
*   Affects: Se code
82
*   Depends: none.
83
*   Depends: none.
83
*/
84
*/
84
void mainInit()
85
void mainInit()
85
{
86
{
86
    LED0_TRIS=0;   
87
    LED0_TRIS=0;   
87
 
88
 
88
    // Enable Interrupts
89
    // Enable Interrupts
89
    INTCONbits.GIEH = 1;
90
    INTCONbits.GIEH = 1;
90
    INTCONbits.GIEL = 1;
91
    INTCONbits.GIEL = 1;
91
 
92
 
92
    // Enable interrupt prirority
93
    // Enable interrupt prirority
93
    RCONbits.IPEN=1;
94
    RCONbits.IPEN=1;
94
   
95
   
95
 
96
 
96
}
97
}
97
 
98
 
98
/*
99
/*
99
*   Function: canParse
100
*   Function: canParse
100
*
101
*
101
*   Input:  Received can message
102
*   Input:  Received can message
102
*   Output: none
103
*   Output: none
103
*   Pre-conditions: canInit and received packet.
104
*   Pre-conditions: canInit and received packet.
104
*   Affects: Sensors/actuators/etc. See code.
105
*   Affects: Sensors/actuators/etc. See code.
105
*   Depends: none.
106
*   Depends: none.
106
*/
107
*/
107
 
108
 
108
void canParse(CAN_MESSAGE cm)
109
void canParse(CAN_PACKET cp)
109
{
110
{
110
    CAN_MESSAGE outCm;
-
 
111
 
111
 
112
}
112
}
113
 
113
 
114
 
114
 
115
 
115
 
116
/*
116
/*
117
*   Function: irecParse
117
*   Function: irecParse
118
*
118
*
119
*   Input:  Received IR message
119
*   Input:  Received IR message
120
*   Output: none
120
*   Output: none
121
*   Pre-conditions: irecInit
121
*   Pre-conditions: irecInit
122
*   Affects: Sensors/actuators/etc. See code.
122
*   Affects: Sensors/actuators/etc. See code.
123
*   Depends: none.
123
*   Depends: none.
124
*/
124
*/
125
#ifdef USE_IREC
125
#ifdef USE_IREC
126
void irecParse(IR_TYPE type, BYTE toggle, BYTE addr, BYTE data)
126
void irecParse(IR_TYPE type, BYTE toggle, BYTE addr, BYTE data)
127
{
127
{
128
    CAN_MESSAGE outCm;
128
    CAN_PACKET outCp;
129
    outCm.funct         = FUNCT_SENSORS;
-
 
130
    outCm.funcc         = FUNCC_SENSORS_IR;
-
 
131
    outCm.data_length   = 4;
-
 
132
    outCm.data[3]       = type;
-
 
133
    outCm.data[2]       = toggle;
-
 
134
    outCm.data[1]       = addr;
-
 
135
    outCm.data[0]       = data;
-
 
136
   
129
 
-
 
130
    outCp.type      = ptPGM;
-
 
131
    outCp.pgm.class = pcSENSOR;
-
 
132
    outCp.pgm.id    = pstIR;
-
 
133
    outCp.length    = 4;
-
 
134
    outCp.data[3]   = type;
-
 
135
    outCp.data[2]   = toggle;
-
 
136
    outCp.data[1]   = addr;
-
 
137
    outCp.data[0]   = data;
137
    while(!canSendMessage(outCm,PRIO_HIGH));
138
    while(!canSendMessage(outCp,PRIO_HIGH));
138
 
139
 
139
 
140
 
140
}
141
}
141
#endif
142
#endif
142
 
143
 
143
// Below are mandantory when using bootloader
144
// Below are mandantory when using bootloader
144
// define DEBUG_MODE to use without bootloader.
145
// define DEBUG_MODE to use without bootloader.
145
 
146
 
146
#ifndef DEBUG_MODE
147
#ifndef DEBUG_MODE
147
extern void _startup (void);
148
extern void _startup (void);
148
#pragma code _RESET_INTERRUPT_VECTOR = 0x001000
149
#pragma code _RESET_INTERRUPT_VECTOR = RM_RESET_VECTOR
149
void _reset (void)
150
void _reset (void)
150
{
151
{
151
    _asm goto _startup _endasm
152
    _asm goto _startup _endasm
152
}
153
}
153
#pragma code
154
#pragma code
154
#endif
155
#endif
155
 
156
 
156
#pragma code _HIGH_INTERRUPT_VECTOR = 0x001008
157
#pragma code _HIGH_INTERRUPT_VECTOR = RM_HIGH_INTERRUPT_VECTOR
157
void _high_ISR (void)
158
void _high_ISR (void)
158
{
159
{
159
    _asm GOTO high_isr _endasm
160
    _asm GOTO high_isr _endasm
160
}
161
}
161
#pragma code
162
#pragma code
162
 
163
 
163
#pragma code _LOW_INTERRUPT_VECTOR = 0x001018
164
#pragma code _LOW_INTERRUPT_VECTOR = RM_LOW_INTERRUPT_VECTOR
164
void _low_ISR (void)
165
void _low_ISR (void)
165
{
166
{
166
    _asm GOTO low_isr _endasm
167
    _asm GOTO low_isr _endasm
167
}
168
}
168
#pragma code
169
#pragma code
169
 
170