Subversion Repositories HomeAutomation

Rev

Rev 129 | 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/canEthernet/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. static void mainInit(void);
  21.  
  22.  
  23. void main()
  24. {
  25.     static TICK t = 0;
  26.     CAN_MESSAGE outCm;
  27.  
  28.     // Inits
  29.  
  30.     mainInit();
  31.  
  32.     canInit();
  33.  
  34.  
  35.     while(1)
  36.     {
  37.         static TICK t = 0;
  38.         static TICK heartbeat = 0;
  39.  
  40.         if ((tickGet()-t)>TICK_SECOND)
  41.         {
  42.             LED0_IO=~LED0_IO;
  43.             t = tickGet();
  44.         }
  45.     }
  46. }
  47.  
  48.  
  49. #pragma interrupt high_isr
  50. void high_isr(void)
  51. {
  52.     canISR();
  53. }
  54.  
  55.  
  56. #pragma interrupt low_isr
  57. void low_isr(void)
  58. {
  59.  
  60. }
  61.  
  62.  
  63.  
  64. /*
  65. *   Function: mainInit
  66. *
  67. *   Input:  none
  68. *   Output: none
  69. *   Pre-conditions: none
  70. *   Affects: Se code
  71. *   Depends: none.
  72. */
  73. void mainInit()
  74. {
  75.     LED0_TRIS=0;   
  76.  
  77.     // Enable Interrupts
  78.     INTCONbits.GIEH = 1;
  79.     INTCONbits.GIEL = 1;
  80.  
  81.     // Enable interrupt prirority
  82.     RCONbits.IPEN=1;
  83.    
  84.  
  85. }
  86.  
  87. /*
  88. *   Function: canParse
  89. *
  90. *   Input:  Received can message
  91. *   Output: none
  92. *   Pre-conditions: canInit and received packet.
  93. *   Affects: Sensors/actuators/etc. See code.
  94. *   Depends: none.
  95. */
  96. void canParse(CAN_MESSAGE cm)
  97. {
  98.     CAN_MESSAGE outCm;
  99.  
  100. }
  101.  
  102.  
  103. // Below are mandantory when using bootloader
  104. // define DEBUG_MODE to use without bootloader.
  105.  
  106. #ifndef DEBUG_MODE
  107. extern void _startup (void);
  108. #pragma code _RESET_INTERRUPT_VECTOR = 0x001000
  109. void _reset (void)
  110. {
  111.     _asm goto _startup _endasm
  112. }
  113. #pragma code
  114. #endif
  115.  
  116. #pragma code _HIGH_INTERRUPT_VECTOR = 0x001008
  117. void _high_ISR (void)
  118. {
  119.     _asm GOTO high_isr _endasm
  120. }
  121. #pragma code
  122.  
  123. #pragma code _LOW_INTERRUPT_VECTOR = 0x001018
  124. void _low_ISR (void)
  125. {
  126.     _asm GOTO low_isr _endasm
  127. }
  128. #pragma code
  129.