RTEMS  5.1
mcan.h
Go to the documentation of this file.
1 /* ---------------------------------------------------------------------------- */
2 /* Atmel Microcontroller Software Support */
3 /* SAM Software Package License */
4 /* ---------------------------------------------------------------------------- */
5 /* Copyright (c) 2015, Atmel Corporation */
6 /* */
7 /* All rights reserved. */
8 /* */
9 /* Redistribution and use in source and binary forms, with or without */
10 /* modification, are permitted provided that the following condition is met: */
11 /* */
12 /* - Redistributions of source code must retain the above copyright notice, */
13 /* this list of conditions and the disclaimer below. */
14 /* */
15 /* Atmel's name may not be used to endorse or promote products derived from */
16 /* this software without specific prior written permission. */
17 /* */
18 /* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR */
19 /* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
20 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE */
21 /* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, */
22 /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */
23 /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */
24 /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */
25 /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */
26 /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
27 /* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
28 /* ---------------------------------------------------------------------------- */
29 
44 #ifndef _MCAN_
45 #define _MCAN_
46 
47 /*------------------------------------------------------------------------------
48  * Headers
49  *------------------------------------------------------------------------------*/
50 
51 #include "chip.h"
52 
53 #include <stdint.h>
54 
55 /*------------------------------------------------------------------------------
56  * Global functions
57  *------------------------------------------------------------------------------*/
58 
59 #ifdef __cplusplus
60 extern "C" {
61 #endif
62 
63 typedef enum {
64  CAN_STD_ID = 0,
65  CAN_EXT_ID = 1
66 } MCan_IdType;
67 
68 typedef enum {
69  CAN_DLC_0 = 0,
70  CAN_DLC_1 = 1,
71  CAN_DLC_2 = 2,
72  CAN_DLC_3 = 3,
73  CAN_DLC_4 = 4,
74  CAN_DLC_5 = 5,
75  CAN_DLC_6 = 6,
76  CAN_DLC_7 = 7,
77  CAN_DLC_8 = 8,
78  CAN_DLC_12 = 9,
79  CAN_DLC_16 = 10,
80  CAN_DLC_20 = 11,
81  CAN_DLC_24 = 12,
82  CAN_DLC_32 = 13,
83  CAN_DLC_48 = 14,
84  CAN_DLC_64 = 15
85 } MCan_DlcType;
86 
87 typedef enum {
88  CAN_FIFO_0 = 0,
89  CAN_FIFO_1 = 1
90 } MCan_FifoType;
91 
92 typedef enum {
93  CAN_INTR_LINE_0 = 0,
94  CAN_INTR_LINE_1 = 1
95 } MCan_IntrLineType;
96 
97 typedef struct MailboxInfoTag {
98  uint32_t id;
99  uint32_t length;
100  uint32_t timestamp;
102 
103 
104 typedef struct MailBox8Tag {
105  MailboxInfoType info;
106  uint8_t data[8];
107 } Mailbox8Type;
108 
109 typedef struct MailBox12Tag {
110  MailboxInfoType info;
111  uint8_t data[12];
112 } Mailbox12Type;
113 
114 typedef struct MailBox16Tag {
115  MailboxInfoType info;
116  uint8_t data[16];
117 } Mailbox16Type;
118 
119 typedef struct MailBox20Tag {
120  MailboxInfoType info;
121  uint8_t data[20];
122 } Mailbox20Type;
123 
124 typedef struct MailBox24Tag {
125  MailboxInfoType info;
126  uint8_t data[24];
127 } Mailbox24Type;
128 
129 typedef struct MailBox32Tag {
130  MailboxInfoType info;
131  uint8_t data[32];
132 } Mailbox32ype;
133 
134 typedef struct MailBox48Tag {
135  MailboxInfoType info;
136  uint8_t data[48];
137 } Mailbox48Type;
138 
139 typedef struct MailBox64Tag {
140  MailboxInfoType info;
141  uint8_t data[64];
142 } Mailbox64Type;
143 
144 
145 
146 typedef struct MCan_MsgRamPntrsTag {
147  uint32_t *pStdFilts;
148  uint32_t *pExtFilts;
149  uint32_t *pRxFifo0;
150  uint32_t *pRxFifo1;
151  uint32_t *pRxDedBuf;
152  uint32_t *pTxEvtFifo;
153  uint32_t *pTxDedBuf;
154  uint32_t *pTxFifoQ;
156 
157 typedef struct MCan_ConfigTag {
158  Mcan *pMCan;
159  uint32_t bitTiming;
160  uint32_t fastBitTiming;
161  uint32_t nmbrStdFilts;
162  uint32_t nmbrExtFilts;
163  uint32_t nmbrFifo0Elmts;
164  uint32_t nmbrFifo1Elmts;
165  uint32_t nmbrRxDedBufElmts;
166  uint32_t nmbrTxEvtFifoElmts;
167  uint32_t nmbrTxDedBufElmts;
168  uint32_t nmbrTxFifoQElmts;
169  uint32_t rxFifo0ElmtSize;
170  uint32_t rxFifo1ElmtSize;
171  uint32_t rxBufElmtSize;
172  // Element sizes and data sizes (encoded element size)
173  uint32_t txBufElmtSize;
174  // Element size and data size (encoded element size)
175  MCan_MsgRamPntrs msgRam;
177 
178 extern const MCan_ConfigType mcan0Config;
179 extern const MCan_ConfigType mcan1Config;
180 
181 __STATIC_INLINE uint32_t MCAN_IsTxComplete(
182  const MCan_ConfigType *mcanConfig)
183 {
184  Mcan *mcan = mcanConfig->pMCan;
185  return (mcan->MCAN_IR & MCAN_IR_TC);
186 }
187 
188 __STATIC_INLINE void MCAN_ClearTxComplete(
189  const MCan_ConfigType *mcanConfig)
190 {
191  Mcan *mcan = mcanConfig->pMCan;
192  mcan->MCAN_IR = MCAN_IR_TC;
193 }
194 
195 __STATIC_INLINE uint32_t MCAN_IsMessageStoredToRxDedBuffer(
196  const MCan_ConfigType *mcanConfig)
197 {
198  Mcan *mcan = mcanConfig->pMCan;
199 
200  return (mcan->MCAN_IR & MCAN_IR_DRX);
201 }
202 
203 __STATIC_INLINE void MCAN_ClearMessageStoredToRxBuffer(
204  const MCan_ConfigType *mcanConfig)
205 {
206  Mcan *mcan = mcanConfig->pMCan;
207  mcan->MCAN_IR = MCAN_IR_DRX;
208 }
209 
210 __STATIC_INLINE uint32_t MCAN_IsMessageStoredToRxFifo0(
211  const MCan_ConfigType *mcanConfig)
212 {
213  Mcan *mcan = mcanConfig->pMCan;
214  return (mcan->MCAN_IR & MCAN_IR_RF0N);
215 }
216 
217 __STATIC_INLINE void MCAN_ClearMessageStoredToRxFifo0(
218  const MCan_ConfigType *mcanConfig)
219 {
220  Mcan *mcan = mcanConfig->pMCan;
221  mcan->MCAN_IR = MCAN_IR_RF0N;
222 }
223 
224 __STATIC_INLINE uint32_t MCAN_IsMessageStoredToRxFifo1(
225  const MCan_ConfigType *mcanConfig)
226 {
227  Mcan *mcan = mcanConfig->pMCan;
228  return (mcan->MCAN_IR & MCAN_IR_RF1N);
229 }
230 
231 __STATIC_INLINE void MCAN_ClearMessageStoredToRxFifo1(
232  const MCan_ConfigType *mcanConfig)
233 {
234  Mcan *mcan = mcanConfig->pMCan;
235  mcan->MCAN_IR = MCAN_IR_RF1N;
236 }
237 
238 void MCAN_Init(
239  const MCan_ConfigType *mcanConfig);
240 
241 void MCAN_InitFdEnable(
242  const MCan_ConfigType *mcanConfig);
243 
245  const MCan_ConfigType *mcanConfig);
246 
247 void MCAN_InitTxQueue(
248  const MCan_ConfigType *mcanConfig);
249 
250 void MCAN_InitLoopback(
251  const MCan_ConfigType *mcanConfig);
252 
253 void MCAN_Enable(
254  const MCan_ConfigType *mcanConfig);
255 
257  const MCan_ConfigType *mcanConfig);
258 
259 void MCAN_RequestFd(
260  const MCan_ConfigType *mcanConfig);
261 
263  const MCan_ConfigType *mcanConfig);
264 
265 void MCAN_LoopbackOn(
266  const MCan_ConfigType *mcanConfig);
267 
268 void MCAN_LoopbackOff(
269  const MCan_ConfigType *mcanConfig);
270 
272  const MCan_ConfigType *mcanConfig,
273  MCan_IntrLineType line);
274 
275 uint8_t *MCAN_ConfigTxDedBuffer(
276  const MCan_ConfigType *mcanConfig,
277  uint8_t buffer,
278  uint32_t id,
279  MCan_IdType idType,
280  MCan_DlcType dlc);
281 
283  const MCan_ConfigType *mcanConfig,
284  uint8_t buffer);
285 
286 uint32_t MCAN_AddToTxFifoQ(
287  const MCan_ConfigType *mcanConfig,
288  uint32_t id, MCan_IdType idType,
289  MCan_DlcType dlc, uint8_t *data);
290 
291 uint8_t MCAN_IsBufferTxd(
292  const MCan_ConfigType *mcanConfig,
293  uint8_t buffer);
294 
296  const MCan_ConfigType *mcanConfig,
297  uint32_t buffer,
298  uint32_t filter,
299  uint32_t id,
300  MCan_IdType idType);
301 
303  const MCan_ConfigType *mcanConfig,
304  MCan_FifoType fifo,
305  uint8_t filter,
306  uint32_t id,
307  MCan_IdType idType,
308  uint32_t mask);
309 
311  const MCan_ConfigType *mcanConfig,
312  uint8_t buffer);
313 
315  const MCan_ConfigType *mcanConfig,
316  uint8_t buffer,
317  Mailbox64Type *pRxMailbox);
318 
319 uint32_t MCAN_GetRxFifoBuffer(
320  const MCan_ConfigType *mcanConfig,
321  MCan_FifoType fifo,
322  Mailbox64Type *pRxMailbox);
323 
324 #ifdef __cplusplus
325 }
326 #endif
327 
328 #endif /* #ifndef _MCAN_ */
329 
#define MCAN_IR_DRX
(MCAN_IR) Message stored to Dedicated Receive Buffer
Definition: component_mcan.h:275
void MCAN_Init(const MCan_ConfigType *mcanConfig)
Initializes the MCAN hardware for giving peripheral. Default: Mixed mode TX Buffer + FIFO.
Definition: mcan.c:540
void MCAN_InitLoopback(const MCan_ConfigType *mcanConfig)
Initializes the MCAN in loop back mode. INIT must be set - so this should be called between MCAN_Init...
Definition: mcan.c:712
Definition: mcan.h:114
void MCAN_LoopbackOff(const MCan_ConfigType *mcanConfig)
Switch off loop back mode.
Definition: mcan.c:815
void MCAN_RequestFdBitRateSwitch(const MCan_ConfigType *mcanConfig)
Request switch to FD mode (tx & rx payloads up to 64 bytes) and transmits WITH bit rate switching....
Definition: mcan.c:786
Mcan hardware registers.
Definition: component_mcan.h:41
void MCAN_InitFdEnable(const MCan_ConfigType *mcanConfig)
Enables a FUTURE switch to FD mode (tx & rx payloads up to 64 bytes) but transmits WITHOUT bit rate s...
Definition: mcan.c:682
Definition: mcan.h:109
void MCAN_IEnableMessageStoredToRxDedBuffer(const MCan_ConfigType *mcanConfig, MCan_IntrLineType line)
Enable message line and message stored to Dedicated Receive Buffer Interrupt Line.
Definition: mcan.c:827
Definition: mcan.h:157
Definition: mcan.h:139
void MCAN_SendTxDedBuffer(const MCan_ConfigType *mcanConfig, uint8_t buffer)
Send Tx buffer.
Definition: mcan.c:882
uint32_t MCAN_GetRxFifoBuffer(const MCan_ConfigType *mcanConfig, MCan_FifoType fifo, Mailbox64Type *pRxMailbox)
Get from the receive FIFO and place in a application mailbox.
Definition: mcan.c:1113
void MCAN_InitFdBitRateSwitchEnable(const MCan_ConfigType *mcanConfig)
Enables a FUTURE switch to FD mode (tx & rx payloads up to 64 bytes) and transmits WITH bit rate swit...
Definition: mcan.c:697
Definition: mcan.h:97
void MCAN_LoopbackOn(const MCan_ConfigType *mcanConfig)
Switch on loop back mode. TEST must be set in MCAN_CCCR - e.g. by a prior call to MCAN_InitLoopback()
Definition: mcan.c:805
Definition: mcan.h:129
#define MCAN_IR_RF1N
(MCAN_IR) Receive FIFO 1 New Message
Definition: component_mcan.h:260
Definition: mcan.h:146
__IO uint32_t MCAN_IR
(Mcan Offset: 0x50) Interrupt Register
Definition: component_mcan.h:57
uint8_t * MCAN_ConfigTxDedBuffer(const MCan_ConfigType *mcanConfig, uint8_t buffer, uint32_t id, MCan_IdType idType, MCan_DlcType dlc)
Configures a Dedicated TX Buffer.
Definition: mcan.c:853
void MCAN_RequestFd(const MCan_ConfigType *mcanConfig)
Requests switch to FD mode (tx & rx payloads up to 64 bytes) but transmits WITHOUT bit rate switching...
Definition: mcan.c:767
#define MCAN_IR_RF0N
(MCAN_IR) Receive FIFO 0 New Message
Definition: component_mcan.h:256
void MCAN_GetRxDedBuffer(const MCan_ConfigType *mcanConfig, uint8_t buffer, Mailbox64Type *pRxMailbox)
Get Rx buffer.
Definition: mcan.c:1056
Definition: mcan.h:124
uint8_t MCAN_IsNewDataInRxDedBuffer(const MCan_ConfigType *mcanConfig, uint8_t buffer)
check if data received into buffer
Definition: mcan.c:1037
#define MCAN_IR_TC
(MCAN_IR) Transmission Completed
Definition: component_mcan.h:265
Definition: mcan.h:134
void MCAN_ConfigRxBufferFilter(const MCan_ConfigType *mcanConfig, uint32_t buffer, uint32_t filter, uint32_t id, MCan_IdType idType)
Configure RX Buffer Filter ID must match exactly for a RX Buffer Filter.
Definition: mcan.c:957
Definition: mcan.h:119
uint8_t MCAN_IsBufferTxd(const MCan_ConfigType *mcanConfig, uint8_t buffer)
Check if data transmitted from buffer/fifo/queue.
Definition: mcan.c:942
uint32_t MCAN_AddToTxFifoQ(const MCan_ConfigType *mcanConfig, uint32_t id, MCan_IdType idType, MCan_DlcType dlc, uint8_t *data)
Adds Message to TX Fifo / Queue.
Definition: mcan.c:898
void MCAN_ConfigRxClassicFilter(const MCan_ConfigType *mcanConfig, MCan_FifoType fifo, uint8_t filter, uint32_t id, MCan_IdType idType, uint32_t mask)
Configure Classic Filter Classic Filters direct accepted messages to a FIFO & include both a ID and a...
Definition: mcan.c:995
Definition: mcan.h:104
void MCAN_InitTxQueue(const MCan_ConfigType *mcanConfig)
Initializes MCAN queue for TX INIT must be set - so this should be called between MCAN_Init() and MCA...
Definition: mcan.c:727
void MCAN_RequestIso11898_1(const MCan_ConfigType *mcanConfig)
Requests switch to Iso11898-1 (standard / classic) mode (tx & rx payloads up to 8 bytes).
Definition: mcan.c:749
void MCAN_Enable(const MCan_ConfigType *mcanConfig)
Enable MCAN peripheral. INIT must be set - so this should be called between MCAN_Init()
Definition: mcan.c:738