|
CAN programming interface environment
Version 3.10
|
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
#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_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) |
| 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 | ) |
| [in] | ptsCanMsgV | Pointer 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.
| void CpMsgClrOverrun | ( | CpCanMsg_ts * | ptsCanMsgV | ) |
| [in] | ptsCanMsgV | Pointer to CAN frame structure |
This function clears the Overrun bit.
| void CpMsgClrRemote | ( | CpCanMsg_ts * | ptsCanMsgV | ) |
| [in] | ptsCanMsgV | Pointer to CAN frame structure |
This function clears the Remote Transmission bit (RTR).
| uint8_t CpMsgDlcToSize | ( | const uint8_t | ubDlcV | ) |
| [in] | ubDlcV | Data Length Code |
This function converts the DLC value to the corresponding size of the CAN frame payload.
| uint8_t CpMsgGetData | ( | const CpCanMsg_ts * | ptsCanMsgV, |
| uint8_t | ubPosV ) |
| [in] | ptsCanMsgV | Pointer to CAN frame structure |
| [in] | ubPosV | Zero-based index of byte position |
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.
| uint8_t CpMsgGetDlc | ( | const CpCanMsg_ts * | ptsCanMsgV | ) |
| [in] | ptsCanMsgV | Pointer to CAN frame structure |
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.
| uint32_t CpMsgGetExtId | ( | const CpCanMsg_ts * | ptsCanMsgV | ) |
| [in] | ptsCanMsgV | Pointer to CAN frame structure |
This function retrieves the identifier value of an extended CAN frame (CAN 2.0B). The frame format can be tested using the CpMsgIsExtended() function.
| uint32_t CpMsgGetIdentifier | ( | const CpCanMsg_ts * | ptsCanMsgV | ) |
| [in] | ptsCanMsgV | Pointer to CAN frame structure |
This function retrieves the identifier value of a CAN frame. The frame format can be tested using the CpMsgIsExtended() function.
| uint16_t CpMsgGetStdId | ( | const CpCanMsg_ts * | ptsCanMsgV | ) |
| [in] | ptsCanMsgV | Pointer to CAN frame structure |
This macro retrieves the identifier value of a standard frame (CAN 2.0A). The frame format can be tested using the CpMsgIsExtended() function.
| CpTime_ts * CpMsgGetTime | ( | CpCanMsg_ts * | ptsCanMsgV | ) |
| [in] | ptsCanMsgV | Pointer to CAN frame structure |
This function returns the time-stamp value for a CAN frame.
| void CpMsgInit | ( | CpCanMsg_ts * | ptsCanMsgV, |
| uint8_t | ubFormatV ) |
| [in] | ptsCanMsgV | Pointer to CAN frame structure |
| [in] | ubFormatV | Frame 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.
| bool_t CpMsgIsBitrateSwitchSet | ( | const CpCanMsg_ts * | ptsCanMsgV | ) |
| [in] | ptsCanMsgV | Pointer to CAN frame structure |
true if bit-rate switch is set Returns true if the frame is a CAN FD frame and the bit-rate switch (BRS) bit is set.
| bool_t CpMsgIsExtended | ( | const CpCanMsg_ts * | ptsCanMsgV | ) |
| [in] | ptsCanMsgV | Pointer to CAN frame structure |
true for Extended CAN frameReturns true for an extended frame format; otherwise false (base frame format).
| bool_t CpMsgIsFdFrame | ( | const CpCanMsg_ts * | ptsCanMsgV | ) |
| [in] | ptsCanMsgV | Pointer to CAN frame structure |
true for CAN FD frameReturns true if the frame type is CAN FD.
| bool_t CpMsgIsOverrun | ( | const CpCanMsg_ts * | ptsCanMsgV | ) |
| [in] | ptsCanMsgV | Pointer to CAN frame structure |
This function checks whether a data overrun has occurred for the CAN frame.
| bool_t CpMsgIsRemote | ( | const CpCanMsg_ts * | ptsCanMsgV | ) |
| [in] | ptsCanMsgV | Pointer to CAN frame structure |
false for data frame, true for remote frameThis function checks whether the Remote Transmission (RTR) bit is set. If the RTR bit is set, the function returns true; otherwise false.
| bool_t CpMsgIsRpc | ( | const CpCanMsg_ts * | ptsCanMsgV | ) |
| [in] | ptsCanMsgV | Pointer to CAN frame structure |
This function checks whether the Remote Procedure Call bit (RPC) is set. If the RPC bit is set, the function returns 1; otherwise 0.
| uint8_t CpMsgRpcGetCanMode | ( | const CpCanMsg_ts * | ptsCanMsgV | ) |
Get CAN controller mode via RPC.
| [in] | ptsCanMsgV | Pointer to CAN frame structure |
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.
| int32_t CpMsgRpcGetDataBitrate | ( | const CpCanMsg_ts * | ptsCanMsgV | ) |
Get data bit-timing selection via RPC.
| [in] | ptsCanMsgV | Pointer to CAN frame structure |
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.
| void CpMsgSetBitrateSwitch | ( | CpCanMsg_ts * | ptsCanMsgV | ) |
| [in] | ptsCanMsgV | Pointer to CAN frame structure |
Sets the bit-rate switch (BRS) bit if the CAN frame is a CAN FD frame; otherwise the frame control field is not altered.
| void CpMsgSetData | ( | CpCanMsg_ts * | ptsCanMsgV, |
| uint8_t | ubPosV, | ||
| uint8_t | ubValueV ) |
| [in] | ptsCanMsgV | Pointer to CAN frame structure |
| [in] | ubPosV | Zero-based index of byte position |
| [in] | ubValueV | Value 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.
| void CpMsgSetDlc | ( | CpCanMsg_ts * | ptsCanMsgV, |
| uint8_t | ubDlcV ) |
| [in] | ptsCanMsgV | Pointer to CAN frame structure |
| [in] | ubDlcV | Data 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.
| void CpMsgSetExtId | ( | CpCanMsg_ts * | ptsCanMsgV, |
| uint32_t | ulExtIdV ) |
| [in] | ptsCanMsgV | Pointer to CAN frame structure |
| [in] | ulExtIdV | Identifier value |
This function sets the identifier value for an extended frame (CAN 2.0B).
| void CpMsgSetIdentifier | ( | CpCanMsg_ts * | ptsCanMsgV, |
| uint32_t | ulIdentifierV ) |
| [in] | ptsCanMsgV | Pointer to CAN frame structure |
| [in] | ulIdentifierV | Identifier value |
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.
| void CpMsgSetOverrun | ( | CpCanMsg_ts * | ptsCanMsgV | ) |
| [in] | ptsCanMsgV | Pointer to CAN frame structure |
This function sets the Overrun bit.
| void CpMsgSetRemote | ( | CpCanMsg_ts * | ptsCanMsgV | ) |
| [in] | ptsCanMsgV | Pointer to CAN frame structure |
This function sets the Remote Transmission bit (RTR).
| void CpMsgSetStdId | ( | CpCanMsg_ts * | ptsCanMsgV, |
| uint16_t | uwStdIdV ) |
| [in] | ptsCanMsgV | Pointer to CAN frame structure |
| [in] | uwStdIdV | Identifier value |
This function sets the identifier value for a standard frame (CAN 2.0A).
| void CpMsgSetTime | ( | CpCanMsg_ts * | ptsCanMsgV, |
| const CpTime_ts * | ptsTimeV ) |
| [in] | ptsCanMsgV | Pointer to CAN frame structure |
| [in] | ptsTimeV | Pointer to time-stamp structure |
This function sets the time-stamp value for a CAN frame.
| uint8_t CpMsgSizeToDlc | ( | uint8_t | ubSizeV | ) |
| [in] | ubSizeV | Size of CAN message payload in bytes |
This function converts the size of the CAN frame payload into a DLC value.