Subversion Repositories HomeAutomation

Rev

Rev 121 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 121 Rev 122
Line 2... Line 2...
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: 2006-11-18 14:35:12 +0100 (Sat, 18 Nov 2006) $
7
 * Last changed:    $LastChangedDate: 2006-11-18 21:08:42 +0100 (Sat, 18 Nov 2006) $
8
 * By:              $LastChangedBy: johboh $
8
 * By:              $LastChangedBy: johboh $
9
 * Revision:        $Revision: 121 $
9
 * Revision:        $Revision: 122 $
10
 ********************************************************************/
10
 ********************************************************************/
11
 
11
 
12
 
12
 
13
#include <compiler.h>
13
#include <compiler.h>
14
#include <stackTasks.h>
14
#include <stackTasks.h>
Line 18... Line 18...
18
 
18
 
19
#ifdef USE_CAN
19
#ifdef USE_CAN
20
    #include <CAN.h>
20
    #include <CAN.h>
21
#endif
21
#endif
22
 
22
 
-
 
23
#ifdef USE_IREC
-
 
24
    #include <IRec.h>
-
 
25
#endif
-
 
26
 
23
static void mainInit(void);
27
static void mainInit(void);
24
 
28
 
25
 
29
 
26
static int MY_ID = DEFAULT_ID;
30
static int MY_ID = DEFAULT_ID;
27
static BYTE MY_NID = DEFAULT_NID;
31
static BYTE MY_NID = DEFAULT_NID;
28
 
32
 
29
void main()
33
void main()
30
{
34
{
31
    static TICK t = 0;
35
    static TICK t = 0;
32
    CAN_MESSAGE outCm;
36
    CAN_MESSAGE outCm;
33
 
37
 
34
    // Inits
38
    // Inits
35
 
39
 
36
    mainInit();
40
    mainInit();
37
 
41
 
38
    #ifdef USE_CAN
42
    #ifdef USE_CAN
39
        canInit();
43
        canInit();
40
    #endif
44
    #endif
-
 
45
 
-
 
46
    #ifdef USE_IREC
-
 
47
        irecInit();
-
 
48
    #endif
41
 
49
 
42
    tickInit();
50
    tickInit();
43
 
51
 
44
    // Read ID and NID if exist.
52
    // Read ID and NID if exist.
45
    if (EERead(NODE_ID_EE)==NODE_HAS_ID)
53
    if (EERead(NODE_ID_EE)==NODE_HAS_ID)
46
    {
54
    {
47
        MY_ID=(((WORD)EERead(NODE_ID_EE + 1))<<8)+EERead(NODE_ID_EE + 2);
55
        MY_ID=(((WORD)EERead(NODE_ID_EE + 1))<<8)+EERead(NODE_ID_EE + 2);
48
        MY_NID=EERead(NODE_ID_EE + 3);
56
        MY_NID=EERead(NODE_ID_EE + 3);
Line 91... Line 99...
91
{
99
{
92
    ClrWdt();
100
    ClrWdt();
93
 
101
 
94
    #ifdef USE_CAN
102
    #ifdef USE_CAN
95
        canISR();
103
        canISR();
-
 
104
    #endif
-
 
105
 
-
 
106
    #ifdef USE_IREC
-
 
107
        irecISR();
96
    #endif
108
    #endif
97
 
109
 
98
    tickUpdate();
110
    tickUpdate();
99
 
111
 
100
}
112
}
Line 118... Line 130...
118
*   Depends: none.
130
*   Depends: none.
119
*/
131
*/
120
void mainInit()
132
void mainInit()
121
{
133
{
122
    LED0_TRIS=0;   
134
    LED0_TRIS=0;   
123
 
135
 
124
    // Enable Interrupts
136
    // Enable Interrupts
125
    INTCONbits.GIEH = 1;
137
    INTCONbits.GIEH = 1;
126
    INTCONbits.GIEL = 1;
138
    INTCONbits.GIEL = 1;
127
 
139
 
128
    // Enable interrupt prirority
140
    // Enable interrupt prirority
Line 179... Line 191...
179
        break;
191
        break;
180
    }
192
    }
181
}
193
}
182
#endif
194
#endif
183
 
195
 
-
 
196
 
-
 
197
/*
-
 
198
*   Function: irecParse
-
 
199
*
-
 
200
*   Input:  Received IR message
-
 
201
*   Output: none
-
 
202
*   Pre-conditions: irecInit
-
 
203
*   Affects: Sensors/actuators/etc. See code.
-
 
204
*   Depends: none.
-
 
205
*/
-
 
206
#ifdef USE_IREC
-
 
207
void irecParse(IR_TYPE type, BYTE toggle, BYTE addr, BYTE data)
-
 
208
{
-
 
209
    CAN_MESSAGE outCm;
-
 
210
    outCm.funct         = 0x01;
-
 
211
    outCm.funcc         = 0x01;
-
 
212
    outCm.nid           = MY_NID;
-
 
213
    outCm.sid           = MY_ID;
-
 
214
    outCm.data_length   = 4;
-
 
215
    outCm.data[3]       = type;
-
 
216
    outCm.data[2]       = toggle;
-
 
217
    outCm.data[1]       = addr;
-
 
218
    outCm.data[0]       = data;
-
 
219
   
-
 
220
    while(!canSendMessage(outCm,PRIO_HIGH));
-
 
221
 
-
 
222
 
-
 
223
}
-
 
224
#endif
184
 
225
 
185
// Below are mandantory when using bootloader
226
// Below are mandantory when using bootloader
186
// define DEBUG_MODE to use without bootloader.
227
// define DEBUG_MODE to use without bootloader.
187
 
228
 
188
#ifndef DEBUG_MODE
229
#ifndef DEBUG_MODE