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

📄 cpcore.h.svn-base

📁 canpie 一个can bus的协议栈 - CAN interface for embedded control - CAN interface for PC (without local
💻 SVN-BASE
📖 第 1 页 / 共 2 页
字号:
//****************************************************************************//
// File:          cp_core.h                                                   //
// Description:                                                               //
// 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 Lesser General Public License as published   //
// by the Free Software Foundation; either version 2.1 of the License, or     //
// (at your option) any later version.                                        //
//============================================================================//
//                                                                            //
// Date        History                                                        //
// ----------  -------------------------------------------------------------- //
// 29.07.2003  Initial version                                                //
//                                                                            //
//****************************************************************************//


#ifndef  _CP_CORE_H_
#define  _CP_CORE_H_


//------------------------------------------------------------------------------
// CVS version information:
// $Id: cpcore.h,v 1.4 2005/08/15 16:28:37 microcontrol Exp $
//------------------------------------------------------------------------------


/*----------------------------------------------------------------------------*\
** Include files                                                              **
**                                                                            **
\*----------------------------------------------------------------------------*/


#include "canpie.h"


//-----------------------------------------------------------------------------
/*!   \file    cpcore.h
**    \brief   CANpie core functions
**
**
*/

/*----------------------------------------------------------------------------*\
** Definitions																						**
**                                                                            **
\*----------------------------------------------------------------------------*/


/*-------------------------------------------------------------------------
** A driver with only one channel and small memory resources does not need
** the 'channel' parameter.
** The definition CP_SMALL_CODE is checked for the value '1' and the
** function prototypes are converted then. The function call in the
** application stays the same (with 'channel' parameter).
**
*/
#if   CP_SMALL_CODE == 1

#define  CpCoreBaudrate(CH, A, B, C)         CpCoreBaudrate(A, B, C)

#define  CpCoreBufferGetData(CH, A, B)       CpCoreBufferGetData(A, B)
#define  CpCoreBufferGetDlc(CH, A, B)        CpCoreBufferGetDlc(A, B)
#define  CpCoreBufferInit(CH, A, B)         	CpCoreBufferInit(A, B)
#define  CpCoreBufferRelease(CH, A)          CpCoreBufferRelease(A)
#define  CpCoreBufferSetData(CH, A, B)       CpCoreBufferSetData(A, B)
#define  CpCoreBufferSetDlc(CH, A, B)        CpCoreBufferSetDlc(A, B)
#define  CpCoreBufferSend(CH, A)             CpCoreBufferSend(A)

#define  CpCoreCanMode(CH, A)                CpCoreCanMode(A)
#define  CpCoreCanStatus(CH, A)              CpCoreCanStatus(A)

#define  CpCoreDriverInit(CH)                CpCoreDriverInit()
#define  CpCoreDriverRelease(CH)             CpCoreDriverRelease()

#define  CpCoreFilterAll(CH, A)              CpCoreFilterAll(A)
#define  CpCoreFilterMsg(CH, A, B)           CpCoreFilterMsg(A, B)

#define  CpCoreHDI(CH, A)                    CpCoreHDI(A)

#define  CpCoreIntFunctions(CH, A, B, C)     CpCoreIntFunctions(A, B, C)

#define  CpCoreMsgRead(CH, A, B)             CpCoreMsgRead(A, B)
#define  CpCoreMsgWrite(CH, A, B)            CpCoreMsgTransmit(A, B)

#define  CpCoreRegRead(CH, A, B)             CpCoreRegRead(A, B)
#define  CpCoreRegWrite(CH, A, B)            CpCoreRegWrite(A, B)

#define  CpCoreStatistic(CH, A)					CpCoreStatistic(A)

#endif


/*----------------------------------------------------------------------------*\
** Function prototypes                                                        **
**                                                                            **
\*----------------------------------------------------------------------------*/


/*!
** \brief   Set bitrate of CAN controller
** \param   ubChannelV     CAN channel of the hardware
** \param   ubBtr0V        Value for Bit Timing Register 0
** \param   ubBtr1V        Value for Bit Timing Register 1
** \param   ubBaudSelV     Baudrate selection
**
** \return  Error code taken from the CpErr enumeration. If no error
**          occured, the function will return CpErr_OK.
**
** This function directly writes to the bit timing registers of the CAN
** controller. It is called by CpUserBaudrate() with pre-defined values
** for common baudrates. The value for the parameter ubBaudSelV is taken
** from the CP_BAUD enumeration. The values given for ubBtr0V and ubBtr1V
** are used if ubBaudSelV is set to #CP_BAUD_BTR, otherwise the correct
** bit timing is calculated internally.
**
*/
_TvCpStatus CpCoreBitrate(_TsCpPort * ptsPortV, _TsCpBitrate * ptsBitrateV);


/*!
** \brief   Get data from message buffer
** \param   ubChannelV     CAN channel of the hardware
** \param   ubBufferV      Buffer number
**
** \return  Error code taken from the CpErr enumeration
**
** This function is the fastest method to get a pointer to the
** data bytes of a CAN message. It is used in combination with
** the function CpCoreBufferSend(). The function returns a pointer
** to the first data byte inside a FullCAN message buffer. All further
** bytes can be accessed by incrementing the pointer. If the function
** call fails, the value 0L is returned.
** buffer has to be configured by a call to CpCoreAllocBuffer() before.
** In contrast to the function CpCoreBufferTransmit() no data is
** copied, which makes this function quite fast. The following
** example demonstrates the access to the data bytes of a CAN message.
** \code
**  _U08 *   pDataT;     // pointer to data
**
** //--- get pointer to data of message buffer 1 ----------
** pDataT  = CpCoreBufferData(CP_CHANNEL_1, CP_BUFFER_1);
**
** *pDataT = 0x11;      // byte 0: set to 11hex
** pDataT++;            // point to next byte
** *pDataT = 0x22;      // byte 1: set to 22hex
**
** //--- send this message out ----------------------------
** CpCoreBufferSend(CP_CHANNEL_1, CP_BUFFER_1);
** \endcode
**
*/
_TvCpStatus CpCoreBufferGetData( _TsCpPort * ptsPortV, _U08 ubBufferIdxV,
                                 _U08 * pubDataV);


/*!
** \brief   Get DLC of specified buffer
** \param   ubChannelV     CAN channel of the hardware
** \param   ubBufferV      Buffer number
** \param   pubDlcV        Data Length Code
**
** \return  Error code taken from the CpErr enumeration. If no error
**          occured, the function will return CpErr_OK.
**
** This function retrieves the Data Length Code (DLC) of the selected buffer
** ubBufferV. The DLC must be in the ra
*/
_TvCpStatus CpCoreBufferGetDlc(  _TsCpPort * ptsPortV, _U08 ubBufferIdxV,
                                 _U08 * pubDlcV);


/*!
** \brief   Allocate buffer in FullCAN controller
** \param   ubChannelV     CAN channel of the hardware
** \param   ptsCanMsgV     Pointer to a CAN message structure, the field
**                         v_MsgFlags holds the number of the message
**                         buffer inside the CAN controller
** \param   ubDirectionV   Direction of message
**
** \return  Error code taken from the #CpErr enumeration. If no error
**          occured, the function will return CpErr_OK.
**
** This function allocates the message buffer in a FullCAN controller
** (e.g. AN82527). The number of the message buffer inside the
** FullCAN controller is coded via the field v_MsgFlags in the CAN
** message structure. For message direction "Transmit" the function
** CpCoreBufferTransmit() has to be called. For message direction
** "Receive" an interrupt handler has to be configured via a
** function call to CpUserIntFunctions(). The parameter ubDirectionV
** can have the following values:
** \li CP_BUFFER_DIR_RX: receive
** \li CP_BUFFER_DIR_TX: transmit
**
*/
_TvCpStatus CpCoreBufferInit( _TsCpPort * ptsPortV, _TsCpCanMsg * ptsCanMsgV,
                              _U08 ubBufferIdxV, _U08 ubDirectionV);


/*!
** \brief   Free message buffer of FullCAN controller
** \param   ubChannelV     CAN channel of the hardware
** \param   ubMsgBufferV   requested message buffer of the CAN controller
**
** \return  Error code taken from the CpErr enumeration. If no error
**          occured, the function will return CpErr_OK.
**
*/
_TvCpStatus CpCoreBufferRelease( _TsCpPort * ptsPortV, _U08 ubBufferIdxV);


/*!
** \brief   Set data of message buffer
** \param   ubChannelV     CAN channel of the hardware
** \param   ubBufferV      Buffer number
** \param   pubDataV       Pointer to data buffer
**
** \return  Error code taken from the CpErr enumeration
**
** This function is the fastest method to set the data bytes of a CAN message.
** It can be used in combination with the function CpCoreBufferSend(). It
** will write 8 data bytes into the buffer defined by <b>ubBufferV</b>. The
** buffer has to be configured by CpCoreAllocBuffer() in advance. The size
** of the data buffer must have a size of 8 bytes.
**
** The following example demonstrates the access to the data bytes of a CAN
** message:
** \code
**  _U08 aubDataT[8];   // buffer for 8 bytes
**
** aubDataT[0] = 0x11;  // byte 0: set to 11hex
** aubDataT[1] = 0x22;  // byte 1: set to 22hex

** //--- copy the stuff to message buffer 1 ---------------
** CpCoreBufferSetData(CP_CHANNEL_1, CP_BUFFER_1, &aubDataT);
**
** //--- send this message out ----------------------------
** CpCoreBufferSend(CP_CHANNEL_1, CP_BUFFER_1);
** \endcode
**
*/
_TvCpStatus CpCoreBufferSetData( _TsCpPort * ptsPortV, _U08 ubBufferIdxV,
                                 _U08 * pubDataV);


/*!
** \brief   Set DLC of specified buffer
** \param   ubChannelV     CAN channel of the hardware
** \param   ubBufferV      Buffer number

⌨️ 快捷键说明

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