+/rtos

git clone https://git.julia.blue/+/rtos

Vivek Malneediconvert lab6 starter code to tivaware4786702

master
13.8 KiB441 linesraw
1//*****************************************************************************
2//
3// can.h - Defines and Macros for the CAN controller.
4//
5// Copyright (c) 2006-2017 Texas Instruments Incorporated.  All rights reserved.
6// Software License Agreement
7//
8//   Redistribution and use in source and binary forms, with or without
9//   modification, are permitted provided that the following conditions
10//   are met:
11//
12//   Redistributions of source code must retain the above copyright
13//   notice, this list of conditions and the following disclaimer.
14//
15//   Redistributions in binary form must reproduce the above copyright
16//   notice, this list of conditions and the following disclaimer in the
17//   documentation and/or other materials provided with the
18//   distribution.
19//
20//   Neither the name of Texas Instruments Incorporated nor the names of
21//   its contributors may be used to endorse or promote products derived
22//   from this software without specific prior written permission.
23//
24// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35//
36// This is part of revision 2.1.4.178 of the Tiva Peripheral Driver Library.
37//
38//*****************************************************************************
39
40#ifndef __DRIVERLIB_CAN_H__
41#define __DRIVERLIB_CAN_H__
42
43#include <stdbool.h>
44#include <stdint.h>
45
46//*****************************************************************************
47//
48//! \addtogroup can_api
49//! @{
50//
51//*****************************************************************************
52
53//*****************************************************************************
54//
55// If building with a C++ compiler, make all of the definitions in this header
56// have a C binding.
57//
58//*****************************************************************************
59#ifdef __cplusplus
60extern "C" {
61#endif
62
63//*****************************************************************************
64//
65// Miscellaneous defines for Message ID Types
66//
67//*****************************************************************************
68
69//*****************************************************************************
70//
71// These are the flags used by the tCANMsgObject.ui32Flags value when calling
72// the CANMessageSet() and CANMessageGet() functions.
73//
74//*****************************************************************************
75
76//
77//! This indicates that transmit interrupts are enabled.
78//
79#define MSG_OBJ_TX_INT_ENABLE 0x00000001
80
81//
82//! This indicates that receive interrupts are enabled.
83//
84#define MSG_OBJ_RX_INT_ENABLE 0x00000002
85
86//
87//! This indicates that a message object is using an extended identifier.
88//
89#define MSG_OBJ_EXTENDED_ID 0x00000004
90
91//
92//! This indicates that a message object is using filtering based on the
93//! object's message identifier.
94//
95#define MSG_OBJ_USE_ID_FILTER 0x00000008
96
97//
98//! This indicates that new data was available in the message object.
99//
100#define MSG_OBJ_NEW_DATA 0x00000080
101
102//
103//! This indicates that data was lost since this message object was last
104//! read.
105//
106#define MSG_OBJ_DATA_LOST 0x00000100
107
108//
109//! This indicates that a message object uses or is using filtering
110//! based on the direction of the transfer.  If the direction filtering is
111//! used, then ID filtering must also be enabled.
112//
113#define MSG_OBJ_USE_DIR_FILTER (0x00000010 | MSG_OBJ_USE_ID_FILTER)
114
115//
116//! This indicates that a message object uses or is using message
117//! identifier filtering based on the extended identifier.  If the extended
118//! identifier filtering is used, then ID filtering must also be enabled.
119//
120#define MSG_OBJ_USE_EXT_FILTER (0x00000020 | MSG_OBJ_USE_ID_FILTER)
121
122//
123//! This indicates that a message object is a remote frame.
124//
125#define MSG_OBJ_REMOTE_FRAME 0x00000040
126
127//
128//! This indicates that this message object is part of a FIFO structure and
129//! not the final message object in a FIFO.
130//
131#define MSG_OBJ_FIFO 0x00000200
132
133//
134//! This indicates that a message object has no flags set.
135//
136#define MSG_OBJ_NO_FLAGS 0x00000000
137
138//*****************************************************************************
139//
140//! This define is used with the flag values to allow checking only status
141//! flags and not configuration flags.
142//
143//*****************************************************************************
144#define MSG_OBJ_STATUS_MASK (MSG_OBJ_NEW_DATA | MSG_OBJ_DATA_LOST)
145
146//*****************************************************************************
147//
148//! The structure used for encapsulating all the items associated with a CAN
149//! message object in the CAN controller.
150//
151//*****************************************************************************
152typedef struct {
153    //
154    //! The CAN message identifier used for 11 or 29 bit identifiers.
155    //
156    uint32_t ui32MsgID;
157
158    //
159    //! The message identifier mask used when identifier filtering is enabled.
160    //
161    uint32_t ui32MsgIDMask;
162
163    //
164    //! This value holds various status flags and settings specified by
165    //! tCANObjFlags.
166    //
167    uint32_t ui32Flags;
168
169    //
170    //! This value is the number of bytes of data in the message object.
171    //
172    uint32_t ui32MsgLen;
173
174    //
175    //! This is a pointer to the message object's data.
176    //
177    uint8_t* pui8MsgData;
178} tCANMsgObject;
179
180//*****************************************************************************
181//
182//! This structure is used for encapsulating the values associated with setting
183//! up the bit timing for a CAN controller.  The structure is used when calling
184//! the CANGetBitTiming and CANSetBitTiming functions.
185//
186//*****************************************************************************
187typedef struct {
188    //
189    //! This value holds the sum of the Synchronization, Propagation, and Phase
190    //! Buffer 1 segments, measured in time quanta.  The valid values for this
191    //! setting range from 2 to 16.
192    //
193    uint32_t ui32SyncPropPhase1Seg;
194
195    //
196    //! This value holds the Phase Buffer 2 segment in time quanta.  The valid
197    //! values for this setting range from 1 to 8.
198    //
199    uint32_t ui32Phase2Seg;
200
201    //
202    //! This value holds the Resynchronization Jump Width in time quanta.  The
203    //! valid values for this setting range from 1 to 4.
204    //
205    uint32_t ui32SJW;
206
207    //
208    //! This value holds the CAN_CLK divider used to determine time quanta.
209    //! The valid values for this setting range from 1 to 1023.
210    //
211    uint32_t ui32QuantumPrescaler;
212} tCANBitClkParms;
213
214//*****************************************************************************
215//
216//! This data type is used to identify the interrupt status register.  This is
217//! used when calling the CANIntStatus() function.
218//
219//*****************************************************************************
220typedef enum {
221    //
222    //! Read the CAN interrupt status information.
223    //
224    CAN_INT_STS_CAUSE,
225
226    //
227    //! Read a message object's interrupt status.
228    //
229    CAN_INT_STS_OBJECT
230} tCANIntStsReg;
231
232//*****************************************************************************
233//
234//! This data type is used to identify which of several status registers to
235//! read when calling the CANStatusGet() function.
236//
237//*****************************************************************************
238typedef enum {
239    //
240    //! Read the full CAN controller status.
241    //
242    CAN_STS_CONTROL,
243
244    //
245    //! Read the full 32-bit mask of message objects with a transmit request
246    //! set.
247    //
248    CAN_STS_TXREQUEST,
249
250    //
251    //! Read the full 32-bit mask of message objects with new data available.
252    //
253    CAN_STS_NEWDAT,
254
255    //
256    //! Read the full 32-bit mask of message objects that are enabled.
257    //
258    CAN_STS_MSGVAL
259} tCANStsReg;
260
261//*****************************************************************************
262//
263// These definitions are used to specify interrupt sources to CANIntEnable()
264// and CANIntDisable().
265//
266//*****************************************************************************
267//
268//! This flag is used to allow a CAN controller to generate error
269//! interrupts.
270//
271#define CAN_INT_ERROR 0x00000008
272
273//
274//! This flag is used to allow a CAN controller to generate status
275//! interrupts.
276//
277#define CAN_INT_STATUS 0x00000004
278
279//
280//! This flag is used to allow a CAN controller to generate any CAN
281//! interrupts.  If this is not set, then no interrupts are generated
282//! by the CAN controller.
283//
284#define CAN_INT_MASTER 0x00000002
285
286//*****************************************************************************
287//
288//! This definition is used to determine the type of message object that is
289//! set up via a call to the CANMessageSet() API.
290//
291//*****************************************************************************
292typedef enum {
293    //
294    //! Transmit message object.
295    //
296    MSG_OBJ_TYPE_TX,
297
298    //
299    //! Transmit remote request message object
300    //
301    MSG_OBJ_TYPE_TX_REMOTE,
302
303    //
304    //! Receive message object.
305    //
306    MSG_OBJ_TYPE_RX,
307
308    //
309    //! Receive remote request message object.
310    //
311    MSG_OBJ_TYPE_RX_REMOTE,
312
313    //
314    //! Remote frame receive remote, with auto-transmit message object.
315    //
316    MSG_OBJ_TYPE_RXTX_REMOTE
317} tMsgObjType;
318
319//*****************************************************************************
320//
321// The following enumeration contains all error or status indicators that can
322// be returned when calling the CANStatusGet() function.
323//
324//*****************************************************************************
325//
326//! CAN controller has entered a Bus Off state.
327//
328#define CAN_STATUS_BUS_OFF 0x00000080
329
330//
331//! CAN controller error level has reached warning level.
332//
333#define CAN_STATUS_EWARN 0x00000040
334
335//
336//! CAN controller error level has reached error passive level.
337//
338#define CAN_STATUS_EPASS 0x00000020
339
340//
341//! A message was received successfully since the last read of this status.
342//
343#define CAN_STATUS_RXOK 0x00000010
344
345//
346//! A message was transmitted successfully since the last read of this
347//! status.
348//
349#define CAN_STATUS_TXOK 0x00000008
350
351//
352//! This is the mask for the last error code field.
353//
354#define CAN_STATUS_LEC_MSK 0x00000007
355
356//
357//! There was no error.
358//
359#define CAN_STATUS_LEC_NONE 0x00000000
360
361//
362//! A bit stuffing error has occurred.
363//
364#define CAN_STATUS_LEC_STUFF 0x00000001
365
366//
367//! A formatting error has occurred.
368//
369#define CAN_STATUS_LEC_FORM 0x00000002
370
371//
372//! An acknowledge error has occurred.
373//
374#define CAN_STATUS_LEC_ACK 0x00000003
375
376//
377//! The bus remained a bit level of 1 for longer than is allowed.
378//
379#define CAN_STATUS_LEC_BIT1 0x00000004
380
381//
382//! The bus remained a bit level of 0 for longer than is allowed.
383//
384#define CAN_STATUS_LEC_BIT0 0x00000005
385
386//
387//! A CRC error has occurred.
388//
389#define CAN_STATUS_LEC_CRC 0x00000006
390
391//
392//! This is the mask for the CAN Last Error Code (LEC).
393//
394#define CAN_STATUS_LEC_MASK 0x00000007
395
396//*****************************************************************************
397//
398// Close the Doxygen group.
399//! @}
400//
401//*****************************************************************************
402
403//*****************************************************************************
404//
405// API Function prototypes
406//
407//*****************************************************************************
408extern void CANBitTimingGet(uint32_t ui32Base, tCANBitClkParms* psClkParms);
409extern void CANBitTimingSet(uint32_t ui32Base, tCANBitClkParms* psClkParms);
410extern uint32_t CANBitRateSet(uint32_t ui32Base, uint32_t ui32SourceClock,
411                              uint32_t ui32BitRate);
412extern void CANDisable(uint32_t ui32Base);
413extern void CANEnable(uint32_t ui32Base);
414extern bool CANErrCntrGet(uint32_t ui32Base, uint32_t* pui32RxCount,
415                          uint32_t* pui32TxCount);
416extern void CANInit(uint32_t ui32Base);
417extern void CANIntClear(uint32_t ui32Base, uint32_t ui32IntClr);
418extern void CANIntDisable(uint32_t ui32Base, uint32_t ui32IntFlags);
419extern void CANIntEnable(uint32_t ui32Base, uint32_t ui32IntFlags);
420extern void CANIntRegister(uint32_t ui32Base, void (*pfnHandler)(void));
421extern uint32_t CANIntStatus(uint32_t ui32Base, tCANIntStsReg eIntStsReg);
422extern void CANIntUnregister(uint32_t ui32Base);
423extern void CANMessageClear(uint32_t ui32Base, uint32_t ui32ObjID);
424extern void CANMessageGet(uint32_t ui32Base, uint32_t ui32ObjID,
425                          tCANMsgObject* psMsgObject, bool bClrPendingInt);
426extern void CANMessageSet(uint32_t ui32Base, uint32_t ui32ObjID,
427                          tCANMsgObject* psMsgObject, tMsgObjType eMsgType);
428extern bool CANRetryGet(uint32_t ui32Base);
429extern void CANRetrySet(uint32_t ui32Base, bool bAutoRetry);
430extern uint32_t CANStatusGet(uint32_t ui32Base, tCANStsReg eStatusReg);
431
432//*****************************************************************************
433//
434// Mark the end of the C bindings section for C++ compilers.
435//
436//*****************************************************************************
437#ifdef __cplusplus
438}
439#endif
440
441#endif // __DRIVERLIB_CAN_H__