gh_i2c.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /*!
  2. *******************************************************************************
  3. **
  4. ** \file gh_i2c.h
  5. **
  6. ** \brief I2C Interface..
  7. **
  8. ** Copyright: 2012 - 2016 (C) GoKe Microelectronics
  9. **
  10. ** \attention THIS SAMPLE CODE IS PROVIDED AS IS. GOKE MICROELECTRONICS
  11. ** ACCEPTS NO RESPONSIBILITY OR LIABILITY FOR ANY ERRORS OR
  12. ** OMMISSIONS.
  13. **
  14. ** \note Do not modify this file as it is generated automatically.
  15. **
  16. ******************************************************************************/
  17. #ifndef _GH_I2C_H
  18. #define _GH_I2C_H
  19. #ifdef __LINUX__
  20. #include "reg4linux.h"
  21. #else
  22. #define FIO_ADDRESS(block,address) (address)
  23. #define FIO_MOFFSET(block,moffset) (moffset)
  24. #endif
  25. #ifndef __LINUX__
  26. #include "gtypes.h" /* global type definitions */
  27. #include "gh_lib_cfg.h" /* configuration */
  28. #endif
  29. #define GH_I2C_ENABLE_DEBUG_PRINT 0
  30. #ifdef __LINUX__
  31. #define GH_I2C_DEBUG_PRINT_FUNCTION printk
  32. #else
  33. #define GH_I2C_DEBUG_PRINT_FUNCTION printf
  34. #endif
  35. #ifndef __LINUX__
  36. #if GH_I2C_ENABLE_DEBUG_PRINT
  37. #include <stdio.h>
  38. #endif
  39. #endif
  40. /*----------------------------------------------------------------------------*/
  41. /* registers */
  42. /*----------------------------------------------------------------------------*/
  43. #define REG_I2C_ENABLE FIO_ADDRESS(I2C,0xa0003000) /* read/write */
  44. #define REG_I2C_CONTROL FIO_ADDRESS(I2C,0xa0003004) /* read/write */
  45. #define REG_I2C_DATA FIO_ADDRESS(I2C,0xa0003008) /* read/write */
  46. #define REG_I2C_STATUS FIO_ADDRESS(I2C,0xa000300C) /* read */
  47. #define REG_I2C_PRESCALEL FIO_ADDRESS(I2C,0xa0003010) /* read/write */
  48. #define REG_I2C_PRESCALEH FIO_ADDRESS(I2C,0xa0003014) /* read/write */
  49. #define REG_I2C_FMCONTROL FIO_ADDRESS(I2C,0xa0003018) /* read/write */
  50. #define REG_I2C_FMDATA FIO_ADDRESS(I2C,0xa000301C) /* read/write */
  51. /*----------------------------------------------------------------------------*/
  52. /* bit group structures */
  53. /*----------------------------------------------------------------------------*/
  54. typedef union { /* I2C_ENABLE */
  55. U32 all;
  56. struct {
  57. U32 en : 1;
  58. U32 : 31;
  59. } bitc;
  60. } GH_I2C_ENABLE_S;
  61. typedef union { /* I2C_CONTROL */
  62. U32 all;
  63. struct {
  64. U32 ack : 1;
  65. U32 intflag : 1;
  66. U32 start : 1;
  67. U32 stop : 1;
  68. U32 : 28;
  69. } bitc;
  70. } GH_I2C_CONTROL_S;
  71. typedef union { /* I2C_DATA */
  72. U32 all;
  73. struct {
  74. U32 data : 8;
  75. U32 : 24;
  76. } bitc;
  77. } GH_I2C_DATA_S;
  78. typedef union { /* I2C_STATUS */
  79. U32 all;
  80. struct {
  81. U32 mode : 1;
  82. U32 : 31;
  83. } bitc;
  84. } GH_I2C_STATUS_S;
  85. typedef union { /* I2C_PRESCALEL */
  86. U32 all;
  87. struct {
  88. U32 scale : 8;
  89. U32 : 24;
  90. } bitc;
  91. } GH_I2C_PRESCALEL_S;
  92. typedef union { /* I2C_PRESCALEH */
  93. U32 all;
  94. struct {
  95. U32 scale : 8;
  96. U32 : 24;
  97. } bitc;
  98. } GH_I2C_PRESCALEH_S;
  99. typedef union { /* I2C_FMCONTROL */
  100. U32 all;
  101. struct {
  102. U32 : 1;
  103. U32 is : 1;
  104. U32 start : 1;
  105. U32 stop : 1;
  106. U32 : 28;
  107. } bitc;
  108. } GH_I2C_FMCONTROL_S;
  109. typedef union { /* I2C_FMDATA */
  110. U32 all;
  111. struct {
  112. U32 data : 8;
  113. U32 : 24;
  114. } bitc;
  115. } GH_I2C_FMDATA_S;
  116. /*----------------------------------------------------------------------------*/
  117. /* mirror variables */
  118. /*----------------------------------------------------------------------------*/
  119. #ifdef __cplusplus
  120. extern "C" {
  121. #endif
  122. /*----------------------------------------------------------------------------*/
  123. /* register I2C_ENABLE (read/write) */
  124. /*----------------------------------------------------------------------------*/
  125. /*! \brief Writes the register 'I2C_ENABLE'. */
  126. void GH_I2C_set_ENABLE(U8 index, U32 data);
  127. /*! \brief Reads the register 'I2C_ENABLE'. */
  128. U32 GH_I2C_get_ENABLE(U8 index);
  129. /*! \brief Writes the bit group 'en' of register 'I2C_ENABLE'. */
  130. void GH_I2C_set_ENABLE_en(U8 index, U8 data);
  131. /*! \brief Reads the bit group 'en' of register 'I2C_ENABLE'. */
  132. U8 GH_I2C_get_ENABLE_en(U8 index);
  133. /*----------------------------------------------------------------------------*/
  134. /* register I2C_CONTROL (read/write) */
  135. /*----------------------------------------------------------------------------*/
  136. /*! \brief Writes the register 'I2C_CONTROL'. */
  137. void GH_I2C_set_CONTROL(U8 index, U32 data);
  138. /*! \brief Reads the register 'I2C_CONTROL'. */
  139. U32 GH_I2C_get_CONTROL(U8 index);
  140. /*! \brief Writes the bit group 'ack' of register 'I2C_CONTROL'. */
  141. void GH_I2C_set_CONTROL_ack(U8 index, U8 data);
  142. /*! \brief Reads the bit group 'ack' of register 'I2C_CONTROL'. */
  143. U8 GH_I2C_get_CONTROL_ack(U8 index);
  144. /*! \brief Writes the bit group 'IntFlag' of register 'I2C_CONTROL'. */
  145. void GH_I2C_set_CONTROL_IntFlag(U8 index, U8 data);
  146. /*! \brief Reads the bit group 'IntFlag' of register 'I2C_CONTROL'. */
  147. U8 GH_I2C_get_CONTROL_IntFlag(U8 index);
  148. /*! \brief Writes the bit group 'start' of register 'I2C_CONTROL'. */
  149. void GH_I2C_set_CONTROL_start(U8 index, U8 data);
  150. /*! \brief Reads the bit group 'start' of register 'I2C_CONTROL'. */
  151. U8 GH_I2C_get_CONTROL_start(U8 index);
  152. /*! \brief Writes the bit group 'stop' of register 'I2C_CONTROL'. */
  153. void GH_I2C_set_CONTROL_stop(U8 index, U8 data);
  154. /*! \brief Reads the bit group 'stop' of register 'I2C_CONTROL'. */
  155. U8 GH_I2C_get_CONTROL_stop(U8 index);
  156. /*----------------------------------------------------------------------------*/
  157. /* register I2C_DATA (read/write) */
  158. /*----------------------------------------------------------------------------*/
  159. /*! \brief Writes the register 'I2C_DATA'. */
  160. void GH_I2C_set_DATA(U8 index, U32 data);
  161. /*! \brief Reads the register 'I2C_DATA'. */
  162. U32 GH_I2C_get_DATA(U8 index);
  163. /*! \brief Writes the bit group 'Data' of register 'I2C_DATA'. */
  164. void GH_I2C_set_DATA_Data(U8 index, U8 data);
  165. /*! \brief Reads the bit group 'Data' of register 'I2C_DATA'. */
  166. U8 GH_I2C_get_DATA_Data(U8 index);
  167. /*----------------------------------------------------------------------------*/
  168. /* register I2C_STATUS (read) */
  169. /*----------------------------------------------------------------------------*/
  170. /*! \brief Reads the register 'I2C_STATUS'. */
  171. U32 GH_I2C_get_STATUS(U8 index);
  172. /*! \brief Reads the bit group 'mode' of register 'I2C_STATUS'. */
  173. U8 GH_I2C_get_STATUS_mode(U8 index);
  174. /*----------------------------------------------------------------------------*/
  175. /* register I2C_PRESCALEL (read/write) */
  176. /*----------------------------------------------------------------------------*/
  177. /*! \brief Writes the register 'I2C_PRESCALEL'. */
  178. void GH_I2C_set_PRESCALEL(U8 index, U32 data);
  179. /*! \brief Reads the register 'I2C_PRESCALEL'. */
  180. U32 GH_I2C_get_PRESCALEL(U8 index);
  181. /*! \brief Writes the bit group 'scale' of register 'I2C_PRESCALEL'. */
  182. void GH_I2C_set_PRESCALEL_scale(U8 index, U8 data);
  183. /*! \brief Reads the bit group 'scale' of register 'I2C_PRESCALEL'. */
  184. U8 GH_I2C_get_PRESCALEL_scale(U8 index);
  185. /*----------------------------------------------------------------------------*/
  186. /* register I2C_PRESCALEH (read/write) */
  187. /*----------------------------------------------------------------------------*/
  188. /*! \brief Writes the register 'I2C_PRESCALEH'. */
  189. void GH_I2C_set_PRESCALEH(U8 index, U32 data);
  190. /*! \brief Reads the register 'I2C_PRESCALEH'. */
  191. U32 GH_I2C_get_PRESCALEH(U8 index);
  192. /*! \brief Writes the bit group 'scale' of register 'I2C_PRESCALEH'. */
  193. void GH_I2C_set_PRESCALEH_scale(U8 index, U8 data);
  194. /*! \brief Reads the bit group 'scale' of register 'I2C_PRESCALEH'. */
  195. U8 GH_I2C_get_PRESCALEH_scale(U8 index);
  196. /*----------------------------------------------------------------------------*/
  197. /* register I2C_FMCONTROL (read/write) */
  198. /*----------------------------------------------------------------------------*/
  199. /*! \brief Writes the register 'I2C_FMCONTROL'. */
  200. void GH_I2C_set_FMCONTROL(U8 index, U32 data);
  201. /*! \brief Reads the register 'I2C_FMCONTROL'. */
  202. U32 GH_I2C_get_FMCONTROL(U8 index);
  203. /*! \brief Writes the bit group 'is' of register 'I2C_FMCONTROL'. */
  204. void GH_I2C_set_FMCONTROL_is(U8 index, U8 data);
  205. /*! \brief Reads the bit group 'is' of register 'I2C_FMCONTROL'. */
  206. U8 GH_I2C_get_FMCONTROL_is(U8 index);
  207. /*! \brief Writes the bit group 'start' of register 'I2C_FMCONTROL'. */
  208. void GH_I2C_set_FMCONTROL_start(U8 index, U8 data);
  209. /*! \brief Reads the bit group 'start' of register 'I2C_FMCONTROL'. */
  210. U8 GH_I2C_get_FMCONTROL_start(U8 index);
  211. /*! \brief Writes the bit group 'stop' of register 'I2C_FMCONTROL'. */
  212. void GH_I2C_set_FMCONTROL_stop(U8 index, U8 data);
  213. /*! \brief Reads the bit group 'stop' of register 'I2C_FMCONTROL'. */
  214. U8 GH_I2C_get_FMCONTROL_stop(U8 index);
  215. /*----------------------------------------------------------------------------*/
  216. /* register I2C_FMDATA (read/write) */
  217. /*----------------------------------------------------------------------------*/
  218. /*! \brief Writes the register 'I2C_FMDATA'. */
  219. void GH_I2C_set_FMDATA(U8 index, U32 data);
  220. /*! \brief Reads the register 'I2C_FMDATA'. */
  221. U32 GH_I2C_get_FMDATA(U8 index);
  222. /*! \brief Writes the bit group 'Data' of register 'I2C_FMDATA'. */
  223. void GH_I2C_set_FMDATA_Data(U8 index, U8 data);
  224. /*! \brief Reads the bit group 'Data' of register 'I2C_FMDATA'. */
  225. U8 GH_I2C_get_FMDATA_Data(U8 index);
  226. /*----------------------------------------------------------------------------*/
  227. /* init function */
  228. /*----------------------------------------------------------------------------*/
  229. /*! \brief Initialises the registers and mirror variables. */
  230. void GH_I2C_init(void);
  231. #ifdef SRC_INLINE
  232. #define SRC_INC 1
  233. #include "gh_i2c.c"
  234. #undef SRC_INC
  235. #endif
  236. #ifdef __cplusplus
  237. }
  238. #endif
  239. #endif /* _GH_I2C_H */
  240. /*----------------------------------------------------------------------------*/
  241. /* end of file */
  242. /*----------------------------------------------------------------------------*/