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

📄 canpie_hal.h.svn-base

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


//------------------------------------------------------------------------------
// CVS version information:
// $Id: canpie_hal.h,v 1.2 2005/07/01 14:09:51 microcontrol Exp $
//------------------------------------------------------------------------------


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

#include <linux/list.h>

#include "canpie.h"
#include "cpfifo.h"

//-----------------------------------------------------------------------------
/*!   \file    canpie_hal.h
**    \brief   Hardware Abstraction Layer (HAL) for Linux
**
**
*/

/*----------------------------------------------------------------------------*\
** Definitions & Enumerations                                                 **
**                                                                            **
\*----------------------------------------------------------------------------*/

#define CP_MODULE_VERSION     "1.02"


#define CP_HAL_DRV_NONE      0x00000000
#define CP_HAL_DRV_OK        0x00000001   // driver is installed


#define CP_QUEUE_MSG_MIN      1           // minimum message queue size
#define CP_QUEUE_MSG_MAX      65535       // maximum message queue size
#define CP_QUEUE_MSG_DEF      64          // default message queue size

#ifndef CP_QUEUE_MAX
#define CP_QUEUE_MAX          32          // total number of queues
#endif


/*----------------------------------------------------------------------------*\
** Structures                                                                 **
**                                                                            **
\*----------------------------------------------------------------------------*/

struct can_sock;

/*----------------------------------------------------------------------------*/
/*!
** \struct  CpMsgQueue_s   canpie_hal.h
** \brief   Message Queue
**
** This structure defines a message queue for incoming (receive) and
** outgoing (transmit) messages. There is a FIFO for each direction.
** 
*/
struct CpMsgQueue_s {

   _TsCpPort            tsCanPort;
      
   _TsCpFifo            tsRcvFifo;
   
   _TsCpFifo            tsTrmFifo;
   
};


typedef struct CpMsgQueue_s		_TsCpMsgQueue;

typedef _TvCpStatus (* _FnBitrate)        (_TsCpPort *, _TsCpBitrate * );
typedef _TvCpStatus (* _FnBufferGetData)  (_TsCpPort *, _U08, _U08 * );
typedef _TvCpStatus (* _FnBufferGetDlc)   (_TsCpPort *, _U08, _U08 * );
typedef _TvCpStatus (* _FnBufferInit)     (_TsCpPort *, _U08, _TsCpCanMsg *, _U08);
typedef _TvCpStatus (* _FnBufferSetData)  (_TsCpPort *, _U08, _U08 * );
typedef _TvCpStatus (* _FnBufferSetDlc)   (_TsCpPort *, _U08, _U08 );
typedef _TvCpStatus (* _FnBufferSend)     (_TsCpPort *, _U08 );
typedef _TvCpStatus (* _FnBufferRelease)  (_TsCpPort *, _U08 );
typedef _TvCpStatus (* _FnCanMode)        (_TsCpPort *, _U08 );
typedef _TvCpStatus (* _FnCanStatus)      (_TsCpPort *, _U08 * );
typedef _TvCpStatus (* _FnCanStats)       (_TsCpPort *, _TsCpStatistic *);
typedef _TvCpStatus (* _FnDriverInit)     (_U08 , _TsCpPort *);
typedef _TvCpStatus (* _FnDriverRelease)  (_TsCpPort *);
typedef _TvCpStatus (* _FnFilterAll)      (_TsCpPort *, _BIT);
typedef _TvCpStatus (* _FnFilterMsg)      (_TsCpPort *, _U16 , _BIT);
typedef _TvCpStatus (* _FnHwDescription)  (_U08, _TsCpHdi * );
typedef _TvCpStatus (* _FnMsgRead)        (_TsCpPort *, _TsCpCanMsg *, _U16 *);
typedef _TvCpStatus (* _FnMsgWrite)       (_TsCpPort *, _TsCpCanMsg *, _U16 *);
typedef _TvCpStatus (* _FnRegRead)        (_U08, _U16, _U08 * );
typedef _TvCpStatus (* _FnRegWrite)       (_U08, _U16, _U08 );


struct CpHal_s {
   
