📄 xgisrs.cxgate
字号:
/*****************************************************
xgisrs.cxgate - implementation of all the XG ISRs
-----------------------------------------------------
*****************************************************/
#include "hidef.h" /* this file declares symbols user by the CodeWarrior environment */
#include "VTypes.h"
#include "XDP512Regs.h"
#include "Globals.h"
#include "MSCAN.h"
#include "GDIC.h"
#include "XGISRs.h"
#define LgPosMax 3240
#define SmPosMin 1080
#define LgPosMin 0
#define SmPosMax 2160
const uchar MsgIDFilterTbl[256] = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
};
#pragma MESSAGE DISABLE C5703 /* diable warning on not using the parameter of the function */
/*************************************************************************************/
ISR void XGISRError(void *dummy)
{
/* Variable Declarations */
/* Begin Function XGISRError() */
_asm("BRK"); /* any uninitialized XGate ISR puts XGate into Debug mode */
} /* end XGISRError */
/*************************************************************************************/
long XGIdleCount = 0;
long XGIdleCounter = 0;
#define MAX_BUTTONS 8
ISR void XPIT2ISR(SwLEDDataType *SwLEDData)
{
/* Variable Declarations */
uchar x;
/* Begin Function XPIT2ISR() */
XGIdleCount = XGIdleCounter;
XGIdleCounter = 0;
RegBase->PORTS &= ~0x80;
RegBase->PITTF = 0x04; /* clear the PIT channel 2 interrupt flag */
if (CalibrationPhase) return;
switch (SwLEDData->CurState) {
case UpState:
{
SwLEDData->SwMask = 0x01; /* initialize the I/O port switch mask */
SwLEDData->PortData = ~RegBase->PT1AD1; /* get the current value of the switches & invert their state */
for (x = 0; x < MAX_BUTTONS; x++) /* check to see if any of them are pressed */
if ((SwLEDData->PortData & SwLEDData->SwMask) == 0) /* this switch pressed? */
SwLEDData->SwMask <<= 1; /* no. check the next one */
else
break; /* yes. switch pressed, leave loop */
if (x != MAX_BUTTONS) /* a switch was pressed, go to the debounce down state */
SwLEDData->CurState = DBDnState;
SwLEDData->LastState = UpState;
break; /* break from case statement & return */
}
case DBDnState:
{
SwLEDData->PortData = ~RegBase->PT1AD1; /* get the current value of the switches */
if ((SwLEDData->PortData & SwLEDData->SwMask) == 0) /* this switch still pressed pressed after debounce period? */
{
SwLEDData->CurState = UpState; /* no. reset state back to up state */
break; /* break from case statement & return */
}
SwLEDData->CurState = DnState; /* set current state to down state & fall through to down state code */
SwLEDData->LastState = DBDnState;
}
case DnState:
{
RegBase->PORTS |= 0x80;
SwLEDData->PortData = ~RegBase->PT1AD1; /* get the current value of the switches */
if ((SwLEDData->PortData & SwLEDData->SwMask) == 0) /* switch still pressed pressed? */
{
SwLEDData->CurState = DBUpState; /* no. set state to debounce up state */
break; /* break from case statement & return */
}
if (SwLEDData->LastState == DBDnState)
{
RegBase->XGSWT = 0x2020; /* initiate XGate software trigger 5 to notify the HC12 */
}
switch (SwLEDData->SwMask) { /* perform action of pressed switch */
case HBSwitch:
{
if (((RegBase->PWME & 0x04) == 0) && (SwLEDData->LastState == DBDnState))
RegBase->PWME |= 0x04;
else if (((RegBase->PWME & 0x04) != 0) && (SwLEDData->LastState == DBDnState))
RegBase->PWME &= ~0x04;
break;
} /* end case HBSwitch */
case FGSwitch:
{
if (((RegBase->PWME & 0x08) == 0) && (SwLEDData->LastState == DBDnState))
RegBase->PWME |= 0x08;
else if (((RegBase->PWME & 0x08) != 0) && (SwLEDData->LastState == DBDnState))
RegBase->PWME &= ~0x08;
break;
} /* end case FGSwitch */
case LSwitch:
{
if (((RegBase->PWME & 0x01) == 0) && (SwLEDData->BlinkTime == 0))
{
RegBase->PWME |= 0x01;
SwLEDData->BlinkTime = 20;
}
else if (((RegBase->PWME & 0x01) != 0) && (SwLEDData->BlinkTime == 0))
{
RegBase->PWME &= ~0x01;
SwLEDData->BlinkTime = 20;
}
SwLEDData->BlinkTime--;
break;
} /* end case LSwitch: */
case RSwitch:
{
if (((RegBase->PWME & 0x02) == 0) && (SwLEDData->BlinkTime == 0))
{
RegBase->PWME |= 0x02;
SwLEDData->BlinkTime = 20;
}
else if (((RegBase->PWME & 0x02) != 0) && (SwLEDData->BlinkTime == 0))
{
RegBase->PWME &= ~0x02;
SwLEDData->BlinkTime = 20;
}
SwLEDData->BlinkTime--;
break;
} /* end case RSwitch */
case UpSwitch:
{
if (RegBase->PWMDTY0 < 200)
{
RegBase->PWMDTY0++;
RegBase->PWMDTY1++;
RegBase->PWMDTY2++;
RegBase->PWMDTY3++;
RegBase->PWMDTY4++;
RegBase->PWMDTY5++;
RegBase->PWMDTY6++;
RegBase->PWMDTY7++;
}
break;
} /* end case UpSwitch */
case DnSwitch:
{
if (RegBase->PWMDTY0 > 5)
{
RegBase->PWMDTY0--;
RegBase->PWMDTY1--;
RegBase->PWMDTY2--;
RegBase->PWMDTY3--;
RegBase->PWMDTY4--;
RegBase->PWMDTY5--;
RegBase->PWMDTY6--;
RegBase->PWMDTY7--;
}
break;
} /* end case DnSwitch */
} /* end switch (SwLEDData->SwMask) */
SwLEDData->LastState = DnState;
break;
} /* end case DnState */
case DBUpState:
{
SwLEDData->PortData = ~RegBase->PT1AD1; /* get the current value of the switches */
if ((~RegBase->PT1AD1 & SwLEDData->SwMask) != 0) /* switch pressed pressed after debounce up period? */
SwLEDData->CurState = DnState; /* yes. set state to down state */
else
{
if (SwLEDData->SwMask == LSwitch)
{
RegBase->PWME &= ~0x01;
SwLEDData->BlinkTime = 0;
}
else if (SwLEDData->SwMask == RSwitch)
{
RegBase->PWME &= ~0x02;
SwLEDData->BlinkTime = 0;
}
SwLEDData->CurState = UpState; /* no. set state back to up state */
}
break;
}
default:
break;
} /* end switch (SwLEDData->CurState) */
RegBase->PORTS |= 0x80;
} /* end XPIT2ISR() */
/*************************************************************************************/
ISR void XPIT1ISR(GDICDataType *GDICData)
{
/* Variable Declarations */
/* Begin Function XPIT1ISR() */
RegBase->PITTF = 0x02; /* clear the PIT channel 1 interrupt flag */
if (!CarSimulation) {
/* in demo mode all the fingers move up and down contignously without any interaction from the HC12 core */
if (GDICData->DemoPosition >= LgPosMax) {
GDICData->UpDnFlag = 1;
GDICData->DemoPosition = LgPosMax;
} else if (GDICData->DemoPosition <= 0) {
GDICData->UpDnFlag = 0;
GDICData->DemoPosition = 0;
}
if (GDICData->UpDnFlag == 0) {
GDICData->DemoPosition += 8;
} else {
GDICData->DemoPosition -= 8;
}
GDICData->FuelPosition = GDICData->DemoPosition;
GDICData->SpeedPosition = GDICData->DemoPosition;
GDICData->RPMPosition = GDICData->DemoPosition;
GDICData->CoolPosition = GDICData->DemoPosition;
}
switch (GDICData->GDICCmdState) {
case LSmallGage:
RegBase->PORTT &= ~GDICLCS; /* assert the left GDIC chip select */
GDICData->GDICCmdState++;
GDICData->GDICCmd.w[0] = 0x4000 + GDICData->FuelPosition;
break;
case LLargeGage:
RegBase->PORTT &= ~GDICLCS; /* assert the left GDIC chip select */
GDICData->GDICCmdState++;
GDICData->GDICCmd.w[0] = 0x6000 + GDICData->SpeedPosition;
break;
case RLargeGage:
RegBase->PORTT &= ~GDICRCS; /* assert the right GDIC chip select */
GDICData->GDICCmdState++;
GDICData->GDICCmd.w[0] = 0x4000 + GDICData->RPMPosition;
break;
case RSmallGage:
RegBase->PORTT &= ~GDICRCS; /* assert the right GDIC chip select */
GDICData->GDICCmdState = LSmallGage;
GDICData->GDICCmd.w[0] = 0x6000 + GDICData->CoolPosition;
break;
}
RegBase->SPI0.CR1 |= SPIE; /* enable SPI0 SPIF interrupts */
RegBase->SPI0.SR; /* read the SPI status register (don't need the value) */
RegBase->SPI0.DR = GDICData->GDICCmd.b[GDICData->CmdByteIndex]; /* send the first byte to the GDICs */
GDICData->CmdByteIndex++;
} /* end XPIT1ISR */
/*************************************************************************************/
ISR void XSPI0ISR(GDICDataType *GDICData)
{
/* Variable Declarations */
/* Begin Function XSPI0ISR() */
RegBase->SPI0.SR; /* read the SPI status register to arm the SPI transmit logic (don't need the value) */
RegBase->SPI0.DR; /* read the data register to clear the SPIF flag (don't need the value) */
if (GDICData->CmdByteIndex == 2) /* sent all bytes of command data? */
{
RegBase->SPI0.CR1 &= ~SPIE; /* done sending both bytes, disable SPIF interrupts */
RegBase->PORTT |= (GDICLCS + GDICRCS); /* negate the GDIC chip selects */
GDICData->CmdByteIndex = 0;
return;
}
RegBase->SPI0.DR = GDICData->GDICCmd.b[GDICData->CmdByteIndex]; /* send a byte to the GDICs */
GDICData->CmdByteIndex++; /* point to the next byte to send */
} /* end XSPI0ISR */
/*************************************************************************************/
ISR void XPIT0ISR(VFDDataType *VFData)
{
/* Variable Declarations */
/* Begin Function XPIT0ISR() */
RegBase->PITTF = 0x01; /* clear the PIT channel 0 interrupt flag */
RegBase->PORTT |= 0x08; /* Grid blanking signal high (disable display) */
VFData->ColumnByteCount = 16; /* number of bytes (128 bits) in 2 columns of the display */
VFData->GridByteCount = 8; /* number of bytes (64 bits) for grid data */
RegBase->TC1 = RegBase->TCNT + 12; /* set up a 2.4 uS delay on TC1 */
RegBase->TIE |= 0x02; /* enable TC1 interrupts */
} /* end XPIT0ISR */
/*************************************************************************************/
ISR void XTC1ISR(VFDDataType *VFData)
{
/* Variable Declarations */
uchar x;
/* Begin Function XTC1ISR() */
switch (VFData->BKGState) {
case 0:
{
RegBase->PORTT |= 0x04; /* pulse the LAT1, LAT2 & LATG signals high */
for (x = 0; x < 2; x++) /* 300 nS pulse */
;
RegBase->PORTT &= ~0x04; /* now back low */
RegBase->TC1 = RegBase->TC1 + 12; /* set up a 2.4 uS delay on TC1 */
VFData->BKGState = 1;
break;
}
case 1:
{
VFData->BK12State = RegBase->PORTT & 0x03; /* save the current state of BK1 & BK2 */
RegBase->PORTT |= 0x03; /* set both anode blanking signals high */
RegBase->TC1 = RegBase->TC1 + 12; /* set up a 2.4 uS delay on TC1 */
VFData->BKGState = 2;
break;
}
case 2:
{
RegBase->PORTT ^= VFData->BK12State;/* set the anode blanking signals to the opposite state of what was saved */
RegBase->TC1 = RegBase->TC1 + 12; /* set up a 2.4 uS delay on TC1 */
VFData->BKGState = 3;
break;
}
case 3:
{
RegBase->PORTT &= ~0x08; /* grid blanking signal low (enable display) */
RegBase->SPI1.CR1 |= 0x20; /* enable SPI1 transmitter interrupts */
RegBase->SPI2.CR1 |= 0x20; /* enable SPI2 transmitter interrupts */
/* fall through - no break */
}
default:
{
RegBase->TIE &= ~0x02; /* disable TC1 interrupts */
VFData->BKGState = 0;
RegBase->XGSWT = 0x4040; /* start buffer transfer task task (SW trigger 6) */
break;
}
} /* end switch (BKGState) */
} /* end XTC1ISR */
/*************************************************************************************/
ISR void XSPI1ISR(VFDDataType *VFData)
{
/* Variable Declarations */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -