AnsweredAssumed Answered

Using Xgate lead to the program collapse

Question asked by 赵子成 on Feb 24, 2018
Latest reply on Feb 26, 2018 by Edward Karpicz

Hi All,

 

Now I use Xgate to process the CAN interrupts. I encounter the following issues:

1、CAN port can send the frame but the content is error, Can port can reveive frame but the content is error.

2、Even worse, the program go to collapse after about 40 seconds running.

 

My SetupXGATE functin is this:

void SetupXGATE(void)
{
/* initialize the XGATE vector block and
set the XGVBR register to its start address */
XGVBR= (unsigned int)(void*__far)(XGATE_VectorTable - XGATE_VECTOR_OFFSET);
ROUTE_INTERRUPT(CAN2_RECV_VEC, 0x81);
ROUTE_INTERRUPT(CAN2_SEND_VEC, 0x81);
/* when changing your derivative to non-core3 one please remove next five lines */
XGISPSEL= 1;
XGISP31= (unsigned int)(void*__far)(XGATE_STACK_L + 1);
XGISPSEL= 2;
XGISP74= (unsigned int)(void*__far)(XGATE_STACK_H + 1);
XGISPSEL= 0;

/* enable XGATE mode and interrupts */
XGMCTL= 0xFBC1; /* XGE | XGFRZ | XGIE */

/* force execution of software trigger 0 handler */
//XGSWT= 0x0101;
}

 

The xgate vector table is like this, about CAN interrupt vector:

const XGATE_TableEntry XGATE_VectorTable[] = {

{(XGATE_Function)ISR_CAN2_Send, (int)&MyData}, // Channel 50 - CAN2 transmit
{(XGATE_Function)ISR_CAN2_Recv, (int)&MyData}, // Channel 51 - CAN2 receive

};

 

And the interrupt functions define are like this:

interrupt void ISR_CAN2_Recv(MyDataType* __restrict pData)

{

if(_ssem(CANSEMXG)) /* semaphore locked */
{
// do something
/* unlock semaphore */
_csem(CANSEMXG);
}

}

interrupt void ISR_CAN2_Send(MyDataType* __restrict pData)

{

if(_ssem(CANSEMXG)) /* semaphore locked */
{
// do something
/* unlock semaphore */
_csem(CANSEMXG);
}

}

 

In my S12X_CPU codes like this:

UINT16 CAN_Send(void)

{

do
{ /* lock semaphore */
XGSEM = SETCANSEM;
}
while(!(XGSEM_XGSEM & CANSEM));

//do something

/* unlock semaphore */
XGSEM = CLRCANSEM;

}

UINT16 CAN_Recv(void)

{

do
{ /* lock semaphore */
XGSEM = SETCANSEM;
}
while(!(XGSEM_XGSEM & CANSEM));

//do something

/* unlock semaphore */
XGSEM = CLRCANSEM;

}

 

And I define the var shared between S12X_CPU and  Xgates like this:

#pragma DATA_SEG SHARED_DATA
const ST_CAN_DIVIDE_MSG *pstCanDivideMsg[CAN_MAX_NUM];
volatile ST_CAN_PROPERTY g_astCanProp[CAN_MAX_NUM];
#pragma DATA_SEG DEFAULT

#pragma DATA_SEG SHARED_DATA
volatile ST_CAN_FRAME astRxCan2Mailbox0Buf[RX_CAN2_MAILBOX0_SIZE];
volatile ST_CAN_FRAME astRxCan2Mailbox1Buf[RX_CAN2_MAILBOX1_SIZE];

volatile ST_CAN_FRAME astTxCan2Mailbox0Buf[TX_CAN2_MAILBOX0_SIZE];
#pragma DATA_SEG DEFAULT

 

I hopes somebody can solve my confusion.

Outcomes