ulp.h 37 KB

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