mcp2515.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. /****************************************************************************
  2. * drivers/can/mcp2515.c
  3. *
  4. * Copyright (C) 2017 Alan Carvalho de Assis. All rights reserved.
  5. * Author: Alan Carvalho de Assis <acassis@gmail.com>
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in
  15. * the documentation and/or other materials provided with the
  16. * distribution.
  17. * 3. Neither the name NuttX, Atmel, nor the names of its contributors may
  18. * be used to endorse or promote products derived from this software
  19. * without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  27. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  28. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  29. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  31. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  32. * POSSIBILITY OF SUCH DAMAGE.
  33. *
  34. ****************************************************************************/
  35. #ifndef __DRIVERS_CAN_MCP2514_H
  36. #define __DRIVERS_CAN_MCP2514_H 1
  37. /****************************************************************************
  38. * Pre-processor Definitions
  39. ****************************************************************************/
  40. /* Register Addresses */
  41. #define MCP2515_RXF0SIDH 0x00
  42. #define MCP2515_RXF0SIDL 0x01
  43. #define MCP2515_RXF0EID8 0x02
  44. #define MCP2515_RXF0EID0 0x03
  45. #define MCP2515_RXF1SIDH 0x04
  46. #define MCP2515_RXF1SIDL 0x05
  47. #define MCP2515_RXF1EID8 0x06
  48. #define MCP2515_RXF1EID0 0x07
  49. #define MCP2515_RXF2SIDH 0x08
  50. #define MCP2515_RXF2SIDL 0x09
  51. #define MCP2515_RXF2EID8 0x0a
  52. #define MCP2515_RXF2EID0 0x0b
  53. #define MCP2515_BFPCTRL 0x0c
  54. #define MCP2515_TXRTSCTRL 0x0d
  55. #define MCP2515_CANSTAT 0x0e
  56. #define MCP2515_CANCTRL 0x0f
  57. #define MCP2515_RXF3SIDH 0x10
  58. #define MCP2515_RXF3SIDL 0x11
  59. #define MCP2515_RXF3EID8 0x12
  60. #define MCP2515_RXF3EID0 0x13
  61. #define MCP2515_RXF4SIDH 0x14
  62. #define MCP2515_RXF4SIDL 0x15
  63. #define MCP2515_RXF4EID8 0x16
  64. #define MCP2515_RXF4EID0 0x17
  65. #define MCP2515_RXF5SIDH 0x18
  66. #define MCP2515_RXF5SIDL 0x19
  67. #define MCP2515_RXF5EID8 0x1a
  68. #define MCP2515_RXF5EID0 0x1b
  69. #define MCP2515_TEC 0x1c
  70. #define MCP2515_REC 0x1d
  71. #define MCP2515_RXM0SIDH 0x20
  72. #define MCP2515_RXM0SIDL 0x21
  73. #define MCP2515_RXM0EID8 0x22
  74. #define MCP2515_RXM0EID0 0x23
  75. #define MCP2515_RXM1SIDH 0x24
  76. #define MCP2515_RXM1SIDL 0x25
  77. #define MCP2515_RXM1EID8 0x26
  78. #define MCP2515_RXM1EID0 0x27
  79. #define MCP2515_CNF3 0x28
  80. #define MCP2515_CNF2 0x29
  81. #define MCP2515_CNF1 0x2a
  82. #define MCP2515_CANINTE 0x2b
  83. #define MCP2515_CANINTF 0x2c
  84. #define MCP2515_EFLG 0x2d
  85. #define MCP2515_TXB0CTRL 0x30
  86. #define MCP2515_TXB0SIDH 0x31
  87. #define MCP2515_TXB0SIDL 0x32
  88. #define MCP2515_TXB0EID8 0x33
  89. #define MCP2515_TXB0EID0 0x34
  90. #define MCP2515_TXB0DLC 0x35
  91. #define MCP2515_TXB0D0 0x36
  92. #define MCP2515_TXB0D1 0x37
  93. #define MCP2515_TXB0D2 0x38
  94. #define MCP2515_TXB0D3 0x39
  95. #define MCP2515_TXB0D4 0x3a
  96. #define MCP2515_TXB0D5 0x3b
  97. #define MCP2515_TXB0D6 0x3c
  98. #define MCP2515_TXB0D7 0x3d
  99. #define MCP2515_TXB1CTRL 0x40
  100. #define MCP2515_TXB1SIDH 0x41
  101. #define MCP2515_TXB1SIDL 0x42
  102. #define MCP2515_TXB1EID8 0x43
  103. #define MCP2515_TXB1EID0 0x44
  104. #define MCP2515_TXB1DLC 0x45
  105. #define MCP2515_TXB1D0 0x46
  106. #define MCP2515_TXB1D1 0x47
  107. #define MCP2515_TXB1D2 0x48
  108. #define MCP2515_TXB1D3 0x49
  109. #define MCP2515_TXB1D4 0x4a
  110. #define MCP2515_TXB1D5 0x4b
  111. #define MCP2515_TXB1D6 0x4c
  112. #define MCP2515_TXB1D7 0x4d
  113. #define MCP2515_TXB2CTRL 0x50
  114. #define MCP2515_TXB2SIDH 0x51
  115. #define MCP2515_TXB2SIDL 0x52
  116. #define MCP2515_TXB2EID8 0x53
  117. #define MCP2515_TXB2EID0 0x54
  118. #define MCP2515_TXB2DLC 0x55
  119. #define MCP2515_TXB2D0 0x56
  120. #define MCP2515_TXB2D1 0x57
  121. #define MCP2515_TXB2D2 0x58
  122. #define MCP2515_TXB2D3 0x59
  123. #define MCP2515_TXB2D4 0x5a
  124. #define MCP2515_TXB2D5 0x5b
  125. #define MCP2515_TXB2D6 0x5c
  126. #define MCP2515_TXB2D7 0x5d
  127. #define MCP2515_RXB0CTRL 0x60
  128. #define MCP2515_RXB0SIDH 0x61
  129. #define MCP2515_RXB0SIDL 0x62
  130. #define MCP2515_RXB0EID8 0x63
  131. #define MCP2515_RXB0EID0 0x64
  132. #define MCP2515_RXB0DLC 0x65
  133. #define MCP2515_RXB0D0 0x66
  134. #define MCP2515_RXB0D1 0x67
  135. #define MCP2515_RXB0D2 0x68
  136. #define MCP2515_RXB0D3 0x69
  137. #define MCP2515_RXB0D4 0x6a
  138. #define MCP2515_RXB0D5 0x6b
  139. #define MCP2515_RXB0D6 0x6c
  140. #define MCP2515_RXB0D7 0x6d
  141. #define MCP2515_RXB1CTRL 0x70
  142. #define MCP2515_RXB1SIDH 0x71
  143. #define MCP2515_RXB1SIDL 0x72
  144. #define MCP2515_RXB1EID8 0x73
  145. #define MCP2515_RXB1EID0 0x74
  146. #define MCP2515_RXB1DLC 0x75
  147. #define MCP2515_RXB1D0 0x76
  148. #define MCP2515_RXB1D1 0x77
  149. #define MCP2515_RXB1D2 0x78
  150. #define MCP2515_RXB1D3 0x79
  151. #define MCP2515_RXB1D4 0x7a
  152. #define MCP2515_RXB1D5 0x7b
  153. #define MCP2515_RXB1D6 0x7c
  154. #define MCP2515_RXB1D7 0x7d
  155. /* Offset to simplify mcp2515_receive() function */
  156. #define MCP2515_RX0_OFFSET 0x00
  157. #define MCP2515_RX1_OFFSET 0x10
  158. /* Offset to simplify mcp2515_send() function */
  159. #define MCP2515_TX0_OFFSET 0x00
  160. #define MCP2515_TX1_OFFSET 0x10
  161. #define MCP2515_TX2_OFFSET 0x20
  162. /* CANCTRL: CAN CONTROL REGISTER */
  163. #define CANCTRL_CLKPRE_SHIFT (0) /* Bits 0-1: CLKOUT Pin Prescaler bits */
  164. #define CANCTRL_CLKPRE_MASK (3 << CANCTRL_CLKPRE_SHIFT)
  165. #define CANCTRL_CLKEN (1 << 2) /* Bit 2: CLKOUT Pin Enable bit */
  166. #define CANCTRL_OSM (1 << 3) /* Bit 3: One-Shot Mode bit */
  167. #define CANCTRL_ABAT (1 << 4) /* Bit 4: Abort All Pending Transmissions bit */
  168. #define CANCTRL_REQOP_SHIFT (5) /* Bits 5-7: Request Operation Mode bits */
  169. #define CANCTRL_REQOP_MASK (7 << CANCTRL_REQOP_SHIFT)
  170. #define CANCTRL_REQOP_NORMAL (0 << CANCTRL_REQOP_SHIFT)
  171. #define CANCTRL_REQOP_SLEEP (1 << CANCTRL_REQOP_SHIFT)
  172. #define CANCTRL_REQOP_LOOPBK (2 << CANCTRL_REQOP_SHIFT)
  173. #define CANCTRL_REQOP_LISTEN (3 << CANCTRL_REQOP_SHIFT)
  174. #define CANCTRL_REQOP_CONFIG (4 << CANCTRL_REQOP_SHIFT)
  175. /* TXBnCTRL – TRANSMIT BUFFER n CONTROL REGISTER */
  176. #define TXBCTRL_TXP_SHIFT (0) /* Bits 0-1: Transmit Buffer Priority */
  177. #define TXBCTRL_TXP_MASK (3 << MCP2515_TXBCTRL_TXP_SHIFT)
  178. /* Bit 2: Not used */
  179. #define TXBCTRL_TXREQ (1 << 3) /* Bit 3: Message Transmit Request bit */
  180. #define TXBCTRL_TXERR (1 << 4) /* Bit 4: Transmission Error Detected bit */
  181. #define TXBCTRL_MLOA (1 << 5) /* Bit 5: Message Lost Arbitration bit */
  182. #define TXBCTRL_ABTF (1 << 6) /* Bit 6: Message Aborted Flag bit */
  183. /* Bit 7: Not used */
  184. /* TXRTSCTRL – TXnRTS PIN CONTROL AND STATUS REGISTER */
  185. #define TXRTSCTRL_B0RTSM (1 << 0) /* Bit 0: TX0RTS Pin mode bit */
  186. #define TXRTSCTRL_B1RTSM (1 << 1) /* Bit 1: TX1RTS Pin mode bit */
  187. #define TXRTSCTRL_B2RTSM (1 << 2) /* Bit 2: TX2RTS Pin mode bit */
  188. #define TXRTSCTRL_B0RTS (1 << 3) /* Bit 3: TX0RTS Pin State bit */
  189. #define TXRTSCTRL_B1RTS (1 << 4) /* Bit 4: TX1RTS Pin State bit */
  190. #define TXRTSCTRL_B2RTS (1 << 5) /* Bit 5: TX2RTS Pin State bit */
  191. /* Bit 6-7: Not used */
  192. /* TXBnSIDH – TRANSMIT BUFFER n STANDARD IDENTIFIER HIGH */
  193. #define TXBSIDH_SID_MASK 0xff /* Standard Identifier bits <10:3> */
  194. /* TXBnSIDL – TRANSMIT BUFFER n STANDARD IDENTIFIER LOW */
  195. #define TXBSIDL_SID_SHIFT (5) /* Bits 5-7: Standard Identifier bits <2:0> */
  196. #define TXBSIDL_SID_MASK (0x7 << TXBSIDL_SID_SHIFT)
  197. #define TXBSIDL_EXIDE (1 << 3) /* Bit 3: Extended Identifier Enable bit */
  198. #define TXBSIDL_EID_SHIFT (0) /* Bits 0-1: Extended Identifier bits <17:16> */
  199. #define TXBSIDL_EID_MASK (0x03 << TXBSIDL_EID_MASK)
  200. /* TXBnEID8 – TRANSMIT BUFFER n EXTENDED IDENTIFIER HIGH */
  201. #define TXBEID8_EID_MASK 0xff /* Bits 0-7: Extended Identifier bits <15:8> */
  202. /* TXBnEID0 – TRANSMIT BUFFER n EXTENDED IDENTIFIER LOW */
  203. #define TXBEID0_EID_MASK 0xff /* Bits 0-7: Extended Identifier bits <7:0> */
  204. /* TXBnDLC - TRANSMIT BUFFER n DATA LENGTH CODE */
  205. #define TXBDLC_DLC_SHIFT (0) /* Bits 0-3: Data Length Code <3:0> bits */
  206. #define TXBDLC_DLC_MASK (0xf << TXBDLC_DLC_SHIFT)
  207. #define TXBDLC_RTR (1 << 6) /* Bit 6: Remote Transmission Request bit */
  208. /* TXBnDm – TRANSMIT BUFFER n DATA BYTE m */
  209. #define TXBD_D0 (1 << 0) /* Bit 0: Transmit Buffer n Data Field Bytes 0 */
  210. #define TXBD_D1 (1 << 1) /* Bit 1: Transmit Buffer n Data Field Bytes 1 */
  211. #define TXBD_D2 (1 << 2) /* Bit 2: Transmit Buffer n Data Field Bytes 2 */
  212. #define TXBD_D3 (1 << 3) /* Bit 3: Transmit Buffer n Data Field Bytes 3 */
  213. #define TXBD_D4 (1 << 4) /* Bit 4: Transmit Buffer n Data Field Bytes 4 */
  214. #define TXBD_D5 (1 << 5) /* Bit 5: Transmit Buffer n Data Field Bytes 5 */
  215. #define TXBD_D6 (1 << 6) /* Bit 6: Transmit Buffer n Data Field Bytes 6 */
  216. #define TXBD_D7 (1 << 7) /* Bit 7: Transmit Buffer n Data Field Bytes 7 */
  217. /* RXB0CTRL – RECEIVE BUFFER 0 CONTROL */
  218. #define RXB0CTRL_FILHIT (1 << 0) /* Bit 0: Filter Hit bit - 1 = Msg was accepted by Filter 1; 0 = Filter 0 */
  219. #define RXB0CTRL_BUKT1 (1 << 1) /* Bit 1: Read-only Copy of BUKT bit (used internally by the MCP2515) */
  220. #define RXB0CTRL_BUKT (1 << 2) /* Bit 2: Rollover Enable bit */
  221. /* These bits are common to RXB0 and RXB1: */
  222. #define RXBCTRL_RXRTR (1 << 3) /* Bit 3: Received Remote Transfer Request bit */
  223. /* Bit 4: Not used */
  224. #define RXBCTRL_RXM_SHIFT (5) /* Bits 5-6: Receive Buffer Operating Mode bits */
  225. #define RXBCTRL_RXM_MASK (0x3 << RXBCTRL_RXM_SHIFT)
  226. #define RXBCTRL_RXM_ALLMSG (3 << RXBCTRL_RXM_SHIFT) /* 11: Turn mask/filters off; receive any message */
  227. #define RXBCTRL_RXM_ALLVALID (0 << RXBCTRL_RXM_SHIFT) /* 00: Receive all valid msgs using (STD or EXT) that meet filter criteria */
  228. /* Bit 7: Not used */
  229. /* N.B.: In the datasheet DS21801D the file RXM of RXBnCTRL could to assume
  230. the value 01 and 10 to receive only STD or EXT msgs respectively.
  231. But in a more recent datasheet DS20001801H it was removed. */
  232. /* RXB1CTRL – RECEIVE BUFFER 1 CONTROL */
  233. #define RXB1CTRL_FILHIT_SHIFT (0) /* Filter Hit bits - indicates which acceptance filter enabled reception of message */
  234. #define RXB1CTRL_FILHIT_MASK (0x7 << RXB0CTRL_FILHIT_SHIFT)
  235. #define RXB1CTRL_FILHIT_F5 (5 << RXB1CTRL_FILHIT_SHIFT) /* Acceptance Filter 5 (RXF5) */
  236. #define RXB1CTRL_FILHIT_F4 (4 << RXB1CTRL_FILHIT_SHIFT) /* Acceptance Filter 4 (RXF4) */
  237. #define RXB1CTRL_FILHIT_F3 (3 << RXB1CTRL_FILHIT_SHIFT) /* Acceptance Filter 3 (RXF3) */
  238. #define RXB1CTRL_FILHIT_F2 (2 << RXB1CTRL_FILHIT_SHIFT) /* Acceptance Filter 2 (RXF2) */
  239. #define RXB1CTRL_FILHIT_F1 (1 << RXB1CTRL_FILHIT_SHIFT) /* Acceptance Filter 1 (RXF1) (Only if BUKT bit set in RXB0CTRL) */
  240. #define RXB1CTRL_FILHIT_F0 (0 << RXB1CTRL_FILHIT_SHIFT) /* Acceptance Filter 0 (RXF0) (Only if BUKT bit set in RXB0CTRL) */
  241. /* BFPCTRL – RXnBF PIN CONTROL AND STATUS */
  242. #define BFPCTRL_B0BFM (1 << 0) /* Bit 0: RX0BF Pin Operation Mode bit */
  243. #define BFPCTRL_B1BFM (1 << 1) /* Bit 1: RX1BF Pin Operation Mode bit */
  244. #define BFPCTRL_B0BFE (1 << 2) /* Bit 2: RX0BF Pin Function Enable bit */
  245. #define BFPCTRL_B1BFE (1 << 3) /* Bit 3: RX1BF Pin Function Enable bit */
  246. #define BFPCTRL_B0BFS (1 << 4) /* Bit 4: RX0BF Pin State bit (Digital Output mode only) */
  247. #define BFPCTRL_B1BFS (1 << 5) /* Bit 5: RX1BF Pin State bit (Digital Output mode only) */
  248. /* Bits 6-7: Not used */
  249. /* RXBnSIDH – RECEIVE BUFFER n STANDARD IDENTIFIER HIGH */
  250. #define RXBSIDH_SID_MASK 0xff /* Standard Identifier bits <10:3> */
  251. /* RXBnSIDL – RECEIVE BUFFER n STANDARD IDENTIFIER LOW */
  252. #define RXBSIDL_SID_SHIFT (5) /* Bits 5-7: Standard Identifier bits <2:0> */
  253. #define RXBSIDL_SID_MASK (0x7 << RXBSIDL_SID_SHIFT)
  254. #define RXBSIDL_SRR (1 << 4) /* Bit 4: Standard Frame Remote Transmit Request bit (valid only if IDE bit = '0')*/
  255. #define RXBSIDL_IDE (1 << 3) /* Bit 3: Extended Identifier Message received */
  256. /* Bit 2: Not used */
  257. #define RXBSIDL_EID_SHIFT (0) /* Bits 0-1: Extended Identifier bits <17:16> */
  258. #define RXBSIDL_EID_MASK (0x03 << RXBSIDL_EID_SHIFT)
  259. /* RXBnEID8 – RECEIVE BUFFER n EXTENDED IDENTIFIER HIGH */
  260. #define RXBEID8_EID_MASK 0xff /* Bits 0-7: Extended Identifier bits <15:8> */
  261. /* RXBnEID0 – RECEIVE BUFFER n EXTENDED IDENTIFIER LOW */
  262. #define RXBEID0_EID_MASK 0xff /* Bits 0-7: Extended Identifier bits <7:0> */
  263. /* RXBnDLC – RECEIVE BUFFER n DATA LENGHT CODE */
  264. #define RXBDLC_DLC_SHIFT (0) /* Bits 0-3: Data Length Code <3:0> bits */
  265. #define RXBDLC_DLC_MASK (0xf << RXBDLC_DLC_SHIFT)
  266. #define RXBDLC_RB0 (1 << 4) /* Bit 4: Reserved bit 0 */
  267. #define RXBDLC_RB1 (1 << 5) /* Bit 5: Reserved bit 1 */
  268. #define RXBDLC_RTR (1 << 6) /* Bit 6: Remote Transmission Request bit */
  269. /* Bit 7: Not used */
  270. /* RXFnSIDH – FILTER n STANDARD IDENTIFIER HIGH */
  271. #define RXFSIDH_SID_MASK 0xff /* Standard Identifier Filter bits <10:3> */
  272. /* RXFnSIDL – FILTER n STANDARD IDENTIFIER LOW */
  273. #define RXFSIDL_EID_SHIFT (0) /* Bit 0-1: Extended Identifier Filter bits <17:16> */
  274. #define RXFSIDL_EID_MASK (3 << RXFSIDL_EID_SHIFT)
  275. #define RXFSIDL_EXIDE (1 << 3) /* Bit 3: Extended Identifier Enable bit */
  276. #define RXFSIDL_SID_SHIFT (5) /* Bits 5-7: Standard Identifier Filter bits <2:0> */
  277. #define RXFSIDL_SID_MASK (0x7 << RXFSIDL_SID_SHIFT)
  278. /* RXFnEID8 – FILTER n EXTENDED IDENTIFIER HIGH */
  279. #define RXFEID8_EID_MASK 0xff /* Extended Identifier bits <15:8> */
  280. /* RXFnEID0 – FILTER n EXTENDED IDENTIFIER LOW */
  281. #define RXFEID0_EID_MASK 0xff /* Extended Identifier bits <7:0> */
  282. /* RXMnSIDH – MASK n STANDARD IDENTIFIER HIGH */
  283. #define RXMSIDH_SID_MASK 0xff /* Standard Identifier Mask bits <10:3> */
  284. /* RXMnSIDL – MASK n STANDARD IDENTIFIER LOW */
  285. #define RXMSIDL_EID_SHIFT (0) /* Bits 0-1: Extended Identifier Mask bits <17:16> */
  286. #define RXMSIDL_EID_MASK (3 << RXMSIDH_EID_SHIFT)
  287. #define RXMSIDL_SID_SHIFT (5) /* Bits 5-7: Standard Identifier Mask bits <2:0> */
  288. #define RXMSIDL_MASK (7 << RXMSIDH_SID_SHIFT)
  289. /* RXMnEID8 – MASK n EXTENDED IDENTIFIER HIGH */
  290. #define RXMEID8_EID_MASK 0xff /* Extended Identifier bits <15:8> */
  291. /* RXMnEID0 – MASK n EXTENDED IDENTIFIER LOW */
  292. #define RXMEID0_EID_MASK 0xff /* Extended Identifier Mask bits <7:0> */
  293. /* CNF1 – CONFIGURATION 1 */
  294. #define CNF1_BRP_SHIFT (0) /* Bits 0-5: Baud Rate Prescaler bits <5:0>, TQ = 2 x (BRP + 1)/Fosc */
  295. #define CNF1_BRP_MASK (0x3f << CNF1_BRP_SHIFT)
  296. #define CNF1_SJW_SHIFT (6) /* Bit 6-7: Synchronization Jump Width Length bits <1:0> */
  297. #define CNF1_SJW_MASK (3 << CNF1_SJW_SHIFT)
  298. # define CNF1_SJW_4xTQ (3 << CNF1_SJW_SHIFT) /* Length = 4 x TQ */
  299. # define CNF1_SJW_3xTQ (2 << CNF1_SJW_SHIFT) /* Length = 3 x TQ */
  300. # define CNF1_SJW_2xTQ (1 << CNF1_SJW_SHIFT) /* Length = 2 x TQ */
  301. # define CNF1_SJW_1xTQ (0 << CNF1_SJW_SHIFT) /* Length = 1 x TQ */
  302. /* CNF2 – CONFIGURATION 2 */
  303. #define CNF2_PRSEG_SHIFT (0) /* Bits 0-2: Propagation Segment Length bits <2:0>, (PRSEG + 1) x TQ */
  304. #define CNF2_PRSEG_MASK (7 << CNF2_PRSEG_SHIFT)
  305. #define CNF2_PHSEG1_SHIFT (3) /* Bits 3-5: PS1 Length bits <2:0>, (PHSEG1 + 1) x TQ */
  306. #define CNF2_PHSEG1_MASK (7 << CNF2_PHSEG1_SHIFT)
  307. #define CNF2_SAM (1 << 6) /* Bit 6: Sample Point Configuration bit */
  308. #define CNF2_BTLMODE (1 << 7) /* Bit 7: PS2 Bit Time Length bit */
  309. /* CNF3 - CONFIGURATION 3 */
  310. #define CNF3_PHSEG2_SHIFT (0) /* Bits 0-2: PS2 Length bits<2:0>, (PHSEG2 + 1) x TQ */
  311. #define CNF3_PHSEG2_MASK (7 << CNF3_PHSEG2_SHIFT)
  312. #define CNF3_WAKFIL (1 << 6) /* Bit 3: Wake-up Filter bit */
  313. #define CNF3_SOF (1 << 7) /* Bit 7: Start-of-Frame signal bit */
  314. /* TEC – TRANSMIT ERROR COUNTER */
  315. #define TEC_MASK 0xff /* Transmit Error Count bits <7:0> */
  316. /* REC – RECEIVER ERROR COUNTER */
  317. #define REC_MASK 0xff /* Receive Error Count bits <7:0> */
  318. /* EFLG – ERROR FLAG */
  319. #define EFLG_EWARN (1 << 0) /* Bit 0: Error Warning Flag bit */
  320. #define EFLG_RXWAR (1 << 1) /* Bit 1: Receive Error Warning Flag bit */
  321. #define EFLG_TXWAR (1 << 2) /* Bit 2: Transmit Error Warning Flag bit */
  322. #define EFLG_RXEP (1 << 3) /* Bit 3: Receive Error-Passive Flag bit */
  323. #define EFLG_TXEP (1 << 4) /* Bit 4: Transmit Error-Passive Flag bit */
  324. #define EFLG_TXBO (1 << 5) /* Bit 5: Bus-Off Error Flag bit */
  325. #define EFLG_RX0OVR (1 << 6) /* Bit 6: Receive Buffer 0 Overflow Flag bit */
  326. #define EFLG_RX1OVR (1 << 7) /* Bit 7: Receive Buffer 1 Overflow Flag bit */
  327. /* CANINTE/CANINTF – INTERRUPT ENABLE/FLAG */
  328. #define MCP2515_INT_RX0 (1 << 0) /* Bit 0: Receive Buffer 0 Full Interrupt Enable bit */
  329. #define MCP2515_INT_RX1 (1 << 1) /* Bit 1: Receive Buffer 1 Full Interrupt Enable bit */
  330. #define MCP2515_INT_TX0 (1 << 2) /* Bit 2: Transmit Buffer 0 Empty Interrupt Enable bit */
  331. #define MCP2515_INT_TX1 (1 << 3) /* Bit 3: Transmit Buffer 1 Empty Interrupt Enable bit */
  332. #define MCP2515_INT_TX2 (1 << 4) /* Bit 4: Transmit Buffer 2 Empty Interrupt Enable bit */
  333. #define MCP2515_INT_ERR (1 << 5) /* Bit 5: Error Interrupt Enable bit (multiple sources in EFLG register) */
  334. #define MCP2515_INT_WAK (1 << 6) /* Bit 6: Wakeup Interrupt Enable bit */
  335. #define MCP2515_INT_MERR (1 << 7) /* Bit 7: Message Error Interrupt Enable bit */
  336. /* MCP2515 SPI Instruction/Command byte */
  337. #define MCP2515_RESET 0xC0
  338. #define MCP2515_READ 0x03
  339. #define MCP2515_READ_RX0 0x90
  340. #define MCP2515_READ_RX1 0x94
  341. #define MCP2515_WRITE 0x02
  342. #define MCP2515_LOAD_TX0 0x40
  343. #define MCP2515_LOAD_TX1 0x42
  344. #define MCP2515_LOAD_TX2 0x44
  345. #define MCP2515_RTS_TX0 0x81
  346. #define MCP2515_RTS_TX1 0x82
  347. #define MCP2515_RTS_TX2 0x84
  348. #define MCP2515_RTS_ALL 0x87
  349. #define MCP2515_READ_STATUS 0xA0
  350. #define MCP2515_RX_STATUS 0xB0
  351. #define MCP2515_BITMOD 0x05
  352. /* CANCTRL register will be 0x87 after reset and in Conf. Mode */
  353. #define DEFAULT_CANCTRL_CONFMODE 0x87
  354. /* Crystal Frequency used on MCP2515 board */
  355. #define MCP2515_CANCLK_FREQUENCY 8000000
  356. #endif /* __DRIVERS_CAN_MCP2514_H */