hwreg_access.h 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. /* Copyright (C) 2018 RDA Technologies Limited and/or its affiliates("RDA").
  2. * All rights reserved.
  3. *
  4. * This software is supplied "AS IS" without any warranties.
  5. * RDA assumes no responsibility or liability for the use of the software,
  6. * conveys no license or title under any patent, copyright, or mask work
  7. * right to the product. RDA reserves the right to make changes in the
  8. * software without notification. RDA also make no representation or
  9. * warranty that such application will be suitable for the specified use
  10. * without further testing or modification.
  11. */
  12. #ifndef _HWREG_ACCESS_H_
  13. #define _HWREG_ACCESS_H_
  14. #include <stdint.h>
  15. #include "hal_config.h"
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. #define EXP2(n) (1 << (n))
  20. typedef uint32_t REG32;
  21. typedef uint16_t REG16;
  22. typedef uint8_t REG8;
  23. typedef uint8_t UINT8;
  24. #define REG_BIT(n) (1U << (n))
  25. #define REG_BIT0 (1U << 0)
  26. #define REG_BIT1 (1U << 1)
  27. #define REG_BIT2 (1U << 2)
  28. #define REG_BIT3 (1U << 3)
  29. #define REG_BIT4 (1U << 4)
  30. #define REG_BIT5 (1U << 5)
  31. #define REG_BIT6 (1U << 6)
  32. #define REG_BIT7 (1U << 7)
  33. #define REG_BIT8 (1U << 8)
  34. #define REG_BIT9 (1U << 9)
  35. #define REG_BIT10 (1U << 10)
  36. #define REG_BIT11 (1U << 11)
  37. #define REG_BIT12 (1U << 12)
  38. #define REG_BIT13 (1U << 13)
  39. #define REG_BIT14 (1U << 14)
  40. #define REG_BIT15 (1U << 15)
  41. #define REG_BIT16 (1U << 16)
  42. #define REG_BIT17 (1U << 17)
  43. #define REG_BIT18 (1U << 18)
  44. #define REG_BIT19 (1U << 19)
  45. #define REG_BIT20 (1U << 20)
  46. #define REG_BIT21 (1U << 21)
  47. #define REG_BIT22 (1U << 22)
  48. #define REG_BIT23 (1U << 23)
  49. #define REG_BIT24 (1U << 24)
  50. #define REG_BIT25 (1U << 25)
  51. #define REG_BIT26 (1U << 26)
  52. #define REG_BIT27 (1U << 27)
  53. #define REG_BIT28 (1U << 28)
  54. #define REG_BIT29 (1U << 29)
  55. #define REG_BIT30 (1U << 30)
  56. #define REG_BIT31 (1U << 31)
  57. // Mask for [hi:lo]. REG_BIT(hi + 1) will cause -Wshift-count-overflow
  58. #define REG_BIT_RANGE_MASK(hi, lo) ({ unsigned _h = (hi) + 1; unsigned _hm = (_h >= 32)? 0 : REG_BIT(_h); _hm - REG_BIT(lo); })
  59. #ifdef CONFIG_SOC_8910
  60. #define HAL_SYSIRQ_NUM(irq) ((irq) + 32)
  61. #define REG_ADDRESS_FOR_ARM
  62. #define REG_ACCESS_ADDRESS(addr) (addr)
  63. #endif
  64. #ifdef CONFIG_SOC_8811
  65. #define HAL_SYSIRQ_NUM(irq) (irq)
  66. #define REG_ADDRESS_FOR_ARM
  67. #define REG_ACCESS_ADDRESS(addr) (addr)
  68. #endif
  69. #ifdef CONFIG_SOC_8850
  70. #define HAL_SYSIRQ_NUM(irq) ((irq) + 32)
  71. #define REG_ADDRESS_FOR_ARM
  72. #define REG_ACCESS_ADDRESS(addr) (addr)
  73. #endif
  74. #ifdef __mips__
  75. #define OSI_KSEG0(addr) (((unsigned long)(addr)&0x1fffffff) | 0x80000000)
  76. #define OSI_KSEG1(addr) (((unsigned long)(addr)&0x1fffffff) | 0xa0000000)
  77. #define OSI_IS_KSEG0(addr) (((unsigned long)(addr)&0xe0000000) == 0x80000000)
  78. #define OSI_IS_KSEG1(addr) (((unsigned long)(addr)&0xe0000000) == 0xa0000000)
  79. #define MEM_ACCESS_CACHED(addr) ((UINT32 *)OSI_KSEG0(addr))
  80. #define MEM_ACCESS_UNCACHED(addr) ((UINT32 *)OSI_KSEG1(addr))
  81. #endif
  82. #ifdef __arm__
  83. #define HAL_READ_CP(...) _HAL_READ_CP(__VA_ARGS__)
  84. #define HAL_WRITE_CP(...) _HAL_WRITE_CP(__VA_ARGS__)
  85. #define _HAL_READ_CP(cp, CRn, opc1, CRm, opc2) __HAL_READ_CP(cp, CRn, opc1, CRm, opc2)
  86. #define _HAL_WRITE_CP(v, cp, CRn, opc1, CRm, opc2) __HAL_WRITE_CP(v, cp, CRn, opc1, CRm, opc2)
  87. #define HAL_CP_MIDR 15, c0, 0, c0, 0 // Main ID Register
  88. #define HAL_CP_CTR 15, c0, 0, c0, 1 // Cache Type Register
  89. #define HAL_CP_TCMTR 15, c0, 0, c0, 2 // TCM Type Register
  90. #define HAL_CP_TLBTR 15, c0, 0, c0, 3 // TLB Type Register
  91. #define HAL_CP_MPIDR 15, c0, 0, c0, 5 // Multiprocessor Affinity Register
  92. #define HAL_CP_PFR0 15, c0, 0, c1, 0 // Processor Feature Register 0
  93. #define HAL_CP_PFR1 15, c0, 0, c1, 1 // Processor Feature Register 1
  94. #define HAL_CP_DFR0 15, c0, 0, c1, 2 // Debug Feature Register 0
  95. #define HAL_CP_AFR0 15, c0, 0, c1, 3 // Auxiliary Feature Register 0
  96. #define HAL_CP_MMFR0 15, c0, 0, c1, 4 // Memory Model Feature Register 0
  97. #define HAL_CP_MMFR1 15, c0, 0, c1, 5 // Memory Model Feature Register 1
  98. #define HAL_CP_MMFR2 15, c0, 0, c1, 6 // Memory Model Feature Register 2
  99. #define HAL_CP_MMFR3 15, c0, 0, c1, 7 // Memory Model Feature Register 3
  100. #define HAL_CP_ISAR0 15, c0, 0, c2, 0 // ISA Feature Register 0
  101. #define HAL_CP_ISAR1 15, c0, 0, c2, 1 // ISA Feature Register 1
  102. #define HAL_CP_ISAR2 15, c0, 0, c2, 2 // ISA Feature Register 2
  103. #define HAL_CP_ISAR3 15, c0, 0, c2, 3 // ISA Feature Register 3
  104. #define HAL_CP_ISAR4 15, c0, 0, c2, 4 // ISA Feature Register 4
  105. #define HAL_CP_ISAR5 15, c0, 0, c0, 5 // ISA Feature Register 5
  106. #define HAL_CP_CCSIDR 15, c0, 1, c0, 0 // Cache Level ID Register
  107. #define HAL_CP_CLIDR 15, c0, 1, c0, 1 // Cache Size ID Registers
  108. #define HAL_CP_AIDR 15, c0, 1, c0, 7 // Auxiliary ID Register
  109. #define HAL_CP_CSSELR 15, c0, 2, c0, 0 // Cache Size Selection Register
  110. #define HAL_CP_SCTLR 15, c1, 0, c0, 0 // System Control Register
  111. #define HAL_CP_ACTLR 15, c1, 0, c0, 1 // Auxiliary Control Register
  112. #define HAL_CP_CPACR 15, c1, 0, c0, 2 // Coprocessor Access Control Register
  113. #define HAL_CP_SCR 15, c1, 0, c1, 0 // Secure Configuration Register
  114. #define HAL_CP_SDER 15, c1, 0, c1, 1 // Secure Debug Enable Register
  115. #define HAL_CP_NSACR 15, c1, 0, c1, 2 // Non-Secure Access Control Register
  116. #define HAL_CP_VCR 15, c1, 0, c1, 3 // Virtualization Control Register
  117. #define HAL_CP_TTBR0 15, c2, 0, c0, 0 // Translation Table Base Register 0
  118. #define HAL_CP_TTBR1 15, c2, 0, c0, 1 // Translation Table Base Register 1
  119. #define HAL_CP_TTBCR 15, c2, 0, c0, 2 // Translation Table Base Control Register
  120. #define HAL_CP_DACR 15, c3, 0, c0, 0 // Domain Access Control Register
  121. #define HAL_CP_DFSR 15, c5, 0, c0, 0 // Data Fault Status Register
  122. #define HAL_CP_IFSR 15, c5, 0, c0, 1 // Instruction Fault Status Register
  123. #define HAL_CP_ADFSR 15, c5, 0, c1, 0 // Auxiliary Data Fault Status Register
  124. #define HAL_CP_AIFSR 15, c5, 0, c1, 1 // Auxiliary Instruction Fault Status Register
  125. #define HAL_CP_DFAR 15, c6, 0, c0, 0 // Data Fault Address Register
  126. #define HAL_CP_IFAR 15, c6, 0, c0, 2 // Instruction Fault Address Register
  127. #define HAL_CP_PAR 15, c7, 0, c4, 0 // Physical Address Register
  128. #define HAL_CP_ICIALLU 15, c7, 0, c5, 0 // Instruction Cache Invalidate All to PoU
  129. #define HAL_CP_ICIMVAU 15, c7, 0, c5, 1 // Instruction Cache Invalidate by MVA to PoU
  130. #define HAL_CP_DCIMVAC 15, c7, 0, c6, 1 // Data Cache Invalidate by MVA to PoC
  131. #define HAL_CP_DCISW 15, c7, 0, c6, 2 // Data Cache Invalidate by Set/Way
  132. #define HAL_CP_DCCMVAC 15, c7, 0, c10, 1 // Data Cache Clean by MVA to PoC
  133. #define HAL_CP_DCCSW 15, c7, 0, c10, 2 // Data Cache Clean by Set/Way
  134. #define HAL_CP_DCCIMVAC 15, c7, 0, c14, 1 // Data Cache Clean and Invalidate by MVA to PoC
  135. #define HAL_CP_DCCISW 15, c7, 0, c14, 2 // Data Cache Clean and Invalidate by Set/Way
  136. #define HAL_CP_PRRR 15, c10, 0, c2, 0 // Primary Region Remap Register
  137. #define HAL_CP_NMRR 15, c10, 0, c2, 1 // Normal Region Remap Register
  138. #define HAL_CP_VBAR 15, c12, 0, c0, 0 // Vector Base Address Register
  139. #define HAL_CP_MVBAR 15, c12, 0, c0, 1 // Monitor Vector Base Address Register
  140. #define HAL_CP_ISR 15, c12, 0, c1, 0 // Interrupt Status Register
  141. #define HAL_CP_VIR 15, c12, 0, c1, 1 // Virtualization Interrupt Register
  142. #define HAL_CP_CONTEXT 15, c13, 0, c0, 1 // Context ID Register
  143. #define HAL_CP_TPIDRURW 15, c13, 0, c0, 2 // User Read/Write Thread ID Register
  144. #define HAL_CP_TPIDRURO 15, c13, 0, c0, 3 // User Read-Only Thread ID Register
  145. #define HAL_CP_TPIDRPRW 15, c13, 0, c0, 4 // PL1 only Thread ID Register
  146. #define HAL_CP_CBAR 15, c15, 4, c0, 0 // Configuration Base Address
  147. #define HAL_CP_TLBHR 15, c15, 5, c0, 0 // TLB Hitmap
  148. #define __HAL_READ_CP(cp, CRn, opc1, CRm, opc2) ({ \
  149. uint32_t result; \
  150. asm volatile("MRC p" #cp ", " #opc1 ", %0, " #CRn ", " #CRm ", " #opc2 \
  151. : "=r"(result) \
  152. : \
  153. : "memory"); \
  154. result; \
  155. })
  156. #define __HAL_WRITE_CP(value, cp, CRn, opc1, CRm, opc2) \
  157. do \
  158. { \
  159. asm volatile("MCR p" #cp ", " #opc1 ", %0, " #CRn ", " #CRm ", " #opc2 \
  160. : \
  161. : "r"(value) \
  162. : "memory"); \
  163. } while (0)
  164. #endif
  165. // Range in [start, end]
  166. #define HWP_ADDRESS_RANGE(hwp) (uintptr_t)(hwp), (uintptr_t)(hwp) + sizeof(*(hwp)) - 1
  167. /**
  168. * \brief register value by fields
  169. */
  170. #define REGT_VAL(type, ...) __REGT_VAL(type, ##__VA_ARGS__)
  171. /**
  172. * \brief pair of (mask, value)
  173. */
  174. #define REGT_MASKVAL(type, ...) __REGT_MASK(type, ##__VA_ARGS__), __REGT_VAL(type, ##__VA_ARGS__)
  175. /**
  176. * \brief write register fields by register type
  177. *
  178. * All other fields not listed are write to 0. Now, at most 9 fields are supported.
  179. * The return value is the value to be written to register.
  180. *
  181. * Example:
  182. * \code{.cpp}
  183. * unsigned val = REGT_FIELD_WRITE(hwp_sysCtrl->sel_clock, REG_SYS_CTRL_SEL_CLOCK_T,
  184. * sys_sel_fast, 1, soft_sel_spiflash, 1);
  185. * \endcode
  186. */
  187. #define REGT_FIELD_WRITE(reg, type, ...) __REGT_FIELD_WRITE(reg, type, ##__VA_ARGS__)
  188. /**
  189. * \brief change register fields by register type
  190. *
  191. * Similar to \p REGT_FIELD_WRITE, just all other fields not listed will be kept.
  192. * Inside, it is read-modify-write.
  193. */
  194. #define REGT_FIELD_CHANGE(reg, type, ...) __REGT_FIELD_CHANGE(reg, type, ##__VA_ARGS__)
  195. /**
  196. * \brief get register field
  197. */
  198. #define REGT_FIELD_GET(reg, type, field) __REGT_FIELD_GET(reg, type, field)
  199. /**
  200. * \brief write ADI register fields by register type
  201. *
  202. * Similar to \p REGT_FIELD_WRITE, just the register is ADI register.
  203. */
  204. #define REGT_ADI_FIELD_WRITE(reg, type, ...) __REGT_ADI_FIELD_WRITE(reg, type, ##__VA_ARGS__)
  205. /**
  206. * \brief change ADI register fields by register type
  207. *
  208. * Similar to \p REGT_FIELD_CHANGE, just the register is ADI register.
  209. */
  210. #define REGT_ADI_FIELD_CHANGE(reg, type, ...) __REGT_ADI_FIELD_CHANGE(reg, type, ##__VA_ARGS__)
  211. /**
  212. * \brief get ADI register field
  213. */
  214. #define REGT_ADI_FIELD_GET(reg, type, field) __REGT_ADI_FIELD_GET(reg, type, field)
  215. /**
  216. * \brief write register fields by a variable
  217. *
  218. * Similar to \p REGT_FIELD_WRITE, just the second parameter is a variable with
  219. * type of the register.
  220. *
  221. * Example:
  222. * \code{.cpp}
  223. * REG_SYS_CTRL_SEL_CLOCK_T sel_clock;
  224. * unsigned val = REGV_FIELD_WRITE(hwp_sysCtrl->sel_clock, sel_clock,
  225. * sys_sel_fast, 1, soft_sel_spiflash, 1);
  226. * \endcode
  227. */
  228. #define REGV_FIELD_WRITE(reg, var, ...) __REGV_FIELD_WRITE(reg, var, ##__VA_ARGS__)
  229. /**
  230. * \brief change register fields by a variable
  231. *
  232. * Similar to \p REGT_FIELD_CHANGE, just the second parameter is a variable with
  233. * type of the register.
  234. */
  235. #define REGV_FIELD_CHANGE(reg, var, ...) __REGV_FIELD_CHANGE(reg, var, ##__VA_ARGS__)
  236. /**
  237. * \brief get register field
  238. */
  239. #define REGV_FIELD_GET(reg, var, field) __REGV_FIELD_GET(reg, var, field)
  240. /**
  241. * \brief write ADI register fields by a variable
  242. *
  243. * Similar to \p REGT_ADI_FIELD_WRITE, just the second parameter is a variable with
  244. * type of the register.
  245. */
  246. #define REGV_ADI_FIELD_WRITE(reg, var, ...) __REGV_ADI_FIELD_WRITE(reg, var, ##__VA_ARGS__)
  247. /**
  248. * \brief change ADI register fields by a variable
  249. *
  250. * Similar to \p REGT_ADI_FIELD_CHANGE, just the second parameter is a variable with
  251. * type of the register.
  252. */
  253. #define REGV_ADI_FIELD_CHANGE(reg, var, ...) __REGV_ADI_FIELD_CHANGE(reg, var, ##__VA_ARGS__)
  254. /**
  255. * \brief get register field
  256. */
  257. #define REGV_ADI_FIELD_GET(reg, var, field) __REGV_ADI_FIELD_GET(reg, var, field)
  258. /**
  259. * \brief loop wait register field to meet a condition by register type
  260. *
  261. * Example:
  262. * \code{.cpp}
  263. * REGT_WAIT_FIELD_NEZ(hwp_sysCtrl->sel_clock, REG_SYS_CTRL_SEL_CLOCK_T, pll_locked);
  264. * \endcode
  265. */
  266. #define REGT_WAIT_FIELD_EQ(reg, type, field, expected) _REGT_WAIT_FIELD(reg, type, field, expected, _REG_WAIT_OP_EQ)
  267. #define REGT_WAIT_FIELD_NE(reg, type, field, expected) _REGT_WAIT_FIELD(reg, type, field, expected, _REG_WAIT_OP_NE)
  268. #define REGT_WAIT_FIELD_GT(reg, type, field, expected) _REGT_WAIT_FIELD(reg, type, field, expected, _REG_WAIT_OP_GT)
  269. #define REGT_WAIT_FIELD_GE(reg, type, field, expected) _REGT_WAIT_FIELD(reg, type, field, expected, _REG_WAIT_OP_GE)
  270. #define REGT_WAIT_FIELD_LT(reg, type, field, expected) _REGT_WAIT_FIELD(reg, type, field, expected, _REG_WAIT_OP_LT)
  271. #define REGT_WAIT_FIELD_LE(reg, type, field, expected) _REGT_WAIT_FIELD(reg, type, field, expected, _REG_WAIT_OP_LE)
  272. #define REGT_WAIT_FIELD_EQZ(reg, type, field) REGT_WAIT_FIELD_EQ(reg, type, field, 0)
  273. #define REGT_WAIT_FIELD_NEZ(reg, type, field) REGT_WAIT_FIELD_NE(reg, type, field, 0)
  274. /**
  275. * \brief loop wait ADI register field to meet a condition by register type
  276. */
  277. #define REGT_ADI_WAIT_FIELD_EQ(reg, type, field, expected) _REGT_ADI_WAIT_FIELD(reg, type, field, expected, _REG_WAIT_OP_EQ)
  278. #define REGT_ADI_WAIT_FIELD_NE(reg, type, field, expected) _REGT_ADI_WAIT_FIELD(reg, type, field, expected, _REG_WAIT_OP_NE)
  279. #define REGT_ADI_WAIT_FIELD_GT(reg, type, field, expected) _REGT_ADI_WAIT_FIELD(reg, type, field, expected, _REG_WAIT_OP_GT)
  280. #define REGT_ADI_WAIT_FIELD_GE(reg, type, field, expected) _REGT_ADI_WAIT_FIELD(reg, type, field, expected, _REG_WAIT_OP_GE)
  281. #define REGT_ADI_WAIT_FIELD_LT(reg, type, field, expected) _REGT_ADI_WAIT_FIELD(reg, type, field, expected, _REG_WAIT_OP_LT)
  282. #define REGT_ADI_WAIT_FIELD_LE(reg, type, field, expected) _REGT_ADI_WAIT_FIELD(reg, type, field, expected, _REG_WAIT_OP_LE)
  283. #define REGT_ADI_WAIT_FIELD_EQZ(reg, type, field) REGT_ADI_WAIT_FIELD_EQ(reg, type, field, 0)
  284. #define REGT_ADI_WAIT_FIELD_NEZ(reg, type, field) REGT_ADI_WAIT_FIELD_NE(reg, type, field, 0)
  285. /**
  286. * \brief loop wait register field to meet a condition by a variable
  287. *
  288. * Example:
  289. * \code{.cpp}
  290. * REG_SYS_CTRL_SEL_CLOCK_T sel_clock;
  291. * REG_WAIT_FIELD_NEZ(sel_clock, hwp_sysCtrl->sel_clock, pll_locked);
  292. * \endcode
  293. */
  294. #define REGV_WAIT_FIELD_EQ(reg, var, field, expected) _REGV_WAIT_FIELD(reg, var, field, expected, _REG_WAIT_OP_EQ)
  295. #define REGV_WAIT_FIELD_NE(reg, var, field, expected) _REGV_WAIT_FIELD(reg, var, field, expected, _REG_WAIT_OP_NE)
  296. #define REGV_WAIT_FIELD_GT(reg, var, field, expected) _REGV_WAIT_FIELD(reg, var, field, expected, _REG_WAIT_OP_GT)
  297. #define REGV_WAIT_FIELD_GE(reg, var, field, expected) _REGV_WAIT_FIELD(reg, var, field, expected, _REG_WAIT_OP_GE)
  298. #define REGV_WAIT_FIELD_LT(reg, var, field, expected) _REGV_WAIT_FIELD(reg, var, field, expected, _REG_WAIT_OP_LT)
  299. #define REGV_WAIT_FIELD_LE(reg, var, field, expected) _REGV_WAIT_FIELD(reg, var, field, expected, _REG_WAIT_OP_LE)
  300. #define REGV_WAIT_FIELD_EQZ(reg, var, field) REGV_WAIT_FIELD_EQ(reg, var, field, 0)
  301. #define REGV_WAIT_FIELD_NEZ(reg, var, field) REGV_WAIT_FIELD_NE(reg, var, field, 0)
  302. /**
  303. * \brief loop wait ADI register field to meet a condition by a variable
  304. */
  305. #define REGV_ADI_WAIT_FIELD_EQ(reg, var, field, expected) _REGV_ADI_WAIT_FIELD(reg, var, field, expected, _REG_WAIT_OP_EQ)
  306. #define REGV_ADI_WAIT_FIELD_NE(reg, var, field, expected) _REGV_ADI_WAIT_FIELD(reg, var, field, expected, _REG_WAIT_OP_NE)
  307. #define REGV_ADI_WAIT_FIELD_GT(reg, var, field, expected) _REGV_ADI_WAIT_FIELD(reg, var, field, expected, _REG_WAIT_OP_GT)
  308. #define REGV_ADI_WAIT_FIELD_GE(reg, var, field, expected) _REGV_ADI_WAIT_FIELD(reg, var, field, expected, _REG_WAIT_OP_GE)
  309. #define REGV_ADI_WAIT_FIELD_LT(reg, var, field, expected) _REGV_ADI_WAIT_FIELD(reg, var, field, expected, _REG_WAIT_OP_LT)
  310. #define REGV_ADI_WAIT_FIELD_LE(reg, var, field, expected) _REGV_ADI_WAIT_FIELD(reg, var, field, expected, _REG_WAIT_OP_LE)
  311. #define REGV_ADI_WAIT_FIELD_EQZ(reg, var, field) REGV_ADI_WAIT_FIELD_EQ(reg, var, field, 0)
  312. #define REGV_ADI_WAIT_FIELD_NEZ(reg, var, field) REGV_ADI_WAIT_FIELD_NE(reg, var, field, 0)
  313. // ============================================================================
  314. // Implementation
  315. // ============================================================================
  316. #define _REGT_WAIT_FIELD(reg, type, field, expected, op) \
  317. do \
  318. { \
  319. type var; \
  320. for (;;) \
  321. { \
  322. (var).v = (reg); \
  323. if (op((var).b.field, (expected))) \
  324. break; \
  325. } \
  326. } while (0)
  327. #define _REGT_ADI_WAIT_FIELD(reg, type, field, expected, op) \
  328. do \
  329. { \
  330. type var; \
  331. for (;;) \
  332. { \
  333. (var).v = halAdiBusRead(&(reg)); \
  334. if (op((var).b.field, (expected))) \
  335. break; \
  336. } \
  337. } while (0)
  338. #define _REGV_WAIT_FIELD(reg, var, field, expected, op) \
  339. do \
  340. { \
  341. for (;;) \
  342. { \
  343. (var).v = (reg); \
  344. if (op((var).b.field, (expected))) \
  345. break; \
  346. } \
  347. } while (0)
  348. #define _REGV_ADI_WAIT_FIELD(reg, var, field, expected, op) \
  349. do \
  350. { \
  351. for (;;) \
  352. { \
  353. (var).v = halAdiBusRead(&(reg)); \
  354. if (op((var).b.field, (expected))) \
  355. break; \
  356. } \
  357. } while (0)
  358. #define _REG_WAIT_OP_EQ(a, b) ((a) == (b))
  359. #define _REG_WAIT_OP_NE(a, b) ((a) != (b))
  360. #define _REG_WAIT_OP_GT(a, b) ((a) > (b))
  361. #define _REG_WAIT_OP_GE(a, b) ((a) >= (b))
  362. #define _REG_WAIT_OP_LT(a, b) ((a) < (b))
  363. #define _REG_WAIT_OP_LE(a, b) ((a) <= (b))
  364. #define __REGT_FIELD_WRITE(reg, type, ...) ({ \
  365. type _val = {}; \
  366. __REGV_SET(_val, __VA_ARGS__); \
  367. reg = _val.v; \
  368. _val.v; \
  369. })
  370. #define __REGT_FIELD_CHANGE(reg, type, ...) ({ \
  371. type _val = {.v = reg}; \
  372. __REGV_SET(_val, __VA_ARGS__); \
  373. reg = _val.v; \
  374. _val.v; \
  375. })
  376. #define __REGT_FIELD_GET(reg, type, f) ({ \
  377. type _val = {.v = reg}; \
  378. _val.b.f; \
  379. })
  380. #define __REGT_ADI_FIELD_WRITE(reg, type, ...) ({ \
  381. type _val = {}; \
  382. __REGV_SET(_val, __VA_ARGS__); \
  383. halAdiBusWrite(&(reg), _val.v); \
  384. _val.v; \
  385. })
  386. #define __REGT_ADI_FIELD_CHANGE(reg, type, ...) ({ \
  387. type _val = {}; \
  388. __REGV_SET(_val, __VA_ARGS__); \
  389. type _maskoff = {0xffffffff}; \
  390. __REGV_MASKOFF(_maskoff, __VA_ARGS__); \
  391. halAdiBusChange(&(reg), ~_maskoff.v, _val.v); \
  392. })
  393. #define __REGT_ADI_FIELD_GET(reg, type, f) ({ \
  394. type _val = {.v = halAdiBusRead(&(reg))}; \
  395. _val.b.f; \
  396. })
  397. #define __REGV_FIELD_WRITE(reg, var, ...) ({ \
  398. var.v = 0; \
  399. __REGV_SET(var, __VA_ARGS__); \
  400. reg = var.v; \
  401. var.v; \
  402. })
  403. #define __REGV_FIELD_CHANGE(reg, var, ...) ({ \
  404. var.v = reg; \
  405. __REGV_SET(var, __VA_ARGS__); \
  406. reg = var.v; \
  407. var.v; \
  408. })
  409. #define __REGV_FIELD_GET(reg, var, f) ({ \
  410. var.v = reg; \
  411. var.b.f; \
  412. })
  413. #define __REGV_ADI_FIELD_WRITE(reg, var, ...) ({ \
  414. var.v = 0; \
  415. __REGV_SET(var, __VA_ARGS__); \
  416. halAdiBusWrite(&(reg), var.v); \
  417. var.v; \
  418. })
  419. #define __REGV_ADI_FIELD_CHANGE(reg, var, ...) ({ \
  420. var.v = 0xffffffff; \
  421. __REGV_MASKOFF(var, __VA_ARGS__); \
  422. unsigned _maskoff = var.v; \
  423. var.v = 0; \
  424. __REGV_SET(var, __VA_ARGS__); \
  425. unsigned _val = var.v; \
  426. halAdiBusChange(&(reg), ~_maskoff, _val); \
  427. })
  428. #define __REGV_ADI_FIELD_GET(reg, var, f) ({ \
  429. var.v = halAdiBusRead(&(reg)); \
  430. var.b.f; \
  431. })
  432. #define __REGT_MASK(type, ...) ({ type _val = {0xffffffff}; __REGV_MASKOFF(_val, __VA_ARGS__); ~_val.v; })
  433. #define __REGT_VAL(type, ...) ({ type _val = {0}; __REGV_SET(_val, __VA_ARGS__); _val.v; })
  434. #define __REGV_SET_IMP2(count, ...) __REGV_SET_##count(__VA_ARGS__)
  435. #define __REGV_SET_IMP1(count, ...) __REGV_SET_IMP2(count, __VA_ARGS__)
  436. #define __REGV_SET(...) __REGV_SET_IMP1(OSI_VA_NARGS(__VA_ARGS__), __VA_ARGS__)
  437. #define __REGV_MASKOFF_IMP2(count, ...) __REGV_MASKOFF_##count(__VA_ARGS__)
  438. #define __REGV_MASKOFF_IMP1(count, ...) __REGV_MASKOFF_IMP2(count, __VA_ARGS__)
  439. #define __REGV_MASKOFF(...) __REGV_MASKOFF_IMP1(OSI_VA_NARGS(__VA_ARGS__), __VA_ARGS__)
  440. #define __REGV_SET_3(v, f1, v1) ({ v.b.f1 = v1; })
  441. #define __REGV_SET_5(v, f1, v1, ...) ({ v.b.f1 = v1; __REGV_SET_3(v, __VA_ARGS__); })
  442. #define __REGV_SET_7(v, f1, v1, ...) ({ v.b.f1 = v1; __REGV_SET_5(v, __VA_ARGS__); })
  443. #define __REGV_SET_9(v, f1, v1, ...) ({ v.b.f1 = v1; __REGV_SET_7(v, __VA_ARGS__); })
  444. #define __REGV_SET_11(v, f1, v1, ...) ({ v.b.f1 = v1; __REGV_SET_9(v, __VA_ARGS__); })
  445. #define __REGV_SET_13(v, f1, v1, ...) ({ v.b.f1 = v1; __REGV_SET_11(v, __VA_ARGS__); })
  446. #define __REGV_SET_15(v, f1, v1, ...) ({ v.b.f1 = v1; __REGV_SET_13(v, __VA_ARGS__); })
  447. #define __REGV_SET_17(v, f1, v1, ...) ({ v.b.f1 = v1; __REGV_SET_15(v, __VA_ARGS__); })
  448. #define __REGV_SET_19(v, f1, v1, ...) ({ v.b.f1 = v1; __REGV_SET_17(v, __VA_ARGS__); })
  449. #define __REGV_MASKOFF_3(v, f1, v1) ({ v.b.f1 = 0; })
  450. #define __REGV_MASKOFF_5(v, f1, v1, ...) ({ v.b.f1 = 0; __REGV_MASKOFF_3(v, __VA_ARGS__); })
  451. #define __REGV_MASKOFF_7(v, f1, v1, ...) ({ v.b.f1 = 0; __REGV_MASKOFF_5(v, __VA_ARGS__); })
  452. #define __REGV_MASKOFF_9(v, f1, v1, ...) ({ v.b.f1 = 0; __REGV_MASKOFF_7(v, __VA_ARGS__); })
  453. #define __REGV_MASKOFF_11(v, f1, v1, ...) ({ v.b.f1 = 0; __REGV_MASKOFF_9(v, __VA_ARGS__); })
  454. #define __REGV_MASKOFF_13(v, f1, v1, ...) ({ v.b.f1 = 0; __REGV_MASKOFF_11(v, __VA_ARGS__); })
  455. #define __REGV_MASKOFF_15(v, f1, v1, ...) ({ v.b.f1 = 0; __REGV_MASKOFF_13(v, __VA_ARGS__); })
  456. #define __REGV_MASKOFF_17(v, f1, v1, ...) ({ v.b.f1 = 0; __REGV_MASKOFF_15(v, __VA_ARGS__); })
  457. #define __REGV_MASKOFF_19(v, f1, v1, ...) ({ v.b.f1 = 0; __REGV_MASKOFF_17(v, __VA_ARGS__); })
  458. // ============================================================================
  459. // Oboleted
  460. // ============================================================================
  461. // hardware registers are defined as union. The template of union is
  462. // union {
  463. // uint32_t v;
  464. // struct {
  465. // uint32_t f1 : 1;
  466. // uint32_t f2 : 2;
  467. // uint32_t f3 : 3;
  468. // ......
  469. // } b;
  470. // };
  471. //
  472. // The following macros are helpers for bit field operations:
  473. // * REG_FIELD_GET: read the register, and return the value of specified field.
  474. // * REG_WAIT_FIELD_EQ/NE/GT/GE/LT/LE/EQZ/NEZ: wait until the register fields
  475. // meet the condition.
  476. // * REG_FIELD_MASK: return a mask (1 for the specified fields) of one or more
  477. // fields. In the above example, mask for f1 and f3 is 0x00000039
  478. // * REG_FIELD_VALUE: return a value with specified fields, other fields are 0.
  479. // * REG_FIELD_MASKVAL: return "mask, value"
  480. // * REG_FIELD_CHANGE: change the specified fields, and other fields are
  481. // untouched. The changed value is returned
  482. // * REG_FIELD_WRITE: write register with specified fields, and other fields
  483. // are 0, return the value to be written to register
  484. #define REGTYPE_FIELD_GET(type, var, f1) ({ type _var = {(var)}; _var.b.f1; })
  485. #define REGTYPE_FIELD_VAL(type, f1, v1) ({ type _var = {.b={.f1=(v1)}}; _var.v; })
  486. #define REGTYPE_FIELD_MASK(type, f1) ({ type _var = {0xffffffff}; _var.b.f1 = 0; ~_var.v; })
  487. #define REG_FIELD_GET(r, var, f) ({ var.v = r; var.b.f; })
  488. #define REG_WAIT_FIELD_EQ(var, reg, field, expected) _REG_WAIT_FIELD(var, reg, field, expected, _REG_WAIT_OP_EQ)
  489. #define REG_WAIT_FIELD_NE(var, reg, field, expected) _REG_WAIT_FIELD(var, reg, field, expected, _REG_WAIT_OP_NE)
  490. #define REG_WAIT_FIELD_GT(var, reg, field, expected) _REG_WAIT_FIELD(var, reg, field, expected, _REG_WAIT_OP_GT)
  491. #define REG_WAIT_FIELD_GE(var, reg, field, expected) _REG_WAIT_FIELD(var, reg, field, expected, _REG_WAIT_OP_GE)
  492. #define REG_WAIT_FIELD_LT(var, reg, field, expected) _REG_WAIT_FIELD(var, reg, field, expected, _REG_WAIT_OP_LT)
  493. #define REG_WAIT_FIELD_LE(var, reg, field, expected) _REG_WAIT_FIELD(var, reg, field, expected, _REG_WAIT_OP_LE)
  494. #define REG_WAIT_FIELD_EQZ(var, reg, field) REG_WAIT_FIELD_EQ(var, reg, field, 0)
  495. #define REG_WAIT_FIELD_NEZ(var, reg, field) REG_WAIT_FIELD_NE(var, reg, field, 0)
  496. #define REG_WAIT_COND(cond) \
  497. do \
  498. { \
  499. while (!(cond)) \
  500. ; \
  501. } while (0)
  502. #define REG_FIELD_MASK1(var, f1) ({ var.v = 0xffffffff; var.b.f1 = 0; var.v = ~var.v; var.v; })
  503. #define REG_FIELD_MASK2(var, f1, f2) ({ var.v = 0xffffffff; var.b.f1 = 0; var.b.f2 = 0; var.v = ~var.v; var.v; })
  504. #define REG_FIELD_MASK3(var, f1, f2, f3) ({ var.v = 0xffffffff; var.b.f1 = 0; var.b.f2 = 0; var.b.f3 = 0; var.v = ~var.v; var.v; })
  505. #define REG_FIELD_MASK4(var, f1, f2, f3, f4) ({ var.v = 0xffffffff; var.b.f1 = 0; var.b.f2 = 0; var.b.f3 = 0; var.b.f4 = 0; var.v = ~var.v; var.v; })
  506. #define REG_FIELD_MASK5(var, f1, f2, f3, f4, f5) ({ var.v = 0xffffffff; var.b.f1 = 0; var.b.f2 = 0; var.b.f3 = 0; var.b.f4 = 0; var.b.f5 = 0; var.v = ~var.v; var.v; })
  507. #define REG_FIELD_MASK6(var, f1, f2, f3, f4, f5, f6) ({ var.v = 0xffffffff; var.b.f1 = 0; var.b.f2 = 0; var.b.f3 = 0; var.b.f4 = 0; var.b.f5 = 0; var.b.f6 = 0; var.v = ~var.v; var.v; })
  508. #define REG_FIELD_VALUE1(var, f1, v1) ({ var.v = 0; var.b.f1 = v1; var.v; })
  509. #define REG_FIELD_VALUE2(var, f1, v1, f2, v2) ({ var.v = 0; var.b.f1 = v1; var.b.f2 = v2; var.v; })
  510. #define REG_FIELD_VALUE3(var, f1, v1, f2, v2, f3, v3) ({ var.v = 0; var.b.f1 = v1; var.b.f2 = v2; var.b.f3 = v3; var.v; })
  511. #define REG_FIELD_VALUE4(var, f1, v1, f2, v2, f3, v3, f4, v4) ({ var.v = 0; var.b.f1 = v1; var.b.f2 = v2; var.b.f3 = v3; var.b.f4 = v4; var.v; })
  512. #define REG_FIELD_VALUE5(var, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5) ({ var.v = 0; var.b.f1 = v1; var.b.f2 = v2; var.b.f3 = v3; var.b.f4 = v4; var.b.f5 = v5; var.v; })
  513. #define REG_FIELD_VALUE6(var, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6) ({ var.v = 0; var.b.f1 = v1; var.b.f2 = v2; var.b.f3 = v3; var.b.f4 = v4; var.b.f5 = v5; var.b.f6 = v6; var.v; })
  514. #define REG_FIELD_MASKVAL1(var, f1, v1) REG_FIELD_MASK1(var, f1), REG_FIELD_VALUE1(var, f1, v1)
  515. #define REG_FIELD_MASKVAL2(var, f1, v1, f2, v2) REG_FIELD_MASK2(var, f1, f2), REG_FIELD_VALUE2(var, f1, v1, f2, v2)
  516. #define REG_FIELD_MASKVAL3(var, f1, v1, f2, v2, f3, v3) REG_FIELD_MASK3(var, f1, f2, f3), REG_FIELD_VALUE3(var, f1, v1, f2, v2, f3, v3)
  517. #define REG_FIELD_MASKVAL4(var, f1, v1, f2, v2, f3, v3, f4, v4) REG_FIELD_MASK4(var, f1, f2, f3, f4), REG_FIELD_VALUE4(var, f1, v1, f2, v2, f3, v3, f4, v4)
  518. #define REG_FIELD_MASKVAL5(var, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5) REG_FIELD_MASK5(var, f1, f2, f3, f4, f5), REG_FIELD_VALUE5(var, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5)
  519. #define REG_FIELD_MASKVAL6(var, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6) REG_FIELD_MASK6(var, f1, f2, f3, f4, f5, f6), REG_FIELD_VALUE6(var, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6)
  520. #define REG_FIELD_CHANGE1(r, var, f1, v1) ({ var.v = r; var.b.f1 = v1; r = var.v; var.v; })
  521. #define REG_FIELD_CHANGE2(r, var, f1, v1, f2, v2) ({ var.v = r; var.b.f1 = v1; var.b.f2 = v2; r = var.v; var.v; })
  522. #define REG_FIELD_CHANGE3(r, var, f1, v1, f2, v2, f3, v3) ({ var.v = r; var.b.f1 = v1; var.b.f2 = v2; var.b.f3 = v3; r = var.v; var.v; })
  523. #define REG_FIELD_CHANGE4(r, var, f1, v1, f2, v2, f3, v3, f4, v4) ({ var.v = r; var.b.f1 = v1; var.b.f2 = v2; var.b.f3 = v3; var.b.f4 = v4; r = var.v; var.v; })
  524. #define REG_FIELD_CHANGE5(r, var, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5) ({ var.v = r; var.b.f1 = v1; var.b.f2 = v2; var.b.f3 = v3; var.b.f4 = v4; var.b.f5 = v5; r = var.v; var.v; })
  525. #define REG_FIELD_CHANGE6(r, var, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6) ({ var.v = r; var.b.f1 = v1; var.b.f2 = v2; var.b.f3 = v3; var.b.f4 = v4; var.b.f5 = v5; var.b.f6 = v6; r = var.v; var.v; })
  526. #define REG_FIELD_WRITE1(r, var, f1, v1) ({ var.v = 0; var.b.f1 = v1; r = var.v; var.v; })
  527. #define REG_FIELD_WRITE2(r, var, f1, v1, f2, v2) ({ var.v = 0; var.b.f1 = v1; var.b.f2 = v2; r = var.v; var.v; })
  528. #define REG_FIELD_WRITE3(r, var, f1, v1, f2, v2, f3, v3) ({ var.v = 0; var.b.f1 = v1; var.b.f2 = v2; var.b.f3 = v3; r = var.v; var.v; })
  529. #define REG_FIELD_WRITE4(r, var, f1, v1, f2, v2, f3, v3, f4, v4) ({ var.v = 0; var.b.f1 = v1; var.b.f2 = v2; var.b.f3 = v3; var.b.f4 = v4; r = var.v; var.v; })
  530. #define REG_FIELD_WRITE5(r, var, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5) ({ var.v = 0; var.b.f1 = v1; var.b.f2 = v2; var.b.f3 = v3; var.b.f4 = v4; var.b.f5 = v5; r = var.v; var.v; })
  531. #define REG_FIELD_WRITE6(r, var, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6) ({ var.v = 0; var.b.f1 = v1; var.b.f2 = v2; var.b.f3 = v3; var.b.f4 = v4; var.b.f5 = v5; var.b.f6 = v6; r = var.v; var.v; })
  532. #define REG_ADI_CHANGE1(r, var, f1, v1) halAdiBusChange(&(r), REG_FIELD_MASKVAL1(var, f1, v1))
  533. #define REG_ADI_CHANGE2(r, var, f1, v1, f2, v2) halAdiBusChange(&(r), REG_FIELD_MASKVAL2(var, f1, v1, f2, v2))
  534. #define REG_ADI_CHANGE3(r, var, f1, v1, f2, v2, f3, v3) halAdiBusChange(&(r), REG_FIELD_MASKVAL3(var, f1, v1, f2, v2, f3, v3))
  535. #define REG_ADI_CHANGE4(r, var, f1, v1, f2, v2, f3, v3, f4, v4) halAdiBusChange(&(r), REG_FIELD_MASKVAL4(var, f1, v1, f2, v2, f3, v3, f4, v4))
  536. #define REG_ADI_CHANGE5(r, var, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5) halAdiBusChange(&(r), REG_FIELD_MASKVAL5(var, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5))
  537. #define REG_ADI_CHANGE6(r, var, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6) halAdiBusChange(&(r), REG_FIELD_MASKVAL6(var, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6))
  538. #define REG_ADI_WRITE1(r, var, f1, v1) halAdiBusWrite(&(r), REG_FIELD_VALUE1(var, f1, v1))
  539. #define REG_ADI_WRITE2(r, var, f1, v1, f2, v2) halAdiBusWrite(&(r), REG_FIELD_VALUE2(var, f1, v1, f2, v2))
  540. #define REG_ADI_WRITE3(r, var, f1, v1, f2, v2, f3, v3) halAdiBusWrite(&(r), REG_FIELD_VALUE3(var, f1, v1, f2, v2, f3, v3))
  541. #define REG_ADI_WRITE4(r, var, f1, v1, f2, v2, f3, v3, f4, v4) halAdiBusWrite(&(r), REG_FIELD_VALUE4(var, f1, v1, f2, v2, f3, v3, f4, v4))
  542. #define REG_ADI_WRITE5(r, var, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5) halAdiBusWrite(&(r), REG_FIELD_VALUE5(var, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5))
  543. #define REG_ADI_WRITE6(r, var, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6) halAdiBusWrite(&(r), REG_FIELD_VALUE6(var, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6))
  544. #define REG_ADI_WAIT_FIELD_EQ(var, reg, field, expected) _REG_ADI_WAIT_FIELD(var, reg, field, expected, _REG_WAIT_OP_EQ)
  545. #define REG_ADI_WAIT_FIELD_NE(var, reg, field, expected) _REG_ADI_WAIT_FIELD(var, reg, field, expected, _REG_WAIT_OP_NE)
  546. #define REG_ADI_WAIT_FIELD_GT(var, reg, field, expected) _REG_ADI_WAIT_FIELD(var, reg, field, expected, _REG_WAIT_OP_GT)
  547. #define REG_ADI_WAIT_FIELD_GE(var, reg, field, expected) _REG_ADI_WAIT_FIELD(var, reg, field, expected, _REG_WAIT_OP_GE)
  548. #define REG_ADI_WAIT_FIELD_LT(var, reg, field, expected) _REG_ADI_WAIT_FIELD(var, reg, field, expected, _REG_WAIT_OP_LT)
  549. #define REG_ADI_WAIT_FIELD_LE(var, reg, field, expected) _REG_ADI_WAIT_FIELD(var, reg, field, expected, _REG_WAIT_OP_LE)
  550. #define REG_ADI_WAIT_FIELD_EQZ(var, reg, field) REG_ADI_WAIT_FIELD_EQ(var, reg, field, 0)
  551. #define REG_ADI_WAIT_FIELD_NEZ(var, reg, field) REG_ADI_WAIT_FIELD_NE(var, reg, field, 0)
  552. #define _REG_WAIT_FIELD(var, reg, field, expected, op) \
  553. do \
  554. { \
  555. for (;;) \
  556. { \
  557. (var).v = (reg); \
  558. if (op((var).b.field, (expected))) \
  559. break; \
  560. } \
  561. } while (0)
  562. #define _REG_ADI_WAIT_FIELD(var, reg, field, expected, op) \
  563. do \
  564. { \
  565. for (;;) \
  566. { \
  567. (var).v = halAdiBusRead(&(reg)); \
  568. if (op((var).b.field, (expected))) \
  569. break; \
  570. } \
  571. } while (0)
  572. #ifdef __cplusplus
  573. }
  574. #endif
  575. #endif