Subversion Repositories HomeAutomation

Rev

Rev 341 | 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-03-03 19:07:14 +0100 (Sat, 03 Mar 2007) $
  8.  * By:              $LastChangedBy: johboh $
  9.  * Revision:        $Revision: 353 $
  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.     // Inits
  31.     mainInit();
  32.     canInit();
  33.  
  34.     #ifdef USE_IREC
  35.         irecInit();
  36.     #endif
  37.  
  38.  
  39.     while(1)
  40.     {  
  41.         TICK currentTick = tickGet();
  42.  
  43.         static TICK tick_led = 0;
  44.  
  45.  
  46.         if ((currentTick-tick_led)>(1*TICK_1S))
  47.         {
  48.             LED0_IO=~LED0_IO;
  49.             tick_led = currentTick;
  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_PACKET cp)
  109. {
  110.  
  111. }
  112.  
  113.  
  114.  
  115. /*
  116. *   Function: irecParse
  117. *
  118. *   Input:  Received IR message
  119. *   Output: none
  120. *   Pre-conditions: irecInit
  121. *   Affects: Sensors/actuators/etc. See code.
  122. *   Depends: none.
  123. */
  124. #ifdef USE_IREC
  125. void irecParse(IR_TYPE type, BYTE toggle, BYTE addr, BYTE data)
  126. {
  127.     CAN_PACKET outCp;
  128.  
  129.     outCp.type      = ptPGM;
  130.     outCp.pgm.class = pcSENSOR;
  131.     outCp.pgm.id    = pstIR;
  132.     outCp.length    = 4;
  133.     outCp.data[3]   = type;
  134.     outCp.data[2]   = toggle;
  135.     outCp.data[1]   = addr;
  136.     outCp.data[0]   = data;
  137.     while(!canSendMessage(outCp,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 = RM_RESET_VECTOR
  149. void _reset (void)
  150. {
  151.     _asm goto _startup _endasm
  152. }
  153. #pragma code
  154. #endif
  155.  
  156. #pragma code _HIGH_INTERRUPT_VECTOR = RM_HIGH_INTERRUPT_VECTOR
  157. void _high_ISR (void)
  158. {
  159.     _asm GOTO high_isr _endasm
  160. }
  161. #pragma code
  162.  
  163. #pragma code _LOW_INTERRUPT_VECTOR = RM_LOW_INTERRUPT_VECTOR
  164. void _low_ISR (void)
  165. {
  166.     _asm GOTO low_isr _endasm
  167. }
  168. #pragma code
  169.