Subversion Repositories HomeAutomation

Rev

Rev 260 | Blame | 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-02-25 21:15:41 +0100 (Sun, 25 Feb 2007) $
  8.  * By:              $LastChangedBy: johboh $
  9.  * Revision:        $Revision: 341 $
  10.  ********************************************************************/
  11.  
  12.  
  13. #include <compiler.h>
  14. #include <stackTasks.h>
  15. #include <Tick.h>
  16. #include <funcdefs.h>
  17. #include <CAN.h>
  18. #include "..\canBoot\Include\boot.h"
  19.  
  20.  
  21. #ifdef USE_IREC
  22.     #include <IRec.h>
  23. #endif
  24.  
  25. static void mainInit(void);
  26.  
  27.  
  28. void main()
  29. {
  30.     static TICK t = 0;
  31.     CAN_PACKET outCp;
  32.  
  33.     // Inits
  34.  
  35.     mainInit();
  36.     canInit();
  37.  
  38.     #ifdef USE_IREC
  39.         irecInit();
  40.     #endif
  41.  
  42.  
  43.     while(1)
  44.     {
  45.         static TICK t = 0;
  46.  
  47.         if ((tickGet()-t)>TICK_SECOND)
  48.         {
  49.             LED0_IO=~LED0_IO;
  50.             t = tickGet();
  51.         }
  52.     }
  53. }
  54.  
  55.  
  56. #pragma interrupt high_isr
  57. void high_isr(void)
  58. {
  59.     canISR();
  60.  
  61.     #ifdef USE_IREC
  62.         irecISR();
  63.     #endif
  64.  
  65. }
  66.  
  67.  
  68. #pragma interrupt low_isr
  69. void low_isr(void)
  70. {
  71.  
  72. }
  73.  
  74.  
  75.  
  76. /*
  77. *   Function: mainInit
  78. *
  79. *   Input:  none
  80. *   Output: none
  81. *   Pre-conditions: none
  82. *   Affects: Se code
  83. *   Depends: none.
  84. */
  85. void mainInit()
  86. {
  87.     LED0_TRIS=0;   
  88.  
  89.     // Enable Interrupts
  90.     INTCONbits.GIEH = 1;
  91.     INTCONbits.GIEL = 1;
  92.  
  93.     // Enable interrupt prirority
  94.     RCONbits.IPEN=1;
  95.    
  96.  
  97. }
  98.  
  99. /*
  100. *   Function: canParse
  101. *
  102. *   Input:  Received can message
  103. *   Output: none
  104. *   Pre-conditions: canInit and received packet.
  105. *   Affects: Sensors/actuators/etc. See code.
  106. *   Depends: none.
  107. */
  108.  
  109. void canParse(CAN_PACKET cp)
  110. {
  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_PACKET outCp;
  129.  
  130.     outCp.type      = ptPGM;
  131.     outCp.pgm.class = pcSENSOR;
  132.     outCp.pgm.id    = pstIR;
  133.     outCp.length    = 4;
  134.     outCp.data[3]   = type;
  135.     outCp.data[2]   = toggle;
  136.     outCp.data[1]   = addr;
  137.     outCp.data[0]   = data;
  138.     while(!canSendMessage(outCp,PRIO_HIGH));
  139.  
  140.  
  141. }
  142. #endif
  143.  
  144. // Below are mandantory when using bootloader
  145. // define DEBUG_MODE to use without bootloader.
  146.  
  147. #ifndef DEBUG_MODE
  148. extern void _startup (void);
  149. #pragma code _RESET_INTERRUPT_VECTOR = RM_RESET_VECTOR
  150. void _reset (void)
  151. {
  152.     _asm goto _startup _endasm
  153. }
  154. #pragma code
  155. #endif
  156.  
  157. #pragma code _HIGH_INTERRUPT_VECTOR = RM_HIGH_INTERRUPT_VECTOR
  158. void _high_ISR (void)
  159. {
  160.     _asm GOTO high_isr _endasm
  161. }
  162. #pragma code
  163.  
  164. #pragma code _LOW_INTERRUPT_VECTOR = RM_LOW_INTERRUPT_VECTOR
  165. void _low_ISR (void)
  166. {
  167.     _asm GOTO low_isr _endasm
  168. }
  169. #pragma code
  170.