RTEMS 6.1-rc4
Loading...
Searching...
No Matches
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
60extern "C" {
61#endif
62
63typedef enum {
64 CAN_STD_ID = 0,
65 CAN_EXT_ID = 1
66} MCan_IdType;
67
68typedef 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
87typedef enum {
88 CAN_FIFO_0 = 0,
89 CAN_FIFO_1 = 1
90} MCan_FifoType;
91
92typedef enum {
93 CAN_INTR_LINE_0 = 0,
94 CAN_INTR_LINE_1 = 1
95} MCan_IntrLineType;
96
97typedef struct MailboxInfoTag {
98 uint32_t id;
99 uint32_t length;
100 uint32_t timestamp;
102
103
104typedef struct MailBox8Tag {
105 MailboxInfoType info;
106 uint8_t data[8];
108
109typedef struct MailBox12Tag {
110 MailboxInfoType info;
111 uint8_t data[12];
113
114typedef struct MailBox16Tag {
115 MailboxInfoType info;
116 uint8_t data[16];
118
119typedef struct MailBox20Tag {
120 MailboxInfoType info;
121 uint8_t data[20];
123
124typedef struct MailBox24Tag {
125 MailboxInfoType info;
126 uint8_t data[24];
128
129typedef struct MailBox32Tag {
130 MailboxInfoType info;
131 uint8_t data[32];
133
134typedef struct MailBox48Tag {
135 MailboxInfoType info;
136 uint8_t data[48];
138
139typedef struct MailBox64Tag {
140 MailboxInfoType info;
141 uint8_t data[64];
143
144
145
146typedef 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
157typedef 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
178extern const MCan_ConfigType mcan0Config;
179extern 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
238void MCAN_Init(
239 const MCan_ConfigType *mcanConfig);
240
242 const MCan_ConfigType *mcanConfig);
243
245 const MCan_ConfigType *mcanConfig);
246
248 const MCan_ConfigType *mcanConfig);
249
251 const MCan_ConfigType *mcanConfig);
252
253void MCAN_Enable(
254 const MCan_ConfigType *mcanConfig);
255
257 const MCan_ConfigType *mcanConfig);
258
259void MCAN_RequestFd(
260 const MCan_ConfigType *mcanConfig);
261
263 const MCan_ConfigType *mcanConfig);
264
265void MCAN_LoopbackOn(
266 const MCan_ConfigType *mcanConfig);
267
269 const MCan_ConfigType *mcanConfig);
270
272 const MCan_ConfigType *mcanConfig,
273 MCan_IntrLineType line);
274
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
286uint32_t MCAN_AddToTxFifoQ(
287 const MCan_ConfigType *mcanConfig,
288 uint32_t id, MCan_IdType idType,
289 MCan_DlcType dlc, uint8_t *data);
290
291uint8_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
319uint32_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
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
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_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
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
uint8_t MCAN_IsNewDataInRxDedBuffer(const MCan_ConfigType *mcanConfig, uint8_t buffer)
check if data received into buffer
Definition: mcan.c:1037
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
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
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
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_LoopbackOff(const MCan_ConfigType *mcanConfig)
Switch off loop back mode.
Definition: mcan.c:815
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
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_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
void MCAN_GetRxDedBuffer(const MCan_ConfigType *mcanConfig, uint8_t buffer, Mailbox64Type *pRxMailbox)
Get Rx buffer.
Definition: mcan.c:1056
void MCAN_SendTxDedBuffer(const MCan_ConfigType *mcanConfig, uint8_t buffer)
Send Tx buffer.
Definition: mcan.c:882
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
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_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
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
uint8_t MCAN_IsBufferTxd(const MCan_ConfigType *mcanConfig, uint8_t buffer)
Check if data transmitted from buffer/fifo/queue.
Definition: mcan.c:942
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
Definition: mcan.h:157
Definition: mcan.h:146
Definition: mcan.h:109
Definition: mcan.h:114
Definition: mcan.h:119
Definition: mcan.h:124
Definition: mcan.h:129
Definition: mcan.h:134
Definition: mcan.h:139
Definition: mcan.h:104
Definition: mcan.h:97
Mcan hardware registers.
Definition: component_mcan.h:41
__IO uint32_t MCAN_IR
(Mcan Offset: 0x50) Interrupt Register
Definition: component_mcan.h:57