can.h 13 KB

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