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