CANpie macros. More...
#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. |
CANpie macros.
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 |
A FullCAN controller has the feature of message buffers. The buffer number is coded in the field v_MsgFlags of the structure CpStruct_CAN. With this macro the number of the buffer (index starts at 1) can be retrieved.
#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 |
This macro retrieves the data of a CAN message. The parameter POS must be within the range 0 .. 7.
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 |
This macro retrieves the data length code (DLC) of a 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 |
This macro retrieves the value for the identifier of an extended frame (CAN 2.0B).
#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 |
This macro retrieves the value for the identifier of an standard frame (CAN 2.0A). The value is scaled to an unsigned 16 bit value.
#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 |
This macro checks the frame type. If the frame is CAN 2.0A (Standard Frame), the value 0 is returned. If the frame is CAN 2.0B (Extended Frame), the value 1 is returned.
#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 |
This macro checks if the Remote Transmission bit (RTR) is set. If the RTR bit is set, the macro will return 1, otherwise 0.
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 |
This macro sets the identifier field and the flags field of a CAN message structure to 0.
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 |
A FullCAN controller has the feature of message buffers. The buffer number is coded in the field v_MsgFlags of the structure CpStruct_CAM. With this macro the number of the buffer (index starts at 1) can be set to a certain value.
#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 |
This macro sets the data in a CAN message. The parameter POS must be within the range 0 .. 7, since there is no error checking.
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 |
This macro sets the data length code (DLC) of a CAN message. The parameter DLC must be within the range from 0..8. No error checking is provided.
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 |
This macro sets the identifer value for an extended frame (CAN 2.0B).
#define CpMacSetRemote | ( | MSG_PTR | ) | (MSG_PTR)->v_MsgId |= CP_MASK_RTR_BIT |
Set RTR bit.
MSG_PTR | Pointer to a CpStruct_CAN message |
This macro sets the Remote Transmission bit (RTR).
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 |
This macro sets the identifer value for an standard frame (CAN 2.0A).