1 #ifndef CYGONCE_CANIO_H
2 #define CYGONCE_CANIO_H
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: Special support for CAN I/O devices
51 //####DESCRIPTIONEND####
53 // ====================================================================
56 //===========================================================================
58 //===========================================================================
59 #include <pkgconf/system.h>
60 #include <pkgconf/io_can.h>
61 #include <pkgconf/hal.h>
62 #include <cyg/infra/cyg_type.h>
63 #include <cyg/io/config_keys.h>
71 //===========================================================================
73 //===========================================================================
76 // Supported baud rates
79 CYGNUM_CAN_KBAUD_10 = 1,
87 CYGNUM_CAN_KBAUD_1000,
88 } cyg_can_baud_rate_t;
89 #define CYGNUM_CAN_KBAUD_MIN CYGNUM_CAN_KBAUD_10
90 #define CYGNUM_CAN_KBAUD_MAX CYGNUM_CAN_KBAUD_1000
93 // Note: two levels of macro are required to get proper expansion.
94 #define _CYG_CAN_BAUD_RATE(n) CYGNUM_CAN_KBAUD_##n
95 #define CYG_CAN_BAUD_RATE(n) _CYG_CAN_BAUD_RATE(n)
98 // Event types for received events. Not all event types are supported by each CAN
99 // hardware but normally these events should cover the most common CAN events
100 // that may occur. A combination of the event type values is allowed.
104 CYGNUM_CAN_EVENT_RX = 0x0001, // message received
105 CYGNUM_CAN_EVENT_TX = 0x0002, // mesage transmitted
106 CYGNUM_CAN_EVENT_WARNING_RX = 0x0004, // tx error counter (TEC) reached warning level (>96)
107 CYGNUM_CAN_EVENT_WARNING_TX = 0x0008, // rx error counter (REC) reached warning level (>96)
108 CYGNUM_CAN_EVENT_ERR_PASSIVE = 0x0010, // CAN "error passive" occured
109 CYGNUM_CAN_EVENT_BUS_OFF = 0x0020, // CAN "bus off" error occured
110 CYGNUM_CAN_EVENT_OVERRUN_RX = 0x0040, // overrun in RX queue or hardware occured
111 CYGNUM_CAN_EVENT_OVERRUN_TX = 0x0080, // overrun in TX queue occured
112 CYGNUM_CAN_EVENT_CAN_ERR = 0x0100, // a CAN bit or frame error occured
113 CYGNUM_CAN_EVENT_LEAVING_STANDBY = 0x0200, // CAN hardware leaves standby / power don mode or is waked up
114 CYGNUM_CAN_EVENT_ENTERING_STANDBY = 0x0400, // CAN hardware enters standby / power down mode
115 CYGNUM_CAN_EVENT_ARBITRATION_LOST = 0x0800, // arbitration lost
116 CYGNUM_CAN_EVENT_DEVICE_CHANGED = 0x1000, // device changed event
117 } cyg_can_event_flags;
120 // Type of CAN identifier.
124 CYGNUM_CAN_ID_STD = 0x00, // standard ID 11 Bit
125 CYGNUM_CAN_ID_EXT = 0x01 // extended ID 29 Bit
133 CYGNUM_CAN_FRAME_DATA = 0x00, // CAN data frame
134 CYGNUM_CAN_FRAME_RTR = 0x01 // CAN remote transmission request
135 } cyg_can_frame_type;
139 // CAN message type for transport or transmit of CAN messages
141 typedef struct can_message
143 cyg_uint32 id; // 11 Bit or 29 Bit CAN identifier - cyg_can_id_type
144 cyg_uint8 data[8];// 8 data bytes
145 cyg_can_id_type ext; // CYGNUM_CAN_ID_STD = 11 Bit CAN id, CYGNUM_CAN_ID_EXT = 29 Bit CAN id
146 cyg_can_frame_type rtr; // CYGNUM_CAN_FRAME_DATA = data frame, CYGNUM_CAN_FRAME_RTR = remote transmission request
147 cyg_uint8 dlc; // data length code (number of bytes (0 - 8) containing valid data
151 // CAN event type for reception of CAN events from driver. CAN events may be
152 // a received CAN message or any other status information like tx msg or
155 typedef struct cyg_can_event_st
157 cyg_uint32 timestamp;
163 // CAN configuration - at the moment there is only one data member but we are
164 // prepared for future enhancements
166 typedef struct cyg_can_info_st {
167 cyg_can_baud_rate_t baud;
171 // buffer configuration - bufsize and count for tx are the number of messages
172 // and for rx the number of events
174 typedef struct cyg_can_buf_info_st
176 cyg_int32 rx_bufsize;
178 cyg_int32 tx_bufsize;
180 } cyg_can_buf_info_t;
183 // Timeout configuration
185 typedef struct cyg_can_timeout_info_st
187 cyg_uint32 rx_timeout;
188 cyg_uint32 tx_timeout;
189 } cyg_can_timeout_info_t;
192 // this data type defines a remote transmission request buffer
194 typedef struct cyg_can_rtr_buf_st
201 // Values for the handle field of the cyg_can_rtr_buf_t data structure
203 #define CYGNUM_CAN_RTR_BUF_NA -0x01 // no free message buffer available
204 #define CYGNUM_CAN_RTR_BUF_INIT -0x02 // initialize the remote message buffer
207 #define CYG_CAN_INFO_INIT(_baud) \
214 //---------------------------------------------------------------------------
215 #endif // CYGONCE_CANIO_H