Subversion Repositories HomeAutomation

Rev

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

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