1 |
786 |
skrzyp |
#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 Free Software Foundation, 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
|
18 |
|
|
// version.
|
19 |
|
|
//
|
20 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT
|
21 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
22 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
23 |
|
|
// for more details.
|
24 |
|
|
//
|
25 |
|
|
// You should have received a copy of the GNU General Public License
|
26 |
|
|
// along with eCos; if not, write to the Free Software Foundation, Inc.,
|
27 |
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
28 |
|
|
//
|
29 |
|
|
// As a special exception, if other files instantiate templates or use
|
30 |
|
|
// macros or inline functions from this file, or you compile this file
|
31 |
|
|
// and link it with other works to produce a work based on this file,
|
32 |
|
|
// this file does not by itself cause the resulting work to be covered by
|
33 |
|
|
// the GNU General Public License. However the source code for this file
|
34 |
|
|
// must still be made available in accordance with section (3) of the GNU
|
35 |
|
|
// General Public License v2.
|
36 |
|
|
//
|
37 |
|
|
// This exception does not invalidate any other reasons why a work based
|
38 |
|
|
// on this file might be covered by the GNU General Public License.
|
39 |
|
|
// -------------------------------------------
|
40 |
|
|
// ####ECOSGPLCOPYRIGHTEND####
|
41 |
|
|
// ====================================================================
|
42 |
|
|
//#####DESCRIPTIONBEGIN####
|
43 |
|
|
//
|
44 |
|
|
// Author(s): Uwe Kindler
|
45 |
|
|
// Contributors: gthomas
|
46 |
|
|
// Date: 2005-05-12
|
47 |
|
|
// Purpose: Special support for CAN I/O devices
|
48 |
|
|
// Description:
|
49 |
|
|
//
|
50 |
|
|
//####DESCRIPTIONEND####
|
51 |
|
|
//
|
52 |
|
|
// ====================================================================
|
53 |
|
|
|
54 |
|
|
|
55 |
|
|
//===========================================================================
|
56 |
|
|
// INCLUDES
|
57 |
|
|
//===========================================================================
|
58 |
|
|
#include <pkgconf/system.h>
|
59 |
|
|
#include <pkgconf/io_can.h>
|
60 |
|
|
#include <pkgconf/hal.h>
|
61 |
|
|
#include <cyg/infra/cyg_type.h>
|
62 |
|
|
#include <cyg/io/config_keys.h>
|
63 |
|
|
|
64 |
|
|
|
65 |
|
|
#ifdef __cplusplus
|
66 |
|
|
extern "C" {
|
67 |
|
|
#endif
|
68 |
|
|
|
69 |
|
|
|
70 |
|
|
//===========================================================================
|
71 |
|
|
// DATA TYPES
|
72 |
|
|
//===========================================================================
|
73 |
|
|
|
74 |
|
|
//
|
75 |
|
|
// Supported baud rates
|
76 |
|
|
//
|
77 |
|
|
typedef enum {
|
78 |
|
|
CYGNUM_CAN_KBAUD_10 = 1,
|
79 |
|
|
CYGNUM_CAN_KBAUD_20,
|
80 |
|
|
CYGNUM_CAN_KBAUD_50,
|
81 |
|
|
CYGNUM_CAN_KBAUD_100,
|
82 |
|
|
CYGNUM_CAN_KBAUD_125,
|
83 |
|
|
CYGNUM_CAN_KBAUD_250,
|
84 |
|
|
CYGNUM_CAN_KBAUD_500,
|
85 |
|
|
CYGNUM_CAN_KBAUD_800,
|
86 |
|
|
CYGNUM_CAN_KBAUD_1000,
|
87 |
|
|
CYGNUM_CAN_KBAUD_AUTO, // automatic detection of baudrate (if supported by hardware)
|
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 |
|
|
#define CYGNUM_CAN_EVENT_RX 0x00000001 // message received
|
103 |
|
|
#define CYGNUM_CAN_EVENT_TX 0x00000002 // mesage transmitted
|
104 |
|
|
#define CYGNUM_CAN_EVENT_WARNING_RX 0x00000004 // tx error counter (TEC) reached warning level (>96)
|
105 |
|
|
#define CYGNUM_CAN_EVENT_WARNING_TX 0x00000008 // rx error counter (REC) reached warning level (>96)
|
106 |
|
|
#define CYGNUM_CAN_EVENT_ERR_PASSIVE 0x00000010 // CAN "error passive" occured
|
107 |
|
|
#define CYGNUM_CAN_EVENT_BUS_OFF 0x00000020 // CAN "bus off" error occured
|
108 |
|
|
#define CYGNUM_CAN_EVENT_OVERRUN_RX 0x00000040 // overrun in RX queue occured
|
109 |
|
|
#define CYGNUM_CAN_EVENT_OVERRUN_TX 0x00000080 // overrun in TX queue occured
|
110 |
|
|
#define CYGNUM_CAN_EVENT_CAN_ERR 0x00000100 // a CAN bit or frame error occured
|
111 |
|
|
#define CYGNUM_CAN_EVENT_LEAVING_STANDBY 0x00000200 // CAN hardware leaves standby/power down mode or is waked up
|
112 |
|
|
#define CYGNUM_CAN_EVENT_ENTERING_STANDBY 0x00000400 // CAN hardware enters standby/power down mode
|
113 |
|
|
#define CYGNUM_CAN_EVENT_ARBITRATION_LOST 0x00000800 // arbitration lost
|
114 |
|
|
#define CYGNUM_CAN_EVENT_FILTER_ERR 0x00001000 // CAN message filter / acceptance filter error
|
115 |
|
|
#define CYGNUM_CAN_EVENT_PHY_FAULT 0x00002000 // General failure of physical layer detected (if supported by hardware)
|
116 |
|
|
#define CYGNUM_CAN_EVENT_PHY_H 0x00004000 // Fault on CAN-H detected (Low Speed CAN)
|
117 |
|
|
#define CYGNUM_CAN_EVENT_PHY_L 0x00008000 // Fault on CAN-L detected (Low Speed CAN)
|
118 |
|
|
#define CYGNUM_CAN_EVENT_ERR_ACTIVE 0x00010000 // CAN controller now "error active"
|
119 |
|
|
#define CYGNUM_CAN_EVENT_OVERRUN_RX_HW 0x00020000 // CAN controller reports a RX overrun
|
120 |
|
|
|
121 |
|
|
typedef cyg_int32 cyg_can_event_flags_t;
|
122 |
|
|
|
123 |
|
|
#define CYGNUM_CAN_EVENT_ALL \
|
124 |
|
|
CYGNUM_CAN_EVENT_RX \
|
125 |
|
|
|CYGNUM_CAN_EVENT_TX \
|
126 |
|
|
|CYGNUM_CAN_EVENT_WARNING_RX \
|
127 |
|
|
|CYGNUM_CAN_EVENT_WARNING_TX \
|
128 |
|
|
|CYGNUM_CAN_EVENT_ERR_PASSIVE \
|
129 |
|
|
|CYGNUM_CAN_EVENT_BUS_OFF \
|
130 |
|
|
|CYGNUM_CAN_EVENT_OVERRUN_RX \
|
131 |
|
|
|CYGNUM_CAN_EVENT_OVERRUN_TX \
|
132 |
|
|
|CYGNUM_CAN_EVENT_CAN_ERR \
|
133 |
|
|
|CYGNUM_CAN_EVENT_LEAVING_STANDBY \
|
134 |
|
|
|CYGNUM_CAN_EVENT_ENTERING_STANDBY \
|
135 |
|
|
|CYGNUM_CAN_EVENT_ARBITRATION_LOST \
|
136 |
|
|
|CYGNUM_CAN_EVENT_FILTER_ERR \
|
137 |
|
|
|CYGNUM_CAN_EVENT_PHY_FAULT \
|
138 |
|
|
|CYGNUM_CAN_EVENT_PHY_H \
|
139 |
|
|
|CYGNUM_CAN_EVENT_PHY_L \
|
140 |
|
|
|CYGNUM_CAN_EVENT_ERR_ACTIVE \
|
141 |
|
|
|CYGNUM_CAN_EVENT_OVERRUN_RX_HW
|
142 |
|
|
|
143 |
|
|
//
|
144 |
|
|
// State of CAN controller
|
145 |
|
|
//
|
146 |
|
|
typedef enum e_cyg_can_state
|
147 |
|
|
{
|
148 |
|
|
CYGNUM_CAN_STATE_ACTIVE, // CAN controller is active, no errors
|
149 |
|
|
CYGNUM_CAN_STATE_STOPPED, // CAN controller is in stopped mode
|
150 |
|
|
CYGNUM_CAN_STATE_STANDBY, // CAN controller is in Sleep mode
|
151 |
|
|
CYGNUM_CAN_STATE_BUS_WARN, // CAN controller is active, warning level is reached
|
152 |
|
|
CYGNUM_CAN_STATE_ERR_PASSIVE, // CAN controller went into error passive mode
|
153 |
|
|
CYGNUM_CAN_STATE_BUS_OFF, // CAN controller went into bus off mode
|
154 |
|
|
CYGNUM_CAN_STATE_PHY_FAULT, // General failure of physical layer detected (if supported by hardware)
|
155 |
|
|
CYGNUM_CAN_STATE_PHY_H, // Fault on CAN-H detected (Low Speed CAN)
|
156 |
|
|
CYGNUM_CAN_STATE_PHY_L, // Fault on CAN-L detected (Low Speed CAN)
|
157 |
|
|
CYGNUM_CAN_STATE_CONFIG, // CAN controller is in configuration state
|
158 |
|
|
} cyg_can_state;
|
159 |
|
|
|
160 |
|
|
//
|
161 |
|
|
// Identifiers for operating mode of the CAN controller.
|
162 |
|
|
//
|
163 |
|
|
typedef enum e_cyg_can_mode
|
164 |
|
|
{
|
165 |
|
|
CYGNUM_CAN_MODE_STOP, // set controller into stop mode
|
166 |
|
|
CYGNUM_CAN_MODE_START, // set controller into operational mode
|
167 |
|
|
CYGNUM_CAN_MODE_STANDBY,// set controller into standby / sleep mode
|
168 |
|
|
CYGNUM_CAN_MODE_CONFIG, // safe mode to add/delete message buffers
|
169 |
|
|
CYGNUM_CAN_MODE_LISTEN_ONLY_ENTER, // set controller into listen only mode.
|
170 |
|
|
CYGNUM_CAN_MODE_LISTEN_ONLY_EXIT // set controller out of listen only mode.
|
171 |
|
|
} cyg_can_mode;
|
172 |
|
|
|
173 |
|
|
//
|
174 |
|
|
// Type of CAN identifier.
|
175 |
|
|
//
|
176 |
|
|
typedef enum e_cyg_can_id_type
|
177 |
|
|
{
|
178 |
|
|
CYGNUM_CAN_ID_STD = 0x00, // standard ID 11 Bit
|
179 |
|
|
CYGNUM_CAN_ID_EXT = 0x01 // extended ID 29 Bit
|
180 |
|
|
} cyg_can_id_type;
|
181 |
|
|
|
182 |
|
|
//
|
183 |
|
|
// Type of CAN frame
|
184 |
|
|
//
|
185 |
|
|
typedef enum e_cyg_can_frame_type
|
186 |
|
|
{
|
187 |
|
|
CYGNUM_CAN_FRAME_DATA = 0x00, // CAN data frame
|
188 |
|
|
CYGNUM_CAN_FRAME_RTR = 0x01 // CAN remote transmission request
|
189 |
|
|
} cyg_can_frame_type;
|
190 |
|
|
|
191 |
|
|
//
|
192 |
|
|
// Message buffer configuration identifier - we do not use an enum here so that
|
193 |
|
|
// a specific device driver can add its own configuration identifier
|
194 |
|
|
//
|
195 |
|
|
typedef cyg_uint8 cyg_can_msgbuf_cfg_id;
|
196 |
|
|
#define CYGNUM_CAN_MSGBUF_RESET_ALL 0 // no message will be received, all remote buffers deleted
|
197 |
|
|
#define CYGNUM_CAN_MSGBUF_RX_FILTER_ALL 1 // cfg driver for reception of all can messges
|
198 |
|
|
#define CYGNUM_CAN_MSGBUF_RX_FILTER_ADD 2 // add single message filter
|
199 |
|
|
#define CYGNUM_CAN_MSGBUF_REMOTE_BUF_ADD 3 // add new remote response buffer
|
200 |
|
|
#define CYGNUM_CAN_MSGBUF_REMOTE_BUF_WRITE 4 // store data into existing remote buffer (remote buf handle required)
|
201 |
|
|
|
202 |
|
|
|
203 |
|
|
//
|
204 |
|
|
// CAN message data - this union is a container for the 8 data bytes of a can
|
205 |
|
|
// message and the union is alway part of a can message - no matter if this type
|
206 |
|
|
// is defined by generic CAN layer or by CAN hardware device driver
|
207 |
|
|
//
|
208 |
|
|
typedef union u_cyg_can_msg_data
|
209 |
|
|
{
|
210 |
|
|
cyg_uint8 bytes[8]; // byte access (array of 8 bytes)
|
211 |
|
|
cyg_uint16 words[4]; // word access (array of 4 words)
|
212 |
|
|
cyg_uint32 dwords[2]; // double word access (array of 2 dwords)
|
213 |
|
|
} cyg_can_msg_data;
|
214 |
|
|
|
215 |
|
|
//
|
216 |
|
|
// CAN message type for transport or transmit of CAN messages
|
217 |
|
|
// The message data is a union. This enables byte, word and dword access and
|
218 |
|
|
// also ensures a 4 byte alignment of the message data
|
219 |
|
|
//
|
220 |
|
|
typedef struct st_cyg_can_message
|
221 |
|
|
{
|
222 |
|
|
cyg_uint32 id; // 11 Bit or 29 Bit CAN identifier - cyg_can_id_type
|
223 |
|
|
cyg_can_msg_data data; // CAN data (8 data bytes)
|
224 |
|
|
cyg_can_id_type ext; // CYGNUM_CAN_ID_STD = 11 Bit CAN id, CYGNUM_CAN_ID_EXT = 29 Bit CAN id
|
225 |
|
|
cyg_can_frame_type rtr; // CYGNUM_CAN_FRAME_DATA = data frame, CYGNUM_CAN_FRAME_RTR = remote transmission request
|
226 |
|
|
cyg_uint8 dlc; // data length code (number of bytes (0 - 8) containing valid data
|
227 |
|
|
} cyg_can_message;
|
228 |
|
|
|
229 |
|
|
//
|
230 |
|
|
// CAN event type for reception of CAN events from driver. CAN events may be
|
231 |
|
|
// a received CAN message or any other status information like tx msg or
|
232 |
|
|
// arbitration lost
|
233 |
|
|
//
|
234 |
|
|
typedef struct cyg_can_event_st
|
235 |
|
|
{
|
236 |
|
|
cyg_uint32 timestamp;
|
237 |
|
|
cyg_can_event_flags_t flags;
|
238 |
|
|
cyg_can_message msg;
|
239 |
|
|
} cyg_can_event;
|
240 |
|
|
|
241 |
|
|
//
|
242 |
|
|
// CAN configuration - at the moment there is only one data member but we are
|
243 |
|
|
// prepared for future enhancements
|
244 |
|
|
//
|
245 |
|
|
typedef struct cyg_can_info_st {
|
246 |
|
|
cyg_can_baud_rate_t baud;
|
247 |
|
|
} cyg_can_info_t;
|
248 |
|
|
|
249 |
|
|
|
250 |
|
|
#define CYG_CAN_INFO_INIT(_baud) \
|
251 |
|
|
{ _baud}
|
252 |
|
|
|
253 |
|
|
//
|
254 |
|
|
// buffer configuration - bufsize and count for tx are the number of messages
|
255 |
|
|
// and for rx the number of events
|
256 |
|
|
//
|
257 |
|
|
typedef struct cyg_can_buf_info_st
|
258 |
|
|
{
|
259 |
|
|
cyg_uint32 rx_bufsize;
|
260 |
|
|
cyg_uint32 rx_count;
|
261 |
|
|
cyg_uint32 tx_bufsize;
|
262 |
|
|
cyg_uint32 tx_count;
|
263 |
|
|
} cyg_can_buf_info_t;
|
264 |
|
|
|
265 |
|
|
//
|
266 |
|
|
// Message box configuration
|
267 |
|
|
//
|
268 |
|
|
typedef struct cyg_can_msgbox_info_st
|
269 |
|
|
{
|
270 |
|
|
cyg_uint16 count; // number of message buffers available for this device
|
271 |
|
|
cyg_uint16 free; // number of free message buffers
|
272 |
|
|
} cyg_can_msgbuf_info;
|
273 |
|
|
|
274 |
|
|
|
275 |
|
|
//
|
276 |
|
|
// Timeout configuration
|
277 |
|
|
//
|
278 |
|
|
typedef struct cyg_can_timeout_info_st
|
279 |
|
|
{
|
280 |
|
|
cyg_uint32 rx_timeout;
|
281 |
|
|
cyg_uint32 tx_timeout;
|
282 |
|
|
} cyg_can_timeout_info_t;
|
283 |
|
|
|
284 |
|
|
|
285 |
|
|
//
|
286 |
|
|
// this data type defines a handle to a message buffer or message box
|
287 |
|
|
// of the CAN hardware device
|
288 |
|
|
//
|
289 |
|
|
typedef cyg_int32 cyg_can_msgbuf_handle;
|
290 |
|
|
|
291 |
|
|
|
292 |
|
|
//
|
293 |
|
|
// structure for configuration of message buffers
|
294 |
|
|
//
|
295 |
|
|
typedef struct cyg_can_msgbox_cfg_st
|
296 |
|
|
{
|
297 |
|
|
cyg_can_msgbuf_cfg_id cfg_id; // configuration id - cfg. what to do with message buffer
|
298 |
|
|
cyg_can_msgbuf_handle handle; // handle to message buffer
|
299 |
|
|
cyg_can_message msg; // CAN message - for configuration of buffer
|
300 |
|
|
} cyg_can_msgbuf_cfg;
|
301 |
|
|
|
302 |
|
|
//
|
303 |
|
|
// structure for configuration of identifier range filtering
|
304 |
|
|
//
|
305 |
|
|
typedef struct cyg_can_filter_range_cfg_st
|
306 |
|
|
{
|
307 |
|
|
cyg_can_id_type ext; // type of identifier concerned
|
308 |
|
|
cyg_uint32 lower_id_bound; // lower bound identifier (included)
|
309 |
|
|
cyg_uint32 upper_id_bound; // upper bound identifier (included)
|
310 |
|
|
} cyg_can_filter_range_cfg;
|
311 |
|
|
|
312 |
|
|
//
|
313 |
|
|
// structure for configuration of identifier/mask filtering
|
314 |
|
|
//
|
315 |
|
|
typedef struct cyg_can_filter_mask_cfg_st
|
316 |
|
|
{
|
317 |
|
|
cyg_can_id_type ext; // type of identifier concerned
|
318 |
|
|
cyg_uint32 id; // identifier to use for filtering
|
319 |
|
|
cyg_uint32 mask; // mask to apply for filtering
|
320 |
|
|
} cyg_can_filter_mask_cfg;
|
321 |
|
|
|
322 |
|
|
//
|
323 |
|
|
// this data type defines a CAN message filter. It consits
|
324 |
|
|
// of a handle to a message box or message buffer and a CAN message.
|
325 |
|
|
// For the filtering only the id and the ext field of the CAN message are
|
326 |
|
|
// important. The values of the other fields doesn't matter
|
327 |
|
|
//
|
328 |
|
|
typedef cyg_can_msgbuf_cfg cyg_can_filter;
|
329 |
|
|
|
330 |
|
|
//
|
331 |
|
|
// this data type defines a remote buffer. It consits
|
332 |
|
|
// of a handle to a message box or message buffer and the message data
|
333 |
|
|
// to send on reception of a remote request
|
334 |
|
|
//
|
335 |
|
|
typedef cyg_can_msgbuf_cfg cyg_can_remote_buf;
|
336 |
|
|
|
337 |
|
|
//
|
338 |
|
|
// Values for the handle field of the cyg_can_rtr_buf, cyg_can_filter and
|
339 |
|
|
// cyg_can_msgbuf_cfg data structure
|
340 |
|
|
//
|
341 |
|
|
#define CYGNUM_CAN_MSGBUF_NA -0x01 // no free message buffer available
|
342 |
|
|
|
343 |
|
|
|
344 |
|
|
//
|
345 |
|
|
// The Hardware Description Interface provides a method to gather information
|
346 |
|
|
// about the CAN hardware and the functionality of the driver. For
|
347 |
|
|
// this purpose the following structure is defined:
|
348 |
|
|
//
|
349 |
|
|
// Support flags:
|
350 |
|
|
// | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
|
351 |
|
|
// +-------+-------+-------+-------+--------+-------+-------+--------+
|
352 |
|
|
// |ListenO|Mask F |Range F|timest.|autobaud|FullCAN| Frametype |
|
353 |
|
|
//
|
354 |
|
|
typedef struct cyg_can_hdi_st
|
355 |
|
|
{
|
356 |
|
|
cyg_uint8 support_flags;
|
357 |
|
|
cyg_uint8 controller_type;
|
358 |
|
|
} cyg_can_hdi;
|
359 |
|
|
|
360 |
|
|
//
|
361 |
|
|
// Bit 0 and Bit 1 of the structure member support_flags describe the
|
362 |
|
|
// possibities of the CAN controller. The following values are defined:
|
363 |
|
|
//
|
364 |
|
|
#define CYGNUM_CAN_HDI_FRAMETYPE_STD 0x00 // standard frame (11-bit identifier), 2.0A
|
365 |
|
|
#define CYGNUM_CAN_HDI_FRAMETYPE_EXT_PASSIVE 0x01 // extended frame (29-bit identifier), 2.0B passive
|
366 |
|
|
#define CYGNUM_CAN_HDI_FRAMETYPE_EXT_ACTIVE 0x02 // extended frame (29-bit identifier), 2.0B active
|
367 |
|
|
#define CYGNUM_CAN_HDI_FULLCAN 0x04 // controller supports more than one receive and transmit buffer
|
368 |
|
|
#define CYGNUM_CAN_HDI_AUTBAUD 0x08 // driver supports automatic baudrate detection
|
369 |
|
|
#define CYGNUM_CAN_HDI_TIMESTAMP 0x10 // driver supports timestamps
|
370 |
|
|
#define CYGNUM_CAN_HDI_RANGE_FILTERING 0x20 // driver supports identifier range filtering
|
371 |
|
|
#define CYGNUM_CAN_HDI_MASK_FILTERING 0x40 // driver supports identifier mask filtering
|
372 |
|
|
#define CYGNUM_CAN_HDI_LISTEN_ONLY 0x80 // driver supports 'listen-only' mode.
|
373 |
|
|
|
374 |
|
|
//
|
375 |
|
|
// Callback configuration structure.
|
376 |
|
|
//
|
377 |
|
|
|
378 |
|
|
typedef void (*cyg_can_event_cb_t)(cyg_uint16, CYG_ADDRWORD);
|
379 |
|
|
//
|
380 |
|
|
// flag_mask should be set with a combination of CYGNUM_CAN_EVENT_* flags.
|
381 |
|
|
// If one of these events happens, the callback function will be called,
|
382 |
|
|
// with the actually event flags passed as a parameter.
|
383 |
|
|
//
|
384 |
|
|
typedef struct cyg_can_callback_cfg_st
|
385 |
|
|
{
|
386 |
|
|
cyg_can_event_cb_t callback_func; // callback function
|
387 |
|
|
cyg_can_event_flags_t flag_mask; // flags mask
|
388 |
|
|
CYG_ADDRWORD data; // data passed to callback
|
389 |
|
|
} cyg_can_callback_cfg;
|
390 |
|
|
|
391 |
|
|
|
392 |
|
|
//===========================================================================
|
393 |
|
|
// CAN MESSAGE ACCESS MACROS
|
394 |
|
|
//
|
395 |
|
|
// An application should not access a cyg_can_message directly instead it
|
396 |
|
|
// should use these macros for all manipulations to a CAN message.
|
397 |
|
|
//===========================================================================
|
398 |
|
|
|
399 |
|
|
//---------------------------------------------------------------------------
|
400 |
|
|
// Frame type macros
|
401 |
|
|
//
|
402 |
|
|
#define CYG_CAN_MSG_SET_FRAME_TYPE(_msg_, _type_) ((_msg_).rtr = (_type_))
|
403 |
|
|
#define CYG_CAN_MSG_GET_FRAME_TYPE(_msg_) ((_msg_).rtr)
|
404 |
|
|
#define CYG_CAN_MSG_SET_RTR(_msg_) ((_msg_).rtr = CYGNUM_CAN_FRAME_RTR)
|
405 |
|
|
#define CYG_CAN_MSG_IS_REMOTE(_msg_) ((_msg_).rtr == CYGNUM_CAN_FRAME_RTR)
|
406 |
|
|
|
407 |
|
|
|
408 |
|
|
//---------------------------------------------------------------------------
|
409 |
|
|
// ID type macros
|
410 |
|
|
//
|
411 |
|
|
#define CYG_CAN_MSG_SET_ID_TYPE(_msg_, _type_) ((_msg_).ext = (_type_))
|
412 |
|
|
#define CYG_CAN_MSG_GET_ID_TYPE(_msg_) ((_msg_).ext)
|
413 |
|
|
#define CYG_CAN_MSG_SET_EXT(_msg_) ((_msg_).ext = CYGNUM_CAN_ID_EXT)
|
414 |
|
|
#define CYG_CAN_MSG_SET_STD(_msg_) ((_msg_).ext = CYGNUM_CAN_ID_STD)
|
415 |
|
|
#define CYG_CAN_MSG_IS_EXT(_msg_) ((_msg_).ext == CYGNUM_CAN_ID_EXT)
|
416 |
|
|
|
417 |
|
|
|
418 |
|
|
//---------------------------------------------------------------------------
|
419 |
|
|
// Identifier access macros
|
420 |
|
|
//
|
421 |
|
|
#define CYG_CAN_MSG_GET_ID(_msg_) ((_msg_).id)
|
422 |
|
|
#define CYG_CAN_MSG_SET_ID(_msg_, _id_) ((_msg_).id = (_id_))
|
423 |
|
|
#define CYG_CAN_MSG_SET_STD_ID(_msg_, _id_) \
|
424 |
|
|
CYG_MACRO_START \
|
425 |
|
|
CYG_CAN_MSG_SET_ID(_msg_, _id_); \
|
426 |
|
|
CYG_CAN_MSG_SET_STD(_msg_); \
|
427 |
|
|
CYG_MACRO_END
|
428 |
|
|
|
429 |
|
|
#define CYG_CAN_MSG_SET_EXT_ID(_msg_, _id_) \
|
430 |
|
|
CYG_MACRO_START \
|
431 |
|
|
CYG_CAN_MSG_SET_ID(_msg_, _id_); \
|
432 |
|
|
CYG_CAN_MSG_SET_EXT(_msg_); \
|
433 |
|
|
CYG_MACRO_END
|
434 |
|
|
|
435 |
|
|
|
436 |
|
|
//---------------------------------------------------------------------------
|
437 |
|
|
// DLC (data length code) access macros
|
438 |
|
|
//
|
439 |
|
|
#define CYG_CAN_MSG_GET_DATA_LEN(_msg_) ((_msg_).dlc)
|
440 |
|
|
#define CYG_CAN_MSG_SET_DATA_LEN(_msg_, _len_) ((_msg_).dlc = (_len_))
|
441 |
|
|
|
442 |
|
|
|
443 |
|
|
//---------------------------------------------------------------------------
|
444 |
|
|
// CAN message data access
|
445 |
|
|
// This macro returns a pointer to a cyg_can_msg_data union
|
446 |
|
|
//
|
447 |
|
|
#define CYG_CAN_MSG_DATA_PTR(_msg_) (&(_msg_).data)
|
448 |
|
|
#define CYG_CAN_MSG_GET_DATA(_msg_, _pos_) ((_msg_).data.bytes[_pos_])
|
449 |
|
|
#define CYG_CAN_MSG_SET_DATA(_msg_, _pos_, _val_) ((_msg_).data.bytes[_pos_] = (_val_))
|
450 |
|
|
|
451 |
|
|
|
452 |
|
|
//---------------------------------------------------------------------------
|
453 |
|
|
// Access multiple parameters
|
454 |
|
|
//
|
455 |
|
|
#define CYG_CAN_MSG_SET_PARAM(_msg_, _id_, _ext_, _dlc_, _rtr_) \
|
456 |
|
|
CYG_MACRO_START \
|
457 |
|
|
CYG_CAN_MSG_SET_ID(_msg_, _id_); \
|
458 |
|
|
CYG_CAN_MSG_SET_ID_TYPE(_msg_, _ext_); \
|
459 |
|
|
CYG_CAN_MSG_SET_DATA_LEN(_msg_, _dlc_); \
|
460 |
|
|
CYG_CAN_MSG_SET_FRAME_TYPE(_msg_, _rtr_); \
|
461 |
|
|
CYG_MACRO_END
|
462 |
|
|
|
463 |
|
|
#define CYG_CAN_MSG_INIT(_clabel_, _id_, _ext_, _dlc_, _rtr_) \
|
464 |
|
|
cyg_can_message _clabel_ = \
|
465 |
|
|
{ \
|
466 |
|
|
id : _id_, \
|
467 |
|
|
ext : _ext_, \
|
468 |
|
|
rtr : _rtr_, \
|
469 |
|
|
dlc : _dlc_, \
|
470 |
|
|
}
|
471 |
|
|
|
472 |
|
|
|
473 |
|
|
|
474 |
|
|
#ifdef __cplusplus
|
475 |
|
|
}
|
476 |
|
|
#endif
|
477 |
|
|
|
478 |
|
|
//---------------------------------------------------------------------------
|
479 |
|
|
#endif // CYGONCE_CANIO_H
|