RTEMS  5.1
mscan-base.h
Go to the documentation of this file.
1 
9 /*
10  * Copyright (c) 2008
11  * Embedded Brains GmbH
12  * Obere Lagerstr. 30
13  * D-82178 Puchheim
14  * Germany
15  * rtems@embedded-brains.de
16  *
17  * The license and distribution terms for this file may be
18  * found in the file LICENSE in this distribution or at
19  * http://www.rtems.org/license/LICENSE.
20  */
21 
22 #ifndef LIBBSP_MSCAN_BASE_H
23 #define LIBBSP_MSCAN_BASE_H
24 
25 #include <stdbool.h>
26 
27 #include <bsp/mpc5200.h>
28 
37 #define MSCAN_BIT_RATE_MIN 10000
38 
39 #define MSCAN_BIT_RATE_MAX 1000000
40 
41 #define MSCAN_BIT_RATE_DEFAULT 125000
42 
43 #define MSCAN_FILTER_NUMBER_MIN 0
44 
45 #define MSCAN_FILTER_NUMBER_2 2
46 
47 #define MSCAN_FILTER_NUMBER_4 4
48 
49 #define MSCAN_FILTER_NUMBER_MAX 8
50 
51 #define MSCAN_FILTER_ID_DEFAULT 0U
52 
53 #define MSCAN_FILTER_MASK_DEFAULT 0xffffffffU
54 
55 #define MSCAN_TRANSMIT_BUFFER_NUMBER 3
56 
63 #define CTL0_RXFRM (1 << 7)
64 #define CTL0_RXACT (1 << 6)
65 #define CTL0_CSWAI (1 << 5)
66 #define CTL0_SYNCH (1 << 4)
67 #define CTL0_TIME (1 << 3)
68 #define CTL0_WUPE (1 << 2)
69 #define CTL0_SLPRQ (1 << 1)
70 #define CTL0_INITRQ (1 << 0)
71 
80 #define CTL1_CANE (1 << 7)
81 #define CTL1_CLKSRC (1 << 6)
82 #define CTL1_LOOPB (1 << 5)
83 #define CTL1_LISTEN (1 << 4)
84 #define CTL1_WUPM (1 << 2)
85 #define CTL1_SLPAK (1 << 1)
86 #define CTL1_INITAK (1 << 0)
87 
96 #define BTR0_SJW_MASK 0xc0
97 #define BTR0_BRP_MASK 0x3f
98 
99 #define BTR0_SJW( btr0) ((btr0) << 6)
100 #define BTR0_BRP( btr0) ((btr0) << 0)
101 
102 #define BTR0_GET_SJW( btr0) (((btr0) & BTR0_SJW_MASK) >> 6)
103 #define BTR0_GET_BRP( btr0) (((btr0) & BTR0_BRP_MASK) >> 0)
104 
113 #define BTR1_SAMP_MASK 0x80
114 #define BTR1_TSEG1_MASK 0x0f
115 #define BTR1_TSEG2_MASK 0x70
116 
117 #define BTR1_SAMP (1 << 7)
118 #define BTR1_TSEG1( btr1) ((btr1) << 0)
119 #define BTR1_TSEG2( btr1) ((btr1) << 4)
120 
121 #define BTR1_GET_TSEG1( btr0) (((btr0) & BTR1_TSEG1_MASK) >> 0)
122 #define BTR1_GET_TSEG2( btr0) (((btr0) & BTR1_TSEG2_MASK) >> 4)
123 
132 #define RFLG_WUPIF (1 << 7)
133 #define RFLG_CSCIF (1 << 6)
134 #define RFLG_RSTAT_MASK (3 << 4)
135 #define RFLG_RSTAT_OK (0 << 4)
136 #define RFLG_RSTAT_WRN (1 << 4)
137 #define RFLG_RSTAT_ERR (2 << 4)
138 #define RFLG_RSTAT_OFF (3 << 4)
139 #define RFLG_TSTAT_MASK (3 << 2)
140 #define RFLG_TSTAT_OK (0 << 2)
141 #define RFLG_TSTAT_WRN (1 << 2)
142 #define RFLG_TSTAT_ERR (2 << 2)
143 #define RFLG_TSTAT_OFF (3 << 2)
144 #define RFLG_OVRIF (1 << 1)
145 #define RFLG_RXF (1 << 0)
146 #define RFLG_GET_RX_STATE(rflg) (((rflg) >> 4) & 0x03)
147 #define RFLG_GET_TX_STATE(rflg) (((rflg) >> 2) & 0x03)
148 
157 #define RIER_WUPIE (1 << 7)
158 #define RIER_CSCIE (1 << 6)
159 #define RIER_RSTAT(rier) ((rier) << 4)
160 #define RIER_TSTAT(rier) ((rier) << 2)
161 #define RIER_OVRIE (1 << 1)
162 #define RIER_RXFIE (1 << 0)
163 
172 #define TFLG_TXE2 (1 << 2)
173 #define TFLG_TXE1 (1 << 1)
174 #define TFLG_TXE0 (1 << 0)
175 
184 #define TIER_TXEI2 (1 << 2)
185 #define TIER_TXEI1 (1 << 1)
186 #define TIER_TXEI0 (1 << 0)
187 
196 #define TARQ_ABTRQ2 (1 << 2)
197 #define TARQ_ABTRQ1 (1 << 1)
198 #define TARQ_ABTRQ0 (1 << 0)
199 
208 #define TAAK_ABTRQ2 (1 << 2)
209 #define TAAK_ABTRQ1 (1 << 1)
210 #define TAAK_ABTRQ0 (1 << 0)
211 
220 #define BSEL_TX2 (1 << 2)
221 #define BSEL_TX1 (1 << 1)
222 #define BSEL_TX0 (1 << 0)
223 
232 #define IDAC_IDAM1 (1 << 5)
233 #define IDAC_IDAM0 (1 << 4)
234 #define IDAC_IDAM (IDAC_IDAM1 | IDAC_IDAM0)
235 #define IDAC_IDHIT( idac) ((idac) & 0x7)
236 
242 typedef struct mpc5200_mscan mscan;
243 
248 typedef struct {
249  uint8_t ctl0;
250  uint8_t rier;
251  uint8_t tier;
252 } mscan_context;
253 
254 bool mscan_enable( volatile mscan *m, unsigned bit_rate);
255 
256 void mscan_disable( volatile mscan *m);
257 
258 void mscan_interrupts_disable( volatile mscan *m);
259 
260 bool mscan_set_bit_rate( volatile mscan *m, unsigned bit_rate);
261 
263 
265 
266 void mscan_sleep_mode_enter( volatile mscan *m);
267 
268 void mscan_sleep_mode_leave( volatile mscan *m);
269 
270 volatile uint8_t *mscan_id_acceptance_register( volatile mscan *m, unsigned i);
271 
272 volatile uint8_t *mscan_id_mask_register( volatile mscan *m, unsigned i);
273 
274 unsigned mscan_filter_number( volatile mscan *m);
275 
276 bool mscan_set_filter_number( volatile mscan *m, unsigned number);
277 
278 bool mscan_filter_operation( volatile mscan *m, bool set, unsigned index, uint32_t *id, uint32_t *mask);
279 
280 void mscan_filter_clear( volatile mscan *m);
281 
282 void mscan_get_error_counters( volatile mscan *m, unsigned *rec, unsigned *tec);
283 
286 #endif /* LIBBSP_MSCAN_BASE_H */
void mscan_initialization_mode_leave(volatile mscan *m, const mscan_context *context)
Leave initialization mode for the MSCAN module m.
Definition: mscan-base.c:240
void mscan_filter_clear(volatile mscan *m)
Sets the filter ID and mask registers of the MSCAN module m to default values.
Definition: mscan-base.c:338
void mscan_interrupts_disable(volatile mscan *m)
Disables all interrupts for the MSCAN module m.
Definition: mscan-base.c:208
unsigned mscan_filter_number(volatile mscan *m)
Returns the number of active filters of the MSCAN module m.
Definition: mscan-base.c:373
bool mscan_set_bit_rate(volatile mscan *m, unsigned bit_rate)
Sets the bit rate for the MSCAN module m to can_bit_rate in [bits/s].
Definition: mscan-base.c:143
void mscan_disable(volatile mscan *m)
Disables the MSCAN module m.
Definition: mscan-base.c:320
volatile uint8_t * mscan_id_acceptance_register(volatile mscan *m, unsigned i)
Returns the address of the CANIDAR register with index i of the MSCAN module m.
Definition: mscan-base.c:435
bool mscan_filter_operation(volatile mscan *m, bool set, unsigned index, uint32_t *id, uint32_t *mask)
Sets or gets the filter ID and mask in id and mask depending on set of MSCAN module m....
Definition: mscan-base.c:480
MSCAN context that has to be saved throughout the initialization mode.
Definition: mscan-base.h:248
bool mscan_enable(volatile mscan *m, unsigned bit_rate)
Enables and initializes the MSCAN module m.
Definition: mscan-base.c:287
unsigned context
Definition: tlb.h:108
bool mscan_set_filter_number(volatile mscan *m, unsigned number)
Sets the number of active filters of the MSCAN module m to number and returns true if number is valid...
Definition: mscan-base.c:396
void mscan_sleep_mode_leave(volatile mscan *m)
Leave sleep mode for the MSCAN module m.
Definition: mscan-base.c:271
void mscan_sleep_mode_enter(volatile mscan *m)
Enter sleep mode for the MSCAN module m.
Definition: mscan-base.c:262
void mscan_initialization_mode_enter(volatile mscan *m, mscan_context *context)
Enter initialization mode for the MSCAN module m.
Definition: mscan-base.c:219
struct mpc5200_mscan mscan
MSCAN registers.
Definition: mscan-base.h:242
volatile uint8_t * mscan_id_mask_register(volatile mscan *m, unsigned i)
Returns the address of the CANIDMR register with index i of the MSCAN module m.
Definition: mscan-base.c:457
void mscan_get_error_counters(volatile mscan *m, unsigned *rec, unsigned *tec)
Returns the receiver and transmitter error counter values in rec and tec of MSCAN module m.
Definition: mscan-base.c:536