J1939 Documentation
Version 4.16.00
|
In order to create small and fast code, CANpie supplies a set of macros to access the CAN message 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 can't be used to check for value ranges or parameter consistency. Usage of macros is enabled via the symbol CP_CAN_MSG_MACRO.
Example
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_ts * | CpMsgGetTime (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) |
int32_t | CpMsgRpcGetNominalBitrate (const CpCanMsg_ts *ptsCanMsgV) |
void | CpMsgRpcSetCanMode (CpCanMsg_ts *ptsCanMsgV, uint8_t ubModeV) |
void | CpMsgRpcSetBitrate (CpCanMsg_ts *ptsCanMsgV, int32_t slNomBitRateV, int32_t slDatBitRateV) |
uint32_t | CpMsgRpcType (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) |
void CpMsgClear | ( | CpCanMsg_ts * | ptsCanMsgV | ) |
Clear message structure.
ptsCanMsgV | Pointer to a CpCanMsg_ts message |
This function sets the identifier field and the flags field of a CAN message structure to 0. It is recommended to use this function when a message structure is assigned in memory.
void CpMsgClrOverrun | ( | CpCanMsg_ts * | ptsCanMsgV | ) |
Clear Overrun bit.
ptsCanMsgV | Pointer to a CpCanMsg_ts message |
This function clears the Overrun bit (RTR).
void CpMsgClrRemote | ( | CpCanMsg_ts * | ptsCanMsgV | ) |
Clear RTR bit.
ptsCanMsgV | Pointer to a CpCanMsg_ts message |
This function clears the Remote Transmission bit (RTR).
uint8_t CpMsgDlcToSize | ( | const uint8_t | ubDlcV | ) |
Convert DLC to payload size.
ubDlcV | Data Length Code |
This function converts the DLC value to the corresponding size of the CAN message payload.
uint8_t CpMsgGetData | ( | const CpCanMsg_ts * | ptsCanMsgV, |
uint8_t | ubPosV ) |
Get Data.
ptsCanMsgV | Pointer to a CpCanMsg_ts message |
ubPosV | Zero based index of byte position |
This function retrieves the data of a CAN message. The parameter ubPosV
must be within the range 0 .. 7 for Classical CAN frames. For ISO CAN FD frames the valid range is 0 .. 63. Please note that the macro implementation does not check the value range of the parameter ubPosV
.
uint8_t CpMsgGetDlc | ( | const CpCanMsg_ts * | ptsCanMsgV | ) |
Get Data Length Code.
ptsCanMsgV | Pointer to a CpCanMsg_ts message |
This function retrieves the data length code (DLC) of a CAN message. The return value range is between 0 and 8.
uint32_t CpMsgGetExtId | ( | const CpCanMsg_ts * | ptsCanMsgV | ) |
Get 29 Bit Identifier Value.
ptsCanMsgV | Pointer to a CpCanMsg_ts message |
This function retrieves the value for the identifier of an extended frame (CAN 2.0B). The frame format of the CAN message can be tested with the CpMsgIsExtended() function.
uint32_t CpMsgGetIdentifier | ( | const CpCanMsg_ts * | ptsCanMsgV | ) |
Get Identifier Value.
ptsCanMsgV | Pointer to a CpCanMsg_ts message |
This function retrieves the value for the identifier of a CAN frame. The frame format of the CAN message can be tested with the CpMsgIsExtended() function.
uint16_t CpMsgGetStdId | ( | const CpCanMsg_ts * | ptsCanMsgV | ) |
Get 11 Bit Identifier Value.
ptsCanMsgV | Pointer to a CpCanMsg_ts message |
This macro retrieves the value for the identifier of an standard frame (CAN 2.0A). The frame format of the CAN message can be tested with the CpMsgIsExtended() function.
CpTime_ts * CpMsgGetTime | ( | CpCanMsg_ts * | ptsCanMsgV | ) |
Get time-stamp value.
ptsCanMsgV | Pointer to a CpCanMsg_ts message |
This function returns the time-stamp value for a CAN frame.
void CpMsgInit | ( | CpCanMsg_ts * | ptsCanMsgV, |
uint8_t | ubFormatV ) |
Initialise message structure.
ptsCanMsgV | Pointer to a CpCanMsg_ts message |
ubFormatV | Frame format |
This function sets the identifier field and the DLC field of a CAN message structure to 0. The parameter ubFormatV defines the frame format. Possible value are:
The contents of the data field and all other optional fields (time-stamp, user, message marker) are not altered.
bool_t CpMsgIsBitrateSwitchSet | ( | const CpCanMsg_ts * | ptsCanMsgV | ) |
Check for bit-rate.
ptsCanMsgV | Pointer to a CpCanMsg_ts message |
true
if bit-rate switch is set This function checks the frame type. If the frame is a CAN FD frame and the bit-rate switch (BRS) bit is set, the value true
is returned.
bool_t CpMsgIsExtended | ( | const CpCanMsg_ts * | ptsCanMsgV | ) |
Check for Extended CAN frame.
ptsCanMsgV | Pointer to a CpCanMsg_ts message |
true
for Extended CAN frameThis function checks the frame type. If the frame is CAN 2.0A (Standard Frame), the value false
is returned. If the frame is CAN 2.0B (Extended Frame), the value true
is returned.
bool_t CpMsgIsFdFrame | ( | const CpCanMsg_ts * | ptsCanMsgV | ) |
Check for CAN FD frame.
ptsCanMsgV | Pointer to a CpCanMsg_ts message |
true
for CAN FD frameThis function checks the frame type. If the frame is a CAN FD frame CAN 2.0B (Extended Frame), the value true
is returned.
bool_t CpMsgIsOverrun | ( | const CpCanMsg_ts * | ptsCanMsgV | ) |
Check for message overrun.
ptsCanMsgV | Pointer to a CpCanMsg_ts message |
This function checks if a data overrun has occurred for the message.
bool_t CpMsgIsRemote | ( | const CpCanMsg_ts * | ptsCanMsgV | ) |
Check for remote frame.
ptsCanMsgV | Pointer to a CpCanMsg_ts message |
This function checks if the Remote Transmission bit (RTR) is set. If the RTR bit is set, the function will return 1, otherwise 0.
bool_t CpMsgIsRpc | ( | const CpCanMsg_ts * | ptsCanMsgV | ) |
Check for Remote Procedure Call.
ptsCanMsgV | Pointer to a CpCanMsg_ts message |
This function checks if the Remote Procedure Call bit (RPC) is set. If the RPC bit is set, the function will return 1, otherwise 0.
uint8_t CpMsgRpcGetCanMode | ( | const CpCanMsg_ts * | ptsCanMsgV | ) |
Get CAN controller mode via RPC.
[in] | ptsCanMsgV | Pointer to a CpCanMsg_ts message |
This function returns the operating mode of the CAN controller which is provided via a Remote Procedure Call. Possible return values are defined in the CpMode_e enumeration.
int32_t CpMsgRpcGetDataBitrate | ( | const CpCanMsg_ts * | ptsCanMsgV | ) |
Get Data Bit Timing selection via RPC.
[in] | ptsCanMsgV | Pointer to a CpCanMsg_ts message |
This function returns the Data Bit Timing selection of the CAN controller which is provided via a Remote Procedure Call. Possible return values are defined in the CpBitrate_e enumeration.
int32_t CpMsgRpcGetNominalBitrate | ( | const CpCanMsg_ts * | ptsCanMsgV | ) |
Get Nominal Bit Timing selection via RPC.
[in] | ptsCanMsgV | Pointer to a CpCanMsg_ts message |
This function returns the Nominal Bit Timing selection of the CAN controller which is provided via a Remote Procedure Call. Possible return values are defined in the CpBitrate_e enumeration.
void CpMsgRpcSetBitrate | ( | CpCanMsg_ts * | ptsCanMsgV, |
int32_t | slNomBitRateV, | ||
int32_t | slDatBitRateV ) |
Set bit-rate of CAN controller via RPC.
[in] | ptsCanMsgV | Pointer to a CpCanMsg_ts message |
[in] | slNomBitRateV | Nominal Bit Timing selection |
[in] | slDatBitRateV | Data Bit Timing selection |
This function initializes the bit timing registers of a CAN controller to pre-defined values. The values are defined by the enumeration CpBitrate_e.
void CpMsgRpcSetCanMode | ( | CpCanMsg_ts * | ptsCanMsgV, |
uint8_t | ubModeV ) |
Set state of CAN controller via RPC.
[in] | ptsCanMsgV | Pointer to a CpCanMsg_ts message |
[in] | ubModeV | Mode selection |
This function changes the operating mode of the CAN controller FSA. Possible values for the parameter ubModeV
are defined in the CpMode_e enumeration.
uint32_t CpMsgRpcType | ( | const CpCanMsg_ts * | ptsCanMsgV | ) |
void CpMsgSetBitrateSwitch | ( | CpCanMsg_ts * | ptsCanMsgV | ) |
Set bit-rate switch.
ptsCanMsgV | Pointer to a CpCanMsg_ts message |
This function checks the frame type. If the frame is a CAN FD frame the bit-rate switch (BRS) bit is set, otherwise the bit value in the message control field is not altered.
void CpMsgSetData | ( | CpCanMsg_ts * | ptsCanMsgV, |
uint8_t | ubPosV, | ||
uint8_t | ubValueV ) |
Set Data.
ptsCanMsgV | Pointer to a CpCanMsg_ts message |
ubPosV | Zero based index of byte position |
ubValueV | Value of data byte in CAN message |
This function sets the data in a CAN message. The parameter ubPosV
must be within the range 0 .. 7 for Classical CAN frames. For ISO CAN FD frames the valid range is 0 .. 63. Please note that the macro implementation does not check the value range of the parameter ubPosV
.
void CpMsgSetDlc | ( | CpCanMsg_ts * | ptsCanMsgV, |
uint8_t | ubDlcV ) |
Set Data Length Code.
ptsCanMsgV | Pointer to a CpCanMsg_ts message |
ubDlcV | Data Length Code |
This function sets the Data Length Code (DLC) of a CAN message. The parameter ubDlcV must be within the range from 0..8. Please note that the macro implementation does not check the value range of the parameter ubDlcV
.
void CpMsgSetExtId | ( | CpCanMsg_ts * | ptsCanMsgV, |
uint32_t | ulExtIdV ) |
Set 29 Bit Identifier Value.
ptsCanMsgV | Pointer to a CpCanMsg_ts message |
ulExtIdV | Identifier value |
This function sets the identifier value for an Extended Frame (CAN 2.0B) and marks the frame format as accordingly. The value of ulExtIdV
is limited to CP_MASK_EXT_FRAME.
void CpMsgSetIdentifier | ( | CpCanMsg_ts * | ptsCanMsgV, |
uint32_t | ulIdentifierV ) |
Set Identifier Value.
ptsCanMsgV | Pointer to a CpCanMsg_ts message |
ulIdentifierV | Identifier value |
This function sets the identifier value for a CAN frame. The parameter ulIdentifierV
is truncated to a 11-bit value (AND operation with CP_MASK_STD_FRAME) when the message uses base frame format. The parameter ulIdentifierV
is truncated to a 29-bit value (AND operation with CP_MASK_EXT_FRAME) when the message uses extended frame format.
void CpMsgSetOverrun | ( | CpCanMsg_ts * | ptsCanMsgV | ) |
Set Overrun bit.
ptsCanMsgV | Pointer to a CpCanMsg_ts message |
This function sets the Overrun bit.
void CpMsgSetRemote | ( | CpCanMsg_ts * | ptsCanMsgV | ) |
Set RTR bit.
ptsCanMsgV | Pointer to a CpCanMsg_ts message |
This function sets the Remote Transmission bit (RTR).
void CpMsgSetStdId | ( | CpCanMsg_ts * | ptsCanMsgV, |
uint16_t | uwStdIdV ) |
Set 11 Bit Identifier Value.
ptsCanMsgV | Pointer to a CpCanMsg_ts message |
uwStdIdV | Identifier value |
This function sets the identifier value for a Standard frame (CAN 2.0A). The value of uwStdIdV
is limited to CP_MASK_STD_FRAME.
void CpMsgSetTime | ( | CpCanMsg_ts * | ptsCanMsgV, |
const CpTime_ts * | ptsTimeV ) |
Set time-stamp value.
ptsCanMsgV | Pointer to a CpCanMsg_ts message |
ptsTimeV | Pointer to time-stamp structure |
This function sets the time-stamp value for a CAN frame.
uint8_t CpMsgSizeToDlc | ( | uint8_t | ubSizeV | ) |
Convert CAN payload size to DLC.
ubSizeV | Size of CAN message payload in bytes |
This function converts the size of the CAN message payload into a DLC value.