Subversion Repositories HomeAutomation

Rev

Details | Last modification | View Log | SVN | RSS feed

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