AnsweredAssumed Answered

Pointer to struct for FlexCAN

Question asked by David XY Zhou on Feb 26, 2016
Latest reply on Mar 1, 2016 by David XY Zhou

volatile PMBox pTxMB= (PMBox)&(g_pCanReg->MB[TX_MB_num]);

while (1) {

   dwTxDLC = (dwTxDlen << CAN_CS_DLC_SHIFT);

   pTxMB->CS |= CAN_CS_CODE(CAN_TX_MSG_BUFFER_NOT_ACTIVE);

   pTxMB->WORD0 = dwData0++;            

   pTxMB->WORD1 = htonl(dwData1++);

   pTxMB->CS |= (CAN_CS_CODE(CAN_MESSAGE_TRANSMIT_ONCE) | dwTxDLC);

   dwRTRBit = pTxMB->CS; // check for RTR bit

   if ((dwRTRBit & CAN_CS_RTR_MASK) == CAN_CS_RTR_MASK) {  

      iRTRNotSetCount++;

   }

  else if ((dwRTRBit & CAN_CS_CODE(CAN_TX_MSG_BUFFER_NOT_ACTIVE))== CAN_CS_CODE(CAN_TX_MSG_BUFFER_NOT_ACTIVE)) {

   //Version 1

   g_pCanReg->MB[TX_MB_num].CS &= ~(CAN_CS_CODE_MASK); 

   g_pCanReg->MB[TX_MB_num].CS |= (CAN_CS_CODE(CAN_MESSAGE_TRANSMIT_RESPONED) | dwTxDLC);

   //Version 2

   //pTxMB->CS &= ~(CAN_CS_CODE_MASK); // Reset the code

   //pTxMB->CS |= (CAN_CS_CODE(CAN_MESSAGE_TRANSMIT_RESPONED) | dwTxDLC);

  //Version 3

   //pTxMB->CS = pTxMB->CS & ~(CAN_CS_CODE_MASK); // Reset the code

   //pTxMB->CS = pTxMB->CS | (CAN_CS_CODE(CAN_MESSAGE_TRANSMIT_RESPONED) | dwTxDLC);

iRTRSetCount++;

}

   // other code omitted ....

} //endof while

 

I tried three versions code as above. But only //version 1 works. I don't know why version2 and version 3 behave differently as version 1.

 

Thank you,

David Zhou

Outcomes