can.h 13.9 KB
Newer Older
qiuyiuestc's avatar
qiuyiuestc 已提交
1 2 3 4
//*****************************************************************************
//
// can.h - Defines and Macros for the CAN controller.
//
qiuyiuestc's avatar
qiuyiuestc 已提交
5
// Copyright (c) 2006-2010 Texas Instruments Incorporated.  All rights reserved.
qiuyiuestc's avatar
qiuyiuestc 已提交
6 7
// Software License Agreement
// 
qiuyiuestc's avatar
qiuyiuestc 已提交
8 9 10 11 12
// Texas Instruments (TI) is supplying this software for use solely and
// exclusively on TI's microcontroller products. The software is owned by
// TI and/or its suppliers, and is protected under applicable copyright
// laws. You may not combine this software with "viral" open-source
// software in order to form a larger program.
qiuyiuestc's avatar
qiuyiuestc 已提交
13
// 
qiuyiuestc's avatar
qiuyiuestc 已提交
14 15 16 17 18 19
// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
// DAMAGES, FOR ANY REASON WHATSOEVER.
qiuyiuestc's avatar
qiuyiuestc 已提交
20
// 
qiuyiuestc's avatar
qiuyiuestc 已提交
21
// This is part of revision 6459 of the Stellaris Peripheral Driver Library.
qiuyiuestc's avatar
qiuyiuestc 已提交
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
//
//*****************************************************************************

#ifndef __CAN_H__
#define __CAN_H__

//*****************************************************************************
//
//! \addtogroup can_api
//! @{
//
//*****************************************************************************

//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif

//*****************************************************************************
//
// Miscellaneous defines for Message ID Types
//
//*****************************************************************************

//*****************************************************************************
//
qiuyiuestc's avatar
qiuyiuestc 已提交
54 55
// These are the flags used by the tCANMsgObject.ulFlags value when calling the
// CANMessageSet() and CANMessageGet() functions.
qiuyiuestc's avatar
qiuyiuestc 已提交
56 57 58
//
//*****************************************************************************

qiuyiuestc's avatar
qiuyiuestc 已提交
59 60 61 62 63
//
//! This definition is used with the tCANMsgObject ulFlags value and indicates
//! that transmit interrupts should be enabled, or are enabled.
//
#define MSG_OBJ_TX_INT_ENABLE   0x00000001
qiuyiuestc's avatar
qiuyiuestc 已提交
64

qiuyiuestc's avatar
qiuyiuestc 已提交
65 66 67 68 69
//
//! This indicates that receive interrupts should be enabled, or are
//! enabled.
//
#define MSG_OBJ_RX_INT_ENABLE   0x00000002
qiuyiuestc's avatar
qiuyiuestc 已提交
70

qiuyiuestc's avatar
qiuyiuestc 已提交
71 72 73 74 75
//
//! This indicates that a message object will use or is using an extended
//! identifier.
//
#define MSG_OBJ_EXTENDED_ID     0x00000004
qiuyiuestc's avatar
qiuyiuestc 已提交
76

qiuyiuestc's avatar
qiuyiuestc 已提交
77 78 79 80 81
//
//! This indicates that a message object will use or is using filtering
//! based on the object's message identifier.
//
#define MSG_OBJ_USE_ID_FILTER   0x00000008
qiuyiuestc's avatar
qiuyiuestc 已提交
82

qiuyiuestc's avatar
qiuyiuestc 已提交
83 84 85 86
//
//! This indicates that new data was available in the message object.
//
#define MSG_OBJ_NEW_DATA        0x00000080
qiuyiuestc's avatar
qiuyiuestc 已提交
87

qiuyiuestc's avatar
qiuyiuestc 已提交
88 89 90 91 92
//
//! This indicates that data was lost since this message object was last
//! read.
//
#define MSG_OBJ_DATA_LOST       0x00000100
qiuyiuestc's avatar
qiuyiuestc 已提交
93

qiuyiuestc's avatar
qiuyiuestc 已提交
94 95 96 97 98 99
//
//! This indicates that a message object will use or is using filtering
//! based on the direction of the transfer.  If the direction filtering is
//! used, then ID filtering must also be enabled.
//
#define MSG_OBJ_USE_DIR_FILTER  (0x00000010 | MSG_OBJ_USE_ID_FILTER)
qiuyiuestc's avatar
qiuyiuestc 已提交
100

