RTEMS 5.2
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
mscan_int.h
1/*===============================================================*\
2| Project: RTEMS generic MPC5200 BSP |
3+-----------------------------------------------------------------+
4| Partially based on the code references which are named below. |
5| Adaptions, modifications, enhancements and any recent parts of |
6| the code are: |
7| Copyright (c) 2005 |
8| Embedded Brains GmbH |
9| Obere Lagerstr. 30 |
10| D-82178 Puchheim |
11| Germany |
12| rtems@embedded-brains.de |
13+-----------------------------------------------------------------+
14| The license and distribution terms for this file may be |
15| found in the file LICENSE in this distribution or at |
16| |
17| http://www.rtems.org/license/LICENSE. |
18| |
19+-----------------------------------------------------------------+
20| this file has to be included by the m driver |
21\*===============================================================*/
22#ifndef __MSCAN_INT_H__
23#define __MSCAN_INT_H__
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29#include <bsp/mscan-base.h>
30
31#include <bsp/mscan.h>
32
33#define MSCAN_RX_BUFF_NUM 4
34#define MSCAN_TX_BUFF_NUM 3
35
36#define MSCAN_NON_INITIALIZED_MODE 0
37#define MSCAN_INITIALIZED_MODE 1
38#define MSCAN_INIT_NORMAL_MODE 2
39#define MSCAN_NORMAL_MODE 4
40#define MSCAN_SLEEP_MODE 8
41
42#define MSCAN_RX_BUFF_NOACTIVE (0 << 4)
43#define MSCAN_RX_BUFF_EMPTY (1 << 6)
44#define MSCAN_RX_BUFF_FULL (1 << 5)
45#define MSCAN_RX_BUFF_OVERRUN ((MSCAN_RX_BUFF_EMPTY) | (MSCAN_RX_BUFF_FULL))
46#define MSCAN_RX_BUFF_BUSY (1 << 4)
47
48#define MSCAN_MBUFF_MASK 0x07
49
50#define MSCAN_TX_BUFF0 (1 << 0)
51#define MSCAN_TX_BUFF1 (1 << 1)
52#define MSCAN_TX_BUFF2 (1 << 2)
53
54#define MSCAN_IDE (1 << 0)
55#define MSCAN_RTR (1 << 1)
56#define MSCAN_READ_RXBUFF_0 (1 << 2)
57#define MSCAN_READ_RXBUFF_1 (1 << 2)
58#define MSCAN_READ_RXBUFF_2 (1 << 2)
59#define MSCAN_READ_RXBUFF_3 (1 << 2)
60
61#define MSCAN_STATE_OK 0
62#define MSCAN_STATE_ERR 1
63#define MSCAN_STATE_WRN 2
64#define MSCAN_STATE_BUSOFF 3
65
66#define TX_MBUF_SEL(buf_no) (1 << (buf_no))
67#define TX_DATA_LEN(len) ((len) & 0x0F)
68
69#define TX_MBUF_EMPTY(val) (1 << (val))
70
71#define ID_RTR (1 << 4)
72
73#define SET_IDR0(u16) ((uint8_t)((u16) >> 3))
74#define SET_IDR1(u16) (MSCAN_MESS_ID_HAS_RTR(u16) ? ((uint8_t)(((u16) & 0x0007) << 5))|((uint8_t)(ID_RTR)) : ((uint8_t)(((u16) & 0x0007) << 5)))
75
76#define SET_IDR2(u16) SET_IDR0(u16)
77#define SET_IDR3(u16) SET_IDR1(u16)
78
79#define SET_IDR4(u16) SET_IDR0(u16)
80#define SET_IDR5(u16) SET_IDR1(u16)
81
82#define SET_IDR6(u16) SET_IDR0(u16)
83#define SET_IDR7(u16) SET_IDR1(u16)
84
85#define GET_IDR0(u16) ((uint16_t) ((u16) << 3))
86#define GET_IDR1(u16) ((((u16)&(ID_RTR))==(ID_RTR)) ? (uint16_t) ((((u16) >> 5)&0x0007)|MSCAN_MESS_ID_RTR) : (uint16_t)(((u16) >> 5)&0x0007))
87
88#define GET_IDR2(u16) GET_IDR0(u16)
89#define GET_IDR3(u16) GET_IDR1(u16)
90
91#define GET_IDR4(u16) GET_IDR0(u16)
92#define GET_IDR5(u16) GET_IDR1(u16)
93
94#define GET_IDR6(u16) GET_IDR0(u16)
95#define GET_IDR7(u16) GET_IDR1(u16)
96
97#define SET_IDMR0(u16) ((uint8_t)((u16) >> 3))
98#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))
99
100#define SET_IDMR2(u16) SET_IDMR0(u16)
101#define SET_IDMR3(u16) SET_IDMR1(u16)
102
103#define SET_IDMR4(u16) SET_IDMR0(u16)
104#define SET_IDMR5(u16) SET_IDMR1(u16)
105
106#define SET_IDMR6(u16) SET_IDMR0(u16)
107#define SET_IDMR7(u16) SET_IDMR1(u16)
108
109#define GET_IDMR0(u16) ((uint16_t)((u16) << 3))
110#define GET_IDMR1(u16) ((((u16)&(ID_RTR))==(ID_RTR)) ? (uint16_t) ((((u16) >> 5)&0x0007)|MSCAN_MESS_ID_RTR) : (uint16_t)(((u16) >> 5)&0x0007))
111
112#define GET_IDMR2(u16) GET_IDMR0(u16)
113#define GET_IDMR3(u16) GET_IDMR1(u16)
114
115#define GET_IDMR4(u16) GET_IDMR0(u16)
116#define GET_IDMR5(u16) GET_IDMR1(u16)
117
118#define GET_IDMR6(u16) GET_IDMR0(u16)
119#define GET_IDMR7(u16) GET_IDMR1(u16)
120
121#define NO_OF_MSCAN_RX_BUFF 20
122#define MSCAN_MESSAGE_SIZE(size) (((size)%CPU_ALIGNMENT) ? (((size) + CPU_ALIGNMENT)-((size) + CPU_ALIGNMENT)%CPU_ALIGNMENT) : (size))
123
124#define TX_BUFFER_0 0
125#define TX_BUFFER_1 1
126#define TX_BUFFER_2 2
127
128#define RX_BUFFER_0 0
129#define RX_BUFFER_1 1
130#define RX_BUFFER_2 2
131#define RX_BUFFER_3 3
132
133#define NO_OF_MSCAN_TX_BUFF 20
134#define RING_BUFFER_EMPTY(rbuff) ((((rbuff)->head) == ((rbuff)->tail)) ? TRUE : FALSE)
135#define RING_BUFFER_FULL(rbuff) ((((rbuff)->head) == ((rbuff)->tail)) ? TRUE : FALSE)
136
137
138typedef struct _mscan_handle
139 {
140 uint8_t mscan_channel;
141 void (*toucan_callback)(int16_t);
142 } mscan_handle;
143
145 {
146 struct can_message * volatile buf_ptr;
147 struct can_message * volatile head_ptr;
148 struct can_message * volatile tail_ptr;
149 };
150
152 {
153 struct can_message can_rx_message[MSCAN_RX_BUFF_NUM];
154 };
155
157 {
158 mscan *regs;
159 uint32_t int_rx_err;
160 rtems_id rx_qid;
161 uint32_t rx_qname;
162 rtems_id tx_rb_sid;
163 uint32_t tx_rb_sname;
164 uint8_t id_extended;
165 uint8_t mode;
166 uint8_t tx_buf_no;
167 struct ring_buf tx_ring_buf;
168 };
169
170extern void CanInterrupt_A(int16_t);
171extern void CanInterrupt_B(int16_t);
172
173/*MSCAN driver internal functions */
174void mscan_hardware_initialize(rtems_device_major_number, uint32_t, void *);
175void mpc5200_mscan_wait_sync(mscan *);
176void mpc5200_mscan_perform_init_mode_settings(mscan *);
177void mpc5200_mscan_perform_normal_mode_settings(mscan *);
178rtems_status_code mpc5200_mscan_set_mode(rtems_device_minor_number, uint8_t);
179rtems_status_code mscan_channel_initialize(rtems_device_major_number, rtems_device_minor_number);
180
181#ifdef __cplusplus
182}
183#endif
184
185#endif /* __MSCAN_H__ */
rtems_status_code
Classic API Status.
Definition: status.h:43
Objects_Id rtems_id
Used to manage and manipulate RTEMS object identifiers.
Definition: types.h:83
struct mpc5200_mscan mscan
MSCAN registers.
Definition: mscan-base.h:242
MSCAN register definitions and support functions.
Definition: mscan_int.h:139
Definition: mscan_int.h:152
Definition: mscan_int.h:157
Definition: mscan_int.h:145
A CAN message represented of both forms.
Definition: can.h:66