   //----------------------------------------------------------------
   // list of all callback functions
   //
   _FnBitrate           pfnBitrate;
   _FnBufferGetData     pfnBufferGetData;
   _FnBufferGetDlc      pfnBufferGetDlc;
   _FnBufferInit        pfnBufferInit;
   _FnBufferSetData     pfnBufferSetData;
   _FnBufferSetDlc      pfnBufferSetDlc;
   _FnBufferSend        pfnBufferSend;
   _FnBufferRelease     pfnBufferRelease;
   _FnCanMode           pfnCanMode;
   _FnCanStatus         pfnCanStatus;
   _FnCanStats          pfnCanStats;
   _FnDriverInit        pfnDriverInit;   
   _FnDriverRelease     pfnDriverRelease;
   _FnFilterAll         pfnFilterAll;
   _FnFilterMsg         pfnFilterMsg;
   _FnHwDescription	   pfnHwDescription;
   _FnMsgRead           pfnMsgRead;
   _FnMsgWrite          pfnMsgWrite;
   _FnRegRead           pfnRegRead;
   _FnRegWrite          pfnRegWrite;

   
   /*! how often is this logical CAN interface used                  */
   int                  slUseCount;
   
   /*! status of this logical CAN interface                          */
   int                  slStatus;

   /*! number of the logical and the physical CAN interface          */
   _TsCpPort            tsCanPort;
      
   /*! array for all Rcv & Trm queues                                 */
   _TsCpMsgQueue        atsMsgQueue[CP_QUEUE_MAX];
      
         
};

typedef struct CpHal_s  _TsCpHal;


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




/*!
** \brief   Register CAN driver
** \param   slPortV        Requested port number
** \param   ptsCpHalV      Pointer to CANpie HAL
**
** \return  A positive value returns the assigned port number. 
**          A negative value is an error code.
**           
** This function registers a CAN hardware driver. The driver
** will be assigned to the logical CAN interface given by the parameter
** slLogIfV. The first interface number starts at index 0 (CP_CHANNEL_1).
** If the driver shall be assigned to the next free port, the value
** -1 must be used for slLogIfV. The function returns the port number
** that has been assigned for the CANpie driver. If the assigment
** fails, the function returns a negative CANpie error code, e.g.
** \li -CpErr_CHANNEL : port is already assigned, out of range
** \li -CpErr_GENERIC : failure in ptsCpHalV
**
*/
int  can_register_driver(int slLogIfV, int slPhyIfV, _TsCpHal * ptsCpHalV);


void can_unregister_driver(int slLogIfV);


_TsCpHal * can_get_hal(int slLogIfV);

_TsCpPort * can_get_port(int slLogIfV);


/*!
** \brief   Create a message queue
** \param   slPortV        Requested port number
** \param   slSizeV        Size of Receive/Transmit FIFO
** \return  Pointer to message queue
**
** This function tries to open a message queue on the selected
** port. If the operation fails, a zero pointer (0L) is returned.
** Upon success, a pointer to the message queue structure is 
** returned. This pointer is required for further message queue
** operations. The parameter size determines the maximum number
** of messages in the receive/transmit FIFO. The maximum number
** of messages is limited to 65535. 
** For values < CP_MSG_QUEUE_MIN the default FIFO size 
** (CP_MSG_QUEUE_DEF) is used.
*/
_TsCpPort * can_queue_create(int slLogIfV, 
                             int slRcvFifoSizeV, int slTrmFifoSizeV);


int can_queue_delete(_TsCpPort * ptsCanPortV);


/*!
** \brief   Read data from receive queue
** \param   slPortV        Requested port number
**
** This function tries to read slMsgNumV CAN messages out of
** the queue. It returns the actual number of messages that
** have been read from the queue.
*/
int can_queue_rcv_pop(_TsCpPort * ptsCanPortV, _TsCpCanMsg * ptsCanMsgV, int slMsgNumV);


int can_queue_rcv_push(_TsCpPort * ptsCanPortV, _TsCpCanMsg * ptsCanMsgV, int slMsgNumV);

                        
int can_queue_resize(_TsCpPort * ptsCanPortV, int slRcvFifoSizeV, int slTrmFifoSizeV);

int can_queue_trm_pop(_TsCpPort * ptsCanPortV, _TsCpCanMsg * ptsCanMsgV, int slMsgNumV);


int can_queue_trm_push(_TsCpPort * ptsCanPortV, _TsCpCanMsg * ptsCanMsgV, int slMsgNumV);

                      
#endif   /* _CANPIE_HAL_H_ */

⌨️ 快捷键说明

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