RTEMS 6.1-rc2
Loading...
Searching...
No Matches
mscan_int.h
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/*
4 * RTEMS generic MPC5200 BSP
5 *
6 * This file has to be included by the m driver.
7 */
8
9/*
10 * Copyright (c) 2005 embedded brains GmbH & Co. KG
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 */
33
34#ifndef __MSCAN_INT_H__
35#define __MSCAN_INT_H__
36
37#ifdef __cplusplus
38extern "C" {
39#endif
40
41#include <bsp/mscan-base.h>
42
43#include <bsp/mscan.h>
44
45#define MSCAN_RX_BUFF_NUM 4
46#define MSCAN_TX_BUFF_NUM 3
47
48#define MSCAN_NON_INITIALIZED_MODE 0
49#define MSCAN_INITIALIZED_MODE 1
50#define MSCAN_INIT_NORMAL_MODE 2
51#define MSCAN_NORMAL_MODE 4
52#define MSCAN_SLEEP_MODE 8
53
54#define MSCAN_RX_BUFF_NOACTIVE (0 << 4)
55#define MSCAN_RX_BUFF_EMPTY (1 << 6)
56#define MSCAN_RX_BUFF_FULL (1 << 5)
57#define MSCAN_RX_BUFF_OVERRUN ((MSCAN_RX_BUFF_EMPTY) | (MSCAN_RX_BUFF_FULL))
58#define MSCAN_RX_BUFF_BUSY (1 << 4)
59
60#define MSCAN_MBUFF_MASK 0x07
61
62#define MSCAN_TX_BUFF0 (1 << 0)
63#define MSCAN_TX_BUFF1 (1 << 1)
64#define MSCAN_TX_BUFF2 (1 << 2)
65
66#define MSCAN_IDE (1 << 0)
67#define MSCAN_RTR (1 << 1)
68#define MSCAN_READ_RXBUFF_0 (1 << 2)
69#define MSCAN_READ_RXBUFF_1 (1 << 2)
70#define MSCAN_READ_RXBUFF_2 (1 << 2)
71#define MSCAN_READ_RXBUFF_3 (1 << 2)
72
73#define MSCAN_STATE_OK 0
74#define MSCAN_STATE_ERR 1
75#define MSCAN_STATE_WRN 2
76#define MSCAN_STATE_BUSOFF 3
77
78#define TX_MBUF_SEL(buf_no) (1 << (buf_no))
79#define TX_DATA_LEN(len) ((len) & 0x0F)
80
81#define TX_MBUF_EMPTY(val) (1 << (val))
82
83#define ID_RTR (1 << 4)
84
85#define SET_IDR0(u16) ((uint8_t)((u16) >> 3))
86#define SET_IDR1(u16) (MSCAN_MESS_ID_HAS_RTR(u16) ? ((uint8_t)(((u16) & 0x0007) << 5))|((uint8_t)(ID_RTR)) : ((uint8_t)(((u16) & 0x0007) << 5)))
87
88#define SET_IDR2(u16) SET_IDR0(u16)
89#define SET_IDR3(u16) SET_IDR1(u16)
90
91#define SET_IDR4(u16) SET_IDR0(u16)
92#define SET_IDR5(u16) SET_IDR1(u16)
93
94#define SET_IDR6(u16) SET_IDR0(u16)
95#define SET_IDR7(u16) SET_IDR1(u16)
96
97#define GET_IDR0(u16) ((uint16_t) ((u16) << 3))
98#define GET_IDR1(u16) ((((u16)&(ID_RTR))==(ID_RTR)) ? (uint16_t) ((((u16) >> 5)&0x0007)|MSCAN_MESS_ID_RTR) : (uint16_t)(((u16) >> 5)&0x0007))
99
100#define GET_IDR2(u16) GET_IDR0(u16)
101#define GET_IDR3(u16) GET_IDR1(u16)
102
103#define GET_IDR4(u16) GET_IDR0(u16)
104#define GET_IDR5(u16) GET_IDR1(u16)
105
106#define GET_IDR6(u16) GET_IDR0(u16)
107#define GET_IDR7(u16) GET_IDR1(u16)
108
109#define SET_IDMR0(u16) ((uint8_t)((u16) >> 3))
110#define SET_IDMR1(u16) (MSCAN_MESS_ID_HAS_RTR(u16) ? ((uint8_t) (((((u16) & 0x0007) << 5)|((uint8_t)(ID_RTR)))|0x0007)) : ((uint8_t)((((u16) & 0x0007) << 5))|0x0007))
111
112#define SET_IDMR2(u16) SET_IDMR0(u16)
113#define SET_IDMR3(u16) SET_IDMR1(u16)
114
115#define SET_IDMR4(u16) SET_IDMR0(u16)
116#define SET_IDMR5(u16) SET_IDMR1(u16)
117
118#define SET_IDMR6(u16) SET_IDMR0(u16)
119#define SET_IDMR7(u16) SET_IDMR1(u16)
120
121#define GET_IDMR0(u16) ((uint16_t)((u16) << 3))
122#define GET_IDMR1(u16) ((((u16)&(ID_RTR))==(ID_RTR)) ? (uint16_t) ((((u16) >> 5)&0x0007)|MSCAN_MESS_ID_RTR) : (uint16_t)(((u16) >> 5)&0x0007))
123
124#define GET_IDMR2(u16) GET_IDMR0(u16)
125#define GET_IDMR3(u16) GET_IDMR1(u16)
126
127#define GET_IDMR4(u16) GET_IDMR0(u16)
128#define GET_IDMR5(u16) GET_IDMR1(u16)
129
130#define GET_IDMR6(u16) GET_IDMR0(u16)
131#define GET_IDMR7(u16) GET_IDMR1(u16)
132
133#define NO_OF_MSCAN_RX_BUFF 20
134#define MSCAN_MESSAGE_SIZE(size) (((size)%CPU_ALIGNMENT) ? (((size) + CPU_ALIGNMENT)-((size) + CPU_ALIGNMENT)%CPU_ALIGNMENT) : (size))
135
136#define TX_BUFFER_0 0
137#define TX_BUFFER_1 1
138#define TX_BUFFER_2 2
139
140#define RX_BUFFER_0 0
141#define RX_BUFFER_1 1
142#define RX_BUFFER_2 2
143#define RX_BUFFER_3 3
144
145#define NO_OF_MSCAN_TX_BUFF 20
146#define RING_BUFFER_EMPTY(rbuff) ((((rbuff)->head) == ((rbuff)->tail)) ? TRUE : FALSE)
147#define RING_BUFFER_FULL(rbuff) ((((rbuff)->head) == ((rbuff)->tail)) ? TRUE : FALSE)
148
149
150typedef struct _mscan_handle
151 {
152 uint8_t mscan_channel;
153 void (*toucan_callback)(int16_t);
154 } mscan_handle;
155
157 {
158 struct can_message * volatile buf_ptr;
159 struct can_message * volatile head_ptr;
160 struct can_message * volatile tail_ptr;
161 };
162
164 {
165 struct can_message can_rx_message[MSCAN_RX_BUFF_NUM];
166 };
167
169 {
170 mscan *regs;
171 uint32_t int_rx_err;
172 rtems_id rx_qid;
173 uint32_t rx_qname;
174 rtems_id tx_rb_sid;
175 uint32_t tx_rb_sname;
176 uint8_t id_extended;
177 uint8_t mode;
178 uint8_t tx_buf_no;
179 struct ring_buf tx_ring_buf;
180 };
181
182extern void CanInterrupt_A(int16_t);
183extern void CanInterrupt_B(int16_t);
184
185/*MSCAN driver internal functions */
186void mscan_hardware_initialize(rtems_device_major_number, uint32_t, void *);
187void mpc5200_mscan_wait_sync(mscan *);
188void mpc5200_mscan_perform_init_mode_settings(mscan *);
189void mpc5200_mscan_perform_normal_mode_settings(mscan *);
190rtems_status_code mpc5200_mscan_set_mode(rtems_device_minor_number, uint8_t);
192
193#ifdef __cplusplus
194}
195#endif
196
197#endif /* __MSCAN_H__ */
uint32_t rtems_device_major_number
This integer type represents the major number of devices.
Definition: io.h:103
uint32_t rtems_device_minor_number
This integer type represents the minor number of devices.
Definition: io.h:115
rtems_status_code
This enumeration provides status codes for directives of the Classic API.
Definition: status.h:85
Objects_Id rtems_id
This type represents RTEMS object identifiers.
Definition: types.h:94
struct mpc5200_mscan mscan
MSCAN registers.
Definition: mscan-base.h:255
MSCAN register definitions and support functions.
Definition: mscan_int.h:151
Definition: mscan_int.h:164
Definition: mscan_int.h:169
Definition: mscan_int.h:157
A CAN message represented of both forms.
Definition: can.h:66