📄 xlin_iface.c
字号:
#include "xgate_lin.h"
#include "xlin_iface.h"
/* table with addresses of the individial SCI channels */
tSCI* scip_table[]={&SCI0,&SCI1,&SCI2,&SCI3,&SCI4,&SCI5};
/* Xgate and Core need to have separate linp tables as the addresses inside them need to be specific to the particular memory map */
tLINnode* const linp_table[]={&LIN0,&LIN1,&LIN2,&LIN3,&LIN4,&LIN5};
/******************************************************************************
Function Name : SCI_Init
Engineer : r54430
Date : 24/03/2004
Parameters : None
Returns : None
Notes : SCI Initialisation function
******************************************************************************/
void SCI_Init(tU08 LINNo) {
/* resolve the sci number into SCI peripheral pointer */
tSCI* pSCI=linp_table[LINNo]->pSCI;
pSCI->scibdh.byte = 0;
pSCI->scibdl.byte = SCI_PRESCALER;
pSCI->scicr1.byte = 0;
/* Enable use of 13bit breaks & turn on shadow registers*/
pSCI->scisr2.byte = 0x84;
/* Shadow register configuration */
pSCI->sciasr1.byte = 0;
pSCI->sciacr1.byte = BERRIE; /* enable Bit Error Interrupt */
/* Enable bit error detection */
pSCI->sciacr2.byte = BERRM0;
}
/******************************************************************************
Function Name : LIN_MsgStatus0
Engineer : r54430
Date : 24/03/2004
Parameters : None
Returns : Current state of buffer
Notes : Only used when the Xgate scheduller is not used and frames are schedulled by the core
******************************************************************************/
tU08 LIN_MsgStatus(tU08 LINNo) {
/* !! no limit checking on LINNo */
tLINnode* pLIN=linp_table[LINNo]; /* resolve LIN number into pointer to LIN structure */
return(pLIN->state);
}
/******************************************************************************
Function Name : LIN_RequestMsg
Engineer : r54430
Date : 24/03/2004
Parameters : None
Returns : Current state of buffer & only queues msg if in idleState
Notes : Only used when the Xgate scheduller is not used and frames are schedulled by the core
******************************************************************************/
tU08 LIN_RequestMsg(tU08 LINNo, tU08 Id, tU08* data, tU08 dir, tU08 len) {
/* !! limits of LINNo not checked !! */
tU08 temp;
tLINnode* pLIN;
temp = LIN_MsgStatus(LINNo);
if (temp != idleState) return temp;
pLIN=linp_table[LINNo]; /* resolve LIN number into pointer to LIN structure */
/* Intialise LIN0 data structure */
pLIN->Id = Id;
pLIN->dir = dir; /* Rx= 0 ; Tx = 1 */
pLIN->len = len; /* frame length*/
pLIN->state = sendSync;
for(temp=0; temp<8; temp++) {
pLIN->data[temp] = *(data + temp);
}
/* Force SCI interrupt */
linp_table[LINNo]->pSCI->scicr2.byte = TIE|TE|RE;
return sendSync;
}
/******************************************************************************
Function Name : LIN_Init
Engineer : r54430
Date : 24/03/2004
Parameters : None
Returns : None
Notes :
******************************************************************************/
void LIN_Init(tU08 LINNo) {
/* limits of LINNo are not checked!!! */
if (LINNo == 0xFF) {
unsigned char i;
for (i=0;i<(sizeof(linp_table)/sizeof(struct LINdata*));i++) {
SCI_Init(i);
linp_table[i]->state=idleState;
linp_table[i]->pSCI=scip_table[i];
}
} else {
linp_table[LINNo]->state=idleState;
linp_table[LINNo]->timer=XLIN_TIMER_STOP;
linp_table[LINNo]->pSCI=scip_table[LINNo];
linp_table[LINNo]->frame=0;
linp_table[LINNo]->frame_time=0;
SCI_Init(LINNo);
}
/* initialise PIT Error Detect tick in case it was not initialised so far */
if (PIT.pitce.bit.pce0==0) {
PIT.pitce.bit.pce0 = 1; /* enable PIT channel 0 */
PIT.pitinte.bit.pinte0 = 1; /* enable interrupts from channel 0 */
PIT.pitmtld0.byte = 16*5-1; /* divide by 16 (SCI divides by 16 as well) and by further 5 to get interrupt every 5 bits */
PIT.pitld0.word = SCI_PRESCALER-1; /* divide by SCI prescaller */
PIT.pitcflmt.byte = PITE | PITFRZ | PFLMT0; /* enable the PIT module and force reload of the micro counter */
PIT.pitflt.bit.pflt0 = 1; /* force reload of counter 0 */
}
/* initialise PIT 1ms tick in case it was not initialised so far */
if (PIT.pitce.bit.pce1==0) {
PIT.pitce.bit.pce1 = 1; /* enable PIT channel 1 */
PIT.pitinte.bit.pinte1 = 1; /* enable interrupts from channel 1 */
PIT.pitld1.word = BUS_CLOCK/16/5-1; /* /16 & /5 because that is what the microtimer0 divides by */
PIT.pitcflmt.byte = PITE | PITFRZ | PFLMT1; /* enable the PIT module and force reload of the micro counter */
PIT.pitflt.bit.pflt1 = 1; /* force reload of counter 1 */
}
}
/******************************************************************************
Function Name : LIN0Error
Engineer : r54430
Date : 07/04/2004
Parameters : None
Returns : None
Notes :
******************************************************************************/
interrupt void LIN0Error(void) {
/* clear Xgate Channel interrupt flag */
XGATE.xgif_60 = BITB;
LIN0.state = idleState; /* ignore error and restart LIN channel */
}
/******************************************************************************
Function Name : LIN1Error
Engineer : r54430
Date : 07/04/2004
Parameters : None
Returns : None
Notes :
******************************************************************************/
interrupt void LIN1Error(void) {
/* clear Xgate Channel interrupt flag */
XGATE.xgif_60 = BITA;
LIN1.state = idleState; /* ignore error and restart LIN channel */
}
/******************************************************************************
Function Name : LIN2Error
Engineer : r54430
Date : 07/04/2004
Parameters : None
Returns : None
Notes :
******************************************************************************/
interrupt void LIN2Error(void) {
/* clear Xgate Channel interrupt flag */
XGATE.xgif_40 = BIT5;
LIN2.state = idleState; /* ignore error and restart LIN channel */
}
/******************************************************************************
Function Name : LIN3Error
Engineer : r54430
Date : 07/04/2004
Parameters : None
Returns : None
Notes :
******************************************************************************/
interrupt void LIN3Error(void) {
/* clear Xgate Channel interrupt flag */
XGATE.xgif_40 = BIT4;
LIN3.state = idleState; /* ignore error and restart LIN channel */
}
/******************************************************************************
Function Name : LIN4Error
Engineer : r54430
Date : 07/04/2004
Parameters : None
Returns : None
Notes :
******************************************************************************/
interrupt void LIN4Error(void) {
/* clear Xgate Channel interrupt flag */
XGATE.xgif_40 = BIT3;
LIN4.state = idleState; /* ignore error and restart LIN channel */
}
/******************************************************************************
Function Name : LIN5Error
Engineer : r54430
Date : 07/04/2004
Parameters : None
Returns : None
Notes :
******************************************************************************/
interrupt void LIN5Error(void) {
/* clear Xgate Channel interrupt flag */
XGATE.xgif_40 = BIT2;
LIN5.state = idleState; /* ignore error and restart LIN channel */
}
/******************************************************************************
Function Name : LIN_Timeout
Engineer : r54430
Date : 07/04/2004
Parameters : None
Returns : None
Notes :
******************************************************************************/
interrupt void LIN_Timeout(void) {
register unsigned char i;
/* clear Xgate Channel interrupt flag */
XGATE.xgif_30 = BITD;
/* scan through the LINs to see which channel has timed out */
for (i=0;i<(sizeof(linp_table)/sizeof(struct LINdata*));i++) {
if (linp_table[i]->state==rxTimeout) {
linp_table[i]->state=idleState; /* ignore error, restart LIN node */
//break; /* scan through all lins, there are uninitialised lins on Core side */
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -