/*********************************************************************
*
* Main application
*
*********************************************************************
* FileName: $HeadURL: https://svn.auml.se/svn/HomeAutomation/trunk/EmbeddedSoftware/PIC/canBase/Source/Main.c $
* Last changed: $LastChangedDate: 2006-11-14 10:55:38 +0100 (Tue, 14 Nov 2006) $
* By: $LastChangedBy: johboh $
* Revision: $Revision: 86 $
********************************************************************/
#include <compiler.h>
#include <stackTasks.h>
#include <Tick.h>
#ifdef USE_CAN
#include <CAN.h>
#endif
static void mainInit(void);
void main()
{
static TICK t = 0;
// Inits
mainInit();
#ifdef USE_CAN
canInit();
#endif
tickInit();
while(1)
{
static TICK t = 0;
if ((tickGet()-t)>TICK_SECOND/2)
{
LED0_IO=~LED0_IO;
}
}
}
#pragma interrupt high_isr
void high_isr(void)
{
#ifdef USE_CAN
canISR();
#endif
tickUpdate();
}
#pragma interrupt low_isr
void low_isr(void)
{
}
/*
* Function: mainInit
*
* Input: none
* Output: none
* Pre-conditions: none
* Affects: Se code
* Depends: none.
*/
void mainInit()
{
LED0_TRIS=0;
// Enable Interrupts
INTCONbits.GIEH = 1;
INTCONbits.GIEL = 1;
// Enable interrupt prirority
RCONbits.IPEN=1;
}
/*
* Function: canParse
*
* Input: Received can message
* Output: none
* Pre-conditions: canInit and received packet.
* Affects: Sensors/actuators/etc. See code.
* Depends: none.
*/
#ifdef USE_CAN
void canParse(CAN_MESSAGE cm)
{
switch(cm.funct)
{
case FUNCT_BOOTLOADER:
if (cm.funcc==FUNCC_BOOT_INIT) { _asm goto 0x0 _endasm }
break;
}
}
#endif
// Below are mandantory when using bootloader
// define DEBUG_MODE to use without bootloader.
#ifndef DEBUG_MODE
extern void _startup (void);
#pragma code _RESET_INTERRUPT_VECTOR = 0x001000
void _reset (void)
{
_asm goto _startup _endasm
}
#pragma code
#endif
#pragma code _HIGH_INTERRUPT_VECTOR = 0x001008
void _high_ISR (void)
{
_asm GOTO high_isr _endasm
}
#pragma code
#pragma code _LOW_INTERRUPT_VECTOR = 0x001018
void _low_ISR (void)
{
_asm GOTO low_isr _endasm
}
#pragma code