source: pacpussensors/trunk/CanGateway/driver/kvaser/linux/VCanOsIf.h@ 109

Last change on this file since 109 was 97, checked in by DHERBOMEZ Gérald, 9 years ago

add include files for kvaser

File size: 14.4 KB
Line 
1/*
2** Copyright 2012 by Kvaser AB, Mölndal, Sweden
3** http://www.kvaser.com
4**
5** This software is dual licensed under the following two licenses:
6** BSD-new and GPLv2. You may use either one. See the included
7** COPYING file for details.
8**
9** License: BSD-new
10** ===============================================================================
11** Redistribution and use in source and binary forms, with or without
12** modification, are permitted provided that the following conditions are met:
13** * Redistributions of source code must retain the above copyright
14** notice, this list of conditions and the following disclaimer.
15** * Redistributions in binary form must reproduce the above copyright
16** notice, this list of conditions and the following disclaimer in the
17** documentation and/or other materials provided with the distribution.
18** * Neither the name of the <organization> nor the
19** names of its contributors may be used to endorse or promote products
20** derived from this software without specific prior written permission.
21**
22** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25** DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
26** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32**
33**
34** License: GPLv2
35** ===============================================================================
36** This program is free software; you can redistribute it and/or
37** modify it under the terms of the GNU General Public License
38** as published by the Free Software Foundation; either version 2
39** of the License, or (at your option) any later version.
40**
41** This program is distributed in the hope that it will be useful,
42** but WITHOUT ANY WARRANTY; without even the implied warranty of
43** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
44** GNU General Public License for more details.
45**
46** You should have received a copy of the GNU General Public License
47** along with this program; if not, write to the Free Software
48** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
49**
50** ---------------------------------------------------------------------------
51**/
52
53/*
54** Project:
55** linuxcan
56** Description:
57** common driver data structures.
58*/
59
60#ifndef _VCAN_OS_IF_H_
61#define _VCAN_OS_IF_H_
62
63
64# include <linux/poll.h>
65# include <asm/atomic.h>
66# include <linux/types.h>
67
68#include "canIfData.h"
69#include "vcanevt.h"
70#include "objbuf.h"
71
72#include "osif_common.h"
73#include "osif_kernel.h"
74#include "queue.h"
75
76
77/*****************************************************************************/
78/* Defines */
79/*****************************************************************************/
80
81#define MAIN_RCV_BUF_SIZE 16
82#define FILE_RCV_BUF_SIZE 500
83#define TX_CHAN_BUF_SIZE 500
84
85/*****************************************************************************/
86/* From vcanio.h */
87/*****************************************************************************/
88
89#define CAN_EXT_MSG_ID 0x80000000
90
91#define CAN_BUSSTAT_BUSOFF 0x01
92#define CAN_BUSSTAT_ERROR_PASSIVE 0x02
93#define CAN_BUSSTAT_ERROR_WARNING 0x04
94#define CAN_BUSSTAT_ERROR_ACTIVE 0x08
95#define CAN_BUSSTAT_BUSOFF_RECOVERY 0x10
96#define CAN_BUSSTAT_IGNORING_ERRORS 0x20
97
98#define CAN_CHIP_TYPE_UNKNOWN 0
99#define CAN_CHIP_TYPE_VIRTUAL 1
100#define CAN_CHIP_TYPE_SJA1000 2
101#define CAN_CHIP_TYPE_527 3
102#define CAN_CHIP_TYPE_C200 4
103
104
105/*****************************************************************************/
106/* */
107/*****************************************************************************/
108
109#define put_user_ret(x,ptr,ret) \
110 { if (os_if_set_int(x,ptr)) return ret; }
111#define get_user_int_ret(x,ptr,ret) \
112 { if (os_if_get_int(x,ptr)) return ret; }
113#define get_user_long_ret(x,ptr,ret) \
114 { if (os_if_get_long(x,ptr)) return ret; }
115#define copy_to_user_ret(to,from,n,retval) \
116 { if (os_if_get_user_data(to,from,n)) return retval; }
117#define copy_from_user_ret(to,from,n,retval) \
118 { if (os_if_set_user_data(to,from,n)) return retval; }
119
120#define ArgPtrIn(s)
121#define ArgPtrOut(s)
122#define ArgIntIn do { \
123 int argh; \
124 get_user_int_ret(&argh, (int *)arg, \
125 -EFAULT); \
126 arg = argh; \
127 } while (0)
128
129
130
131#define VCAN_STAT_OK 0
132#define VCAN_STAT_FAIL -1 // -EIO
133#define VCAN_STAT_TIMEOUT -2 // -EAGAIN (TIMEDOUT)?
134#define VCAN_STAT_NO_DEVICE -3 // -ENODEV
135#define VCAN_STAT_NO_RESOURCES -4 // -EAGAIN
136#define VCAN_STAT_NO_MEMORY -5 // -ENOMEM
137#define VCAN_STAT_SIGNALED -6 // -ERESTARTSYS
138#define VCAN_STAT_BAD_PARAMETER -7 // -EINVAL
139
140#define OPEN_AS_CAN 0
141#define OPEN_AS_CANFD_ISO 1
142#define OPEN_AS_CANFD_NONISO 2
143
144/*****************************************************************************/
145/* Data structures */
146/*****************************************************************************/
147
148typedef union {
149 uint32_t L;
150 struct { unsigned short w0, w1; } W;
151 struct { unsigned char b0, b1, b2, b3; } B;
152} WL;
153
154typedef struct CanChipState {
155 int state; /* buson / busoff / error passive / warning */
156 int txerr; /* tx error counter */
157 int rxerr; /* rx error counter */
158} CanChipState;
159
160
161/* Channel specific data */
162typedef struct VCanChanData
163{
164 int minorNr;
165 unsigned char channel;
166 unsigned char chipType;
167 unsigned char ean[8];
168 uint32_t serialHigh;
169 uint32_t serialLow;
170
171 /* Status */
172 unsigned char isOnBus;
173 unsigned char transType; // TRANSCEIVER_TYPE_xxx
174 unsigned char lineMode; // TRANSCEIVER_LINEMODE_xxx
175 unsigned char resNet; // TRANSCEIVER_RESNET_xxx
176 atomic_t transId;
177 atomic_t chanId;
178 unsigned int overrun;
179 CanChipState chipState;
180 unsigned int errorCount;
181 uint32_t errorTime;
182 unsigned char rxErrorCounter;
183 unsigned char txErrorCounter;
184 unsigned char canFdMode;
185 unsigned char driverMode;
186
187 /* Transmit buffer */
188 CAN_MSG txChanBuffer[TX_CHAN_BUF_SIZE];
189 CAN_MSG *currentTxMsg;
190 Queue txChanQueue;
191
192 /* Processes waiting for all messages to be sent */
193 OS_IF_WAITQUEUE_HEAD flushQ;
194
195 atomic_t fileOpenCount;
196 struct VCanOpenFileNode *openFileList;
197
198
199 OS_IF_LOCK openLock;
200 void *hwChanData;
201 OS_IF_ATOMIC_BIT waitEmpty;
202
203 struct VCanCardData *vCard;
204} VCanChanData;
205
206
207// For VCanCardData->card_flags
208#define DEVHND_CARD_FIRMWARE_BETA 0x01 // Firmware is beta
209#define DEVHND_CARD_FIRMWARE_RC 0x02 // Firmware is release candidate
210#define DEVHND_CARD_AUTO_RESP_OBJBUFS 0x04 // Firmware supports auto-response object buffers
211#define DEVHND_CARD_REFUSE_TO_RUN 0x08 // Major problem detected
212#define DEVHND_CARD_REFUSE_TO_USE_CAN 0x10 // Major problem detected
213#define DEVHND_CARD_AUTO_TX_OBJBUFS 0x20 // Firmware supports periodic transmit object buffers
214
215/* Cards specific data */
216typedef struct VCanCardData
217{
218 uint32_t hw_type;
219 uint32_t card_flags;
220 uint32_t capabilities; // qqq This should be per channel!
221 unsigned int nrChannels;
222 uint32_t serialNumber;
223 unsigned char ean[8];
224 unsigned int firmwareVersionMajor;
225 unsigned int firmwareVersionMinor;
226 unsigned int firmwareVersionBuild;
227 unsigned int hwRevisionMajor;
228 unsigned int hwRevisionMinor;
229
230 uint32_t timeHi;
231 uint32_t timeOrigin;
232 uint32_t usPerTick;
233
234 /* Ports and addresses */
235 unsigned char cardPresent;
236 VCanChanData **chanData;
237 void *hwCardData;
238
239 OS_IF_SEMAPHORE open;
240
241 struct VCanCardData *next;
242} VCanCardData;
243
244
245typedef struct VCanDriverData
246{
247 int noOfDevices;
248 int majorDevNr;
249 struct timeval startTime;
250 char *deviceName;
251} VCanDriverData;
252
253typedef struct
254{
255 int bufHead;
256 int bufTail;
257#if DEBUG
258 int lastEmpty;
259 int lastNotEmpty;
260#endif
261 VCAN_EVENT fileRcvBuffer[FILE_RCV_BUF_SIZE];
262 int size;
263 OS_IF_WAITQUEUE_HEAD rxWaitQ;
264} VCanReceiveData;
265
266/* File pointer specific data */
267typedef struct VCanOpenFileNode {
268 OS_IF_SEMAPHORE ioctl_mutex;
269 VCanReceiveData rcv;
270 unsigned char transId;
271 struct file *filp;
272 struct VCanChanData *chanData;
273 int chanNr;
274 unsigned char writeIsBlock;
275 unsigned char readIsBlock;
276 unsigned char modeTx;
277 unsigned char modeTxRq;
278 unsigned char modeNoTxEcho;
279 unsigned char channelOpen;
280 unsigned char channelLocked;
281 long writeTimeout;
282 long readTimeout;
283 VCanMsgFilter filter;
284 OS_IF_TASK_QUEUE_HANDLE objbufWork;
285 OS_IF_WQUEUE *objbufTaskQ;
286 OBJECT_BUFFER *objbuf;
287 atomic_t objbufActive;
288 uint32_t overruns;
289 struct VCanOpenFileNode *next;
290} VCanOpenFileNode;
291
292
293/* Dispatch call structure */
294typedef struct VCanHWInterface {
295 int (*initAllDevices) (void);
296 int (*setBusParams) (VCanChanData *chd, VCanBusParams *par);
297 int (*getBusParams) (VCanChanData *chd, VCanBusParams *par);
298 int (*autoSecondarySamplePoint)(VCanChanData *chd);
299 int (*getSecondarySamplePoint)(VCanChanData *chd, unsigned int *);
300 int (*setSecondarySamplePoint)(VCanChanData *chd, unsigned int *);
301 int (*setOutputMode) (VCanChanData *chd, int silent);
302 int (*setTranceiverMode) (VCanChanData *chd, int linemode, int resnet);
303 int (*busOn) (VCanChanData *chd);
304 int (*busOff) (VCanChanData *chd);
305 int (*txAvailable) (VCanChanData *chd);
306 int (*procRead) (struct seq_file* m, void* v);
307 int (*closeAllDevices) (void);
308 int (*getTime) (VCanCardData*, unsigned long *time);
309 int (*flushSendBuffer) (VCanChanData*);
310 int (*getRxErr) (VCanChanData*);
311 int (*getTxErr) (VCanChanData*);
312 unsigned long (*rxQLen) (VCanChanData*);
313 unsigned long (*txQLen) (VCanChanData*);
314 int (*requestChipState) (VCanChanData*);
315 void (*requestSend) (VCanCardData*, VCanChanData*);
316 unsigned int (*getVersion) (int);
317 int (*objbufExists) (VCanChanData *chd, int bufType, int bufNo);
318 int (*objbufFree) (VCanChanData *chd, int bufType, int bufNo);
319 int (*objbufAlloc) (VCanChanData *chd, int bufType, int *bufNo);
320 int (*objbufWrite) (VCanChanData *chd, int bufType, int bufNo,
321 int id, int flags, int dlc, unsigned char *data);
322 int (*objbufEnable) (VCanChanData *chd, int bufType, int bufNo,
323 int enable);
324 int (*objbufSetFilter) (VCanChanData *chd, int bufType, int bufNo,
325 int code, int mask);
326 int (*objbufSetFlags) (VCanChanData *chd, int bufType, int bufNo,
327 int flags);
328 int (*objbufSetPeriod) (VCanChanData *chd, int bufType, int bufNo,
329 int period);
330 int (*objbufSetMsgCount) (VCanChanData *chd, int bufType, int bufNo,
331 int count);
332 int (*objbufSendBurst) (VCanChanData *chd, int bufType, int bufNo,
333 int burstLen);
334
335 int (*llAccess) (VCanChanData*, void **);
336
337} VCanHWInterface;
338
339
340#define WAITNODE_DATA_SIZE 32 // 32 == MAX(MAX_CMD_LEN in filo_cmds.h and helios_cmds.h)
341typedef struct WaitNode {
342 struct list_head list;
343 OS_IF_SEMAPHORE waitSemaphore;
344 void *replyPtr;
345 unsigned char cmdNr;
346 unsigned char transId;
347 unsigned char timedOut;
348} WaitNode;
349
350
351
352/*****************************************************************************/
353/* Shared data structures */
354/*****************************************************************************/
355
356extern VCanDriverData driverData;
357extern VCanCardData *canCards;
358extern VCanHWInterface hwIf;
359extern OS_IF_LOCK canCardsLock;
360extern struct file_operations fops;
361
362
363
364
365/*****************************************************************************/
366/* Function definitions */
367/*****************************************************************************/
368
369
370
371/* Functions */
372int vCanInitData(VCanCardData *chd);
373int vCanTime(VCanCardData *vCard, unsigned long *time);
374int vCanDispatchEvent(VCanChanData *chd, VCAN_EVENT *e);
375int vCanFlushSendBuffer(VCanChanData *chd);
376unsigned long getQLen(unsigned long head, unsigned long tail, unsigned long size);
377
378
379#endif /* _VCAN_OS_IF_H_ */
Note: See TracBrowser for help on using the repository browser.