ulp.h 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030
  1. /*
  2. * SPDX-FileCopyrightText: 2016-2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #pragma once
  7. #include <stdint.h>
  8. #include <stddef.h>
  9. #include <stdlib.h>
  10. #include "esp_err.h"
  11. #include "ulp_common.h"
  12. #include "ulp_fsm_common.h"
  13. #include "soc/reg_base.h"
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. /**
  18. * @defgroup ulp_registers ULP coprocessor registers
  19. * @{
  20. */
  21. #define R0 0 /*!< general purpose register 0 */
  22. #define R1 1 /*!< general purpose register 1 */
  23. #define R2 2 /*!< general purpose register 2 */
  24. #define R3 3 /*!< general purpose register 3 */
  25. /**@}*/
  26. /** @defgroup ulp_opcodes ULP coprocessor opcodes, sub opcodes, and various modifiers/flags
  27. *
  28. * These definitions are not intended to be used directly.
  29. * They are used in definitions of instructions later on.
  30. *
  31. * @{
  32. */
  33. #define OPCODE_WR_REG 1 /*!< Instruction: write peripheral register (RTC_CNTL/RTC_IO/SARADC) */
  34. #define OPCODE_RD_REG 2 /*!< Instruction: read peripheral register (RTC_CNTL/RTC_IO/SARADC) */
  35. #define RD_REG_PERIPH_RTC_CNTL 0 /*!< Identifier of RTC_CNTL peripheral for RD_REG and WR_REG instructions */
  36. #define RD_REG_PERIPH_RTC_IO 1 /*!< Identifier of RTC_IO peripheral for RD_REG and WR_REG instructions */
  37. #define RD_REG_PERIPH_SENS 2 /*!< Identifier of SARADC peripheral for RD_REG and WR_REG instructions */
  38. #define RD_REG_PERIPH_RTC_I2C 3 /*!< Identifier of RTC_I2C peripheral for RD_REG and WR_REG instructions */
  39. #define OPCODE_I2C 3 /*!< Instruction: read/write I2C */
  40. #define SUB_OPCODE_I2C_RD 0 /*!< I2C read */
  41. #define SUB_OPCODE_I2C_WR 1 /*!< I2C write */
  42. #define OPCODE_DELAY 4 /*!< Instruction: delay (nop) for a given number of cycles */
  43. #define OPCODE_ADC 5 /*!< Instruction: SAR ADC measurement */
  44. #define OPCODE_ST 6 /*!< Instruction: store indirect to RTC memory */
  45. #define SUB_OPCODE_ST 4 /*!< Store 32 bits, 16 MSBs contain PC, 16 LSBs contain value from source register */
  46. #define OPCODE_ALU 7 /*!< Arithmetic instructions */
  47. #define SUB_OPCODE_ALU_REG 0 /*!< Arithmetic instruction, both source values are in register */
  48. #define SUB_OPCODE_ALU_IMM 1 /*!< Arithmetic instruction, one source value is an immediate */
  49. #define SUB_OPCODE_ALU_CNT 2 /*!< Arithmetic instruction, stage counter and an immediate */
  50. #define ALU_SEL_ADD 0 /*!< Addition */
  51. #define ALU_SEL_SUB 1 /*!< Subtraction */
  52. #define ALU_SEL_AND 2 /*!< Logical AND */
  53. #define ALU_SEL_OR 3 /*!< Logical OR */
  54. #define ALU_SEL_MOV 4 /*!< Copy value (immediate to destination register or source register to destination register */
  55. #define ALU_SEL_LSH 5 /*!< Shift left by given number of bits */
  56. #define ALU_SEL_RSH 6 /*!< Shift right by given number of bits */
  57. #define ALU_SEL_SINC 0 /*!< Increment the stage counter */
  58. #define ALU_SEL_SDEC 1 /*!< Decrement the stage counter */
  59. #define ALU_SEL_SRST 2 /*!< Reset the stage counter */
  60. #define OPCODE_BRANCH 8 /*!< Branch instructions */
  61. #define SUB_OPCODE_BX 0 /*!< Branch to absolute PC (immediate or in register) */
  62. #define SUB_OPCODE_BR 1 /*!< Branch to relative PC, conditional on R0 */
  63. #define SUB_OPCODE_BS 2 /*!< Branch to relative PC, conditional on the stage counter */
  64. #define BX_JUMP_TYPE_DIRECT 0 /*!< Unconditional jump */
  65. #define BX_JUMP_TYPE_ZERO 1 /*!< Branch if last ALU result is zero */
  66. #define BX_JUMP_TYPE_OVF 2 /*!< Branch if last ALU operation caused and overflow */
  67. #define SUB_OPCODE_B 1 /*!< Branch to a relative offset */
  68. #define B_CMP_L 0 /*!< Branch if R0 is less than an immediate */
  69. #define B_CMP_GE 1 /*!< Branch if R0 is greater than or equal to an immediate */
  70. #define JUMPS_LT 0 /*!< Branch if the stage counter < */
  71. #define JUMPS_GE 1 /*!< Branch if the stage counter >= */
  72. #define JUMPS_LE 2 /*!< Branch if the stage counter <= */
  73. #define OPCODE_END 9 /*!< Stop executing the program */
  74. #define SUB_OPCODE_END 0 /*!< Stop executing the program and optionally wake up the chip */
  75. #define SUB_OPCODE_SLEEP 1 /*!< Stop executing the program and run it again after selected interval */
  76. #define OPCODE_TSENS 10 /*!< Instruction: temperature sensor measurement. Poor accuracy, not recommended for most use-cases */
  77. #define OPCODE_HALT 11 /*!< Halt the coprocessor */
  78. #define OPCODE_LD 13 /*!< Indirect load lower 16 bits from RTC memory */
  79. #define OPCODE_MACRO 15 /*!< Not a real opcode. Used to identify labels and branches in the program */
  80. #define SUB_OPCODE_MACRO_LABEL 0 /*!< Label macro */
  81. #define SUB_OPCODE_MACRO_BRANCH 1 /*!< Branch macro */
  82. #define SUB_OPCODE_MACRO_LABELPC 2 /*!< Label pointer macro */
  83. /**@}*/
  84. /**
  85. * @brief Instruction format structure
  86. *
  87. * All ULP instructions are 32 bit long.
  88. * This union contains field layouts used by all of the supported instructions.
  89. * This union also includes a special "macro" instruction layout.
  90. * This is not a real instruction which can be executed by the CPU. It acts
  91. * as a token which is removed from the program by the
  92. * ulp_process_macros_and_load function.
  93. *
  94. * These structures are not intended to be used directly.
  95. * Preprocessor definitions provided below fill the fields of these structure with
  96. * the right arguments.
  97. */
  98. union ulp_insn {
  99. struct {
  100. uint32_t cycles : 16; /*!< Number of cycles to sleep */
  101. uint32_t unused : 12; /*!< Unused */
  102. uint32_t opcode : 4; /*!< Opcode (OPCODE_DELAY) */
  103. } delay; /*!< Format of DELAY instruction */
  104. struct {
  105. uint32_t dreg : 2; /*!< Register which contains data to store */
  106. uint32_t sreg : 2; /*!< Register which contains address in RTC memory (expressed in words) */
  107. uint32_t unused1 : 6; /*!< Unused */
  108. uint32_t offset : 11; /*!< Offset to add to sreg */
  109. uint32_t unused2 : 4; /*!< Unused */
  110. uint32_t sub_opcode : 3; /*!< Sub opcode (SUB_OPCODE_ST) */
  111. uint32_t opcode : 4; /*!< Opcode (OPCODE_ST) */
  112. } st; /*!< Format of ST instruction */
  113. struct {
  114. uint32_t dreg : 2; /*!< Register where the data should be loaded to */
  115. uint32_t sreg : 2; /*!< Register which contains address in RTC memory (expressed in words) */
  116. uint32_t unused1 : 6; /*!< Unused */
  117. uint32_t offset : 11; /*!< Offset to add to sreg */
  118. uint32_t unused2 : 7; /*!< Unused */
  119. uint32_t opcode : 4; /*!< Opcode (OPCODE_LD) */
  120. } ld; /*!< Format of LD instruction */
  121. struct {
  122. uint32_t unused : 28; /*!< Unused */
  123. uint32_t opcode : 4; /*!< Opcode (OPCODE_HALT) */
  124. } halt; /*!< Format of HALT instruction */
  125. struct {
  126. uint32_t dreg : 2; /*!< Register which contains target PC, expressed in words (used if .reg == 1) */
  127. uint32_t addr : 11; /*!< Target PC, expressed in words (used if .reg == 0) */
  128. uint32_t unused : 8; /*!< Unused */
  129. uint32_t reg : 1; /*!< Target PC in register (1) or immediate (0) */
  130. uint32_t type : 3; /*!< Jump condition (BX_JUMP_TYPE_xxx) */
  131. uint32_t sub_opcode : 3; /*!< Sub opcode (SUB_OPCODE_BX) */
  132. uint32_t opcode : 4; /*!< Opcode (OPCODE_BRANCH) */
  133. } bx; /*!< Format of BRANCH instruction (absolute address) */
  134. struct {
  135. uint32_t imm : 16; /*!< Immediate value to compare against */
  136. uint32_t cmp : 1; /*!< Comparison to perform: B_CMP_L or B_CMP_GE */
  137. uint32_t offset : 7; /*!< Absolute value of target PC offset w.r.t. current PC, expressed in words */
  138. uint32_t sign : 1; /*!< Sign of target PC offset: 0: positive, 1: negative */
  139. uint32_t sub_opcode : 3; /*!< Sub opcode (SUB_OPCODE_B) */
  140. uint32_t opcode : 4; /*!< Opcode (OPCODE_BRANCH) */
  141. } b; /*!< Format of BRANCH instruction (relative address, conditional on R0) */
  142. struct {
  143. uint32_t imm : 8; /*!< Immediate value to compare against */
  144. uint32_t unused : 7; /*!< Unused */
  145. uint32_t cmp : 2; /*!< Comparison to perform: JUMPS_LT, JUMPS_GE or JUMPS_LE */
  146. uint32_t offset : 7; /*!< Absolute value of target PC offset w.r.t. current PC, expressed in words */
  147. uint32_t sign : 1; /*!< Sign of target PC offset: 0: positive, 1: negative */
  148. uint32_t sub_opcode : 3; /*!< Sub opcode (SUB_OPCODE_BS) */
  149. uint32_t opcode : 4; /*!< Opcode (OPCODE_BRANCH) */
  150. } bs; /*!< Format of BRANCH instruction (relative address, conditional on the stage counter) */
  151. struct {
  152. uint32_t dreg : 2; /*!< Destination register */
  153. uint32_t sreg : 2; /*!< Register with operand A */
  154. uint32_t treg : 2; /*!< Register with operand B */
  155. uint32_t unused : 15; /*!< Unused */
  156. uint32_t sel : 4; /*!< Operation to perform, one of ALU_SEL_xxx */
  157. uint32_t sub_opcode : 3; /*!< Sub opcode (SUB_OPCODE_ALU_REG) */
  158. uint32_t opcode : 4; /*!< Opcode (OPCODE_ALU) */
  159. } alu_reg; /*!< Format of ALU instruction (both sources are registers) */
  160. struct {
  161. uint32_t unused1 : 4; /*!< Unused */
  162. uint32_t imm : 8; /*!< Immediate value of operand */
  163. uint32_t unused2 : 9; /*!< Unused */
  164. uint32_t sel : 4; /*!< Operation to perform, one of ALU_SEL_Sxxx */
  165. uint32_t sub_opcode : 3; /*!< Sub opcode (SUB_OPCODE_ALU_CNT) */
  166. uint32_t opcode : 4; /*!< Opcode (OPCODE_ALU) */
  167. } alu_reg_s; /*!< Format of ALU instruction (stage counter and an immediate) */
  168. struct {
  169. uint32_t dreg : 2; /*!< Destination register */
  170. uint32_t sreg : 2; /*!< Register with operand A */
  171. uint32_t imm : 16; /*!< Immediate value of operand B */
  172. uint32_t unused : 1; /*!< Unused */
  173. uint32_t sel : 4; /*!< Operation to perform, one of ALU_SEL_xxx */
  174. uint32_t sub_opcode : 3; /*!< Sub opcode (SUB_OPCODE_ALU_IMM) */
  175. uint32_t opcode : 4; /*!< Opcode (OPCODE_ALU) */
  176. } alu_imm; /*!< Format of ALU instruction (one source is an immediate) */
  177. struct {
  178. uint32_t addr : 8; /*!< Address within either RTC_CNTL, RTC_IO, or SARADC */
  179. uint32_t periph_sel : 2; /*!< Select peripheral: RTC_CNTL (0), RTC_IO(1), SARADC(2) */
  180. uint32_t data : 8; /*!< 8 bits of data to write */
  181. uint32_t low : 5; /*!< Low bit */
  182. uint32_t high : 5; /*!< High bit */
  183. uint32_t opcode : 4; /*!< Opcode (OPCODE_WR_REG) */
  184. } wr_reg; /*!< Format of WR_REG instruction */
  185. struct {
  186. uint32_t addr : 8; /*!< Address within either RTC_CNTL, RTC_IO, or SARADC */
  187. uint32_t periph_sel : 2; /*!< Select peripheral: RTC_CNTL (0), RTC_IO(1), SARADC(2) */
  188. uint32_t unused : 8; /*!< Unused */
  189. uint32_t low : 5; /*!< Low bit */
  190. uint32_t high : 5; /*!< High bit */
  191. uint32_t opcode : 4; /*!< Opcode (OPCODE_RD_REG) */
  192. } rd_reg; /*!< Format of RD_REG instruction */
  193. struct {
  194. uint32_t dreg : 2; /*!< Register where to store ADC result */
  195. uint32_t mux : 4; /*!< Select SARADC pad (mux + 1) */
  196. uint32_t sar_sel : 1; /*!< Select SARADC0 (0) or SARADC1 (1) */
  197. uint32_t unused1 : 1; /*!< Unused */
  198. uint32_t cycles : 16; /*!< TBD, cycles used for measurement */
  199. uint32_t unused2 : 4; /*!< Unused */
  200. uint32_t opcode: 4; /*!< Opcode (OPCODE_ADC) */
  201. } adc; /*!< Format of ADC instruction */
  202. struct {
  203. uint32_t dreg : 2; /*!< Register where to store temperature measurement result */
  204. uint32_t wait_delay: 14; /*!< Cycles to wait after measurement is done */
  205. uint32_t reserved: 12; /*!< Reserved, set to 0 */
  206. uint32_t opcode: 4; /*!< Opcode (OPCODE_TSENS) */
  207. } tsens; /*!< Format of TSENS instruction */
  208. struct {
  209. uint32_t i2c_addr : 8; /*!< I2C slave address */
  210. uint32_t data : 8; /*!< 8 bits of data for write operation */
  211. uint32_t low_bits : 3; /*!< low bit of range for write operation (lower bits are masked) */
  212. uint32_t high_bits : 3; /*!< high bit of range for write operation (higher bits are masked) */
  213. uint32_t i2c_sel : 4; /*!< index of slave address register [7:0] */
  214. uint32_t unused : 1; /*!< Unused */
  215. uint32_t rw : 1; /*!< Write (1) or read (0) */
  216. uint32_t opcode : 4; /*!< Opcode (OPCODE_I2C) */
  217. } i2c; /*!< Format of I2C instruction */
  218. struct {
  219. uint32_t wakeup : 1; /*!< Set to 1 to wake up chip */
  220. uint32_t unused : 24; /*!< Unused */
  221. uint32_t sub_opcode : 3; /*!< Sub opcode (SUB_OPCODE_WAKEUP) */
  222. uint32_t opcode : 4; /*!< Opcode (OPCODE_END) */
  223. } end; /*!< Format of END instruction with wakeup */
  224. struct {
  225. uint32_t cycle_sel : 4; /*!< Select which one of SARADC_ULP_CP_SLEEP_CYCx_REG to get the sleep duration from */
  226. uint32_t unused : 21; /*!< Unused */
  227. uint32_t sub_opcode : 3; /*!< Sub opcode (SUB_OPCODE_SLEEP) */
  228. uint32_t opcode : 4; /*!< Opcode (OPCODE_END) */
  229. } sleep; /*!< Format of END instruction with sleep */
  230. struct {
  231. uint32_t dreg : 2; /*!< Destination register (for SUB_OPCODE_MACRO_LABELPC) > */
  232. uint32_t label : 16; /*!< Label number */
  233. uint32_t unused : 6; /*!< Unused */
  234. uint32_t sub_opcode : 4; /*!< SUB_OPCODE_MACRO_LABEL or SUB_OPCODE_MACRO_BRANCH or SUB_OPCODE_MACRO_LABELPC */
  235. uint32_t opcode: 4; /*!< Opcode (OPCODE_MACRO) */
  236. } macro; /*!< Format of tokens used by MACROs */
  237. uint32_t instruction; /*!< Encoded instruction for ULP coprocessor */
  238. };
  239. /**
  240. * Delay (nop) for a given number of cycles
  241. */
  242. #define I_DELAY(cycles_) { .delay = {\
  243. .cycles = cycles_, \
  244. .unused = 0, \
  245. .opcode = OPCODE_DELAY } }
  246. /**
  247. * Halt the coprocessor.
  248. *
  249. * This instruction halts the coprocessor, but keeps ULP timer active.
  250. * As such, ULP program will be restarted again by timer.
  251. * To stop the program and prevent the timer from restarting the program,
  252. * use I_END(0) instruction.
  253. */
  254. #define I_HALT() { .halt = {\
  255. .unused = 0, \
  256. .opcode = OPCODE_HALT } }
  257. /**
  258. * Map SoC peripheral register to periph_sel field of RD_REG and WR_REG
  259. * instructions.
  260. *
  261. * @param reg peripheral register in RTC_CNTL_, RTC_IO_, SENS_, RTC_I2C peripherals.
  262. * @return periph_sel value for the peripheral to which this register belongs.
  263. */
  264. static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg) {
  265. uint32_t ret = 3;
  266. if (reg < DR_REG_RTCCNTL_BASE) {
  267. assert(0 && "invalid register base");
  268. } else if (reg < DR_REG_RTCIO_BASE) {
  269. ret = RD_REG_PERIPH_RTC_CNTL;
  270. } else if (reg < DR_REG_SENS_BASE) {
  271. ret = RD_REG_PERIPH_RTC_IO;
  272. } else if (reg < DR_REG_RTC_I2C_BASE){
  273. ret = RD_REG_PERIPH_SENS;
  274. } else if (reg < DR_REG_IO_MUX_BASE){
  275. ret = RD_REG_PERIPH_RTC_I2C;
  276. } else {
  277. assert(0 && "invalid register base");
  278. }
  279. return ret;
  280. }
  281. /**
  282. * Write literal value to a peripheral register
  283. *
  284. * reg[high_bit : low_bit] = val
  285. * This instruction can access RTC_CNTL_, RTC_IO_, SENS_, and RTC_I2C peripheral registers.
  286. */
  287. #define I_WR_REG(reg, low_bit, high_bit, val) {.wr_reg = {\
  288. .addr = (reg & 0xff) / sizeof(uint32_t), \
  289. .periph_sel = SOC_REG_TO_ULP_PERIPH_SEL(reg), \
  290. .data = val, \
  291. .low = low_bit, \
  292. .high = high_bit, \
  293. .opcode = OPCODE_WR_REG } }
  294. /**
  295. * Read from peripheral register into R0
  296. *
  297. * R0 = reg[high_bit : low_bit]
  298. * This instruction can access RTC_CNTL_, RTC_IO_, SENS_, and RTC_I2C peripheral registers.
  299. */
  300. #define I_RD_REG(reg, low_bit, high_bit) {.rd_reg = {\
  301. .addr = (reg & 0xff) / sizeof(uint32_t), \
  302. .periph_sel = SOC_REG_TO_ULP_PERIPH_SEL(reg), \
  303. .unused = 0, \
  304. .low = low_bit, \
  305. .high = high_bit, \
  306. .opcode = OPCODE_RD_REG } }
  307. /**
  308. * Set or clear a bit in the peripheral register.
  309. *
  310. * Sets bit (1 << shift) of register reg to value val.
  311. * This instruction can access RTC_CNTL_, RTC_IO_, SENS_, and RTC_I2C peripheral registers.
  312. */
  313. #define I_WR_REG_BIT(reg, shift, val) I_WR_REG(reg, shift, shift, val)
  314. /**
  315. * Wake the SoC from deep sleep.
  316. *
  317. * This instruction initiates wake up from deep sleep.
  318. * Use esp_deep_sleep_enable_ulp_wakeup to enable deep sleep wakeup
  319. * triggered by the ULP before going into deep sleep.
  320. * Note that ULP program will still keep running until the I_HALT
  321. * instruction, and it will still be restarted by timer at regular
  322. * intervals, even when the SoC is woken up.
  323. *
  324. * To stop the ULP program, use I_HALT instruction.
  325. *
  326. * To disable the timer which start ULP program, use I_END()
  327. * instruction. I_END instruction clears the
  328. * RTC_CNTL_ULP_CP_SLP_TIMER_EN_S bit of RTC_CNTL_STATE0_REG
  329. * register, which controls the ULP timer.
  330. */
  331. #define I_WAKE() { .end = { \
  332. .wakeup = 1, \
  333. .unused = 0, \
  334. .sub_opcode = SUB_OPCODE_END, \
  335. .opcode = OPCODE_END } }
  336. /**
  337. * Stop ULP program timer.
  338. *
  339. * This is a convenience macro which disables the ULP program timer.
  340. * Once this instruction is used, ULP program will not be restarted
  341. * anymore until ulp_run function is called.
  342. *
  343. * ULP program will continue running after this instruction. To stop
  344. * the currently running program, use I_HALT().
  345. */
  346. #define I_END() \
  347. I_WR_REG_BIT(RTC_CNTL_STATE0_REG, RTC_CNTL_ULP_CP_SLP_TIMER_EN_S, 0)
  348. /**
  349. * Select the time interval used to run ULP program.
  350. *
  351. * This instructions selects which of the SENS_SLEEP_CYCLES_Sx
  352. * registers' value is used by the ULP program timer.
  353. * When the ULP program stops at I_HALT instruction, ULP program
  354. * timer start counting. When the counter reaches the value of
  355. * the selected SENS_SLEEP_CYCLES_Sx register, ULP program
  356. * start running again from the start address (passed to the ulp_run
  357. * function).
  358. * There are 5 SENS_SLEEP_CYCLES_Sx registers, so 0 <= timer_idx < 5.
  359. *
  360. * By default, SENS_SLEEP_CYCLES_S0 register is used by the ULP
  361. * program timer.
  362. */
  363. #define I_SLEEP_CYCLE_SEL(timer_idx) { .sleep = { \
  364. .cycle_sel = timer_idx, \
  365. .unused = 0, \
  366. .sub_opcode = SUB_OPCODE_SLEEP, \
  367. .opcode = OPCODE_END } }
  368. /**
  369. * Perform temperature sensor measurement and store it into reg_dest.
  370. *
  371. * Delay can be set between 1 and ((1 << 14) - 1). Higher values give
  372. * higher measurement resolution.
  373. */
  374. #define I_TSENS(reg_dest, delay) { .tsens = { \
  375. .dreg = reg_dest, \
  376. .wait_delay = delay, \
  377. .reserved = 0, \
  378. .opcode = OPCODE_TSENS } }
  379. /**
  380. * Perform ADC measurement and store result in reg_dest.
  381. *
  382. * adc_idx selects ADC (0 or 1).
  383. * pad_idx selects ADC pad (0 - 7).
  384. */
  385. #define I_ADC(reg_dest, adc_idx, pad_idx) { .adc = {\
  386. .dreg = reg_dest, \
  387. .mux = pad_idx + 1, \
  388. .sar_sel = adc_idx, \
  389. .unused1 = 0, \
  390. .cycles = 0, \
  391. .unused2 = 0, \
  392. .opcode = OPCODE_ADC } }
  393. /**
  394. * Store value from register reg_val into RTC memory.
  395. *
  396. * The value is written to an offset calculated by adding value of
  397. * reg_addr register and offset_ field (this offset is expressed in 32-bit words).
  398. * 32 bits written to RTC memory are built as follows:
  399. * - bits [31:21] hold the PC of current instruction, expressed in 32-bit words
  400. * - bits [20:18] = 3'b0
  401. * - bits [17:16] reg_addr (0..3)
  402. * - bits [15:0] are assigned the contents of reg_val
  403. *
  404. * RTC_SLOW_MEM[addr + offset_] = { insn_PC[10:0], 3'b0, reg_addr, reg_val[15:0] }
  405. */
  406. #define I_ST(reg_val, reg_addr, offset_) { .st = { \
  407. .dreg = reg_val, \
  408. .sreg = reg_addr, \
  409. .unused1 = 0, \
  410. .offset = offset_, \
  411. .unused2 = 0, \
  412. .sub_opcode = SUB_OPCODE_ST, \
  413. .opcode = OPCODE_ST } }
  414. /**
  415. * Load value from RTC memory into reg_dest register.
  416. *
  417. * Loads 16 LSBs from RTC memory word given by the sum of value in reg_addr and
  418. * value of offset_.
  419. */
  420. #define I_LD(reg_dest, reg_addr, offset_) { .ld = { \
  421. .dreg = reg_dest, \
  422. .sreg = reg_addr, \
  423. .unused1 = 0, \
  424. .offset = offset_, \
  425. .unused2 = 0, \
  426. .opcode = OPCODE_LD } }
  427. /**
  428. * Branch relative if R0 less than immediate value.
  429. *
  430. * pc_offset is expressed in words, and can be from -127 to 127
  431. * imm_value is a 16-bit value to compare R0 against
  432. */
  433. #define I_BL(pc_offset, imm_value) { .b = { \
  434. .imm = imm_value, \
  435. .cmp = B_CMP_L, \
  436. .offset = abs(pc_offset), \
  437. .sign = (pc_offset >= 0) ? 0 : 1, \
  438. .sub_opcode = SUB_OPCODE_B, \
  439. .opcode = OPCODE_BRANCH } }
  440. /**
  441. * Branch relative if R0 greater or equal than immediate value.
  442. *
  443. * pc_offset is expressed in words, and can be from -127 to 127
  444. * imm_value is a 16-bit value to compare R0 against
  445. */
  446. #define I_BGE(pc_offset, imm_value) { .b = { \
  447. .imm = imm_value, \
  448. .cmp = B_CMP_GE, \
  449. .offset = abs(pc_offset), \
  450. .sign = (pc_offset >= 0) ? 0 : 1, \
  451. .sub_opcode = SUB_OPCODE_B, \
  452. .opcode = OPCODE_BRANCH } }
  453. /**
  454. * Unconditional branch to absolute PC, address in register.
  455. *
  456. * reg_pc is the register which contains address to jump to.
  457. * Address is expressed in 32-bit words.
  458. */
  459. #define I_BXR(reg_pc) { .bx = { \
  460. .dreg = reg_pc, \
  461. .addr = 0, \
  462. .unused = 0, \
  463. .reg = 1, \
  464. .type = BX_JUMP_TYPE_DIRECT, \
  465. .sub_opcode = SUB_OPCODE_BX, \
  466. .opcode = OPCODE_BRANCH } }
  467. /**
  468. * Unconditional branch to absolute PC, immediate address.
  469. *
  470. * Address imm_pc is expressed in 32-bit words.
  471. */
  472. #define I_BXI(imm_pc) { .bx = { \
  473. .dreg = 0, \
  474. .addr = imm_pc, \
  475. .unused = 0, \
  476. .reg = 0, \
  477. .type = BX_JUMP_TYPE_DIRECT, \
  478. .sub_opcode = SUB_OPCODE_BX, \
  479. .opcode = OPCODE_BRANCH } }
  480. /**
  481. * Branch to absolute PC if ALU result is zero, address in register.
  482. *
  483. * reg_pc is the register which contains address to jump to.
  484. * Address is expressed in 32-bit words.
  485. */
  486. #define I_BXZR(reg_pc) { .bx = { \
  487. .dreg = reg_pc, \
  488. .addr = 0, \
  489. .unused = 0, \
  490. .reg = 1, \
  491. .type = BX_JUMP_TYPE_ZERO, \
  492. .sub_opcode = SUB_OPCODE_BX, \
  493. .opcode = OPCODE_BRANCH } }
  494. /**
  495. * Branch to absolute PC if ALU result is zero, immediate address.
  496. *
  497. * Address imm_pc is expressed in 32-bit words.
  498. */
  499. #define I_BXZI(imm_pc) { .bx = { \
  500. .dreg = 0, \
  501. .addr = imm_pc, \
  502. .unused = 0, \
  503. .reg = 0, \
  504. .type = BX_JUMP_TYPE_ZERO, \
  505. .sub_opcode = SUB_OPCODE_BX, \
  506. .opcode = OPCODE_BRANCH } }
  507. /**
  508. * Branch to absolute PC if ALU overflow, address in register
  509. *
  510. * reg_pc is the register which contains address to jump to.
  511. * Address is expressed in 32-bit words.
  512. */
  513. #define I_BXFR(reg_pc) { .bx = { \
  514. .dreg = reg_pc, \
  515. .addr = 0, \
  516. .unused = 0, \
  517. .reg = 1, \
  518. .type = BX_JUMP_TYPE_OVF, \
  519. .sub_opcode = SUB_OPCODE_BX, \
  520. .opcode = OPCODE_BRANCH } }
  521. /**
  522. * Branch to absolute PC if ALU overflow, immediate address
  523. *
  524. * Address imm_pc is expressed in 32-bit words.
  525. */
  526. #define I_BXFI(imm_pc) { .bx = { \
  527. .dreg = 0, \
  528. .addr = imm_pc, \
  529. .unused = 0, \
  530. .reg = 0, \
  531. .type = BX_JUMP_TYPE_OVF, \
  532. .sub_opcode = SUB_OPCODE_BX, \
  533. .opcode = OPCODE_BRANCH } }
  534. /**
  535. * Addition: dest = src1 + src2
  536. */
  537. #define I_ADDR(reg_dest, reg_src1, reg_src2) { .alu_reg = { \
  538. .dreg = reg_dest, \
  539. .sreg = reg_src1, \
  540. .treg = reg_src2, \
  541. .unused = 0, \
  542. .sel = ALU_SEL_ADD, \
  543. .sub_opcode = SUB_OPCODE_ALU_REG, \
  544. .opcode = OPCODE_ALU } }
  545. /**
  546. * Subtraction: dest = src1 - src2
  547. */
  548. #define I_SUBR(reg_dest, reg_src1, reg_src2) { .alu_reg = { \
  549. .dreg = reg_dest, \
  550. .sreg = reg_src1, \
  551. .treg = reg_src2, \
  552. .unused = 0, \
  553. .sel = ALU_SEL_SUB, \
  554. .sub_opcode = SUB_OPCODE_ALU_REG, \
  555. .opcode = OPCODE_ALU } }
  556. /**
  557. * Logical AND: dest = src1 & src2
  558. */
  559. #define I_ANDR(reg_dest, reg_src1, reg_src2) { .alu_reg = { \
  560. .dreg = reg_dest, \
  561. .sreg = reg_src1, \
  562. .treg = reg_src2, \
  563. .unused = 0, \
  564. .sel = ALU_SEL_AND, \
  565. .sub_opcode = SUB_OPCODE_ALU_REG, \
  566. .opcode = OPCODE_ALU } }
  567. /**
  568. * Logical OR: dest = src1 | src2
  569. */
  570. #define I_ORR(reg_dest, reg_src1, reg_src2) { .alu_reg = { \
  571. .dreg = reg_dest, \
  572. .sreg = reg_src1, \
  573. .treg = reg_src2, \
  574. .unused = 0, \
  575. .sel = ALU_SEL_OR, \
  576. .sub_opcode = SUB_OPCODE_ALU_REG, \
  577. .opcode = OPCODE_ALU } }
  578. /**
  579. * Copy: dest = src
  580. */
  581. #define I_MOVR(reg_dest, reg_src) { .alu_reg = { \
  582. .dreg = reg_dest, \
  583. .sreg = reg_src, \
  584. .treg = 0, \
  585. .unused = 0, \
  586. .sel = ALU_SEL_MOV, \
  587. .sub_opcode = SUB_OPCODE_ALU_REG, \
  588. .opcode = OPCODE_ALU } }
  589. /**
  590. * Logical shift left: dest = src << shift
  591. */
  592. #define I_LSHR(reg_dest, reg_src, reg_shift) { .alu_reg = { \
  593. .dreg = reg_dest, \
  594. .sreg = reg_src, \
  595. .treg = reg_shift, \
  596. .unused = 0, \
  597. .sel = ALU_SEL_LSH, \
  598. .sub_opcode = SUB_OPCODE_ALU_REG, \
  599. .opcode = OPCODE_ALU } }
  600. /**
  601. * Logical shift right: dest = src >> shift
  602. */
  603. #define I_RSHR(reg_dest, reg_src, reg_shift) { .alu_reg = { \
  604. .dreg = reg_dest, \
  605. .sreg = reg_src, \
  606. .treg = reg_shift, \
  607. .unused = 0, \
  608. .sel = ALU_SEL_RSH, \
  609. .sub_opcode = SUB_OPCODE_ALU_REG, \
  610. .opcode = OPCODE_ALU } }
  611. /**
  612. * Add register and an immediate value: dest = src1 + imm
  613. */
  614. #define I_ADDI(reg_dest, reg_src, imm_) { .alu_imm = { \
  615. .dreg = reg_dest, \
  616. .sreg = reg_src, \
  617. .imm = imm_, \
  618. .unused = 0, \
  619. .sel = ALU_SEL_ADD, \
  620. .sub_opcode = SUB_OPCODE_ALU_IMM, \
  621. .opcode = OPCODE_ALU } }
  622. /**
  623. * Subtract register and an immediate value: dest = src - imm
  624. */
  625. #define I_SUBI(reg_dest, reg_src, imm_) { .alu_imm = { \
  626. .dreg = reg_dest, \
  627. .sreg = reg_src, \
  628. .imm = imm_, \
  629. .unused = 0, \
  630. .sel = ALU_SEL_SUB, \
  631. .sub_opcode = SUB_OPCODE_ALU_IMM, \
  632. .opcode = OPCODE_ALU } }
  633. /**
  634. * Logical AND register and an immediate value: dest = src & imm
  635. */
  636. #define I_ANDI(reg_dest, reg_src, imm_) { .alu_imm = { \
  637. .dreg = reg_dest, \
  638. .sreg = reg_src, \
  639. .imm = imm_, \
  640. .unused = 0, \
  641. .sel = ALU_SEL_AND, \
  642. .sub_opcode = SUB_OPCODE_ALU_IMM, \
  643. .opcode = OPCODE_ALU } }
  644. /**
  645. * Logical OR register and an immediate value: dest = src | imm
  646. */
  647. #define I_ORI(reg_dest, reg_src, imm_) { .alu_imm = { \
  648. .dreg = reg_dest, \
  649. .sreg = reg_src, \
  650. .imm = imm_, \
  651. .unused = 0, \
  652. .sel = ALU_SEL_OR, \
  653. .sub_opcode = SUB_OPCODE_ALU_IMM, \
  654. .opcode = OPCODE_ALU } }
  655. /**
  656. * Copy an immediate value into register: dest = imm
  657. */
  658. #define I_MOVI(reg_dest, imm_) { .alu_imm = { \
  659. .dreg = reg_dest, \
  660. .sreg = 0, \
  661. .imm = imm_, \
  662. .unused = 0, \
  663. .sel = ALU_SEL_MOV, \
  664. .sub_opcode = SUB_OPCODE_ALU_IMM, \
  665. .opcode = OPCODE_ALU } }
  666. /**
  667. * Logical shift left register value by an immediate: dest = src << imm
  668. */
  669. #define I_LSHI(reg_dest, reg_src, imm_) { .alu_imm = { \
  670. .dreg = reg_dest, \
  671. .sreg = reg_src, \
  672. .imm = imm_, \
  673. .unused = 0, \
  674. .sel = ALU_SEL_LSH, \
  675. .sub_opcode = SUB_OPCODE_ALU_IMM, \
  676. .opcode = OPCODE_ALU } }
  677. /**
  678. * Logical shift right register value by an immediate: dest = val >> imm
  679. */
  680. #define I_RSHI(reg_dest, reg_src, imm_) { .alu_imm = { \
  681. .dreg = reg_dest, \
  682. .sreg = reg_src, \
  683. .imm = imm_, \
  684. .unused = 0, \
  685. .sel = ALU_SEL_RSH, \
  686. .sub_opcode = SUB_OPCODE_ALU_IMM, \
  687. .opcode = OPCODE_ALU } }
  688. /**
  689. * Define a label with number label_num.
  690. *
  691. * This is a macro which doesn't generate a real instruction.
  692. * The token generated by this macro is removed by ulp_process_macros_and_load
  693. * function. Label defined using this macro can be used in branch macros defined
  694. * below.
  695. */
  696. #define M_LABEL(label_num) { .macro = { \
  697. .dreg = 0, \
  698. .label = label_num, \
  699. .unused = 0, \
  700. .sub_opcode = SUB_OPCODE_MACRO_LABEL, \
  701. .opcode = OPCODE_MACRO } }
  702. /**
  703. * Token macro used by M_B and M_BX macros. Not to be used directly.
  704. */
  705. #define M_BRANCH(label_num) { .macro = { \
  706. .dreg = 0, \
  707. .label = label_num, \
  708. .unused = 0, \
  709. .sub_opcode = SUB_OPCODE_MACRO_BRANCH, \
  710. .opcode = OPCODE_MACRO } }
  711. /**
  712. * Token macro used by M_MOVL macro. Not to be used directly.
  713. */
  714. #define M_LABELPC(label_num) { .macro = { \
  715. .dreg = 0, \
  716. .label = label_num, \
  717. .unused = 0, \
  718. .sub_opcode = SUB_OPCODE_MACRO_LABELPC, \
  719. .opcode = OPCODE_MACRO } }
  720. /**
  721. * Macro: Move the program counter at the given label into the register.
  722. * This address can then be used with I_BXR, I_BXZR, I_BXFR, etc.
  723. *
  724. * This macro generates two ulp_insn_t values separated by a comma, and should
  725. * be used when defining contents of ulp_insn_t arrays. First value is not a
  726. * real instruction; it is a token which is removed by ulp_process_macros_and_load
  727. * function.
  728. */
  729. #define M_MOVL(reg_dest, label_num) \
  730. M_LABELPC(label_num), \
  731. I_MOVI(reg_dest, 0)
  732. /**
  733. * Macro: branch to label label_num if R0 is less than immediate value.
  734. *
  735. * This macro generates two ulp_insn_t values separated by a comma, and should
  736. * be used when defining contents of ulp_insn_t arrays. First value is not a
  737. * real instruction; it is a token which is removed by ulp_process_macros_and_load
  738. * function.
  739. */
  740. #define M_BL(label_num, imm_value) \
  741. M_BRANCH(label_num), \
  742. I_BL(0, imm_value)
  743. /**
  744. * Macro: branch to label label_num if R0 is greater or equal than immediate value
  745. *
  746. * This macro generates two ulp_insn_t values separated by a comma, and should
  747. * be used when defining contents of ulp_insn_t arrays. First value is not a
  748. * real instruction; it is a token which is removed by ulp_process_macros_and_load
  749. * function.
  750. */
  751. #define M_BGE(label_num, imm_value) \
  752. M_BRANCH(label_num), \
  753. I_BGE(0, imm_value)
  754. /**
  755. * Macro: unconditional branch to label
  756. *
  757. * This macro generates two ulp_insn_t values separated by a comma, and should
  758. * be used when defining contents of ulp_insn_t arrays. First value is not a
  759. * real instruction; it is a token which is removed by ulp_process_macros_and_load
  760. * function.
  761. */
  762. #define M_BX(label_num) \
  763. M_BRANCH(label_num), \
  764. I_BXI(0)
  765. /**
  766. * Macro: branch to label if ALU result is zero
  767. *
  768. * This macro generates two ulp_insn_t values separated by a comma, and should
  769. * be used when defining contents of ulp_insn_t arrays. First value is not a
  770. * real instruction; it is a token which is removed by ulp_process_macros_and_load
  771. * function.
  772. */
  773. #define M_BXZ(label_num) \
  774. M_BRANCH(label_num), \
  775. I_BXZI(0)
  776. /**
  777. * Macro: branch to label if ALU overflow
  778. *
  779. * This macro generates two ulp_insn_t values separated by a comma, and should
  780. * be used when defining contents of ulp_insn_t arrays. First value is not a
  781. * real instruction; it is a token which is removed by ulp_process_macros_and_load
  782. * function.
  783. */
  784. #define M_BXF(label_num) \
  785. M_BRANCH(label_num), \
  786. I_BXFI(0)
  787. /**
  788. * Increment the stage counter by immediate value
  789. */
  790. #define I_STAGE_INC(imm_) { .alu_reg_s = { \
  791. .unused1 = 0, \
  792. .imm = imm_, \
  793. .unused2 = 0, \
  794. .sel = ALU_SEL_SINC, \
  795. .sub_opcode = SUB_OPCODE_ALU_CNT, \
  796. .opcode = OPCODE_ALU } }
  797. /**
  798. * Decrement the stage counter by immediate value
  799. */
  800. #define I_STAGE_DEC(imm_) { .alu_reg_s = { \
  801. .unused1 = 0, \
  802. .imm = imm_, \
  803. .unused2 = 0, \
  804. .sel = ALU_SEL_SDEC, \
  805. .sub_opcode = SUB_OPCODE_ALU_CNT, \
  806. .opcode = OPCODE_ALU } }
  807. /**
  808. * Reset the stage counter
  809. */
  810. #define I_STAGE_RST() { .alu_reg_s = { \
  811. .unused1 = 0, \
  812. .imm = 0, \
  813. .unused2 = 0, \
  814. .sel = ALU_SEL_SRST, \
  815. .sub_opcode = SUB_OPCODE_ALU_CNT, \
  816. .opcode = OPCODE_ALU } }
  817. /**
  818. * Macro: branch to label if the stage counter is less than immediate value
  819. *
  820. * This macro generates two ulp_insn_t values separated by a comma, and should
  821. * be used when defining contents of ulp_insn_t arrays. First value is not a
  822. * real instruction; it is a token which is removed by ulp_process_macros_and_load
  823. * function.
  824. */
  825. #define M_BSLT(label_num, imm_value) \
  826. M_BRANCH(label_num), \
  827. I_JUMPS(0, imm_value, JUMPS_LT)
  828. /**
  829. * Macro: branch to label if the stage counter is greater than or equal to immediate value
  830. *
  831. * This macro generates two ulp_insn_t values separated by a comma, and should
  832. * be used when defining contents of ulp_insn_t arrays. First value is not a
  833. * real instruction; it is a token which is removed by ulp_process_macros_and_load
  834. * function.
  835. */
  836. #define M_BSGE(label_num, imm_value) \
  837. M_BRANCH(label_num), \
  838. I_JUMPS(0, imm_value, JUMPS_GE)
  839. /**
  840. * Macro: branch to label if the stage counter is less than or equal to immediate value
  841. *
  842. * This macro generates two ulp_insn_t values separated by a comma, and should
  843. * be used when defining contents of ulp_insn_t arrays. First value is not a
  844. * real instruction; it is a token which is removed by ulp_process_macros_and_load
  845. * function.
  846. */
  847. #define M_BSLE(label_num, imm_value) \
  848. M_BRANCH(label_num), \
  849. I_JUMPS(0, imm_value, JUMPS_LE)
  850. /**
  851. * Macro: branch to label if the stage counter is equal to immediate value.
  852. * Implemented using two JUMPS instructions:
  853. * JUMPS next, imm_value, LT
  854. * JUMPS label_num, imm_value, LE
  855. *
  856. * This macro generates three ulp_insn_t values separated by commas, and should
  857. * be used when defining contents of ulp_insn_t arrays. Second value is not a
  858. * real instruction; it is a token which is removed by ulp_process_macros_and_load
  859. * function.
  860. */
  861. #define M_BSEQ(label_num, imm_value) \
  862. I_JUMPS(2, imm_value, JUMPS_LT), \
  863. M_BRANCH(label_num), \
  864. I_JUMPS(0, imm_value, JUMPS_LE)
  865. /**
  866. * Macro: branch to label if the stage counter is greater than immediate value.
  867. * Implemented using two instructions:
  868. * JUMPS next, imm_value, LE
  869. * JUMPS label_num, imm_value, GE
  870. *
  871. * This macro generates three ulp_insn_t values separated by commas, and should
  872. * be used when defining contents of ulp_insn_t arrays. Second value is not a
  873. * real instruction; it is a token which is removed by ulp_process_macros_and_load
  874. * function.
  875. */
  876. #define M_BSGT(label_num, imm_value) \
  877. I_JUMPS(2, imm_value, JUMPS_LE), \
  878. M_BRANCH(label_num), \
  879. I_JUMPS(0, imm_value, JUMPS_GE)
  880. /**
  881. * Branch relative if (stage counter [comp_type] [imm_value]) evaluates to true.
  882. *
  883. * pc_offset is expressed in words, and can be from -127 to 127
  884. * imm_value is an 8-bit value to compare the stage counter against
  885. * comp_type is the type of comparison to perform: JUMPS_LT (<), JUMPS_GE (>=) or JUMPS_LE (<=)
  886. */
  887. #define I_JUMPS(pc_offset, imm_value, comp_type) { .bs = { \
  888. .imm = imm_value, \
  889. .unused = 0, \
  890. .cmp = comp_type, \
  891. .offset = abs(pc_offset), \
  892. .sign = (pc_offset >= 0) ? 0 : 1, \
  893. .sub_opcode = SUB_OPCODE_BS, \
  894. .opcode = OPCODE_BRANCH } }
  895. /**
  896. * Perform an I2C transaction with a slave device.
  897. * I_I2C_READ and I_I2C_WRITE are provided for convenience, instead of using this directly.
  898. *
  899. * Slave address (in 7-bit format) has to be set in advance into SENS_I2C_SLAVE_ADDRx register field, where x == slave_sel.
  900. * For read operations, 8 bits of read result is stored into R0 register.
  901. * For write operations, val will be written to sub_addr at [high_bit:low_bit]. Bits outside of this range are masked.
  902. */
  903. #define I_I2C_RW(sub_addr, val, low_bit, high_bit, slave_sel, rw_bit) { .i2c = {\
  904. .i2c_addr = sub_addr, \
  905. .data = val, \
  906. .low_bits = low_bit, \
  907. .high_bits = high_bit, \
  908. .i2c_sel = slave_sel, \
  909. .unused = 0, \
  910. .rw = rw_bit, \
  911. .opcode = OPCODE_I2C } }
  912. /**
  913. * Read a byte from the sub address of an I2C slave, and store the result in R0.
  914. *
  915. * Slave address (in 7-bit format) has to be set in advance into SENS_I2C_SLAVE_ADDRx register field, where x == slave_sel.
  916. */
  917. #define I_I2C_READ(slave_sel, sub_addr) I_I2C_RW(sub_addr, 0, 0, 0, slave_sel, SUB_OPCODE_I2C_RD)
  918. /**
  919. * Write a byte to the sub address of an I2C slave.
  920. *
  921. * Slave address (in 7-bit format) has to be set in advance into SENS_I2C_SLAVE_ADDRx register field, where x == slave_sel.
  922. */
  923. #define I_I2C_WRITE(slave_sel, sub_addr, val) I_I2C_RW(sub_addr, val, 0, 7, slave_sel, SUB_OPCODE_I2C_WR)
  924. #ifdef __cplusplus
  925. }
  926. #endif