can.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. //*****************************************************************************
  2. //
  3. // can.h - Defines and Macros for the CAN controller.
  4. //
  5. // Copyright (c) 2006-2011 Texas Instruments Incorporated. All rights reserved.
  6. // Software License Agreement
  7. //
  8. // Texas Instruments (TI) is supplying this software for use solely and
  9. // exclusively on TI's microcontroller products. The software is owned by
  10. // TI and/or its suppliers, and is protected under applicable copyright
  11. // laws. You may not combine this software with "viral" open-source
  12. // software in order to form a larger program.
  13. //
  14. // THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
  15. // NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
  16. // NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  17. // A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
  18. // CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
  19. // DAMAGES, FOR ANY REASON WHATSOEVER.
  20. //
  21. // This is part of revision 8264 of the Stellaris Peripheral Driver Library.
  22. //
  23. //*****************************************************************************
  24. #ifndef __CAN_H__
  25. #define __CAN_H__
  26. //*****************************************************************************
  27. //
  28. //! \addtogroup can_api
  29. //! @{
  30. //
  31. //*****************************************************************************
  32. //*****************************************************************************
  33. //
  34. // If building with a C++ compiler, make all of the definitions in this header
  35. // have a C binding.
  36. //
  37. //*****************************************************************************
  38. #ifdef __cplusplus
  39. extern "C"
  40. {
  41. #endif
  42. //*****************************************************************************
  43. //
  44. // Miscellaneous defines for Message ID Types
  45. //
  46. //*****************************************************************************
  47. //*****************************************************************************
  48. //
  49. // These are the flags used by the tCANMsgObject.ulFlags value when calling the
  50. // CANMessageSet() and CANMessageGet() functions.
  51. //
  52. //*****************************************************************************
  53. //
  54. //! This definition is used with the tCANMsgObject ulFlags value and indicates
  55. //! that transmit interrupts should be enabled, or are enabled.
  56. //
  57. #define MSG_OBJ_TX_INT_ENABLE 0x00000001
  58. //
  59. //! This indicates that receive interrupts should be enabled, or are
  60. //! enabled.
  61. //
  62. #define MSG_OBJ_RX_INT_ENABLE 0x00000002
  63. //
  64. //! This indicates that a message object will use or is using an extended
  65. //! identifier.
  66. //
  67. #define MSG_OBJ_EXTENDED_ID 0x00000004
  68. //
  69. //! This indicates that a message object will use or is using filtering
  70. //! based on the object's message identifier.
  71. //
  72. #define MSG_OBJ_USE_ID_FILTER 0x00000008
  73. //
  74. //! This indicates that new data was available in the message object.
  75. //
  76. #define MSG_OBJ_NEW_DATA 0x00000080
  77. //
  78. //! This indicates that data was lost since this message object was last
  79. //! read.
  80. //
  81. #define MSG_OBJ_DATA_LOST 0x00000100
  82. //
  83. //! This indicates that a message object will use or is using filtering
  84. //! based on the direction of the transfer. If the direction filtering is
  85. //! used, then ID filtering must also be enabled.
  86. //
  87. #define MSG_OBJ_USE_DIR_FILTER (0x00000010 | MSG_OBJ_USE_ID_FILTER)
  88. //
  89. //! This indicates that a message object will use or is using message
  90. //! identifier filtering based on the extended identifier. If the extended
  91. //! identifier filtering is used, then ID filtering must also be enabled.
  92. //
  93. #define MSG_OBJ_USE_EXT_FILTER (0x00000020 | MSG_OBJ_USE_ID_FILTER)
  94. //
  95. //! This indicates that a message object is a remote frame.
  96. //
  97. #define MSG_OBJ_REMOTE_FRAME 0x00000040
  98. //
  99. //! This indicates that this message object is part of a FIFO structure and
  100. //! not the final message object in a FIFO.
  101. //
  102. #define MSG_OBJ_FIFO 0x00000200
  103. //
  104. //! This indicates that a message object has no flags set.
  105. //
  106. #define MSG_OBJ_NO_FLAGS 0x00000000
  107. //*****************************************************************************
  108. //
  109. //! This define is used with the flag values to allow checking only status
  110. //! flags and not configuration flags.
  111. //
  112. //*****************************************************************************
  113. #define MSG_OBJ_STATUS_MASK (MSG_OBJ_NEW_DATA | MSG_OBJ_DATA_LOST)
  114. //*****************************************************************************
  115. //
  116. //! The structure used for encapsulating all the items associated with a CAN
  117. //! message object in the CAN controller.
  118. //
  119. //*****************************************************************************
  120. typedef struct
  121. {
  122. //
  123. //! The CAN message identifier used for 11 or 29 bit identifiers.
  124. //
  125. unsigned long ulMsgID;
  126. //
  127. //! The message identifier mask used when identifier filtering is enabled.
  128. //
  129. unsigned long ulMsgIDMask;
  130. //
  131. //! This value holds various status flags and settings specified by
  132. //! tCANObjFlags.
  133. //
  134. unsigned long ulFlags;
  135. //
  136. //! This value is the number of bytes of data in the message object.
  137. //
  138. unsigned long ulMsgLen;
  139. //
  140. //! This is a pointer to the message object's data.
  141. //
  142. unsigned char *pucMsgData;
  143. }
  144. tCANMsgObject;
  145. //*****************************************************************************
  146. //
  147. //! This structure is used for encapsulating the values associated with setting
  148. //! up the bit timing for a CAN controller. The structure is used when calling
  149. //! the CANGetBitTiming and CANSetBitTiming functions.
  150. //
  151. //*****************************************************************************
  152. typedef struct
  153. {
  154. //
  155. //! This value holds the sum of the Synchronization, Propagation, and Phase
  156. //! Buffer 1 segments, measured in time quanta. The valid values for this
  157. //! setting range from 2 to 16.
  158. //
  159. unsigned long ulSyncPropPhase1Seg;
  160. //
  161. //! This value holds the Phase Buffer 2 segment in time quanta. The valid
  162. //! values for this setting range from 1 to 8.
  163. //
  164. unsigned long ulPhase2Seg;
  165. //
  166. //! This value holds the Resynchronization Jump Width in time quanta. The
  167. //! valid values for this setting range from 1 to 4.
  168. //
  169. unsigned long ulSJW;
  170. //
  171. //! This value holds the CAN_CLK divider used to determine time quanta.
  172. //! The valid values for this setting range from 1 to 1023.
  173. //
  174. unsigned long ulQuantumPrescaler;
  175. }
  176. tCANBitClkParms;
  177. //*****************************************************************************
  178. //
  179. //! This data type is used to identify the interrupt status register. This is
  180. //! used when calling the CANIntStatus() function.
  181. //
  182. //*****************************************************************************
  183. typedef enum
  184. {
  185. //
  186. //! Read the CAN interrupt status information.
  187. //
  188. CAN_INT_STS_CAUSE,
  189. //
  190. //! Read a message object's interrupt status.
  191. //
  192. CAN_INT_STS_OBJECT
  193. }
  194. tCANIntStsReg;
  195. //*****************************************************************************
  196. //
  197. //! This data type is used to identify which of several status registers to
  198. //! read when calling the CANStatusGet() function.
  199. //
  200. //*****************************************************************************
  201. typedef enum
  202. {
  203. //
  204. //! Read the full CAN controller status.
  205. //
  206. CAN_STS_CONTROL,
  207. //
  208. //! Read the full 32-bit mask of message objects with a transmit request
  209. //! set.
  210. //
  211. CAN_STS_TXREQUEST,
  212. //
  213. //! Read the full 32-bit mask of message objects with new data available.
  214. //
  215. CAN_STS_NEWDAT,
  216. //
  217. //! Read the full 32-bit mask of message objects that are enabled.
  218. //
  219. CAN_STS_MSGVAL
  220. }
  221. tCANStsReg;
  222. //*****************************************************************************
  223. //
  224. // These definitions are used to specify interrupt sources to CANIntEnable()
  225. // and CANIntDisable().
  226. //
  227. //*****************************************************************************
  228. //
  229. //! This flag is used to allow a CAN controller to generate error
  230. //! interrupts.
  231. //
  232. #define CAN_INT_ERROR 0x00000008
  233. //
  234. //! This flag is used to allow a CAN controller to generate status
  235. //! interrupts.
  236. //
  237. #define CAN_INT_STATUS 0x00000004
  238. //
  239. //! This flag is used to allow a CAN controller to generate any CAN
  240. //! interrupts. If this is not set, then no interrupts will be generated
  241. //! by the CAN controller.
  242. //
  243. #define CAN_INT_MASTER 0x00000002
  244. //*****************************************************************************
  245. //
  246. //! This definition is used to determine the type of message object that will
  247. //! be set up via a call to the CANMessageSet() API.
  248. //
  249. //*****************************************************************************
  250. typedef enum
  251. {
  252. //
  253. //! Transmit message object.
  254. //
  255. MSG_OBJ_TYPE_TX,
  256. //
  257. //! Transmit remote request message object
  258. //
  259. MSG_OBJ_TYPE_TX_REMOTE,
  260. //
  261. //! Receive message object.
  262. //
  263. MSG_OBJ_TYPE_RX,
  264. //
  265. //! Receive remote request message object.
  266. //
  267. MSG_OBJ_TYPE_RX_REMOTE,
  268. //
  269. //! Remote frame receive remote, with auto-transmit message object.
  270. //
  271. MSG_OBJ_TYPE_RXTX_REMOTE
  272. }
  273. tMsgObjType;
  274. //*****************************************************************************
  275. //
  276. // The following enumeration contains all error or status indicators that can
  277. // be returned when calling the CANStatusGet() function.
  278. //
  279. //*****************************************************************************
  280. //
  281. //! CAN controller has entered a Bus Off state.
  282. //
  283. #define CAN_STATUS_BUS_OFF 0x00000080
  284. //
  285. //! CAN controller error level has reached warning level.
  286. //
  287. #define CAN_STATUS_EWARN 0x00000040
  288. //
  289. //! CAN controller error level has reached error passive level.
  290. //
  291. #define CAN_STATUS_EPASS 0x00000020
  292. //
  293. //! A message was received successfully since the last read of this status.
  294. //
  295. #define CAN_STATUS_RXOK 0x00000010
  296. //
  297. //! A message was transmitted successfully since the last read of this
  298. //! status.
  299. //
  300. #define CAN_STATUS_TXOK 0x00000008
  301. //
  302. //! This is the mask for the last error code field.
  303. //
  304. #define CAN_STATUS_LEC_MSK 0x00000007
  305. //
  306. //! There was no error.
  307. //
  308. #define CAN_STATUS_LEC_NONE 0x00000000
  309. //
  310. //! A bit stuffing error has occurred.
  311. //
  312. #define CAN_STATUS_LEC_STUFF 0x00000001
  313. //
  314. //! A formatting error has occurred.
  315. //
  316. #define CAN_STATUS_LEC_FORM 0x00000002
  317. //
  318. //! An acknowledge error has occurred.
  319. //
  320. #define CAN_STATUS_LEC_ACK 0x00000003
  321. //
  322. //! The bus remained a bit level of 1 for longer than is allowed.
  323. //
  324. #define CAN_STATUS_LEC_BIT1 0x00000004
  325. //
  326. //! The bus remained a bit level of 0 for longer than is allowed.
  327. //
  328. #define CAN_STATUS_LEC_BIT0 0x00000005
  329. //
  330. //! A CRC error has occurred.
  331. //
  332. #define CAN_STATUS_LEC_CRC 0x00000006
  333. //
  334. //! This is the mask for the CAN Last Error Code (LEC).
  335. //
  336. #define CAN_STATUS_LEC_MASK 0x00000007
  337. //*****************************************************************************
  338. //
  339. // API Function prototypes
  340. //
  341. //*****************************************************************************
  342. extern void CANBitTimingGet(unsigned long ulBase, tCANBitClkParms *pClkParms);
  343. extern void CANBitTimingSet(unsigned long ulBase, tCANBitClkParms *pClkParms);
  344. extern unsigned long CANBitRateSet(unsigned long ulBase,
  345. unsigned long ulSourceClock,
  346. unsigned long ulBitRate);
  347. extern void CANDisable(unsigned long ulBase);
  348. extern void CANEnable(unsigned long ulBase);
  349. extern tBoolean CANErrCntrGet(unsigned long ulBase, unsigned long *pulRxCount,
  350. unsigned long *pulTxCount);
  351. extern void CANInit(unsigned long ulBase);
  352. extern void CANIntClear(unsigned long ulBase, unsigned long ulIntClr);
  353. extern void CANIntDisable(unsigned long ulBase, unsigned long ulIntFlags);
  354. extern void CANIntEnable(unsigned long ulBase, unsigned long ulIntFlags);
  355. extern void CANIntRegister(unsigned long ulBase, void (*pfnHandler)(void));
  356. extern unsigned long CANIntStatus(unsigned long ulBase,
  357. tCANIntStsReg eIntStsReg);
  358. extern void CANIntUnregister(unsigned long ulBase);
  359. extern void CANMessageClear(unsigned long ulBase, unsigned long ulObjID);
  360. extern void CANMessageGet(unsigned long ulBase, unsigned long ulObjID,
  361. tCANMsgObject *pMsgObject, tBoolean bClrPendingInt);
  362. extern void CANMessageSet(unsigned long ulBase, unsigned long ulObjID,
  363. tCANMsgObject *pMsgObject, tMsgObjType eMsgType);
  364. extern tBoolean CANRetryGet(unsigned long ulBase);
  365. extern void CANRetrySet(unsigned long ulBase, tBoolean bAutoRetry);
  366. extern unsigned long CANStatusGet(unsigned long ulBase, tCANStsReg eStatusReg);
  367. //*****************************************************************************
  368. //
  369. // Several CAN APIs have been renamed, with the original function name being
  370. // deprecated. These defines provide backward compatibility.
  371. //
  372. //*****************************************************************************
  373. #ifndef DEPRECATED
  374. #define CANSetBitTiming(a, b) CANBitTimingSet(a, b)
  375. #define CANGetBitTiming(a, b) CANBitTimingGet(a, b)
  376. #endif
  377. //*****************************************************************************
  378. //
  379. // Mark the end of the C bindings section for C++ compilers.
  380. //
  381. //*****************************************************************************
  382. #ifdef __cplusplus
  383. }
  384. #endif
  385. //*****************************************************************************
  386. //
  387. // Close the Doxygen group.
  388. //! @}
  389. //
  390. //*****************************************************************************
  391. #endif // __CAN_H__