source: rtems/bsps/include/grlib/grcan.h @ 31720925

5
Last change on this file since 31720925 was 31720925, checked in by Sebastian Huber <sebastian.huber@…>, on 12/22/18 at 06:13:44

grlib: Move header files

Update #3678.

  • Property mode set to 100644
File size: 10.2 KB
Line 
1/**
2 * @file
3 * @ingroup sparc_bsp
4 * @defgroup can GRCAN
5 * @ingroup can
6 * @brief Macros used for grcan controller
7 */
8
9/*
10 *  COPYRIGHT (c) 2007.
11 *  Cobham Gaisler AB.
12 *
13 *  The license and distribution terms for this file may be
14 *  found in the file LICENSE in this distribution or at
15 *  http://www.rtems.org/license/LICENSE.
16 */
17
18#ifndef __GRCAN_H__
19#define __GRCAN_H__
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25struct grcan_regs {
26        volatile unsigned int conf;          /* 0x00 */
27        volatile unsigned int stat;          /* 0x04 */
28        volatile unsigned int ctrl;          /* 0x08 */
29        volatile unsigned int dummy0[3];     /* 0x0C-0x014 */
30        volatile unsigned int smask;         /* 0x18 */
31        volatile unsigned int scode;         /* 0x1C */
32
33        volatile unsigned int dummy1[56];    /* 0x20-0xFC */
34
35        volatile unsigned int pimsr;         /* 0x100 */
36        volatile unsigned int pimr;          /* 0x104 */
37        volatile unsigned int pisr;          /* 0x108 */
38        volatile unsigned int pir;           /* 0x10C */
39        volatile unsigned int imr;           /* 0x110 */
40        volatile unsigned int picr;          /* 0x114 */
41
42        volatile unsigned int dummy2[58];    /* 0x118-0x1FC */
43
44        volatile unsigned int tx0ctrl;       /* 0x200 */
45        volatile unsigned int tx0addr;       /* 0x204 */
46        volatile unsigned int tx0size;       /* 0x208 */
47        volatile unsigned int tx0wr;         /* 0x20C */
48        volatile unsigned int tx0rd;         /* 0x210 */
49        volatile unsigned int tx0irq;        /* 0x214 */
50
51        volatile unsigned int dummy3[58];    /* 0x218-0x2FC */
52
53        volatile unsigned int rx0ctrl;       /* 0x300 */
54        volatile unsigned int rx0addr;       /* 0x304 */
55        volatile unsigned int rx0size;       /* 0x308 */
56        volatile unsigned int rx0wr;         /* 0x30C */
57        volatile unsigned int rx0rd;         /* 0x310 */
58        volatile unsigned int rx0irq;        /* 0x314 */
59        volatile unsigned int rx0mask;       /* 0x318 */
60        volatile unsigned int rx0code;       /* 0x31C */
61};
62
63struct grcan_stats {
64        unsigned int passive_cnt;
65        unsigned int overrun_cnt;
66        unsigned int rxsync_cnt;
67        unsigned int txsync_cnt;
68        unsigned int txloss_cnt;
69        unsigned int ahberr_cnt;
70        unsigned int ints;
71        unsigned int busoff_cnt;
72};
73
74struct grcan_timing {
75        unsigned char scaler;
76        unsigned char ps1;
77        unsigned char ps2;
78        unsigned int  rsj;
79        unsigned char bpr;
80};
81
82struct grcan_selection {
83        int selection;
84        int enable0;
85        int enable1;
86};
87
88struct grcan_filter {
89        unsigned long long mask;
90        unsigned long long code;
91};
92
93/* CAN MESSAGE */
94typedef struct {
95        char extended; /* 1= Extended Frame (29-bit id), 0= STD Frame (11-bit id) */
96        char rtr; /* RTR - Remote Transmission Request */
97        char unused; /* unused */
98        unsigned char len;
99        unsigned char data[8];
100        unsigned int id;
101} CANMsg;
102
103enum {
104        GRCAN_RET_OK            =  0,
105        GRCAN_RET_INVARG        = -1,
106        GRCAN_RET_NOTSTARTED    = -2,
107        GRCAN_RET_TIMEOUT       = -3,
108        /* Bus-off condition detected (request aborted by driver) */
109        GRCAN_RET_BUSOFF        = -4,
110        /* AHB error condition detected (request aborted by driver) */
111        GRCAN_RET_AHBERR        = -5,
112};
113
114/*
115 * User functions can cause these transitions:
116 *   STATE_STOPPED -> STATE_STARTED
117 *   STATE_STARTED -> STATE_STOPPED
118 *   STATE_BUSOFF  -> STATE_STOPPED
119 *   STATE_AHBERR  -> STATE_STOPPED
120 *
121 * ISR can cause these transition
122 *   STATE_STARTED -> STATE_BUSOFF
123 *   STATE_STARTED -> STATE_AHBERR
124 *
125 * STATE_BUSOFF is entered from ISR on bus-off condition. STATE_AHBERR is
126 * entered from ISR on AHB DMA errors on RX/TX operations. At transition the ISR
127 * disables DMA, masks all interrupts and releases semaphores.
128 */
129enum grcan_state {
130        STATE_STOPPED           = 0,
131        STATE_STARTED           = 1,
132        STATE_BUSOFF            = 2,
133        STATE_AHBERR            = 3,
134};
135
136#define GRCAN_CFG_ABORT      0x00000001
137#define GRCAN_CFG_ENABLE0    0x00000002
138#define GRCAN_CFG_ENABLE1    0x00000004
139#define GRCAN_CFG_SELECTION  0x00000008
140#define GRCAN_CFG_SILENT     0x00000010
141#define GRCAN_CFG_BPR        0x00000300
142#define GRCAN_CFG_RSJ        0x00007000
143#define GRCAN_CFG_PS1        0x00f00000
144#define GRCAN_CFG_PS2        0x000f0000
145#define GRCAN_CFG_SCALER     0xff000000
146
147#define GRCAN_CFG_BPR_BIT    8
148#define GRCAN_CFG_RSJ_BIT    12
149#define GRCAN_CFG_PS1_BIT    20
150#define GRCAN_CFG_PS2_BIT    16
151#define GRCAN_CFG_SCALER_BIT 24
152
153#define GRCAN_CTRL_RESET  0x2
154#define GRCAN_CTRL_ENABLE 0x1
155
156#define GRCAN_TXCTRL_ENABLE 1
157#define GRCAN_TXCTRL_ONGOING 1
158
159#define GRCAN_RXCTRL_ENABLE 1
160#define GRCAN_RXCTRL_ONGOING 1
161
162/* Relative offset of IRQ sources to AMBA Plug&Play */
163#define GRCAN_IRQ_IRQ 0
164#define GRCAN_IRQ_TXSYNC 1
165#define GRCAN_IRQ_RXSYNC 2
166
167#define GRCAN_ERR_IRQ        0x1
168#define GRCAN_OFF_IRQ        0x2
169#define GRCAN_OR_IRQ         0x4
170#define GRCAN_RXAHBERR_IRQ   0x8
171#define GRCAN_TXAHBERR_IRQ   0x10
172#define GRCAN_RXIRQ_IRQ      0x20
173#define GRCAN_TXIRQ_IRQ      0x40
174#define GRCAN_RXFULL_IRQ     0x80
175#define GRCAN_TXEMPTY_IRQ    0x100
176#define GRCAN_RX_IRQ         0x200
177#define GRCAN_TX_IRQ         0x400
178#define GRCAN_RXSYNC_IRQ     0x800
179#define GRCAN_TXSYNC_IRQ     0x1000
180#define GRCAN_RXERR_IRQ      0x2000
181#define GRCAN_TXERR_IRQ      0x4000
182#define GRCAN_RXMISS_IRQ     0x8000
183#define GRCAN_TXLOSS_IRQ     0x10000
184
185#define GRCAN_STAT_PASS      0x1
186#define GRCAN_STAT_OFF       0x2
187#define GRCAN_STAT_OR        0x4
188#define GRCAN_STAT_AHBERR    0x8
189#define GRCAN_STAT_ACTIVE    0x10
190#define GRCAN_STAT_RXERRCNT  0xff00
191#define GRCAN_STAT_TXERRCNT  0xff0000
192
193/*
194 * Return number of GRCAN devices available to driver
195 */
196extern int grcan_dev_count(void);
197
198/*
199 * Open a GRCAN device
200 *
201 * dev_no:      Device number to open
202 * return:      Device handle to use with all other grcan_ API functions. The
203 *              function returns NULL if device can not be opened.
204 */
205extern void *grcan_open(int dev_no);
206
207/*
208 * Open a GRCAN device by name. Finds device index then calls
209 * grcan_open(index).
210 *
211 * name:        Device name to open
212 * dev_no:      Device number matching name. Will be set if device found.
213 * return:      Device handle to use with all other grcan_ API functions. The
214 *              function returns NULL if device can not be opened or not found.
215 */
216extern void *grcan_open_by_name(char *name, int *dev_no);
217
218/*
219 * Close a GRCAN device
220 *
221 * return: This function always returns 0 (success)
222 */
223extern int grcan_close(void *d);
224
225/*
226 * Receive CAN messages
227 *
228 * Multiple CAN messages can be received in one call.
229 *
230 * d: Device handle
231 * msg: Pointer to receive messages
232 * count: Number of CAN messages to receive
233 *
234 * return:
235 *   >=0:                       Number of CAN messages received. This can be
236 *                              less than the count parameter.
237 *   GRCAN_RET_INVARG:          count parameter less than one or NULL msg.
238 *   GRCAN_RET_NOTSTARTED:      Device not in started mode
239 *   GRCAN_RET_TIMEOUT:         Timeout in non-blocking mode
240 *   GRCAN_RET_BUSOFF:          A read was interrupted by a bus-off error.
241 *                              Device has left started mode.
242 *   GRCAN_RET_AHBERR:          Similar to BUSOFF, but was caused by AHB Error.
243 */
244extern int grcan_read(
245        void *d,
246        CANMsg *msg,
247        size_t count
248);
249
250/*
251 * Transmit CAN messages
252 *
253 * Multiple CAN messages can be transmit in one call.
254 *
255 * d: Device handle
256 * msg: Pointer to messages to transmit
257 * count: Number of CAN messages to transmit
258 *
259 * return:
260 *   >=0:                       Number of CAN messages transmitted. This can be
261 *                              less than the count parameter.
262 *   GRCAN_RET_INVARG:          count parameter less than one.
263 *   GRCAN_RET_NOTSTARTED:      Device not in started mode
264 *   GRCAN_RET_TIMEOUT:         Timeout in non-blocking mode
265 *   GRCAN_RET_BUSOFF:          A write was interrupted by a Bus-off error.
266 *                              Device has left started mode
267 *   GRCAN_RET_AHBERR:          Similar to BUSOFF, but was caused by AHB Error.
268 */
269extern int grcan_write(
270        void *d,
271        CANMsg *msg,
272        size_t count
273);
274
275/*
276 * Returns current GRCAN software state
277 *
278 * If STATE_BUSOFF or STATE_AHBERR is returned then the function grcan_stop()
279 * shall be called before continue using the driver.
280 *
281 * d: Device handle
282 * return:
283 *   STATE_STOPPED              Stopped
284 *   STATE_STARTED              Started
285 *   STATE_BUSOFF               Bus-off has been detected
286 *   STATE_AHBERR               AHB error has been detected
287 */
288extern int grcan_get_state(void *d);
289
290/* The remaining functions return 0 on success and non-zero on failure. */
291
292/* Functions controlling operational
293 * mode
294 */
295/* Bring the link up after open or bus-off */
296extern int grcan_start(void *d);
297/* stop to change baud rate/config or closing down */
298extern int grcan_stop(void *d);
299/* Wait until all TX messages have been sent */
300extern int grcan_flush(void *d);
301
302/* Functions that require connection
303 * to be stopped
304 */
305/* enable silent mode read only state */
306extern int grcan_set_silent(void *d, int silent);
307/* enable/disable stopping link on AHB Error */
308extern int grcan_set_abort(void *d, int abort);
309/* Set Enable0,Enable1,Selection */
310extern int grcan_set_selection(void *d, const struct grcan_selection *selection);
311/* Set baudrate by using driver's baud rate timing calculation routines */
312extern int grcan_set_speed(void *d, unsigned int hz);
313/* Set baudrate by specifying the timing registers manually */
314extern int grcan_set_btrs(void *d, const struct grcan_timing *timing);
315
316/* Functions can be called whenever */
317/* Enable/disable Blocking on reception (until at least one message has been received) */
318int grcan_set_rxblock(void* d, int block);
319/* Enable/disable Blocking on transmission (until at least one message has been transmitted) */
320int grcan_set_txblock(void* d, int block);
321/* Enable/disable Blocking until all requested messages has been sent */
322int grcan_set_txcomplete(void* d, int complete);
323/* Enable/disable Blocking until all requested has been received */
324int grcan_set_rxcomplete(void* d, int complete);
325/* Get statistics */
326extern int grcan_get_stats(void *d, struct grcan_stats *stats);
327/* Clear statistics */
328extern int grcan_clr_stats(void *d);
329/* Set Acceptance filters, provide pointer to "struct grcan_filter" or NULL to disable filtering (let all messages pass) */
330extern int grcan_set_afilter(void *d, const struct grcan_filter *filter);
331/* Set Sync Messages RX/TX filters, NULL disables the IRQ completely */
332extern int grcan_set_sfilter(void *d, const struct grcan_filter *filter);
333/* Get status register of GRCAN core */
334extern int grcan_get_status(void *d, unsigned int *status);
335
336void grcan_register_drv(void);
337
338#ifdef __cplusplus
339}
340#endif
341
342#endif
Note: See TracBrowser for help on using the repository browser.