Subversion Repositories HomeAutomation

Rev

Rev 125 | Rev 341 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1. /*********************************************************************
  2.  *
  3.  *                  Main application
  4.  *
  5.  *********************************************************************
  6.  * FileName:        $HeadURL: https://svn.auml.se/svn/HomeAutomation/trunk/EmbeddedSoftware/PIC/canIR/Source/Main.c $
  7.  * Last changed:    $LastChangedDate: 2007-01-28 14:58:11 +0100 (Sun, 28 Jan 2007) $
  8.  * By:              $LastChangedBy: johboh $
  9.  * Revision:        $Revision: 260 $
  10.  ********************************************************************/
  11.  
  12.  
  13. #include <compiler.h>
  14. #include <stackTasks.h>
  15. #include <Tick.h>
  16. #include <funcdefs.h>
  17. #include <CAN.h>
  18.  
  19.  
  20. #ifdef USE_IREC
  21.     #include <IRec.h>
  22. #endif
  23.  
  24. static void mainInit(void);
  25.  
  26.  
  27. void main()
  28. {
  29.     static TICK t = 0;
  30.     CAN_MESSAGE outCm;
  31.  
  32.     // Inits
  33.  
  34.     mainInit();
  35.     canInit();
  36.  
  37.     #ifdef USE_IREC
  38.         irecInit();
  39.     #endif
  40.  
  41.  
  42.     while(1)
  43.     {
  44.         static TICK t = 0;
  45.  
  46.         if ((tickGet()-t)>TICK_SECOND)
  47.         {
  48.             LED0_IO=~LED0_IO;
  49.             t = tickGet();
  50.         }
  51.     }
  52. }
  53.  
  54.  
  55. #pragma interrupt high_isr
  56. void high_isr(void)
  57. {
  58.     canISR();
  59.  
  60.     #ifdef USE_IREC
  61.         irecISR();
  62.     #endif
  63.  
  64. }
  65.  
  66.  
  67. #pragma interrupt low_isr
  68. void low_isr(void)
  69. {
  70.  
  71. }
  72.  
  73.  
  74.  
  75. /*
  76. *   Function: mainInit
  77. *
  78. *   Input:  none
  79. *   Output: none
  80. *   Pre-conditions: none
  81. *   Affects: Se code
  82. *   Depends: none.
  83. */
  84. void mainInit()
  85. {
  86.     LED0_TRIS=0;   
  87.  
  88.     // Enable Interrupts
  89.     INTCONbits.GIEH = 1;
  90.     INTCONbits.GIEL = 1;
  91.  
  92.     // Enable interrupt prirority
  93.     RCONbits.IPEN=1;
  94.    
  95.  
  96. }
  97.  
  98. /*
  99. *   Function: canParse
  100. *
  101. *   Input:  Received can message
  102. *   Output: none
  103. *   Pre-conditions: canInit and received packet.
  104. *   Affects: Sensors/actuators/etc. See code.
  105. *   Depends: none.
  106. */
  107.  
  108. void canParse(CAN_MESSAGE cm)
  109. {
  110.     CAN_MESSAGE outCm;
  111.  
  112. }
  113.  
  114.  
  115.  
  116. /*
  117. *   Function: irecParse
  118. *
  119. *   Input:  Received IR message
  120. *   Output: none
  121. *   Pre-conditions: irecInit
  122. *   Affects: Sensors/actuators/etc. See code.
  123. *   Depends: none.
  124. */
  125. #ifdef USE_IREC
  126. void irecParse(IR_TYPE type, BYTE toggle, BYTE addr, BYTE data)
  127. {
  128.     CAN_MESSAGE outCm;
  129.     outCm.funct         = FUNCT_SENSORS;
  130.     outCm.funcc         = FUNCC_SENSORS_IR;
  131.     outCm.data_length   = 4;
  132.     outCm.data[3]       = type;
  133.     outCm.data[2]       = toggle;
  134.     outCm.data[1]       = addr;
  135.     outCm.data[0]       = data;
  136.    
  137.     while(!canSendMessage(outCm,PRIO_HIGH));
  138.  
  139.  
  140. }
  141. #endif
  142.  
  143. // Below are mandantory when using bootloader
  144. // define DEBUG_MODE to use without bootloader.
  145.  
  146. #ifndef DEBUG_MODE
  147. extern void _startup (void);
  148. #pragma code _RESET_INTERRUPT_VECTOR = 0x001000
  149. void _reset (void)
  150. {
  151.     _asm goto _startup _endasm
  152. }
  153. #pragma code
  154. #endif
  155.  
  156. #pragma code _HIGH_INTERRUPT_VECTOR = 0x001008
  157. void _high_ISR (void)
  158. {
  159.     _asm GOTO high_isr _endasm
  160. }
  161. #pragma code
  162.  
  163. #pragma code _LOW_INTERRUPT_VECTOR = 0x001018
  164. void _low_ISR (void)
  165. {
  166.     _asm GOTO low_isr _endasm
  167. }
  168. #pragma code
  169.