Subversion Repositories HomeAutomation

Rev

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

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