My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

lpc17xx_can.h 32KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872
  1. /**********************************************************************
  2. * $Id$ lpc17xx_can.h 2010-06-18
  3. *//**
  4. * @file lpc17xx_can.h
  5. * @brief Contains all macro definitions and function prototypes
  6. * support for CAN firmware library on LPC17xx
  7. * @version 3.0
  8. * @date 18. June. 2010
  9. * @author NXP MCU SW Application Team
  10. *
  11. * Copyright(C) 2010, NXP Semiconductor
  12. * All rights reserved.
  13. *
  14. ***********************************************************************
  15. * Software that is described herein is for illustrative purposes only
  16. * which provides customers with programming information regarding the
  17. * products. This software is supplied "AS IS" without any warranties.
  18. * NXP Semiconductors assumes no responsibility or liability for the
  19. * use of the software, conveys no license or title under any patent,
  20. * copyright, or mask work right to the product. NXP Semiconductors
  21. * reserves the right to make changes in the software without
  22. * notification. NXP Semiconductors also make no representation or
  23. * warranty that such application will be suitable for the specified
  24. * use without further testing or modification.
  25. * Permission to use, copy, modify, and distribute this software and its
  26. * documentation is hereby granted, under NXP Semiconductors'
  27. * relevant copyright in the software, without fee, provided that it
  28. * is used in conjunction with NXP Semiconductors microcontrollers. This
  29. * copyright, permission, and disclaimer notice must appear in all copies of
  30. * this code.
  31. **********************************************************************/
  32. /* Peripheral group ----------------------------------------------------------- */
  33. /** @defgroup CAN CAN (Control Area Network)
  34. * @ingroup LPC1700CMSIS_FwLib_Drivers
  35. * @{
  36. */
  37. #ifndef LPC17XX_CAN_H_
  38. #define LPC17XX_CAN_H_
  39. /* Includes ------------------------------------------------------------------- */
  40. #include "LPC17xx.h"
  41. #include "lpc_types.h"
  42. #ifdef __cplusplus
  43. extern "C"
  44. {
  45. #endif
  46. /* Public Types --------------------------------------------------------------- */
  47. /** @defgroup CAN_Public_Macros CAN Public Macros
  48. * @{
  49. */
  50. #define MSG_ENABLE ((uint8_t)(0))
  51. #define MSG_DISABLE ((uint8_t)(1))
  52. #define CAN1_CTRL ((uint8_t)(0))
  53. #define CAN2_CTRL ((uint8_t)(1))
  54. #define PARAM_FULLCAN_IC(n) ((n==FULLCAN_IC0)||(n==FULLCAN_IC1))
  55. #define ID_11 1
  56. #define MAX_HW_FULLCAN_OBJ 64
  57. #define MAX_SW_FULLCAN_OBJ 32
  58. /**
  59. * @}
  60. */
  61. /* Private Macros ------------------------------------------------------------- */
  62. /** @defgroup CAN_Private_Macros CAN Private Macros
  63. * @{
  64. */
  65. /* --------------------- BIT DEFINITIONS -------------------------------------- */
  66. /*********************************************************************//**
  67. * Macro defines for CAN Mode Register
  68. **********************************************************************/
  69. /** CAN Reset mode */
  70. #define CAN_MOD_RM ((uint32_t)(1))
  71. /** CAN Listen Only Mode */
  72. #define CAN_MOD_LOM ((uint32_t)(1<<1))
  73. /** CAN Self Test mode */
  74. #define CAN_MOD_STM ((uint32_t)(1<<2))
  75. /** CAN Transmit Priority mode */
  76. #define CAN_MOD_TPM ((uint32_t)(1<<3))
  77. /** CAN Sleep mode */
  78. #define CAN_MOD_SM ((uint32_t)(1<<4))
  79. /** CAN Receive Polarity mode */
  80. #define CAN_MOD_RPM ((uint32_t)(1<<5))
  81. /** CAN Test mode */
  82. #define CAN_MOD_TM ((uint32_t)(1<<7))
  83. /*********************************************************************//**
  84. * Macro defines for CAN Command Register
  85. **********************************************************************/
  86. /** CAN Transmission Request */
  87. #define CAN_CMR_TR ((uint32_t)(1))
  88. /** CAN Abort Transmission */
  89. #define CAN_CMR_AT ((uint32_t)(1<<1))
  90. /** CAN Release Receive Buffer */
  91. #define CAN_CMR_RRB ((uint32_t)(1<<2))
  92. /** CAN Clear Data Overrun */
  93. #define CAN_CMR_CDO ((uint32_t)(1<<3))
  94. /** CAN Self Reception Request */
  95. #define CAN_CMR_SRR ((uint32_t)(1<<4))
  96. /** CAN Select Tx Buffer 1 */
  97. #define CAN_CMR_STB1 ((uint32_t)(1<<5))
  98. /** CAN Select Tx Buffer 2 */
  99. #define CAN_CMR_STB2 ((uint32_t)(1<<6))
  100. /** CAN Select Tx Buffer 3 */
  101. #define CAN_CMR_STB3 ((uint32_t)(1<<7))
  102. /*********************************************************************//**
  103. * Macro defines for CAN Global Status Register
  104. **********************************************************************/
  105. /** CAN Receive Buffer Status */
  106. #define CAN_GSR_RBS ((uint32_t)(1))
  107. /** CAN Data Overrun Status */
  108. #define CAN_GSR_DOS ((uint32_t)(1<<1))
  109. /** CAN Transmit Buffer Status */
  110. #define CAN_GSR_TBS ((uint32_t)(1<<2))
  111. /** CAN Transmit Complete Status */
  112. #define CAN_GSR_TCS ((uint32_t)(1<<3))
  113. /** CAN Receive Status */
  114. #define CAN_GSR_RS ((uint32_t)(1<<4))
  115. /** CAN Transmit Status */
  116. #define CAN_GSR_TS ((uint32_t)(1<<5))
  117. /** CAN Error Status */
  118. #define CAN_GSR_ES ((uint32_t)(1<<6))
  119. /** CAN Bus Status */
  120. #define CAN_GSR_BS ((uint32_t)(1<<7))
  121. /** CAN Current value of the Rx Error Counter */
  122. #define CAN_GSR_RXERR(n) ((uint32_t)((n&0xFF)<<16))
  123. /** CAN Current value of the Tx Error Counter */
  124. #define CAN_GSR_TXERR(n) ((uint32_t)(n&0xFF)<<24))
  125. /*********************************************************************//**
  126. * Macro defines for CAN Interrupt and Capture Register
  127. **********************************************************************/
  128. /** CAN Receive Interrupt */
  129. #define CAN_ICR_RI ((uint32_t)(1))
  130. /** CAN Transmit Interrupt 1 */
  131. #define CAN_ICR_TI1 ((uint32_t)(1<<1))
  132. /** CAN Error Warning Interrupt */
  133. #define CAN_ICR_EI ((uint32_t)(1<<2))
  134. /** CAN Data Overrun Interrupt */
  135. #define CAN_ICR_DOI ((uint32_t)(1<<3))
  136. /** CAN Wake-Up Interrupt */
  137. #define CAN_ICR_WUI ((uint32_t)(1<<4))
  138. /** CAN Error Passive Interrupt */
  139. #define CAN_ICR_EPI ((uint32_t)(1<<5))
  140. /** CAN Arbitration Lost Interrupt */
  141. #define CAN_ICR_ALI ((uint32_t)(1<<6))
  142. /** CAN Bus Error Interrupt */
  143. #define CAN_ICR_BEI ((uint32_t)(1<<7))
  144. /** CAN ID Ready Interrupt */
  145. #define CAN_ICR_IDI ((uint32_t)(1<<8))
  146. /** CAN Transmit Interrupt 2 */
  147. #define CAN_ICR_TI2 ((uint32_t)(1<<9))
  148. /** CAN Transmit Interrupt 3 */
  149. #define CAN_ICR_TI3 ((uint32_t)(1<<10))
  150. /** CAN Error Code Capture */
  151. #define CAN_ICR_ERRBIT(n) ((uint32_t)((n&0x1F)<<16))
  152. /** CAN Error Direction */
  153. #define CAN_ICR_ERRDIR ((uint32_t)(1<<21))
  154. /** CAN Error Capture */
  155. #define CAN_ICR_ERRC(n) ((uint32_t)((n&0x3)<<22))
  156. /** CAN Arbitration Lost Capture */
  157. #define CAN_ICR_ALCBIT(n) ((uint32_t)((n&0xFF)<<24))
  158. /*********************************************************************//**
  159. * Macro defines for CAN Interrupt Enable Register
  160. **********************************************************************/
  161. /** CAN Receive Interrupt Enable */
  162. #define CAN_IER_RIE ((uint32_t)(1))
  163. /** CAN Transmit Interrupt Enable for buffer 1 */
  164. #define CAN_IER_TIE1 ((uint32_t)(1<<1))
  165. /** CAN Error Warning Interrupt Enable */
  166. #define CAN_IER_EIE ((uint32_t)(1<<2))
  167. /** CAN Data Overrun Interrupt Enable */
  168. #define CAN_IER_DOIE ((uint32_t)(1<<3))
  169. /** CAN Wake-Up Interrupt Enable */
  170. #define CAN_IER_WUIE ((uint32_t)(1<<4))
  171. /** CAN Error Passive Interrupt Enable */
  172. #define CAN_IER_EPIE ((uint32_t)(1<<5))
  173. /** CAN Arbitration Lost Interrupt Enable */
  174. #define CAN_IER_ALIE ((uint32_t)(1<<6))
  175. /** CAN Bus Error Interrupt Enable */
  176. #define CAN_IER_BEIE ((uint32_t)(1<<7))
  177. /** CAN ID Ready Interrupt Enable */
  178. #define CAN_IER_IDIE ((uint32_t)(1<<8))
  179. /** CAN Transmit Enable Interrupt for Buffer 2 */
  180. #define CAN_IER_TIE2 ((uint32_t)(1<<9))
  181. /** CAN Transmit Enable Interrupt for Buffer 3 */
  182. #define CAN_IER_TIE3 ((uint32_t)(1<<10))
  183. /*********************************************************************//**
  184. * Macro defines for CAN Bus Timing Register
  185. **********************************************************************/
  186. /** CAN Baudrate Prescaler */
  187. #define CAN_BTR_BRP(n) ((uint32_t)(n&0x3FF))
  188. /** CAN Synchronization Jump Width */
  189. #define CAN_BTR_SJM(n) ((uint32_t)((n&0x3)<<14))
  190. /** CAN Time Segment 1 */
  191. #define CAN_BTR_TESG1(n) ((uint32_t)(n&0xF)<<16))
  192. /** CAN Time Segment 2 */
  193. #define CAN_BTR_TESG2(n) ((uint32_t)(n&0xF)<<20))
  194. /** CAN Sampling */
  195. #define CAN_BTR_SAM(n) ((uint32_t)(1<<23))
  196. /*********************************************************************//**
  197. * Macro defines for CAN Error Warning Limit Register
  198. **********************************************************************/
  199. /** CAN Error Warning Limit */
  200. #define CAN_EWL_EWL(n) ((uint32_t)(n&0xFF))
  201. /*********************************************************************//**
  202. * Macro defines for CAN Status Register
  203. **********************************************************************/
  204. /** CAN Receive Buffer Status */
  205. #define CAN_SR_RBS ((uint32_t)(1))
  206. /** CAN Data Overrun Status */
  207. #define CAN_SR_DOS ((uint32_t)(1<<1))
  208. /** CAN Transmit Buffer Status 1 */
  209. #define CAN_SR_TBS1 ((uint32_t)(1<<2))
  210. /** CAN Transmission Complete Status of Buffer 1 */
  211. #define CAN_SR_TCS1 ((uint32_t)(1<<3))
  212. /** CAN Receive Status */
  213. #define CAN_SR_RS ((uint32_t)(1<<4))
  214. /** CAN Transmit Status 1 */
  215. #define CAN_SR_TS1 ((uint32_t)(1<<5))
  216. /** CAN Error Status */
  217. #define CAN_SR_ES ((uint32_t)(1<<6))
  218. /** CAN Bus Status */
  219. #define CAN_SR_BS ((uint32_t)(1<<7))
  220. /** CAN Transmit Buffer Status 2 */
  221. #define CAN_SR_TBS2 ((uint32_t)(1<<10))
  222. /** CAN Transmission Complete Status of Buffer 2 */
  223. #define CAN_SR_TCS2 ((uint32_t)(1<<11))
  224. /** CAN Transmit Status 2 */
  225. #define CAN_SR_TS2 ((uint32_t)(1<<13))
  226. /** CAN Transmit Buffer Status 2 */
  227. #define CAN_SR_TBS3 ((uint32_t)(1<<18))
  228. /** CAN Transmission Complete Status of Buffer 2 */
  229. #define CAN_SR_TCS3 ((uint32_t)(1<<19))
  230. /** CAN Transmit Status 2 */
  231. #define CAN_SR_TS3 ((uint32_t)(1<<21))
  232. /*********************************************************************//**
  233. * Macro defines for CAN Receive Frame Status Register
  234. **********************************************************************/
  235. /** CAN ID Index */
  236. #define CAN_RFS_ID_INDEX(n) ((uint32_t)(n&0x3FF))
  237. /** CAN Bypass */
  238. #define CAN_RFS_BP ((uint32_t)(1<<10))
  239. /** CAN Data Length Code */
  240. #define CAN_RFS_DLC(n) ((uint32_t)((n&0xF)<<16)
  241. /** CAN Remote Transmission Request */
  242. #define CAN_RFS_RTR ((uint32_t)(1<<30))
  243. /** CAN control 11 bit or 29 bit Identifier */
  244. #define CAN_RFS_FF ((uint32_t)(1<<31))
  245. /*********************************************************************//**
  246. * Macro defines for CAN Receive Identifier Register
  247. **********************************************************************/
  248. /** CAN 11 bit Identifier */
  249. #define CAN_RID_ID_11(n) ((uint32_t)(n&0x7FF))
  250. /** CAN 29 bit Identifier */
  251. #define CAN_RID_ID_29(n) ((uint32_t)(n&0x1FFFFFFF))
  252. /*********************************************************************//**
  253. * Macro defines for CAN Receive Data A Register
  254. **********************************************************************/
  255. /** CAN Receive Data 1 */
  256. #define CAN_RDA_DATA1(n) ((uint32_t)(n&0xFF))
  257. /** CAN Receive Data 2 */
  258. #define CAN_RDA_DATA2(n) ((uint32_t)((n&0xFF)<<8))
  259. /** CAN Receive Data 3 */
  260. #define CAN_RDA_DATA3(n) ((uint32_t)((n&0xFF)<<16))
  261. /** CAN Receive Data 4 */
  262. #define CAN_RDA_DATA4(n) ((uint32_t)((n&0xFF)<<24))
  263. /*********************************************************************//**
  264. * Macro defines for CAN Receive Data B Register
  265. **********************************************************************/
  266. /** CAN Receive Data 5 */
  267. #define CAN_RDB_DATA5(n) ((uint32_t)(n&0xFF))
  268. /** CAN Receive Data 6 */
  269. #define CAN_RDB_DATA6(n) ((uint32_t)((n&0xFF)<<8))
  270. /** CAN Receive Data 7 */
  271. #define CAN_RDB_DATA7(n) ((uint32_t)((n&0xFF)<<16))
  272. /** CAN Receive Data 8 */
  273. #define CAN_RDB_DATA8(n) ((uint32_t)((n&0xFF)<<24))
  274. /*********************************************************************//**
  275. * Macro defines for CAN Transmit Frame Information Register
  276. **********************************************************************/
  277. /** CAN Priority */
  278. #define CAN_TFI_PRIO(n) ((uint32_t)(n&0xFF))
  279. /** CAN Data Length Code */
  280. #define CAN_TFI_DLC(n) ((uint32_t)((n&0xF)<<16))
  281. /** CAN Remote Frame Transmission */
  282. #define CAN_TFI_RTR ((uint32_t)(1<<30))
  283. /** CAN control 11-bit or 29-bit Identifier */
  284. #define CAN_TFI_FF ((uint32_t)(1<<31))
  285. /*********************************************************************//**
  286. * Macro defines for CAN Transmit Identifier Register
  287. **********************************************************************/
  288. /** CAN 11-bit Identifier */
  289. #define CAN_TID_ID11(n) ((uint32_t)(n&0x7FF))
  290. /** CAN 11-bit Identifier */
  291. #define CAN_TID_ID29(n) ((uint32_t)(n&0x1FFFFFFF))
  292. /*********************************************************************//**
  293. * Macro defines for CAN Transmit Data A Register
  294. **********************************************************************/
  295. /** CAN Transmit Data 1 */
  296. #define CAN_TDA_DATA1(n) ((uint32_t)(n&0xFF))
  297. /** CAN Transmit Data 2 */
  298. #define CAN_TDA_DATA2(n) ((uint32_t)((n&0xFF)<<8))
  299. /** CAN Transmit Data 3 */
  300. #define CAN_TDA_DATA3(n) ((uint32_t)((n&0xFF)<<16))
  301. /** CAN Transmit Data 4 */
  302. #define CAN_TDA_DATA4(n) ((uint32_t)((n&0xFF)<<24))
  303. /*********************************************************************//**
  304. * Macro defines for CAN Transmit Data B Register
  305. **********************************************************************/
  306. /** CAN Transmit Data 5 */
  307. #define CAN_TDA_DATA5(n) ((uint32_t)(n&0xFF))
  308. /** CAN Transmit Data 6 */
  309. #define CAN_TDA_DATA6(n) ((uint32_t)((n&0xFF)<<8))
  310. /** CAN Transmit Data 7 */
  311. #define CAN_TDA_DATA7(n) ((uint32_t)((n&0xFF)<<16))
  312. /** CAN Transmit Data 8 */
  313. #define CAN_TDA_DATA8(n) ((uint32_t)((n&0xFF)<<24))
  314. /*********************************************************************//**
  315. * Macro defines for CAN Sleep Clear Register
  316. **********************************************************************/
  317. /** CAN1 Sleep mode */
  318. #define CAN1SLEEPCLR ((uint32_t)(1<<1))
  319. /** CAN2 Sleep Mode */
  320. #define CAN2SLEEPCLR ((uint32_t)(1<<2))
  321. /*********************************************************************//**
  322. * Macro defines for CAN Wake up Flags Register
  323. **********************************************************************/
  324. /** CAN1 Sleep mode */
  325. #define CAN_WAKEFLAGES_CAN1WAKE ((uint32_t)(1<<1))
  326. /** CAN2 Sleep Mode */
  327. #define CAN_WAKEFLAGES_CAN2WAKE ((uint32_t)(1<<2))
  328. /*********************************************************************//**
  329. * Macro defines for Central transmit Status Register
  330. **********************************************************************/
  331. /** CAN Transmit 1 */
  332. #define CAN_TSR_TS1 ((uint32_t)(1))
  333. /** CAN Transmit 2 */
  334. #define CAN_TSR_TS2 ((uint32_t)(1<<1))
  335. /** CAN Transmit Buffer Status 1 */
  336. #define CAN_TSR_TBS1 ((uint32_t)(1<<8))
  337. /** CAN Transmit Buffer Status 2 */
  338. #define CAN_TSR_TBS2 ((uint32_t)(1<<9))
  339. /** CAN Transmission Complete Status 1 */
  340. #define CAN_TSR_TCS1 ((uint32_t)(1<<16))
  341. /** CAN Transmission Complete Status 2 */
  342. #define CAN_TSR_TCS2 ((uint32_t)(1<<17))
  343. /*********************************************************************//**
  344. * Macro defines for Central Receive Status Register
  345. **********************************************************************/
  346. /** CAN Receive Status 1 */
  347. #define CAN_RSR_RS1 ((uint32_t)(1))
  348. /** CAN Receive Status 1 */
  349. #define CAN_RSR_RS2 ((uint32_t)(1<<1))
  350. /** CAN Receive Buffer Status 1*/
  351. #define CAN_RSR_RB1 ((uint32_t)(1<<8))
  352. /** CAN Receive Buffer Status 2*/
  353. #define CAN_RSR_RB2 ((uint32_t)(1<<9))
  354. /** CAN Data Overrun Status 1 */
  355. #define CAN_RSR_DOS1 ((uint32_t)(1<<16))
  356. /** CAN Data Overrun Status 1 */
  357. #define CAN_RSR_DOS2 ((uint32_t)(1<<17))
  358. /*********************************************************************//**
  359. * Macro defines for Central Miscellaneous Status Register
  360. **********************************************************************/
  361. /** Same CAN Error Status in CAN1GSR */
  362. #define CAN_MSR_E1 ((uint32_t)(1))
  363. /** Same CAN Error Status in CAN2GSR */
  364. #define CAN_MSR_E2 ((uint32_t)(1<<1))
  365. /** Same CAN Bus Status in CAN1GSR */
  366. #define CAN_MSR_BS1 ((uint32_t)(1<<8))
  367. /** Same CAN Bus Status in CAN2GSR */
  368. #define CAN_MSR_BS2 ((uint32_t)(1<<9))
  369. /*********************************************************************//**
  370. * Macro defines for Acceptance Filter Mode Register
  371. **********************************************************************/
  372. /** CAN Acceptance Filter Off mode */
  373. #define CAN_AFMR_AccOff ((uint32_t)(1))
  374. /** CAN Acceptance File Bypass mode */
  375. #define CAN_AFMR_AccBP ((uint32_t)(1<<1))
  376. /** FullCAN Mode Enhancements */
  377. #define CAN_AFMR_eFCAN ((uint32_t)(1<<2))
  378. /*********************************************************************//**
  379. * Macro defines for Standard Frame Individual Start Address Register
  380. **********************************************************************/
  381. /** The start address of the table of individual Standard Identifier */
  382. #define CAN_STT_sa(n) ((uint32_t)((n&1FF)<<2))
  383. /*********************************************************************//**
  384. * Macro defines for Standard Frame Group Start Address Register
  385. **********************************************************************/
  386. /** The start address of the table of grouped Standard Identifier */
  387. #define CAN_SFF_GRP_sa(n) ((uint32_t)((n&3FF)<<2))
  388. /*********************************************************************//**
  389. * Macro defines for Extended Frame Start Address Register
  390. **********************************************************************/
  391. /** The start address of the table of individual Extended Identifier */
  392. #define CAN_EFF_sa(n) ((uint32_t)((n&1FF)<<2))
  393. /*********************************************************************//**
  394. * Macro defines for Extended Frame Group Start Address Register
  395. **********************************************************************/
  396. /** The start address of the table of grouped Extended Identifier */
  397. #define CAN_Eff_GRP_sa(n) ((uint32_t)((n&3FF)<<2))
  398. /*********************************************************************//**
  399. * Macro defines for End Of AF Table Register
  400. **********************************************************************/
  401. /** The End of Table of AF LookUp Table */
  402. #define CAN_EndofTable(n) ((uint32_t)((n&3FF)<<2))
  403. /*********************************************************************//**
  404. * Macro defines for LUT Error Address Register
  405. **********************************************************************/
  406. /** CAN Look-Up Table Error Address */
  407. #define CAN_LUTerrAd(n) ((uint32_t)((n&1FF)<<2))
  408. /*********************************************************************//**
  409. * Macro defines for LUT Error Register
  410. **********************************************************************/
  411. /** CAN Look-Up Table Error */
  412. #define CAN_LUTerr ((uint32_t)(1))
  413. /*********************************************************************//**
  414. * Macro defines for Global FullCANInterrupt Enable Register
  415. **********************************************************************/
  416. /** Global FullCANInterrupt Enable */
  417. #define CAN_FCANIE ((uint32_t)(1))
  418. /*********************************************************************//**
  419. * Macro defines for FullCAN Interrupt and Capture Register 0
  420. **********************************************************************/
  421. /** FullCAN Interrupt and Capture (0-31)*/
  422. #define CAN_FCANIC0_IntPnd(n) ((uint32_t)(1<<n))
  423. /*********************************************************************//**
  424. * Macro defines for FullCAN Interrupt and Capture Register 1
  425. **********************************************************************/
  426. /** FullCAN Interrupt and Capture (0-31)*/
  427. #define CAN_FCANIC1_IntPnd(n) ((uint32_t)(1<<(n-32)))
  428. /* ---------------- CHECK PARAMETER DEFINITIONS ---------------------------- */
  429. /** Macro to determine if it is valid CAN peripheral or not */
  430. #define PARAM_CANx(x) ((((uint32_t*)x)==((uint32_t *)LPC_CAN1)) \
  431. ||(((uint32_t*)x)==((uint32_t *)LPC_CAN2)))
  432. /* Macro to determine if it is valid CANAF or not*/
  433. #define PARAM_CANAFx(x) (((uint32_t*)x)== ((uint32_t*)LPC_CANAF))
  434. /* Macro to determine if it is valid CANAF RAM or not*/
  435. #define PARAM_CANAFRAMx(x) (((uint32_t*)x)== (uint32_t*)LPC_CANAF_RAM)
  436. /* Macro to determine if it is valid CANCR or not*/
  437. #define PARAM_CANCRx(x) (((uint32_t*)x)==((uint32_t*)LPC_CANCR))
  438. /** Macro to check Data to send valid */
  439. #define PARAM_I2S_DATA(data) ((data>=0)&&(data <= 0xFFFFFFFF))
  440. /** Macro to check frequency value */
  441. #define PRAM_I2S_FREQ(freq) ((freq>=16000)&&(freq <= 96000))
  442. /** Macro to check Frame Identifier */
  443. #define PARAM_ID_11(n) ((n>>11)==0) /*-- 11 bit --*/
  444. #define PARAM_ID_29(n) ((n>>29)==0) /*-- 29 bit --*/
  445. /** Macro to check DLC value */
  446. #define PARAM_DLC(n) ((n>>4)==0) /*-- 4 bit --*/
  447. /** Macro to check ID format type */
  448. #define PARAM_ID_FORMAT(n) ((n==STD_ID_FORMAT)||(n==EXT_ID_FORMAT))
  449. /** Macro to check Group identifier */
  450. #define PARAM_GRP_ID(x, y) ((x<=y))
  451. /** Macro to check Frame type */
  452. #define PARAM_FRAME_TYPE(n) ((n==DATA_FRAME)||(n==REMOTE_FRAME))
  453. /** Macro to check Control/Central Status type parameter */
  454. #define PARAM_CTRL_STS_TYPE(n) ((n==CANCTRL_GLOBAL_STS)||(n==CANCTRL_INT_CAP) \
  455. ||(n==CANCTRL_ERR_WRN)||(n==CANCTRL_STS))
  456. /** Macro to check CR status type */
  457. #define PARAM_CR_STS_TYPE(n) ((n==CANCR_TX_STS)||(n==CANCR_RX_STS) \
  458. ||(n==CANCR_MS))
  459. /** Macro to check AF Mode type parameter */
  460. #define PARAM_AFMODE_TYPE(n) ((n==CAN_Normal)||(n==CAN_AccOff) \
  461. ||(n==CAN_AccBP)||(n==CAN_eFCAN))
  462. /** Macro to check Operation Mode */
  463. #define PARAM_MODE_TYPE(n) ((n==CAN_OPERATING_MODE)||(n==CAN_RESET_MODE) \
  464. ||(n==CAN_LISTENONLY_MODE)||(n==CAN_SELFTEST_MODE) \
  465. ||(n==CAN_TXPRIORITY_MODE)||(n==CAN_SLEEP_MODE) \
  466. ||(n==CAN_RXPOLARITY_MODE)||(n==CAN_TEST_MODE))
  467. /** Macro define for struct AF_Section parameter */
  468. #define PARAM_CTRL(n) ((n==CAN1_CTRL)|(n==CAN2_CTRL))
  469. /** Macro define for struct AF_Section parameter */
  470. #define PARAM_MSG_DISABLE(n) ((n==MSG_ENABLE)|(n==MSG_DISABLE))
  471. /**Macro to check Interrupt Type parameter */
  472. #define PARAM_INT_EN_TYPE(n) ((n==CANINT_RIE)||(n==CANINT_TIE1) \
  473. ||(n==CANINT_EIE)||(n==CANINT_DOIE) \
  474. ||(n==CANINT_WUIE)||(n==CANINT_EPIE) \
  475. ||(n==CANINT_ALIE)||(n==CANINT_BEIE) \
  476. ||(n==CANINT_IDIE)||(n==CANINT_TIE2) \
  477. ||(n==CANINT_TIE3)||(n==CANINT_FCE))
  478. /** Macro to check AFLUT Entry type */
  479. #define PARAM_AFLUT_ENTRY_TYPE(n) ((n==FULLCAN_ENTRY)||(n==EXPLICIT_STANDARD_ENTRY)\
  480. ||(n==GROUP_STANDARD_ENTRY)||(n==EXPLICIT_EXTEND_ENTRY) \
  481. ||(n==GROUP_EXTEND_ENTRY))
  482. /** Macro to check position */
  483. #define PARAM_POSITION(n) (n<512)
  484. /**
  485. * @}
  486. */
  487. /* Public Types --------------------------------------------------------------- */
  488. /** @defgroup CAN_Public_Types CAN Public Types
  489. * @{
  490. */
  491. /** CAN configuration structure */
  492. /***********************************************************************
  493. * CAN device configuration commands (IOCTL commands and arguments)
  494. **********************************************************************/
  495. /**
  496. * @brief CAN ID format definition
  497. */
  498. typedef enum {
  499. STD_ID_FORMAT = 0, /**< Use standard ID format (11 bit ID) */
  500. EXT_ID_FORMAT = 1 /**< Use extended ID format (29 bit ID) */
  501. } CAN_ID_FORMAT_Type;
  502. /**
  503. * @brief AFLUT Entry type definition
  504. */
  505. typedef enum {
  506. FULLCAN_ENTRY = 0,
  507. EXPLICIT_STANDARD_ENTRY,
  508. GROUP_STANDARD_ENTRY,
  509. EXPLICIT_EXTEND_ENTRY,
  510. GROUP_EXTEND_ENTRY
  511. } AFLUT_ENTRY_Type;
  512. /**
  513. * @brief Symbolic names for type of CAN message
  514. */
  515. typedef enum {
  516. DATA_FRAME = 0, /**< Data frame */
  517. REMOTE_FRAME = 1 /**< Remote frame */
  518. } CAN_FRAME_Type;
  519. /**
  520. * @brief CAN Control status definition
  521. */
  522. typedef enum {
  523. CANCTRL_GLOBAL_STS = 0, /**< CAN Global Status */
  524. CANCTRL_INT_CAP, /**< CAN Interrupt and Capture */
  525. CANCTRL_ERR_WRN, /**< CAN Error Warning Limit */
  526. CANCTRL_STS /**< CAN Control Status */
  527. } CAN_CTRL_STS_Type;
  528. /**
  529. * @brief Central CAN status type definition
  530. */
  531. typedef enum {
  532. CANCR_TX_STS = 0, /**< Central CAN Tx Status */
  533. CANCR_RX_STS, /**< Central CAN Rx Status */
  534. CANCR_MS /**< Central CAN Miscellaneous Status */
  535. } CAN_CR_STS_Type;
  536. /**
  537. * @brief FullCAN Interrupt Capture type definition
  538. */
  539. typedef enum{
  540. FULLCAN_IC0, /**< FullCAN Interrupt and Capture 0 */
  541. FULLCAN_IC1 /**< FullCAN Interrupt and Capture 1 */
  542. }FullCAN_IC_Type;
  543. /**
  544. * @brief CAN interrupt enable type definition
  545. */
  546. typedef enum {
  547. CANINT_RIE = 0, /**< CAN Receiver Interrupt Enable */
  548. CANINT_TIE1, /**< CAN Transmit Interrupt Enable */
  549. CANINT_EIE, /**< CAN Error Warning Interrupt Enable */
  550. CANINT_DOIE, /**< CAN Data Overrun Interrupt Enable */
  551. CANINT_WUIE, /**< CAN Wake-Up Interrupt Enable */
  552. CANINT_EPIE, /**< CAN Error Passive Interrupt Enable */
  553. CANINT_ALIE, /**< CAN Arbitration Lost Interrupt Enable */
  554. CANINT_BEIE, /**< CAN Bus Error Inter rupt Enable */
  555. CANINT_IDIE, /**< CAN ID Ready Interrupt Enable */
  556. CANINT_TIE2, /**< CAN Transmit Interrupt Enable for Buffer2 */
  557. CANINT_TIE3, /**< CAN Transmit Interrupt Enable for Buffer3 */
  558. CANINT_FCE /**< FullCAN Interrupt Enable */
  559. } CAN_INT_EN_Type;
  560. /**
  561. * @brief Acceptance Filter Mode type definition
  562. */
  563. typedef enum {
  564. CAN_Normal = 0, /**< Normal Mode */
  565. CAN_AccOff, /**< Acceptance Filter Off Mode */
  566. CAN_AccBP, /**< Acceptance Fileter Bypass Mode */
  567. CAN_eFCAN /**< FullCAN Mode Enhancement */
  568. } CAN_AFMODE_Type;
  569. /**
  570. * @brief CAN Mode Type definition
  571. */
  572. typedef enum {
  573. CAN_OPERATING_MODE = 0, /**< Operating Mode */
  574. CAN_RESET_MODE, /**< Reset Mode */
  575. CAN_LISTENONLY_MODE, /**< Listen Only Mode */
  576. CAN_SELFTEST_MODE, /**< Seft Test Mode */
  577. CAN_TXPRIORITY_MODE, /**< Transmit Priority Mode */
  578. CAN_SLEEP_MODE, /**< Sleep Mode */
  579. CAN_RXPOLARITY_MODE, /**< Receive Polarity Mode */
  580. CAN_TEST_MODE /**< Test Mode */
  581. } CAN_MODE_Type;
  582. /**
  583. * @brief Error values that functions can return
  584. */
  585. typedef enum {
  586. CAN_OK = 1, /**< No error */
  587. CAN_OBJECTS_FULL_ERROR, /**< No more rx or tx objects available */
  588. CAN_FULL_OBJ_NOT_RCV, /**< Full CAN object not received */
  589. CAN_NO_RECEIVE_DATA, /**< No have receive data available */
  590. CAN_AF_ENTRY_ERROR, /**< Entry load in AFLUT is unvalid */
  591. CAN_CONFLICT_ID_ERROR, /**< Conflict ID occur */
  592. CAN_ENTRY_NOT_EXIT_ERROR /**< Entry remove outo AFLUT is not exit */
  593. } CAN_ERROR;
  594. /**
  595. * @brief Pin Configuration structure
  596. */
  597. typedef struct {
  598. uint8_t RD; /**< Serial Inputs, from CAN transceivers, should be:
  599. ** For CAN1:
  600. - CAN_RD1_P0_0: RD pin is on P0.0
  601. - CAN_RD1_P0_21 : RD pin is on P0.21
  602. ** For CAN2:
  603. - CAN_RD2_P0_4: RD pin is on P0.4
  604. - CAN_RD2_P2_7: RD pin is on P2.7
  605. */
  606. uint8_t TD; /**< Serial Outputs, To CAN transceivers, should be:
  607. ** For CAN1:
  608. - CAN_TD1_P0_1: TD pin is on P0.1
  609. - CAN_TD1_P0_22: TD pin is on P0.22
  610. ** For CAN2:
  611. - CAN_TD2_P0_5: TD pin is on P0.5
  612. - CAN_TD2_P2_8: TD pin is on P2.8
  613. */
  614. } CAN_PinCFG_Type;
  615. /**
  616. * @brief CAN message object structure
  617. */
  618. typedef struct {
  619. uint32_t id; /**< 29 bit identifier, it depend on "format" value
  620. - if format = STD_ID_FORMAT, id should be 11 bit identifier
  621. - if format = EXT_ID_FORMAT, id should be 29 bit identifier
  622. */
  623. uint8_t dataA[4]; /**< Data field A */
  624. uint8_t dataB[4]; /**< Data field B */
  625. uint8_t len; /**< Length of data field in bytes, should be:
  626. - 0000b-0111b: 0-7 bytes
  627. - 1xxxb: 8 bytes
  628. */
  629. uint8_t format; /**< Identifier Format, should be:
  630. - STD_ID_FORMAT: Standard ID - 11 bit format
  631. - EXT_ID_FORMAT: Extended ID - 29 bit format
  632. */
  633. uint8_t type; /**< Remote Frame transmission, should be:
  634. - DATA_FRAME: the number of data bytes called out by the DLC
  635. field are send from the CANxTDA and CANxTDB registers
  636. - REMOTE_FRAME: Remote Frame is sent
  637. */
  638. } CAN_MSG_Type;
  639. /**
  640. * @brief FullCAN Entry structure
  641. */
  642. typedef struct {
  643. uint8_t controller; /**< CAN Controller, should be:
  644. - CAN1_CTRL: CAN1 Controller
  645. - CAN2_CTRL: CAN2 Controller
  646. */
  647. uint8_t disable; /**< Disable bit, should be:
  648. - MSG_ENABLE: disable bit = 0
  649. - MSG_DISABLE: disable bit = 1
  650. */
  651. uint16_t id_11; /**< Standard ID, should be 11-bit value */
  652. } FullCAN_Entry;
  653. /**
  654. * @brief Standard ID Frame Format Entry structure
  655. */
  656. typedef struct {
  657. uint8_t controller; /**< CAN Controller, should be:
  658. - CAN1_CTRL: CAN1 Controller
  659. - CAN2_CTRL: CAN2 Controller
  660. */
  661. uint8_t disable; /**< Disable bit, should be:
  662. - MSG_ENABLE: disable bit = 0
  663. - MSG_DISABLE: disable bit = 1
  664. */
  665. uint16_t id_11; /**< Standard ID, should be 11-bit value */
  666. } SFF_Entry;
  667. /**
  668. * @brief Group of Standard ID Frame Format Entry structure
  669. */
  670. typedef struct {
  671. uint8_t controller1; /**< First CAN Controller, should be:
  672. - CAN1_CTRL: CAN1 Controller
  673. - CAN2_CTRL: CAN2 Controller
  674. */
  675. uint8_t disable1; /**< First Disable bit, should be:
  676. - MSG_ENABLE: disable bit = 0)
  677. - MSG_DISABLE: disable bit = 1
  678. */
  679. uint16_t lowerID; /**< ID lower bound, should be 11-bit value */
  680. uint8_t controller2; /**< Second CAN Controller, should be:
  681. - CAN1_CTRL: CAN1 Controller
  682. - CAN2_CTRL: CAN2 Controller
  683. */
  684. uint8_t disable2; /**< Second Disable bit, should be:
  685. - MSG_ENABLE: disable bit = 0
  686. - MSG_DISABLE: disable bit = 1
  687. */
  688. uint16_t upperID; /**< ID upper bound, should be 11-bit value and
  689. equal or greater than lowerID
  690. */
  691. } SFF_GPR_Entry;
  692. /**
  693. * @brief Extended ID Frame Format Entry structure
  694. */
  695. typedef struct {
  696. uint8_t controller; /**< CAN Controller, should be:
  697. - CAN1_CTRL: CAN1 Controller
  698. - CAN2_CTRL: CAN2 Controller
  699. */
  700. uint32_t ID_29; /**< Extend ID, shoud be 29-bit value */
  701. } EFF_Entry;
  702. /**
  703. * @brief Group of Extended ID Frame Format Entry structure
  704. */
  705. typedef struct {
  706. uint8_t controller1; /**< First CAN Controller, should be:
  707. - CAN1_CTRL: CAN1 Controller
  708. - CAN2_CTRL: CAN2 Controller
  709. */
  710. uint8_t controller2; /**< Second Disable bit, should be:
  711. - MSG_ENABLE: disable bit = 0(default)
  712. - MSG_DISABLE: disable bit = 1
  713. */
  714. uint32_t lowerEID; /**< Extended ID lower bound, should be 29-bit value */
  715. uint32_t upperEID; /**< Extended ID upper bound, should be 29-bit value */
  716. } EFF_GPR_Entry;
  717. /**
  718. * @brief Acceptance Filter Section Table structure
  719. */
  720. typedef struct {
  721. FullCAN_Entry* FullCAN_Sec; /**< The pointer point to FullCAN_Entry */
  722. uint8_t FC_NumEntry; /**< FullCAN Entry Number */
  723. SFF_Entry* SFF_Sec; /**< The pointer point to SFF_Entry */
  724. uint8_t SFF_NumEntry; /**< Standard ID Entry Number */
  725. SFF_GPR_Entry* SFF_GPR_Sec; /**< The pointer point to SFF_GPR_Entry */
  726. uint8_t SFF_GPR_NumEntry; /**< Group Standard ID Entry Number */
  727. EFF_Entry* EFF_Sec; /**< The pointer point to EFF_Entry */
  728. uint8_t EFF_NumEntry; /**< Extended ID Entry Number */
  729. EFF_GPR_Entry* EFF_GPR_Sec; /**< The pointer point to EFF_GPR_Entry */
  730. uint8_t EFF_GPR_NumEntry; /**< Group Extended ID Entry Number */
  731. } AF_SectionDef;
  732. /**
  733. * @}
  734. */
  735. /* Public Functions ----------------------------------------------------------- */
  736. /** @defgroup CAN_Public_Functions CAN Public Functions
  737. * @{
  738. */
  739. /* Init/DeInit CAN peripheral -----------*/
  740. void CAN_Init(LPC_CAN_TypeDef *CANx, uint32_t baudrate);
  741. void CAN_DeInit(LPC_CAN_TypeDef *CANx);
  742. /* CAN messages functions ---------------*/
  743. Status CAN_SendMsg(LPC_CAN_TypeDef *CANx, CAN_MSG_Type *CAN_Msg);
  744. Status CAN_ReceiveMsg(LPC_CAN_TypeDef *CANx, CAN_MSG_Type *CAN_Msg);
  745. CAN_ERROR FCAN_ReadObj(LPC_CANAF_TypeDef* CANAFx, CAN_MSG_Type *CAN_Msg);
  746. /* CAN configure functions ---------------*/
  747. void CAN_ModeConfig(LPC_CAN_TypeDef* CANx, CAN_MODE_Type mode,
  748. FunctionalState NewState);
  749. void CAN_SetAFMode(LPC_CANAF_TypeDef* CANAFx, CAN_AFMODE_Type AFmode);
  750. void CAN_SetCommand(LPC_CAN_TypeDef* CANx, uint32_t CMRType);
  751. /* AFLUT functions ---------------------- */
  752. CAN_ERROR CAN_SetupAFLUT(LPC_CANAF_TypeDef* CANAFx, AF_SectionDef* AFSection);
  753. CAN_ERROR CAN_LoadFullCANEntry(LPC_CAN_TypeDef* CANx, uint16_t ID);
  754. CAN_ERROR CAN_LoadExplicitEntry(LPC_CAN_TypeDef* CANx, uint32_t ID,
  755. CAN_ID_FORMAT_Type format);
  756. CAN_ERROR CAN_LoadGroupEntry(LPC_CAN_TypeDef* CANx, uint32_t lowerID,
  757. uint32_t upperID, CAN_ID_FORMAT_Type format);
  758. CAN_ERROR CAN_RemoveEntry(AFLUT_ENTRY_Type EntryType, uint16_t position);
  759. /* CAN interrupt functions -----------------*/
  760. void CAN_IRQCmd(LPC_CAN_TypeDef* CANx, CAN_INT_EN_Type arg, FunctionalState NewState);
  761. uint32_t CAN_IntGetStatus(LPC_CAN_TypeDef* CANx);
  762. /* CAN get status functions ----------------*/
  763. IntStatus CAN_FullCANIntGetStatus (LPC_CANAF_TypeDef* CANAFx);
  764. uint32_t CAN_FullCANPendGetStatus (LPC_CANAF_TypeDef* CANAFx, FullCAN_IC_Type type);
  765. uint32_t CAN_GetCTRLStatus(LPC_CAN_TypeDef* CANx, CAN_CTRL_STS_Type arg);
  766. uint32_t CAN_GetCRStatus(LPC_CANCR_TypeDef* CANCRx, CAN_CR_STS_Type arg);
  767. /**
  768. * @}
  769. */
  770. #ifdef __cplusplus
  771. }
  772. #endif
  773. #endif /* LPC17XX_CAN_H_ */
  774. /**
  775. * @}
  776. */
  777. /* --------------------------------- End Of File ------------------------------ */