RTEMS
6.3
Toggle main menu visibility
Loading...
Searching...
No Matches
bsps
shared
grlib
can
grcan_internal.h
1
/* SPDX-License-Identifier: BSD-2-Clause */
2
3
/*
4
* GRCAN driver
5
*
6
* COPYRIGHT (c) 2007-2019.
7
* Cobham Gaisler AB.
8
*
9
* Redistribution and use in source and binary forms, with or without
10
* modification, are permitted provided that the following conditions
11
* are met:
12
* 1. Redistributions of source code must retain the above copyright
13
* notice, this list of conditions and the following disclaimer.
14
* 2. Redistributions in binary form must reproduce the above copyright
15
* notice, this list of conditions and the following disclaimer in the
16
* documentation and/or other materials provided with the distribution.
17
*
18
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
* POSSIBILITY OF SUCH DAMAGE.
29
*/
30
31
#ifndef GRCAN_DEFAULT_BAUD
32
/* default to 500kbits/s */
33
#define GRCAN_DEFAULT_BAUD 500000
34
#endif
35
36
#ifndef GRCAN_SAMPLING_POINT
37
#define GRCAN_SAMPLING_POINT 80
38
#endif
39
40
#define WRAP_AROUND_TX_MSGS 1
41
#define WRAP_AROUND_RX_MSGS 2
42
#define GRCAN_MSG_SIZE sizeof(struct grcan_msg)
43
44
struct
grcan_msg
{
45
unsigned
int
head[2];
46
unsigned
char
data[8];
47
};
48
49
struct
grcan_config
{
50
struct
grcan_timing
timing;
51
struct
grcanfd_timing
timing_fd;
52
struct
grcan_selection
selection;
53
int
abort;
54
int
silent;
55
};
56
57
struct
grcan_priv
{
58
struct
drvmgr_dev
*dev;
/* Driver manager device */
59
char
devName[52];
/* Device Name */
60
unsigned
int
baseaddr, ram_base;
61
struct
grcan_regs
*regs;
62
int
irq;
63
int
minor;
64
int
open;
65
int
started;
66
unsigned
int
channel;
67
int
flushing;
68
unsigned
int
corefreq_hz;
69
int
fd_capable;
70
71
/* Circular DMA buffers */
72
void
*_rx, *_rx_hw;
73
void
*_tx, *_tx_hw;
74
void
*txbuf_adr;
75
void
*rxbuf_adr;
76
struct
grcan_msg
*rx;
77
struct
grcan_msg
*tx;
78
unsigned
int
rxbuf_size;
/* requested RX buf size in bytes */
79
unsigned
int
txbuf_size;
/* requested TX buf size in bytes */
80
81
int
txblock, rxblock;
82
int
txcomplete, rxcomplete;
83
84
struct
grcan_filter
sfilter;
85
struct
grcan_filter
afilter;
86
int
config_changed;
/* 0=no changes, 1=changes ==> a Core reset is needed */
87
struct
grcan_config
config;
88
struct
grcan_stats
stats;
89
90
rtems_id
rx_sem, tx_sem, txempty_sem, dev_sem;
91
SPIN_DECLARE(devlock);
92
};
93
94
#ifdef GRCAN_REG_BYPASS_CACHE
95
#define READ_REG(address) grlib_read_uncached32((unsigned int)(address))
96
#else
97
#define READ_REG(address) (*(volatile unsigned int *)(address))
98
#endif
99
100
#ifdef GRCAN_DMA_BYPASS_CACHE
101
#define READ_DMA_DOUBLE(address) grlib_read_uncached64((uint64_t *)(address))
102
#define READ_DMA_WORD(address) grlib_read_uncached32((unsigned int)(address))
103
#define READ_DMA_BYTE(address) grlib_read_uncached8((unsigned int)(address))
104
#else
105
#define READ_DMA_DOUBLE(address) (*(volatile uint64_t *)(address))
106
#define READ_DMA_WORD(address) (*(volatile unsigned int *)(address))
107
#define READ_DMA_BYTE(address) (*(volatile unsigned char *)(address))
108
#endif
109
110
extern
int
state2err[4];
111
extern
struct
grlib_canbtrs_ranges
grcan_btrs_ranges;
112
extern
struct
grlib_canbtrs_ranges
grcanfd_nom_btrs_ranges;
113
extern
struct
grlib_canbtrs_ranges
grcanfd_fd_btrs_ranges;
114
115
int
grcan_wait_rxdata(
struct
grcan_priv
*pDev,
int
min);
116
int
grcan_wait_txspace(
struct
grcan_priv
*pDev,
int
min);
117
118
static
inline
unsigned
int
grcan_hw_rxavail(
119
unsigned
int
rp,
120
unsigned
int
wp,
121
unsigned
int
size)
122
{
123
if
(rp == wp) {
124
/* read pointer and write pointer is equal only
125
* when RX buffer is empty.
126
*/
127
return
0;
128
}
129
130
if
(wp > rp) {
131
return
(wp - rp) / GRCAN_MSG_SIZE;
132
}
else
{
133
return
(size - (rp - wp)) / GRCAN_MSG_SIZE;
134
}
135
}
136
137
static
inline
unsigned
int
grcan_hw_txspace(
138
unsigned
int
rp,
139
unsigned
int
wp,
140
unsigned
int
size)
141
{
142
unsigned
int
left;
143
144
if
(rp == wp) {
145
/* read pointer and write pointer is equal only
146
* when TX buffer is empty.
147
*/
148
return
size / GRCAN_MSG_SIZE - WRAP_AROUND_TX_MSGS;
149
}
150
151
/* size - 4 - abs(read-write) */
152
if
(wp > rp) {
153
left = size - (wp - rp);
154
}
else
{
155
left = rp - wp;
156
}
157
158
return
left / GRCAN_MSG_SIZE - WRAP_AROUND_TX_MSGS;
159
}
rtems_id
Objects_Id rtems_id
This type represents RTEMS object identifiers.
Definition
types.h:94
drvmgr_dev
Definition
drvmgr.h:299
grcan_config
Definition
grcan_internal.h:49
grcan_filter
Definition
grcan.h:131
grcan_msg
Definition
grcan_internal.h:44
grcan_priv
Definition
grcan_internal.h:57
grcan_regs
Definition
grcan.h:54
grcan_selection
Definition
grcan.h:125
grcan_stats
Definition
grcan.h:98
grcan_timing
Definition
grcan.h:109
grcanfd_timing
Definition
grcan.h:117
grlib_canbtrs_ranges
Definition
canbtrs.h:52
Generated by
1.18.0