hw_i2c.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. //*****************************************************************************
  2. //
  3. // hw_i2c.h - Macros used when accessing the I2C master and slave hardware.
  4. //
  5. // Copyright (c) 2005-2009 Luminary Micro, Inc. All rights reserved.
  6. // Software License Agreement
  7. //
  8. // Luminary Micro, Inc. (LMI) is supplying this software for use solely and
  9. // exclusively on LMI's microcontroller products.
  10. //
  11. // The software is owned by LMI and/or its suppliers, and is protected under
  12. // applicable copyright laws. All rights are reserved. You may not combine
  13. // this software with "viral" open-source software in order to form a larger
  14. // program. Any use in violation of the foregoing restrictions may subject
  15. // the user to criminal sanctions under applicable laws, as well as to civil
  16. // liability for the breach of the terms and conditions of this license.
  17. //
  18. // THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
  19. // OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
  20. // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
  21. // LMI SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
  22. // CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
  23. //
  24. // This is part of revision 4694 of the Stellaris Firmware Development Package.
  25. //
  26. //*****************************************************************************
  27. #ifndef __HW_I2C_H__
  28. #define __HW_I2C_H__
  29. //*****************************************************************************
  30. //
  31. // The following are defines for the offsets between the I2C master and slave
  32. // registers.
  33. //
  34. //*****************************************************************************
  35. #define I2C_O_MSA 0x00000000 // I2C Master Slave Address
  36. #define I2C_O_SOAR 0x00000000 // I2C Slave Own Address
  37. #define I2C_O_SCSR 0x00000004 // I2C Slave Control/Status
  38. #define I2C_O_MCS 0x00000004 // I2C Master Control/Status
  39. #define I2C_O_SDR 0x00000008 // I2C Slave Data
  40. #define I2C_O_MDR 0x00000008 // I2C Master Data
  41. #define I2C_O_MTPR 0x0000000C // I2C Master Timer Period
  42. #define I2C_O_SIMR 0x0000000C // I2C Slave Interrupt Mask
  43. #define I2C_O_SRIS 0x00000010 // I2C Slave Raw Interrupt Status
  44. #define I2C_O_MIMR 0x00000010 // I2C Master Interrupt Mask
  45. #define I2C_O_MRIS 0x00000014 // I2C Master Raw Interrupt Status
  46. #define I2C_O_SMIS 0x00000014 // I2C Slave Masked Interrupt
  47. // Status
  48. #define I2C_O_SICR 0x00000018 // I2C Slave Interrupt Clear
  49. #define I2C_O_MMIS 0x00000018 // I2C Master Masked Interrupt
  50. // Status
  51. #define I2C_O_MICR 0x0000001C // I2C Master Interrupt Clear
  52. #define I2C_O_MCR 0x00000020 // I2C Master Configuration
  53. //*****************************************************************************
  54. //
  55. // The following are defines for the bit fields in the I2C_O_MSA register.
  56. //
  57. //*****************************************************************************
  58. #define I2C_MSA_SA_M 0x000000FE // I2C Slave Address.
  59. #define I2C_MSA_RS 0x00000001 // Receive not Send
  60. #define I2C_MSA_SA_S 1
  61. //*****************************************************************************
  62. //
  63. // The following are defines for the bit fields in the I2C_O_SOAR register.
  64. //
  65. //*****************************************************************************
  66. #define I2C_SOAR_OAR_M 0x0000007F // I2C Slave Own Address.
  67. #define I2C_SOAR_OAR_S 0
  68. //*****************************************************************************
  69. //
  70. // The following are defines for the bit fields in the I2C_O_SCSR register.
  71. //
  72. //*****************************************************************************
  73. #define I2C_SCSR_FBR 0x00000004 // First Byte Received.
  74. #define I2C_SCSR_TREQ 0x00000002 // Transmit Request.
  75. #define I2C_SCSR_DA 0x00000001 // Device Active.
  76. #define I2C_SCSR_RREQ 0x00000001 // Receive Request.
  77. //*****************************************************************************
  78. //
  79. // The following are defines for the bit fields in the I2C_O_MCS register.
  80. //
  81. //*****************************************************************************
  82. #define I2C_MCS_BUSBSY 0x00000040 // Bus Busy.
  83. #define I2C_MCS_IDLE 0x00000020 // I2C Idle.
  84. #define I2C_MCS_ARBLST 0x00000010 // Arbitration Lost.
  85. #define I2C_MCS_ACK 0x00000008 // Data Acknowledge Enable.
  86. #define I2C_MCS_DATACK 0x00000008 // Acknowledge Data.
  87. #define I2C_MCS_ADRACK 0x00000004 // Acknowledge Address.
  88. #define I2C_MCS_STOP 0x00000004 // Generate STOP.
  89. #define I2C_MCS_START 0x00000002 // Generate START.
  90. #define I2C_MCS_ERROR 0x00000002 // Error.
  91. #define I2C_MCS_RUN 0x00000001 // I2C Master Enable.
  92. #define I2C_MCS_BUSY 0x00000001 // I2C Busy.
  93. //*****************************************************************************
  94. //
  95. // The following are defines for the bit fields in the I2C_O_SDR register.
  96. //
  97. //*****************************************************************************
  98. #define I2C_SDR_DATA_M 0x000000FF // Data for Transfer.
  99. #define I2C_SDR_DATA_S 0
  100. //*****************************************************************************
  101. //
  102. // The following are defines for the bit fields in the I2C_O_MDR register.
  103. //
  104. //*****************************************************************************
  105. #define I2C_MDR_DATA_M 0x000000FF // Data Transferred.
  106. #define I2C_MDR_DATA_S 0
  107. //*****************************************************************************
  108. //
  109. // The following are defines for the bit fields in the I2C_O_MTPR register.
  110. //
  111. //*****************************************************************************
  112. #define I2C_MTPR_TPR_M 0x000000FF // SCL Clock Period.
  113. #define I2C_MTPR_TPR_S 0
  114. //*****************************************************************************
  115. //
  116. // The following are defines for the bit fields in the I2C_O_SIMR register.
  117. //
  118. //*****************************************************************************
  119. #define I2C_SIMR_STOPIM 0x00000004 // Stop Condition Interrupt Mask.
  120. #define I2C_SIMR_STARTIM 0x00000002 // Start Condition Interrupt Mask.
  121. #define I2C_SIMR_DATAIM 0x00000001 // Data Interrupt Mask.
  122. //*****************************************************************************
  123. //
  124. // The following are defines for the bit fields in the I2C_O_SRIS register.
  125. //
  126. //*****************************************************************************
  127. #define I2C_SRIS_STOPRIS 0x00000004 // Stop Condition Raw Interrupt
  128. // Status.
  129. #define I2C_SRIS_STARTRIS 0x00000002 // Start Condition Raw Interrupt
  130. // Status.
  131. #define I2C_SRIS_DATARIS 0x00000001 // Data Raw Interrupt Status.
  132. //*****************************************************************************
  133. //
  134. // The following are defines for the bit fields in the I2C_O_MIMR register.
  135. //
  136. //*****************************************************************************
  137. #define I2C_MIMR_IM 0x00000001 // Interrupt Mask.
  138. //*****************************************************************************
  139. //
  140. // The following are defines for the bit fields in the I2C_O_MRIS register.
  141. //
  142. //*****************************************************************************
  143. #define I2C_MRIS_RIS 0x00000001 // Raw Interrupt Status.
  144. //*****************************************************************************
  145. //
  146. // The following are defines for the bit fields in the I2C_O_SMIS register.
  147. //
  148. //*****************************************************************************
  149. #define I2C_SMIS_STOPMIS 0x00000004 // Stop Condition Masked Interrupt
  150. // Status.
  151. #define I2C_SMIS_STARTMIS 0x00000002 // Start Condition Masked Interrupt
  152. // Status.
  153. #define I2C_SMIS_DATAMIS 0x00000001 // Data Masked Interrupt Status.
  154. //*****************************************************************************
  155. //
  156. // The following are defines for the bit fields in the I2C_O_SICR register.
  157. //
  158. //*****************************************************************************
  159. #define I2C_SICR_STOPIC 0x00000004 // Stop Condition Interrupt Clear.
  160. #define I2C_SICR_STARTIC 0x00000002 // Start Condition Interrupt Clear.
  161. #define I2C_SICR_DATAIC 0x00000001 // Data Clear Interrupt.
  162. //*****************************************************************************
  163. //
  164. // The following are defines for the bit fields in the I2C_O_MMIS register.
  165. //
  166. //*****************************************************************************
  167. #define I2C_MMIS_MIS 0x00000001 // Masked Interrupt Status.
  168. //*****************************************************************************
  169. //
  170. // The following are defines for the bit fields in the I2C_O_MICR register.
  171. //
  172. //*****************************************************************************
  173. #define I2C_MICR_IC 0x00000001 // Interrupt Clear.
  174. //*****************************************************************************
  175. //
  176. // The following are defines for the bit fields in the I2C_O_MCR register.
  177. //
  178. //*****************************************************************************
  179. #define I2C_MCR_SFE 0x00000020 // I2C Slave Function Enable.
  180. #define I2C_MCR_MFE 0x00000010 // I2C Master Function Enable.
  181. #define I2C_MCR_LPBK 0x00000001 // I2C Loopback.
  182. //*****************************************************************************
  183. //
  184. // The following definitions are deprecated.
  185. //
  186. //*****************************************************************************
  187. #ifndef DEPRECATED
  188. //*****************************************************************************
  189. //
  190. // The following are deprecated defines for the offsets between the I2C master
  191. // and slave registers.
  192. //
  193. //*****************************************************************************
  194. #define I2C_O_SLAVE 0x00000800 // Offset from master to slave
  195. //*****************************************************************************
  196. //
  197. // The following are deprecated defines for the I2C master register offsets.
  198. //
  199. //*****************************************************************************
  200. #define I2C_MASTER_O_SA 0x00000000 // Slave address register
  201. #define I2C_MASTER_O_CS 0x00000004 // Control and Status register
  202. #define I2C_MASTER_O_DR 0x00000008 // Data register
  203. #define I2C_MASTER_O_TPR 0x0000000C // Timer period register
  204. #define I2C_MASTER_O_IMR 0x00000010 // Interrupt mask register
  205. #define I2C_MASTER_O_RIS 0x00000014 // Raw interrupt status register
  206. #define I2C_MASTER_O_MIS 0x00000018 // Masked interrupt status reg
  207. #define I2C_MASTER_O_MICR 0x0000001C // Interrupt clear register
  208. #define I2C_MASTER_O_CR 0x00000020 // Configuration register
  209. //*****************************************************************************
  210. //
  211. // The following are deprecated defines for the I2C slave register offsets.
  212. //
  213. //*****************************************************************************
  214. #define I2C_SLAVE_O_SICR 0x00000018 // Interrupt clear register
  215. #define I2C_SLAVE_O_MIS 0x00000014 // Masked interrupt status reg
  216. #define I2C_SLAVE_O_RIS 0x00000010 // Raw interrupt status register
  217. #define I2C_SLAVE_O_IM 0x0000000C // Interrupt mask register
  218. #define I2C_SLAVE_O_DR 0x00000008 // Data register
  219. #define I2C_SLAVE_O_CSR 0x00000004 // Control/Status register
  220. #define I2C_SLAVE_O_OAR 0x00000000 // Own address register
  221. //*****************************************************************************
  222. //
  223. // The following are deprecated defines for the bit fields in the I2C master
  224. // slave address register.
  225. //
  226. //*****************************************************************************
  227. #define I2C_MASTER_SA_SA_MASK 0x000000FE // Slave address
  228. #define I2C_MASTER_SA_RS 0x00000001 // Receive/send
  229. #define I2C_MASTER_SA_SA_SHIFT 1
  230. //*****************************************************************************
  231. //
  232. // The following are deprecated defines for the bit fields in the I2C Master
  233. // Control and Status register.
  234. //
  235. //*****************************************************************************
  236. #define I2C_MASTER_CS_BUS_BUSY 0x00000040 // Bus busy
  237. #define I2C_MASTER_CS_IDLE 0x00000020 // Idle
  238. #define I2C_MASTER_CS_ERR_MASK 0x0000001C
  239. #define I2C_MASTER_CS_BUSY 0x00000001 // Controller is TX/RX data
  240. #define I2C_MASTER_CS_ERROR 0x00000002 // Error occurred
  241. #define I2C_MASTER_CS_ADDR_ACK 0x00000004 // Address byte not acknowledged
  242. #define I2C_MASTER_CS_DATA_ACK 0x00000008 // Data byte not acknowledged
  243. #define I2C_MASTER_CS_ARB_LOST 0x00000010 // Lost arbitration
  244. #define I2C_MASTER_CS_ACK 0x00000008 // Acknowlegde
  245. #define I2C_MASTER_CS_STOP 0x00000004 // Stop
  246. #define I2C_MASTER_CS_START 0x00000002 // Start
  247. #define I2C_MASTER_CS_RUN 0x00000001 // Run
  248. //*****************************************************************************
  249. //
  250. // The following are deprecated defines for the values used in determining the
  251. // contents of the I2C Master Timer Period register.
  252. //
  253. //*****************************************************************************
  254. #define I2C_SCL_FAST 400000 // SCL fast frequency
  255. #define I2C_SCL_STANDARD 100000 // SCL standard frequency
  256. #define I2C_MASTER_TPR_SCL_LP 0x00000006 // SCL low period
  257. #define I2C_MASTER_TPR_SCL_HP 0x00000004 // SCL high period
  258. #define I2C_MASTER_TPR_SCL (I2C_MASTER_TPR_SCL_HP + I2C_MASTER_TPR_SCL_LP)
  259. //*****************************************************************************
  260. //
  261. // The following are deprecated defines for the bit fields in the I2C Master
  262. // Interrupt Mask register.
  263. //
  264. //*****************************************************************************
  265. #define I2C_MASTER_IMR_IM 0x00000001 // Master interrupt mask
  266. //*****************************************************************************
  267. //
  268. // The following are deprecated defines for the bit fields in the I2C Master
  269. // Raw Interrupt Status register.
  270. //
  271. //*****************************************************************************
  272. #define I2C_MASTER_RIS_RIS 0x00000001 // Master raw interrupt status
  273. //*****************************************************************************
  274. //
  275. // The following are deprecated defines for the bit fields in the I2C Master
  276. // Masked Interrupt Status register.
  277. //
  278. //*****************************************************************************
  279. #define I2C_MASTER_MIS_MIS 0x00000001 // Master masked interrupt status
  280. //*****************************************************************************
  281. //
  282. // The following are deprecated defines for the bit fields in the I2C Master
  283. // Interrupt Clear register.
  284. //
  285. //*****************************************************************************
  286. #define I2C_MASTER_MICR_IC 0x00000001 // Master interrupt clear
  287. //*****************************************************************************
  288. //
  289. // The following are deprecated defines for the bit fields in the I2C Master
  290. // Configuration register.
  291. //
  292. //*****************************************************************************
  293. #define I2C_MASTER_CR_SFE 0x00000020 // Slave function enable
  294. #define I2C_MASTER_CR_MFE 0x00000010 // Master function enable
  295. #define I2C_MASTER_CR_LPBK 0x00000001 // Loopback enable
  296. //*****************************************************************************
  297. //
  298. // The following are deprecated defines for the bit fields in the I2C Slave Own
  299. // Address register.
  300. //
  301. //*****************************************************************************
  302. #define I2C_SLAVE_SOAR_OAR_MASK 0x0000007F // Slave address
  303. //*****************************************************************************
  304. //
  305. // The following are deprecated defines for the bit fields in the I2C Slave
  306. // Control/Status register.
  307. //
  308. //*****************************************************************************
  309. #define I2C_SLAVE_CSR_FBR 0x00000004 // First byte received from master
  310. #define I2C_SLAVE_CSR_TREQ 0x00000002 // Transmit request received
  311. #define I2C_SLAVE_CSR_DA 0x00000001 // Enable the device
  312. #define I2C_SLAVE_CSR_RREQ 0x00000001 // Receive data from I2C master
  313. //*****************************************************************************
  314. //
  315. // The following are deprecated defines for the bit fields in the I2C Slave
  316. // Interrupt Mask register.
  317. //
  318. //*****************************************************************************
  319. #define I2C_SLAVE_IMR_IM 0x00000001 // Slave interrupt mask
  320. //*****************************************************************************
  321. //
  322. // The following are deprecated defines for the bit fields in the I2C Slave Raw
  323. // Interrupt Status register.
  324. //
  325. //*****************************************************************************
  326. #define I2C_SLAVE_RIS_RIS 0x00000001 // Slave raw interrupt status
  327. //*****************************************************************************
  328. //
  329. // The following are deprecated defines for the bit fields in the I2C Slave
  330. // Masked Interrupt Status register.
  331. //
  332. //*****************************************************************************
  333. #define I2C_SLAVE_MIS_MIS 0x00000001 // Slave masked interrupt status
  334. //*****************************************************************************
  335. //
  336. // The following are deprecated defines for the bit fields in the I2C Slave
  337. // Interrupt Clear register.
  338. //
  339. //*****************************************************************************
  340. #define I2C_SLAVE_SICR_IC 0x00000001 // Slave interrupt clear
  341. //*****************************************************************************
  342. //
  343. // The following are deprecated defines for the bit fields in the I2C_O_SIMR
  344. // register.
  345. //
  346. //*****************************************************************************
  347. #define I2C_SIMR_IM 0x00000001 // Interrupt Mask.
  348. //*****************************************************************************
  349. //
  350. // The following are deprecated defines for the bit fields in the I2C_O_SRIS
  351. // register.
  352. //
  353. //*****************************************************************************
  354. #define I2C_SRIS_RIS 0x00000001 // Raw Interrupt Status.
  355. //*****************************************************************************
  356. //
  357. // The following are deprecated defines for the bit fields in the I2C_O_SMIS
  358. // register.
  359. //
  360. //*****************************************************************************
  361. #define I2C_SMIS_MIS 0x00000001 // Masked Interrupt Status.
  362. //*****************************************************************************
  363. //
  364. // The following are deprecated defines for the bit fields in the I2C_O_SICR
  365. // register.
  366. //
  367. //*****************************************************************************
  368. #define I2C_SICR_IC 0x00000001 // Clear Interrupt.
  369. #endif
  370. #endif // __HW_I2C_H__