📄 canpie_proc.c.svn-base
字号:
//****************************************************************************//// File: canpie_proc.c //// Description: CANpie /proc support 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 //// ---------- -------------------------------------------------------------- //// 29.07.2003 Initial version //// ////****************************************************************************////------------------------------------------------------------------------------// CVS version information:// $Id: canpie_proc.c,v 1.2 2005/06/17 13:48:37 microcontrol Exp $//------------------------------------------------------------------------------/*----------------------------------------------------------------------------*\** Include files **** **\*----------------------------------------------------------------------------*/#include <linux/proc_fs.h>#include <linux/kernel.h>#include <linux/module.h>#include <linux/can/canpie_dbg.h>#include <linux/can/canpie_hal.h>#include <linux/can/cpcore.h>/*----------------------------------------------------------------------------*\** Definitions **** **\*----------------------------------------------------------------------------*//*----------------------------------------------------------------------------*\** /proc filesystem support **** Static variables and function prototypes **\*----------------------------------------------------------------------------*/#ifdef CONFIG_PROC_FSstatic int slProcCan_InitializedS = 0;int can_proc_init(void);int can_proc_cleanup(void);int can_proc_dev_add(int slCanIfV);int can_proc_dev_remove(int slCanIfV);//----------------------------------------------------------------------------//// Internal (static) functions for access to the files in the //// directory '/proc/net/can'. //// Functions for read access have the suffix '_rd' //// Functions for write access have the suffix '_wr' //// ////----------------------------------------------------------------------------////-------------------------------------------------------------------// file : /proc/net/can/info// access: read-only// static int proc_can_info_rd ( char *page, char **start, off_t off, int count, int *eof , void *data );//-------------------------------------------------------------------// file : /proc/net/can/debug// access: read/write// info : modify the debug level of canpie module//static int proc_can_debug_rd ( char *page, char **start, off_t off, int count, int *eof , void *data );static int proc_can_debug_wr ( struct file *file, const char *buffer, unsigned long count, void *data ); //-------------------------------------------------------------------// file : /proc/net/can/canX/baud// access: read/write// info : modify the baudrate of the CAN interface//static int proc_dev_baud_rd ( char *page, char **start, off_t off, int count, int *eof , void *data );static int proc_dev_baud_wr ( struct file *file, const char *buffer, unsigned long count, void *data ); //-------------------------------------------------------------------// file : /proc/net/can/canX/mode// access: read/write// info : modify the mode of the CAN interface (start/stop)//static int proc_dev_mode_rd ( char *page, char **start, off_t off, int count, int *eof , void *data );static int proc_dev_mode_wr ( struct file *file, const char *buffer, unsigned long count, void *data ); static struct proc_dir_entry * ptsProcCanRootS;static struct proc_dir_entry * atsProcCanDevS[CP_CHANNEL_MAX];#else /* undef CONFIG_PROC_FS */#define can_proc_init() 0#define can_proc_cleanup() 0#define can_proc_dev_add() 0#define can_proc_dev_remove() 0#endif // CONFIG_PROC_FS/*----------------------------------------------------------------------------*\** Module variables **** **\*----------------------------------------------------------------------------*//*----------------------------------------------------------------------------*\** Functions **** **\*----------------------------------------------------------------------------*//*----------------------------------------------------------------------------*\** /proc filesystem support **** function implementation **\*----------------------------------------------------------------------------*/#ifdef CONFIG_PROC_FS//----------------------------------------------------------------------------//// can_proc_dev_add() //// ////----------------------------------------------------------------------------//int can_proc_dev_add(int slCanIfV){ struct proc_dir_entry * ptsProcCanEntryT; char szPortNameT[16]; //----------------------------------------------------------------- // check if the supplied port number is in range and not // occupied yet // if( (slCanIfV < 0) || (slCanIfV >= CP_CHANNEL_MAX) ) { PK_ERR("Can't create /proc/net/can/ entry for port %d", slCanIfV); return(-EPERM); } if(atsProcCanDevS[slCanIfV] != 0L) { PK_ERR("Directory /proc/net/can/can%d already assigned", slCanIfV); return(-EEXIST); } if(ptsProcCanRootS == 0L) { PK_ERR("/proc/net/can/ does not exist"); return(-ENOENT); } //----------------------------------------------------------------- // create the directory for canN // sprintf(szPortNameT, "can%d", slCanIfV); atsProcCanDevS[slCanIfV] = proc_mkdir(szPortNameT, ptsProcCanRootS); if(atsProcCanDevS[slCanIfV] == 0L) { PK_ERR("Could not create /proc/net/can/%s", szPortNameT); return(-ENOENT); } //----------------------------------------------------------------- // the 'baud' file holds the current buadrate // ptsProcCanEntryT = create_proc_entry("baud", S_IFREG | S_IRUGO | S_IWUSR, atsProcCanDevS[slCanIfV]); if(ptsProcCanEntryT) { ptsProcCanEntryT->read_proc = &proc_dev_baud_rd; ptsProcCanEntryT->write_proc = &proc_dev_baud_wr; ptsProcCanEntryT->owner = THIS_MODULE; ptsProcCanEntryT->data = can_get_port(slCanIfV); } //----------------------------------------------------------------- // the 'mode' file holds the CAN mode (stop/start) // ptsProcCanEntryT = create_proc_entry("mode", S_IFREG | S_IRUGO | S_IWUSR, atsProcCanDevS[slCanIfV]); if(ptsProcCanEntryT) { ptsProcCanEntryT->read_proc = &proc_dev_mode_rd; ptsProcCanEntryT->write_proc = &proc_dev_mode_wr; ptsProcCanEntryT->owner = THIS_MODULE; ptsProcCanEntryT->data = can_get_port(slCanIfV); } return(0);}//----------------------------------------------------------------------------//// cp_proc_candev_del() //// ////----------------------------------------------------------------------------//int can_proc_dev_remove(int slCanIfV){ char szPortNameT[16]; //---------------------------------------------------------------- // create the name for the sub-directory of /proc/net/can // sprintf(szPortNameT, "can%d", slCanIfV); //---------------------------------------------------------------- // test if there is a proc-entry available // if(ptsProcCanRootS == 0L) { PK_ERR("/proc/net/can/ does not exist"); return(-ENOENT); } if(atsProcCanDevS[slCanIfV] == 0L) { PK_ERR("/proc/net/can/%s does not exist", szPortNameT); return(-ENOENT); } //----------------------------------------------------------------- // remove the files in the directory /proc/net/can/canX //
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -