groke6@364: /* groke6@364: * can4linux.h - can4linux CAN driver module groke6@364: * groke6@364: * This file is subject to the terms and conditions of the GNU General Public groke6@364: * License. See the file "COPYING" in the main directory of this archive groke6@364: * for more details. groke6@364: * groke6@364: * Copyright (c) 2001 port GmbH Halle/Saale groke6@364: *------------------------------------------------------------------ groke6@364: * $Header$ groke6@364: * groke6@364: *-------------------------------------------------------------------------- groke6@364: * groke6@364: * groke6@364: * modification history groke6@364: * -------------------- groke6@364: * $Log$ groke6@364: * Revision 1.1 2008-01-22 09:27:13 groke6 groke6@364: * Added can4linux driver support. groke6@364: * groke6@364: * Revision 1.1 2004/08/12 10:14:31 jschoew groke6@364: * add can4linux examples groke6@364: * groke6@364: * Revision 1.5 2004/05/14 10:02:54 oe groke6@364: * - started supporting CPC-Card groke6@364: * - version number in can4linux.h available groke6@364: * - only one structure type for Config_par_t Command_par_t groke6@364: * - new ioctl command CMD_CLEARBUFFERS groke6@364: * groke6@364: * Revision 1.4 2003/08/27 17:49:04 oe groke6@364: * - New CanStatusPar structure groke6@364: * groke6@364: * Revision 1.3 2002/08/20 05:57:22 oe groke6@364: * - new write() handling, now not ovrwriting buffer content if buffer fill groke6@364: * - ioctl() get status returns buffer information groke6@364: * groke6@364: * Revision 1.2 2002/08/08 17:50:46 oe groke6@364: * - MSG_ERR_MASK extended groke6@364: * groke6@364: * Revision 1.1 2002/01/10 19:13:19 oe groke6@364: * - application header file changed name can.h -> can4linux.h groke6@364: * groke6@364: * Revision 1.2 2001/09/14 14:58:09 oe groke6@364: * first free release groke6@364: * groke6@364: * Revision 1.1.1.1 2001/06/11 18:30:54 oe groke6@364: * minimal version can4linux embedded, compile time Konfigurierbar groke6@364: * groke6@364: * groke6@364: * groke6@364: * groke6@364: *-------------------------------------------------------------------------- groke6@364: */ groke6@364: groke6@364: /** groke6@364: * \file can.h groke6@364: * \author Heinz-Jrgen Oertel, port GmbH groke6@364: * $Revision$ groke6@364: * $Date$ groke6@364: * groke6@364: * can4linux interface definitions groke6@364: * groke6@364: * groke6@364: * groke6@364: */ groke6@364: groke6@364: groke6@364: #ifndef __CAN_H groke6@364: #define __CAN_H groke6@364: groke6@364: #ifdef __cplusplus groke6@364: extern "C" { groke6@364: #endif groke6@364: groke6@364: groke6@364: #define CAN4LINUXVERSION 0x0301 /*(Version 3.1)*/ groke6@364: groke6@364: #ifndef __KERNEL__ groke6@364: #include groke6@364: #endif groke6@364: /*---------- the can message structure */ groke6@364: groke6@364: #define CAN_MSG_LENGTH 8 /**< maximum length of a CAN frame */ groke6@364: groke6@364: groke6@364: #define MSG_RTR (1<<0) /**< RTR Message */ groke6@364: #define MSG_OVR (1<<1) /**< CAN controller Msg overflow error */ groke6@364: #define MSG_EXT (1<<2) /**< extended message format */ groke6@364: #define MSG_PASSIVE (1<<4) /**< controller in error passive */ groke6@364: #define MSG_BUSOFF (1<<5) /**< controller Bus Off */ groke6@364: #define MSG_ (1<<6) /**< */ groke6@364: #define MSG_BOVR (1<<7) /**< receive/transmit buffer overflow */ groke6@364: /** groke6@364: * mask used for detecting CAN errors in the canmsg_t flags field groke6@364: */ groke6@364: #define MSG_ERR_MASK (MSG_OVR + MSG_PASSIVE + MSG_BUSOFF + MSG_BOVR) groke6@364: groke6@364: /** groke6@364: * The CAN message structure. groke6@364: * Used for all data transfers between the application and the driver groke6@364: * using read() or write(). groke6@364: */ groke6@364: typedef struct { groke6@364: /** flags, indicating or controlling special message properties */ groke6@364: int flags; groke6@364: int cob; /**< CAN object number, used in Full CAN */ groke6@364: unsigned long id; /**< CAN message ID, 4 bytes */ groke6@364: struct timeval timestamp; /**< time stamp for received messages */ groke6@364: short int length; /**< number of bytes in the CAN message */ groke6@364: unsigned char data[CAN_MSG_LENGTH]; /**< data, 0...8 bytes */ groke6@364: } canmsg_t; groke6@364: groke6@364: groke6@364: groke6@364: /** groke6@364: ---------- IOCTL requests */ groke6@364: groke6@364: #define COMMAND 0 /**< IOCTL command request */ groke6@364: #define CONFIG 1 /**< IOCTL configuration request */ groke6@364: #define SEND 2 /**< IOCTL request */ groke6@364: #define RECEIVE 3 /**< IOCTL request */ groke6@364: #define CONFIGURERTR 4 /**< IOCTL request */ groke6@364: #define STATUS 5 /**< IOCTL status request */ groke6@364: groke6@364: /*---------- CAN ioctl parameter types */ groke6@364: /** groke6@364: IOCTL Command request parameter structure */ groke6@364: struct Command_par { groke6@364: int cmd; /**< special driver command */ groke6@364: int target; /**< special configuration target */ groke6@364: unsigned long val1; /**< 1. parameter for the target */ groke6@364: unsigned long val2; /**< 2. parameter for the target */ groke6@364: int error; /**< return value */ groke6@364: unsigned long retval; /**< return value */ groke6@364: }; groke6@364: groke6@364: groke6@364: typedef struct Command_par Command_par_t ; groke6@364: /** groke6@364: PSW made them all the same groke6@364: IOCTL Configuration request parameter structure */ groke6@364: typedef struct Command_par Config_par_t ; groke6@364: groke6@364: groke6@364: /** groke6@364: IOCTL generic CAN controller status request parameter structure */ groke6@364: typedef struct CanStatusPar { groke6@364: unsigned int baud; /**< actual bit rate */ groke6@364: unsigned int status; /**< CAN controller status register */ groke6@364: unsigned int error_warning_limit; /**< the error warning limit */ groke6@364: unsigned int rx_errors; /**< content of RX error counter */ groke6@364: unsigned int tx_errors; /**< content of TX error counter */ groke6@364: unsigned int error_code; /**< content of error code register */ groke6@364: unsigned int rx_buffer_size; /**< size of rx buffer */ groke6@364: unsigned int rx_buffer_used; /**< number of messages */ groke6@364: unsigned int tx_buffer_size; /**< size of tx buffer */ groke6@364: unsigned int tx_buffer_used; /**< number of messages */ groke6@364: unsigned long retval; /**< return value */ groke6@364: unsigned int type; /**< CAN controller / driver type */ groke6@364: } CanStatusPar_t; groke6@364: groke6@364: /** groke6@364: IOCTL CanStatusPar.type CAN controller hardware chips */ groke6@364: #define CAN_TYPE_UNSPEC 0 groke6@364: #define CAN_TYPE_SJA1000 1 groke6@364: #define CAN_TYPE_FlexCAN 2 groke6@364: #define CAN_TYPE_TouCAN 3 groke6@364: #define CAN_TYPE_82527 4 groke6@364: #define CAN_TYPE_TwinCAN 5 groke6@364: groke6@364: groke6@364: /** groke6@364: IOCTL Send request parameter structure */ groke6@364: typedef struct Send_par { groke6@364: canmsg_t *Tx; /**< CAN message struct */ groke6@364: int error; /**< return value for errno */ groke6@364: unsigned long retval; /**< return value */ groke6@364: } Send_par_t ; groke6@364: groke6@364: /** groke6@364: IOCTL Receive request parameter structure */ groke6@364: typedef struct Receive_par { groke6@364: canmsg_t *Rx; /**< CAN message struct */ groke6@364: int error; /**< return value for errno */ groke6@364: unsigned long retval; /**< return value */ groke6@364: } Receive_par_t ; groke6@364: groke6@364: /** groke6@364: IOCTL ConfigureRTR request parameter structure */ groke6@364: typedef struct ConfigureRTR_par { groke6@364: unsigned message; /**< CAN message ID */ groke6@364: canmsg_t *Tx; /**< CAN message struct */ groke6@364: int error; /**< return value for errno */ groke6@364: unsigned long retval; /**< return value */ groke6@364: } ConfigureRTR_par_t ; groke6@364: groke6@364: /** groke6@364: ---------- IOCTL Command subcommands and there targets */ groke6@364: groke6@364: # define CMD_START 1 groke6@364: # define CMD_STOP 2 groke6@364: # define CMD_RESET 3 groke6@364: # define CMD_CLEARBUFFERS 4 groke6@364: groke6@364: groke6@364: groke6@364: groke6@364: /** groke6@364: ---------- IOCTL Configure targets */ groke6@364: groke6@364: # define CONF_ACC 0 /* mask and code */ groke6@364: # define CONF_ACCM 1 /* mask only */ groke6@364: # define CONF_ACCC 2 /* code only */ groke6@364: # define CONF_TIMING 3 /* bit timing */ groke6@364: # define CONF_OMODE 4 /* output control register */ groke6@364: # define CONF_FILTER 5 groke6@364: # define CONF_FENABLE 6 groke6@364: # define CONF_FDISABLE 7 groke6@364: groke6@364: #ifdef __cplusplus groke6@364: } groke6@364: #endif groke6@364: groke6@364: #endif /* __CAN_H */