CAN programming interface environment
Version 3.10
Loading...
Searching...
No Matches
cp_msg.h File Reference

Detailed Description

To create compact and fast code, CANpie supplies a set of macros to access the CAN frame structure (CpCanMsg_ts). These macros can be used instead of the functions defined in the cp_msg.h header file. However, keep in mind that macros cannot be used to check value ranges or parameter consistency. Use of macros is enabled via the symbol CP_CAN_MSG_MACRO.

Example

//----------------------------------------------------------------
// set up a CAN frame
CpCanMsg_ts myMessage;
CpMsgInit(&myMessage, CP_MSG_FORMAT_CBFF); // initialise as a classic standard CAN frame
CpMsgSetIdentifier(&myMessage, 100); // identifier is 100 (decimal)
CpMsgSetDlc(&myMessage, 2); // Data Length Code (DLC) is 2
CpMsgSetData(&myMessage, 0, 0x11); // byte 0 has the value 0x11
CpMsgSetData(&myMessage, 1, 0x22); // byte 1 has the value 0x22
//... do something with it ....
//--- evaluate whether a CAN frame was received ------------------
CpCanMsg_ts receiveMsg;
//... receive the stuff ....
if(CpMsgIsExtended(&receiveMsg))
{
//--- this is an extended frame ---------------------
DoExtendedMessageService();
return;
}
if(CpMsgIsRemote(&receiveMsg))
{
//... do something with RTR frames
}
void CpMsgSetDlc(CpCanMsg_ts *ptsCanMsgV, uint8_t ubDlcV)
void CpMsgInit(CpCanMsg_ts *ptsCanMsgV, uint8_t ubFormatV)
bool_t CpMsgIsRemote(const CpCanMsg_ts *ptsCanMsgV)
void CpMsgSetData(CpCanMsg_ts *ptsCanMsgV, uint8_t ubPosV, uint8_t ubValueV)
void CpMsgSetIdentifier(CpCanMsg_ts *ptsCanMsgV, uint32_t ulIdentifierV)
bool_t CpMsgIsExtended(const CpCanMsg_ts *ptsCanMsgV)
#define CP_MSG_FORMAT_CBFF
Definition canpie.h:406
CAN frame structure.
Definition canpie.h:986
#include "canpie.h"

Functions

void CpMsgClear (CpCanMsg_ts *ptsCanMsgV)
 
void CpMsgClrOverrun (CpCanMsg_ts *ptsCanMsgV)
 
void CpMsgClrRemote (CpCanMsg_ts *ptsCanMsgV)
 
uint8_t CpMsgDlcToSize (const uint8_t ubDlcV)
 
uint8_t CpMsgGetData (const CpCanMsg_ts *ptsCanMsgV, uint8_t ubPosV)
 
uint8_t CpMsgGetDlc (const CpCanMsg_ts *ptsCanMsgV)
 
uint32_t CpMsgGetExtId (const CpCanMsg_ts *ptsCanMsgV)
 
uint32_t CpMsgGetIdentifier (const CpCanMsg_ts *ptsCanMsgV)
 
uint16_t CpMsgGetStdId (const CpCanMsg_ts *ptsCanMsgV)
 
CpTime_tsCpMsgGetTime (CpCanMsg_ts *ptsCanMsgV)
 
void CpMsgInit (CpCanMsg_ts *ptsCanMsgV, uint8_t ubFormatV)
 
bool_t CpMsgIsBitrateSwitchSet (const CpCanMsg_ts *ptsCanMsgV)
 
bool_t CpMsgIsExtended (const CpCanMsg_ts *ptsCanMsgV)
 
bool_t CpMsgIsFdFrame (const CpCanMsg_ts *ptsCanMsgV)
 
bool_t CpMsgIsOverrun (const CpCanMsg_ts *ptsCanMsgV)
 
bool_t CpMsgIsRemote (const CpCanMsg_ts *ptsCanMsgV)
 
bool_t CpMsgIsRpc (const CpCanMsg_ts *ptsCanMsgV)
 
uint8_t CpMsgRpcGetCanMode (const CpCanMsg_ts *ptsCanMsgV)
 
int32_t CpMsgRpcGetDataBitrate (const CpCanMsg_ts *ptsCanMsgV)
 
void CpMsgSetBitrateSwitch (CpCanMsg_ts *ptsCanMsgV)
 
void CpMsgSetData (CpCanMsg_ts *ptsCanMsgV, uint8_t ubPosV, uint8_t ubValueV)
 
void CpMsgSetDlc (CpCanMsg_ts *ptsCanMsgV, uint8_t ubDlcV)
 
void CpMsgSetExtId (CpCanMsg_ts *ptsCanMsgV, uint32_t ulExtIdV)
 
void CpMsgSetIdentifier (CpCanMsg_ts *ptsCanMsgV, uint32_t ulIdentifierV)
 
void CpMsgSetOverrun (CpCanMsg_ts *ptsCanMsgV)
 
void CpMsgSetRemote (CpCanMsg_ts *ptsCanMsgV)
 
void CpMsgSetStdId (CpCanMsg_ts *ptsCanMsgV, uint16_t uwStdIdV)
 
void CpMsgSetTime (CpCanMsg_ts *ptsCanMsgV, const CpTime_ts *ptsTimeV)
 
uint8_t CpMsgSizeToDlc (uint8_t ubSizeV)
 

Function Documentation

◆ CpMsgClear()

void CpMsgClear ( CpCanMsg_ts * ptsCanMsgV)
Parameters
[in]ptsCanMsgVPointer to CAN frame structure

This function sets the identifier field and the flags field of a CAN frame structure to 0. It is recommended to use this function when a CAN frame structure is assigned in memory.

Deprecated
It is recommended to use CpMsgInit() for new applications.

◆ CpMsgClrOverrun()

void CpMsgClrOverrun ( CpCanMsg_ts * ptsCanMsgV)
Parameters
[in]ptsCanMsgVPointer to CAN frame structure
See also
CpMsgSetOverrun()

This function clears the Overrun bit.

◆ CpMsgClrRemote()

void CpMsgClrRemote ( CpCanMsg_ts * ptsCanMsgV)
Parameters
[in]ptsCanMsgVPointer to CAN frame structure
See also
CpMsgSetRemote()

This function clears the Remote Transmission bit (RTR).

◆ CpMsgDlcToSize()

uint8_t CpMsgDlcToSize ( const uint8_t ubDlcV)
Parameters
[in]ubDlcVData Length Code
Returns
Number of bytes in CAN payload
See also
CpMsgSizeToDlc()

This function converts the DLC value to the corresponding size of the CAN frame payload.

◆ CpMsgGetData()

uint8_t CpMsgGetData ( const CpCanMsg_ts * ptsCanMsgV,
uint8_t ubPosV )
Parameters
[in]ptsCanMsgVPointer to CAN frame structure
[in]ubPosVZero-based index of byte position
Returns
Value of data at position ubPosV

This function retrieves the data of a CAN frame. The parameter ubPosV must be within the range 0 .. 7 for Classic CAN frames. For ISO CAN FD frames the valid range is 0 .. 63. Please note that the macro implementation does not check whether the parameter ubPosV lies within the valid range.

◆ CpMsgGetDlc()

uint8_t CpMsgGetDlc ( const CpCanMsg_ts * ptsCanMsgV)
Parameters
[in]ptsCanMsgVPointer to CAN frame structure
Returns
Data Length Code (DLC) of CAN frame

This function retrieves the Data Length Code (DLC) of a CAN frame. The return value range is 0 .. 8 for Classic CAN frames and 0 .. 15 for ISO CAN FD frames.

◆ CpMsgGetExtId()

uint32_t CpMsgGetExtId ( const CpCanMsg_ts * ptsCanMsgV)
Parameters
[in]ptsCanMsgVPointer to CAN frame structure
Returns
Extended Identifier value
See also
CpMsgGetStdId()

This function retrieves the identifier value of an extended CAN frame (CAN 2.0B). The frame format can be tested using the CpMsgIsExtended() function.

Deprecated
It is recommended to use CpMsgGetIdentifier() for new applications.

◆ CpMsgGetIdentifier()

uint32_t CpMsgGetIdentifier ( const CpCanMsg_ts * ptsCanMsgV)
Parameters
[in]ptsCanMsgVPointer to CAN frame structure
Returns
Identifier value
See also
CpMsgSetIdentifier()

This function retrieves the identifier value of a CAN frame. The frame format can be tested using the CpMsgIsExtended() function.

◆ CpMsgGetStdId()

