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