]> git.karo-electronics.de Git - karo-tx-redboot.git/blob - packages/io/can/v2_0/include/canio.h
60739a17aae317aec7372c620e65dcb80a8685f0
[karo-tx-redboot.git] / packages / io / can / v2_0 / include / canio.h
1 #ifndef CYGONCE_CANIO_H
2 #define CYGONCE_CANIO_H
3 // ====================================================================
4 //
5 //      canio.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-05-12
48 // Purpose:      Special support for CAN I/O devices
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 #include <pkgconf/hal.h>
62 #include <cyg/infra/cyg_type.h>
63 #include <cyg/io/config_keys.h>
64
65
66 #ifdef __cplusplus
67 extern "C" {
68 #endif
69
70
71 //===========================================================================
72 //                                DATA TYPES
73 //===========================================================================
74
75 //
76 // Supported baud rates
77 //
78 typedef enum {
79     CYGNUM_CAN_KBAUD_10 = 1,
80     CYGNUM_CAN_KBAUD_20,
81     CYGNUM_CAN_KBAUD_50,
82     CYGNUM_CAN_KBAUD_100,
83     CYGNUM_CAN_KBAUD_125,
84     CYGNUM_CAN_KBAUD_250,
85     CYGNUM_CAN_KBAUD_500,
86     CYGNUM_CAN_KBAUD_800,
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
91
92
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)
96
97 //
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.
101 //
102 typedef enum 
103 {
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;
118
119 //
120 // Type of CAN identifier. 
121 //
122 typedef enum
123 {
124     CYGNUM_CAN_ID_STD = 0x00, // standard ID 11 Bit
125     CYGNUM_CAN_ID_EXT = 0x01  // extended ID 29 Bit
126 } cyg_can_id_type;
127
128 //
129 // Type of CAN frame
130 //
131 typedef enum
132 {
133     CYGNUM_CAN_FRAME_DATA = 0x00, // CAN data frame
134     CYGNUM_CAN_FRAME_RTR  = 0x01  // CAN remote transmission request
135 } cyg_can_frame_type;
136
137
138 //
139 // CAN message type for transport or transmit of CAN messages 
140 //
141 typedef struct can_message
142 {
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
148 } cyg_can_message;
149
150 //
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
153 // arbitration lost
154 //
155 typedef struct cyg_can_event_st
156 {
157     cyg_uint32      timestamp;
158     cyg_can_message msg;
159     cyg_uint16      flags;     
160 } cyg_can_event;
161
162 //
163 // CAN configuration - at the moment there is only one data member but we are
164 // prepared for future enhancements
165 //
166 typedef struct cyg_can_info_st {
167     cyg_can_baud_rate_t   baud;
168 } cyg_can_info_t;
169
170 //
171 // buffer configuration - bufsize and count for tx are the number of messages
172 // and for rx the number of events
173 //
174 typedef struct cyg_can_buf_info_st
175 {  
176     cyg_int32 rx_bufsize; 
177     cyg_int32 rx_count;
178     cyg_int32 tx_bufsize;
179     cyg_int32 tx_count;
180 } cyg_can_buf_info_t;
181
182 //
183 // Timeout configuration
184 //
185 typedef struct cyg_can_timeout_info_st
186 {
187     cyg_uint32 rx_timeout; 
188     cyg_uint32 tx_timeout;
189 } cyg_can_timeout_info_t;
190
191 //
192 // this data type defines a remote transmission request buffer
193 //
194 typedef struct cyg_can_rtr_buf_st
195 {
196     cyg_int8        handle;
197     cyg_can_message msg;
198 } cyg_can_rtr_buf_t;
199
200 //
201 // Values for the handle field of the cyg_can_rtr_buf_t data structure
202 //
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
205
206
207 #define CYG_CAN_INFO_INIT(_baud) \
208   { _baud}
209
210 #ifdef __cplusplus
211 }
212 #endif
213
214 //---------------------------------------------------------------------------
215 #endif // CYGONCE_CANIO_H