sja1000.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. /*
  2. * Copyright (C) 2004 by Ole Reinhardt <ole.reinhardt@kernelconcepts.de>,
  3. * Kernelconcepts http://www.kernelconcepts.de
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. Neither the name of the copyright holders nor the names of
  15. * contributors may be used to endorse or promote products derived
  16. * from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY EGNITE SOFTWARE GMBH AND CONTRIBUTORS
  19. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  21. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL EGNITE
  22. * SOFTWARE GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  23. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  24. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  25. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  26. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  27. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  28. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  29. * SUCH DAMAGE.
  30. *
  31. * For additional information see http://www.ethernut.de/
  32. *
  33. */
  34. /*!
  35. * \file include/dev/sja1000.h
  36. * \brief Header for SJA1000 CAN-Bus controller driver
  37. *
  38. *
  39. * The SJA1000 controller is connected to the memory bus. It's base
  40. * address and interrupt is set by NutRegisterDevice.
  41. *
  42. * Have a look to our m-can board if you have questions.
  43. */
  44. /*!
  45. * \addtogroup xgCanSJA1000
  46. */
  47. /*@{*/
  48. #ifndef _SJA1000_H_
  49. #define _SJA1000_H_
  50. //Register and bit definitions for the SJA1000
  51. // address and bit definitions for the Mode & Control Register
  52. #define SJA1000_MODECTRL (*(volatile u_char*) (sja_base+0))
  53. #define RM_RR_Bit 0x01 // reset mode (request) bit
  54. #define LOM_Bit 0x02 // listen only mode bit
  55. #define STM_Bit 0x04 // self test mode bit
  56. #define AFM_Bit 0x08 // acceptance filter mode bit
  57. #define SM_Bit 0x10 // enter sleep mode bit
  58. // address and bit definitions for the Interrupt Enable & Control Register
  59. #define SJA1000_IEN (*(volatile u_char*) (sja_base+4)) // PeliCAN mode
  60. #define RIE_Bit 0x01 // receive interrupt enable bit
  61. #define TIE_Bit 0x02 // transmit interrupt enable bit
  62. #define EIE_Bit 0x04 // error warning interrupt enable bit
  63. #define DOIE_Bit 0x08 // data overrun interrupt enable bit
  64. #define WUIE_Bit 0x10 // wake-up interrupt enable bit
  65. #define EPIE_Bit 0x20 // error passive interrupt enable bit
  66. #define ALIE_Bit 0x40 // arbitration lost interr. enable bit
  67. #define BEIE_Bit 0x80 // bus error interrupt enable bit
  68. // address and bit definitions for the Command Register
  69. #define SJA1000_CMD (*(volatile u_char*) (sja_base+1))
  70. #define TR_Bit 0x01 // transmission request bit
  71. #define AT_Bit 0x02 // abort transmission bit
  72. #define RRB_Bit 0x04 // release receive buffer bit
  73. #define CDO_Bit 0x08 // clear data overrun bit
  74. #define SRR_Bit 0x10 // self reception request bit
  75. // address and bit definitions for the Status Register
  76. #define SJA1000_STATUS (*(volatile u_char*) (sja_base+2))
  77. #define RBS_Bit 0x01 // receive buffer status bit
  78. #define DOS_Bit 0x02 // data overrun status bit
  79. #define TBS_Bit 0x04 // transmit buffer status bit
  80. #define TCS_Bit 0x08 // transmission complete status bit
  81. #define RS_Bit 0x10 // receive status bit
  82. #define TS_Bit 0x20 // transmit status bit
  83. #define ES_Bit 0x40 // error status bit
  84. #define BS_Bit 0x80 // bus status bit
  85. // address and bit definitions for the Interrupt Register
  86. #define SJA1000_INT (*(volatile u_char*) (sja_base+3))
  87. #define RI_Bit 0x01 // receive interrupt bit
  88. #define TI_Bit 0x02 // transmit interrupt bit
  89. #define EI_Bit 0x04 // error warning interrupt bit
  90. #define DOI_Bit 0x08 // data overrun interrupt bit
  91. #define WUI_Bit 0x10 // wake-up interrupt bit
  92. #define EPI_Bit 0x20 // error passive interrupt bit
  93. #define ALI_Bit 0x40 // arbitration lost interrupt bit
  94. #define BEI_Bit 0x80 // bus error interrupt bit
  95. // address and bit definitions for the Bus Timing Registers
  96. #define SJA1000_BT0 (*(volatile u_char*) (sja_base+6))
  97. #define SJA1000_BT1 (*(volatile u_char*) (sja_base+7))
  98. #define SAM_Bit 0x80 // sample mode bit
  99. // 1 == the bus is sampled 3 times
  100. // 0 == the bus is sampled once */
  101. // address and bit definitions for the Output Control Register
  102. #define SJA1000_OUTCTRL (*(volatile u_char*) (sja_base+8))
  103. // OCMODE1, OCMODE0
  104. #define BiPhaseMode 0x00 // bi-phase output mode
  105. #define NormalMode 0x02 // normal output mode
  106. #define ClkOutMode 0x03 // clock output mode
  107. // output pin configuration for TX1
  108. #define OCPOL1_Bit 0x20 // output polarity control bit
  109. #define Tx1Float 0x00 // configured as float
  110. #define Tx1PullDn 0x40 // configured as pull-down
  111. #define Tx1PullUp 0x80 // configured as pull-up
  112. #define Tx1PshPull 0xC0 // configured as push/pull
  113. // output configuration for TX0
  114. #define OCPOLO_Bit 0x04 // output polarity control bit
  115. #define Tx0Float 0x00 // configured as float
  116. #define Tx0PullDn 0x08 // configured as pull-down
  117. #define Tx0PullUp 0x10 // configured as pull-up
  118. #define Tx0PshPull 0x18 // configured as push/pull
  119. // address definitions of Acceptance Code & Mask Registers
  120. #define SJA1000_AC0 (*(volatile u_char*) (sja_base+16))
  121. #define SJA1000_AC1 (*(volatile u_char*) (sja_base+17))
  122. #define SJA1000_AC2 (*(volatile u_char*) (sja_base+18))
  123. #define SJA1000_AC3 (*(volatile u_char*) (sja_base+19))
  124. #define SJA1000_AM0 (*(volatile u_char*) (sja_base+20))
  125. #define SJA1000_AM1 (*(volatile u_char*) (sja_base+21))
  126. #define SJA1000_AM2 (*(volatile u_char*) (sja_base+22))
  127. #define SJA1000_AM3 (*(volatile u_char*) (sja_base+23))
  128. // address definitions of the Rx-Buffer
  129. #define SJA1000_RxFrameInfo (*(volatile u_char*) (sja_base+16))
  130. #define SJA1000_Rx1 (*(volatile u_char*) (sja_base+17))
  131. #define SJA1000_Rx2 (*(volatile u_char*) (sja_base+18))
  132. #define SJA1000_Rx3 (*(volatile u_char*) (sja_base+19))
  133. #define SJA1000_Rx4 (*(volatile u_char*) (sja_base+20))
  134. #define SJA1000_Rx5 (*(volatile u_char*) (sja_base+21))
  135. #define SJA1000_Rx6 (*(volatile u_char*) (sja_base+22))
  136. #define SJA1000_Rx7 (*(volatile u_char*) (sja_base+23))
  137. #define SJA1000_Rx8 (*(volatile u_char*) (sja_base+24))
  138. #define SJA1000_Rx9 (*(volatile u_char*) (sja_base+25))
  139. #define SJA1000_Rx10 (*(volatile u_char*) (sja_base+26))
  140. #define SJA1000_Rx11 (*(volatile u_char*) (sja_base+27))
  141. #define SJA1000_Rx12 (*(volatile u_char*) (sja_base+28))
  142. // address definitions of the Tx-Buffer
  143. /* write only addresses */
  144. #define TestReg (*(volatile u_char*) (sja_base+9))
  145. #define SJA1000_TxFrameInfo (*(volatile u_char*) (sja_base+16))
  146. #define SJA1000_Tx1 (*(volatile u_char*) (sja_base+17))
  147. #define SJA1000_Tx2 (*(volatile u_char*) (sja_base+18))
  148. #define SJA1000_Tx3 (*(volatile u_char*) (sja_base+19))
  149. #define SJA1000_Tx4 (*(volatile u_char*) (sja_base+20))
  150. #define SJA1000_Tx5 (*(volatile u_char*) (sja_base+21))
  151. #define SJA1000_Tx6 (*(volatile u_char*) (sja_base+22))
  152. #define SJA1000_Tx7 (*(volatile u_char*) (sja_base+23))
  153. #define SJA1000_Tx8 (*(volatile u_char*) (sja_base+24))
  154. #define SJA1000_Tx9 (*(volatile u_char*) (sja_base+25))
  155. #define SJA1000_Tx10 (*(volatile u_char*) (sja_base+26))
  156. #define SJA1000_Tx11 (*(volatile u_char*) (sja_base+27))
  157. #define SJA1000_Tx12 (*(volatile u_char*) (sja_base+28))
  158. /* read only addresses */
  159. #define SJA1000_TxFrameInfoRd (*(volatile u_char*) (sja_base+96))
  160. #define SJA1000_TxRd1 (*(volatile u_char*) (sja_base+97))
  161. #define SJA1000_TxRd2 (*(volatile u_char*) (sja_base+98))
  162. #define SJA1000_TxRd3 (*(volatile u_char*) (sja_base+99))
  163. #define SJA1000_TxRd4 (*(volatile u_char*) (sja_base+100))
  164. #define SJA1000_TxRd5 (*(volatile u_char*) (sja_base+101))
  165. #define SJA1000_TxRd6 (*(volatile u_char*) (sja_base+102))
  166. #define SJA1000_TxRd7 (*(volatile u_char*) (sja_base+103))
  167. #define SJA1000_TxRd8 (*(volatile u_char*) (sja_base+104))
  168. #define SJA1000_TxRd9 (*(volatile u_char*) (sja_base+105))
  169. #define SJA1000_TxRd10 (*(volatile u_char*) (sja_base+106))
  170. #define SJA1000_TxRd11 (*(volatile u_char*) (sja_base+107))
  171. #define SJA1000_TxRd12 (*(volatile u_char*) (sja_base+108))
  172. // address definitions of Other Registers
  173. #define SJA1000_ArbLostCap (*(volatile u_char*) (sja_base+11))
  174. #define SJA1000_ErrCodeCap (*(volatile u_char*) (sja_base+12))
  175. #define SJA1000_ErrWarnLimit (*(volatile u_char*) (sja_base+13))
  176. #define SJA1000_RxErrCount (*(volatile u_char*) (sja_base+14))
  177. #define SJA1000_TxErrCount (*(volatile u_char*) (sja_base+15))
  178. #define SJA1000_RxMsgCount (*(volatile u_char*) (sja_base+29))
  179. #define SJA1000_RxBufStartAdr (*(volatile u_char*) (sja_base+30))
  180. // address and bit definitions for the Clock Divider Register
  181. #define SJA1000_CLK_DIV (*(volatile u_char*) (sja_base+31))
  182. #define DivBy1 0x07 // CLKOUT = oscillator frequency
  183. #define DivBy2 0x00 // CLKOUT = 1/2 oscillator frequency
  184. #define ClkOff_Bit 0x08 // clock off bit, control of the CLK OUT pin
  185. #define RXINTEN_Bit 0x20 // pin TX1 used for receive interrupt
  186. #define CBP_Bit 0x40 // CAN comparator bypass control bit
  187. #define CANMode_Bit 0x80 // CAN mode definition bit
  188. #define ClkOutMode 0x03 // clock output mode
  189. // output pin configuration for TX1
  190. #define OCPOL1_Bit 0x20 // output polarity control bit
  191. #define Tx1Float 0x00 // configured as float
  192. #define Tx1PullDn 0x40 // configured as pull-down
  193. #define Tx1PullUp 0x80 // configured as pull-up
  194. #define Tx1PshPull 0xC0 // configured as push/pull
  195. // output pin configuration for TX0
  196. #define OCPOL0_Bit 0x04 // output polarity control bit
  197. #define Tx0Float 0x00 // configured as float
  198. #define Tx0PullDn 0x08 // configured as pull-down
  199. // Some sample konstants
  200. /* bus timing values for
  201. - bit-rate : 1 MBit/s
  202. - oscillator frequency : 16 MHz, 0,1%
  203. - maximum tolerated propagation delay : 623 ns
  204. - minimum requested propagation delay : 23 ns
  205. */
  206. #define Presc_MB_16 0x00 // baud rate prescaler : 1
  207. #define SJW_MB_16 0x00 // SJW : 1
  208. #define TSEG1_MB_16 0x04 // TSEG1 : 5
  209. #define TSEG2_MB_16 0x10 // TSEG2 : 2
  210. // Error codes
  211. #define errCAN_INVALID_BAUD 7
  212. #define CAN_OK 0
  213. #define CAN_ERR 1
  214. #define CAN_INIT_SPEED_ERR 1
  215. #define CAN_NOT_INITIATED 1
  216. #define CAN_NOT_STARTED 1
  217. #define CAN_TXBUF_FULL 2
  218. #define CAN_RXBUF_EMPTY 2
  219. // Flag bits
  220. #define CAN_LOST_FRAME 0x01
  221. #define CAN_BUS_OFF 0x02
  222. // Frame Flag bits
  223. #define CAN_29 0x80
  224. #define CAN_RTR 0x40
  225. #define ClrIntEnSJA 0x00
  226. extern NUTDEVICE devSJA1000;
  227. #endif
  228. /*@}*/