source: rtems/c/src/lib/libbsp/sparc/shared/include/grcan.h @ bc40b4d

5
Last change on this file since bc40b4d was bc40b4d, checked in by Martin Aberg <maberg@…>, on Jan 24, 2017 at 10:16:41 AM

leon, grcan: consistent indentation

This commit does not contain any change of functionality.

  • Property mode set to 100644
File size: 8.1 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};
72
73struct grcan_timing {
74        unsigned char scaler;
75        unsigned char ps1;
76        unsigned char ps2;
77        unsigned int  rsj;
78        unsigned char bpr;
79};
80
81struct grcan_selection {
82        int selection;
83        int enable0;
84        int enable1;
85};
86
87struct grcan_filter {
88        unsigned long long mask;
89        unsigned long long code;
90};
91
92/* CAN MESSAGE */
93typedef struct {
94        char extended; /* 1= Extended Frame (29-bit id), 0= STD Frame (11-bit id) */
95        char rtr; /* RTR - Remote Transmission Request */
96        char unused; /* unused */
97        unsigned char len;
98        unsigned char data[8];
99        unsigned int id;
100} CANMsg;
101
102#define GRCAN_CFG_ABORT      0x00000001
103#define GRCAN_CFG_ENABLE0    0x00000002
104#define GRCAN_CFG_ENABLE1    0x00000004
105#define GRCAN_CFG_SELECTION  0x00000008
106#define GRCAN_CFG_SILENT     0x00000010
107#define GRCAN_CFG_BPR        0x00000300
108#define GRCAN_CFG_RSJ        0x00007000
109#define GRCAN_CFG_PS1        0x00f00000
110#define GRCAN_CFG_PS2        0x000f0000
111#define GRCAN_CFG_SCALER     0xff000000
112
113#define GRCAN_CFG_BPR_BIT    8
114#define GRCAN_CFG_RSJ_BIT    12
115#define GRCAN_CFG_PS1_BIT    20
116#define GRCAN_CFG_PS2_BIT    16
117#define GRCAN_CFG_SCALER_BIT 24
118
119#define GRCAN_CTRL_RESET  0x2
120#define GRCAN_CTRL_ENABLE 0x1
121
122#define GRCAN_TXCTRL_ENABLE 1
123#define GRCAN_TXCTRL_ONGOING 1
124
125#define GRCAN_RXCTRL_ENABLE 1
126#define GRCAN_RXCTRL_ONGOING 1
127
128/* Relative offset of IRQ sources to AMBA Plug&Play */
129#define GRCAN_IRQ_IRQ 0
130#define GRCAN_IRQ_TXSYNC 1
131#define GRCAN_IRQ_RXSYNC 2
132
133#define GRCAN_ERR_IRQ        0x1
134#define GRCAN_OFF_IRQ        0x2
135#define GRCAN_OR_IRQ         0x4
136#define GRCAN_RXAHBERR_IRQ   0x8
137#define GRCAN_TXAHBERR_IRQ   0x10
138#define GRCAN_RXIRQ_IRQ      0x20
139#define GRCAN_TXIRQ_IRQ      0x40
140#define GRCAN_RXFULL_IRQ     0x80
141#define GRCAN_TXEMPTY_IRQ    0x100
142#define GRCAN_RX_IRQ         0x200
143#define GRCAN_TX_IRQ         0x400
144#define GRCAN_RXSYNC_IRQ     0x800
145#define GRCAN_TXSYNC_IRQ     0x1000
146#define GRCAN_RXERR_IRQ      0x2000
147#define GRCAN_TXERR_IRQ      0x4000
148#define GRCAN_RXMISS_IRQ     0x8000
149#define GRCAN_TXLOSS_IRQ     0x10000
150
151#define GRCAN_STAT_PASS      0x1
152#define GRCAN_STAT_OFF       0x2
153#define GRCAN_STAT_OR        0x4
154#define GRCAN_STAT_AHBERR    0x8
155#define GRCAN_STAT_ACTIVE    0x10
156#define GRCAN_STAT_RXERRCNT  0xff00
157#define GRCAN_STAT_TXERRCNT  0xff0000
158
159/*
160 * Return number of GRCAN devices available to driver
161 */
162extern int grcan_dev_count(void);
163
164/*
165 * Open a GRCAN device
166 *
167 * dev_no:      Device number to open
168 * return:      Device handle to use with all other grcan_ API functions. The
169 *              function returns NULL if device can not be opened.
170 */
171extern void *grcan_open(int dev_no);
172
173/*
174 * Close a GRCAN device
175 *
176 * return: This function always returns 0 (success)
177 */
178extern int grcan_close(void *d);
179
180/*
181 * Receive CAN messages
182 *
183 * Multiple CAN messages can be received in one call.
184 *
185 * d: Device handle
186 * msg: Pointer to receive messages
187 * count: Number of CAN messages to receive
188 *
189 * return:
190 *   >=0:       Number of CAN messages received. This can be less than the
191 *              count parameter.
192 *   -1:        count parameter less than size of struct grcan_msg or NULL msg.
193 *   -2:        Device not in started mode
194 *   -3:        Timeout in non-blocking mode
195 *   -4:        A blocking read was interrupted by a Bus-off error. Device has
196 *              left started mode.
197 */
198extern int grcan_read(
199        void *d,
200        CANMsg *msg,
201        size_t count
202);
203
204/*
205 * Transmit CAN messages
206 *
207 * Multiple CAN messages can be transmit in one call.
208 *
209 * d: Device handle
210 * msg: Pointer to messages to transmit
211 * count: Number of CAN messages to transmit
212 *
213 * return:
214 *   >=0:       Number of CAN messages transmitted. This can be less than the
215 *              count parameter.
216 *   -1:        count parameter less than size of struct grcan_msg
217 *   -2:        Device not in started mode
218 *   -3:        Timeout in non-blocking mode
219 *   -4:        Bus-off error. Device has left started mode
220 */
221extern int grcan_write(
222        void *d,
223        CANMsg *msg,
224        size_t count
225);
226
227/* The remaining functions return 0 on success and non-zero on failure. */
228
229/* Functions controlling operational
230 * mode
231 */
232/* Bring the link up after open or bus-off */
233extern int grcan_start(void *d);
234/* stop to change baud rate/config or closing down */
235extern int grcan_stop(void *d);
236/* return 1 when started, othervise 0 */
237extern int grcan_isstarted(void *d);
238/* Wait until all TX messages have been sent */
239extern int grcan_flush(void *d);
240
241/* Functions that require connection
242 * to be stopped
243 */
244/* enable silent mode read only state */
245extern int grcan_set_silent(void *d, int silent);
246/* enable/disable stopping link on AHB Error */
247extern int grcan_set_abort(void *d, int abort);
248/* Set Enable0,Enable1,Selection */
249extern int grcan_set_selection(void *d, const struct grcan_selection *selection);
250/* Set baudrate by using driver's baud rate timing calculation routines */
251extern int grcan_set_speed(void *d, unsigned int hz);
252/* Set baudrate by specifying the timing registers manually */
253extern int grcan_set_btrs(void *d, const struct grcan_timing *timing);
254
255/* Functions can be called whenever */
256/* Enable/disable Blocking on reception (until at least one message has been received) */
257int grcan_set_rxblock(void* d, int block);
258/* Enable/disable Blocking on transmission (until at least one message has been transmitted) */
259int grcan_set_txblock(void* d, int block);
260/* Enable/disable Blocking until all requested messages has been sent */
261int grcan_set_txcomplete(void* d, int complete);
262/* Enable/disable Blocking until all requested has been received */
263int grcan_set_rxcomplete(void* d, int complete);
264/* Get statistics */
265extern int grcan_get_stats(void *d, struct grcan_stats *stats);
266/* Clear statistics */
267extern int grcan_clr_stats(void *d);
268/* Set Acceptance filters, provide pointer to "struct grcan_filter" or NULL to disable filtering (let all messages pass) */
269extern int grcan_set_afilter(void *d, const struct grcan_filter *filter);
270/* Set Sync Messages RX/TX filters, NULL disables the IRQ completely */
271extern int grcan_set_sfilter(void *d, const struct grcan_filter *filter);
272/* Get status register of GRCAN core */
273extern int grcan_get_status(void *d, unsigned int *status);
274
275void grcan_register_drv(void);
276
277#ifdef __cplusplus
278}
279#endif
280
281#endif
Note: See TracBrowser for help on using the repository browser.