can_loop.c

来自「canpie 一个can bus的协议栈 - CAN interface fo」· C语言 代码 · 共 555 行 · 第 1/2 页

C
555
字号
//****************************************************************************//
// File:          cp_loop.c                                                   //
// Description:   CANpie core module for Linux                                //
// 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                                                        //
// ----------  -------------------------------------------------------------- //
// 02.01.2004  Initial version                                                //
//                                                                            //
//****************************************************************************//


//------------------------------------------------------------------------------
// CVS version information:
// $Id: can_loop.c,v 1.1 2005/06/01 21:47:17 microcontrol Exp $
//------------------------------------------------------------------------------


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

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>

#include <net/can/canpie.h>
#include <net/can/canpie_hal.h>
#include <net/can/cpcanmsg.h>


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

//---------------------------------------------------------
// PK_DBG: print kernel debug stuff
//
#ifdef  CP_DEBUG
#undef  PK_DBG
#define PK_DBG(fmt, args...)  printk(KERN_DEBUG "cp_loop: => %24s(): " fmt "\n", __FUNCTION__, ##args);
#else
#define PK_DBG(fmt, args...)  
#endif

//---------------------------------------------------------
// PK_INF: print kernel information
//
#undef  PK_INF
#define PK_INF(fmt, args...)  printk(KERN_INFO  "cp_loop: " fmt "\n", ##args)


//---------------------------------------------------------
// PK_ERR: print kernel error
//
#undef  PK_ERR
#define PK_ERR(fmt, args...)  printk(KERN_ERR   "cp_loop: " fmt "\n", ##args)



#define CP_LOOP_VERSION      "1.0"

#define MAX_MAILBOX           14        // number of virtual mailboxes

#define MAX_PHY_IF            4        // maximum number of "physical" interfaces


/*----------------------------------------------------------------------------*\
** Module information                                                         **
**                                                                            **
\*----------------------------------------------------------------------------*/
MODULE_AUTHOR("Uwe Koppe <koppe@microcontrol.net");
MODULE_DESCRIPTION("CANpie loopback module");
MODULE_LICENSE("GPL");


/*----------------------------------------------------------------------------*\
** Module variables                                                           **
**                                                                            **
\*----------------------------------------------------------------------------*/

static int           port = -1;
MODULE_PARM(port, "i");
MODULE_PARM_DESC(port, "Logic port number ");



static char * szDriverNameS = "cp_loop";
static char * szDriverVersS = "1.00";

static _TsCpCanMsg   atsMsgBufferS[MAX_MAILBOX];


static int           aslCanLogIf[MAX_PHY_IF];


/*----------------------------------------------------------------------------*\
** Functions                                                                  **
**                                                                            **
\*----------------------------------------------------------------------------*/



//----------------------------------------------------------------------------//
// CpLoopBitrate()                                                            //
// Setup baudrate of CAN controller                                           //
//----------------------------------------------------------------------------//
_TvCpStatus CpLoopBitrate(_TsCpPort * ptsPortV, _TsCpBitrate * ptsBitrateV)
{
   _U08  ubReturnT = CpErr_OK;
   
   //----------------------------------------------------------------
   // test the channel number
   //


   return(ubReturnT);
}


//----------------------------------------------------------------------------//
// CpLoopBufferGetDlc()                                                       //
// Get DLC of buffer                                                          //
//----------------------------------------------------------------------------//
_U08 CpLoopBufferGetDlc(_TsCpPort * ptvPortV, _U08 ubBufferV, _U08 * pubDlcV)
{
   _TsCpCanMsg *   ptsCanMsgT;
     
   //----------------------------------------------------------------
   // test the channel number
   //

   
   //----------------------------------------------------------------
   // test the buffer number
   //
   if(ubBufferV < CP_BUFFER_1) return (CpErr_BUFFER);
   if(ubBufferV > MAX_MAILBOX) return (CpErr_BUFFER);
   
   ptsCanMsgT = &atsMsgBufferS[ubBufferV - 1];
   *pubDlcV = CpMsgGetDlc(ptsCanMsgT);
   
   return(CpErr_OK);
}


