Subversion Repositories HomeAutomation

Rev

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