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.
Hi
One evident problem is shared pointer. You can't easily share pointers between S12X and XGATE. It's possible, but you need to have deep knowledge of how to trick them. 16bit XGATE pointer can point to RAM/registers/part of flash pages 0xE0,E1. Nonpaged S12 0x2000 is what XGATE sees at 0xE000. It may be easier to share array index instead.
Regards,
Edward