qiuyiuestc's avatar
qiuyiuestc 已提交
101 102 103 104 105 106
//
//! This indicates that a message object will use or is using message
//! identifier filtering based on the extended identifier.  If the extended
//! identifier filtering is used, then ID filtering must also be enabled.
//
#define MSG_OBJ_USE_EXT_FILTER  (0x00000020 | MSG_OBJ_USE_ID_FILTER)
qiuyiuestc's avatar
qiuyiuestc 已提交
107

qiuyiuestc's avatar
qiuyiuestc 已提交
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
//
//! This indicates that a message object is a remote frame.
//
#define MSG_OBJ_REMOTE_FRAME    0x00000040

//
//! This indicates that this message object is part of a FIFO structure and
//! not the final message object in a FIFO.
//
#define MSG_OBJ_FIFO            0x00000200

//
//! This indicates that a message object has no flags set.
//
#define MSG_OBJ_NO_FLAGS        0x00000000
qiuyiuestc's avatar
qiuyiuestc 已提交
123 124 125

//*****************************************************************************
//
qiuyiuestc's avatar
qiuyiuestc 已提交
126 127
//! This define is used with the flag values to allow checking only status
//! flags and not configuration flags.
qiuyiuestc's avatar
qiuyiuestc 已提交
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
//
//*****************************************************************************
#define MSG_OBJ_STATUS_MASK     (MSG_OBJ_NEW_DATA | MSG_OBJ_DATA_LOST)

//*****************************************************************************
//
//! The structure used for encapsulating all the items associated with a CAN
//! message object in the CAN controller.
//
//*****************************************************************************
typedef struct
{
    //
    //! The CAN message identifier used for 11 or 29 bit identifiers.
    //
    unsigned long ulMsgID;

    //
    //! The message identifier mask used when identifier filtering is enabled.
    //
    unsigned long ulMsgIDMask;

    //
    //! This value holds various status flags and settings specified by
    //! tCANObjFlags.
    //
    unsigned long ulFlags;

    //
    //! This value is the number of bytes of data in the message object.
    //
    unsigned long ulMsgLen;

    //
    //! This is a pointer to the message object's data.
    //
    unsigned char *pucMsgData;
}
tCANMsgObject;

//*****************************************************************************
//
//! This structure is used for encapsulating the values associated with setting
//! up the bit timing for a CAN controller.  The structure is used when calling
//! the CANGetBitTiming and CANSetBitTiming functions.
//
//*****************************************************************************
typedef struct
{
    //
    //! This value holds the sum of the Synchronization, Propagation, and Phase
    //! Buffer 1 segments, measured in time quanta.  The valid values for this
    //! setting range from 2 to 16.
    //
    unsigned int uSyncPropPhase1Seg;

    //
    //! This value holds the Phase Buffer 2 segment in time quanta.  The valid
    //! values for this setting range from 1 to 8.
    //
    unsigned int uPhase2Seg;

    //
    //! This value holds the Resynchronization Jump Width in time quanta.  The
    //! valid values for this setting range from 1 to 4.
    //
    unsigned int uSJW;

    //
    //! This value holds the CAN_CLK divider used to determine time quanta.
    //! The valid values for this setting range from 1 to 1023.
    //
    unsigned int uQuantumPrescaler;
}
tCANBitClkParms;

//*****************************************************************************
//
//! This data type is used to identify the interrupt status register.  This is
//! used when calling the CANIntStatus() function.
//
//*****************************************************************************
typedef enum
{
    //
    //! Read the CAN interrupt status information.
    //
    CAN_INT_STS_CAUSE,

    //
    //! Read a message object's interrupt status.
    //
    CAN_INT_STS_OBJECT
}
tCANIntStsReg;

//*****************************************************************************
//
//! This data type is used to identify which of several status registers to
//! read when calling the CANStatusGet() function.
//
//*****************************************************************************
typedef enum
{
    //
    //! Read the full CAN controller status.
    //
    CAN_STS_CONTROL,

    //
    //! Read the full 32-bit mask of message objects with a transmit request
    //! set.
    //
    CAN_STS_TXREQUEST,

    //
    //! Read the full 32-bit mask of message objects with new data available.
    //
    CAN_STS_NEWDAT,

    //
    //! Read the full 32-bit mask of message objects that are enabled.
    //
    CAN_STS_MSGVAL
}
tCANStsReg;