uint16_t CpMsgGetStdId ( const CpCanMsg_ts * ptsCanMsgV)
Parameters
[in]ptsCanMsgVPointer to CAN frame structure
Returns
Standard Identifier value
See also
CpMsgGetExtId()

This macro retrieves the identifier value of a standard frame (CAN 2.0A). The frame format can be tested using the CpMsgIsExtended() function.

Deprecated
It is recommended to use CpMsgGetIdentifier() for new applications.

◆ CpMsgGetTime()

CpTime_ts * CpMsgGetTime ( CpCanMsg_ts * ptsCanMsgV)
Parameters
[in]ptsCanMsgVPointer to CAN frame structure
Returns
Pointer to time-stamp structure
See also
CpMsgSetTime

This function returns the time-stamp value for a CAN frame.

◆ CpMsgInit()

void CpMsgInit ( CpCanMsg_ts * ptsCanMsgV,
uint8_t ubFormatV )
Parameters
[in]ptsCanMsgVPointer to CAN frame structure
[in]ubFormatVFrame format

This function sets the identifier field and the DLC field of a CAN frame structure to 0. The parameter ubFormatV defines the frame format. Possible values are:

The contents of the data field and all other optional fields (time-stamp, user, frame marker) are not altered.

◆ CpMsgIsBitrateSwitchSet()

bool_t CpMsgIsBitrateSwitchSet ( const CpCanMsg_ts * ptsCanMsgV)
Parameters
[in]ptsCanMsgVPointer to CAN frame structure
Returns
true if bit-rate switch is set
See also
CpMsgSetBitrateSwitch()

Returns true if the frame is a CAN FD frame and the bit-rate switch (BRS) bit is set.

◆ CpMsgIsExtended()

bool_t CpMsgIsExtended ( const CpCanMsg_ts * ptsCanMsgV)
Parameters
[in]ptsCanMsgVPointer to CAN frame structure
Returns
true for Extended CAN frame

Returns true for an extended frame format; otherwise false (base frame format).

◆ CpMsgIsFdFrame()

bool_t CpMsgIsFdFrame ( const CpCanMsg_ts * ptsCanMsgV)
Parameters
[in]ptsCanMsgVPointer to CAN frame structure
Returns
true for CAN FD frame

Returns true if the frame type is CAN FD.

◆ CpMsgIsOverrun()

bool_t CpMsgIsOverrun ( const CpCanMsg_ts * ptsCanMsgV)
Parameters
[in]ptsCanMsgVPointer to CAN frame structure
Returns
1 for data overrun, otherwise 0

This function checks whether a data overrun has occurred for the CAN frame.

◆ CpMsgIsRemote()

bool_t CpMsgIsRemote ( const CpCanMsg_ts * ptsCanMsgV)
Parameters
[in]ptsCanMsgVPointer to CAN frame structure
Returns
false for data frame, true for remote frame

This function checks whether the Remote Transmission (RTR) bit is set. If the RTR bit is set, the function returns true; otherwise false.

◆ CpMsgIsRpc()

bool_t CpMsgIsRpc ( const CpCanMsg_ts * ptsCanMsgV)
Parameters
[in]ptsCanMsgVPointer to CAN frame structure
Returns
0 for CAN frame, 1 for Remote Procedure Call

This function checks whether the Remote Procedure Call bit (RPC) is set. If the RPC bit is set, the function returns 1; otherwise 0.

◆ CpMsgRpcGetCanMode()

uint8_t CpMsgRpcGetCanMode ( const CpCanMsg_ts * ptsCanMsgV)

Get CAN controller mode via RPC.

Parameters
[in]ptsCanMsgVPointer to CAN frame structure
Returns
Mode selection

This function returns the operating mode of the CAN controller, provided via a Remote Procedure Call. Possible return values are defined in the CpMode_e enumeration.

◆ CpMsgRpcGetDataBitrate()

int32_t CpMsgRpcGetDataBitrate ( const CpCanMsg_ts * ptsCanMsgV)

Get data bit-timing selection via RPC.

Parameters
[in]ptsCanMsgVPointer to CAN frame structure
Returns
Data bit rate

This function returns the data bit-timing selection of the CAN controller, provided via a Remote Procedure Call. Possible return values are defined in the CpBitrate_e enumeration.

◆ CpMsgSetBitrateSwitch()

