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