cpmacro.h File Reference

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.

Detailed Description

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 Documentation

#define CP_MASK_BUF_BITS   0x000000F0

Mask for buffer field in v_MsgFlags

Definition at line 138 of file cpmacro.h.

#define CP_MASK_DLC_BITS   0x0000000F

Mask for DLC field in v_MsgFlags

Definition at line 129 of file cpmacro.h.

#define CP_MASK_EXT_BIT   0x80000000

Set the EXT bit in the v_MsgId field

Definition at line 111 of file cpmacro.h.

#define CP_MASK_EXT_FRAME   0x1FFFFFFF

Mask for extended frame (29 bits)

Definition at line 102 of file cpmacro.h.

#define CP_MASK_RTR_BIT   0x40000000

Set the RTR bit in the v_MsgId field

Definition at line 120 of file cpmacro.h.

#define CP_MASK_STD_FRAME   0x000007FF

Mask for standard frame (11 bits)

Definition at line 93 of file cpmacro.h.

#define CpMacGetBufNum ( MSG_PTR   )     (_U08)(((MSG_PTR)->v_MsgFlags) >> 4)

Get message buffer number.

Parameters:
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.

Definition at line 150 of file cpmacro.h.

#define CpMacGetData ( MSG_PTR,
POS   )     ( (MSG_PTR)->v_MsgData[POS] )

Get Data.

Parameters:
MSG_PTR Pointer to a CpStruct_CAN message
POS Zero based index of byte position
See also:
The corresponding function CpMsgGetData()

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.

Parameters:
MSG_PTR Pointer to a CpStruct_CAN message
See also:
The corresponding function CpMsgGetDlc()

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.

Parameters:
MSG_PTR Pointer to a CpStruct_CAN message
See also:
The corresponding function CpMsgGetExtId()

This macro retrieves the value for the identifier of an extended frame (CAN 2.0B).

Definition at line 186 of file cpmacro.h.

#define CpMacGetStdId ( MSG_PTR   )     (_U16)(((MSG_PTR)->v_MsgId) & CP_MASK_STD_FRAME)

Get 11 Bit Identifier Value.

Parameters:
MSG_PTR Pointer to a CpStruct_CAN message
See also:
The corresponding function CpMsgGetStdId()

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.

Definition at line 199 of file cpmacro.h.

#define CpMacIsExtended ( MSG_PTR   )     (_U08)(((MSG_PTR)->v_MsgId & CP_MASK_EXT_BIT ) != 0)

Check the frame type.

Parameters:
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.

Definition at line 211 of file cpmacro.h.

#define CpMacIsRemote ( MSG_PTR   )     (_U08)(((MSG_PTR)->v_MsgId & CP_MASK_RTR_BIT) != 0)

Check for remote frame.

Parameters:
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.

Parameters:
MSG_PTR Pointer to a CpStruct_CAN message
See also:
The corresponding function CpMsgClear()

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.

Parameters:
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.

Definition at line 248 of file cpmacro.h.

#define CpMacSetData ( MSG_PTR,
POS,
VAL   )     (MSG_PTR)->v_MsgData[POS] = VAL

Set Data.

Parameters:
MSG_PTR Pointer to a CpStruct_CAN message
POS Zero based index of byte position
VAL Value of data byte in CAN message
See also:
The corresponding function CpMsgSetData()

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.

Parameters:
MSG_PTR Pointer to a CpStruct_CAN message
DLC Data length code
See also:
The corresponding function CpMsgSetDlc()

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.

Parameters:
MSG_PTR Pointer to a CpStruct_CAN message
VAL Identifier value
See also:
The corresponding function CpMsgSetExtId()

This macro sets the identifer value for an extended frame (CAN 2.0B).

Definition at line 290 of file cpmacro.h.

#define CpMacSetRemote ( MSG_PTR   )     (MSG_PTR)->v_MsgId |= CP_MASK_RTR_BIT

Set RTR bit.

Parameters:
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.

Parameters:
MSG_PTR Pointer to a CpStruct_CAN message
VAL Identifier value
See also:
The corresponding function CpMsgSetExtId()

This macro sets the identifer value for an standard frame (CAN 2.0A).

Definition at line 313 of file cpmacro.h.

Generated on Thu Dec 23 15:05:28 2010 for OrocosComponentLibrary by  doxygen 1.6.3