⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cp_msg.h.svn-base

📁 canpie 一个can bus的协议栈 - CAN interface for embedded control - CAN interface for PC (without local
💻 SVN-BASE
字号:
/*****************************************************************************\
*  CANpie                                                                     *
*                                                                             *
*  File        : cp_msg.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_MSG_H_
#define  _CP_MSG_H_


#include "canpie.h"

/*-----------------------------------------------------------------------------
**    Online documentation for Doxygen
*/

/*!
** \file    cp_msg.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 cp_msg.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;
** CpMsgClear(&myMessage);                // clear the message
** CpMsgSetStdId(&myMessage, 100, 0);     // identifier is 100 dec, no RTR
** CpMsgSetDlc(&myMessage, 2);            // data length code is 2
** CpMsgSetData(&myMessage, 0, 0x11);     // byte 0 has the value 0x11
** CpMsgSetData(&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(CpMsgIsExtended(&receiveMsg))
** {
**    //--- this is an Extended Frame ---------------------
**    DoExtendedMessageService();
**    return;
** }
**
** if(CpMsgIsRemote(&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);



/*!
** \brief   Check for remote frame
** \param   ptsCanMsgV  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);


/*!
** \brief   Clear message structure
** \param   ptsCanMsgV  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);


/*!
** \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 function sets the identifer value for an
** extended frame (CAN 2.0B).
*/
void  CpMsgSetExtId(_TsCpCanMsg * ptsCanMsgV, _U32 ulExtIdV);


/*!
** \brief   Set RTR bit
** \param   ptsCanMsgV  Pointer to a _TsCpCanMsg message
**
** This function sets the Remote Transmission bit (RTR).
*/
void  CpMsgSetRemote(_TsCpCanMsg * ptsCanMsgV);


/*!
** \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 & CP_MASK_EXT_BIT )
#define  CpMsgIsRemote(MSG_PTR)           ( (MSG_PTR)->ubMsgCtrl & CP_MASK_RTR_BIT )
#define  CpMsgIsOverrun(MSG_PTR)          ( (MSG_PTR)->ubMsgCtrl & CP_MASK_OVR_BIT )

#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 |= CP_MASK_EXT_BIT   );

#define  CpMsgSetRemote(MSG_PTR)          ( (MSG_PTR)->ubMsgCtrl |= CP_MASK_RTR_BIT   );

#define  CpMsgSetOverrun(MSG_PTR)         ( (MSG_PTR)->ubMsgCtrl |= CP_MASK_OVR_BIT   );

#define  CpMsgSetStdId(MSG_PTR, VAL)      ( (MSG_PTR)->tuMsgId.uwStd = VAL )

#endif


#endif   /* _CP_MSG_H_ */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -