RTEMS 5.2
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
grcan.h
Go to the documentation of this file.
1
7/*
8 * COPYRIGHT (c) 2007.
9 * Cobham Gaisler AB.
10 *
11 * The license and distribution terms for this file may be
12 * found in the file LICENSE in this distribution or at
13 * http://www.rtems.org/license/LICENSE.
14 */
15
16#ifndef __GRCAN_H__
17#define __GRCAN_H__
18
29#include <stdint.h>
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
35struct grcan_regs {
36 volatile unsigned int conf; /* 0x00 */
37 volatile unsigned int stat; /* 0x04 */
38 volatile unsigned int ctrl; /* 0x08 */
39 volatile unsigned int dummy0[3]; /* 0x0C-0x014 */
40 volatile unsigned int smask; /* 0x18 */
41 volatile unsigned int scode; /* 0x1C */
42
43 volatile unsigned int dummy1[8]; /* 0x20-0x3C */
44
45 volatile unsigned int nbtr; /* 0x40 */
46 volatile unsigned int fdbtr; /* 0x44 */
47 volatile unsigned int tdelay; /* 0x48 */
48
49 volatile unsigned int dummy1b[45]; /* 0x4C-0xFC */
50
51 volatile unsigned int pimsr; /* 0x100 */
52 volatile unsigned int pimr; /* 0x104 */
53 volatile unsigned int pisr; /* 0x108 */
54 volatile unsigned int pir; /* 0x10C */
55 volatile unsigned int imr; /* 0x110 */
56 volatile unsigned int picr; /* 0x114 */
57
58 volatile unsigned int dummy2[58]; /* 0x118-0x1FC */
59
60 volatile unsigned int tx0ctrl; /* 0x200 */
61 volatile unsigned int tx0addr; /* 0x204 */
62 volatile unsigned int tx0size; /* 0x208 */
63 volatile unsigned int tx0wr; /* 0x20C */
64 volatile unsigned int tx0rd; /* 0x210 */
65 volatile unsigned int tx0irq; /* 0x214 */
66
67 volatile unsigned int dummy3[58]; /* 0x218-0x2FC */
68
69 volatile unsigned int rx0ctrl; /* 0x300 */
70 volatile unsigned int rx0addr; /* 0x304 */
71 volatile unsigned int rx0size; /* 0x308 */
72 volatile unsigned int rx0wr; /* 0x30C */
73 volatile unsigned int rx0rd; /* 0x310 */
74 volatile unsigned int rx0irq; /* 0x314 */
75 volatile unsigned int rx0mask; /* 0x318 */
76 volatile unsigned int rx0code; /* 0x31C */
77};
78
80 unsigned int passive_cnt;
81 unsigned int overrun_cnt;
82 unsigned int rxsync_cnt;
83 unsigned int txsync_cnt;
84 unsigned int txloss_cnt;
85 unsigned int ahberr_cnt;
86 unsigned int ints;
87 unsigned int busoff_cnt;
88};
89
91 unsigned char scaler;
92 unsigned char ps1;
93 unsigned char ps2;
94 unsigned char rsj;
95 unsigned char bpr;
96};
97
99 unsigned char scaler;
100 unsigned char ps1;
101 unsigned char ps2;
102 unsigned char sjw;
103 unsigned char resv_zero;
104};
105
107 int selection;
108 int enable0;
109 int enable1;
110};
111
113 unsigned long long mask;
114 unsigned long long code;
115};
116
117#define GRCAN_FDOPT_NOM 0
118#define GRCAN_FDOPT_FDBTR 0x01
119#define GRCAN_FDOPT_FDFRM 0x02
120#define GRCAN_FDMASK (GRCAN_FDOPT_FDBTR | GRCAN_FDOPT_FDFRM)
121
122/* CAN MESSAGE */
123typedef struct {
124 char extended; /* 1= Extended Frame (29-bit id), 0= STD Frame (11-bit id) */
125 char rtr; /* RTR - Remote Transmission Request */
126 char unused; /* Must be 0 to select classic CAN frame */
127 unsigned char len;
128 unsigned char data[8];
129 unsigned int id;
130} CANMsg;
131
132/* CAN-FD MESSAGE */
133typedef struct {
134 uint8_t extended; /* 1= Extended Frame (29-bit id), 0= STD Frame (11-bit id) */
135 uint8_t rtr; /* RTR - Remote Transmission Request */
136 uint8_t fdopts; /* Bit1: 1=Switch bit rate. bit2: 1=FD frame. */
137 uint8_t len; /* 0-8, 12, 16, 20, 24, 32, 48 or 64 bytes */
138 uint32_t id;
139 union {
140 uint64_t dwords[8]; /* up to 64 bytes if FD=1 and len>8 */
141 uint8_t bytes[64]; /* up to 64 bytes if FD=1 and len>8 */
142 } data;
143} CANFDMsg;
144
145enum {
146 GRCAN_RET_OK = 0,
147 GRCAN_RET_INVARG = -1,
148 GRCAN_RET_NOTSTARTED = -2,
149 GRCAN_RET_TIMEOUT = -3,
150 /* Bus-off condition detected (request aborted by driver) */
151 GRCAN_RET_BUSOFF = -4,
152 /* AHB error condition detected (request aborted by driver) */
153 GRCAN_RET_AHBERR = -5,
154};
155
156/*
157 * User functions can cause these transitions:
158 * STATE_STOPPED -> STATE_STARTED
159 * STATE_STARTED -> STATE_STOPPED
160 * STATE_BUSOFF -> STATE_STOPPED
161 * STATE_AHBERR -> STATE_STOPPED
162 *
163 * ISR can cause these transition
164 * STATE_STARTED -> STATE_BUSOFF
165 * STATE_STARTED -> STATE_AHBERR
166 *
167 * STATE_BUSOFF is entered from ISR on bus-off condition. STATE_AHBERR is
168 * entered from ISR on AHB DMA errors on RX/TX operations. At transition the ISR
169 * disables DMA, masks all interrupts and releases semaphores.
170 */
171enum grcan_state {
172 STATE_STOPPED = 0,
173 STATE_STARTED = 1,
174 STATE_BUSOFF = 2,
175 STATE_AHBERR = 3,
176};
177
178#define GRCAN_CFG_ABORT 0x00000001
179#define GRCAN_CFG_ENABLE0 0x00000002
180#define GRCAN_CFG_ENABLE1 0x00000004
181#define GRCAN_CFG_SELECTION 0x00000008
182#define GRCAN_CFG_SILENT 0x00000010
183#define GRCAN_CFG_BPR 0x00000300
184#define GRCAN_CFG_RSJ 0x00007000
185#define GRCAN_CFG_PS1 0x00f00000
186#define GRCAN_CFG_PS2 0x000f0000
187#define GRCAN_CFG_SCALER 0xff000000
188
189#define GRCAN_CFG_BPR_BIT 8
190#define GRCAN_CFG_RSJ_BIT 12
191#define GRCAN_CFG_PS1_BIT 20
192#define GRCAN_CFG_PS2_BIT 16
193#define GRCAN_CFG_SCALER_BIT 24
194
195#define GRCAN_CTRL_RESET 0x2
196#define GRCAN_CTRL_ENABLE 0x1
197
198#define GRCAN_TXCTRL_ENABLE 1
199#define GRCAN_TXCTRL_ONGOING 1
200
201#define GRCAN_RXCTRL_ENABLE 1
202#define GRCAN_RXCTRL_ONGOING 1
203
204#define GRCANFD_NBTR_SCALER 0x00ff0000
205#define GRCANFD_NBTR_PS1 0x0000fc00
206#define GRCANFD_NBTR_PS2 0x000003e0
207#define GRCANFD_NBTR_SJW 0x0000001f
208
209#define GRCANFD_NBTR_SCALER_BIT 16
210#define GRCANFD_NBTR_PS1_BIT 10
211#define GRCANFD_NBTR_PS2_BIT 5
212#define GRCANFD_NBTR_SJW_BIT 0
213
214#define GRCANFD_FDBTR_SCALER 0x00ff0000
215#define GRCANFD_FDBTR_PS1 0x00003c00
216#define GRCANFD_FDBTR_PS2 0x000001e0
217#define GRCANFD_FDBTR_SJW 0x0000000f
218
219#define GRCANFD_FDBTR_SCALER_BIT 16
220#define GRCANFD_FDBTR_PS1_BIT 10
221#define GRCANFD_FDBTR_PS2_BIT 5
222#define GRCANFD_FDBTR_SJW_BIT 0
223
224/* Relative offset of IRQ sources to AMBA Plug&Play */
225#define GRCAN_IRQ_IRQ 0
226#define GRCAN_IRQ_TXSYNC 1
227#define GRCAN_IRQ_RXSYNC 2
228
229#define GRCAN_ERR_IRQ 0x1
230#define GRCAN_OFF_IRQ 0x2
231#define GRCAN_OR_IRQ 0x4
232#define GRCAN_RXAHBERR_IRQ 0x8
233#define GRCAN_TXAHBERR_IRQ 0x10
234#define GRCAN_RXIRQ_IRQ 0x20
235#define GRCAN_TXIRQ_IRQ 0x40
236#define GRCAN_RXFULL_IRQ 0x80
237#define GRCAN_TXEMPTY_IRQ 0x100
238#define GRCAN_RX_IRQ 0x200
239#define GRCAN_TX_IRQ 0x400
240#define GRCAN_RXSYNC_IRQ 0x800
241#define GRCAN_TXSYNC_IRQ 0x1000
242#define GRCAN_RXERR_IRQ 0x2000
243#define GRCAN_TXERR_IRQ 0x4000
244#define GRCAN_RXMISS_IRQ 0x8000
245#define GRCAN_TXLOSS_IRQ 0x10000
246
247#define GRCAN_STAT_PASS 0x1
248#define GRCAN_STAT_OFF 0x2
249#define GRCAN_STAT_OR 0x4
250#define GRCAN_STAT_AHBERR 0x8
251#define GRCAN_STAT_ACTIVE 0x10
252#define GRCAN_STAT_RXERRCNT 0xff00
253#define GRCAN_STAT_TXERRCNT 0xff0000
254
255/*
256 * Return number of GRCAN devices available to driver
257 */
258extern int grcan_dev_count(void);
259
260/*
261 * Open a GRCAN device
262 *
263 * dev_no: Device number to open
264 * return: Device handle to use with all other grcan_ API functions. The
265 * function returns NULL if device can not be opened.
266 */
267extern void *grcan_open(int dev_no);
268
269/*
270 * Open a GRCAN device by name. Finds device index then calls
271 * grcan_open(index).
272 *
273 * name: Device name to open
274 * dev_no: Device number matching name. Will be set if device found.
275 * return: Device handle to use with all other grcan_ API functions. The
276 * function returns NULL if device can not be opened or not found.
277 */
278extern void *grcan_open_by_name(char *name, int *dev_no);
279
280/*
281 * Close a GRCAN device
282 *
283 * return: This function always returns 0 (success)
284 */
285extern int grcan_close(void *d);
286
287/*
288 * Returns if CAN hardware device is CANFD capable.
289 *
290 * dev_no: Device handle
291 * return: 0=Not FD capable, 1=FD capable.
292 * function returns NULL if device can not be opened.
293 */
294extern int grcan_canfd_capable(void *d);
295
296/*
297 * Receive CAN messages
298 *
299 * Multiple CAN messages can be received in one call.
300 *
301 * d: Device handle
302 * msg: Pointer to receive messages
303 * count: Number of CAN messages to receive
304 *
305 * return:
306 * >=0: Number of CAN messages received. This can be
307 * less than the count parameter.
308 * GRCAN_RET_INVARG: count parameter less than one or NULL msg.
309 * GRCAN_RET_NOTSTARTED: Device not in started mode
310 * GRCAN_RET_TIMEOUT: Timeout in non-blocking mode
311 * GRCAN_RET_BUSOFF: A read was interrupted by a bus-off error.
312 * Device has left started mode.
313 * GRCAN_RET_AHBERR: Similar to BUSOFF, but was caused by AHB Error.
314 */
315extern int grcan_read(
316 void *d,
317 CANMsg *msg,
318 size_t count
319);
320
321/*
322 * Receive CAN messages (only GRCANFD)
323 *
324 * Multiple CAN messages can be received in one call.
325 *
326 * d: Device handle
327 * msg: Pointer to receive messages
328 * count: Number of CAN messages to receive
329 *
330 * return:
331 * >=0: Number of CAN messages received. This can be
332 * less than the count parameter.
333 * GRCAN_RET_INVARG: count parameter less than one or NULL msg.
334 * GRCAN_RET_NOTSTARTED: Device not in started mode
335 * GRCAN_RET_TIMEOUT: Timeout in non-blocking mode
336 * GRCAN_RET_BUSOFF: A read was interrupted by a bus-off error.
337 * Device has left started mode.
338 * GRCAN_RET_AHBERR: Similar to BUSOFF, but was caused by AHB Error.
339 */
340extern int grcanfd_read(
341 void *d,
342 CANFDMsg *msg,
343 size_t count
344);
345
346/*
347 * Transmit CAN messages
348 *
349 * Multiple CAN messages can be transmit in one call.
350 *
351 * d: Device handle
352 * msg: Pointer to messages to transmit
353 * count: Number of CAN messages to transmit
354 *
355 * return:
356 * >=0: Number of CAN messages transmitted. This can be
357 * less than the count parameter.
358 * GRCAN_RET_INVARG: count parameter less than one.
359 * GRCAN_RET_NOTSTARTED: Device not in started mode
360 * GRCAN_RET_TIMEOUT: Timeout in non-blocking mode
361 * GRCAN_RET_BUSOFF: A write was interrupted by a Bus-off error.
362 * Device has left started mode
363 * GRCAN_RET_AHBERR: Similar to BUSOFF, but was caused by AHB Error.
364 */
365extern int grcan_write(
366 void *d,
367 CANMsg *msg,
368 size_t count
369);
370
371/*
372 * Transmit CAN-FD complient messages (only GRCANFD)
373 *
374 * Multiple CAN messages can be transmit in one call.
375 *
376 * d: Device handle
377 * msg: Pointer to messages to transmit
378 * count: Number of CAN messages to transmit
379 *
380 * return:
381 * >=0: Number of CAN messages transmitted. This can be
382 * less than the count parameter.
383 * GRCAN_RET_INVARG: count parameter less than one.
384 * GRCAN_RET_NOTSTARTED: Device not in started mode
385 * GRCAN_RET_TIMEOUT: Timeout in non-blocking mode
386 * GRCAN_RET_BUSOFF: A write was interrupted by a Bus-off error.
387 * Device has left started mode
388 * GRCAN_RET_AHBERR: Similar to BUSOFF, but was caused by AHB Error.
389 */
390extern int grcanfd_write(
391 void *d,
392 CANFDMsg *msg,
393 size_t ucount
394);
395
396/*
397 * Returns current GRCAN software state
398 *
399 * If STATE_BUSOFF or STATE_AHBERR is returned then the function grcan_stop()
400 * shall be called before continue using the driver.
401 *
402 * d: Device handle
403 * return:
404 * STATE_STOPPED Stopped
405 * STATE_STARTED Started
406 * STATE_BUSOFF Bus-off has been detected
407 * STATE_AHBERR AHB error has been detected
408 */
409extern int grcan_get_state(void *d);
410
411/* The remaining functions return 0 on success and non-zero on failure. */
412
413/* Functions controlling operational
414 * mode
415 */
416/* Bring the link up after open or bus-off */
417extern int grcan_start(void *d);
418/* stop to change baud rate/config or closing down */
419extern int grcan_stop(void *d);
420/* Wait until all TX messages have been sent */
421extern int grcan_flush(void *d);
422
423/* Functions that require connection
424 * to be stopped
425 */
426/* enable silent mode read only state */
427extern int grcan_set_silent(void *d, int silent);
428/* enable/disable stopping link on AHB Error */
429extern int grcan_set_abort(void *d, int abort);
430/* Set Enable0,Enable1,Selection */
431extern int grcan_set_selection(void *d, const struct grcan_selection *selection);
432/* Set baudrate by using driver's baud rate timing calculation routines */
433extern int grcan_set_speed(void *d, unsigned int hz);
434/* Set baudrate by specifying the timing registers manually */
435extern int grcan_set_btrs(void *d, const struct grcan_timing *timing);
436
437/* Set the Nominal and FD baudrate by using driver's baud rate timing
438 * calculation routines
439 */
440extern int grcanfd_set_speed(void *d, unsigned int nomhz, unsigned int fdhz);
441/* Set Nominal and FD baudrate by specifying the timing registers manually*/
442extern int grcanfd_set_btrs(
443 void *d,
444 const struct grcanfd_timing *nominal,
445 const struct grcanfd_timing *fd);
446
447/* Functions can be called whenever */
448/* Enable/disable Blocking on reception (until at least one message has been received) */
449int grcan_set_rxblock(void* d, int block);
450/* Enable/disable Blocking on transmission (until at least one message has been transmitted) */
451int grcan_set_txblock(void* d, int block);
452/* Enable/disable Blocking until all requested messages has been sent */
453int grcan_set_txcomplete(void* d, int complete);
454/* Enable/disable Blocking until all requested has been received */
455int grcan_set_rxcomplete(void* d, int complete);
456/* Get statistics */
457extern int grcan_get_stats(void *d, struct grcan_stats *stats);
458/* Clear statistics */
459extern int grcan_clr_stats(void *d);
460/* Set Acceptance filters, provide pointer to "struct grcan_filter" or NULL to disable filtering (let all messages pass) */
461extern int grcan_set_afilter(void *d, const struct grcan_filter *filter);
462/* Set Sync Messages RX/TX filters, NULL disables the IRQ completely */
463extern int grcan_set_sfilter(void *d, const struct grcan_filter *filter);
464/* Get status register of GRCAN core */
465extern int grcan_get_status(void *d, unsigned int *status);
466
467void grcan_register_drv(void);
468
469#ifdef __cplusplus
470}
471#endif
472
475#endif
Definition: grcan.h:133
Definition: grcan.h:123
Definition: inftrees.h:24
Definition: grcan.h:112
Definition: grcan.h:35
Definition: grcan.h:106
Definition: grcan.h:79
Definition: grcan.h:90
Definition: grcan.h:98
Definition: b1553brm.c:75