can.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. /** @file can.h
  2. * @brief CAN Driver Header File
  3. * @date 29.May.2013
  4. * @version 03.05.02
  5. *
  6. * This file contains:
  7. * - Definitions
  8. * - Types
  9. * - Interface Prototypes
  10. * .
  11. * which are relevant for the CAN driver.
  12. */
  13. /* (c) Texas Instruments 2009-2013, All rights reserved. */
  14. #ifndef __CAN_H__
  15. #define __CAN_H__
  16. #include "reg_can.h"
  17. /* USER CODE BEGIN (0) */
  18. /* USER CODE END */
  19. /* CAN General Definitions */
  20. /** @def canLEVEL_ACTIVE
  21. * @brief Alias name for CAN error operation level active (Error counter 0-95)
  22. */
  23. #define canLEVEL_ACTIVE 0x00U
  24. /** @def canLEVEL_WARNING
  25. * @brief Alias name for CAN error operation level warning (Error counter 96-127)
  26. */
  27. #define canLEVEL_WARNING 0x40U
  28. /** @def canLEVEL_PASSIVE
  29. * @brief Alias name for CAN error operation level passive (Error counter 128-255)
  30. */
  31. #define canLEVEL_PASSIVE 0x20U
  32. /** @def canLEVEL_BUS_OFF
  33. * @brief Alias name for CAN error operation level bus off (Error counter 256)
  34. */
  35. #define canLEVEL_BUS_OFF 0x80U
  36. /** @def canERROR_NO
  37. * @brief Alias name for no CAN error occurred
  38. */
  39. #define canERROR_OK 0U
  40. /** @def canERROR_STUFF
  41. * @brief Alias name for CAN stuff error an RX message
  42. */
  43. #define canERROR_STUFF 1U
  44. /** @def canERROR_FORMAT
  45. * @brief Alias name for CAN form/format error an RX message
  46. */
  47. #define canERROR_FORMAT 2U
  48. /** @def canERROR_ACKNOWLEDGE
  49. * @brief Alias name for CAN TX message wasn't acknowledged
  50. */
  51. #define canERROR_ACKNOWLEDGE 3U
  52. /** @def canERROR_BIT1
  53. * @brief Alias name for CAN TX message sending recessive level but monitoring dominant
  54. */
  55. #define canERROR_BIT1 4U
  56. /** @def canERROR_BIT0
  57. * @brief Alias name for CAN TX message sending dominant level but monitoring recessive
  58. */
  59. #define canERROR_BIT0 5U
  60. /** @def canERROR_CRC
  61. * @brief Alias name for CAN RX message received wrong CRC
  62. */
  63. #define canERROR_CRC 6U
  64. /** @def canERROR_NO
  65. * @brief Alias name for CAN no message has send or received since last call of CANGetLastError
  66. */
  67. #define canERROR_NO 7U
  68. /** @def canMESSAGE_BOX1
  69. * @brief Alias name for CAN message box 1
  70. *
  71. * @note This value should be used for API argument @a messageBox
  72. */
  73. #define canMESSAGE_BOX1 1U
  74. /** @def canMESSAGE_BOX2
  75. * @brief Alias name for CAN message box 2
  76. *
  77. * @note This value should be used for API argument @a messageBox
  78. */
  79. #define canMESSAGE_BOX2 2U
  80. /** @def canMESSAGE_BOX3
  81. * @brief Alias name for CAN message box 3
  82. *
  83. * @note This value should be used for API argument @a messageBox
  84. */
  85. #define canMESSAGE_BOX3 3U
  86. /** @def canMESSAGE_BOX4
  87. * @brief Alias name for CAN message box 4
  88. *
  89. * @note This value should be used for API argument @a messageBox
  90. */
  91. #define canMESSAGE_BOX4 4U
  92. /** @def canMESSAGE_BOX5
  93. * @brief Alias name for CAN message box 5
  94. *
  95. * @note This value should be used for API argument @a messageBox
  96. */
  97. #define canMESSAGE_BOX5 5U
  98. /** @def canMESSAGE_BOX6
  99. * @brief Alias name for CAN message box 6
  100. *
  101. * @note This value should be used for API argument @a messageBox
  102. */
  103. #define canMESSAGE_BOX6 6U
  104. /** @def canMESSAGE_BOX7
  105. * @brief Alias name for CAN message box 7
  106. *
  107. * @note This value should be used for API argument @a messageBox
  108. */
  109. #define canMESSAGE_BOX7 7U
  110. /** @def canMESSAGE_BOX8
  111. * @brief Alias name for CAN message box 8
  112. *
  113. * @note This value should be used for API argument @a messageBox
  114. */
  115. #define canMESSAGE_BOX8 8U
  116. /** @def canMESSAGE_BOX9
  117. * @brief Alias name for CAN message box 9
  118. *
  119. * @note This value should be used for API argument @a messageBox
  120. */
  121. #define canMESSAGE_BOX9 9U
  122. /** @def canMESSAGE_BOX10
  123. * @brief Alias name for CAN message box 10
  124. *
  125. * @note This value should be used for API argument @a messageBox
  126. */
  127. #define canMESSAGE_BOX10 10U
  128. /** @def canMESSAGE_BOX11
  129. * @brief Alias name for CAN message box 11
  130. *
  131. * @note This value should be used for API argument @a messageBox
  132. */
  133. #define canMESSAGE_BOX11 11U
  134. /** @def canMESSAGE_BOX12
  135. * @brief Alias name for CAN message box 12
  136. *
  137. * @note This value should be used for API argument @a messageBox
  138. */
  139. #define canMESSAGE_BOX12 12U
  140. /** @def canMESSAGE_BOX13
  141. * @brief Alias name for CAN message box 13
  142. *
  143. * @note This value should be used for API argument @a messageBox
  144. */
  145. #define canMESSAGE_BOX13 13U
  146. /** @def canMESSAGE_BOX14
  147. * @brief Alias name for CAN message box 14
  148. *
  149. * @note This value should be used for API argument @a messageBox
  150. */
  151. #define canMESSAGE_BOX14 14U
  152. /** @def canMESSAGE_BOX15
  153. * @brief Alias name for CAN message box 15
  154. *
  155. * @note This value should be used for API argument @a messageBox
  156. */
  157. #define canMESSAGE_BOX15 15U
  158. /** @def canMESSAGE_BOX16
  159. * @brief Alias name for CAN message box 16
  160. *
  161. * @note This value should be used for API argument @a messageBox
  162. */
  163. #define canMESSAGE_BOX16 16U
  164. /** @def canMESSAGE_BOX17
  165. * @brief Alias name for CAN message box 17
  166. *
  167. * @note This value should be used for API argument @a messageBox
  168. */
  169. #define canMESSAGE_BOX17 17U
  170. /** @def canMESSAGE_BOX18
  171. * @brief Alias name for CAN message box 18
  172. *
  173. * @note This value should be used for API argument @a messageBox
  174. */
  175. #define canMESSAGE_BOX18 18U
  176. /** @def canMESSAGE_BOX19
  177. * @brief Alias name for CAN message box 19
  178. *
  179. * @note This value should be used for API argument @a messageBox
  180. */
  181. #define canMESSAGE_BOX19 19U
  182. /** @def canMESSAGE_BOX20
  183. * @brief Alias name for CAN message box 20
  184. *
  185. * @note This value should be used for API argument @a messageBox
  186. */
  187. #define canMESSAGE_BOX20 20U
  188. /** @def canMESSAGE_BOX21
  189. * @brief Alias name for CAN message box 21
  190. *
  191. * @note This value should be used for API argument @a messageBox
  192. */
  193. #define canMESSAGE_BOX21 21U
  194. /** @def canMESSAGE_BOX22
  195. * @brief Alias name for CAN message box 22
  196. *
  197. * @note This value should be used for API argument @a messageBox
  198. */
  199. #define canMESSAGE_BOX22 22U
  200. /** @def canMESSAGE_BOX23
  201. * @brief Alias name for CAN message box 23
  202. *
  203. * @note This value should be used for API argument @a messageBox
  204. */
  205. #define canMESSAGE_BOX23 23U
  206. /** @def canMESSAGE_BOX24
  207. * @brief Alias name for CAN message box 24
  208. *
  209. * @note This value should be used for API argument @a messageBox
  210. */
  211. #define canMESSAGE_BOX24 24U
  212. /** @def canMESSAGE_BOX25
  213. * @brief Alias name for CAN message box 25
  214. *
  215. * @note This value should be used for API argument @a messageBox
  216. */
  217. #define canMESSAGE_BOX25 25U
  218. /** @def canMESSAGE_BOX26
  219. * @brief Alias name for CAN message box 26
  220. *
  221. * @note This value should be used for API argument @a messageBox
  222. */
  223. #define canMESSAGE_BOX26 26U
  224. /** @def canMESSAGE_BOX27
  225. * @brief Alias name for CAN message box 27
  226. *
  227. * @note This value should be used for API argument @a messageBox
  228. */
  229. #define canMESSAGE_BOX27 27U
  230. /** @def canMESSAGE_BOX28
  231. * @brief Alias name for CAN message box 28
  232. *
  233. * @note This value should be used for API argument @a messageBox
  234. */
  235. #define canMESSAGE_BOX28 28U
  236. /** @def canMESSAGE_BOX29
  237. * @brief Alias name for CAN message box 29
  238. *
  239. * @note This value should be used for API argument @a messageBox
  240. */
  241. #define canMESSAGE_BOX29 29U
  242. /** @def canMESSAGE_BOX30
  243. * @brief Alias name for CAN message box 30
  244. *
  245. * @note This value should be used for API argument @a messageBox
  246. */
  247. #define canMESSAGE_BOX30 30U
  248. /** @def canMESSAGE_BOX31
  249. * @brief Alias name for CAN message box 31
  250. *
  251. * @note This value should be used for API argument @a messageBox
  252. */
  253. #define canMESSAGE_BOX31 31U
  254. /** @def canMESSAGE_BOX32
  255. * @brief Alias name for CAN message box 32
  256. *
  257. * @note This value should be used for API argument @a messageBox
  258. */
  259. #define canMESSAGE_BOX32 32U
  260. /** @def canMESSAGE_BOX33
  261. * @brief Alias name for CAN message box 33
  262. *
  263. * @note This value should be used for API argument @a messageBox
  264. */
  265. #define canMESSAGE_BOX33 33U
  266. /** @def canMESSAGE_BOX34
  267. * @brief Alias name for CAN message box 34
  268. *
  269. * @note This value should be used for API argument @a messageBox
  270. */
  271. #define canMESSAGE_BOX34 34U
  272. /** @def canMESSAGE_BOX35
  273. * @brief Alias name for CAN message box 35
  274. *
  275. * @note This value should be used for API argument @a messageBox
  276. */
  277. #define canMESSAGE_BOX35 35U
  278. /** @def canMESSAGE_BOX36
  279. * @brief Alias name for CAN message box 36
  280. *
  281. * @note This value should be used for API argument @a messageBox
  282. */
  283. #define canMESSAGE_BOX36 36U
  284. /** @def canMESSAGE_BOX37
  285. * @brief Alias name for CAN message box 37
  286. *
  287. * @note This value should be used for API argument @a messageBox
  288. */
  289. #define canMESSAGE_BOX37 37U
  290. /** @def canMESSAGE_BOX38
  291. * @brief Alias name for CAN message box 38
  292. *
  293. * @note This value should be used for API argument @a messageBox
  294. */
  295. #define canMESSAGE_BOX38 38U
  296. /** @def canMESSAGE_BOX39
  297. * @brief Alias name for CAN message box 39
  298. *
  299. * @note This value should be used for API argument @a messageBox
  300. */
  301. #define canMESSAGE_BOX39 39U
  302. /** @def canMESSAGE_BOX40
  303. * @brief Alias name for CAN message box 40
  304. *
  305. * @note This value should be used for API argument @a messageBox
  306. */
  307. #define canMESSAGE_BOX40 40U
  308. /** @def canMESSAGE_BOX41
  309. * @brief Alias name for CAN message box 41
  310. *
  311. * @note This value should be used for API argument @a messageBox
  312. */
  313. #define canMESSAGE_BOX41 41U
  314. /** @def canMESSAGE_BOX42
  315. * @brief Alias name for CAN message box 42
  316. *
  317. * @note This value should be used for API argument @a messageBox
  318. */
  319. #define canMESSAGE_BOX42 42U
  320. /** @def canMESSAGE_BOX43
  321. * @brief Alias name for CAN message box 43
  322. *
  323. * @note This value should be used for API argument @a messageBox
  324. */
  325. #define canMESSAGE_BOX43 43U
  326. /** @def canMESSAGE_BOX44
  327. * @brief Alias name for CAN message box 44
  328. *
  329. * @note This value should be used for API argument @a messageBox
  330. */
  331. #define canMESSAGE_BOX44 44U
  332. /** @def canMESSAGE_BOX45
  333. * @brief Alias name for CAN message box 45
  334. *
  335. * @note This value should be used for API argument @a messageBox
  336. */
  337. #define canMESSAGE_BOX45 45U
  338. /** @def canMESSAGE_BOX46
  339. * @brief Alias name for CAN message box 46
  340. *
  341. * @note This value should be used for API argument @a messageBox
  342. */
  343. #define canMESSAGE_BOX46 46U
  344. /** @def canMESSAGE_BOX47
  345. * @brief Alias name for CAN message box 47
  346. *
  347. * @note This value should be used for API argument @a messageBox
  348. */
  349. #define canMESSAGE_BOX47 47U
  350. /** @def canMESSAGE_BOX48
  351. * @brief Alias name for CAN message box 48
  352. *
  353. * @note This value should be used for API argument @a messageBox
  354. */
  355. #define canMESSAGE_BOX48 48U
  356. /** @def canMESSAGE_BOX49
  357. * @brief Alias name for CAN message box 49
  358. *
  359. * @note This value should be used for API argument @a messageBox
  360. */
  361. #define canMESSAGE_BOX49 49U
  362. /** @def canMESSAGE_BOX50
  363. * @brief Alias name for CAN message box 50
  364. *
  365. * @note This value should be used for API argument @a messageBox
  366. */
  367. #define canMESSAGE_BOX50 50U
  368. /** @def canMESSAGE_BOX51
  369. * @brief Alias name for CAN message box 51
  370. *
  371. * @note This value should be used for API argument @a messageBox
  372. */
  373. #define canMESSAGE_BOX51 51U
  374. /** @def canMESSAGE_BOX52
  375. * @brief Alias name for CAN message box 52
  376. *
  377. * @note This value should be used for API argument @a messageBox
  378. */
  379. #define canMESSAGE_BOX52 52U
  380. /** @def canMESSAGE_BOX53
  381. * @brief Alias name for CAN message box 53
  382. *
  383. * @note This value should be used for API argument @a messageBox
  384. */
  385. #define canMESSAGE_BOX53 53U
  386. /** @def canMESSAGE_BOX54
  387. * @brief Alias name for CAN message box 54
  388. *
  389. * @note This value should be used for API argument @a messageBox
  390. */
  391. #define canMESSAGE_BOX54 54U
  392. /** @def canMESSAGE_BOX55
  393. * @brief Alias name for CAN message box 55
  394. *
  395. * @note This value should be used for API argument @a messageBox
  396. */
  397. #define canMESSAGE_BOX55 55U
  398. /** @def canMESSAGE_BOX56
  399. * @brief Alias name for CAN message box 56
  400. *
  401. * @note This value should be used for API argument @a messageBox
  402. */
  403. #define canMESSAGE_BOX56 56U
  404. /** @def canMESSAGE_BOX57
  405. * @brief Alias name for CAN message box 57
  406. *
  407. * @note This value should be used for API argument @a messageBox
  408. */
  409. #define canMESSAGE_BOX57 57U
  410. /** @def canMESSAGE_BOX58
  411. * @brief Alias name for CAN message box 58
  412. *
  413. * @note This value should be used for API argument @a messageBox
  414. */
  415. #define canMESSAGE_BOX58 58U
  416. /** @def canMESSAGE_BOX59
  417. * @brief Alias name for CAN message box 59
  418. *
  419. * @note This value should be used for API argument @a messageBox
  420. */
  421. #define canMESSAGE_BOX59 59U
  422. /** @def canMESSAGE_BOX60
  423. * @brief Alias name for CAN message box 60
  424. *
  425. * @note This value should be used for API argument @a messageBox
  426. */
  427. #define canMESSAGE_BOX60 60U
  428. /** @def canMESSAGE_BOX61
  429. * @brief Alias name for CAN message box 61
  430. *
  431. * @note This value should be used for API argument @a messageBox
  432. */
  433. #define canMESSAGE_BOX61 61U
  434. /** @def canMESSAGE_BOX62
  435. * @brief Alias name for CAN message box 62
  436. *
  437. * @note This value should be used for API argument @a messageBox
  438. */
  439. #define canMESSAGE_BOX62 62U
  440. /** @def canMESSAGE_BOX63
  441. * @brief Alias name for CAN message box 63
  442. *
  443. * @note This value should be used for API argument @a messageBox
  444. */
  445. #define canMESSAGE_BOX63 63U
  446. /** @def canMESSAGE_BOX64
  447. * @brief Alias name for CAN message box 64
  448. *
  449. * @note This value should be used for API argument @a messageBox
  450. */
  451. #define canMESSAGE_BOX64 64U
  452. /* USER CODE BEGIN (1) */
  453. /* USER CODE END */
  454. /**
  455. * @defgroup CAN CAN
  456. * @brief Controller Area Network Module.
  457. *
  458. * The Controller Area Network is a high-integrity, serial, multi-master communication protocol for distributed
  459. * real-time applications. This CAN module is implemented according to ISO 11898-1 and is suitable for
  460. * industrial, automotive and general embedded communications
  461. *
  462. * Related Files
  463. * - reg_can.h
  464. * - can.h
  465. * - can.c
  466. * @addtogroup CAN
  467. * @{
  468. */
  469. /* CAN Interface Functions */
  470. void canInit(void);
  471. uint32 canTransmit(canBASE_t *node, uint32 messageBox, const uint8 * data);
  472. uint32 canGetData(canBASE_t *node, uint32 messageBox, uint8 * const data);
  473. uint32 canIsTxMessagePending(canBASE_t *node, uint32 messageBox);
  474. uint32 canIsRxMessageArrived(canBASE_t *node, uint32 messageBox);
  475. uint32 canIsMessageBoxValid(canBASE_t *node, uint32 messageBox);
  476. uint32 canGetLastError(canBASE_t *node);
  477. uint32 canGetErrorLevel(canBASE_t *node);
  478. void canEnableErrorNotification(canBASE_t *node);
  479. void canDisableErrorNotification(canBASE_t *node);
  480. void canIoSetDirection(canBASE_t *node,uint32 TxDir,uint32 RxDir);
  481. void canIoSetPort(canBASE_t *node, uint32 TxValue, uint32 RxValue);
  482. uint32 canIoTxGetBit(canBASE_t *node);
  483. uint32 canIoRxGetBit(canBASE_t *node);
  484. /** @fn void canErrorNotification(canBASE_t *node, uint32 notification)
  485. * @brief Error notification
  486. * @param[in] node Pointer to CAN node:
  487. * - canREG1: CAN1 node pointer
  488. * - canREG2: CAN2 node pointer
  489. * - canREG3: CAN3 node pointer
  490. * @param[in] notification Error notification code:
  491. * - canLEVEL_WARNING (0x40): When RX- or TX error counter are between 96 and 127
  492. * - canLEVEL_BUS_OFF (0x80): When RX- or TX error counter are above 255
  493. *
  494. * @note This function has to be provide by the user.
  495. */
  496. void canErrorNotification(canBASE_t *node, uint32 notification);
  497. /** @fn void canMessageNotification(canBASE_t *node, uint32 messageBox)
  498. * @brief Message notification
  499. * @param[in] node Pointer to CAN node:
  500. * - canREG1: CAN1 node pointer
  501. * - canREG2: CAN2 node pointer
  502. * - canREG3: CAN3 node pointer
  503. * @param[in] messageBox Message box number of CAN node:
  504. * - canMESSAGE_BOX1: CAN message box 1
  505. * - canMESSAGE_BOXn: CAN message box n [n: 1-64]
  506. * - canMESSAGE_BOX64: CAN message box 64
  507. *
  508. * @note This function has to be provide by the user.
  509. */
  510. void canMessageNotification(canBASE_t *node, uint32 messageBox);
  511. /**@}*/
  512. /* USER CODE BEGIN (2) */
  513. /* USER CODE END */
  514. #endif