void CpMsgSetBitrateSwitch ( CpCanMsg_ts * ptsCanMsgV)
Parameters
[in]ptsCanMsgVPointer to CAN frame structure
See also
CpMsgIsBitrateSwitch()

Sets the bit-rate switch (BRS) bit if the CAN frame is a CAN FD frame; otherwise the frame control field is not altered.

◆ CpMsgSetData()

void CpMsgSetData ( CpCanMsg_ts * ptsCanMsgV,
uint8_t ubPosV,
uint8_t ubValueV )
Parameters
[in]ptsCanMsgVPointer to CAN frame structure
[in]ubPosVZero-based index of byte position
[in]ubValueVValue of data byte in CAN frame

This function sets the data in a CAN frame. The parameter ubPosV must be within the range 0 .. 7 for Classic CAN frames. For ISO CAN FD frames the valid range is 0 .. 63. Please note that the macro implementation does not check whether the parameter ubPosV lies within the valid range.

◆ CpMsgSetDlc()

void CpMsgSetDlc ( CpCanMsg_ts * ptsCanMsgV,
uint8_t ubDlcV )
Parameters
[in]ptsCanMsgVPointer to CAN frame structure
[in]ubDlcVData Length Code

This function sets the Data Length Code (DLC) of a CAN frame. The parameter ubDlcV must be within the range 0 .. 8 for Classic CAN frames and the range 0 .. 15 for ISO CAN FD frames.

Please note that the macro implementation does not check the value range of the parameter ubDlcV.

◆ CpMsgSetExtId()

void CpMsgSetExtId ( CpCanMsg_ts * ptsCanMsgV,
uint32_t ulExtIdV )
Parameters
[in]ptsCanMsgVPointer to CAN frame structure
[in]ulExtIdVIdentifier value
See also
CpMsgSetStdId()

This function sets the identifier value for an extended frame (CAN 2.0B).

Deprecated
It is recommended to use CpMsgSetIdentifier() for new applications.

◆ CpMsgSetIdentifier()

void CpMsgSetIdentifier ( CpCanMsg_ts * ptsCanMsgV,
uint32_t ulIdentifierV )
Parameters
[in]ptsCanMsgVPointer to CAN frame structure
[in]ulIdentifierVIdentifier value
See also
CpMsgGetIdentifier()

This function sets the identifier value for a CAN frame. The parameter ulIdentifierV is truncated to an 11-bit value (AND operation with CP_MASK_STD_FRAME) when the CAN frame is initialised as base frame format. The parameter ulIdentifierV is truncated to a 29-bit value (AND operation with CP_MASK_EXT_FRAME) when the CAN frame is initialised as extended frame format.

◆ CpMsgSetOverrun()

void CpMsgSetOverrun ( CpCanMsg_ts * ptsCanMsgV)
Parameters
[in]ptsCanMsgVPointer to CAN frame structure
See also
CpMsgClrOverrun()

This function sets the Overrun bit.

◆ CpMsgSetRemote()

void CpMsgSetRemote ( CpCanMsg_ts * ptsCanMsgV)
Parameters
[in]ptsCanMsgVPointer to CAN frame structure
See also
CpMsgClrRemote()

This function sets the Remote Transmission bit (RTR).

◆ CpMsgSetStdId()

void CpMsgSetStdId ( CpCanMsg_ts * ptsCanMsgV,
uint16_t uwStdIdV )
Parameters
[in]ptsCanMsgVPointer to CAN frame structure
[in]uwStdIdVIdentifier value
See also
CpMsgSetExtFrame()

This function sets the identifier value for a standard frame (CAN 2.0A).

Deprecated
It is recommended to use CpMsgSetIdentifier() for new applications.

◆ CpMsgSetTime()

void CpMsgSetTime ( CpCanMsg_ts * ptsCanMsgV,
const CpTime_ts * ptsTimeV )
Parameters
[in]ptsCanMsgVPointer to CAN frame structure
[in]ptsTimeVPointer to time-stamp structure

This function sets the time-stamp value for a CAN frame.

◆ CpMsgSizeToDlc()

uint8_t CpMsgSizeToDlc ( uint8_t ubSizeV)
Parameters
[in]ubSizeVSize of CAN message payload in bytes
Returns
DLC value
See also
CpMsgDlcToSize()

This function converts the size of the CAN frame payload into a DLC value.