RTEMS 6.1-rc6
Loading...
Searching...
No Matches
mscan-base.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
11/*
12 * Copyright (c) 2008 embedded brains GmbH & Co. KG
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 */
34
35#ifndef LIBBSP_MSCAN_BASE_H
36#define LIBBSP_MSCAN_BASE_H
37
38#include <stdbool.h>
39
40#include <bsp/mpc5200.h>
41
50#define MSCAN_BIT_RATE_MIN 10000
51
52#define MSCAN_BIT_RATE_MAX 1000000
53
54#define MSCAN_BIT_RATE_DEFAULT 125000
55
56#define MSCAN_FILTER_NUMBER_MIN 0
57
58#define MSCAN_FILTER_NUMBER_2 2
59
60#define MSCAN_FILTER_NUMBER_4 4
61
62#define MSCAN_FILTER_NUMBER_MAX 8
63
64#define MSCAN_FILTER_ID_DEFAULT 0U
65
66#define MSCAN_FILTER_MASK_DEFAULT 0xffffffffU
67
68#define MSCAN_TRANSMIT_BUFFER_NUMBER 3
69
76#define CTL0_RXFRM (1 << 7)
77#define CTL0_RXACT (1 << 6)
78#define CTL0_CSWAI (1 << 5)
79#define CTL0_SYNCH (1 << 4)
80#define CTL0_TIME (1 << 3)
81#define CTL0_WUPE (1 << 2)
82#define CTL0_SLPRQ (1 << 1)
83#define CTL0_INITRQ (1 << 0)
84
93#define CTL1_CANE (1 << 7)
94#define CTL1_CLKSRC (1 << 6)
95#define CTL1_LOOPB (1 << 5)
96#define CTL1_LISTEN (1 << 4)
97#define CTL1_WUPM (1 << 2)
98#define CTL1_SLPAK (1 << 1)
99#define CTL1_INITAK (1 << 0)
100
109#define BTR0_SJW_MASK 0xc0
110#define BTR0_BRP_MASK 0x3f
111
112#define BTR0_SJW( btr0) ((btr0) << 6)
113#define BTR0_BRP( btr0) ((btr0) << 0)
114
115#define BTR0_GET_SJW( btr0) (((btr0) & BTR0_SJW_MASK) >> 6)
116#define BTR0_GET_BRP( btr0) (((btr0) & BTR0_BRP_MASK) >> 0)
117
126#define BTR1_SAMP_MASK 0x80
127#define BTR1_TSEG1_MASK 0x0f
128#define BTR1_TSEG2_MASK 0x70
129
130#define BTR1_SAMP (1 << 7)
131#define BTR1_TSEG1( btr1) ((btr1) << 0)
132#define BTR1_TSEG2( btr1) ((btr1) << 4)
133
134#define BTR1_GET_TSEG1( btr0) (((btr0) & BTR1_TSEG1_MASK) >> 0)
135#define BTR1_GET_TSEG2( btr0) (((btr0) & BTR1_TSEG2_MASK) >> 4)
136
145#define RFLG_WUPIF (1 << 7)
146#define RFLG_CSCIF (1 << 6)
147#define RFLG_RSTAT_MASK (3 << 4)
148#define RFLG_RSTAT_OK (0 << 4)
149#define RFLG_RSTAT_WRN (1 << 4)
150#define RFLG_RSTAT_ERR (2 << 4)
151#define RFLG_RSTAT_OFF (3 << 4)
152#define RFLG_TSTAT_MASK (3 << 2)
153#define RFLG_TSTAT_OK (0 << 2)
154#define RFLG_TSTAT_WRN (1 << 2)
155#define RFLG_TSTAT_ERR (2 << 2)
156#define RFLG_TSTAT_OFF (3 << 2)
157#define RFLG_OVRIF (1 << 1)
158#define RFLG_RXF (1 << 0)
159#define RFLG_GET_RX_STATE(rflg) (((rflg) >> 4) & 0x03)
160#define RFLG_GET_TX_STATE(rflg) (((rflg) >> 2) & 0x03)
161
170#define RIER_WUPIE (1 << 7)
171#define RIER_CSCIE (1 << 6)
172#define RIER_RSTAT(rier) ((rier) << 4)
173#define RIER_TSTAT(rier) ((rier) << 2)
174#define RIER_OVRIE (1 << 1)
175#define RIER_RXFIE (1 << 0)
176
185#define TFLG_TXE2 (1 << 2)
186#define TFLG_TXE1 (1 << 1)
187#define TFLG_TXE0 (1 << 0)
188
197#define TIER_TXEI2 (1 << 2)
198#define TIER_TXEI1 (1 << 1)
199#define TIER_TXEI0 (1 << 0)
200
209#define TARQ_ABTRQ2 (1 << 2)
210#define TARQ_ABTRQ1 (1 << 1)
211#define TARQ_ABTRQ0 (1 << 0)
212
221#define TAAK_ABTRQ2 (1 << 2)
222#define TAAK_ABTRQ1 (1 << 1)
223#define TAAK_ABTRQ0 (1 << 0)
224
233#define BSEL_TX2 (1 << 2)
234#define BSEL_TX1 (1 << 1)
235#define BSEL_TX0 (1 << 0)
236
245#define IDAC_IDAM1 (1 << 5)
246#define IDAC_IDAM0 (1 << 4)
247#define IDAC_IDAM (IDAC_IDAM1 | IDAC_IDAM0)
248#define IDAC_IDHIT( idac) ((idac) & 0x7)
249
255typedef struct mpc5200_mscan mscan;
256
261typedef struct {
262 uint8_t ctl0;
263 uint8_t rier;
264 uint8_t tier;
266
267bool mscan_enable( volatile mscan *m, unsigned bit_rate);
268
269void mscan_disable( volatile mscan *m);
270
271void mscan_interrupts_disable( volatile mscan *m);
272
273bool mscan_set_bit_rate( volatile mscan *m, unsigned bit_rate);
274
276
278
279void mscan_sleep_mode_enter( volatile mscan *m);
280
281void mscan_sleep_mode_leave( volatile mscan *m);
282
283volatile uint8_t *mscan_id_acceptance_register( volatile mscan *m, unsigned i);
284
285volatile uint8_t *mscan_id_mask_register( volatile mscan *m, unsigned i);
286
287unsigned mscan_filter_number( volatile mscan *m);
288
289bool mscan_set_filter_number( volatile mscan *m, unsigned number);
290
291bool mscan_filter_operation( volatile mscan *m, bool set, unsigned index, uint32_t *id, uint32_t *mask);
292
293void mscan_filter_clear( volatile mscan *m);
294
295void mscan_get_error_counters( volatile mscan *m, unsigned *rec, unsigned *tec);
296
299#endif /* LIBBSP_MSCAN_BASE_H */
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:549
void mscan_sleep_mode_leave(volatile mscan *m)
Leave sleep mode for the MSCAN module m.
Definition: mscan-base.c:284
void mscan_initialization_mode_leave(volatile mscan *m, const mscan_context *context)
Leave initialization mode for the MSCAN module m.
Definition: mscan-base.c:253
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:448
void mscan_initialization_mode_enter(volatile mscan *m, mscan_context *context)
Enter initialization mode for the MSCAN module m.
Definition: mscan-base.c:232
bool mscan_enable(volatile mscan *m, unsigned bit_rate)
Enables and initializes the MSCAN module m.
Definition: mscan-base.c:300
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:470
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:156
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:409
struct mpc5200_mscan mscan
MSCAN registers.
Definition: mscan-base.h:255
void mscan_interrupts_disable(volatile mscan *m)
Disables all interrupts for the MSCAN module m.
Definition: mscan-base.c:221
void mscan_sleep_mode_enter(volatile mscan *m)
Enter sleep mode for the MSCAN module m.
Definition: mscan-base.c:275
void mscan_disable(volatile mscan *m)
Disables the MSCAN module m.
Definition: mscan-base.c:333
unsigned mscan_filter_number(volatile mscan *m)
Returns the number of active filters of the MSCAN module m.
Definition: mscan-base.c:386
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:351
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:493
rtems_termios_device_context * context
Definition: console-config.c:62
MSCAN context that has to be saved throughout the initialization mode.
Definition: mscan-base.h:261