Subversion Repositories HomeAutomation

Rev

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