1 //***************************************************************************** 2 // 3 // can.h - Defines and Macros for the CAN controller. 4 // 5 // Copyright (c) 2006-2012 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 9453 of the Stellaris Peripheral Driver Library. 37 // 38 //***************************************************************************** 39 40 #ifndef __CAN_H__ 41 #define __CAN_H__ 42 43 //***************************************************************************** 44 // 45 //! \addtogroup can_api 46 //! @{ 47 // 48 //***************************************************************************** 49 50 //***************************************************************************** 51 // 52 // If building with a C++ compiler, make all of the definitions in this header 53 // have a C binding. 54 // 55 //***************************************************************************** 56 #ifdef __cplusplus 57 extern "C" 58 { 59 #endif 60 61 //***************************************************************************** 62 // 63 // Miscellaneous defines for Message ID Types 64 // 65 //***************************************************************************** 66 67 //***************************************************************************** 68 // 69 // These are the flags used by the tCANMsgObject.ulFlags value when calling the 70 // CANMessageSet() and CANMessageGet() functions. 71 // 72 //***************************************************************************** 73 74 // 75 //! This definition is used with the tCANMsgObject ulFlags value and indicates 76 //! that transmit interrupts should be enabled, or are enabled. 77 // 78 #define MSG_OBJ_TX_INT_ENABLE 0x00000001 79 80 // 81 //! This indicates that receive interrupts should be enabled, or are 82 //! enabled. 83 // 84 #define MSG_OBJ_RX_INT_ENABLE 0x00000002 85 86 // 87 //! This indicates that a message object will use or is using an extended 88 //! identifier. 89 // 90 #define MSG_OBJ_EXTENDED_ID 0x00000004 91 92 // 93 //! This indicates that a message object will use or is using filtering 94 //! based on the object's message identifier. 95 // 96 #define MSG_OBJ_USE_ID_FILTER 0x00000008 97 98 // 99 //! This indicates that new data was available in the message object. 100 // 101 #define MSG_OBJ_NEW_DATA 0x00000080 102 103 // 104 //! This indicates that data was lost since this message object was last 105 //! read. 106 // 107 #define MSG_OBJ_DATA_LOST 0x00000100 108 109 // 110 //! This indicates that a message object will use or is using filtering 111 //! based on the direction of the transfer. If the direction filtering is 112 //! used, then ID filtering must also be enabled. 113 // 114 #define MSG_OBJ_USE_DIR_FILTER (0x00000010 | MSG_OBJ_USE_ID_FILTER) 115 116 // 117 //! This indicates that a message object will use or is using message 118 //! identifier filtering based on the extended identifier. If the extended 119 //! identifier filtering is used, then ID filtering must also be enabled. 120 // 121 #define MSG_OBJ_USE_EXT_FILTER (0x00000020 | MSG_OBJ_USE_ID_FILTER) 122 123 // 124 //! This indicates that a message object is a remote frame. 125 // 126 #define MSG_OBJ_REMOTE_FRAME 0x00000040 127 128 // 129 //! This indicates that this message object is part of a FIFO structure and 130 //! not the final message object in a FIFO. 131 // 132 #define MSG_OBJ_FIFO 0x00000200 133 134 // 135 //! This indicates that a message object has no flags set. 136 // 137 #define MSG_OBJ_NO_FLAGS 0x00000000 138 139 //***************************************************************************** 140 // 141 //! This define is used with the flag values to allow checking only status 142 //! flags and not configuration flags. 143 // 144 //***************************************************************************** 145 #define MSG_OBJ_STATUS_MASK (MSG_OBJ_NEW_DATA | MSG_OBJ_DATA_LOST) 146 147 //***************************************************************************** 148 // 149 //! The structure used for encapsulating all the items associated with a CAN 150 //! message object in the CAN controller. 151 // 152 //***************************************************************************** 153 typedef struct 154 { 155 // 156 //! The CAN message identifier used for 11 or 29 bit identifiers. 157 // 158 unsigned long ulMsgID; 159 160 // 161 //! The message identifier mask used when identifier filtering is enabled. 162 // 163 unsigned long ulMsgIDMask; 164 165 // 166 //! This value holds various status flags and settings specified by 167 //! tCANObjFlags. 168 // 169 unsigned long ulFlags; 170 171 // 172 //! This value is the number of bytes of data in the message object. 173 // 174 unsigned long ulMsgLen; 175 176 // 177 //! This is a pointer to the message object's data. 178 // 179 unsigned char *pucMsgData; 180 } 181 tCANMsgObject; 182 183 //***************************************************************************** 184 // 185 //! This structure is used for encapsulating the values associated with setting 186 //! up the bit timing for a CAN controller. The structure is used when calling 187 //! the CANGetBitTiming and CANSetBitTiming functions. 188 // 189 //***************************************************************************** 190 typedef struct 191 { 192 // 193 //! This value holds the sum of the Synchronization, Propagation, and Phase 194 //! Buffer 1 segments, measured in time quanta. The valid values for this 195 //! setting range from 2 to 16. 196 // 197 unsigned long ulSyncPropPhase1Seg; 198 199 // 200 //! This value holds the Phase Buffer 2 segment in time quanta. The valid 201 //! values for this setting range from 1 to 8. 202 // 203 unsigned long ulPhase2Seg; 204 205 // 206 //! This value holds the Resynchronization Jump Width in time quanta. The 207 //! valid values for this setting range from 1 to 4. 208 // 209 unsigned long ulSJW; 210 211 // 212 //! This value holds the CAN_CLK divider used to determine time quanta. 213 //! The valid values for this setting range from 1 to 1023. 214 // 215 unsigned long ulQuantumPrescaler; 216 } 217 tCANBitClkParms; 218 219 //***************************************************************************** 220 // 221 //! This data type is used to identify the interrupt status register. This is 222 //! used when calling the CANIntStatus() function. 223 // 224 //***************************************************************************** 225 typedef enum 226 { 227 // 228 //! Read the CAN interrupt status information. 229 // 230 CAN_INT_STS_CAUSE, 231 232 // 233 //! Read a message object's interrupt status. 234 // 235 CAN_INT_STS_OBJECT 236 } 237 tCANIntStsReg; 238 239 //***************************************************************************** 240 // 241 //! This data type is used to identify which of several status registers to 242 //! read when calling the CANStatusGet() function. 243 // 244 //***************************************************************************** 245 typedef enum 246 { 247 // 248 //! Read the full CAN controller status. 249 // 250 CAN_STS_CONTROL, 251 252 // 253 //! Read the full 32-bit mask of message objects with a transmit request 254 //! set. 255 // 256 CAN_STS_TXREQUEST, 257 258 // 259 //! Read the full 32-bit mask of message objects with new data available. 260 // 261 CAN_STS_NEWDAT, 262 263 // 264 //! Read the full 32-bit mask of message objects that are enabled. 265 // 266 CAN_STS_MSGVAL 267 } 268 tCANStsReg; 269 270 //***************************************************************************** 271 // 272 // These definitions are used to specify interrupt sources to CANIntEnable() 273 // and CANIntDisable(). 274 // 275 //***************************************************************************** 276 // 277 //! This flag is used to allow a CAN controller to generate error 278 //! interrupts. 279 // 280 #define CAN_INT_ERROR 0x00000008 281 282 // 283 //! This flag is used to allow a CAN controller to generate status 284 //! interrupts. 285 // 286 #define CAN_INT_STATUS 0x00000004 287 288 // 289 //! This flag is used to allow a CAN controller to generate any CAN 290 //! interrupts. If this is not set, then no interrupts will be generated 291 //! by the CAN controller. 292 // 293 #define CAN_INT_MASTER 0x00000002 294 295 //***************************************************************************** 296 // 297 //! This definition is used to determine the type of message object that will 298 //! be set up via a call to the CANMessageSet() API. 299 // 300 //***************************************************************************** 301 typedef enum 302 { 303 // 304 //! Transmit message object. 305 // 306 MSG_OBJ_TYPE_TX, 307 308 // 309 //! Transmit remote request message object 310 // 311 MSG_OBJ_TYPE_TX_REMOTE, 312 313 // 314 //! Receive message object. 315 // 316 MSG_OBJ_TYPE_RX, 317 318 // 319 //! Receive remote request message object. 320 // 321 MSG_OBJ_TYPE_RX_REMOTE, 322 323 // 324 //! Remote frame receive remote, with auto-transmit message object. 325 // 326 MSG_OBJ_TYPE_RXTX_REMOTE 327 } 328 tMsgObjType; 329 330 //***************************************************************************** 331 // 332 // The following enumeration contains all error or status indicators that can 333 // be returned when calling the CANStatusGet() function. 334 // 335 //***************************************************************************** 336 // 337 //! CAN controller has entered a Bus Off state. 338 // 339 #define CAN_STATUS_BUS_OFF 0x00000080 340 341 // 342 //! CAN controller error level has reached warning level. 343 // 344 #define CAN_STATUS_EWARN 0x00000040 345 346 // 347 //! CAN controller error level has reached error passive level. 348 // 349 #define CAN_STATUS_EPASS 0x00000020 350 351 // 352 //! A message was received successfully since the last read of this status. 353 // 354 #define CAN_STATUS_RXOK 0x00000010 355 356 // 357 //! A message was transmitted successfully since the last read of this 358 //! status. 359 // 360 #define CAN_STATUS_TXOK 0x00000008 361 362 // 363 //! This is the mask for the last error code field. 364 // 365 #define CAN_STATUS_LEC_MSK 0x00000007 366 367 // 368 //! There was no error. 369 // 370 #define CAN_STATUS_LEC_NONE 0x00000000 371 372 // 373 //! A bit stuffing error has occurred. 374 // 375 #define CAN_STATUS_LEC_STUFF 0x00000001 376 377 // 378 //! A formatting error has occurred. 379 // 380 #define CAN_STATUS_LEC_FORM 0x00000002 381 382 // 383 //! An acknowledge error has occurred. 384 // 385 #define CAN_STATUS_LEC_ACK 0x00000003 386 387 // 388 //! The bus remained a bit level of 1 for longer than is allowed. 389 // 390 #define CAN_STATUS_LEC_BIT1 0x00000004 391 392 // 393 //! The bus remained a bit level of 0 for longer than is allowed. 394 // 395 #define CAN_STATUS_LEC_BIT0 0x00000005 396 397 // 398 //! A CRC error has occurred. 399 // 400 #define CAN_STATUS_LEC_CRC 0x00000006 401 402 // 403 //! This is the mask for the CAN Last Error Code (LEC). 404 // 405 #define CAN_STATUS_LEC_MASK 0x00000007 406 407 //***************************************************************************** 408 // 409 // API Function prototypes 410 // 411 //***************************************************************************** 412 extern void CANBitTimingGet(unsigned long ulBase, tCANBitClkParms *pClkParms); 413 extern void CANBitTimingSet(unsigned long ulBase, tCANBitClkParms *pClkParms); 414 extern unsigned long CANBitRateSet(unsigned long ulBase, 415 unsigned long ulSourceClock, 416 unsigned long ulBitRate); 417 extern void CANDisable(unsigned long ulBase); 418 extern void CANEnable(unsigned long ulBase); 419 extern tBoolean CANErrCntrGet(unsigned long ulBase, unsigned long *pulRxCount, 420 unsigned long *pulTxCount); 421 extern void CANInit(unsigned long ulBase); 422 extern void CANIntClear(unsigned long ulBase, unsigned long ulIntClr); 423 extern void CANIntDisable(unsigned long ulBase, unsigned long ulIntFlags); 424 extern void CANIntEnable(unsigned long ulBase, unsigned long ulIntFlags); 425 extern void CANIntRegister(unsigned long ulBase, void (*pfnHandler)(void)); 426 extern unsigned long CANIntStatus(unsigned long ulBase, 427 tCANIntStsReg eIntStsReg); 428 extern void CANIntUnregister(unsigned long ulBase); 429 extern void CANMessageClear(unsigned long ulBase, unsigned long ulObjID); 430 extern void CANMessageGet(unsigned long ulBase, unsigned long ulObjID, 431 tCANMsgObject *pMsgObject, tBoolean bClrPendingInt); 432 extern void CANMessageSet(unsigned long ulBase, unsigned long ulObjID, 433 tCANMsgObject *pMsgObject, tMsgObjType eMsgType); 434 extern tBoolean CANRetryGet(unsigned long ulBase); 435 extern void CANRetrySet(unsigned long ulBase, tBoolean bAutoRetry); 436 extern unsigned long CANStatusGet(unsigned long ulBase, tCANStsReg eStatusReg); 437 438 //***************************************************************************** 439 // 440 // Several CAN APIs have been renamed, with the original function name being 441 // deprecated. These defines provide backward compatibility. 442 // 443 //***************************************************************************** 444 #ifndef DEPRECATED 445 #define CANSetBitTiming(a, b) CANBitTimingSet(a, b) 446 #define CANGetBitTiming(a, b) CANBitTimingGet(a, b) 447 #endif 448 449 //***************************************************************************** 450 // 451 // Mark the end of the C bindings section for C++ compilers. 452 // 453 //***************************************************************************** 454 #ifdef __cplusplus 455 } 456 #endif 457 458 //***************************************************************************** 459 // 460 // Close the Doxygen group. 461 //! @} 462 // 463 //***************************************************************************** 464 465 #endif // __CAN_H__ 466