]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/io/can/v2_0/include/can.h
Initial revision
[karo-tx-redboot.git] / packages / io / can / v2_0 / include / can.h
1 #ifndef CYGONCE_CAN_H
2 #define CYGONCE_CAN_H
3 // ====================================================================
4 //
5 //      can.h
6 //
7 //      Device I/O 
8 //
9 // ====================================================================
10 //####ECOSGPLCOPYRIGHTBEGIN####
11 // -------------------------------------------
12 // This file is part of eCos, the Embedded Configurable Operating System.
13 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
14 //
15 // eCos is free software; you can redistribute it and/or modify it under
16 // the terms of the GNU General Public License as published by the Free
17 // Software Foundation; either version 2 or (at your option) any later version.
18 //
19 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
20 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
22 // for more details.
23 //
24 // You should have received a copy of the GNU General Public License along
25 // with eCos; if not, write to the Free Software Foundation, Inc.,
26 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
27 //
28 // As a special exception, if other files instantiate templates or use macros
29 // or inline functions from this file, or you compile this file and link it
30 // with other works to produce a work based on this file, this file does not
31 // by itself cause the resulting work to be covered by the GNU General Public
32 // License. However the source code for this file must still be made available
33 // in accordance with section (3) of the GNU General Public License.
34 //
35 // This exception does not invalidate any other reasons why a work based on
36 // this file might be covered by the GNU General Public License.
37 //
38 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
39 // at http://sources.redhat.com/ecos/ecos-license/
40 // -------------------------------------------
41 //####ECOSGPLCOPYRIGHTEND####
42 // ====================================================================
43 //#####DESCRIPTIONBEGIN####
44 //
45 // Author(s):    Uwe Kindler
46 // Contributors: gthomas
47 // Date:         2005-12-05
48 // Purpose:      Internal interfaces for CAN I/O drivers
49 // Description:
50 //
51 //####DESCRIPTIONEND####
52 //
53 // ====================================================================
54
55
56 //==========================================================================
57 //                                INCLUDES
58 //==========================================================================
59 #include <pkgconf/system.h>
60 #include <pkgconf/io_can.h>
61
62 #include <cyg/infra/cyg_type.h>
63 #include <cyg/io/io.h>
64 #include <cyg/io/canio.h>
65 #include <cyg/io/devtab.h>
66 #include <cyg/hal/drv_api.h>
67
68
69 //===========================================================================
70 //                            FORWARD DECLARATIONS
71 //===========================================================================
72 typedef struct can_channel       can_channel;
73 typedef struct can_lowlevel_funs can_lowlevel_funs;
74
75
76 //===========================================================================
77 //                                DATA TYPES
78 //===========================================================================
79
80 //---------------------------------------------------------------------------
81 // Pointers into uper-level driver which ISRs and DSRs need
82 //
83 typedef struct 
84 {
85     void (*can_init)(can_channel *chan);              // Initialize the can channel
86     void (*xmt_msg)(can_channel *chan, void *pdata);  // transmit one single message
87     void (*rcv_event)(can_channel *chan, void *pdata);// indicate can event occurance
88 } can_callbacks_t;
89
90
91 #define CAN_CALLBACKS(_l,_init,_xmt_msg,_rcv_event)  \
92 can_callbacks_t _l = {                               \
93     _init,                                           \
94     _xmt_msg,                                        \
95     _rcv_event                                       \
96 };
97
98 extern can_callbacks_t cyg_io_can_callbacks;
99
100
101 //---------------------------------------------------------------------------
102 // Data buffer for receive and transmit FIFOs
103 //
104 typedef struct can_cbuf_st
105 {
106     void                    *pdata;      // points to data buffer
107     volatile int             put;
108     volatile int             get;
109     int                      len;
110     volatile int             data_cnt;   // count of events or messages currently in buffer
111     cyg_drv_cond_t           wait;
112     cyg_drv_mutex_t          lock;
113     bool                     waiting;
114 #if defined(CYGOPT_IO_CAN_SUPPORT_NONBLOCKING)
115     bool                     blocking;   // true - timeouts will bes used, false - call blocks until data arrives
116 #endif    
117     volatile bool            abort;      // Set by an outsider to kill processing
118     volatile cyg_int32       pending;    // This many bytes waiting to be sent
119 #if defined(CYGOPT_IO_CAN_SUPPORT_TIMEOUTS)
120     cyg_uint32               timeout;    // timeout value for reading data from buffer
121 #endif
122 } can_cbuf_t;
123
124
125 #ifdef CYGOPT_IO_CAN_SUPPORT_TIMEOUTS
126 #define _TX_TIMEOUT CYGNUM_IO_CAN_DEFAULT_TIMEOUT_WRITE
127 #define _RX_TIMEOUT CYGNUM_IO_CAN_DEFAULT_TIMEOUT_READ
128 #define CBUF_INIT(_data, _len, _timeout)   \
129    {_data, 0, 0, _len, timeout : _timeout}
130 #else
131 #define _TX_TIMEOUT 0
132 #define _RX_TIMEOUT 0
133 #define CBUF_INIT(_data, _len, _timeout)   \
134    {_data, 0, 0, _len, }
135 #endif // #ifdef CYGOPT_IO_CAN_SUPPORT_TIMEOUTS
136  
137    
138 //---------------------------------------------------------------------------
139 // Private data which describes this channel + initialisation macro
140 //
141 struct can_channel 
142 {
143     can_lowlevel_funs  *funs;
144     can_callbacks_t    *callbacks;
145     void               *dev_priv;  // Whatever is needed by actual device routines
146     cyg_can_info_t      config;    // Current configuration
147     bool                init;      // true if driver is already initialized
148     can_cbuf_t          out_cbuf;  // buffer for transmit can messages
149     can_cbuf_t          in_cbuf;   // buffer with received can events
150 };
151
152
153
154 #define CAN_CHANNEL_USING_INTERRUPTS(_l,                                \
155                        _funs,                                           \
156                        _dev_priv,                                       \
157                        _baud,                                           \
158                        _out_buf, _out_buflen,                           \
159                        _in_buf, _in_buflen)                             \
160 can_channel _l = {                                                      \
161     &_funs,                                                             \
162     &cyg_io_can_callbacks,                                              \
163     &(_dev_priv),                                                       \
164     CYG_CAN_INFO_INIT(_baud),                                           \
165     false,                                                              \
166     CBUF_INIT(_out_buf, _out_buflen, _TX_TIMEOUT),                      \
167     CBUF_INIT(_in_buf, _in_buflen, _RX_TIMEOUT)                         \
168 };
169
170
171
172 //---------------------------------------------------------------------------
173 // Low level interface functions - these functions are required by the generic 
174 // CAN driver in order to access the low level hardware
175 //
176 struct can_lowlevel_funs 
177 {
178     bool (*putmsg)(can_channel *priv, cyg_can_message *pmsg, void *pdata);   // send one can message - return true if consumed
179     bool (*getevent)(can_channel *priv, cyg_can_event *pevent, void *pdata); // fetch one CAN event from device
180     Cyg_ErrNo (*set_config)(can_channel    *priv,                        // Change hardware configuration (baud rate, etc)
181                             cyg_uint32      key, 
182                             const void     *xbuf,
183                             cyg_uint32     *len);
184     void (*start_xmit)(can_channel *priv);                               // Enable the transmit channel and turn on transmit interrupts
185     void (*stop_xmit)(can_channel *priv);                                // Disable the transmit channel and turn transmit interrupts off
186 };
187
188 #define CAN_LOWLEVEL_FUNS(_l,_putmsg,_getevent,_set_config,_start_xmit,_stop_xmit)  \
189 can_lowlevel_funs _l = {                                                            \
190   _putmsg,                                                                          \
191   _getevent,                                                                        \
192   _set_config,                                                                      \
193   _start_xmit,                                                                      \
194   _stop_xmit                                                                        \
195 };
196
197 extern cyg_devio_table_t cyg_io_can_devio;
198 //-------------------------------------------------------------------------
199 #endif // CYGONCE_SERIAL_H