can_dev.h

Go to the documentation of this file.
00001 #ifndef _CAN_DEV_H_
00002 #define _CAN_DEV_H_
00003 
00004 /*
00005  * Copyright (C) 2004 by Ole Reinhardt<ole.reinhardt@kernelconcepts.de>
00006  * Kernel concepts (http://www.kernelconcepts.de) All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions
00010  * are met:
00011  *
00012  * 1. Redistributions of source code must retain the above copyright
00013  *    notice, this list of conditions and the following disclaimer.
00014  * 2. Redistributions in binary form must reproduce the above copyright
00015  *    notice, this list of conditions and the following disclaimer in the
00016  *    documentation and/or other materials provided with the distribution.
00017  * 3. Neither the name of the copyright holders nor the names of
00018  *    contributors may be used to endorse or promote products derived
00019  *    from this software without specific prior written permission.
00020  *
00021  * THIS SOFTWARE IS PROVIDED BY EGNITE SOFTWARE GMBH AND CONTRIBUTORS
00022  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL EGNITE
00025  * SOFTWARE GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
00028  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
00029  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00030  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
00031  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00032  * SUCH DAMAGE.
00033  *
00034  * For additional information see http://www.ethernut.de/
00035  *
00036  */
00037 
00043 /*
00044  * $Log: can_dev.h,v $
00045  * Revision 1.6  2007/09/08 03:01:11  hwmaier
00046  * Changes to support RX time-out, CAN_SetRxTimeout() added.
00047  *
00048  * Revision 1.5  2005/10/07 21:44:22  hwmaier
00049  * CAN_SetSpeed function added. Baudrates moved here.
00050  *
00051  * Revision 1.4  2004/08/25 15:48:21  olereinhardt
00052  * Added function to set an acceptance filter
00053  *
00054  * Revision 1.3  2004/08/02 09:59:53  olereinhardt
00055  * changed typing of CAN_TryRxFrame
00056  *
00057  * Revision 1.2  2004/06/23 10:15:35  olereinhardt
00058  * Added function for buffer monitoring (avail / free)
00059  *
00060  * Revision 1.1  2004/06/07 15:13:48  olereinhardt
00061  * Initial checkin
00062  *
00063  */
00064 
00065 #include <sys/types.h>
00066 #include <sys/device.h>
00067 
00072 
00073 #define CAN_IF_2A    0x01
00074 #define CAN_IF_2B    0x02
00075 
00076 
00077 /*
00078  * CAN Baud rate constants
00079  */
00080 #define CAN_SPEED_10K      0   
00081 #define CAN_SPEED_20K      1   
00082 #define CAN_SPEED_50K      2   
00083 #define CAN_SPEED_100K     3   
00084 #define CAN_SPEED_125K     4   
00085 #define CAN_SPEED_250K     5   
00086 #define CAN_SPEED_500K     6   
00087 #define CAN_SPEED_800K     7   
00088 #define CAN_SPEED_1M       8   
00089 #define CAN_SPEED_CUSTOM 255
00090 
00091 
00097 struct _CANFRAME {              // todo: Implement flags
00098     u_long id;                  // Identifier
00099     u_char len;                 // Length of frame, max = 8
00100     u_char byte[8];
00101     u_char ext;                 // Boolean, extendet frame
00102     u_char rtr;                 // Boolean, remote transmition bit
00103 };
00104 
00109 typedef struct _CANFRAME CANFRAME;
00110 
00115 struct _CANINFO {
00116     HANDLE volatile can_rx_rdy;     
00117     HANDLE volatile can_tx_rdy;     
00118     u_long can_rx_frames;           
00119     u_long can_tx_frames;           
00120     u_long can_interrupts;          
00121     u_long can_overruns;            
00122     u_long can_errors;              
00123 };
00124 
00128 typedef struct _CANINFO CANINFO;
00129 
00136 struct ifcan {
00137     u_char can_type;            
00138     u_long can_baudrate;        
00139     u_char can_acc_mask[4];     
00140     u_char can_acc_code[4];     
00141     u_long can_rtimeout;        
00143     u_char (*can_rxavail) (NUTDEVICE *);           
00144     u_char (*can_txfree) (NUTDEVICE *);            
00145     u_char (*can_recv) (NUTDEVICE *, CANFRAME *);  
00146     void   (*can_send) (NUTDEVICE *, CANFRAME *);  
00147     void   (*can_set_ac) (NUTDEVICE *, u_char*);   
00148     void   (*can_set_am) (NUTDEVICE *, u_char*);   
00149     u_char (*can_set_baud) (NUTDEVICE *, u_long);  
00150 };
00151 
00155 typedef struct ifcan IFCAN;
00156 
00157 u_char CAN_SetSpeed(NUTDEVICE *dev, u_long baudrate);
00158 void   CAN_SetFilter(NUTDEVICE *dev, u_char *ac, u_char *am);
00159 
00160 void   CAN_TxFrame(NUTDEVICE *dev, CANFRAME *frame);
00161 u_char CAN_TryTxFrame(NUTDEVICE *dev, CANFRAME *frame);
00162 u_char CAN_TxFree(NUTDEVICE *dev);
00163 
00164 u_char CAN_RxFrame(NUTDEVICE *dev, CANFRAME *frame);
00165 u_char CAN_TryRxFrame(NUTDEVICE *dev, CANFRAME *frame);
00166 u_char CAN_RxAvail(NUTDEVICE *dev);
00167 void   CAN_SetRxTimeout(NUTDEVICE *dev, u_long timeout);
00168 
00171 #endif

© 2000-2007 by egnite Software GmbH - visit http://www.ethernut.de/