RTEMS: bsps/shared/grlib/can/grcan_internal.h Source File

| RTEMS 5.4-rc2

Loading...
Searching...
No Matches
grcan_internal.h
1/*
2 * GRCAN driver
3 *
4 * COPYRIGHT (c) 2007-2019.
5 * Cobham Gaisler AB.
6 *
7 * The license and distribution terms for this file may be
8 * found in the file LICENSE in this distribution or at
9 * http://www.rtems.org/license/LICENSE.
10 */
11
12#ifndef GRCAN_DEFAULT_BAUD
13 /* default to 500kbits/s */
14 #define GRCAN_DEFAULT_BAUD 500000
15#endif
16
17#ifndef GRCAN_SAMPLING_POINT
18 #define GRCAN_SAMPLING_POINT 80
19#endif
20
21#define WRAP_AROUND_TX_MSGS 1
22#define WRAP_AROUND_RX_MSGS 2
23#define GRCAN_MSG_SIZE sizeof(struct grcan_msg)
24
25 struct grcan_msg {
26 unsigned int head[2];
27 unsigned char data[8];
28};
29
30 struct grcan_config {
31 struct grcan_timing timing;
32 struct grcanfd_timing timing_fd;
33 struct grcan_selection selection;
34 int abort;
35 int silent;
36};
37
38 struct grcan_priv {
39 struct drvmgr_dev *dev; /* Driver manager device */
40 char devName[32]; /* Device Name */
41 unsigned int baseaddr, ram_base;
42 struct grcan_regs *regs;
43 int irq;
44 int minor;
45 int open;
46 int started;
47 unsigned int channel;
48 int flushing;
49 unsigned int corefreq_hz;
50 int fd_capable;
51
52 /* Circular DMA buffers */
53 void *_rx, *_rx_hw;
54 void *_tx, *_tx_hw;
55 void *txbuf_adr;
56 void *rxbuf_adr;
57 struct grcan_msg *rx;
58 struct grcan_msg *tx;
59 unsigned int rxbuf_size; /* requested RX buf size in bytes */
60 unsigned int txbuf_size; /* requested TX buf size in bytes */
61
62 int txblock, rxblock;
63 int txcomplete, rxcomplete;
64
65 struct grcan_filter sfilter;
66 struct grcan_filter afilter;
67 int config_changed; /* 0=no changes, 1=changes ==> a Core reset is needed */
68 struct grcan_config config;
69 struct grcan_stats stats;
70
71 rtems_id rx_sem, tx_sem, txempty_sem, dev_sem;
72 SPIN_DECLARE(devlock);
73};
74
75#ifdef GRCAN_REG_BYPASS_CACHE
76#define READ_REG(address) grlib_read_uncached32((unsigned int)(address))
77#else
78#define READ_REG(address) (*(volatile unsigned int *)(address))
79#endif
80
81#ifdef GRCAN_DMA_BYPASS_CACHE
82#define READ_DMA_DOUBLE(address) grlib_read_uncached64((uint64_t *)(address))
83#define READ_DMA_WORD(address) grlib_read_uncached32((unsigned int)(address))
84#define READ_DMA_BYTE(address) grlib_read_uncached8((unsigned int)(address))
85#else
86#define READ_DMA_DOUBLE(address) (*(volatile uint64_t *)(address))
87#define READ_DMA_WORD(address) (*(volatile unsigned int *)(address))
88#define READ_DMA_BYTE(address) (*(volatile unsigned char *)(address))
89#endif
90
91extern int state2err[4];
92extern struct grlib_canbtrs_ranges grcan_btrs_ranges;
93extern struct grlib_canbtrs_ranges grcanfd_nom_btrs_ranges;
94extern struct grlib_canbtrs_ranges grcanfd_fd_btrs_ranges;
95
96int grcan_wait_rxdata(struct grcan_priv *pDev, int min);
97int grcan_wait_txspace(struct grcan_priv *pDev, int min);
98
99static inline unsigned int grcan_hw_rxavail(
100 unsigned int rp,
101 unsigned int wp,
102 unsigned int size)
103{
104 if (rp == wp) {
105 /* read pointer and write pointer is equal only
106 * when RX buffer is empty.
107 */
108 return 0;
109 }
110
111 if (wp > rp) {
112 return (wp - rp) / GRCAN_MSG_SIZE;
113 } else {
114 return (size - (rp - wp)) / GRCAN_MSG_SIZE;
115 }
116}
117
118static inline unsigned int grcan_hw_txspace(
119 unsigned int rp,
120 unsigned int wp,
121 unsigned int size)
122{
123 unsigned int left;
124
125 if (rp == wp) {
126 /* read pointer and write pointer is equal only
127 * when TX buffer is empty.
128 */
129 return size / GRCAN_MSG_SIZE - WRAP_AROUND_TX_MSGS;
130 }
131
132 /* size - 4 - abs(read-write) */
133 if (wp > rp) {
134 left = size - (wp - rp);
135 } else {
136 left = rp - wp;
137 }
138
139 return left / GRCAN_MSG_SIZE - WRAP_AROUND_TX_MSGS;
140}
rtems_id
Objects_Id rtems_id
Used to manage and manipulate RTEMS object identifiers.
Definition: types.h:83
open
int open(const char *path, int oflag,...)
Definition: open.c:149
config_s
Definition: deflate.c:115
drvmgr_dev
Definition: drvmgr.h:273
grcan_config
Definition: grcan_internal.h:30
grcan_filter
Definition: grcan.h:112
grcan_msg
Definition: grcan_internal.h:25
grcan_priv
Definition: grcan_internal.h:38
grcan_regs
Definition: grcan.h:35
grcan_selection
Definition: grcan.h:106
grcan_stats
Definition: grcan.h:79
grcan_timing
Definition: grcan.h:90
grcanfd_timing
Definition: grcan.h:98
grlib_canbtrs_ranges
Definition: canbtrs.h:52