ulp.h 37 KB

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