//*****************************************************************************
//
qiuyiuestc's avatar
qiuyiuestc 已提交
257 258
// These definitions are used to specify interrupt sources to CANIntEnable()
// and CANIntDisable().
qiuyiuestc's avatar
qiuyiuestc 已提交
259 260
//
//*****************************************************************************
qiuyiuestc's avatar
qiuyiuestc 已提交
261 262 263 264 265
//
//! This flag is used to allow a CAN controller to generate error
//! interrupts.
//
#define CAN_INT_ERROR           0x00000008
qiuyiuestc's avatar
qiuyiuestc 已提交
266

qiuyiuestc's avatar
qiuyiuestc 已提交
267 268 269 270 271
//
//! This flag is used to allow a CAN controller to generate status
//! interrupts.
//
#define CAN_INT_STATUS          0x00000004
qiuyiuestc's avatar
qiuyiuestc 已提交
272

qiuyiuestc's avatar
qiuyiuestc 已提交
273 274 275 276 277 278
//
//! This flag is used to allow a CAN controller to generate any CAN
//! interrupts.  If this is not set, then no interrupts will be generated
//! by the CAN controller.
//
#define CAN_INT_MASTER          0x00000002
qiuyiuestc's avatar
qiuyiuestc 已提交
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316

//*****************************************************************************
//
//! This definition is used to determine the type of message object that will
//! be set up via a call to the CANMessageSet() API.
//
//*****************************************************************************
typedef enum
{
    //
    //! Transmit message object.
    //
    MSG_OBJ_TYPE_TX,

    //
    //! Transmit remote request message object
    //
    MSG_OBJ_TYPE_TX_REMOTE,

    //
    //! Receive message object.
    //
    MSG_OBJ_TYPE_RX,

    //
    //! Receive remote request message object.
    //
    MSG_OBJ_TYPE_RX_REMOTE,

    //
    //! Remote frame receive remote, with auto-transmit message object.
    //
    MSG_OBJ_TYPE_RXTX_REMOTE
}
tMsgObjType;

//*****************************************************************************
//
qiuyiuestc's avatar
qiuyiuestc 已提交
317 318
// The following enumeration contains all error or status indicators that can
// be returned when calling the CANStatusGet() function.
qiuyiuestc's avatar
qiuyiuestc 已提交
319 320
//
//*****************************************************************************
qiuyiuestc's avatar
qiuyiuestc 已提交
321 322 323 324
//
//! CAN controller has entered a Bus Off state.
//
#define CAN_STATUS_BUS_OFF      0x00000080
qiuyiuestc's avatar
qiuyiuestc 已提交
325

qiuyiuestc's avatar
qiuyiuestc 已提交
326 327 328 329
//
//! CAN controller error level has reached warning level.
//
#define CAN_STATUS_EWARN        0x00000040
qiuyiuestc's avatar
qiuyiuestc 已提交
330

qiuyiuestc's avatar
qiuyiuestc 已提交
331 332 333 334
//
//! CAN controller error level has reached error passive level.
//
#define CAN_STATUS_EPASS        0x00000020
qiuyiuestc's avatar
qiuyiuestc 已提交
335

qiuyiuestc's avatar
qiuyiuestc 已提交
336 337 338 339
//
//! A message was received successfully since the last read of this status.
//
#define CAN_STATUS_RXOK         0x00000010
qiuyiuestc's avatar
qiuyiuestc 已提交
340

qiuyiuestc's avatar
qiuyiuestc 已提交
341 342 343 344 345
//
//! A message was transmitted successfully since the last read of this
//! status.
//
#define CAN_STATUS_TXOK         0x00000008
qiuyiuestc's avatar
qiuyiuestc 已提交
346

qiuyiuestc's avatar
qiuyiuestc 已提交
347 348 349 350
//
//! This is the mask for the last error code field.
//
#define CAN_STATUS_LEC_MSK      0x00000007
qiuyiuestc's avatar
qiuyiuestc 已提交
351

qiuyiuestc's avatar
qiuyiuestc 已提交
352 353 354 355
//
//! There was no error.
//
#define CAN_STATUS_LEC_NONE     0x00000000
qiuyiuestc's avatar
qiuyiuestc 已提交
356

qiuyiuestc's avatar
qiuyiuestc 已提交
357 358 359 360
//
//! A bit stuffing error has occurred.
//
#define CAN_STATUS_LEC_STUFF    0x00000001
qiuyiuestc's avatar
qiuyiuestc 已提交
361

qiuyiuestc's avatar
qiuyiuestc 已提交
362 363 364 365
//
//! A formatting error has occurred.
//
#define CAN_STATUS_LEC_FORM     0x00000002
qiuyiuestc's avatar
qiuyiuestc 已提交
366

qiuyiuestc's avatar
qiuyiuestc 已提交
367 368 369 370
//
//! An acknowledge error has occurred.
//
#define CAN_STATUS_LEC_ACK      0x00000003
qiuyiuestc's avatar
qiuyiuestc 已提交
371

qiuyiuestc's avatar
qiuyiuestc 已提交
372 373 374 375
//
//! The bus remained a bit level of 1 for longer than is allowed.
//
#define CAN_STATUS_LEC_BIT1     0x00000004
qiuyiuestc's avatar
qiuyiuestc 已提交
376

qiuyiuestc's avatar
qiuyiuestc 已提交
377 378 379 380
//
//! The bus remained a bit level of 0 for longer than is allowed.
//
#define CAN_STATUS_LEC_BIT0     0x00000005
qiuyiuestc's avatar
qiuyiuestc 已提交
381

qiuyiuestc's avatar
qiuyiuestc 已提交
382 383 384 385
//
//! A CRC error has occurred.
//
#define CAN_STATUS_LEC_CRC      0x00000006
qiuyiuestc's avatar
qiuyiuestc 已提交
386

qiuyiuestc's avatar
qiuyiuestc 已提交
387 388 389 390
//
//! This is the mask for the CAN Last Error Code (LEC).
//
#define CAN_STATUS_LEC_MASK     0x00000007
qiuyiuestc's avatar
qiuyiuestc 已提交
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450

//*****************************************************************************
//
// API Function prototypes
//
//*****************************************************************************
extern void CANBitTimingGet(unsigned long ulBase, tCANBitClkParms *pClkParms);
extern void CANBitTimingSet(unsigned long ulBase, tCANBitClkParms *pClkParms);
extern unsigned long CANBitRateSet(unsigned long ulBase,
                                   unsigned long ulSourceClock,
                                   unsigned long ulBitRate);
extern void CANDisable(unsigned long ulBase);
extern void CANEnable(unsigned long ulBase);
extern tBoolean CANErrCntrGet(unsigned long ulBase, unsigned long *pulRxCount,
                              unsigned long *pulTxCount);
extern void CANInit(unsigned long ulBase);
extern void CANIntClear(unsigned long ulBase, unsigned long ulIntClr);
extern void CANIntDisable(unsigned long ulBase, unsigned long ulIntFlags);
extern void CANIntEnable(unsigned long ulBase, unsigned long ulIntFlags);
extern void CANIntRegister(unsigned long ulBase, void (*pfnHandler)(void));
extern unsigned long CANIntStatus(unsigned long ulBase,
                                  tCANIntStsReg eIntStsReg);
extern void CANIntUnregister(unsigned long ulBase);
extern void CANMessageClear(unsigned long ulBase, unsigned long ulObjID);
extern void CANMessageGet(unsigned long ulBase, unsigned long ulObjID,
                          tCANMsgObject *pMsgObject, tBoolean bClrPendingInt);
extern void CANMessageSet(unsigned long ulBase, unsigned long ulObjID,
                          tCANMsgObject *pMsgObject, tMsgObjType eMsgType);
extern tBoolean CANRetryGet(unsigned long ulBase);
extern void CANRetrySet(unsigned long ulBase, tBoolean bAutoRetry);
extern unsigned long CANStatusGet(unsigned long ulBase, tCANStsReg eStatusReg);

//*****************************************************************************
//
// Several CAN APIs have been renamed, with the original function name being
// deprecated.  These defines provide backward compatibility.
//
//*****************************************************************************
#ifndef DEPRECATED
#define CANSetBitTiming(a, b)   CANBitTimingSet(a, b)
#define CANGetBitTiming(a, b)   CANBitTimingGet(a, b)
#endif

//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif

//*****************************************************************************
//
// Close the Doxygen group.
//! @}
//
//*****************************************************************************

#endif //  __CAN_H__