//----------------------------------------------------------------------------//
// CpLoopBufferInit()                                                         //
// Initialize buffer of FullCAN controller                                    //
//----------------------------------------------------------------------------//
_U08 CpLoopBufferInit(_TsCpPort * ptvPortV, _TsCpCanMsg * ptsCanMsgV,
                      _U08 ubDirectionV)
{
   //----------------------------------------------------------------
   // test the channel number
   //

   
   return (CpErr_OK);
}


//----------------------------------------------------------------------------//
// CpLoopBufferRelease()                                                      //
// release a FullCAN buffer                                                   //
//----------------------------------------------------------------------------//
_U08 CpLoopBufferRelease(_TsCpPort * ptvPortV, _U08 ubBufferV)
{
   //----------------------------------------------------------------
   // test the channel number
   //
   
   
   //----------------------------------------------------------------
   // test the buffer number
   //
   if(ubBufferV < CP_BUFFER_1) return (CpErr_BUFFER);
   if(ubBufferV > MAX_MAILBOX) return (CpErr_BUFFER);

   return (CpErr_OK);
}


//----------------------------------------------------------------------------//
// CpLoopBufferSetDlc()                                                       //
// Set DLC of buffer                                                          //
//----------------------------------------------------------------------------//
_U08 CpLoopBufferSetDlc(_TsCpPort * ptvPortV, _U08 ubBufferV, _U08 ubDlcV)
{
   //----------------------------------------------------------------
   // test the channel number
   //

   //----------------------------------------------------------------
   // test the buffer number
   //
   if(ubBufferV < CP_BUFFER_1) return (CpErr_BUFFER);
   if(ubBufferV > MAX_MAILBOX) return (CpErr_BUFFER);


   return (CpErr_OK);
}




//----------------------------------------------------------------------------//
// CpLoopBufferSend()                                                     		//
// Send message of FullCAN buffer                                      			//
//----------------------------------------------------------------------------//
_U08 CpLoopBufferSend(_U08 ubChannelV, _U08 ubBufferV)
{
   //----------------------------------------------------------------
   // test the channel number
   //
   if( ubChannelV >= CP_CHANNEL_MAX) return (CpErr_CHANNEL);

      
   //----------------------------------------------------------------
   // test the buffer number
   //
   if(ubBufferV < CP_BUFFER_1) return (CpErr_BUFFER);
   if(ubBufferV > MAX_MAILBOX) return (CpErr_BUFFER);

   return (CpErr_OK);
}


//----------------------------------------------------------------------------//
// CpLoopBufferTransmit()                                                     //
// Transmit contents of buffer                                                //
//----------------------------------------------------------------------------//
_U08 CpLoopBufferTransmit(_U08 ubChannelV, _TsCpCanMsg * ptsCanMsgV)
{
   //----------------------------------------------------------------
   // test the channel number
   //
   if( ubChannelV >= CP_CHANNEL_MAX) return (CpErr_CHANNEL);

   return (CpErr_OK);
}


//----------------------------------------------------------------------------//
// CpLoopCanMode()                                                            //
// Set mode of CAN controller                                                 //
//----------------------------------------------------------------------------//
_TvCpStatus CpLoopCanMode(_TsCpPort * ptsPortV, _U08 ubModeV)
{
   _U08  ubReturnT = CpErr_OK;

   //----------------------------------------------------------------
   // test the channel number
   //

   return(ubReturnT);
}


//----------------------------------------------------------------------------//
// CpLoopCanStatus()                                                          //
// Retrive status of CAN controller                                           //
//----------------------------------------------------------------------------//
_TvCpStatus CpLoopCanStatus(_TsCpPort * ptsPortV, _U08 * pubStatusV)
{
   _U08  ubStatusT = 0;
   _U08  ubReturnT = CpErr_OK;

⌨️ 快捷键说明

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