📄 cpcanmsg.h.svn-base
字号:
/*****************************************************************************\
* CANpie *
* *
* File : cpcanmsg.h *
* Description : This file supplies some support macros for access of the *
* "_TsCpCanMsg" message structure. The macros are a faster *
* solution compared to functions. However, there is the lack *
* of error checking. Please be aware of this when using these *
* macros. *
* Author : Uwe Koppe *
* e-mail : koppe@microcontrol.net *
* *
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
* *
* *
\*****************************************************************************/
#ifndef _CP_CAN_MSG_H_
#define _CP_CAN_MSG_H_
#include "canpie.h"
/*-----------------------------------------------------------------------------
** Online documentation for Doxygen
*/
/*!
** \file cpmsg.h
** \brief CANpie message access
**
** In order to create small and fast code, CANpie supplies a set of
** macros to access the CAN message structure (_TsCpCanMsg). 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. <p>
** \b Example
** \code
** //--- setup a CAN message ----------------------------------------
** _TsCpCanMsg 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 -----------------------
** _TsCpCanMsg receiveMsg;
** //... receive the stuff ....
**
** if(CpMacIsExtended(&receiveMsg))
** {
** //--- this is an Extended Frame ---------------------
** DoExtendedMessageService();
** return;
** }
**
** if(CpMacIsRemote(&receiveMsg))
** {
** //... do something with RTR frames
** }
** \endcode
*/
/*!
** \brief Get Data
** \param ptsCanMsgV Pointer to a _TsCpCanMsg message
** \param ubPosV Zero based index of byte position
**
** This functions retrieves the data of a CAN message. The parameter
** ubPosV must be within the range 0 .. 7.
*/
_U08 CpMsgGetData(_TsCpCanMsg * ptsCanMsgV, _U08 ubPosV);
/*!
** \brief Get Data Length Code
** \param ptsCanMsgV Pointer to a _TsCpCanMsg message
**
** This function retrieves the data length code (DLC) of a CAN message.
*/
_U08 CpMsgGetDlc(_TsCpCanMsg * ptsCanMsgV);
/*!
** \brief Get 29 Bit Identifier Value
** \param ptsCanMsgV Pointer to a _TsCpCanMsg message
**
** This macro retrieves the value for the identifier of an
** extended frame (CAN 2.0B).
*/
_U32 CpMsgGetExtId(_TsCpCanMsg * ptsCanMsgV);
/*!
** \brief Get 11 Bit Identifier Value
** \param ptsCanMsgV Pointer to a _TsCpCanMsg 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.
*/
_U16 CpMsgGetStdId(_TsCpCanMsg * ptsCanMsgV);
#define CpMacGetTime(MSG_PTR) ((MSG_PTR)->ulMsgTime)
/*!
** \brief Check the frame type
** \param ptsCanMsgV Pointer to a _TsCpCanMsg message
**
** This function 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), a value > 0 is returned.
*/
_U08 CpMsgIsExtended(_TsCpCanMsg * ptsCanMsgV);
/*!
** \def CpMacIsRemote(MSG_PTR)
** \brief Check for remote frame
** \param MSG_PTR Pointer to a _TsCpCanMsg 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.
*/
_U08 CpMsgIsRemote(_TsCpCanMsg * ptsCanMsgV);
/*!
** \def CpMacMsgClear(MSG_PTR)
** \brief Clear message structure
** \param MSG_PTR Pointer to a _TsCpCanMsg message
** \see The corresponding function CpMsgClear()
**
** This macro sets the identifier field and the flags field
** of a CAN message structure to 0.
*/
void CpMsgClear(_TsCpCanMsg * ptsCanMsgV);
#define CpMacMsgClear(MSG_PTR) (MSG_PTR)->ulExtId=0; \
(MSG_PTR)->ubMsgCtrl=0;
/*!
** \def CpMacSetBufNum(MSG_PTR)
** \brief Set message buffer number
** \param MSG_PTR Pointer to a _TsCpCanMsg 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 CpMacSetBufNum(MSG_PTR, VAL) (MSG_PTR)->ulMsgFlags &= (~CP_MASK_BUF_BITS); (MSG_PTR)->ulMsgFlags |= (VAL << 8)
/*!
** \brief Set Data
** \param ptsCanMsgV Pointer to a _TsCpCanMsg message
** \param ubPosV Zero based index of byte position
** \param 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.
*/
void CpMsgSetData(_TsCpCanMsg * ptsCanMsgV, _U08 ubPosV, _U08 ubValueV);
/*!
** \brief Set Data Length Code
** \param ptsCanMsgV Pointer to a _TsCpCanMsg message
** \param 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.
*/
void CpMsgSetDlc(_TsCpCanMsg * ptsCanMsgV, _U08 ubDlcV);
/*!
** \brief Set 29 Bit Identifier Value
** \param ptsCanMsgV Pointer to a _TsCpCanMsg message
** \param ulExtIdV Identifier value
**
** This macro sets the identifer value for an
** extended frame (CAN 2.0B).
*/
void CpMsgSetExtId(_TsCpCanMsg * ptsCanMsgV, _U32 ulExtIdV);
/*!
** \def CpMacSetRemote(MSG_PTR)
** \brief Set RTR bit
** \param MSG_PTR Pointer to a _TsCpCanMsg message
**
** This macro sets the Remote Transmission bit (RTR).
*/
#define CpMacSetRemote(MSG_PTR) (MSG_PTR)->ulMsgId |= CP_MASK_RTR_BIT
/*!
** \brief Set 11 Bit Identifier Value
** \param ptsCanMsgV Pointer to a _TsCpCanMsg message
** \param uwStdIdV Identifier value
**
** This function sets the identifer value for an
** standard frame (CAN 2.0A).
*/
void CpMsgSetStdId(_TsCpCanMsg * ptsCanMsgV, _U16 uwStdIdV);
#define CpMacSetTime(MSG_PTR, VAL) (MSG_PTR)->ulMsgTime = VAL
//-------------------------------------------------------------------//
// Macros for CpMsgXXX() commands //
//-------------------------------------------------------------------//
#if CP_CAN_MSG_MACRO == 1
#define CpMsgClear(MSG_PTR) ( (MSG_PTR)->ubMsgCtrl = 0); \
( (MSG_PTR)->ubMsgDLC = 0);
#define CpMsgGetData(MSG_PTR, POS) ( (MSG_PTR)->tuMsgData.aubByte[POS] )
#define CpMsgGetDlc(MSG_PTR) ( (MSG_PTR)->ubMsgDLC)
#define CpMsgGetExtId(MSG_PTR) ( (MSG_PTR)->tuMsgId.ulExt)
#define CpMsgGetStdId(MSG_PTR) ( (MSG_PTR)->tuMsgId.uwStd)
#define CpMsgIsExtended(MSG_PTR) ( (MSG_PTR)->ubMsgCtrl & 0x01 )
#define CpMsgIsRemote(MSG_PTR) ( (MSG_PTR)->ubMsgCtrl & 0x02 )
#define CpMsgSetData(MSG_PTR, POS, VAL) ( (MSG_PTR)->tuMsgData.aubByte[POS] = VAL )
#define CpMsgSetDlc(MSG_PTR, DLC) ( (MSG_PTR)->ubMsgDLC = DLC )
#define CpMsgSetExtId(MSG_PTR, VAL) ( (MSG_PTR)->tuMsgId.ulExt = VAL ); \
( (MSG_PTR)->ubMsgCtrl |= 0x01 );
#define CpMsgSetStdId(MSG_PTR, VAL) ( (MSG_PTR)->tuMsgId.uwStd = VAL )
#endif
#endif /* _CP_CAN_MSG_H_ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -