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