3 // ====================================================================
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.
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.
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
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.
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.
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.
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####
45 // Author(s): Uwe Kindler
46 // Contributors: gthomas
48 // Purpose: Internal interfaces for CAN I/O drivers
51 //####DESCRIPTIONEND####
53 // ====================================================================
56 //==========================================================================
58 //==========================================================================
59 #include <pkgconf/system.h>
60 #include <pkgconf/io_can.h>
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>
69 // define standard and extended id masks
70 #define CYG_CAN_STD_ID_MASK 0x7FF
71 #define CYG_CAN_EXT_ID_MASK 0x1FFFFFFF
74 // include device header
75 // a device can define its own types of CAN messages and CAN events. It does this
76 // in the device header CYGDAT_IO_CAN_DEVICE_INL. Because this header is included
77 // here, the device header file can use all definitions in the files included
78 // in the include section above
80 #ifdef CYGDAT_IO_CAN_DEVICE_INL
81 #include CYGDAT_IO_CAN_DEVICE_INL // include device header
85 // If the device did not define its own type of CAN message and CAN event, then
86 // we define standard types here and use the types cyg_can_message and cyg_can_event
90 #define CYG_CAN_MSG_T cyg_can_message
91 #define CYG_CAN_EVENT_T cyg_can_event
92 #define CYG_CAN_WRITE_MSG(_devmsg_ptr_, _iomsg_ptr_) (*(_devmsg_ptr_) = *(_iomsg_ptr_))
93 #define CYG_CAN_READ_EVENT(_ioevent_ptr_, _devevent_ptr_) (*(_ioevent_ptr_) = *(_devevent_ptr_))
97 //===========================================================================
98 // FORWARD DECLARATIONS
99 //===========================================================================
100 typedef struct can_channel can_channel;
101 typedef struct can_lowlevel_funs can_lowlevel_funs;
104 //===========================================================================
106 //===========================================================================
108 //---------------------------------------------------------------------------
109 // Pointers into uper-level driver which ISRs and DSRs need
113 void (*can_init)(can_channel *chan); // Initialize the can channel
114 void (*xmt_msg)(can_channel *chan, void *pdata); // transmit one single message
115 void (*rcv_event)(can_channel *chan, void *pdata);// indicate can event occurance
119 #define CAN_CALLBACKS(_l,_init,_xmt_msg,_rcv_event) \
120 can_callbacks_t _l = { \
126 extern can_callbacks_t cyg_io_can_callbacks;
129 //---------------------------------------------------------------------------
130 // Data buffer for receive and transmit FIFOs
132 typedef struct can_cbuf_st
134 void *pdata; // points to data buffer
138 volatile int data_cnt; // count of events or messages currently in buffer
140 cyg_drv_mutex_t lock;
142 #if defined(CYGOPT_IO_CAN_SUPPORT_NONBLOCKING)
143 bool blocking; // true - timeouts will bes used, false - call blocks until data arrives
145 volatile bool abort; // Set by an outsider to kill processing
146 volatile cyg_int32 pending; // This many bytes waiting to be sent
147 #if defined(CYGOPT_IO_CAN_SUPPORT_TIMEOUTS)
148 cyg_uint32 timeout; // timeout value for reading data from buffer
153 #ifdef CYGOPT_IO_CAN_SUPPORT_TIMEOUTS
154 #define _TX_TIMEOUT CYGNUM_IO_CAN_DEFAULT_TIMEOUT_WRITE
155 #define _RX_TIMEOUT CYGNUM_IO_CAN_DEFAULT_TIMEOUT_READ
156 #define CBUF_INIT(_data, _len, _timeout) \
157 {_data, 0, 0, _len, timeout : _timeout}
159 #define _TX_TIMEOUT 0
160 #define _RX_TIMEOUT 0
161 #define CBUF_INIT(_data, _len, _timeout) \
162 {_data, 0, 0, _len, }
163 #endif // #ifdef CYGOPT_IO_CAN_SUPPORT_TIMEOUTS
166 //---------------------------------------------------------------------------
167 // Private data which describes this channel + initialisation macro
171 can_lowlevel_funs *funs;
172 can_callbacks_t *callbacks;
173 void *dev_priv; // Whatever is needed by actual device routines
174 cyg_can_info_t config; // Current configuration
175 bool init; // true if driver is already initialized
176 can_cbuf_t out_cbuf; // buffer for transmit can messages
177 can_cbuf_t in_cbuf; // buffer with received can events
178 #ifdef CYGOPT_IO_CAN_SUPPORT_CALLBACK
179 cyg_can_callback_cfg callback_cfg; // Callback configuration
183 #ifdef CYGOPT_IO_CAN_SUPPORT_CALLBACK
184 #define CYG_CAN_CALLBACK_INIT , {(cyg_can_event_cb_t) 0, 0, 0}
186 #define CYG_CAN_CALLBACK_INIT
190 #define CAN_CHANNEL_USING_INTERRUPTS(_l, \
194 _out_buf, _out_buflen, \
195 _in_buf, _in_buflen) \
198 &cyg_io_can_callbacks, \
200 CYG_CAN_INFO_INIT(_baud), \
202 CBUF_INIT(_out_buf, _out_buflen, _TX_TIMEOUT), \
203 CBUF_INIT(_in_buf, _in_buflen, _RX_TIMEOUT) \
204 CYG_CAN_CALLBACK_INIT \
209 //---------------------------------------------------------------------------
210 // Low level interface functions - these functions are required by the generic
211 // CAN driver in order to access the low level hardware
213 struct can_lowlevel_funs
215 bool (*putmsg)(can_channel *priv, CYG_CAN_MSG_T *pmsg, void *pdata); // send one can message - return true if consumed
216 bool (*getevent)(can_channel *priv, CYG_CAN_EVENT_T *pevent, void *pdata); // fetch one CAN event from device
217 Cyg_ErrNo (*get_config)(can_channel *priv, // query hardware configuration (baud rate, etc)
221 Cyg_ErrNo (*set_config)(can_channel *priv, // Change hardware configuration (baud rate, etc)
225 void (*start_xmit)(can_channel *priv); // Enable the transmit channel and turn on transmit interrupts
226 void (*stop_xmit)(can_channel *priv); // Disable the transmit channel and turn transmit interrupts off
229 #define CAN_LOWLEVEL_FUNS(_l,_putmsg,_getevent,_get_config,_set_config,_start_xmit,_stop_xmit) \
230 can_lowlevel_funs _l = { \
239 extern cyg_devio_table_t cyg_io_can_devio;
240 //-------------------------------------------------------------------------
241 #endif // CYGONCE_SERIAL_H