Hi Philipp,
following your suggestion
P.Steil wrote:you can use the example 3_TIMER as a basis.
- init the timer like in the example
- use CANRxMsg_t for the RX Queues
- create a copy of CAN_UserRead() for the CANRxMsg_t type
- add a handler for the timestamps like this:
void ISRGetTime ( CANRxMsg_t *msg)
{
// read timer register
msg->TimeStamp32 = SYSTIME_NOW;
}
I created a CAN_UserReadTS() function:
Code: Select all
// CAN_UserReadTS()
// read message with timestamp from CAN_BUSx
u32_t CAN_UserReadTS ( CANHandle_t hBus, CANRxMsg_t *pBuff)
{
u32_t ret;
CANRxMsg_t *pMsg;
ret = 0;
pMsg = CAN_RxQueueGetNext ( hBus);
if ( pMsg != NULL)
{
pBuff->Id = pMsg->Id;
pBuff->Len = pMsg->Len;
pBuff->Type = pMsg->Type;
pBuff->Data32[0] = pMsg->Data32[0];
pBuff->Data32[1] = pMsg->Data32[1];
pBuff->TimeStamp32 = pMsg->TimeStamp32;
CAN_RxQueueReadNext ( hBus);
ret = 1;
}
return ret;
}
And a timestamp handler in can_user.c
Code: Select all
// CAN_ISRGetTime()
// set timestamp in ISR for message
void CAN_ISRGetTime ( CANRxMsg_t *rxmsg)
{
// read timer register
rxmsg->TimeStamp32 = SYSTIME_NOW;
}
and enabled
Code: Select all
// timestamp incomming frames
CAN_SetTimestampHandler ( CAN_BUS1, CAN_ISRGetTime);
And now
Code: Select all
CANRxMsg_t RxMsg;
// process messages from CAN1
if ( CAN_UserReadTS ( CAN_BUS1, &RxMsg) != 0)
returns proper CAN frames with timestamps
Thanks for the hints!
Best regards,
Oliver