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 //===========================================================================
70 // FORWARD DECLARATIONS
71 //===========================================================================
72 typedef struct can_channel can_channel;
73 typedef struct can_lowlevel_funs can_lowlevel_funs;
76 //===========================================================================
78 //===========================================================================
80 //---------------------------------------------------------------------------
81 // Pointers into uper-level driver which ISRs and DSRs need
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
91 #define CAN_CALLBACKS(_l,_init,_xmt_msg,_rcv_event) \
92 can_callbacks_t _l = { \
98 extern can_callbacks_t cyg_io_can_callbacks;
101 //---------------------------------------------------------------------------
102 // Data buffer for receive and transmit FIFOs
104 typedef struct can_cbuf_st
106 void *pdata; // points to data buffer
110 volatile int data_cnt; // count of events or messages currently in buffer
112 cyg_drv_mutex_t lock;
114 #if defined(CYGOPT_IO_CAN_SUPPORT_NONBLOCKING)
115 bool blocking; // true - timeouts will bes used, false - call blocks until data arrives
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
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}
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
138 //---------------------------------------------------------------------------
139 // Private data which describes this channel + initialisation macro
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
154 #define CAN_CHANNEL_USING_INTERRUPTS(_l, \
158 _out_buf, _out_buflen, \
159 _in_buf, _in_buflen) \
162 &cyg_io_can_callbacks, \
164 CYG_CAN_INFO_INIT(_baud), \
166 CBUF_INIT(_out_buf, _out_buflen, _TX_TIMEOUT), \
167 CBUF_INIT(_in_buf, _in_buflen, _RX_TIMEOUT) \
172 //---------------------------------------------------------------------------
173 // Low level interface functions - these functions are required by the generic
174 // CAN driver in order to access the low level hardware
176 struct can_lowlevel_funs
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)
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
188 #define CAN_LOWLEVEL_FUNS(_l,_putmsg,_getevent,_set_config,_start_xmit,_stop_xmit) \
189 can_lowlevel_funs _l = { \
197 extern cyg_devio_table_t cyg_io_can_devio;
198 //-------------------------------------------------------------------------
199 #endif // CYGONCE_SERIAL_H