#include "compiler.h"
Go to the source code of this file.
Defines | |
| #define | CP_MASK_STD_FRAME 0x000007FF |
| #define | CP_MASK_EXT_FRAME 0x1FFFFFFF |
| #define | CP_MASK_EXT_BIT 0x80000000 |
| #define | CP_MASK_RTR_BIT 0x40000000 |
| #define | CP_MASK_DLC_BITS 0x0000000F |
| #define | CP_MASK_BUF_BITS 0x000000F0 |
| #define | CpMacGetBufNum(MSG_PTR) (_U08)(((MSG_PTR)->v_MsgFlags) >> 4) |
| Get message buffer number. | |
| #define | CpMacGetData(MSG_PTR, POS) ( (MSG_PTR)->v_MsgData[POS] ) |
| Get Data. | |
| #define | CpMacGetDlc(MSG_PTR) (_U08)(((MSG_PTR)->v_MsgFlags) & CP_MASK_DLC_BITS) |
| Get Data Length Code. | |
| #define | CpMacGetExtId(MSG_PTR) (((MSG_PTR)->v_MsgId) & CP_MASK_EXT_FRAME) |
| Get 29 Bit Identifier Value. | |
| #define | CpMacGetStdId(MSG_PTR) (_U16)(((MSG_PTR)->v_MsgId) & CP_MASK_STD_FRAME) |
| Get 11 Bit Identifier Value. | |
| #define | CpMacIsExtended(MSG_PTR) (_U08)(((MSG_PTR)->v_MsgId & CP_MASK_EXT_BIT ) != 0) |
| Check the frame type. | |
| #define | CpMacIsRemote(MSG_PTR) (_U08)(((MSG_PTR)->v_MsgId & CP_MASK_RTR_BIT) != 0) |
| Check for remote frame. | |
| #define | CpMacMsgClear(MSG_PTR) (MSG_PTR)->v_MsgId= 0;(MSG_PTR)->v_MsgFlags = 0 |
| Clear message structure. | |
| #define | CpMacSetBufNum(MSG_PTR, VAL) (MSG_PTR)->v_MsgFlags &= (~CP_MASK_BUF_BITS); (MSG_PTR)->v_MsgFlags |= (VAL << 4) |
| Set message buffer number. | |
| #define | CpMacSetData(MSG_PTR, POS, VAL) (MSG_PTR)->v_MsgData[POS] = VAL |
| Set Data. | |
| #define | CpMacSetDlc(MSG_PTR, DLC) (MSG_PTR)->v_MsgFlags &= (~CP_MASK_DLC_BITS); (MSG_PTR)->v_MsgFlags |= DLC |
| Set Data Length Code. | |
| #define | CpMacSetExtId(MSG_PTR, VAL) (MSG_PTR)->v_MsgId = VAL | CP_MASK_EXT_BIT |
| Set 29 Bit Identifier Value. | |
| #define | CpMacSetRemote(MSG_PTR) (MSG_PTR)->v_MsgId |= CP_MASK_RTR_BIT |
| Set RTR bit. | |
| #define | CpMacSetStdId(MSG_PTR, VAL) (MSG_PTR)->v_MsgId = VAL |
| Set 11 Bit Identifier Value. | |
In order to create small and fast code, CANpie supplies a set of macros to access the CAN message structure (CpStruct_CAN). These macros can be used instead of the functions defined in the cpmsg.h header file. However keep in mind that macros can't be used to check for value ranges or parameter consistence.
Example
//--- setup a CAN message ---------------------------------------- CpStruct_CAN myMessage; CpMacMsgClear(&myMessage); // clear the message CpMacSetStdId(&myMessage, 100, 0); // identifier is 100 dec, no RTR CpMacSetDlc(&myMessage, 2); // data length code is 2 CpMacSetData(&myMessage, 0, 0x11); // byte 0 has the value 0x11 CpMacSetData(&myMessage, 1, 0x22); // byte 1 has the value 0x22 //... do something with it .... //--- evaluate a message that was received ----------------------- CpStruct_CAN receiveMsg; //... receive the stuff .... if(CpMacIsExtended(&receiveMsg)) { //--- this is an Extended Frame --------------------- DoExtendedMessageService(); return; } if(CpMacIsRemote(&receiveMsg)) { //... do something with RTR frames }
Definition in file cpmacro.h.
| #define CP_MASK_BUF_BITS 0x000000F0 |
| #define CP_MASK_DLC_BITS 0x0000000F |
| #define CP_MASK_EXT_BIT 0x80000000 |
| #define CP_MASK_EXT_FRAME 0x1FFFFFFF |
| #define CP_MASK_RTR_BIT 0x40000000 |
| #define CP_MASK_STD_FRAME 0x000007FF |
| #define CpMacGetBufNum | ( | MSG_PTR | ) | (_U08)(((MSG_PTR)->v_MsgFlags) >> 4) |
Get message buffer number.
| MSG_PTR | Pointer to a CpStruct_CAN message |
| #define CpMacGetData | ( | MSG_PTR, | |||
| POS | ) | ( (MSG_PTR)->v_MsgData[POS] ) |
Get Data.
| MSG_PTR | Pointer to a CpStruct_CAN message | |
| POS | Zero based index of byte position |
Definition at line 163 of file cpmacro.h.
Referenced by CANMessage::getData().
| #define CpMacGetDlc | ( | MSG_PTR | ) | (_U08)(((MSG_PTR)->v_MsgFlags) & CP_MASK_DLC_BITS) |
Get Data Length Code.
| MSG_PTR | Pointer to a CpStruct_CAN message |
Definition at line 174 of file cpmacro.h.
Referenced by CANMessage::getDLC().
| #define CpMacGetExtId | ( | MSG_PTR | ) | (((MSG_PTR)->v_MsgId) & CP_MASK_EXT_FRAME) |
Get 29 Bit Identifier Value.
| MSG_PTR | Pointer to a CpStruct_CAN message |
| #define CpMacGetStdId | ( | MSG_PTR | ) | (_U16)(((MSG_PTR)->v_MsgId) & CP_MASK_STD_FRAME) |
Get 11 Bit Identifier Value.
| MSG_PTR | Pointer to a CpStruct_CAN message |
| #define CpMacIsExtended | ( | MSG_PTR | ) | (_U08)(((MSG_PTR)->v_MsgId & CP_MASK_EXT_BIT ) != 0) |
Check the frame type.
| MSG_PTR | Pointer to a CpStruct_CAN message |
| #define CpMacIsRemote | ( | MSG_PTR | ) | (_U08)(((MSG_PTR)->v_MsgId & CP_MASK_RTR_BIT) != 0) |
Check for remote frame.
| MSG_PTR | Pointer to a CpStruct_CAN message |
Definition at line 223 of file cpmacro.h.
Referenced by CANMessage::isRemote().
| #define CpMacMsgClear | ( | MSG_PTR | ) | (MSG_PTR)->v_MsgId= 0;(MSG_PTR)->v_MsgFlags = 0 |
Clear message structure.
| MSG_PTR | Pointer to a CpStruct_CAN message |
Definition at line 235 of file cpmacro.h.
Referenced by CANMessage::clear().
| #define CpMacSetBufNum | ( | MSG_PTR, | |||
| VAL | ) | (MSG_PTR)->v_MsgFlags &= (~CP_MASK_BUF_BITS); (MSG_PTR)->v_MsgFlags |= (VAL << 4) |
Set message buffer number.
| MSG_PTR | Pointer to a CpStruct_CAN message |
| #define CpMacSetData | ( | MSG_PTR, | |||
| POS, | |||||
| VAL | ) | (MSG_PTR)->v_MsgData[POS] = VAL |
Set Data.
| MSG_PTR | Pointer to a CpStruct_CAN message | |
| POS | Zero based index of byte position | |
| VAL | Value of data byte in CAN message |
Definition at line 263 of file cpmacro.h.
Referenced by CANMessage::setData().
| #define CpMacSetDlc | ( | MSG_PTR, | |||
| DLC | ) | (MSG_PTR)->v_MsgFlags &= (~CP_MASK_DLC_BITS); (MSG_PTR)->v_MsgFlags |= DLC |
Set Data Length Code.
| MSG_PTR | Pointer to a CpStruct_CAN message | |
| DLC | Data length code |
Definition at line 277 of file cpmacro.h.
Referenced by CANMessage::setDataDLC(), and CANMessage::setDLC().
| #define CpMacSetExtId | ( | MSG_PTR, | |||
| VAL | ) | (MSG_PTR)->v_MsgId = VAL | CP_MASK_EXT_BIT |
Set 29 Bit Identifier Value.
| MSG_PTR | Pointer to a CpStruct_CAN message | |
| VAL | Identifier value |
| #define CpMacSetRemote | ( | MSG_PTR | ) | (MSG_PTR)->v_MsgId |= CP_MASK_RTR_BIT |
Set RTR bit.
| MSG_PTR | Pointer to a CpStruct_CAN message |
Definition at line 300 of file cpmacro.h.
Referenced by CANMessage::setRemote().
| #define CpMacSetStdId | ( | MSG_PTR, | |||
| VAL | ) | (MSG_PTR)->v_MsgId = VAL |
Set 11 Bit Identifier Value.
| MSG_PTR | Pointer to a CpStruct_CAN message | |
| VAL | Identifier value |
1.5.8