regsi2c.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. /*
  2. * Copyright (c) 2012, Freescale Semiconductor, Inc.
  3. * All rights reserved.
  4. *
  5. * THIS SOFTWARE IS PROVIDED BY FREESCALE "AS IS" AND ANY EXPRESS OR IMPLIED
  6. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  7. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
  8. * SHALL FREESCALE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  9. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
  10. * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  11. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  12. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  13. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  14. * OF SUCH DAMAGE.
  15. */
  16. /*
  17. * WARNING! DO NOT EDIT THIS FILE DIRECTLY!
  18. *
  19. * This file was generated automatically and any changes may be lost.
  20. */
  21. #ifndef __HW_I2C_REGISTERS_H__
  22. #define __HW_I2C_REGISTERS_H__
  23. #include "regs.h"
  24. /*
  25. * i.MX6SDL I2C
  26. *
  27. * I2C
  28. *
  29. * Registers defined in this header file:
  30. * - HW_I2C_IADR - I2C Address Register
  31. * - HW_I2C_IFDR - I2C Frequency Divider Register
  32. * - HW_I2C_I2CR - I2C Control Register
  33. * - HW_I2C_I2SR - I2C Status Register
  34. * - HW_I2C_I2DR - I2C Data I/O Register
  35. *
  36. * - hw_i2c_t - Struct containing all module registers.
  37. */
  38. //! @name Module base addresses
  39. //@{
  40. #ifndef REGS_I2C_BASE
  41. #define HW_I2C_INSTANCE_COUNT (4) //!< Number of instances of the I2C module.
  42. #define HW_I2C1 (1) //!< Instance number for I2C1.
  43. #define HW_I2C2 (2) //!< Instance number for I2C2.
  44. #define HW_I2C3 (3) //!< Instance number for I2C3.
  45. #define HW_I2C4 (4) //!< Instance number for I2C4.
  46. #define REGS_I2C1_BASE (0x021a0000) //!< Base address for I2C instance number 1.
  47. #define REGS_I2C2_BASE (0x021a4000) //!< Base address for I2C instance number 2.
  48. #define REGS_I2C3_BASE (0x021a8000) //!< Base address for I2C instance number 3.
  49. #define REGS_I2C4_BASE (0x021f8000) //!< Base address for I2C instance number 4.
  50. //! @brief Get the base address of I2C by instance number.
  51. //! @param x I2C instance number, from 1 through 4.
  52. #define REGS_I2C_BASE(x) ( (x) == HW_I2C1 ? REGS_I2C1_BASE : (x) == HW_I2C2 ? REGS_I2C2_BASE : (x) == HW_I2C3 ? REGS_I2C3_BASE : (x) == HW_I2C4 ? REGS_I2C4_BASE : 0x00d00000)
  53. //! @brief Get the instance number given a base address.
  54. //! @param b Base address for an instance of I2C.
  55. #define REGS_I2C_INSTANCE(b) ( (b) == REGS_I2C1_BASE ? HW_I2C1 : (b) == REGS_I2C2_BASE ? HW_I2C2 : (b) == REGS_I2C3_BASE ? HW_I2C3 : (b) == REGS_I2C4_BASE ? HW_I2C4 : 0)
  56. #endif
  57. //@}
  58. //-------------------------------------------------------------------------------------------
  59. // HW_I2C_IADR - I2C Address Register
  60. //-------------------------------------------------------------------------------------------
  61. #ifndef __LANGUAGE_ASM__
  62. /*!
  63. * @brief HW_I2C_IADR - I2C Address Register (RW)
  64. *
  65. * Reset value: 0x0000
  66. */
  67. typedef union _hw_i2c_iadr
  68. {
  69. reg16_t U;
  70. struct _hw_i2c_iadr_bitfields
  71. {
  72. unsigned short RESERVED0 : 1; //!< [0] Reserved
  73. unsigned short ADR : 7; //!< [7:1] Slave address.
  74. unsigned short RESERVED1 : 8; //!< [15:8] Reserved
  75. } B;
  76. } hw_i2c_iadr_t;
  77. #endif
  78. /*!
  79. * @name Constants and macros for entire I2C_IADR register
  80. */
  81. //@{
  82. #define HW_I2C_IADR_ADDR(x) (REGS_I2C_BASE(x) + 0x0)
  83. #ifndef __LANGUAGE_ASM__
  84. #define HW_I2C_IADR(x) (*(volatile hw_i2c_iadr_t *) HW_I2C_IADR_ADDR(x))
  85. #define HW_I2C_IADR_RD(x) (HW_I2C_IADR(x).U)
  86. #define HW_I2C_IADR_WR(x, v) (HW_I2C_IADR(x).U = (v))
  87. #define HW_I2C_IADR_SET(x, v) (HW_I2C_IADR_WR(x, HW_I2C_IADR_RD(x) | (v)))
  88. #define HW_I2C_IADR_CLR(x, v) (HW_I2C_IADR_WR(x, HW_I2C_IADR_RD(x) & ~(v)))
  89. #define HW_I2C_IADR_TOG(x, v) (HW_I2C_IADR_WR(x, HW_I2C_IADR_RD(x) ^ (v)))
  90. #endif
  91. //@}
  92. /*
  93. * constants & macros for individual I2C_IADR bitfields
  94. */
  95. /*! @name Register I2C_IADR, field ADR[7:1] (RW)
  96. *
  97. * Slave address. Contains the specific slave address to be used by the I2C. Slave mode is the
  98. * default I2C mode for an address match on the bus. The I2C_IADR holds the address the I2C responds
  99. * to when addressed as a slave. The slave address is not the address sent on the bus during the
  100. * address transfer. The register is not reset by a software reset.
  101. */
  102. //@{
  103. #define BP_I2C_IADR_ADR (1) //!< Bit position for I2C_IADR_ADR.
  104. #define BM_I2C_IADR_ADR (0x000000fe) //!< Bit mask for I2C_IADR_ADR.
  105. //! @brief Get value of I2C_IADR_ADR from a register value.
  106. #define BG_I2C_IADR_ADR(r) ((__REG_VALUE_TYPE((r), reg16_t) & BM_I2C_IADR_ADR) >> BP_I2C_IADR_ADR)
  107. //! @brief Format value for bitfield I2C_IADR_ADR.
  108. #define BF_I2C_IADR_ADR(v) ((__REG_VALUE_TYPE((v), reg16_t) << BP_I2C_IADR_ADR) & BM_I2C_IADR_ADR)
  109. #ifndef __LANGUAGE_ASM__
  110. //! @brief Set the ADR field to a new value.
  111. #define BW_I2C_IADR_ADR(x, v) (HW_I2C_IADR_WR(x, (HW_I2C_IADR_RD(x) & ~BM_I2C_IADR_ADR) | BF_I2C_IADR_ADR(v)))
  112. #endif
  113. //@}
  114. //-------------------------------------------------------------------------------------------
  115. // HW_I2C_IFDR - I2C Frequency Divider Register
  116. //-------------------------------------------------------------------------------------------
  117. #ifndef __LANGUAGE_ASM__
  118. /*!
  119. * @brief HW_I2C_IFDR - I2C Frequency Divider Register (RW)
  120. *
  121. * Reset value: 0x0000
  122. *
  123. * The I2C_IFDR provides a programmable prescaler to configure the clock for bit-rate selection. The
  124. * register does not get reset by software reset. The following table describes the Divider values
  125. * for register field "IC". Table below describes the register values for field "IC". I2C_IFDR
  126. * Register Field Values IC Divider IC Divider IC Divider IC Divider 0x00 30 0x10 288 0x20 22 0x30
  127. * 160 0x01 32 0x11 320 0x21 24 0x31 192 0x02 36 0x12 384 0x22 26 0x32 224 0x03 42 0x13 480 0x23 28
  128. * 0x33 256 0x04 48 0x14 576 0x24 32 0x34 320 0x05 52 0x15 640 0x25 36 0x35 384 0x06 60 0x16 768
  129. * 0x26 40 0x36 448 0x07 72 0x17 960 0x27 44 0x37 512 0x08 80 0x18 1152 0x28 48 0x38 640 0x09 88
  130. * 0x19 1280 0x29 56 0x39 768 0x0A 104 0x1A 1536 0x2A 64 0x3A 896 0x0B 128 0x1B 1920 0x2B 72 0x3B
  131. * 1024 0x0C 144 0x1C 2304 0x2C 80 0x3C 1280 0x0D 160 0x1D 2560 0x2D 96 0x3D 1536 0x0E 192 0x1E 3072
  132. * 0x2E 112 0x3E 1792 0x0F 240 0x1F 3840 0x2F 128 0x3F 2048
  133. */
  134. typedef union _hw_i2c_ifdr
  135. {
  136. reg16_t U;
  137. struct _hw_i2c_ifdr_bitfields
  138. {
  139. unsigned short IC : 6; //!< [5:0] I2C clock rate.
  140. unsigned short RESERVED0 : 10; //!< [15:6] Reserved
  141. } B;
  142. } hw_i2c_ifdr_t;
  143. #endif
  144. /*!
  145. * @name Constants and macros for entire I2C_IFDR register
  146. */
  147. //@{
  148. #define HW_I2C_IFDR_ADDR(x) (REGS_I2C_BASE(x) + 0x4)
  149. #ifndef __LANGUAGE_ASM__
  150. #define HW_I2C_IFDR(x) (*(volatile hw_i2c_ifdr_t *) HW_I2C_IFDR_ADDR(x))
  151. #define HW_I2C_IFDR_RD(x) (HW_I2C_IFDR(x).U)
  152. #define HW_I2C_IFDR_WR(x, v) (HW_I2C_IFDR(x).U = (v))
  153. #define HW_I2C_IFDR_SET(x, v) (HW_I2C_IFDR_WR(x, HW_I2C_IFDR_RD(x) | (v)))
  154. #define HW_I2C_IFDR_CLR(x, v) (HW_I2C_IFDR_WR(x, HW_I2C_IFDR_RD(x) & ~(v)))
  155. #define HW_I2C_IFDR_TOG(x, v) (HW_I2C_IFDR_WR(x, HW_I2C_IFDR_RD(x) ^ (v)))
  156. #endif
  157. //@}
  158. /*
  159. * constants & macros for individual I2C_IFDR bitfields
  160. */
  161. /*! @name Register I2C_IFDR, field IC[5:0] (RW)
  162. *
  163. * I2C clock rate. Pre-scales the clock for bit-rate selection. Due to potentially slow I2Cn_SCL and
  164. * I2Cn_SDA rise and fall times, bus signals are sampled at the prescaler frequency. The serial bit
  165. * clock frequency may be lower than IPG_CLK_ROOT divided by the divider shown in the I2C Data I/O
  166. * Register. The IC value should not be changed during the data transfer, however, it can be changed
  167. * before REPEAT START or START programming sequence in I2C. The I2C protocol supports bit rates up
  168. * to 400 kbps. The IC bits need to be programmed in accordance with this constraint.
  169. */
  170. //@{
  171. #define BP_I2C_IFDR_IC (0) //!< Bit position for I2C_IFDR_IC.
  172. #define BM_I2C_IFDR_IC (0x0000003f) //!< Bit mask for I2C_IFDR_IC.
  173. //! @brief Get value of I2C_IFDR_IC from a register value.
  174. #define BG_I2C_IFDR_IC(r) ((__REG_VALUE_TYPE((r), reg16_t) & BM_I2C_IFDR_IC) >> BP_I2C_IFDR_IC)
  175. //! @brief Format value for bitfield I2C_IFDR_IC.
  176. #define BF_I2C_IFDR_IC(v) ((__REG_VALUE_TYPE((v), reg16_t) << BP_I2C_IFDR_IC) & BM_I2C_IFDR_IC)
  177. #ifndef __LANGUAGE_ASM__
  178. //! @brief Set the IC field to a new value.
  179. #define BW_I2C_IFDR_IC(x, v) (HW_I2C_IFDR_WR(x, (HW_I2C_IFDR_RD(x) & ~BM_I2C_IFDR_IC) | BF_I2C_IFDR_IC(v)))
  180. #endif
  181. //@}
  182. //-------------------------------------------------------------------------------------------
  183. // HW_I2C_I2CR - I2C Control Register
  184. //-------------------------------------------------------------------------------------------
  185. #ifndef __LANGUAGE_ASM__
  186. /*!
  187. * @brief HW_I2C_I2CR - I2C Control Register (RW)
  188. *
  189. * Reset value: 0x0000
  190. *
  191. * The I2C_I2CR is used to enable the I2C and the I2C interrupt. It also contains bits that govern
  192. * operation as a slave or a master.
  193. */
  194. typedef union _hw_i2c_i2cr
  195. {
  196. reg16_t U;
  197. struct _hw_i2c_i2cr_bitfields
  198. {
  199. unsigned short RESERVED0 : 2; //!< [1:0] Reserved
  200. unsigned short RSTA : 1; //!< [2] Repeat start.
  201. unsigned short TXAK : 1; //!< [3] Transmit acknowledge enable.
  202. unsigned short MTX : 1; //!< [4] Transmit/receive mode select bit.
  203. unsigned short MSTA : 1; //!< [5] Master/slave mode select bit.
  204. unsigned short IIEN : 1; //!< [6] I2C interrupt enable.
  205. unsigned short IEN : 1; //!< [7] I2C enable.
  206. unsigned short RESERVED1 : 8; //!< [15:8] Reserved
  207. } B;
  208. } hw_i2c_i2cr_t;
  209. #endif
  210. /*!
  211. * @name Constants and macros for entire I2C_I2CR register
  212. */
  213. //@{
  214. #define HW_I2C_I2CR_ADDR(x) (REGS_I2C_BASE(x) + 0x8)
  215. #ifndef __LANGUAGE_ASM__
  216. #define HW_I2C_I2CR(x) (*(volatile hw_i2c_i2cr_t *) HW_I2C_I2CR_ADDR(x))
  217. #define HW_I2C_I2CR_RD(x) (HW_I2C_I2CR(x).U)
  218. #define HW_I2C_I2CR_WR(x, v) (HW_I2C_I2CR(x).U = (v))
  219. #define HW_I2C_I2CR_SET(x, v) (HW_I2C_I2CR_WR(x, HW_I2C_I2CR_RD(x) | (v)))
  220. #define HW_I2C_I2CR_CLR(x, v) (HW_I2C_I2CR_WR(x, HW_I2C_I2CR_RD(x) & ~(v)))
  221. #define HW_I2C_I2CR_TOG(x, v) (HW_I2C_I2CR_WR(x, HW_I2C_I2CR_RD(x) ^ (v)))
  222. #endif
  223. //@}
  224. /*
  225. * constants & macros for individual I2C_I2CR bitfields
  226. */
  227. /*! @name Register I2C_I2CR, field RSTA[2] (WORZ)
  228. *
  229. * Repeat start. Always reads as 0. Attempting a repeat start without bus mastership causes loss of
  230. * arbitration.
  231. *
  232. * Values:
  233. * - 0 - No repeat start
  234. * - 1 - Generates a repeated START condition
  235. */
  236. //@{
  237. #define BP_I2C_I2CR_RSTA (2) //!< Bit position for I2C_I2CR_RSTA.
  238. #define BM_I2C_I2CR_RSTA (0x00000004) //!< Bit mask for I2C_I2CR_RSTA.
  239. //! @brief Get value of I2C_I2CR_RSTA from a register value.
  240. #define BG_I2C_I2CR_RSTA(r) ((__REG_VALUE_TYPE((r), reg16_t) & BM_I2C_I2CR_RSTA) >> BP_I2C_I2CR_RSTA)
  241. //! @brief Format value for bitfield I2C_I2CR_RSTA.
  242. #define BF_I2C_I2CR_RSTA(v) ((__REG_VALUE_TYPE((v), reg16_t) << BP_I2C_I2CR_RSTA) & BM_I2C_I2CR_RSTA)
  243. //@}
  244. /*! @name Register I2C_I2CR, field TXAK[3] (RW)
  245. *
  246. * Transmit acknowledge enable. Specifies the value driven onto I2Cn_SDA during acknowledge cycles
  247. * for both master and slave receivers. Writing TXAK applies only when the I2C bus is a receiver.
  248. *
  249. * Values:
  250. * - 0 - An acknowledge signal is sent to the bus at the ninth clock bit after receiving one byte of data.
  251. * - 1 - No acknowledge signal response is sent (that is, the acknowledge bit = 1).
  252. */
  253. //@{
  254. #define BP_I2C_I2CR_TXAK (3) //!< Bit position for I2C_I2CR_TXAK.
  255. #define BM_I2C_I2CR_TXAK (0x00000008) //!< Bit mask for I2C_I2CR_TXAK.
  256. //! @brief Get value of I2C_I2CR_TXAK from a register value.
  257. #define BG_I2C_I2CR_TXAK(r) ((__REG_VALUE_TYPE((r), reg16_t) & BM_I2C_I2CR_TXAK) >> BP_I2C_I2CR_TXAK)
  258. //! @brief Format value for bitfield I2C_I2CR_TXAK.
  259. #define BF_I2C_I2CR_TXAK(v) ((__REG_VALUE_TYPE((v), reg16_t) << BP_I2C_I2CR_TXAK) & BM_I2C_I2CR_TXAK)
  260. #ifndef __LANGUAGE_ASM__
  261. //! @brief Set the TXAK field to a new value.
  262. #define BW_I2C_I2CR_TXAK(x, v) (HW_I2C_I2CR_WR(x, (HW_I2C_I2CR_RD(x) & ~BM_I2C_I2CR_TXAK) | BF_I2C_I2CR_TXAK(v)))
  263. #endif
  264. //@}
  265. /*! @name Register I2C_I2CR, field MTX[4] (RW)
  266. *
  267. * Transmit/receive mode select bit. Selects the direction of master and slave transfers.
  268. *
  269. * Values:
  270. * - 0 - Receive. When a slave is addressed, the software should set MTX according to the slave read/write
  271. * bit in the I2C status register (I2C_I2SR[SRW]).
  272. * - 1 - Transmit. In master mode, MTX should be set according to the type of transfer required. Therefore,
  273. * for address cycles, MTX is always 1.
  274. */
  275. //@{
  276. #define BP_I2C_I2CR_MTX (4) //!< Bit position for I2C_I2CR_MTX.
  277. #define BM_I2C_I2CR_MTX (0x00000010) //!< Bit mask for I2C_I2CR_MTX.
  278. //! @brief Get value of I2C_I2CR_MTX from a register value.
  279. #define BG_I2C_I2CR_MTX(r) ((__REG_VALUE_TYPE((r), reg16_t) & BM_I2C_I2CR_MTX) >> BP_I2C_I2CR_MTX)
  280. //! @brief Format value for bitfield I2C_I2CR_MTX.
  281. #define BF_I2C_I2CR_MTX(v) ((__REG_VALUE_TYPE((v), reg16_t) << BP_I2C_I2CR_MTX) & BM_I2C_I2CR_MTX)
  282. #ifndef __LANGUAGE_ASM__
  283. //! @brief Set the MTX field to a new value.
  284. #define BW_I2C_I2CR_MTX(x, v) (HW_I2C_I2CR_WR(x, (HW_I2C_I2CR_RD(x) & ~BM_I2C_I2CR_MTX) | BF_I2C_I2CR_MTX(v)))
  285. #endif
  286. //@}
  287. /*! @name Register I2C_I2CR, field MSTA[5] (RW)
  288. *
  289. * Master/slave mode select bit. If the master loses arbitration, MSTA is cleared without generating
  290. * a STOP signal. Module clock should be on for writing to the MSTA bit. The MSTA bit is cleared by
  291. * software to generate a STOP condition; it can also be cleared by hardware when the I2C loses the
  292. * bus arbitration.
  293. *
  294. * Values:
  295. * - 0 - Slave mode. Changing MSTA from 1 to 0 generates a STOP and selects slave mode.
  296. * - 1 - Master mode. Changing MSTA from 0 to 1 signals a START on the bus and selects master mode.
  297. */
  298. //@{
  299. #define BP_I2C_I2CR_MSTA (5) //!< Bit position for I2C_I2CR_MSTA.
  300. #define BM_I2C_I2CR_MSTA (0x00000020) //!< Bit mask for I2C_I2CR_MSTA.
  301. //! @brief Get value of I2C_I2CR_MSTA from a register value.
  302. #define BG_I2C_I2CR_MSTA(r) ((__REG_VALUE_TYPE((r), reg16_t) & BM_I2C_I2CR_MSTA) >> BP_I2C_I2CR_MSTA)
  303. //! @brief Format value for bitfield I2C_I2CR_MSTA.
  304. #define BF_I2C_I2CR_MSTA(v) ((__REG_VALUE_TYPE((v), reg16_t) << BP_I2C_I2CR_MSTA) & BM_I2C_I2CR_MSTA)
  305. #ifndef __LANGUAGE_ASM__
  306. //! @brief Set the MSTA field to a new value.
  307. #define BW_I2C_I2CR_MSTA(x, v) (HW_I2C_I2CR_WR(x, (HW_I2C_I2CR_RD(x) & ~BM_I2C_I2CR_MSTA) | BF_I2C_I2CR_MSTA(v)))
  308. #endif
  309. //@}
  310. /*! @name Register I2C_I2CR, field IIEN[6] (RW)
  311. *
  312. * I2C interrupt enable. If data is written during the START condition, that is, just after setting
  313. * the I2C_I2CR[MSTA] and I2C_I2CR[MTX] bits, then the ICF bit is cleared at the falling edge of
  314. * SCLK after START. If data is written after the START condition and falling edge of SCLK, then ICF
  315. * bit is cleared as soon as data is written.
  316. *
  317. * Values:
  318. * - 0 - I2C interrupts are disabled, but the status flag I2C_I2SR[IIF] continues to be set when an interrupt
  319. * condition occurs.
  320. * - 1 - I2C interrupts are enabled. An I2C interrupt occurs if I2C_I2SR[IIF] is also set.
  321. */
  322. //@{
  323. #define BP_I2C_I2CR_IIEN (6) //!< Bit position for I2C_I2CR_IIEN.
  324. #define BM_I2C_I2CR_IIEN (0x00000040) //!< Bit mask for I2C_I2CR_IIEN.
  325. //! @brief Get value of I2C_I2CR_IIEN from a register value.
  326. #define BG_I2C_I2CR_IIEN(r) ((__REG_VALUE_TYPE((r), reg16_t) & BM_I2C_I2CR_IIEN) >> BP_I2C_I2CR_IIEN)
  327. //! @brief Format value for bitfield I2C_I2CR_IIEN.
  328. #define BF_I2C_I2CR_IIEN(v) ((__REG_VALUE_TYPE((v), reg16_t) << BP_I2C_I2CR_IIEN) & BM_I2C_I2CR_IIEN)
  329. #ifndef __LANGUAGE_ASM__
  330. //! @brief Set the IIEN field to a new value.
  331. #define BW_I2C_I2CR_IIEN(x, v) (HW_I2C_I2CR_WR(x, (HW_I2C_I2CR_RD(x) & ~BM_I2C_I2CR_IIEN) | BF_I2C_I2CR_IIEN(v)))
  332. #endif
  333. //@}
  334. /*! @name Register I2C_I2CR, field IEN[7] (RW)
  335. *
  336. * I2C enable. Also controls the software reset of the entire I2C. Resetting the bit generates an
  337. * internal reset to the block. If the block is enabled in the middle of a byte transfer, slave mode
  338. * ignores the current bus transfer and starts operating when the next start condition is detected.
  339. * Master mode is not aware that the bus is busy so initiating a start cycle may corrupt the current
  340. * bus cycle, ultimately causing either the current master or the I2C to lose arbitration. After
  341. * which, bus operation returns to normal.
  342. *
  343. * Values:
  344. * - 0 - The block is disabled, but registers can still be accessed.
  345. * - 1 - The I2C is enabled. This bit must be set before any other I2C_I2CR bits have any effect.
  346. */
  347. //@{
  348. #define BP_I2C_I2CR_IEN (7) //!< Bit position for I2C_I2CR_IEN.
  349. #define BM_I2C_I2CR_IEN (0x00000080) //!< Bit mask for I2C_I2CR_IEN.
  350. //! @brief Get value of I2C_I2CR_IEN from a register value.
  351. #define BG_I2C_I2CR_IEN(r) ((__REG_VALUE_TYPE((r), reg16_t) & BM_I2C_I2CR_IEN) >> BP_I2C_I2CR_IEN)
  352. //! @brief Format value for bitfield I2C_I2CR_IEN.
  353. #define BF_I2C_I2CR_IEN(v) ((__REG_VALUE_TYPE((v), reg16_t) << BP_I2C_I2CR_IEN) & BM_I2C_I2CR_IEN)
  354. #ifndef __LANGUAGE_ASM__
  355. //! @brief Set the IEN field to a new value.
  356. #define BW_I2C_I2CR_IEN(x, v) (HW_I2C_I2CR_WR(x, (HW_I2C_I2CR_RD(x) & ~BM_I2C_I2CR_IEN) | BF_I2C_I2CR_IEN(v)))
  357. #endif
  358. //@}
  359. //-------------------------------------------------------------------------------------------
  360. // HW_I2C_I2SR - I2C Status Register
  361. //-------------------------------------------------------------------------------------------
  362. #ifndef __LANGUAGE_ASM__
  363. /*!
  364. * @brief HW_I2C_I2SR - I2C Status Register (RW)
  365. *
  366. * Reset value: 0x0081
  367. *
  368. * The I2C_I2SR contains bits that indicate transaction direction and status.
  369. */
  370. typedef union _hw_i2c_i2sr
  371. {
  372. reg16_t U;
  373. struct _hw_i2c_i2sr_bitfields
  374. {
  375. unsigned short RXAK : 1; //!< [0] Received acknowledge.
  376. unsigned short IIF : 1; //!< [1] I2C interrupt.
  377. unsigned short SRW : 1; //!< [2] Slave read/write.
  378. unsigned short RESERVED0 : 1; //!< [3] Reserved
  379. unsigned short IAL : 1; //!< [4] Arbitration lost.
  380. unsigned short IBB : 1; //!< [5] I2C bus busy bit.
  381. unsigned short IAAS : 1; //!< [6] I2C addressed as a slave bit.
  382. unsigned short ICF : 1; //!< [7] Data transferring bit.
  383. unsigned short RESERVED1 : 8; //!< [15:8] Reserved
  384. } B;
  385. } hw_i2c_i2sr_t;
  386. #endif
  387. /*!
  388. * @name Constants and macros for entire I2C_I2SR register
  389. */
  390. //@{
  391. #define HW_I2C_I2SR_ADDR(x) (REGS_I2C_BASE(x) + 0xc)
  392. #ifndef __LANGUAGE_ASM__
  393. #define HW_I2C_I2SR(x) (*(volatile hw_i2c_i2sr_t *) HW_I2C_I2SR_ADDR(x))
  394. #define HW_I2C_I2SR_RD(x) (HW_I2C_I2SR(x).U)
  395. #define HW_I2C_I2SR_WR(x, v) (HW_I2C_I2SR(x).U = (v))
  396. #define HW_I2C_I2SR_SET(x, v) (HW_I2C_I2SR_WR(x, HW_I2C_I2SR_RD(x) | (v)))
  397. #define HW_I2C_I2SR_CLR(x, v) (HW_I2C_I2SR_WR(x, HW_I2C_I2SR_RD(x) & ~(v)))
  398. #define HW_I2C_I2SR_TOG(x, v) (HW_I2C_I2SR_WR(x, HW_I2C_I2SR_RD(x) ^ (v)))
  399. #endif
  400. //@}
  401. /*
  402. * constants & macros for individual I2C_I2SR bitfields
  403. */
  404. /*! @name Register I2C_I2SR, field RXAK[0] (RO)
  405. *
  406. * Received acknowledge. This is the value received of the I2Cn_SDA input for the acknowledge bit
  407. * during a bus cycle.
  408. *
  409. * Values:
  410. * - 0 - An "acknowledge" signal was received after the completion of an 8-bit data transmission on the bus.
  411. * - 1 - A "No acknowledge" signal was detected at the ninth clock.
  412. */
  413. //@{
  414. #define BP_I2C_I2SR_RXAK (0) //!< Bit position for I2C_I2SR_RXAK.
  415. #define BM_I2C_I2SR_RXAK (0x00000001) //!< Bit mask for I2C_I2SR_RXAK.
  416. //! @brief Get value of I2C_I2SR_RXAK from a register value.
  417. #define BG_I2C_I2SR_RXAK(r) ((__REG_VALUE_TYPE((r), reg16_t) & BM_I2C_I2SR_RXAK) >> BP_I2C_I2SR_RXAK)
  418. //@}
  419. /*! @name Register I2C_I2SR, field IIF[1] (RW)
  420. *
  421. * I2C interrupt. Must be cleared by the software by writing a "0" to it in the interrupt routine.
  422. * The software cannot set the bit.
  423. *
  424. * Values:
  425. * - 0 - No I2C interrupt pending.
  426. * - 1 - An interrupt is pending. This causes a processor interrupt request (if the interrupt enable is
  427. * asserted [IIEN = 1]). The interrupt is set when one of the following occurs: One byte
  428. * transfer is completed (the interrupt is set at the falling edge of the ninth clock). An
  429. * address is received that matches its own specific address in slave-receive mode. Arbitration
  430. * is lost.
  431. */
  432. //@{
  433. #define BP_I2C_I2SR_IIF (1) //!< Bit position for I2C_I2SR_IIF.
  434. #define BM_I2C_I2SR_IIF (0x00000002) //!< Bit mask for I2C_I2SR_IIF.
  435. //! @brief Get value of I2C_I2SR_IIF from a register value.
  436. #define BG_I2C_I2SR_IIF(r) ((__REG_VALUE_TYPE((r), reg16_t) & BM_I2C_I2SR_IIF) >> BP_I2C_I2SR_IIF)
  437. //! @brief Format value for bitfield I2C_I2SR_IIF.
  438. #define BF_I2C_I2SR_IIF(v) ((__REG_VALUE_TYPE((v), reg16_t) << BP_I2C_I2SR_IIF) & BM_I2C_I2SR_IIF)
  439. #ifndef __LANGUAGE_ASM__
  440. //! @brief Set the IIF field to a new value.
  441. #define BW_I2C_I2SR_IIF(x, v) (HW_I2C_I2SR_WR(x, (HW_I2C_I2SR_RD(x) & ~BM_I2C_I2SR_IIF) | BF_I2C_I2SR_IIF(v)))
  442. #endif
  443. //@}
  444. /*! @name Register I2C_I2SR, field SRW[2] (RO)
  445. *
  446. * Slave read/write. When the I2C is addressed as a slave, IAAS is set, and the slave read/write bit
  447. * (SRW) indicates the value of the R/W command bit of the calling address sent from the master. SRW
  448. * is valid only when a complete transfer has occurred, no other transfers have been initiated, and
  449. * the I2C is a slave and has an address match.
  450. *
  451. * Values:
  452. * - 0 - Slave receive, master writing to slave
  453. * - 1 - Slave transmit, master reading from slave
  454. */
  455. //@{
  456. #define BP_I2C_I2SR_SRW (2) //!< Bit position for I2C_I2SR_SRW.
  457. #define BM_I2C_I2SR_SRW (0x00000004) //!< Bit mask for I2C_I2SR_SRW.
  458. //! @brief Get value of I2C_I2SR_SRW from a register value.
  459. #define BG_I2C_I2SR_SRW(r) ((__REG_VALUE_TYPE((r), reg16_t) & BM_I2C_I2SR_SRW) >> BP_I2C_I2SR_SRW)
  460. //@}
  461. /*! @name Register I2C_I2SR, field IAL[4] (RW)
  462. *
  463. * Arbitration lost. Set by hardware in the following circumstances (IAL must be cleared by software
  464. * by writing a "0" to it at the start of the interrupt service routine): I2Cn_SDA input sampled low
  465. * when the master drives high during an address or data-transmit cycle. I2Cn_SDA input sampled low
  466. * when the master drives high during the acknowledge bit of a data-receive cycle. For the above two
  467. * cases, the bit is set at the falling edge of 9th I2Cn_SCL clock during the ACK cycle. A start
  468. * cycle is attempted when the bus is busy. A repeated start cycle is requested in slave mode. A
  469. * stop condition is detected when the master did not request it. Software cannot set the bit.
  470. *
  471. * Values:
  472. * - 0 - No arbitration lost.
  473. * - 1 - Arbitration is lost.
  474. */
  475. //@{
  476. #define BP_I2C_I2SR_IAL (4) //!< Bit position for I2C_I2SR_IAL.
  477. #define BM_I2C_I2SR_IAL (0x00000010) //!< Bit mask for I2C_I2SR_IAL.
  478. //! @brief Get value of I2C_I2SR_IAL from a register value.
  479. #define BG_I2C_I2SR_IAL(r) ((__REG_VALUE_TYPE((r), reg16_t) & BM_I2C_I2SR_IAL) >> BP_I2C_I2SR_IAL)
  480. //! @brief Format value for bitfield I2C_I2SR_IAL.
  481. #define BF_I2C_I2SR_IAL(v) ((__REG_VALUE_TYPE((v), reg16_t) << BP_I2C_I2SR_IAL) & BM_I2C_I2SR_IAL)
  482. #ifndef __LANGUAGE_ASM__
  483. //! @brief Set the IAL field to a new value.
  484. #define BW_I2C_I2SR_IAL(x, v) (HW_I2C_I2SR_WR(x, (HW_I2C_I2SR_RD(x) & ~BM_I2C_I2SR_IAL) | BF_I2C_I2SR_IAL(v)))
  485. #endif
  486. //@}
  487. /*! @name Register I2C_I2SR, field IBB[5] (RO)
  488. *
  489. * I2C bus busy bit. Indicates the status of the bus. When I2C is enabled (I2C_I2CR[IEN] = 1), it
  490. * continuously polls the bus data (SDAK) and clock (SCLK) signals to determine a START or STOP
  491. * condition.
  492. *
  493. * Values:
  494. * - 0 - Bus is idle. If a STOP signal is detected, IBB is cleared.
  495. * - 1 - Bus is busy. When START is detected, IBB is set.
  496. */
  497. //@{
  498. #define BP_I2C_I2SR_IBB (5) //!< Bit position for I2C_I2SR_IBB.
  499. #define BM_I2C_I2SR_IBB (0x00000020) //!< Bit mask for I2C_I2SR_IBB.
  500. //! @brief Get value of I2C_I2SR_IBB from a register value.
  501. #define BG_I2C_I2SR_IBB(r) ((__REG_VALUE_TYPE((r), reg16_t) & BM_I2C_I2SR_IBB) >> BP_I2C_I2SR_IBB)
  502. //@}
  503. /*! @name Register I2C_I2SR, field IAAS[6] (RO)
  504. *
  505. * I2C addressed as a slave bit. The ARM platform is interrupted if the interrupt enable
  506. * (I2C_I2CR[IIEN]) is set. The ARM platform must check the slave read/write bit (SRW) and set its
  507. * TX/RX mode accordingly. Writing to I2C_I2CR clears this bit.
  508. *
  509. * Values:
  510. * - 0 - Not addressed
  511. * - 1 - Addressed as a slave. Set when its own address (I2C_IADR) matches the calling address.
  512. */
  513. //@{
  514. #define BP_I2C_I2SR_IAAS (6) //!< Bit position for I2C_I2SR_IAAS.
  515. #define BM_I2C_I2SR_IAAS (0x00000040) //!< Bit mask for I2C_I2SR_IAAS.
  516. //! @brief Get value of I2C_I2SR_IAAS from a register value.
  517. #define BG_I2C_I2SR_IAAS(r) ((__REG_VALUE_TYPE((r), reg16_t) & BM_I2C_I2SR_IAAS) >> BP_I2C_I2SR_IAAS)
  518. //@}
  519. /*! @name Register I2C_I2SR, field ICF[7] (RO)
  520. *
  521. * Data transferring bit. While one byte of data is transferred, ICF is cleared.
  522. *
  523. * Values:
  524. * - 0 - Transfer is in progress.
  525. * - 1 - Transfer is complete. This bit is set by the falling edge of the ninth clock of the last byte
  526. * transfer.
  527. */
  528. //@{
  529. #define BP_I2C_I2SR_ICF (7) //!< Bit position for I2C_I2SR_ICF.
  530. #define BM_I2C_I2SR_ICF (0x00000080) //!< Bit mask for I2C_I2SR_ICF.
  531. //! @brief Get value of I2C_I2SR_ICF from a register value.
  532. #define BG_I2C_I2SR_ICF(r) ((__REG_VALUE_TYPE((r), reg16_t) & BM_I2C_I2SR_ICF) >> BP_I2C_I2SR_ICF)
  533. //@}
  534. //-------------------------------------------------------------------------------------------
  535. // HW_I2C_I2DR - I2C Data I/O Register
  536. //-------------------------------------------------------------------------------------------
  537. #ifndef __LANGUAGE_ASM__
  538. /*!
  539. * @brief HW_I2C_I2DR - I2C Data I/O Register (RW)
  540. *
  541. * Reset value: 0x0000
  542. *
  543. * In master-receive mode, reading the data register allows a read to occur and initiates the next
  544. * byte to be received. In slave mode, the same function is available after it is addressed.
  545. */
  546. typedef union _hw_i2c_i2dr
  547. {
  548. reg16_t U;
  549. struct _hw_i2c_i2dr_bitfields
  550. {
  551. unsigned short DATA : 8; //!< [7:0] Data Byte.
  552. unsigned short RESERVED0 : 8; //!< [15:8] Reserved
  553. } B;
  554. } hw_i2c_i2dr_t;
  555. #endif
  556. /*!
  557. * @name Constants and macros for entire I2C_I2DR register
  558. */
  559. //@{
  560. #define HW_I2C_I2DR_ADDR(x) (REGS_I2C_BASE(x) + 0x10)
  561. #ifndef __LANGUAGE_ASM__
  562. #define HW_I2C_I2DR(x) (*(volatile hw_i2c_i2dr_t *) HW_I2C_I2DR_ADDR(x))
  563. #define HW_I2C_I2DR_RD(x) (HW_I2C_I2DR(x).U)
  564. #define HW_I2C_I2DR_WR(x, v) (HW_I2C_I2DR(x).U = (v))
  565. #define HW_I2C_I2DR_SET(x, v) (HW_I2C_I2DR_WR(x, HW_I2C_I2DR_RD(x) | (v)))
  566. #define HW_I2C_I2DR_CLR(x, v) (HW_I2C_I2DR_WR(x, HW_I2C_I2DR_RD(x) & ~(v)))
  567. #define HW_I2C_I2DR_TOG(x, v) (HW_I2C_I2DR_WR(x, HW_I2C_I2DR_RD(x) ^ (v)))
  568. #endif
  569. //@}
  570. /*
  571. * constants & macros for individual I2C_I2DR bitfields
  572. */
  573. /*! @name Register I2C_I2DR, field DATA[7:0] (RW)
  574. *
  575. * Data Byte. Holds the last data byte received or the next data byte to be transferred. Software
  576. * writes the next data byte to be transmitted or reads the data byte received. The core-written
  577. * value in I2C_I2DR cannot be read back by the core. Only data written by the I2C bus side can be
  578. * read.
  579. */
  580. //@{
  581. #define BP_I2C_I2DR_DATA (0) //!< Bit position for I2C_I2DR_DATA.
  582. #define BM_I2C_I2DR_DATA (0x000000ff) //!< Bit mask for I2C_I2DR_DATA.
  583. //! @brief Get value of I2C_I2DR_DATA from a register value.
  584. #define BG_I2C_I2DR_DATA(r) ((__REG_VALUE_TYPE((r), reg16_t) & BM_I2C_I2DR_DATA) >> BP_I2C_I2DR_DATA)
  585. //! @brief Format value for bitfield I2C_I2DR_DATA.
  586. #define BF_I2C_I2DR_DATA(v) ((__REG_VALUE_TYPE((v), reg16_t) << BP_I2C_I2DR_DATA) & BM_I2C_I2DR_DATA)
  587. #ifndef __LANGUAGE_ASM__
  588. //! @brief Set the DATA field to a new value.
  589. #define BW_I2C_I2DR_DATA(x, v) (HW_I2C_I2DR_WR(x, (HW_I2C_I2DR_RD(x) & ~BM_I2C_I2DR_DATA) | BF_I2C_I2DR_DATA(v)))
  590. #endif
  591. //@}
  592. //-------------------------------------------------------------------------------------------
  593. // hw_i2c_t - module struct
  594. //-------------------------------------------------------------------------------------------
  595. /*!
  596. * @brief All I2C module registers.
  597. */
  598. #ifndef __LANGUAGE_ASM__
  599. #pragma pack(1)
  600. typedef struct _hw_i2c
  601. {
  602. volatile hw_i2c_iadr_t IADR; //!< I2C Address Register
  603. reg16_t _reserved0;
  604. volatile hw_i2c_ifdr_t IFDR; //!< I2C Frequency Divider Register
  605. reg16_t _reserved1;
  606. volatile hw_i2c_i2cr_t I2CR; //!< I2C Control Register
  607. reg16_t _reserved2;
  608. volatile hw_i2c_i2sr_t I2SR; //!< I2C Status Register
  609. reg16_t _reserved3;
  610. volatile hw_i2c_i2dr_t I2DR; //!< I2C Data I/O Register
  611. } hw_i2c_t;
  612. #pragma pack()
  613. //! @brief Macro to access all I2C registers.
  614. //! @param x I2C instance number.
  615. //! @return Reference (not a pointer) to the registers struct. To get a pointer to the struct,
  616. //! use the '&' operator, like <code>&HW_I2C(0)</code>.
  617. #define HW_I2C(x) (*(hw_i2c_t *) REGS_I2C_BASE(x))
  618. #endif
  619. #endif // __HW_I2C_REGISTERS_H__
  620. // v18/121106/1.2.2
  621. // EOF