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