mirror of
https://github.com/espressif/esp-idf.git
synced 2025-07-30 18:57:19 +02:00
ulp: Added support for ULP FSM on esp32s3 and fixed bugs for esp32s2
This commit enables ULP FSM support for esp32s3 and updates ULP FSM code flow for other chips. It adds C Macro support for the ULP FSM instruction set on esp32s2 and esp32s3. The unit tests are also updated to test ULP FSM on ep32s2 and esp32s3.
This commit is contained in:
committed by
Marius Vikhammer
parent
74d745a80b
commit
a0e3d488da
@ -4,6 +4,6 @@ export ULP_AS := $(ULP_BINUTILS_PREFIX)as
|
||||
export ULP_LD := $(ULP_BINUTILS_PREFIX)ld
|
||||
export ULP_OBJCOPY := $(ULP_BINUTILS_PREFIX)objcopy
|
||||
export ULP_OBJDUMP := $(ULP_BINUTILS_PREFIX)objdump
|
||||
export ULP_LD_TEMPLATE := $(IDF_PATH)/components/ulp/ld/esp32.ulp.ld
|
||||
export ULP_LD_TEMPLATE := $(IDF_PATH)/components/ulp/ld/ulp_fsm.ld
|
||||
export ULP_NM := $(ULP_BINUTILS_PREFIX)nm
|
||||
export ULP_MAP_GEN := $(IDF_PATH)/components/ulp/esp32ulp_mapgen.py
|
||||
|
16
components/ulp/cmake/toolchain-esp32s3-ulp.cmake
Normal file
16
components/ulp/cmake/toolchain-esp32s3-ulp.cmake
Normal file
@ -0,0 +1,16 @@
|
||||
# CMake toolchain file for ULP
|
||||
|
||||
set(CMAKE_SYSTEM_NAME Generic)
|
||||
|
||||
# Compiler is only used for preprocessing
|
||||
# The S2 and S3 ULP are the same, so we use the same toolchain
|
||||
set(CMAKE_C_COMPILER "xtensa-esp32s2-elf-gcc")
|
||||
|
||||
set(CMAKE_ASM_COMPILER "esp32s2ulp-elf-as")
|
||||
set(CMAKE_LINKER "esp32s2ulp-elf-ld")
|
||||
|
||||
set(CMAKE_ASM${ASM_DIALECT}_COMPILE_OBJECT "${CMAKE_ASM${ASM_DIALECT}_COMPILER} \
|
||||
<DEFINES> <INCLUDES> -o <OBJECT> -c <SOURCE>")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "-A elf32-esp32s2ulp -nostdlib" CACHE STRING "ULP Linker Base Flags")
|
||||
set(CMAKE_ASM_LINK_EXECUTABLE "${CMAKE_LINKER} <FLAGS> <CMAKE_ASM_LINK_FLAGS> \
|
||||
<LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
|
@ -289,6 +289,8 @@ union ulp_insn {
|
||||
|
||||
};
|
||||
|
||||
_Static_assert(sizeof(ulp_insn_t) == 4, "ULP coprocessor instruction size should be 4 bytes");
|
||||
|
||||
/**
|
||||
* Delay (nop) for a given number of cycles
|
||||
*/
|
||||
|
@ -1,16 +1,8 @@
|
||||
// Copyright 2016-2018 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2016-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
@ -24,9 +16,6 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define ULP_FSM_PREPARE_SLEEP_CYCLES 2 /*!< Cycles spent by FSM preparing ULP for sleep */
|
||||
#define ULP_FSM_WAKEUP_SLEEP_CYCLES 2 /*!< Cycles spent by FSM waking up ULP from sleep */
|
||||
|
||||
/**
|
||||
* @defgroup ulp_registers ULP coprocessor registers
|
||||
* @{
|
||||
@ -63,7 +52,9 @@ extern "C" {
|
||||
#define OPCODE_ADC 5 /*!< Instruction: SAR ADC measurement (not implemented yet) */
|
||||
|
||||
#define OPCODE_ST 6 /*!< Instruction: store indirect to RTC memory */
|
||||
#define SUB_OPCODE_ST 4 /*!< Store 32 bits, 16 MSBs contain PC, 16 LSBs contain value from source register */
|
||||
#define SUB_OPCODE_ST_AUTO 1 /*!< Automatic Storage Mode - Access continuous addresses. Use SUB_OPCODE_ST_OFFSET to configure the initial address before using this instruction. */
|
||||
#define SUB_OPCODE_ST_OFFSET 3 /*!< Automatic Storage Mode - Configure the initial address. */
|
||||
#define SUB_OPCODE_ST 4 /*!< Manual Storage Mode. Store 32 bits, 16 MSBs contain PC, 16 LSBs contain value from source register */
|
||||
|
||||
#define OPCODE_ALU 7 /*!< Arithmetic instructions */
|
||||
#define SUB_OPCODE_ALU_REG 0 /*!< Arithmetic instruction, both source values are in register */
|
||||
@ -76,15 +67,23 @@ extern "C" {
|
||||
#define ALU_SEL_MOV 4 /*!< Copy value (immediate to destination register or source register to destination register */
|
||||
#define ALU_SEL_LSH 5 /*!< Shift left by given number of bits */
|
||||
#define ALU_SEL_RSH 6 /*!< Shift right by given number of bits */
|
||||
#define ALU_SEL_STAGE_INC 0 /*!< Increment stage count register */
|
||||
#define ALU_SEL_STAGE_DEC 1 /*!< Decrement stage count register */
|
||||
#define ALU_SEL_STAGE_RST 2 /*!< Reset stage count register */
|
||||
|
||||
#define OPCODE_BRANCH 8 /*!< Branch instructions */
|
||||
#define SUB_OPCODE_BX 0 /*!< Branch to absolute PC (immediate or in register) */
|
||||
#define SUB_OPCODE_B 0 /*!< Branch to a relative offset */
|
||||
#define SUB_OPCODE_BX 1 /*!< Branch to absolute PC (immediate or in register) */
|
||||
#define SUB_OPCODE_BS 2 /*!< Branch to a relative offset by comparing the stage_cnt register */
|
||||
#define BX_JUMP_TYPE_DIRECT 0 /*!< Unconditional jump */
|
||||
#define BX_JUMP_TYPE_ZERO 1 /*!< Branch if last ALU result is zero */
|
||||
#define BX_JUMP_TYPE_OVF 2 /*!< Branch if last ALU operation caused and overflow */
|
||||
#define SUB_OPCODE_B 1 /*!< Branch to a relative offset */
|
||||
#define B_CMP_L 0 /*!< Branch if R0 is less than an immediate */
|
||||
#define B_CMP_GE 1 /*!< Branch if R0 is greater than or equal to an immediate */
|
||||
#define B_CMP_G 1 /*!< Branch if R0 is greater than an immediate */
|
||||
#define B_CMP_E 2 /*!< Branch if R0 is equal to an immediate */
|
||||
#define BS_CMP_L 0 /*!< Branch if stage_cnt is less than an immediate */
|
||||
#define BS_CMP_GE 1 /*!< Branch if stage_cnt is greater than or equal to an immediate */
|
||||
#define BS_CMP_LE 2 /*!< Branch if stage_cnt is less than or equal to an immediate */
|
||||
|
||||
#define OPCODE_END 9 /*!< Stop executing the program */
|
||||
#define SUB_OPCODE_END 0 /*!< Stop executing the program and optionally wake up the chip */
|
||||
@ -99,6 +98,7 @@ extern "C" {
|
||||
#define OPCODE_MACRO 15 /*!< Not a real opcode. Used to identify labels and branches in the program */
|
||||
#define SUB_OPCODE_MACRO_LABEL 0 /*!< Label macro */
|
||||
#define SUB_OPCODE_MACRO_BRANCH 1 /*!< Branch macro */
|
||||
#define SUB_OPCODE_MACRO_LABELPC 2 /*!< Label pointer macro */
|
||||
/**@}*/
|
||||
|
||||
/**
|
||||
@ -126,7 +126,10 @@ union ulp_insn {
|
||||
struct {
|
||||
uint32_t dreg : 2; /*!< Register which contains data to store */
|
||||
uint32_t sreg : 2; /*!< Register which contains address in RTC memory (expressed in words) */
|
||||
uint32_t unused1 : 6; /*!< Unused */
|
||||
uint32_t label: 2; /*!< Data label, 2-bit user defined unsigned value */
|
||||
uint32_t upper: 1; /*!< 0: write the low half-word; 1: write the high half-word */
|
||||
uint32_t wr_way: 2; /*!< 0: write the full-word; 1: with the label; 3: without the label */
|
||||
uint32_t unused1 : 1; /*!< Unused */
|
||||
uint32_t offset : 11; /*!< Offset to add to sreg */
|
||||
uint32_t unused2 : 4; /*!< Unused */
|
||||
uint32_t sub_opcode : 3; /*!< Sub opcode (SUB_OPCODE_ST) */
|
||||
@ -138,7 +141,8 @@ union ulp_insn {
|
||||
uint32_t sreg : 2; /*!< Register which contains address in RTC memory (expressed in words) */
|
||||
uint32_t unused1 : 6; /*!< Unused */
|
||||
uint32_t offset : 11; /*!< Offset to add to sreg */
|
||||
uint32_t unused2 : 7; /*!< Unused */
|
||||
uint32_t unused2 : 6; /*!< Unused */
|
||||
uint32_t rd_upper: 1; /*!< 0: read the high half-word; 1: read the low half-word*/
|
||||
uint32_t opcode : 4; /*!< Opcode (OPCODE_LD) */
|
||||
} ld; /*!< Format of LD instruction */
|
||||
|
||||
@ -150,19 +154,20 @@ union ulp_insn {
|
||||
struct {
|
||||
uint32_t dreg : 2; /*!< Register which contains target PC, expressed in words (used if .reg == 1) */
|
||||
uint32_t addr : 11; /*!< Target PC, expressed in words (used if .reg == 0) */
|
||||
uint32_t unused : 8; /*!< Unused */
|
||||
uint32_t unused1 : 8; /*!< Unused */
|
||||
uint32_t reg : 1; /*!< Target PC in register (1) or immediate (0) */
|
||||
uint32_t type : 3; /*!< Jump condition (BX_JUMP_TYPE_xxx) */
|
||||
uint32_t sub_opcode : 3; /*!< Sub opcode (SUB_OPCODE_BX) */
|
||||
uint32_t unused2 : 1; /*!< Unused */
|
||||
uint32_t sub_opcode : 2; /*!< Sub opcode (SUB_OPCODE_BX) */
|
||||
uint32_t opcode : 4; /*!< Opcode (OPCODE_BRANCH) */
|
||||
} bx; /*!< Format of BRANCH instruction (absolute address) */
|
||||
|
||||
struct {
|
||||
uint32_t imm : 16; /*!< Immediate value to compare against */
|
||||
uint32_t cmp : 1; /*!< Comparison to perform: B_CMP_L or B_CMP_GE */
|
||||
uint32_t cmp : 2; /*!< Comparison to perform: B_CMP_L or B_CMP_GE */
|
||||
uint32_t offset : 7; /*!< Absolute value of target PC offset w.r.t. current PC, expressed in words */
|
||||
uint32_t sign : 1; /*!< Sign of target PC offset: 0: positive, 1: negative */
|
||||
uint32_t sub_opcode : 3; /*!< Sub opcode (SUB_OPCODE_B) */
|
||||
uint32_t sub_opcode : 2; /*!< Sub opcode (SUB_OPCODE_B) */
|
||||
uint32_t opcode : 4; /*!< Opcode (OPCODE_BRANCH) */
|
||||
} b; /*!< Format of BRANCH instruction (relative address) */
|
||||
|
||||
@ -170,9 +175,10 @@ union ulp_insn {
|
||||
uint32_t dreg : 2; /*!< Destination register */
|
||||
uint32_t sreg : 2; /*!< Register with operand A */
|
||||
uint32_t treg : 2; /*!< Register with operand B */
|
||||
uint32_t unused : 15; /*!< Unused */
|
||||
uint32_t unused1 : 15; /*!< Unused */
|
||||
uint32_t sel : 4; /*!< Operation to perform, one of ALU_SEL_xxx */
|
||||
uint32_t sub_opcode : 3; /*!< Sub opcode (SUB_OPCODE_ALU_REG) */
|
||||
uint32_t unused2 : 1; /*!< Unused */
|
||||
uint32_t sub_opcode : 2; /*!< Sub opcode (SUB_OPCODE_ALU_REG) */
|
||||
uint32_t opcode : 4; /*!< Opcode (OPCODE_ALU) */
|
||||
} alu_reg; /*!< Format of ALU instruction (both sources are registers) */
|
||||
|
||||
@ -180,12 +186,23 @@ union ulp_insn {
|
||||
uint32_t dreg : 2; /*!< Destination register */
|
||||
uint32_t sreg : 2; /*!< Register with operand A */
|
||||
uint32_t imm : 16; /*!< Immediate value of operand B */
|
||||
uint32_t unused : 1; /*!< Unused */
|
||||
uint32_t unused1: 1; /*!< Unused */
|
||||
uint32_t sel : 4; /*!< Operation to perform, one of ALU_SEL_xxx */
|
||||
uint32_t sub_opcode : 3; /*!< Sub opcode (SUB_OPCODE_ALU_IMM) */
|
||||
uint32_t unused2 : 1; /*!< Unused */
|
||||
uint32_t sub_opcode : 2; /*!< Sub opcode (SUB_OPCODE_ALU_IMM) */
|
||||
uint32_t opcode : 4; /*!< Opcode (OPCODE_ALU) */
|
||||
} alu_imm; /*!< Format of ALU instruction (one source is an immediate) */
|
||||
|
||||
struct {
|
||||
uint32_t unused1: 4; /*!< Unused */
|
||||
uint32_t imm : 8; /*!< Immediate value */
|
||||
uint32_t unused2: 9; /*!< Unused */
|
||||
uint32_t sel : 4; /*!< Operation to perform, one of ALU_SEL_xxx */
|
||||
uint32_t unused3 : 1; /*!< Unused */
|
||||
uint32_t sub_opcode : 2; /*!< Sub opcode (SUB_OPCODE_ALU_CNT) */
|
||||
uint32_t opcode : 4; /*!< Opcode (OPCODE_ALU) */
|
||||
} alu_cnt; /*!< Format of ALU instruction with stage count register and an immediate */
|
||||
|
||||
struct {
|
||||
uint32_t addr : 8; /*!< Address within either RTC_CNTL, RTC_IO, or SARADC */
|
||||
uint32_t periph_sel : 2; /*!< Select peripheral: RTC_CNTL (0), RTC_IO(1), SARADC(2) */
|
||||
@ -234,18 +251,11 @@ union ulp_insn {
|
||||
|
||||
struct {
|
||||
uint32_t wakeup : 1; /*!< Set to 1 to wake up chip */
|
||||
uint32_t unused : 24; /*!< Unused */
|
||||
uint32_t sub_opcode : 3; /*!< Sub opcode (SUB_OPCODE_WAKEUP) */
|
||||
uint32_t unused : 25; /*!< Unused */
|
||||
uint32_t sub_opcode : 2; /*!< Sub opcode (SUB_OPCODE_WAKEUP) */
|
||||
uint32_t opcode : 4; /*!< Opcode (OPCODE_END) */
|
||||
} end; /*!< Format of END instruction with wakeup */
|
||||
|
||||
struct {
|
||||
uint32_t cycle_sel : 4; /*!< Select which one of SARADC_ULP_CP_SLEEP_CYCx_REG to get the sleep duration from */
|
||||
uint32_t unused : 21; /*!< Unused */
|
||||
uint32_t sub_opcode : 3; /*!< Sub opcode (SUB_OPCODE_SLEEP) */
|
||||
uint32_t opcode : 4; /*!< Opcode (OPCODE_END) */
|
||||
} sleep; /*!< Format of END instruction with sleep */
|
||||
|
||||
struct {
|
||||
uint32_t label : 16; /*!< Label number */
|
||||
uint32_t unused : 8; /*!< Unused */
|
||||
@ -255,6 +265,8 @@ union ulp_insn {
|
||||
|
||||
};
|
||||
|
||||
_Static_assert(sizeof(ulp_insn_t) == 4, "ULP coprocessor instruction size should be 4 bytes");
|
||||
|
||||
/**
|
||||
* Delay (nop) for a given number of cycles
|
||||
*/
|
||||
@ -282,7 +294,8 @@ union ulp_insn {
|
||||
* @param reg peripheral register in RTC_CNTL_, RTC_IO_, SENS_, RTC_I2C peripherals.
|
||||
* @return periph_sel value for the peripheral to which this register belongs.
|
||||
*/
|
||||
static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg) {
|
||||
static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg)
|
||||
{
|
||||
uint32_t ret = 3;
|
||||
if (reg < DR_REG_RTCCNTL_BASE) {
|
||||
assert(0 && "invalid register base");
|
||||
@ -290,9 +303,9 @@ static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg) {
|
||||
ret = RD_REG_PERIPH_RTC_CNTL;
|
||||
} else if (reg < DR_REG_SENS_BASE) {
|
||||
ret = RD_REG_PERIPH_RTC_IO;
|
||||
} else if (reg < DR_REG_RTC_I2C_BASE){
|
||||
} else if (reg < DR_REG_RTC_I2C_BASE) {
|
||||
ret = RD_REG_PERIPH_SENS;
|
||||
} else if (reg < DR_REG_IO_MUX_BASE){
|
||||
} else if (reg < DR_REG_IO_MUX_BASE) {
|
||||
ret = RD_REG_PERIPH_RTC_I2C;
|
||||
} else {
|
||||
assert(0 && "invalid register base");
|
||||
@ -350,7 +363,7 @@ static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg) {
|
||||
*
|
||||
* To disable the timer which start ULP program, use I_END()
|
||||
* instruction. I_END instruction clears the
|
||||
* RTC_CNTL_ULP_CP_SLP_TIMER_EN_S bit of RTC_CNTL_STATE0_REG
|
||||
* RTC_CNTL_ULP_CP_SLP_TIMER_EN_S bit of RTC_CNTL_ULP_CP_TIMER_REG
|
||||
* register, which controls the ULP timer.
|
||||
*/
|
||||
#define I_WAKE() { .end = { \
|
||||
@ -370,27 +383,7 @@ static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg) {
|
||||
* the currently running program, use I_HALT().
|
||||
*/
|
||||
#define I_END() \
|
||||
I_WR_REG_BIT(RTC_CNTL_STATE0_REG, RTC_CNTL_ULP_CP_SLP_TIMER_EN_S, 0)
|
||||
/**
|
||||
* Select the time interval used to run ULP program.
|
||||
*
|
||||
* This instructions selects which of the SENS_SLEEP_CYCLES_Sx
|
||||
* registers' value is used by the ULP program timer.
|
||||
* When the ULP program stops at I_HALT instruction, ULP program
|
||||
* timer start counting. When the counter reaches the value of
|
||||
* the selected SENS_SLEEP_CYCLES_Sx register, ULP program
|
||||
* start running again from the start address (passed to the ulp_run
|
||||
* function).
|
||||
* There are 5 SENS_SLEEP_CYCLES_Sx registers, so 0 <= timer_idx < 5.
|
||||
*
|
||||
* By default, SENS_SLEEP_CYCLES_S0 register is used by the ULP
|
||||
* program timer.
|
||||
*/
|
||||
#define I_SLEEP_CYCLE_SEL(timer_idx) { .sleep = { \
|
||||
.cycle_sel = timer_idx, \
|
||||
.unused = 0, \
|
||||
.sub_opcode = SUB_OPCODE_SLEEP, \
|
||||
.opcode = OPCODE_END } }
|
||||
I_WR_REG_BIT(RTC_CNTL_ULP_CP_TIMER_REG, RTC_CNTL_ULP_CP_SLP_TIMER_EN_S, 0)
|
||||
|
||||
/**
|
||||
* Perform temperature sensor measurement and store it into reg_dest.
|
||||
@ -420,45 +413,247 @@ static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg) {
|
||||
.opcode = OPCODE_ADC } }
|
||||
|
||||
/**
|
||||
* Store value from register reg_val into RTC memory.
|
||||
* Store lower half-word, upper half-word or full-word data from register reg_val into RTC memory address.
|
||||
*
|
||||
* The value is written to an offset calculated by adding value of
|
||||
* This instruction can be used to write data to discontinuous addresses in the RTC_SLOW_MEM.
|
||||
* The value is written to an offset calculated by adding the value of
|
||||
* reg_addr register and offset_ field (this offset is expressed in 32-bit words).
|
||||
* 32 bits written to RTC memory are built as follows:
|
||||
* - bits [31:21] hold the PC of current instruction, expressed in 32-bit words
|
||||
* - bits [20:18] = 3'b0
|
||||
* - bits [17:16] reg_addr (0..3)
|
||||
* - bits [15:0] are assigned the contents of reg_val
|
||||
* The storage method is dictated by the wr_way and upper field settings as summarized in the following table:
|
||||
*
|
||||
* RTC_SLOW_MEM[addr + offset_] = { insn_PC[10:0], 3'b0, reg_addr, reg_val[15:0] }
|
||||
* @verbatim
|
||||
* |--------|-------|----------------------------------------------------------------------------------------|----------------------------|
|
||||
* | wr_way | upper | data | operation |
|
||||
* |--------|-------|----------------------------------------------------------------------------------------|----------------------------|
|
||||
* | | | | Write full-word, including |
|
||||
* | 0 | X | RTC_SLOW_MEM[addr + offset_]{31:0} = {insn_PC[10:0], 3’b0, label_[1:0], reg_val[15:0]} | the PC and the data |
|
||||
* |--------|-------|----------------------------------------------------------------------------------------|----------------------------|
|
||||
* | | | | Store the data with label |
|
||||
* | 1 | 0 | RTC_SLOW_MEM[addr + offset_]{15:0} = {label_[1:0], reg_val[13:0]} | in the low half-word |
|
||||
* |--------|-------|----------------------------------------------------------------------------------------|----------------------------|
|
||||
* | | | | Store the data with label |
|
||||
* | 1 | 1 | RTC_SLOW_MEM[addr + offset_]{31:16} = {label_[1:0], reg_val[13:0]} | in the high half-word |
|
||||
* |--------|-------|----------------------------------------------------------------------------------------|----------------------------|
|
||||
* | | | | Store the data without |
|
||||
* | 3 | 0 | RTC_SLOW_MEM[addr + offset_]{15:0} = reg_val[15:0] | label in the low half-word |
|
||||
* |--------|-------|----------------------------------------------------------------------------------------|----------------------------|
|
||||
* | | | | Store the data without |
|
||||
* | 3 | 1 | RTC_SLOW_MEM[addr + offset_]{31:16} = reg_val[15:0] | label in the high half-word|
|
||||
* |--------|-------|----------------------------------------------------------------------------------------|----------------------------|
|
||||
* @endverbatim
|
||||
*
|
||||
* SUB_OPCODE_ST = manual_en:1, offset_set:0, wr_auto:0
|
||||
*/
|
||||
#define I_ST(reg_val, reg_addr, offset_) { .st = { \
|
||||
#define I_ST_MANUAL(reg_val, reg_addr, offset_, label_, upper_, wr_way_) { .st = { \
|
||||
.dreg = reg_val, \
|
||||
.sreg = reg_addr, \
|
||||
.label = label_, \
|
||||
.upper = upper_, \
|
||||
.wr_way = wr_way_, \
|
||||
.unused1 = 0, \
|
||||
.offset = offset_, \
|
||||
.unused2 = 0, \
|
||||
.sub_opcode = SUB_OPCODE_ST, \
|
||||
.opcode = OPCODE_ST } }
|
||||
|
||||
/**
|
||||
* Store value from register reg_val into RTC memory.
|
||||
*
|
||||
* I_ST() instruction provides backward compatibility for code written for esp32 to be run on esp32s2.
|
||||
* This instruction is equivalent to calling I_ST_MANUAL() instruction with label = 0, upper = 0 and wr_way = 3.
|
||||
*/
|
||||
#define I_ST(reg_val, reg_addr, offset_) I_ST_MANUAL(reg_val, reg_addr, offset_, 0, 0, 3)
|
||||
|
||||
/**
|
||||
* Load value from RTC memory into reg_dest register.
|
||||
* Store value from register reg_val to lower 16 bits of the RTC memory address.
|
||||
*
|
||||
* Loads 16 LSBs from RTC memory word given by the sum of value in reg_addr and
|
||||
* value of offset_.
|
||||
* This instruction is equivalent to calling I_ST_MANUAL() instruction with label = 0, upper = 0 and wr_way = 3.
|
||||
*/
|
||||
#define I_LD(reg_dest, reg_addr, offset_) { .ld = { \
|
||||
#define I_STL(reg_val, reg_addr, offset_) I_ST_MANUAL(reg_val, reg_addr, offset_, 0, 0, 3)
|
||||
|
||||
/**
|
||||
* Store value from register reg_val to upper 16 bits of the RTC memory address.
|
||||
*
|
||||
* This instruction is equivalent to calling I_ST_MANUAL() instruction with label = 0, upper = 1 and wr_way = 3.
|
||||
*/
|
||||
#define I_STH(reg_val, reg_addr, offset_) I_ST_MANUAL(reg_val, reg_addr, offset_, 0, 1, 3)
|
||||
|
||||
/**
|
||||
* Store value from register reg_val to full 32 bit word of the RTC memory address.
|
||||
*
|
||||
* This instruction is equivalent to calling I_ST_MANUAL() instruction with wr_way = 0.
|
||||
*/
|
||||
#define I_ST32(reg_val, reg_addr, offset_, label_) I_ST_MANUAL(reg_val, reg_addr, offset_, label_, 0, 0)
|
||||
|
||||
/**
|
||||
* Store value from register reg_val with label to lower 16 bits of RTC memory address.
|
||||
*
|
||||
* This instruction is equivalent to calling I_ST_MANUAL() instruction with label = label_, upper = 0 and wr_way = 1.
|
||||
*/
|
||||
#define I_STL_LABEL(reg_val, reg_addr, offset_, label_) I_ST_MANUAL(reg_val, reg_addr, offset_, label_, 0, 1)
|
||||
|
||||
/**
|
||||
* Store value from register reg_val with label to upper 16 bits of RTC memory address.
|
||||
*
|
||||
* This instruction is equivalent to calling I_ST_MANUAL() instruction with label = label_, upper = 1 and wr_way = 1.
|
||||
*/
|
||||
#define I_STH_LABEL(reg_val, reg_addr, offset_, label_) I_ST_MANUAL(reg_val, reg_addr, offset_, label_, 1, 1)
|
||||
|
||||
/**
|
||||
* Store lower half-word, upper half-word or full-word data from register reg_val into RTC memory address with auto-increment of the offset value.
|
||||
*
|
||||
* This instruction can be used to write data to continuous addresses in the RTC_SLOW_MEM.
|
||||
* The initial address must be set using the SUB_OPCODE_ST_OFFSET instruction before the auto store instruction is called.
|
||||
* The data written to the RTC memory address could be written to the full 32 bit word or to the lower half-word or the
|
||||
* upper half-word. The storage method is dictated by the wr_way field and the number of times the SUB_OPCODE_ST_AUTO instruction is called.
|
||||
* write_cnt indicates the later. The following table summarizes the storage method:
|
||||
*
|
||||
* @verbatim
|
||||
* |--------|-----------|----------------------------------------------------------------------------------------|----------------------------|
|
||||
* | wr_way | write_cnt | data | operation |
|
||||
* |--------|-----------|----------------------------------------------------------------------------------------|----------------------------|
|
||||
* | | | | Write full-word, including |
|
||||
* | 0 | X | RTC_SLOW_MEM[addr + offset_]{31:0} = {insn_PC[10:0], 3’b0, label_[1:0], reg_val[15:0]} | the PC and the data |
|
||||
* |--------|-----------|----------------------------------------------------------------------------------------|----------------------------|
|
||||
* | | | | Store the data with label |
|
||||
* | 1 | odd | RTC_SLOW_MEM[addr + offset_]{15:0} = {label_[1:0], reg_val[13:0]} | in the low half-word |
|
||||
* |--------|-----------|----------------------------------------------------------------------------------------|----------------------------|
|
||||
* | | | | Store the data with label |
|
||||
* | 1 | even | RTC_SLOW_MEM[addr + offset_]{31:16} = {label_[1:0], reg_val[13:0]} | in the high half-word |
|
||||
* |--------|-----------|----------------------------------------------------------------------------------------|----------------------------|
|
||||
* | | | | Store the data without |
|
||||
* | 3 | odd | RTC_SLOW_MEM[addr + offset_]{15:0} = reg_val[15:0] | label in the low half-word |
|
||||
* |--------|-----------|----------------------------------------------------------------------------------------|----------------------------|
|
||||
* | | | | Store the data without |
|
||||
* | 3 | even | RTC_SLOW_MEM[addr + offset_]{31:16} = reg_val[15:0] | label in the high half-word|
|
||||
* |--------|-----------|----------------------------------------------------------------------------------------|----------------------------|
|
||||
* @endverbatim
|
||||
*
|
||||
* The initial address offset is incremented after each store operation as follows:
|
||||
* - When a full-word is written, the offset is automatically incremented by 1 after each SUB_OPCODE_ST_AUTO operation.
|
||||
* - When a half-word is written (lower half-word first), the offset is automatically incremented by 1 after two
|
||||
* SUB_OPCODE_ST_AUTO operations.
|
||||
*
|
||||
* SUB_OPCODE_ST_AUTO = manual_en:0, offset_set:0, wr_auto:1
|
||||
*/
|
||||
#define I_ST_AUTO(reg_val, reg_addr, label_, wr_way_) { .st = { \
|
||||
.dreg = reg_addr, \
|
||||
.sreg = reg_val, \
|
||||
.label = label_, \
|
||||
.upper = 0, \
|
||||
.wr_way = wr_way_, \
|
||||
.unused1 = 0, \
|
||||
.offset = 0, \
|
||||
.unused2 = 0, \
|
||||
.sub_opcode = SUB_OPCODE_ST_AUTO, \
|
||||
.opcode = OPCODE_ST } }
|
||||
|
||||
/**
|
||||
* Set the initial address offset for auto-store operation
|
||||
*
|
||||
* This instruction sets the initial address of the RTC_SLOW_MEM to be used by the auto-store operation.
|
||||
* The offset is incremented automatically.
|
||||
* Refer I_ST_AUTO() for detailed explaination.
|
||||
*
|
||||
* SUB_OPCODE_ST_OFFSET = manual_en:0, offset_set:1, wr_auto:1
|
||||
*/
|
||||
#define I_STO(offset_) { .st = { \
|
||||
.dreg = 0, \
|
||||
.sreg = 0, \
|
||||
.label = 0, \
|
||||
.upper = 0, \
|
||||
.wr_way = 0, \
|
||||
.unused1 = 0, \
|
||||
.offset = offset_, \
|
||||
.unused2 = 0, \
|
||||
.sub_opcode = SUB_OPCODE_ST_OFFSET, \
|
||||
.opcode = OPCODE_ST } }
|
||||
|
||||
/**
|
||||
* Store value from register reg_val to 32 bit word of the RTC memory address.
|
||||
*
|
||||
* This instruction is equivalent to calling I_ST_AUTO() instruction with label = 0 and wr_way = 3.
|
||||
* The data in reg_val will be either written to the lower half-word or the upper half-word of the RTC memory address
|
||||
* depending on the count of the number of times the I_STI() instruction is called.
|
||||
* The initial offset is automatically incremented with I_STI() is called twice.
|
||||
* Refer I_ST_AUTO() for detailed explaination.
|
||||
*/
|
||||
#define I_STI(reg_val, reg_addr) I_ST_AUTO(reg_val, reg_addr, 0, 3)
|
||||
|
||||
/**
|
||||
* Store value from register reg_val with label to 32 bit word of the RTC memory address.
|
||||
*
|
||||
* This instruction is equivalent to calling I_ST_AUTO() instruction with label = label_ and wr_way = 1.
|
||||
* The data in reg_val will be either written to the lower half-word or the upper half-word of the RTC memory address
|
||||
* depending on the count of the number of times the I_STI_LABEL() instruction is called.
|
||||
* The initial offset is automatically incremented with I_STI_LABEL() is called twice.
|
||||
* Refer I_ST_AUTO() for detailed explaination.
|
||||
*/
|
||||
#define I_STI_LABEL(reg_val, reg_addr, label_) I_ST_AUTO(reg_val, reg_addr, label_, 1)
|
||||
|
||||
/**
|
||||
* Store value from register reg_val to full 32 bit word of the RTC memory address.
|
||||
*
|
||||
* This instruction is equivalent to calling I_ST_AUTO() instruction with label = label_ and wr_way = 0.
|
||||
* The data in reg_val will be written to the RTC memory address along with the label and the PC.
|
||||
* The initial offset is automatically incremented each time the I_STI32() instruction is called.
|
||||
* Refer I_ST_AUTO() for detailed explaination.
|
||||
*/
|
||||
#define I_STI32(reg_val, reg_addr, label_) I_ST_AUTO(reg_val, reg_addr, label_, 0)
|
||||
|
||||
/**
|
||||
* Load lower half-word, upper half-word or full-word data from RTC memory address into the register reg_dest.
|
||||
*
|
||||
* This instruction reads the lower half-word or upper half-word of the RTC memory address depending on the value
|
||||
* of rd_upper_. The following table summarizes the loading method:
|
||||
*
|
||||
* @verbatim
|
||||
* |----------|------------------------------------------------------|-------------------------|
|
||||
* | rd_upper | data | operation |
|
||||
* |----------|------------------------------------------------------|-------------------------|
|
||||
* | | | Read lower half-word of |
|
||||
* | 0 | reg_dest{15:0} = RTC_SLOW_MEM[addr + offset_]{31:16} | the memory |
|
||||
* |----------|------------------------------------------------------|-------------------------|
|
||||
* | | | Read upper half-word of |
|
||||
* | 1 | reg_dest{15:0} = RTC_SLOW_MEM[addr + offset_]{15:0} | the memory |
|
||||
* |----------|------------------------------------------------------|-------------------------|
|
||||
* @endverbatim
|
||||
*
|
||||
*/
|
||||
#define I_LD_MANUAL(reg_dest, reg_addr, offset_, rd_upper_) { .ld = { \
|
||||
.dreg = reg_dest, \
|
||||
.sreg = reg_addr, \
|
||||
.unused1 = 0, \
|
||||
.offset = offset_, \
|
||||
.unused2 = 0, \
|
||||
.rd_upper = rd_upper_, \
|
||||
.opcode = OPCODE_LD } }
|
||||
|
||||
/**
|
||||
* Load lower 16 bits value from RTC memory into reg_dest register.
|
||||
*
|
||||
* Loads 16 LSBs (rd_upper = 1) from RTC memory word given by the sum of value in reg_addr and
|
||||
* value of offset_.
|
||||
* I_LD() instruction provides backward compatibility for code written for esp32 to be run on esp32s2.
|
||||
*/
|
||||
#define I_LD(reg_dest, reg_addr, offset_) I_LD_MANUAL(reg_dest, reg_addr, offset_, 0)
|
||||
|
||||
/**
|
||||
* Branch relative if R0 less than immediate value.
|
||||
* Load lower 16 bits value from RTC memory into reg_dest register.
|
||||
*
|
||||
* I_LDL() instruction and I_LD() instruction can be used interchangably.
|
||||
*/
|
||||
#define I_LDL(reg_dest, reg_addr, offset_) I_LD(reg_dest, reg_addr, offset_)
|
||||
|
||||
/**
|
||||
* Load upper 16 bits value from RTC memory into reg_dest register.
|
||||
*
|
||||
* Loads 16 MSBs (rd_upper = 0) from RTC memory word given by the sum of value in reg_addr and
|
||||
* value of offset_.
|
||||
*/
|
||||
#define I_LDH(reg_dest, reg_addr, offset_) I_LD_MANUAL(reg_dest, reg_addr, offset_, 1)
|
||||
|
||||
/**
|
||||
* Branch relative if R0 register less than the immediate value.
|
||||
*
|
||||
* pc_offset is expressed in words, and can be from -127 to 127
|
||||
* imm_value is a 16-bit value to compare R0 against
|
||||
@ -472,14 +667,28 @@ static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg) {
|
||||
.opcode = OPCODE_BRANCH } }
|
||||
|
||||
/**
|
||||
* Branch relative if R0 greater or equal than immediate value.
|
||||
* Branch relative if R0 register greater than the immediate value.
|
||||
*
|
||||
* pc_offset is expressed in words, and can be from -127 to 127
|
||||
* imm_value is a 16-bit value to compare R0 against
|
||||
*/
|
||||
#define I_BGE(pc_offset, imm_value) { .b = { \
|
||||
#define I_BG(pc_offset, imm_value) { .b = { \
|
||||
.imm = imm_value, \
|
||||
.cmp = B_CMP_GE, \
|
||||
.cmp = B_CMP_G, \
|
||||
.offset = abs(pc_offset), \
|
||||
.sign = (pc_offset >= 0) ? 0 : 1, \
|
||||
.sub_opcode = SUB_OPCODE_B, \
|
||||
.opcode = OPCODE_BRANCH } }
|
||||
|
||||
/**
|
||||
* Branch relative if R0 register is equal to the immediate value.
|
||||
*
|
||||
* pc_offset is expressed in words, and can be from -127 to 127
|
||||
* imm_value is a 16-bit value to compare R0 against
|
||||
*/
|
||||
#define I_BE(pc_offset, imm_value) { .b = { \
|
||||
.imm = imm_value, \
|
||||
.cmp = B_CMP_E, \
|
||||
.offset = abs(pc_offset), \
|
||||
.sign = (pc_offset >= 0) ? 0 : 1, \
|
||||
.sub_opcode = SUB_OPCODE_B, \
|
||||
@ -494,9 +703,10 @@ static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg) {
|
||||
#define I_BXR(reg_pc) { .bx = { \
|
||||
.dreg = reg_pc, \
|
||||
.addr = 0, \
|
||||
.unused = 0, \
|
||||
.unused1 = 0, \
|
||||
.reg = 1, \
|
||||
.type = BX_JUMP_TYPE_DIRECT, \
|
||||
.unused2 = 0, \
|
||||
.sub_opcode = SUB_OPCODE_BX, \
|
||||
.opcode = OPCODE_BRANCH } }
|
||||
|
||||
@ -508,9 +718,10 @@ static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg) {
|
||||
#define I_BXI(imm_pc) { .bx = { \
|
||||
.dreg = 0, \
|
||||
.addr = imm_pc, \
|
||||
.unused = 0, \
|
||||
.unused1 = 0, \
|
||||
.reg = 0, \
|
||||
.type = BX_JUMP_TYPE_DIRECT, \
|
||||
.unused2 = 0, \
|
||||
.sub_opcode = SUB_OPCODE_BX, \
|
||||
.opcode = OPCODE_BRANCH } }
|
||||
|
||||
@ -523,9 +734,10 @@ static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg) {
|
||||
#define I_BXZR(reg_pc) { .bx = { \
|
||||
.dreg = reg_pc, \
|
||||
.addr = 0, \
|
||||
.unused = 0, \
|
||||
.unused1 = 0, \
|
||||
.reg = 1, \
|
||||
.type = BX_JUMP_TYPE_ZERO, \
|
||||
.unused2 = 0, \
|
||||
.sub_opcode = SUB_OPCODE_BX, \
|
||||
.opcode = OPCODE_BRANCH } }
|
||||
|
||||
@ -537,9 +749,10 @@ static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg) {
|
||||
#define I_BXZI(imm_pc) { .bx = { \
|
||||
.dreg = 0, \
|
||||
.addr = imm_pc, \
|
||||
.unused = 0, \
|
||||
.unused1 = 0, \
|
||||
.reg = 0, \
|
||||
.type = BX_JUMP_TYPE_ZERO, \
|
||||
.unused2 = 0, \
|
||||
.sub_opcode = SUB_OPCODE_BX, \
|
||||
.opcode = OPCODE_BRANCH } }
|
||||
|
||||
@ -552,9 +765,10 @@ static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg) {
|
||||
#define I_BXFR(reg_pc) { .bx = { \
|
||||
.dreg = reg_pc, \
|
||||
.addr = 0, \
|
||||
.unused = 0, \
|
||||
.unused1 = 0, \
|
||||
.reg = 1, \
|
||||
.type = BX_JUMP_TYPE_OVF, \
|
||||
.unused2 = 0, \
|
||||
.sub_opcode = SUB_OPCODE_BX, \
|
||||
.opcode = OPCODE_BRANCH } }
|
||||
|
||||
@ -566,12 +780,54 @@ static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg) {
|
||||
#define I_BXFI(imm_pc) { .bx = { \
|
||||
.dreg = 0, \
|
||||
.addr = imm_pc, \
|
||||
.unused = 0, \
|
||||
.unused1 = 0, \
|
||||
.reg = 0, \
|
||||
.type = BX_JUMP_TYPE_OVF, \
|
||||
.unused2 = 0, \
|
||||
.sub_opcode = SUB_OPCODE_BX, \
|
||||
.opcode = OPCODE_BRANCH } }
|
||||
|
||||
/**
|
||||
* Branch relative if stage_cnt is less than or equal to the immediate value.
|
||||
*
|
||||
* pc_offset is expressed in words, and can be from -127 to 127
|
||||
* imm_value is a 16-bit value to compare R0 against
|
||||
*/
|
||||
#define I_BSLE(pc_offset, imm_value) { .b = { \
|
||||
.imm = imm_value, \
|
||||
.cmp = BS_CMP_LE, \
|
||||
.offset = abs(pc_offset), \
|
||||
.sign = (pc_offset >= 0) ? 0 : 1, \
|
||||
.sub_opcode = SUB_OPCODE_BS, \
|
||||
.opcode = OPCODE_BRANCH } }
|
||||
|
||||
/**
|
||||
* Branch relative if stage_cnt register is greater than or equal to the immediate value.
|
||||
*
|
||||
* pc_offset is expressed in words, and can be from -127 to 127
|
||||
* imm_value is a 16-bit value to compare R0 against
|
||||
*/
|
||||
#define I_BSGE(pc_offset, imm_value) { .b = { \
|
||||
.imm = imm_value, \
|
||||
.cmp = BS_CMP_GE, \
|
||||
.offset = abs(pc_offset), \
|
||||
.sign = (pc_offset >= 0) ? 0 : 1, \
|
||||
.sub_opcode = SUB_OPCODE_BS, \
|
||||
.opcode = OPCODE_BRANCH } }
|
||||
|
||||
/**
|
||||
* Branch relative if stage_cnt register is less than the immediate value.
|
||||
*
|
||||
* pc_offset is expressed in words, and can be from -127 to 127
|
||||
* imm_value is a 16-bit value to compare R0 against
|
||||
*/
|
||||
#define I_BSL(pc_offset, imm_value) { .b = { \
|
||||
.imm = imm_value, \
|
||||
.cmp = BS_CMP_L, \
|
||||
.offset = abs(pc_offset), \
|
||||
.sign = (pc_offset >= 0) ? 0 : 1, \
|
||||
.sub_opcode = SUB_OPCODE_BS, \
|
||||
.opcode = OPCODE_BRANCH } }
|
||||
|
||||
/**
|
||||
* Addition: dest = src1 + src2
|
||||
@ -580,8 +836,9 @@ static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg) {
|
||||
.dreg = reg_dest, \
|
||||
.sreg = reg_src1, \
|
||||
.treg = reg_src2, \
|
||||
.unused = 0, \
|
||||
.unused1 = 0, \
|
||||
.sel = ALU_SEL_ADD, \
|
||||
.unused2 = 0, \
|
||||
.sub_opcode = SUB_OPCODE_ALU_REG, \
|
||||
.opcode = OPCODE_ALU } }
|
||||
|
||||
@ -592,8 +849,9 @@ static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg) {
|
||||
.dreg = reg_dest, \
|
||||
.sreg = reg_src1, \
|
||||
.treg = reg_src2, \
|
||||
.unused = 0, \
|
||||
.unused1 = 0, \
|
||||
.sel = ALU_SEL_SUB, \
|
||||
.unused2 = 0, \
|
||||
.sub_opcode = SUB_OPCODE_ALU_REG, \
|
||||
.opcode = OPCODE_ALU } }
|
||||
|
||||
@ -604,8 +862,9 @@ static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg) {
|
||||
.dreg = reg_dest, \
|
||||
.sreg = reg_src1, \
|
||||
.treg = reg_src2, \
|
||||
.unused = 0, \
|
||||
.unused1 = 0, \
|
||||
.sel = ALU_SEL_AND, \
|
||||
.unused2 = 0, \
|
||||
.sub_opcode = SUB_OPCODE_ALU_REG, \
|
||||
.opcode = OPCODE_ALU } }
|
||||
|
||||
@ -616,8 +875,9 @@ static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg) {
|
||||
.dreg = reg_dest, \
|
||||
.sreg = reg_src1, \
|
||||
.treg = reg_src2, \
|
||||
.unused = 0, \
|
||||
.unused1 = 0, \
|
||||
.sel = ALU_SEL_OR, \
|
||||
.unused2 = 0, \
|
||||
.sub_opcode = SUB_OPCODE_ALU_REG, \
|
||||
.opcode = OPCODE_ALU } }
|
||||
|
||||
@ -628,8 +888,9 @@ static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg) {
|
||||
.dreg = reg_dest, \
|
||||
.sreg = reg_src, \
|
||||
.treg = 0, \
|
||||
.unused = 0, \
|
||||
.unused1 = 0, \
|
||||
.sel = ALU_SEL_MOV, \
|
||||
.unused2 = 0, \
|
||||
.sub_opcode = SUB_OPCODE_ALU_REG, \
|
||||
.opcode = OPCODE_ALU } }
|
||||
|
||||
@ -640,8 +901,9 @@ static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg) {
|
||||
.dreg = reg_dest, \
|
||||
.sreg = reg_src, \
|
||||
.treg = reg_shift, \
|
||||
.unused = 0, \
|
||||
.unused1 = 0, \
|
||||
.sel = ALU_SEL_LSH, \
|
||||
.unused2 = 0, \
|
||||
.sub_opcode = SUB_OPCODE_ALU_REG, \
|
||||
.opcode = OPCODE_ALU } }
|
||||
|
||||
@ -653,8 +915,9 @@ static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg) {
|
||||
.dreg = reg_dest, \
|
||||
.sreg = reg_src, \
|
||||
.treg = reg_shift, \
|
||||
.unused = 0, \
|
||||
.unused1 = 0, \
|
||||
.sel = ALU_SEL_RSH, \
|
||||
.unused2 = 0, \
|
||||
.sub_opcode = SUB_OPCODE_ALU_REG, \
|
||||
.opcode = OPCODE_ALU } }
|
||||
|
||||
@ -665,8 +928,9 @@ static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg) {
|
||||
.dreg = reg_dest, \
|
||||
.sreg = reg_src, \
|
||||
.imm = imm_, \
|
||||
.unused = 0, \
|
||||
.unused1 = 0, \
|
||||
.sel = ALU_SEL_ADD, \
|
||||
.unused2 = 0, \
|
||||
.sub_opcode = SUB_OPCODE_ALU_IMM, \
|
||||
.opcode = OPCODE_ALU } }
|
||||
|
||||
@ -678,8 +942,9 @@ static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg) {
|
||||
.dreg = reg_dest, \
|
||||
.sreg = reg_src, \
|
||||
.imm = imm_, \
|
||||
.unused = 0, \
|
||||
.unused1 = 0, \
|
||||
.sel = ALU_SEL_SUB, \
|
||||
.unused2 = 0, \
|
||||
.sub_opcode = SUB_OPCODE_ALU_IMM, \
|
||||
.opcode = OPCODE_ALU } }
|
||||
|
||||
@ -690,8 +955,9 @@ static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg) {
|
||||
.dreg = reg_dest, \
|
||||
.sreg = reg_src, \
|
||||
.imm = imm_, \
|
||||
.unused = 0, \
|
||||
.unused1 = 0, \
|
||||
.sel = ALU_SEL_AND, \
|
||||
.unused2 = 0, \
|
||||
.sub_opcode = SUB_OPCODE_ALU_IMM, \
|
||||
.opcode = OPCODE_ALU } }
|
||||
|
||||
@ -702,8 +968,9 @@ static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg) {
|
||||
.dreg = reg_dest, \
|
||||
.sreg = reg_src, \
|
||||
.imm = imm_, \
|
||||
.unused = 0, \
|
||||
.unused1 = 0, \
|
||||
.sel = ALU_SEL_OR, \
|
||||
.unused2 = 0, \
|
||||
.sub_opcode = SUB_OPCODE_ALU_IMM, \
|
||||
.opcode = OPCODE_ALU } }
|
||||
|
||||
@ -714,8 +981,9 @@ static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg) {
|
||||
.dreg = reg_dest, \
|
||||
.sreg = 0, \
|
||||
.imm = imm_, \
|
||||
.unused = 0, \
|
||||
.unused1 = 0, \
|
||||
.sel = ALU_SEL_MOV, \
|
||||
.unused2 = 0, \
|
||||
.sub_opcode = SUB_OPCODE_ALU_IMM, \
|
||||
.opcode = OPCODE_ALU } }
|
||||
|
||||
@ -726,8 +994,9 @@ static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg) {
|
||||
.dreg = reg_dest, \
|
||||
.sreg = reg_src, \
|
||||
.imm = imm_, \
|
||||
.unused = 0, \
|
||||
.unused1 = 0, \
|
||||
.sel = ALU_SEL_LSH, \
|
||||
.unused2 = 0, \
|
||||
.sub_opcode = SUB_OPCODE_ALU_IMM, \
|
||||
.opcode = OPCODE_ALU } }
|
||||
|
||||
@ -739,11 +1008,48 @@ static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg) {
|
||||
.dreg = reg_dest, \
|
||||
.sreg = reg_src, \
|
||||
.imm = imm_, \
|
||||
.unused = 0, \
|
||||
.unused1 = 0, \
|
||||
.sel = ALU_SEL_RSH, \
|
||||
.unused2 = 0, \
|
||||
.sub_opcode = SUB_OPCODE_ALU_IMM, \
|
||||
.opcode = OPCODE_ALU } }
|
||||
|
||||
/**
|
||||
* Increment stage_cnt register by an immediate: stage_cnt = stage_cnt + imm
|
||||
*/
|
||||
#define I_STAGE_INC(reg_dest, reg_src, imm_) { .alu_cnt = { \
|
||||
.unused1 = 0, \
|
||||
.imm = imm_, \
|
||||
.unused2 = 0, \
|
||||
.sel = ALU_SEL_STAGE_INC, \
|
||||
.unused3 = 0, \
|
||||
.sub_opcode = SUB_OPCODE_ALU_CNT, \
|
||||
.opcode = OPCODE_ALU } }
|
||||
|
||||
/**
|
||||
* Decrement stage_cnt register by an immediate: stage_cnt = stage_cnt - imm
|
||||
*/
|
||||
#define I_STAGE_DEC(reg_dest, reg_src, imm_) { .alu_cnt = { \
|
||||
.unused1 = 0, \
|
||||
.imm = imm_, \
|
||||
.unused2 = 0, \
|
||||
.sel = ALU_SEL_STAGE_DEC, \
|
||||
.unused3 = 0, \
|
||||
.sub_opcode = SUB_OPCODE_ALU_CNT, \
|
||||
.opcode = OPCODE_ALU } }
|
||||
|
||||
/**
|
||||
* Reset stage_cnt register by an immediate: stage_cnt = 0
|
||||
*/
|
||||
#define I_STAGE_RST(reg_dest, reg_src, imm_) { .alu_cnt = { \
|
||||
.unused1 = 0, \
|
||||
.imm = imm_, \
|
||||
.unused2 = 0, \
|
||||
.sel = ALU_SEL_STAGE_RST, \
|
||||
.unused3 = 0, \
|
||||
.sub_opcode = SUB_OPCODE_ALU_CNT, \
|
||||
.opcode = OPCODE_ALU } }
|
||||
|
||||
/**
|
||||
* Define a label with number label_num.
|
||||
*
|
||||
@ -780,16 +1086,28 @@ static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg) {
|
||||
I_BL(0, imm_value)
|
||||
|
||||
/**
|
||||
* Macro: branch to label label_num if R0 is greater or equal than immediate value
|
||||
* Macro: branch to label label_num if R0 is greater than immediate value
|
||||
*
|
||||
* This macro generates two ulp_insn_t values separated by a comma, and should
|
||||
* be used when defining contents of ulp_insn_t arrays. First value is not a
|
||||
* real instruction; it is a token which is removed by ulp_process_macros_and_load
|
||||
* function.
|
||||
*/
|
||||
#define M_BGE(label_num, imm_value) \
|
||||
#define M_BG(label_num, imm_value) \
|
||||
M_BRANCH(label_num), \
|
||||
I_BGE(0, imm_value)
|
||||
I_BG(0, imm_value)
|
||||
|
||||
/**
|
||||
* Macro: branch to label label_num if R0 equal to the immediate value
|
||||
*
|
||||
* This macro generates two ulp_insn_t values separated by a comma, and should
|
||||
* be used when defining contents of ulp_insn_t arrays. First value is not a
|
||||
* real instruction; it is a token which is removed by ulp_process_macros_and_load
|
||||
* function.
|
||||
*/
|
||||
#define M_BE(label_num, imm_value) \
|
||||
M_BRANCH(label_num), \
|
||||
I_BE(0, imm_value)
|
||||
|
||||
/**
|
||||
* Macro: unconditional branch to label
|
||||
@ -828,7 +1146,6 @@ static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg) {
|
||||
I_BXFI(0)
|
||||
|
||||
|
||||
|
||||
#define RTC_SLOW_MEM ((uint32_t*) 0x50000000) /*!< RTC slow memory, 8k size */
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -1,16 +1,8 @@
|
||||
// Copyright 2016-2018 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2016-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
@ -24,9 +16,6 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define ULP_FSM_PREPARE_SLEEP_CYCLES 2 /*!< Cycles spent by FSM preparing ULP for sleep */
|
||||
#define ULP_FSM_WAKEUP_SLEEP_CYCLES 2 /*!< Cycles spent by FSM waking up ULP from sleep */
|
||||
|
||||
/**
|
||||
* @defgroup ulp_registers ULP coprocessor registers
|
||||
* @{
|
||||
@ -63,7 +52,9 @@ extern "C" {
|
||||
#define OPCODE_ADC 5 /*!< Instruction: SAR ADC measurement (not implemented yet) */
|
||||
|
||||
#define OPCODE_ST 6 /*!< Instruction: store indirect to RTC memory */
|
||||
#define SUB_OPCODE_ST 4 /*!< Store 32 bits, 16 MSBs contain PC, 16 LSBs contain value from source register */
|
||||
#define SUB_OPCODE_ST_AUTO 1 /*!< Automatic Storage Mode - Access continuous addresses. Use SUB_OPCODE_ST_OFFSET to configure the initial address before using this instruction. */
|
||||
#define SUB_OPCODE_ST_OFFSET 3 /*!< Automatic Storage Mode - Configure the initial address. */
|
||||
#define SUB_OPCODE_ST 4 /*!< Manual Storage Mode. Store 32 bits, 16 MSBs contain PC, 16 LSBs contain value from source register */
|
||||
|
||||
#define OPCODE_ALU 7 /*!< Arithmetic instructions */
|
||||
#define SUB_OPCODE_ALU_REG 0 /*!< Arithmetic instruction, both source values are in register */
|
||||
@ -76,15 +67,23 @@ extern "C" {
|
||||
#define ALU_SEL_MOV 4 /*!< Copy value (immediate to destination register or source register to destination register */
|
||||
#define ALU_SEL_LSH 5 /*!< Shift left by given number of bits */
|
||||
#define ALU_SEL_RSH 6 /*!< Shift right by given number of bits */
|
||||
#define ALU_SEL_STAGE_INC 0 /*!< Increment stage count register */
|
||||
#define ALU_SEL_STAGE_DEC 1 /*!< Decrement stage count register */
|
||||
#define ALU_SEL_STAGE_RST 2 /*!< Reset stage count register */
|
||||
|
||||
#define OPCODE_BRANCH 8 /*!< Branch instructions */
|
||||
#define SUB_OPCODE_BX 0 /*!< Branch to absolute PC (immediate or in register) */
|
||||
#define SUB_OPCODE_B 0 /*!< Branch to a relative offset */
|
||||
#define SUB_OPCODE_BX 1 /*!< Branch to absolute PC (immediate or in register) */
|
||||
#define SUB_OPCODE_BS 2 /*!< Branch to a relative offset by comparing the stage_cnt register */
|
||||
#define BX_JUMP_TYPE_DIRECT 0 /*!< Unconditional jump */
|
||||
#define BX_JUMP_TYPE_ZERO 1 /*!< Branch if last ALU result is zero */
|
||||
#define BX_JUMP_TYPE_OVF 2 /*!< Branch if last ALU operation caused and overflow */
|
||||
#define SUB_OPCODE_B 1 /*!< Branch to a relative offset */
|
||||
#define B_CMP_L 0 /*!< Branch if R0 is less than an immediate */
|
||||
#define B_CMP_GE 1 /*!< Branch if R0 is greater than or equal to an immediate */
|
||||
#define B_CMP_G 1 /*!< Branch if R0 is greater than an immediate */
|
||||
#define B_CMP_E 2 /*!< Branch if R0 is equal to an immediate */
|
||||
#define BS_CMP_L 0 /*!< Branch if stage_cnt is less than an immediate */
|
||||
#define BS_CMP_GE 1 /*!< Branch if stage_cnt is greater than or equal to an immediate */
|
||||
#define BS_CMP_LE 2 /*!< Branch if stage_cnt is less than or equal to an immediate */
|
||||
|
||||
#define OPCODE_END 9 /*!< Stop executing the program */
|
||||
#define SUB_OPCODE_END 0 /*!< Stop executing the program and optionally wake up the chip */
|
||||
@ -99,6 +98,7 @@ extern "C" {
|
||||
#define OPCODE_MACRO 15 /*!< Not a real opcode. Used to identify labels and branches in the program */
|
||||
#define SUB_OPCODE_MACRO_LABEL 0 /*!< Label macro */
|
||||
#define SUB_OPCODE_MACRO_BRANCH 1 /*!< Branch macro */
|
||||
#define SUB_OPCODE_MACRO_LABELPC 2 /*!< Label pointer macro */
|
||||
/**@}*/
|
||||
|
||||
/**
|
||||
@ -126,7 +126,10 @@ union ulp_insn {
|
||||
struct {
|
||||
uint32_t dreg : 2; /*!< Register which contains data to store */
|
||||
uint32_t sreg : 2; /*!< Register which contains address in RTC memory (expressed in words) */
|
||||
uint32_t unused1 : 6; /*!< Unused */
|
||||
uint32_t label: 2; /*!< Data label, 2-bit user defined unsigned value */
|
||||
uint32_t upper: 1; /*!< 0: write the low half-word; 1: write the high half-word */
|
||||
uint32_t wr_way: 2; /*!< 0: write the full-word; 1: with the label; 3: without the label */
|
||||
uint32_t unused1 : 1; /*!< Unused */
|
||||
uint32_t offset : 11; /*!< Offset to add to sreg */
|
||||
uint32_t unused2 : 4; /*!< Unused */
|
||||
uint32_t sub_opcode : 3; /*!< Sub opcode (SUB_OPCODE_ST) */
|
||||
@ -138,7 +141,8 @@ union ulp_insn {
|
||||
uint32_t sreg : 2; /*!< Register which contains address in RTC memory (expressed in words) */
|
||||
uint32_t unused1 : 6; /*!< Unused */
|
||||
uint32_t offset : 11; /*!< Offset to add to sreg */
|
||||
uint32_t unused2 : 7; /*!< Unused */
|
||||
uint32_t unused2 : 6; /*!< Unused */
|
||||
uint32_t rd_upper: 1; /*!< 0: read the high half-word; 1: read the low half-word*/
|
||||
uint32_t opcode : 4; /*!< Opcode (OPCODE_LD) */
|
||||
} ld; /*!< Format of LD instruction */
|
||||
|
||||
@ -150,19 +154,20 @@ union ulp_insn {
|
||||
struct {
|
||||
uint32_t dreg : 2; /*!< Register which contains target PC, expressed in words (used if .reg == 1) */
|
||||
uint32_t addr : 11; /*!< Target PC, expressed in words (used if .reg == 0) */
|
||||
uint32_t unused : 8; /*!< Unused */
|
||||
uint32_t unused1 : 8; /*!< Unused */
|
||||
uint32_t reg : 1; /*!< Target PC in register (1) or immediate (0) */
|
||||
uint32_t type : 3; /*!< Jump condition (BX_JUMP_TYPE_xxx) */
|
||||
uint32_t sub_opcode : 3; /*!< Sub opcode (SUB_OPCODE_BX) */
|
||||
uint32_t unused2 : 1; /*!< Unused */
|
||||
uint32_t sub_opcode : 2; /*!< Sub opcode (SUB_OPCODE_BX) */
|
||||
uint32_t opcode : 4; /*!< Opcode (OPCODE_BRANCH) */
|
||||
} bx; /*!< Format of BRANCH instruction (absolute address) */
|
||||
|
||||
struct {
|
||||
uint32_t imm : 16; /*!< Immediate value to compare against */
|
||||
uint32_t cmp : 1; /*!< Comparison to perform: B_CMP_L or B_CMP_GE */
|
||||
uint32_t cmp : 2; /*!< Comparison to perform: B_CMP_L or B_CMP_GE */
|
||||
uint32_t offset : 7; /*!< Absolute value of target PC offset w.r.t. current PC, expressed in words */
|
||||
uint32_t sign : 1; /*!< Sign of target PC offset: 0: positive, 1: negative */
|
||||
uint32_t sub_opcode : 3; /*!< Sub opcode (SUB_OPCODE_B) */
|
||||
uint32_t sub_opcode : 2; /*!< Sub opcode (SUB_OPCODE_B) */
|
||||
uint32_t opcode : 4; /*!< Opcode (OPCODE_BRANCH) */
|
||||
} b; /*!< Format of BRANCH instruction (relative address) */
|
||||
|
||||
@ -170,9 +175,10 @@ union ulp_insn {
|
||||
uint32_t dreg : 2; /*!< Destination register */
|
||||
uint32_t sreg : 2; /*!< Register with operand A */
|
||||
uint32_t treg : 2; /*!< Register with operand B */
|
||||
uint32_t unused : 15; /*!< Unused */
|
||||
uint32_t unused1 : 15; /*!< Unused */
|
||||
uint32_t sel : 4; /*!< Operation to perform, one of ALU_SEL_xxx */
|
||||
uint32_t sub_opcode : 3; /*!< Sub opcode (SUB_OPCODE_ALU_REG) */
|
||||
uint32_t unused2 : 1; /*!< Unused */
|
||||
uint32_t sub_opcode : 2; /*!< Sub opcode (SUB_OPCODE_ALU_REG) */
|
||||
uint32_t opcode : 4; /*!< Opcode (OPCODE_ALU) */
|
||||
} alu_reg; /*!< Format of ALU instruction (both sources are registers) */
|
||||
|
||||
@ -180,12 +186,23 @@ union ulp_insn {
|
||||
uint32_t dreg : 2; /*!< Destination register */
|
||||
uint32_t sreg : 2; /*!< Register with operand A */
|
||||
uint32_t imm : 16; /*!< Immediate value of operand B */
|
||||
uint32_t unused : 1; /*!< Unused */
|
||||
uint32_t unused1: 1; /*!< Unused */
|
||||
uint32_t sel : 4; /*!< Operation to perform, one of ALU_SEL_xxx */
|
||||
uint32_t sub_opcode : 3; /*!< Sub opcode (SUB_OPCODE_ALU_IMM) */
|
||||
uint32_t unused2 : 1; /*!< Unused */
|
||||
uint32_t sub_opcode : 2; /*!< Sub opcode (SUB_OPCODE_ALU_IMM) */
|
||||
uint32_t opcode : 4; /*!< Opcode (OPCODE_ALU) */
|
||||
} alu_imm; /*!< Format of ALU instruction (one source is an immediate) */
|
||||
|
||||
struct {
|
||||
uint32_t unused1: 4; /*!< Unused */
|
||||
uint32_t imm : 8; /*!< Immediate value */
|
||||
uint32_t unused2: 9; /*!< Unused */
|
||||
uint32_t sel : 4; /*!< Operation to perform, one of ALU_SEL_xxx */
|
||||
uint32_t unused3 : 1; /*!< Unused */
|
||||
uint32_t sub_opcode : 2; /*!< Sub opcode (SUB_OPCODE_ALU_CNT) */
|
||||
uint32_t opcode : 4; /*!< Opcode (OPCODE_ALU) */
|
||||
} alu_cnt; /*!< Format of ALU instruction with stage count register and an immediate */
|
||||
|
||||
struct {
|
||||
uint32_t addr : 8; /*!< Address within either RTC_CNTL, RTC_IO, or SARADC */
|
||||
uint32_t periph_sel : 2; /*!< Select peripheral: RTC_CNTL (0), RTC_IO(1), SARADC(2) */
|
||||
@ -201,7 +218,7 @@ union ulp_insn {
|
||||
uint32_t unused : 8; /*!< Unused */
|
||||
uint32_t low : 5; /*!< Low bit */
|
||||
uint32_t high : 5; /*!< High bit */
|
||||
uint32_t opcode : 4; /*!< Opcode (OPCODE_WR_REG) */
|
||||
uint32_t opcode : 4; /*!< Opcode (OPCODE_RD_REG) */
|
||||
} rd_reg; /*!< Format of RD_REG instruction */
|
||||
|
||||
struct {
|
||||
@ -234,18 +251,11 @@ union ulp_insn {
|
||||
|
||||
struct {
|
||||
uint32_t wakeup : 1; /*!< Set to 1 to wake up chip */
|
||||
uint32_t unused : 24; /*!< Unused */
|
||||
uint32_t sub_opcode : 3; /*!< Sub opcode (SUB_OPCODE_WAKEUP) */
|
||||
uint32_t unused : 25; /*!< Unused */
|
||||
uint32_t sub_opcode : 2; /*!< Sub opcode (SUB_OPCODE_WAKEUP) */
|
||||
uint32_t opcode : 4; /*!< Opcode (OPCODE_END) */
|
||||
} end; /*!< Format of END instruction with wakeup */
|
||||
|
||||
struct {
|
||||
uint32_t cycle_sel : 4; /*!< Select which one of SARADC_ULP_CP_SLEEP_CYCx_REG to get the sleep duration from */
|
||||
uint32_t unused : 21; /*!< Unused */
|
||||
uint32_t sub_opcode : 3; /*!< Sub opcode (SUB_OPCODE_SLEEP) */
|
||||
uint32_t opcode : 4; /*!< Opcode (OPCODE_END) */
|
||||
} sleep; /*!< Format of END instruction with sleep */
|
||||
|
||||
struct {
|
||||
uint32_t label : 16; /*!< Label number */
|
||||
uint32_t unused : 8; /*!< Unused */
|
||||
@ -255,6 +265,7 @@ union ulp_insn {
|
||||
|
||||
};
|
||||
|
||||
_Static_assert(sizeof(ulp_insn_t) == 4, "ULP coprocessor instruction size should be 4 bytes");
|
||||
|
||||
/**
|
||||
* Delay (nop) for a given number of cycles
|
||||
@ -352,7 +363,7 @@ static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg)
|
||||
*
|
||||
* To disable the timer which start ULP program, use I_END()
|
||||
* instruction. I_END instruction clears the
|
||||
* RTC_CNTL_ULP_CP_SLP_TIMER_EN_S bit of RTC_CNTL_STATE0_REG
|
||||
* RTC_CNTL_ULP_CP_SLP_TIMER_EN_S bit of RTC_CNTL_ULP_CP_TIMER_REG
|
||||
* register, which controls the ULP timer.
|
||||
*/
|
||||
#define I_WAKE() { .end = { \
|
||||
@ -372,27 +383,7 @@ static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg)
|
||||
* the currently running program, use I_HALT().
|
||||
*/
|
||||
#define I_END() \
|
||||
I_WR_REG_BIT(RTC_CNTL_STATE0_REG, RTC_CNTL_ULP_CP_SLP_TIMER_EN_S, 0)
|
||||
/**
|
||||
* Select the time interval used to run ULP program.
|
||||
*
|
||||
* This instructions selects which of the SENS_SLEEP_CYCLES_Sx
|
||||
* registers' value is used by the ULP program timer.
|
||||
* When the ULP program stops at I_HALT instruction, ULP program
|
||||
* timer start counting. When the counter reaches the value of
|
||||
* the selected SENS_SLEEP_CYCLES_Sx register, ULP program
|
||||
* start running again from the start address (passed to the ulp_run
|
||||
* function).
|
||||
* There are 5 SENS_SLEEP_CYCLES_Sx registers, so 0 <= timer_idx < 5.
|
||||
*
|
||||
* By default, SENS_SLEEP_CYCLES_S0 register is used by the ULP
|
||||
* program timer.
|
||||
*/
|
||||
#define I_SLEEP_CYCLE_SEL(timer_idx) { .sleep = { \
|
||||
.cycle_sel = timer_idx, \
|
||||
.unused = 0, \
|
||||
.sub_opcode = SUB_OPCODE_SLEEP, \
|
||||
.opcode = OPCODE_END } }
|
||||
I_WR_REG_BIT(RTC_CNTL_ULP_CP_TIMER_REG, RTC_CNTL_ULP_CP_SLP_TIMER_EN_S, 0)
|
||||
|
||||
/**
|
||||
* Perform temperature sensor measurement and store it into reg_dest.
|
||||
@ -422,44 +413,247 @@ static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg)
|
||||
.opcode = OPCODE_ADC } }
|
||||
|
||||
/**
|
||||
* Store value from register reg_val into RTC memory.
|
||||
* Store lower half-word, upper half-word or full-word data from register reg_val into RTC memory address.
|
||||
*
|
||||
* The value is written to an offset calculated by adding value of
|
||||
* This instruction can be used to write data to discontinuous addresses in the RTC_SLOW_MEM.
|
||||
* The value is written to an offset calculated by adding the value of
|
||||
* reg_addr register and offset_ field (this offset is expressed in 32-bit words).
|
||||
* 32 bits written to RTC memory are built as follows:
|
||||
* - bits [31:21] hold the PC of current instruction, expressed in 32-bit words
|
||||
* - bits [20:16] = 5'b1
|
||||
* - bits [15:0] are assigned the contents of reg_val
|
||||
* The storage method is dictated by the wr_way and upper field settings as summarized in the following table:
|
||||
*
|
||||
* RTC_SLOW_MEM[addr + offset_] = { 5'b0, insn_PC[10:0], val[15:0] }
|
||||
* @verbatim
|
||||
* |--------|-------|----------------------------------------------------------------------------------------|----------------------------|
|
||||
* | wr_way | upper | data | operation |
|
||||
* |--------|-------|----------------------------------------------------------------------------------------|----------------------------|
|
||||
* | | | | Write full-word, including |
|
||||
* | 0 | X | RTC_SLOW_MEM[addr + offset_]{31:0} = {insn_PC[10:0], 3’b0, label_[1:0], reg_val[15:0]} | the PC and the data |
|
||||
* |--------|-------|----------------------------------------------------------------------------------------|----------------------------|
|
||||
* | | | | Store the data with label |
|
||||
* | 1 | 0 | RTC_SLOW_MEM[addr + offset_]{15:0} = {label_[1:0], reg_val[13:0]} | in the low half-word |
|
||||
* |--------|-------|----------------------------------------------------------------------------------------|----------------------------|
|
||||
* | | | | Store the data with label |
|
||||
* | 1 | 1 | RTC_SLOW_MEM[addr + offset_]{31:16} = {label_[1:0], reg_val[13:0]} | in the high half-word |
|
||||
* |--------|-------|----------------------------------------------------------------------------------------|----------------------------|
|
||||
* | | | | Store the data without |
|
||||
* | 3 | 0 | RTC_SLOW_MEM[addr + offset_]{15:0} = reg_val[15:0] | label in the low half-word |
|
||||
* |--------|-------|----------------------------------------------------------------------------------------|----------------------------|
|
||||
* | | | | Store the data without |
|
||||
* | 3 | 1 | RTC_SLOW_MEM[addr + offset_]{31:16} = reg_val[15:0] | label in the high half-word|
|
||||
* |--------|-------|----------------------------------------------------------------------------------------|----------------------------|
|
||||
* @endverbatim
|
||||
*
|
||||
* SUB_OPCODE_ST = manual_en:1, offset_set:0, wr_auto:0
|
||||
*/
|
||||
#define I_ST(reg_val, reg_addr, offset_) { .st = { \
|
||||
#define I_ST_MANUAL(reg_val, reg_addr, offset_, label_, upper_, wr_way_) { .st = { \
|
||||
.dreg = reg_val, \
|
||||
.sreg = reg_addr, \
|
||||
.label = label_, \
|
||||
.upper = upper_, \
|
||||
.wr_way = wr_way_, \
|
||||
.unused1 = 0, \
|
||||
.offset = offset_, \
|
||||
.unused2 = 0, \
|
||||
.sub_opcode = SUB_OPCODE_ST, \
|
||||
.opcode = OPCODE_ST } }
|
||||
|
||||
/**
|
||||
* Store value from register reg_val into RTC memory.
|
||||
*
|
||||
* I_ST() instruction provides backward compatibility for code written for esp32 to be run on esp32s2.
|
||||
* This instruction is equivalent to calling I_ST_MANUAL() instruction with label = 0, upper = 0 and wr_way = 3.
|
||||
*/
|
||||
#define I_ST(reg_val, reg_addr, offset_) I_ST_MANUAL(reg_val, reg_addr, offset_, 0, 0, 3)
|
||||
|
||||
/**
|
||||
* Load value from RTC memory into reg_dest register.
|
||||
* Store value from register reg_val to lower 16 bits of the RTC memory address.
|
||||
*
|
||||
* Loads 16 LSBs from RTC memory word given by the sum of value in reg_addr and
|
||||
* value of offset_.
|
||||
* This instruction is equivalent to calling I_ST_MANUAL() instruction with label = 0, upper = 0 and wr_way = 3.
|
||||
*/
|
||||
#define I_LD(reg_dest, reg_addr, offset_) { .ld = { \
|
||||
#define I_STL(reg_val, reg_addr, offset_) I_ST_MANUAL(reg_val, reg_addr, offset_, 0, 0, 3)
|
||||
|
||||
/**
|
||||
* Store value from register reg_val to upper 16 bits of the RTC memory address.
|
||||
*
|
||||
* This instruction is equivalent to calling I_ST_MANUAL() instruction with label = 0, upper = 1 and wr_way = 3.
|
||||
*/
|
||||
#define I_STH(reg_val, reg_addr, offset_) I_ST_MANUAL(reg_val, reg_addr, offset_, 0, 1, 3)
|
||||
|
||||
/**
|
||||
* Store value from register reg_val to full 32 bit word of the RTC memory address.
|
||||
*
|
||||
* This instruction is equivalent to calling I_ST_MANUAL() instruction with wr_way = 0.
|
||||
*/
|
||||
#define I_ST32(reg_val, reg_addr, offset_, label_) I_ST_MANUAL(reg_val, reg_addr, offset_, label_, 0, 0)
|
||||
|
||||
/**
|
||||
* Store value from register reg_val with label to lower 16 bits of RTC memory address.
|
||||
*
|
||||
* This instruction is equivalent to calling I_ST_MANUAL() instruction with label = label_, upper = 0 and wr_way = 1.
|
||||
*/
|
||||
#define I_STL_LABEL(reg_val, reg_addr, offset_, label_) I_ST_MANUAL(reg_val, reg_addr, offset_, label_, 0, 1)
|
||||
|
||||
/**
|
||||
* Store value from register reg_val with label to upper 16 bits of RTC memory address.
|
||||
*
|
||||
* This instruction is equivalent to calling I_ST_MANUAL() instruction with label = label_, upper = 1 and wr_way = 1.
|
||||
*/
|
||||
#define I_STH_LABEL(reg_val, reg_addr, offset_, label_) I_ST_MANUAL(reg_val, reg_addr, offset_, label_, 1, 1)
|
||||
|
||||
/**
|
||||
* Store lower half-word, upper half-word or full-word data from register reg_val into RTC memory address with auto-increment of the offset value.
|
||||
*
|
||||
* This instruction can be used to write data to continuous addresses in the RTC_SLOW_MEM.
|
||||
* The initial address must be set using the SUB_OPCODE_ST_OFFSET instruction before the auto store instruction is called.
|
||||
* The data written to the RTC memory address could be written to the full 32 bit word or to the lower half-word or the
|
||||
* upper half-word. The storage method is dictated by the wr_way field and the number of times the SUB_OPCODE_ST_AUTO instruction is called.
|
||||
* write_cnt indicates the later. The following table summarizes the storage method:
|
||||
*
|
||||
* @verbatim
|
||||
* |--------|-----------|----------------------------------------------------------------------------------------|----------------------------|
|
||||
* | wr_way | write_cnt | data | operation |
|
||||
* |--------|-----------|----------------------------------------------------------------------------------------|----------------------------|
|
||||
* | | | | Write full-word, including |
|
||||
* | 0 | X | RTC_SLOW_MEM[addr + offset_]{31:0} = {insn_PC[10:0], 3’b0, label_[1:0], reg_val[15:0]} | the PC and the data |
|
||||
* |--------|-----------|----------------------------------------------------------------------------------------|----------------------------|
|
||||
* | | | | Store the data with label |
|
||||
* | 1 | odd | RTC_SLOW_MEM[addr + offset_]{15:0} = {label_[1:0], reg_val[13:0]} | in the low half-word |
|
||||
* |--------|-----------|----------------------------------------------------------------------------------------|----------------------------|
|
||||
* | | | | Store the data with label |
|
||||
* | 1 | even | RTC_SLOW_MEM[addr + offset_]{31:16} = {label_[1:0], reg_val[13:0]} | in the high half-word |
|
||||
* |--------|-----------|----------------------------------------------------------------------------------------|----------------------------|
|
||||
* | | | | Store the data without |
|
||||
* | 3 | odd | RTC_SLOW_MEM[addr + offset_]{15:0} = reg_val[15:0] | label in the low half-word |
|
||||
* |--------|-----------|----------------------------------------------------------------------------------------|----------------------------|
|
||||
* | | | | Store the data without |
|
||||
* | 3 | even | RTC_SLOW_MEM[addr + offset_]{31:16} = reg_val[15:0] | label in the high half-word|
|
||||
* |--------|-----------|----------------------------------------------------------------------------------------|----------------------------|
|
||||
* @endverbatim
|
||||
*
|
||||
* The initial address offset is incremented after each store operation as follows:
|
||||
* - When a full-word is written, the offset is automatically incremented by 1 after each SUB_OPCODE_ST_AUTO operation.
|
||||
* - When a half-word is written (lower half-word first), the offset is automatically incremented by 1 after two
|
||||
* SUB_OPCODE_ST_AUTO operations.
|
||||
*
|
||||
* SUB_OPCODE_ST_AUTO = manual_en:0, offset_set:0, wr_auto:1
|
||||
*/
|
||||
#define I_ST_AUTO(reg_val, reg_addr, label_, wr_way_) { .st = { \
|
||||
.dreg = reg_addr, \
|
||||
.sreg = reg_val, \
|
||||
.label = label_, \
|
||||
.upper = 0, \
|
||||
.wr_way = wr_way_, \
|
||||
.unused1 = 0, \
|
||||
.offset = 0, \
|
||||
.unused2 = 0, \
|
||||
.sub_opcode = SUB_OPCODE_ST_AUTO, \
|
||||
.opcode = OPCODE_ST } }
|
||||
|
||||
/**
|
||||
* Set the initial address offset for auto-store operation
|
||||
*
|
||||
* This instruction sets the initial address of the RTC_SLOW_MEM to be used by the auto-store operation.
|
||||
* The offset is incremented automatically.
|
||||
* Refer I_ST_AUTO() for detailed explaination.
|
||||
*
|
||||
* SUB_OPCODE_ST_OFFSET = manual_en:0, offset_set:1, wr_auto:1
|
||||
*/
|
||||
#define I_STO(offset_) { .st = { \
|
||||
.dreg = 0, \
|
||||
.sreg = 0, \
|
||||
.label = 0, \
|
||||
.upper = 0, \
|
||||
.wr_way = 0, \
|
||||
.unused1 = 0, \
|
||||
.offset = offset_, \
|
||||
.unused2 = 0, \
|
||||
.sub_opcode = SUB_OPCODE_ST_OFFSET, \
|
||||
.opcode = OPCODE_ST } }
|
||||
|
||||
/**
|
||||
* Store value from register reg_val to 32 bit word of the RTC memory address.
|
||||
*
|
||||
* This instruction is equivalent to calling I_ST_AUTO() instruction with label = 0 and wr_way = 3.
|
||||
* The data in reg_val will be either written to the lower half-word or the upper half-word of the RTC memory address
|
||||
* depending on the count of the number of times the I_STI() instruction is called.
|
||||
* The initial offset is automatically incremented with I_STI() is called twice.
|
||||
* Refer I_ST_AUTO() for detailed explaination.
|
||||
*/
|
||||
#define I_STI(reg_val, reg_addr) I_ST_AUTO(reg_val, reg_addr, 0, 3)
|
||||
|
||||
/**
|
||||
* Store value from register reg_val with label to 32 bit word of the RTC memory address.
|
||||
*
|
||||
* This instruction is equivalent to calling I_ST_AUTO() instruction with label = label_ and wr_way = 1.
|
||||
* The data in reg_val will be either written to the lower half-word or the upper half-word of the RTC memory address
|
||||
* depending on the count of the number of times the I_STI_LABEL() instruction is called.
|
||||
* The initial offset is automatically incremented with I_STI_LABEL() is called twice.
|
||||
* Refer I_ST_AUTO() for detailed explaination.
|
||||
*/
|
||||
#define I_STI_LABEL(reg_val, reg_addr, label_) I_ST_AUTO(reg_val, reg_addr, label_, 1)
|
||||
|
||||
/**
|
||||
* Store value from register reg_val to full 32 bit word of the RTC memory address.
|
||||
*
|
||||
* This instruction is equivalent to calling I_ST_AUTO() instruction with label = label_ and wr_way = 0.
|
||||
* The data in reg_val will be written to the RTC memory address along with the label and the PC.
|
||||
* The initial offset is automatically incremented each time the I_STI32() instruction is called.
|
||||
* Refer I_ST_AUTO() for detailed explaination.
|
||||
*/
|
||||
#define I_STI32(reg_val, reg_addr, label_) I_ST_AUTO(reg_val, reg_addr, label_, 0)
|
||||
|
||||
/**
|
||||
* Load lower half-word, upper half-word or full-word data from RTC memory address into the register reg_dest.
|
||||
*
|
||||
* This instruction reads the lower half-word or upper half-word of the RTC memory address depending on the value
|
||||
* of rd_upper_. The following table summarizes the loading method:
|
||||
*
|
||||
* @verbatim
|
||||
* |----------|------------------------------------------------------|-------------------------|
|
||||
* | rd_upper | data | operation |
|
||||
* |----------|------------------------------------------------------|-------------------------|
|
||||
* | | | Read lower half-word of |
|
||||
* | 0 | reg_dest{15:0} = RTC_SLOW_MEM[addr + offset_]{31:16} | the memory |
|
||||
* |----------|------------------------------------------------------|-------------------------|
|
||||
* | | | Read upper half-word of |
|
||||
* | 1 | reg_dest{15:0} = RTC_SLOW_MEM[addr + offset_]{15:0} | the memory |
|
||||
* |----------|------------------------------------------------------|-------------------------|
|
||||
* @endverbatim
|
||||
*
|
||||
*/
|
||||
#define I_LD_MANUAL(reg_dest, reg_addr, offset_, rd_upper_) { .ld = { \
|
||||
.dreg = reg_dest, \
|
||||
.sreg = reg_addr, \
|
||||
.unused1 = 0, \
|
||||
.offset = offset_, \
|
||||
.unused2 = 0, \
|
||||
.rd_upper = rd_upper_, \
|
||||
.opcode = OPCODE_LD } }
|
||||
|
||||
/**
|
||||
* Load lower 16 bits value from RTC memory into reg_dest register.
|
||||
*
|
||||
* Loads 16 LSBs (rd_upper = 1) from RTC memory word given by the sum of value in reg_addr and
|
||||
* value of offset_.
|
||||
* I_LD() instruction provides backward compatibility for code written for esp32 to be run on esp32s2.
|
||||
*/
|
||||
#define I_LD(reg_dest, reg_addr, offset_) I_LD_MANUAL(reg_dest, reg_addr, offset_, 0)
|
||||
|
||||
/**
|
||||
* Branch relative if R0 less than immediate value.
|
||||
* Load lower 16 bits value from RTC memory into reg_dest register.
|
||||
*
|
||||
* I_LDL() instruction and I_LD() instruction can be used interchangably.
|
||||
*/
|
||||
#define I_LDL(reg_dest, reg_addr, offset_) I_LD(reg_dest, reg_addr, offset_)
|
||||
|
||||
/**
|
||||
* Load upper 16 bits value from RTC memory into reg_dest register.
|
||||
*
|
||||
* Loads 16 MSBs (rd_upper = 0) from RTC memory word given by the sum of value in reg_addr and
|
||||
* value of offset_.
|
||||
*/
|
||||
#define I_LDH(reg_dest, reg_addr, offset_) I_LD_MANUAL(reg_dest, reg_addr, offset_, 1)
|
||||
|
||||
/**
|
||||
* Branch relative if R0 register less than the immediate value.
|
||||
*
|
||||
* pc_offset is expressed in words, and can be from -127 to 127
|
||||
* imm_value is a 16-bit value to compare R0 against
|
||||
@ -473,14 +667,28 @@ static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg)
|
||||
.opcode = OPCODE_BRANCH } }
|
||||
|
||||
/**
|
||||
* Branch relative if R0 greater or equal than immediate value.
|
||||
* Branch relative if R0 register greater than the immediate value.
|
||||
*
|
||||
* pc_offset is expressed in words, and can be from -127 to 127
|
||||
* imm_value is a 16-bit value to compare R0 against
|
||||
*/
|
||||
#define I_BGE(pc_offset, imm_value) { .b = { \
|
||||
#define I_BG(pc_offset, imm_value) { .b = { \
|
||||
.imm = imm_value, \
|
||||
.cmp = B_CMP_GE, \
|
||||
.cmp = B_CMP_G, \
|
||||
.offset = abs(pc_offset), \
|
||||
.sign = (pc_offset >= 0) ? 0 : 1, \
|
||||
.sub_opcode = SUB_OPCODE_B, \
|
||||
.opcode = OPCODE_BRANCH } }
|
||||
|
||||
/**
|
||||
* Branch relative if R0 register is equal to the immediate value.
|
||||
*
|
||||
* pc_offset is expressed in words, and can be from -127 to 127
|
||||
* imm_value is a 16-bit value to compare R0 against
|
||||
*/
|
||||
#define I_BE(pc_offset, imm_value) { .b = { \
|
||||
.imm = imm_value, \
|
||||
.cmp = B_CMP_E, \
|
||||
.offset = abs(pc_offset), \
|
||||
.sign = (pc_offset >= 0) ? 0 : 1, \
|
||||
.sub_opcode = SUB_OPCODE_B, \
|
||||
@ -495,9 +703,10 @@ static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg)
|
||||
#define I_BXR(reg_pc) { .bx = { \
|
||||
.dreg = reg_pc, \
|
||||
.addr = 0, \
|
||||
.unused = 0, \
|
||||
.unused1 = 0, \
|
||||
.reg = 1, \
|
||||
.type = BX_JUMP_TYPE_DIRECT, \
|
||||
.unused2 = 0, \
|
||||
.sub_opcode = SUB_OPCODE_BX, \
|
||||
.opcode = OPCODE_BRANCH } }
|
||||
|
||||
@ -509,9 +718,10 @@ static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg)
|
||||
#define I_BXI(imm_pc) { .bx = { \
|
||||
.dreg = 0, \
|
||||
.addr = imm_pc, \
|
||||
.unused = 0, \
|
||||
.unused1 = 0, \
|
||||
.reg = 0, \
|
||||
.type = BX_JUMP_TYPE_DIRECT, \
|
||||
.unused2 = 0, \
|
||||
.sub_opcode = SUB_OPCODE_BX, \
|
||||
.opcode = OPCODE_BRANCH } }
|
||||
|
||||
@ -524,9 +734,10 @@ static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg)
|
||||
#define I_BXZR(reg_pc) { .bx = { \
|
||||
.dreg = reg_pc, \
|
||||
.addr = 0, \
|
||||
.unused = 0, \
|
||||
.unused1 = 0, \
|
||||
.reg = 1, \
|
||||
.type = BX_JUMP_TYPE_ZERO, \
|
||||
.unused2 = 0, \
|
||||
.sub_opcode = SUB_OPCODE_BX, \
|
||||
.opcode = OPCODE_BRANCH } }
|
||||
|
||||
@ -538,9 +749,10 @@ static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg)
|
||||
#define I_BXZI(imm_pc) { .bx = { \
|
||||
.dreg = 0, \
|
||||
.addr = imm_pc, \
|
||||
.unused = 0, \
|
||||
.unused1 = 0, \
|
||||
.reg = 0, \
|
||||
.type = BX_JUMP_TYPE_ZERO, \
|
||||
.unused2 = 0, \
|
||||
.sub_opcode = SUB_OPCODE_BX, \
|
||||
.opcode = OPCODE_BRANCH } }
|
||||
|
||||
@ -553,9 +765,10 @@ static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg)
|
||||
#define I_BXFR(reg_pc) { .bx = { \
|
||||
.dreg = reg_pc, \
|
||||
.addr = 0, \
|
||||
.unused = 0, \
|
||||
.unused1 = 0, \
|
||||
.reg = 1, \
|
||||
.type = BX_JUMP_TYPE_OVF, \
|
||||
.unused2 = 0, \
|
||||
.sub_opcode = SUB_OPCODE_BX, \
|
||||
.opcode = OPCODE_BRANCH } }
|
||||
|
||||
@ -567,12 +780,54 @@ static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg)
|
||||
#define I_BXFI(imm_pc) { .bx = { \
|
||||
.dreg = 0, \
|
||||
.addr = imm_pc, \
|
||||
.unused = 0, \
|
||||
.unused1 = 0, \
|
||||
.reg = 0, \
|
||||
.type = BX_JUMP_TYPE_OVF, \
|
||||
.unused2 = 0, \
|
||||
.sub_opcode = SUB_OPCODE_BX, \
|
||||
.opcode = OPCODE_BRANCH } }
|
||||
|
||||
/**
|
||||
* Branch relative if stage_cnt is less than or equal to the immediate value.
|
||||
*
|
||||
* pc_offset is expressed in words, and can be from -127 to 127
|
||||
* imm_value is a 16-bit value to compare R0 against
|
||||
*/
|
||||
#define I_BSLE(pc_offset, imm_value) { .b = { \
|
||||
.imm = imm_value, \
|
||||
.cmp = BS_CMP_LE, \
|
||||
.offset = abs(pc_offset), \
|
||||
.sign = (pc_offset >= 0) ? 0 : 1, \
|
||||
.sub_opcode = SUB_OPCODE_BS, \
|
||||
.opcode = OPCODE_BRANCH } }
|
||||
|
||||
/**
|
||||
* Branch relative if stage_cnt register is greater than or equal to the immediate value.
|
||||
*
|
||||
* pc_offset is expressed in words, and can be from -127 to 127
|
||||
* imm_value is a 16-bit value to compare R0 against
|
||||
*/
|
||||
#define I_BSGE(pc_offset, imm_value) { .b = { \
|
||||
.imm = imm_value, \
|
||||
.cmp = BS_CMP_GE, \
|
||||
.offset = abs(pc_offset), \
|
||||
.sign = (pc_offset >= 0) ? 0 : 1, \
|
||||
.sub_opcode = SUB_OPCODE_BS, \
|
||||
.opcode = OPCODE_BRANCH } }
|
||||
|
||||
/**
|
||||
* Branch relative if stage_cnt register is less than the immediate value.
|
||||
*
|
||||
* pc_offset is expressed in words, and can be from -127 to 127
|
||||
* imm_value is a 16-bit value to compare R0 against
|
||||
*/
|
||||
#define I_BSL(pc_offset, imm_value) { .b = { \
|
||||
.imm = imm_value, \
|
||||
.cmp = BS_CMP_L, \
|
||||
.offset = abs(pc_offset), \
|
||||
.sign = (pc_offset >= 0) ? 0 : 1, \
|
||||
.sub_opcode = SUB_OPCODE_BS, \
|
||||
.opcode = OPCODE_BRANCH } }
|
||||
|
||||
/**
|
||||
* Addition: dest = src1 + src2
|
||||
@ -581,8 +836,9 @@ static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg)
|
||||
.dreg = reg_dest, \
|
||||
.sreg = reg_src1, \
|
||||
.treg = reg_src2, \
|
||||
.unused = 0, \
|
||||
.unused1 = 0, \
|
||||
.sel = ALU_SEL_ADD, \
|
||||
.unused2 = 0, \
|
||||
.sub_opcode = SUB_OPCODE_ALU_REG, \
|
||||
.opcode = OPCODE_ALU } }
|
||||
|
||||
@ -593,8 +849,9 @@ static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg)
|
||||
.dreg = reg_dest, \
|
||||
.sreg = reg_src1, \
|
||||
.treg = reg_src2, \
|
||||
.unused = 0, \
|
||||
.unused1 = 0, \
|
||||
.sel = ALU_SEL_SUB, \
|
||||
.unused2 = 0, \
|
||||
.sub_opcode = SUB_OPCODE_ALU_REG, \
|
||||
.opcode = OPCODE_ALU } }
|
||||
|
||||
@ -605,8 +862,9 @@ static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg)
|
||||
.dreg = reg_dest, \
|
||||
.sreg = reg_src1, \
|
||||
.treg = reg_src2, \
|
||||
.unused = 0, \
|
||||
.unused1 = 0, \
|
||||
.sel = ALU_SEL_AND, \
|
||||
.unused2 = 0, \
|
||||
.sub_opcode = SUB_OPCODE_ALU_REG, \
|
||||
.opcode = OPCODE_ALU } }
|
||||
|
||||
@ -617,8 +875,9 @@ static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg)
|
||||
.dreg = reg_dest, \
|
||||
.sreg = reg_src1, \
|
||||
.treg = reg_src2, \
|
||||
.unused = 0, \
|
||||
.unused1 = 0, \
|
||||
.sel = ALU_SEL_OR, \
|
||||
.unused2 = 0, \
|
||||
.sub_opcode = SUB_OPCODE_ALU_REG, \
|
||||
.opcode = OPCODE_ALU } }
|
||||
|
||||
@ -629,8 +888,9 @@ static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg)
|
||||
.dreg = reg_dest, \
|
||||
.sreg = reg_src, \
|
||||
.treg = 0, \
|
||||
.unused = 0, \
|
||||
.unused1 = 0, \
|
||||
.sel = ALU_SEL_MOV, \
|
||||
.unused2 = 0, \
|
||||
.sub_opcode = SUB_OPCODE_ALU_REG, \
|
||||
.opcode = OPCODE_ALU } }
|
||||
|
||||
@ -641,8 +901,9 @@ static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg)
|
||||
.dreg = reg_dest, \
|
||||
.sreg = reg_src, \
|
||||
.treg = reg_shift, \
|
||||
.unused = 0, \
|
||||
.unused1 = 0, \
|
||||
.sel = ALU_SEL_LSH, \
|
||||
.unused2 = 0, \
|
||||
.sub_opcode = SUB_OPCODE_ALU_REG, \
|
||||
.opcode = OPCODE_ALU } }
|
||||
|
||||
@ -654,8 +915,9 @@ static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg)
|
||||
.dreg = reg_dest, \
|
||||
.sreg = reg_src, \
|
||||
.treg = reg_shift, \
|
||||
.unused = 0, \
|
||||
.unused1 = 0, \
|
||||
.sel = ALU_SEL_RSH, \
|
||||
.unused2 = 0, \
|
||||
.sub_opcode = SUB_OPCODE_ALU_REG, \
|
||||
.opcode = OPCODE_ALU } }
|
||||
|
||||
@ -666,8 +928,9 @@ static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg)
|
||||
.dreg = reg_dest, \
|
||||
.sreg = reg_src, \
|
||||
.imm = imm_, \
|
||||
.unused = 0, \
|
||||
.unused1 = 0, \
|
||||
.sel = ALU_SEL_ADD, \
|
||||
.unused2 = 0, \
|
||||
.sub_opcode = SUB_OPCODE_ALU_IMM, \
|
||||
.opcode = OPCODE_ALU } }
|
||||
|
||||
@ -679,8 +942,9 @@ static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg)
|
||||
.dreg = reg_dest, \
|
||||
.sreg = reg_src, \
|
||||
.imm = imm_, \
|
||||
.unused = 0, \
|
||||
.unused1 = 0, \
|
||||
.sel = ALU_SEL_SUB, \
|
||||
.unused2 = 0, \
|
||||
.sub_opcode = SUB_OPCODE_ALU_IMM, \
|
||||
.opcode = OPCODE_ALU } }
|
||||
|
||||
@ -691,8 +955,9 @@ static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg)
|
||||
.dreg = reg_dest, \
|
||||
.sreg = reg_src, \
|
||||
.imm = imm_, \
|
||||
.unused = 0, \
|
||||
.unused1 = 0, \
|
||||
.sel = ALU_SEL_AND, \
|
||||
.unused2 = 0, \
|
||||
.sub_opcode = SUB_OPCODE_ALU_IMM, \
|
||||
.opcode = OPCODE_ALU } }
|
||||
|
||||
@ -703,8 +968,9 @@ static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg)
|
||||
.dreg = reg_dest, \
|
||||
.sreg = reg_src, \
|
||||
.imm = imm_, \
|
||||
.unused = 0, \
|
||||
.unused1 = 0, \
|
||||
.sel = ALU_SEL_OR, \
|
||||
.unused2 = 0, \
|
||||
.sub_opcode = SUB_OPCODE_ALU_IMM, \
|
||||
.opcode = OPCODE_ALU } }
|
||||
|
||||
@ -715,8 +981,9 @@ static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg)
|
||||
.dreg = reg_dest, \
|
||||
.sreg = 0, \
|
||||
.imm = imm_, \
|
||||
.unused = 0, \
|
||||
.unused1 = 0, \
|
||||
.sel = ALU_SEL_MOV, \
|
||||
.unused2 = 0, \
|
||||
.sub_opcode = SUB_OPCODE_ALU_IMM, \
|
||||
.opcode = OPCODE_ALU } }
|
||||
|
||||
@ -727,8 +994,9 @@ static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg)
|
||||
.dreg = reg_dest, \
|
||||
.sreg = reg_src, \
|
||||
.imm = imm_, \
|
||||
.unused = 0, \
|
||||
.unused1 = 0, \
|
||||
.sel = ALU_SEL_LSH, \
|
||||
.unused2 = 0, \
|
||||
.sub_opcode = SUB_OPCODE_ALU_IMM, \
|
||||
.opcode = OPCODE_ALU } }
|
||||
|
||||
@ -740,11 +1008,48 @@ static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg)
|
||||
.dreg = reg_dest, \
|
||||
.sreg = reg_src, \
|
||||
.imm = imm_, \
|
||||
.unused = 0, \
|
||||
.unused1 = 0, \
|
||||
.sel = ALU_SEL_RSH, \
|
||||
.unused2 = 0, \
|
||||
.sub_opcode = SUB_OPCODE_ALU_IMM, \
|
||||
.opcode = OPCODE_ALU } }
|
||||
|
||||
/**
|
||||
* Increment stage_cnt register by an immediate: stage_cnt = stage_cnt + imm
|
||||
*/
|
||||
#define I_STAGE_INC(reg_dest, reg_src, imm_) { .alu_cnt = { \
|
||||
.unused1 = 0, \
|
||||
.imm = imm_, \
|
||||
.unused2 = 0, \
|
||||
.sel = ALU_SEL_STAGE_INC, \
|
||||
.unused3 = 0, \
|
||||
.sub_opcode = SUB_OPCODE_ALU_CNT, \
|
||||
.opcode = OPCODE_ALU } }
|
||||
|
||||
/**
|
||||
* Decrement stage_cnt register by an immediate: stage_cnt = stage_cnt - imm
|
||||
*/
|
||||
#define I_STAGE_DEC(reg_dest, reg_src, imm_) { .alu_cnt = { \
|
||||
.unused1 = 0, \
|
||||
.imm = imm_, \
|
||||
.unused2 = 0, \
|
||||
.sel = ALU_SEL_STAGE_DEC, \
|
||||
.unused3 = 0, \
|
||||
.sub_opcode = SUB_OPCODE_ALU_CNT, \
|
||||
.opcode = OPCODE_ALU } }
|
||||
|
||||
/**
|
||||
* Reset stage_cnt register by an immediate: stage_cnt = 0
|
||||
*/
|
||||
#define I_STAGE_RST(reg_dest, reg_src, imm_) { .alu_cnt = { \
|
||||
.unused1 = 0, \
|
||||
.imm = imm_, \
|
||||
.unused2 = 0, \
|
||||
.sel = ALU_SEL_STAGE_RST, \
|
||||
.unused3 = 0, \
|
||||
.sub_opcode = SUB_OPCODE_ALU_CNT, \
|
||||
.opcode = OPCODE_ALU } }
|
||||
|
||||
/**
|
||||
* Define a label with number label_num.
|
||||
*
|
||||
@ -781,16 +1086,28 @@ static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg)
|
||||
I_BL(0, imm_value)
|
||||
|
||||
/**
|
||||
* Macro: branch to label label_num if R0 is greater or equal than immediate value
|
||||
* Macro: branch to label label_num if R0 is greater than immediate value
|
||||
*
|
||||
* This macro generates two ulp_insn_t values separated by a comma, and should
|
||||
* be used when defining contents of ulp_insn_t arrays. First value is not a
|
||||
* real instruction; it is a token which is removed by ulp_process_macros_and_load
|
||||
* function.
|
||||
*/
|
||||
#define M_BGE(label_num, imm_value) \
|
||||
#define M_BG(label_num, imm_value) \
|
||||
M_BRANCH(label_num), \
|
||||
I_BGE(0, imm_value)
|
||||
I_BG(0, imm_value)
|
||||
|
||||
/**
|
||||
* Macro: branch to label label_num if R0 equal to the immediate value
|
||||
*
|
||||
* This macro generates two ulp_insn_t values separated by a comma, and should
|
||||
* be used when defining contents of ulp_insn_t arrays. First value is not a
|
||||
* real instruction; it is a token which is removed by ulp_process_macros_and_load
|
||||
* function.
|
||||
*/
|
||||
#define M_BE(label_num, imm_value) \
|
||||
M_BRANCH(label_num), \
|
||||
I_BE(0, imm_value)
|
||||
|
||||
/**
|
||||
* Macro: unconditional branch to label
|
||||
@ -828,8 +1145,6 @@ static inline uint32_t SOC_REG_TO_ULP_PERIPH_SEL(uint32_t reg)
|
||||
M_BRANCH(label_num), \
|
||||
I_BXFI(0)
|
||||
|
||||
|
||||
|
||||
#define RTC_SLOW_MEM ((uint32_t*) 0x50000000) /*!< RTC slow memory, 8k size */
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -103,6 +103,22 @@ esp_err_t ulp_run(uint32_t entry_point);
|
||||
*/
|
||||
esp_err_t ulp_set_wakeup_period(size_t period_index, uint32_t period_us);
|
||||
|
||||
/**
|
||||
* @brief Stop the ULP timer
|
||||
*
|
||||
* @note This will stop the ULP from waking up if halted, but will not abort any program
|
||||
* currently executing on the ULP.
|
||||
*/
|
||||
void ulp_timer_stop(void);
|
||||
|
||||
/**
|
||||
* @brief Resume the ULP timer
|
||||
*
|
||||
* @note This will resume an already configured timer, but does no other configuration
|
||||
*
|
||||
*/
|
||||
void ulp_timer_resume(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -1,12 +1,14 @@
|
||||
if(IDF_TARGET STREQUAL "esp32")
|
||||
set(src_dirs ${IDF_TARGET})
|
||||
set(ulp_sources "ulp/test_jumps_esp32.S")
|
||||
set(src_dirs "ulp_fsm")
|
||||
set(ulp_sources "ulp_fsm/ulp/test_jumps.S")
|
||||
elseif(IDF_TARGET STREQUAL "esp32s2" OR IDF_TARGET STREQUAL "esp32s3")
|
||||
if(CONFIG_ESP32S2_ULP_COPROC_RISCV STREQUAL "y" OR CONFIG_ESP32S3_ULP_COPROC_RISCV STREQUAL "y")
|
||||
if(CONFIG_ESP32S2_ULP_COPROC_RISCV OR CONFIG_ESP32S3_ULP_COPROC_RISCV)
|
||||
set(src_dirs "ulp_riscv")
|
||||
set(ulp_sources "ulp_riscv/ulp/test_main.c")
|
||||
else()
|
||||
set(src_dirs "ulp_fsm")
|
||||
set(ulp_sources "ulp_fsm/ulp/test_jumps.S")
|
||||
endif()
|
||||
#TODO: Add ULP-FSM Test case for esp32s2 and esp32s3
|
||||
endif()
|
||||
|
||||
idf_component_register(SRC_DIRS ${src_dirs}
|
||||
|
@ -1,460 +0,0 @@
|
||||
// Copyright 2010-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
#include <freertos/semphr.h>
|
||||
|
||||
#include <unity.h>
|
||||
#include "esp_attr.h"
|
||||
#include "esp_err.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_sleep.h"
|
||||
|
||||
#include "esp32/ulp.h"
|
||||
|
||||
#include "soc/soc.h"
|
||||
#include "soc/rtc.h"
|
||||
#include "soc/rtc_cntl_reg.h"
|
||||
#include "soc/sens_reg.h"
|
||||
#include "driver/rtc_io.h"
|
||||
|
||||
#include "sdkconfig.h"
|
||||
#include "esp_rom_sys.h"
|
||||
|
||||
static void hexdump(const uint32_t* src, size_t count) {
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
printf("%08x ", *src);
|
||||
++src;
|
||||
if ((i + 1) % 4 == 0) {
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("ulp add test", "[ulp]")
|
||||
{
|
||||
memset(RTC_SLOW_MEM, 0, CONFIG_ESP32_ULP_COPROC_RESERVE_MEM);
|
||||
const ulp_insn_t program[] = {
|
||||
I_MOVI(R3, 16),
|
||||
I_LD(R0, R3, 0),
|
||||
I_LD(R1, R3, 1),
|
||||
I_ADDR(R2, R0, R1),
|
||||
I_ST(R2, R3, 2),
|
||||
I_HALT()
|
||||
};
|
||||
RTC_SLOW_MEM[16] = 10;
|
||||
RTC_SLOW_MEM[17] = 11;
|
||||
size_t size = sizeof(program)/sizeof(ulp_insn_t);
|
||||
TEST_ASSERT_EQUAL(ESP_OK, ulp_process_macros_and_load(0, program, &size));
|
||||
TEST_ASSERT_EQUAL(ESP_OK, ulp_run(0));
|
||||
esp_rom_delay_us(1000);
|
||||
hexdump(RTC_SLOW_MEM, CONFIG_ESP32_ULP_COPROC_RESERVE_MEM / 4);
|
||||
TEST_ASSERT_EQUAL(10 + 11, RTC_SLOW_MEM[18] & 0xffff);
|
||||
}
|
||||
|
||||
TEST_CASE("ulp branch test", "[ulp]")
|
||||
{
|
||||
assert(CONFIG_ESP32_ULP_COPROC_RESERVE_MEM >= 260 && "this test needs ESP32_ULP_COPROC_RESERVE_MEM option set in menuconfig");
|
||||
memset(RTC_SLOW_MEM, 0, CONFIG_ESP32_ULP_COPROC_RESERVE_MEM);
|
||||
const ulp_insn_t program[] = {
|
||||
I_MOVI(R0, 34), // r0 = dst
|
||||
M_LABEL(1),
|
||||
I_MOVI(R1, 32),
|
||||
I_LD(R1, R1, 0), // r1 = mem[33]
|
||||
I_MOVI(R2, 33),
|
||||
I_LD(R2, R2, 0), // r2 = mem[34]
|
||||
I_SUBR(R3, R1, R2), // r3 = r1 - r2
|
||||
I_ST(R3, R0, 0), // dst[0] = r3
|
||||
I_ADDI(R0, R0, 1),
|
||||
M_BL(1, 64),
|
||||
I_HALT(),
|
||||
};
|
||||
RTC_SLOW_MEM[32] = 42;
|
||||
RTC_SLOW_MEM[33] = 18;
|
||||
hexdump(RTC_SLOW_MEM, CONFIG_ESP32_ULP_COPROC_RESERVE_MEM / 4);
|
||||
size_t size = sizeof(program)/sizeof(ulp_insn_t);
|
||||
ulp_process_macros_and_load(0, program, &size);
|
||||
ulp_run(0);
|
||||
printf("\n\n");
|
||||
hexdump(RTC_SLOW_MEM, CONFIG_ESP32_ULP_COPROC_RESERVE_MEM / 4);
|
||||
for (int i = 34; i < 64; ++i) {
|
||||
TEST_ASSERT_EQUAL(42 - 18, RTC_SLOW_MEM[i] & 0xffff);
|
||||
}
|
||||
TEST_ASSERT_EQUAL(0, RTC_SLOW_MEM[64]);
|
||||
}
|
||||
|
||||
TEST_CASE("ulp wakeup test", "[ulp][ignore]")
|
||||
{
|
||||
assert(CONFIG_ESP32_ULP_COPROC_RESERVE_MEM >= 260 && "this test needs ESP32_ULP_COPROC_RESERVE_MEM option set in menuconfig");
|
||||
memset(RTC_SLOW_MEM, 0, CONFIG_ESP32_ULP_COPROC_RESERVE_MEM);
|
||||
const ulp_insn_t program[] = {
|
||||
I_MOVI(R1, 1024),
|
||||
M_LABEL(1),
|
||||
I_DELAY(32000),
|
||||
I_SUBI(R1, R1, 1),
|
||||
M_BXZ(3),
|
||||
I_RSHI(R3, R1, 5), // R3 = R1 / 32
|
||||
I_ST(R1, R3, 16),
|
||||
M_BX(1),
|
||||
M_LABEL(3),
|
||||
I_MOVI(R2, 42),
|
||||
I_MOVI(R3, 15),
|
||||
I_ST(R2, R3, 0),
|
||||
I_WAKE(),
|
||||
I_END(),
|
||||
I_HALT()
|
||||
};
|
||||
size_t size = sizeof(program)/sizeof(ulp_insn_t);
|
||||
ulp_process_macros_and_load(0, program, &size);
|
||||
ulp_run(0);
|
||||
esp_sleep_enable_ulp_wakeup();
|
||||
esp_deep_sleep_start();
|
||||
}
|
||||
|
||||
TEST_CASE("ulp can write and read peripheral registers", "[ulp]")
|
||||
{
|
||||
assert(CONFIG_ESP32_ULP_COPROC_RESERVE_MEM >= 260 && "this test needs ESP32_ULP_COPROC_RESERVE_MEM option set in menuconfig");
|
||||
CLEAR_PERI_REG_MASK(RTC_CNTL_STATE0_REG, RTC_CNTL_ULP_CP_SLP_TIMER_EN);
|
||||
memset(RTC_SLOW_MEM, 0, CONFIG_ESP32_ULP_COPROC_RESERVE_MEM);
|
||||
REG_WRITE(RTC_CNTL_STORE1_REG, 0x89abcdef);
|
||||
|
||||
const ulp_insn_t program[] = {
|
||||
I_MOVI(R1, 64),
|
||||
I_RD_REG(RTC_CNTL_STORE1_REG, 0, 15),
|
||||
I_ST(R0, R1, 0),
|
||||
I_RD_REG(RTC_CNTL_STORE1_REG, 4, 11),
|
||||
I_ST(R0, R1, 1),
|
||||
I_RD_REG(RTC_CNTL_STORE1_REG, 16, 31),
|
||||
I_ST(R0, R1, 2),
|
||||
I_RD_REG(RTC_CNTL_STORE1_REG, 20, 27),
|
||||
I_ST(R0, R1, 3),
|
||||
I_WR_REG(RTC_CNTL_STORE0_REG, 0, 7, 0x89),
|
||||
I_WR_REG(RTC_CNTL_STORE0_REG, 8, 15, 0xab),
|
||||
I_WR_REG(RTC_CNTL_STORE0_REG, 16, 23, 0xcd),
|
||||
I_WR_REG(RTC_CNTL_STORE0_REG, 24, 31, 0xef),
|
||||
I_LD(R0, R1, 4),
|
||||
I_ADDI(R0, R0, 1),
|
||||
I_ST(R0, R1, 4),
|
||||
I_END(),
|
||||
I_HALT()
|
||||
};
|
||||
size_t size = sizeof(program)/sizeof(ulp_insn_t);
|
||||
TEST_ESP_OK(ulp_process_macros_and_load(0, program, &size));
|
||||
TEST_ESP_OK(ulp_run(0));
|
||||
vTaskDelay(100/portTICK_PERIOD_MS);
|
||||
|
||||
TEST_ASSERT_EQUAL_HEX32(0xefcdab89, REG_READ(RTC_CNTL_STORE0_REG));
|
||||
TEST_ASSERT_EQUAL_HEX16(0xcdef, RTC_SLOW_MEM[64] & 0xffff);
|
||||
TEST_ASSERT_EQUAL_HEX16(0xde, RTC_SLOW_MEM[65] & 0xffff);
|
||||
TEST_ASSERT_EQUAL_HEX16(0x89ab, RTC_SLOW_MEM[66] & 0xffff);
|
||||
TEST_ASSERT_EQUAL_HEX16(0x9a, RTC_SLOW_MEM[67] & 0xffff);
|
||||
TEST_ASSERT_EQUAL_HEX32(1 | (15 << 21) | (1 << 16), RTC_SLOW_MEM[68]);
|
||||
}
|
||||
|
||||
TEST_CASE("ULP I_WR_REG instruction test", "[ulp]")
|
||||
{
|
||||
assert(CONFIG_ESP32_ULP_COPROC_RESERVE_MEM >= 260 && "this test needs ESP32_ULP_COPROC_RESERVE_MEM option set in menuconfig");
|
||||
memset(RTC_SLOW_MEM, 0, CONFIG_ESP32_ULP_COPROC_RESERVE_MEM);
|
||||
typedef struct {
|
||||
int low;
|
||||
int width;
|
||||
} wr_reg_test_item_t;
|
||||
|
||||
const wr_reg_test_item_t test_items[] = {
|
||||
{0, 1}, {0, 2}, {0, 3}, {0, 4}, {0, 5}, {0, 6}, {0, 7}, {0, 8},
|
||||
{3, 1}, {3, 2}, {3, 3}, {3, 4}, {3, 5}, {3, 6}, {3, 7}, {3, 8},
|
||||
{15, 1}, {15, 2}, {15, 3}, {15, 4}, {15, 5}, {15, 6}, {15, 7}, {15, 8},
|
||||
{16, 1}, {16, 2}, {16, 3}, {16, 4}, {16, 5}, {16, 6}, {16, 7}, {16, 8},
|
||||
{18, 1}, {18, 2}, {18, 3}, {18, 4}, {18, 5}, {18, 6}, {18, 7}, {18, 8},
|
||||
{24, 1}, {24, 2}, {24, 3}, {24, 4}, {24, 5}, {24, 6}, {24, 7}, {24, 8},
|
||||
};
|
||||
|
||||
const size_t test_items_count =
|
||||
sizeof(test_items)/sizeof(test_items[0]);
|
||||
for (size_t i = 0; i < test_items_count; ++i) {
|
||||
const uint32_t mask = (uint32_t) (((1ULL << test_items[i].width) - 1) << test_items[i].low);
|
||||
const uint32_t not_mask = ~mask;
|
||||
printf("#%2d: low: %2d width: %2d mask: %08x expected: %08x ", i,
|
||||
test_items[i].low, test_items[i].width,
|
||||
mask, not_mask);
|
||||
|
||||
REG_WRITE(RTC_CNTL_STORE0_REG, 0xffffffff);
|
||||
REG_WRITE(RTC_CNTL_STORE1_REG, 0x00000000);
|
||||
const ulp_insn_t program[] = {
|
||||
I_WR_REG(RTC_CNTL_STORE0_REG,
|
||||
test_items[i].low,
|
||||
test_items[i].low + test_items[i].width - 1,
|
||||
0),
|
||||
I_WR_REG(RTC_CNTL_STORE1_REG,
|
||||
test_items[i].low,
|
||||
test_items[i].low + test_items[i].width - 1,
|
||||
0xff & ((1 << test_items[i].width) - 1)),
|
||||
I_END(),
|
||||
I_HALT()
|
||||
};
|
||||
size_t size = sizeof(program)/sizeof(ulp_insn_t);
|
||||
ulp_process_macros_and_load(0, program, &size);
|
||||
ulp_run(0);
|
||||
vTaskDelay(10/portTICK_PERIOD_MS);
|
||||
uint32_t clear = REG_READ(RTC_CNTL_STORE0_REG);
|
||||
uint32_t set = REG_READ(RTC_CNTL_STORE1_REG);
|
||||
printf("clear: %08x set: %08x\n", clear, set);
|
||||
TEST_ASSERT_EQUAL_HEX32(not_mask, clear);
|
||||
TEST_ASSERT_EQUAL_HEX32(mask, set);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("ulp controls RTC_IO", "[ulp][ignore]")
|
||||
{
|
||||
assert(CONFIG_ESP32_ULP_COPROC_RESERVE_MEM >= 260 && "this test needs ESP32_ULP_COPROC_RESERVE_MEM option set in menuconfig");
|
||||
memset(RTC_SLOW_MEM, 0, CONFIG_ESP32_ULP_COPROC_RESERVE_MEM);
|
||||
const ulp_insn_t program[] = {
|
||||
I_MOVI(R0, 0), // R0 is LED state
|
||||
I_MOVI(R2, 16), // loop R2 from 16 down to 0
|
||||
M_LABEL(4),
|
||||
I_SUBI(R2, R2, 1),
|
||||
M_BXZ(6),
|
||||
I_ADDI(R0, R0, 1), // R0 = (R0 + 1) % 2
|
||||
I_ANDI(R0, R0, 0x1),
|
||||
M_BL(0, 1), // if R0 < 1 goto 0
|
||||
M_LABEL(1),
|
||||
I_WR_REG(RTC_GPIO_OUT_REG, 26, 27, 1), // RTC_GPIO12 = 1
|
||||
M_BX(2), // goto 2
|
||||
M_LABEL(0), // 0:
|
||||
I_WR_REG(RTC_GPIO_OUT_REG, 26, 27, 0), // RTC_GPIO12 = 0
|
||||
M_LABEL(2), // 2:
|
||||
I_MOVI(R1, 100), // loop R1 from 100 down to 0
|
||||
M_LABEL(3),
|
||||
I_SUBI(R1, R1, 1),
|
||||
M_BXZ(5),
|
||||
I_DELAY(32000), // delay for a while
|
||||
M_BX(3),
|
||||
M_LABEL(5),
|
||||
M_BX(4),
|
||||
M_LABEL(6),
|
||||
I_WAKE(), // wake up the SoC
|
||||
I_END(), // stop ULP program timer
|
||||
I_HALT()
|
||||
};
|
||||
const gpio_num_t led_gpios[] = {
|
||||
GPIO_NUM_2,
|
||||
GPIO_NUM_0,
|
||||
GPIO_NUM_4
|
||||
};
|
||||
for (size_t i = 0; i < sizeof(led_gpios)/sizeof(led_gpios[0]); ++i) {
|
||||
rtc_gpio_init(led_gpios[i]);
|
||||
rtc_gpio_set_direction(led_gpios[i], RTC_GPIO_MODE_OUTPUT_ONLY);
|
||||
rtc_gpio_set_level(led_gpios[i], 0);
|
||||
}
|
||||
size_t size = sizeof(program)/sizeof(ulp_insn_t);
|
||||
ulp_process_macros_and_load(0, program, &size);
|
||||
ulp_run(0);
|
||||
esp_sleep_enable_ulp_wakeup();
|
||||
esp_deep_sleep_start();
|
||||
}
|
||||
|
||||
TEST_CASE("ulp power consumption in deep sleep", "[ulp][ignore]")
|
||||
{
|
||||
assert(CONFIG_ESP32_ULP_COPROC_RESERVE_MEM >= 4 && "this test needs ESP32_ULP_COPROC_RESERVE_MEM option set in menuconfig");
|
||||
ulp_insn_t insn = I_HALT();
|
||||
memcpy(&RTC_SLOW_MEM[0], &insn, sizeof(insn));
|
||||
|
||||
REG_WRITE(SENS_ULP_CP_SLEEP_CYC0_REG, 0x8000);
|
||||
|
||||
ulp_run(0);
|
||||
|
||||
esp_sleep_enable_ulp_wakeup();
|
||||
esp_sleep_enable_timer_wakeup(10 * 1000000);
|
||||
esp_deep_sleep_start();
|
||||
}
|
||||
|
||||
TEST_CASE("ulp timer setting", "[ulp]")
|
||||
{
|
||||
/*
|
||||
* Run a simple ULP program which increments the counter, for one second.
|
||||
* Program calls I_HALT each time and gets restarted by the timer.
|
||||
* Compare the expected number of times the program runs with the actual.
|
||||
*/
|
||||
assert(CONFIG_ESP32_ULP_COPROC_RESERVE_MEM >= 32 && "this test needs ESP32_ULP_COPROC_RESERVE_MEM option set in menuconfig");
|
||||
memset(RTC_SLOW_MEM, 0, CONFIG_ESP32_ULP_COPROC_RESERVE_MEM);
|
||||
|
||||
const int offset = 6;
|
||||
const ulp_insn_t program[] = {
|
||||
I_MOVI(R1, offset), // r1 <- offset
|
||||
I_LD(R2, R1, 0), // load counter
|
||||
I_ADDI(R2, R2, 1), // counter += 1
|
||||
I_ST(R2, R1, 0), // save counter
|
||||
I_HALT(),
|
||||
};
|
||||
|
||||
size_t size = sizeof(program)/sizeof(ulp_insn_t);
|
||||
TEST_ESP_OK(ulp_process_macros_and_load(0, program, &size));
|
||||
assert(offset >= size && "data offset needs to be greater or equal to program size");
|
||||
TEST_ESP_OK(ulp_run(0));
|
||||
// disable the ULP program timer — we will enable it later
|
||||
CLEAR_PERI_REG_MASK(RTC_CNTL_STATE0_REG, RTC_CNTL_ULP_CP_SLP_TIMER_EN);
|
||||
|
||||
const uint32_t cycles_to_test[] = {0x80, 0x100, 0x200, 0x400, 0x800, 0x1000, 0x2000, 0x4000};
|
||||
const size_t tests_count = sizeof(cycles_to_test) / sizeof(cycles_to_test[0]);
|
||||
for (size_t i = 0; i < tests_count; ++i) {
|
||||
// zero out the counter
|
||||
RTC_SLOW_MEM[offset] = 0;
|
||||
// set the number of slow clock cycles
|
||||
REG_WRITE(SENS_ULP_CP_SLEEP_CYC0_REG, cycles_to_test[i]);
|
||||
// enable the timer and wait for a second
|
||||
SET_PERI_REG_MASK(RTC_CNTL_STATE0_REG, RTC_CNTL_ULP_CP_SLP_TIMER_EN);
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
// get the counter value and stop the timer
|
||||
uint32_t counter = RTC_SLOW_MEM[offset] & 0xffff;
|
||||
CLEAR_PERI_REG_MASK(RTC_CNTL_STATE0_REG, RTC_CNTL_ULP_CP_SLP_TIMER_EN);
|
||||
// compare the actual and expected numbers of iterations of ULP program
|
||||
float expected_period = (cycles_to_test[i] + 16) / (float) rtc_clk_slow_freq_get_hz() + 5 / 8e6f;
|
||||
float error = 1.0f - counter * expected_period;
|
||||
printf("%u\t%u\t%.01f\t%.04f\n", cycles_to_test[i], counter, 1.0f / expected_period, error);
|
||||
// Should be within 15%
|
||||
TEST_ASSERT_INT_WITHIN(15, 0, (int) error * 100);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("ulp can use TSENS in deep sleep", "[ulp][ignore]")
|
||||
{
|
||||
assert(CONFIG_ESP32_ULP_COPROC_RESERVE_MEM >= 260 && "this test needs ESP32_ULP_COPROC_RESERVE_MEM option set in menuconfig");
|
||||
|
||||
hexdump(RTC_SLOW_MEM, CONFIG_ESP32_ULP_COPROC_RESERVE_MEM / 4);
|
||||
printf("\n\n");
|
||||
memset(RTC_SLOW_MEM, 0, CONFIG_ESP32_ULP_COPROC_RESERVE_MEM);
|
||||
|
||||
// Allow TSENS to be controlled by the ULP
|
||||
SET_PERI_REG_BITS(SENS_SAR_TSENS_CTRL_REG, SENS_TSENS_CLK_DIV, 10, SENS_TSENS_CLK_DIV_S);
|
||||
SET_PERI_REG_BITS(SENS_SAR_MEAS_WAIT2_REG, SENS_FORCE_XPD_SAR, 3, SENS_FORCE_XPD_SAR_S);
|
||||
CLEAR_PERI_REG_MASK(SENS_SAR_TSENS_CTRL_REG, SENS_TSENS_POWER_UP);
|
||||
CLEAR_PERI_REG_MASK(SENS_SAR_TSENS_CTRL_REG, SENS_TSENS_DUMP_OUT);
|
||||
CLEAR_PERI_REG_MASK(SENS_SAR_TSENS_CTRL_REG, SENS_TSENS_POWER_UP_FORCE);
|
||||
|
||||
// data start offset
|
||||
size_t offset = 20;
|
||||
// number of samples to collect
|
||||
RTC_SLOW_MEM[offset] = (CONFIG_ESP32_ULP_COPROC_RESERVE_MEM) / 4 - offset - 8;
|
||||
// sample counter
|
||||
RTC_SLOW_MEM[offset + 1] = 0;
|
||||
|
||||
const ulp_insn_t program[] = {
|
||||
I_MOVI(R1, offset), // r1 <- offset
|
||||
I_LD(R2, R1, 1), // r2 <- counter
|
||||
I_LD(R3, R1, 0), // r3 <- length
|
||||
I_SUBI(R3, R3, 1), // end = length - 1
|
||||
I_SUBR(R3, R3, R2), // r3 = length - counter
|
||||
M_BXF(1), // if overflow goto 1:
|
||||
I_WR_REG(SENS_SAR_MEAS_WAIT2_REG, SENS_FORCE_XPD_SAR_S, SENS_FORCE_XPD_SAR_S + 1, 3),
|
||||
I_TSENS(R0, 16383), // r0 <- tsens
|
||||
I_WR_REG(SENS_SAR_MEAS_WAIT2_REG, SENS_FORCE_XPD_SAR_S, SENS_FORCE_XPD_SAR_S + 1, 0),
|
||||
I_ST(R0, R2, offset + 4),
|
||||
I_ADDI(R2, R2, 1), // counter += 1
|
||||
I_ST(R2, R1, 1), // save counter
|
||||
I_HALT(), // enter sleep
|
||||
M_LABEL(1), // done with measurements
|
||||
I_END(), // stop ULP timer
|
||||
I_WAKE(), // initiate wakeup
|
||||
I_HALT()
|
||||
};
|
||||
|
||||
size_t size = sizeof(program)/sizeof(ulp_insn_t);
|
||||
TEST_ESP_OK(ulp_process_macros_and_load(0, program, &size));
|
||||
assert(offset >= size);
|
||||
|
||||
TEST_ESP_OK(ulp_run(0));
|
||||
esp_sleep_enable_timer_wakeup(4000000);
|
||||
esp_sleep_enable_ulp_wakeup();
|
||||
esp_deep_sleep_start();
|
||||
}
|
||||
|
||||
TEST_CASE("can use ADC in deep sleep", "[ulp][ignore]")
|
||||
{
|
||||
assert(CONFIG_ESP32_ULP_COPROC_RESERVE_MEM >= 260 && "this test needs ESP32_ULP_COPROC_RESERVE_MEM option set in menuconfig");
|
||||
|
||||
hexdump(RTC_SLOW_MEM, CONFIG_ESP32_ULP_COPROC_RESERVE_MEM / 4);
|
||||
printf("\n\n");
|
||||
memset(RTC_SLOW_MEM, 0, CONFIG_ESP32_ULP_COPROC_RESERVE_MEM);
|
||||
|
||||
SET_PERI_REG_BITS(SENS_SAR_START_FORCE_REG, SENS_SAR1_BIT_WIDTH, 3, SENS_SAR1_BIT_WIDTH_S);
|
||||
SET_PERI_REG_BITS(SENS_SAR_START_FORCE_REG, SENS_SAR2_BIT_WIDTH, 3, SENS_SAR2_BIT_WIDTH_S);
|
||||
|
||||
SET_PERI_REG_BITS(SENS_SAR_READ_CTRL_REG, SENS_SAR1_SAMPLE_BIT, 0x3, SENS_SAR1_SAMPLE_BIT_S);
|
||||
SET_PERI_REG_BITS(SENS_SAR_READ_CTRL2_REG, SENS_SAR2_SAMPLE_BIT, 0x3, SENS_SAR2_SAMPLE_BIT_S);
|
||||
|
||||
CLEAR_PERI_REG_MASK(SENS_SAR_MEAS_START2_REG, SENS_MEAS2_START_FORCE);
|
||||
CLEAR_PERI_REG_MASK(SENS_SAR_MEAS_START1_REG, SENS_MEAS1_START_FORCE);
|
||||
|
||||
SET_PERI_REG_BITS(SENS_SAR_MEAS_WAIT2_REG, SENS_FORCE_XPD_SAR, 0, SENS_FORCE_XPD_SAR_S);
|
||||
SET_PERI_REG_BITS(SENS_SAR_MEAS_WAIT2_REG, SENS_FORCE_XPD_AMP, 2, SENS_FORCE_XPD_AMP_S);
|
||||
|
||||
// SAR1 invert result
|
||||
SET_PERI_REG_MASK(SENS_SAR_READ_CTRL_REG, SENS_SAR1_DATA_INV);
|
||||
SET_PERI_REG_MASK(SENS_SAR_READ_CTRL_REG, SENS_SAR2_DATA_INV);
|
||||
|
||||
|
||||
// const int adc = 1;
|
||||
// const int channel = 1;
|
||||
// const int atten = 3;
|
||||
// const int gpio_num = 0;
|
||||
|
||||
const int adc = 0;
|
||||
const int channel = 0;
|
||||
const int atten = 0;
|
||||
const int gpio_num = 36;
|
||||
|
||||
rtc_gpio_init(gpio_num);
|
||||
|
||||
CLEAR_PERI_REG_MASK(SENS_SAR_MEAS_START1_REG, SENS_SAR1_EN_PAD_FORCE_M);
|
||||
CLEAR_PERI_REG_MASK(SENS_SAR_MEAS_START2_REG, SENS_SAR2_EN_PAD_FORCE_M);
|
||||
|
||||
SET_PERI_REG_BITS(SENS_SAR_ATTEN1_REG, 3, atten, 2 * channel); //set SAR1 attenuation
|
||||
SET_PERI_REG_BITS(SENS_SAR_ATTEN2_REG, 3, atten, 2 * channel); //set SAR2 attenuation
|
||||
|
||||
// data start offset
|
||||
size_t offset = 20;
|
||||
// number of samples to collect
|
||||
RTC_SLOW_MEM[offset] = (CONFIG_ESP32_ULP_COPROC_RESERVE_MEM) / 4 - offset - 8;
|
||||
// sample counter
|
||||
RTC_SLOW_MEM[offset + 1] = 0;
|
||||
|
||||
const ulp_insn_t program[] = {
|
||||
I_MOVI(R1, offset), // r1 <- offset
|
||||
I_LD(R2, R1, 1), // r2 <- counter
|
||||
I_LD(R3, R1, 0), // r3 <- length
|
||||
I_SUBI(R3, R3, 1), // end = length - 1
|
||||
I_SUBR(R3, R3, R2), // r3 = length - counter
|
||||
M_BXF(1), // if overflow goto 1:
|
||||
I_ADC(R0, adc, channel), // r0 <- ADC
|
||||
I_ST(R0, R2, offset + 4),
|
||||
I_ADDI(R2, R2, 1), // counter += 1
|
||||
I_ST(R2, R1, 1), // save counter
|
||||
I_HALT(),
|
||||
M_LABEL(1), // done with measurements
|
||||
I_END(), // stop ULP program timer
|
||||
I_HALT()
|
||||
};
|
||||
|
||||
size_t size = sizeof(program)/sizeof(ulp_insn_t);
|
||||
TEST_ESP_OK(ulp_process_macros_and_load(0, program, &size));
|
||||
assert(offset >= size);
|
||||
|
||||
TEST_ESP_OK(ulp_run(0));
|
||||
esp_sleep_enable_timer_wakeup(4000000);
|
||||
esp_deep_sleep_start();
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
#include <unistd.h>
|
||||
#include "unity.h"
|
||||
#include "soc/rtc_cntl_reg.h"
|
||||
#include "esp32/ulp.h"
|
||||
#include "ulp_test_app.h"
|
||||
|
||||
|
||||
extern const uint8_t ulp_test_app_bin_start[] asm("_binary_ulp_test_app_bin_start");
|
||||
extern const uint8_t ulp_test_app_bin_end[] asm("_binary_ulp_test_app_bin_end");
|
||||
|
||||
|
||||
TEST_CASE("jumps condition", "[ulp]")
|
||||
{
|
||||
esp_err_t err = ulp_load_binary(0, ulp_test_app_bin_start,
|
||||
(ulp_test_app_bin_end - ulp_test_app_bin_start) / sizeof(uint32_t));
|
||||
TEST_ESP_OK(err);
|
||||
|
||||
REG_CLR_BIT(RTC_CNTL_INT_RAW_REG, RTC_CNTL_ULP_CP_INT_RAW);
|
||||
TEST_ESP_OK(ulp_run(&ulp_test_jumps - RTC_SLOW_MEM));
|
||||
usleep(10000);
|
||||
|
||||
TEST_ASSERT_NOT_EQUAL(0, REG_GET_BIT(RTC_CNTL_INT_RAW_REG, RTC_CNTL_ULP_CP_INT_RAW));
|
||||
TEST_ASSERT_EQUAL(0, ulp_jumps_fail & UINT16_MAX);
|
||||
TEST_ASSERT_EQUAL(1, ulp_jumps_pass & UINT16_MAX);
|
||||
}
|
680
components/ulp/test/ulp_fsm/test_ulp.c
Normal file
680
components/ulp/test/ulp_fsm/test_ulp.c
Normal file
@ -0,0 +1,680 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2010-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
#include <freertos/semphr.h>
|
||||
|
||||
#include <unity.h>
|
||||
#include "esp_attr.h"
|
||||
#include "esp_err.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_sleep.h"
|
||||
#include "soc/soc.h"
|
||||
#include "soc/rtc.h"
|
||||
#include "soc/rtc_cntl_reg.h"
|
||||
#include "soc/sens_reg.h"
|
||||
#include "soc/rtc_io_reg.h"
|
||||
#include "driver/rtc_io.h"
|
||||
|
||||
#include "sdkconfig.h"
|
||||
#include "esp_rom_sys.h"
|
||||
|
||||
#if CONFIG_IDF_TARGET_ESP32
|
||||
#include "esp32/ulp.h"
|
||||
#elif CONFIG_IDF_TARGET_ESP32S2
|
||||
#include "esp32s2/ulp.h"
|
||||
#elif CONFIG_IDF_TARGET_ESP32S3
|
||||
#include "esp32s3/ulp.h"
|
||||
#endif
|
||||
|
||||
#include "ulp_test_app.h"
|
||||
|
||||
extern const uint8_t ulp_test_app_bin_start[] asm("_binary_ulp_test_app_bin_start");
|
||||
extern const uint8_t ulp_test_app_bin_end[] asm("_binary_ulp_test_app_bin_end");
|
||||
|
||||
#define HEX_DUMP_DEBUG 0
|
||||
|
||||
|
||||
|
||||
#if CONFIG_IDF_TARGET_ESP32
|
||||
#define COPROC_RESERVE_MEM CONFIG_ESP32_ULP_COPROC_RESERVE_MEM
|
||||
#elif CONFIG_IDF_TARGET_ESP32S2
|
||||
#define COPROC_RESERVE_MEM CONFIG_ESP32S2_ULP_COPROC_RESERVE_MEM
|
||||
#elif CONFIG_IDF_TARGET_ESP32S3
|
||||
#define COPROC_RESERVE_MEM CONFIG_ESP32S3_ULP_COPROC_RESERVE_MEM
|
||||
#endif
|
||||
|
||||
static void hexdump(const uint32_t* src, size_t count) {
|
||||
#if HEX_DUMP_DEBUG
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
printf("%08x ", *src);
|
||||
++src;
|
||||
if ((i + 1) % 4 == 0) {
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
#else
|
||||
(void)src;
|
||||
(void)count;
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST_CASE("ULP FSM addition test", "[ulp]")
|
||||
{
|
||||
/* Clear the RTC_SLOW_MEM region for the ULP co-processor binary to be loaded */
|
||||
memset(RTC_SLOW_MEM, 0, COPROC_RESERVE_MEM);
|
||||
|
||||
/* ULP co-processor program to add data in 2 memory locations using ULP macros */
|
||||
const ulp_insn_t program[] = {
|
||||
I_MOVI(R3, 16), // r3 = 16
|
||||
I_LD(R0, R3, 0), // r0 = mem[r3 + 0]
|
||||
I_LD(R1, R3, 1), // r1 = mem[r3 + 1]
|
||||
I_ADDR(R2, R0, R1), // r2 = r0 + r1
|
||||
I_ST(R2, R3, 2), // mem[r3 + 2] = r2
|
||||
I_HALT() // halt
|
||||
};
|
||||
|
||||
/* Load the memory regions used by the ULP co-processor */
|
||||
RTC_SLOW_MEM[16] = 10;
|
||||
RTC_SLOW_MEM[17] = 11;
|
||||
|
||||
/* Calculate the size of the ULP co-processor binary, load it and run the ULP coprocessor */
|
||||
size_t size = sizeof(program)/sizeof(ulp_insn_t);
|
||||
TEST_ASSERT_EQUAL(ESP_OK, ulp_process_macros_and_load(0, program, &size));
|
||||
TEST_ASSERT_EQUAL(ESP_OK, ulp_run(0));
|
||||
|
||||
/* Wait for the ULP co-processor to finish up */
|
||||
esp_rom_delay_us(1000);
|
||||
hexdump(RTC_SLOW_MEM, 20);
|
||||
|
||||
/* Verify the test results */
|
||||
TEST_ASSERT_EQUAL(10 + 11, RTC_SLOW_MEM[18] & 0xffff);
|
||||
}
|
||||
|
||||
TEST_CASE("ULP FSM subtraction and branch test", "[ulp]")
|
||||
{
|
||||
assert(COPROC_RESERVE_MEM >= 260 && "this test needs ULP_COPROC_RESERVE_MEM option set in menuconfig");
|
||||
|
||||
/* Clear the RTC_SLOW_MEM region for the ULP co-processor binary to be loaded */
|
||||
memset(RTC_SLOW_MEM, 0, COPROC_RESERVE_MEM);
|
||||
|
||||
/* ULP co-processor program to perform subtractions and branch to a label */
|
||||
const ulp_insn_t program[] = {
|
||||
I_MOVI(R0, 34), // r0 = 34
|
||||
M_LABEL(1), // define a label with label number as 1
|
||||
I_MOVI(R1, 32), // r1 = 32
|
||||
I_LD(R1, R1, 0), // r1 = mem[32 + 0]
|
||||
I_MOVI(R2, 33), // r2 = 33
|
||||
I_LD(R2, R2, 0), // r2 = mem[33 + 0]
|
||||
I_SUBR(R3, R1, R2), // r3 = r1 - r2
|
||||
I_ST(R3, R0, 0), // mem[r0 + 0] = r3
|
||||
I_ADDI(R0, R0, 1), // r0 = r0 + 1
|
||||
M_BL(1, 64), // branch to label 1 if r0 < 64
|
||||
I_HALT(), // halt
|
||||
};
|
||||
|
||||
/* Load the memory regions used by the ULP co-processor */
|
||||
RTC_SLOW_MEM[32] = 42;
|
||||
RTC_SLOW_MEM[33] = 18;
|
||||
|
||||
/* Calculate the size of the ULP co-processor binary, load it and run the ULP coprocessor */
|
||||
size_t size = sizeof(program)/sizeof(ulp_insn_t);
|
||||
TEST_ASSERT_EQUAL(ESP_OK, ulp_process_macros_and_load(0, program, &size));
|
||||
TEST_ASSERT_EQUAL(ESP_OK, ulp_run(0));
|
||||
printf("\n\n");
|
||||
|
||||
/* Wait for the ULP co-processor to finish up */
|
||||
esp_rom_delay_us(1000);
|
||||
hexdump(RTC_SLOW_MEM, 50);
|
||||
|
||||
/* Verify the test results */
|
||||
for (int i = 34; i < 64; ++i) {
|
||||
TEST_ASSERT_EQUAL(42 - 18, RTC_SLOW_MEM[i] & 0xffff);
|
||||
}
|
||||
TEST_ASSERT_EQUAL(0, RTC_SLOW_MEM[64]);
|
||||
}
|
||||
|
||||
TEST_CASE("ULP FSM JUMPS instruction test", "[ulp]")
|
||||
{
|
||||
/*
|
||||
* Load the ULP binary.
|
||||
*
|
||||
* This ULP program is written in assembly. Please refer associated .S file.
|
||||
*/
|
||||
esp_err_t err = ulp_load_binary(0, ulp_test_app_bin_start,
|
||||
(ulp_test_app_bin_end - ulp_test_app_bin_start) / sizeof(uint32_t));
|
||||
TEST_ESP_OK(err);
|
||||
|
||||
/* Clear ULP FSM raw interrupt */
|
||||
REG_CLR_BIT(RTC_CNTL_INT_RAW_REG, RTC_CNTL_ULP_CP_INT_RAW);
|
||||
|
||||
/* Run the ULP coprocessor */
|
||||
TEST_ESP_OK(ulp_run(&ulp_test_jumps - RTC_SLOW_MEM));
|
||||
|
||||
/* Wait for the ULP co-processor to finish up */
|
||||
esp_rom_delay_us(1000);
|
||||
|
||||
/* Verify that ULP FSM issued an interrupt to wake up the main CPU */
|
||||
TEST_ASSERT_NOT_EQUAL(0, REG_GET_BIT(RTC_CNTL_INT_RAW_REG, RTC_CNTL_ULP_CP_INT_RAW));
|
||||
|
||||
/* Verify the test results */
|
||||
TEST_ASSERT_EQUAL(0, ulp_jumps_fail & UINT16_MAX);
|
||||
TEST_ASSERT_EQUAL(1, ulp_jumps_pass & UINT16_MAX);
|
||||
}
|
||||
|
||||
TEST_CASE("ULP FSM light-sleep wakeup test", "[ulp]")
|
||||
{
|
||||
assert(COPROC_RESERVE_MEM >= 260 && "this test needs ULP_COPROC_RESERVE_MEM option set in menuconfig");
|
||||
|
||||
/* Clear the RTC_SLOW_MEM region for the ULP co-processor binary to be loaded */
|
||||
memset(RTC_SLOW_MEM, 0, COPROC_RESERVE_MEM);
|
||||
|
||||
/* ULP co-processor program to perform some activities and wakeup the main CPU from deep-sleep */
|
||||
const ulp_insn_t program[] = {
|
||||
I_MOVI(R1, 1024), // r1 = 1024
|
||||
M_LABEL(1), // define label 1
|
||||
I_DELAY(32000), // add a delay (NOP for 32000 cycles)
|
||||
I_SUBI(R1, R1, 1), // r1 = r1 - 1
|
||||
M_BXZ(3), // branch to label 3 if ALU value is 0. (r1 = 0)
|
||||
I_RSHI(R3, R1, 5), // r3 = r1 / 32
|
||||
I_ST(R1, R3, 16), // mem[r3 + 16] = r1
|
||||
M_BX(1), // loop to label 1
|
||||
M_LABEL(3), // define label 3
|
||||
I_MOVI(R2, 42), // r2 = 42
|
||||
I_MOVI(R3, 15), // r3 = 15
|
||||
I_ST(R2, R3, 0), // mem[r3 + 0] = r2
|
||||
I_WAKE(), // wake the SoC from deep-sleep
|
||||
I_END(), // stop ULP timer
|
||||
I_HALT() // halt
|
||||
};
|
||||
|
||||
/* Calculate the size of the ULP co-processor binary, load it and run the ULP coprocessor */
|
||||
size_t size = sizeof(program)/sizeof(ulp_insn_t);
|
||||
TEST_ASSERT_EQUAL(ESP_OK, ulp_process_macros_and_load(0, program, &size));
|
||||
TEST_ASSERT_EQUAL(ESP_OK, ulp_run(0));
|
||||
|
||||
/* Setup wakeup triggers */
|
||||
TEST_ASSERT(esp_sleep_enable_ulp_wakeup() == ESP_OK);
|
||||
|
||||
/* Enter Light Sleep */
|
||||
TEST_ASSERT(esp_light_sleep_start() == ESP_OK);
|
||||
|
||||
/* Wait for wakeup from ULP FSM Coprocessor */
|
||||
printf("cause %d\r\n", esp_sleep_get_wakeup_cause());
|
||||
TEST_ASSERT(esp_sleep_get_wakeup_cause() == ESP_SLEEP_WAKEUP_ULP);
|
||||
}
|
||||
|
||||
TEST_CASE("ULP FSM deep-sleep wakeup test", "[ulp][reset=SW_CPU_RESET][ignore]")
|
||||
{
|
||||
assert(COPROC_RESERVE_MEM >= 260 && "this test needs ULP_COPROC_RESERVE_MEM option set in menuconfig");
|
||||
|
||||
/* Clearout the RTC_SLOW_MEM region for the ULP co-processor binary to be loaded */
|
||||
memset(RTC_SLOW_MEM, 0, COPROC_RESERVE_MEM);
|
||||
|
||||
/* ULP co-processor program to perform some activities and wakeup the main CPU from deep-sleep */
|
||||
const ulp_insn_t program[] = {
|
||||
I_MOVI(R1, 1024), // r1 = 1024
|
||||
M_LABEL(1), // define label 1
|
||||
I_DELAY(32000), // add a delay (NOP for 32000 cycles)
|
||||
I_SUBI(R1, R1, 1), // r1 = r1 - 1
|
||||
M_BXZ(3), // branch to label 3 if ALU value is 0. (r1 = 0)
|
||||
I_RSHI(R3, R1, 5), // r3 = r1 / 32
|
||||
I_ST(R1, R3, 16), // mem[r3 + 16] = r1
|
||||
M_BX(1), // loop to label 1
|
||||
M_LABEL(3), // define label 3
|
||||
I_MOVI(R2, 42), // r2 = 42
|
||||
I_MOVI(R3, 15), // r3 = 15
|
||||
I_ST(R2, R3, 0), // mem[r3 + 0] = r2
|
||||
I_WAKE(), // wake the SoC from deep-sleep
|
||||
I_END(), // stop ULP timer
|
||||
I_HALT() // halt
|
||||
};
|
||||
|
||||
/* Calculate the size of the ULP co-processor binary, load it and run the ULP coprocessor */
|
||||
size_t size = sizeof(program)/sizeof(ulp_insn_t);
|
||||
TEST_ASSERT_EQUAL(ESP_OK, ulp_process_macros_and_load(0, program, &size));
|
||||
TEST_ASSERT_EQUAL(ESP_OK, ulp_run(0));
|
||||
|
||||
/* Setup wakeup triggers */
|
||||
TEST_ASSERT(esp_sleep_enable_ulp_wakeup() == ESP_OK);
|
||||
|
||||
/* Enter Deep Sleep */
|
||||
esp_deep_sleep_start();
|
||||
UNITY_TEST_FAIL(__LINE__, "Should not get here!");
|
||||
}
|
||||
|
||||
TEST_CASE("ULP FSM can write and read peripheral registers", "[ulp]")
|
||||
{
|
||||
assert(COPROC_RESERVE_MEM >= 260 && "this test needs ULP_COPROC_RESERVE_MEM option set in menuconfig");
|
||||
|
||||
/* Clear ULP timer */
|
||||
CLEAR_PERI_REG_MASK(RTC_CNTL_STATE0_REG, RTC_CNTL_ULP_CP_SLP_TIMER_EN);
|
||||
|
||||
/* Clear the RTC_SLOW_MEM region for the ULP co-processor binary to be loaded */
|
||||
memset(RTC_SLOW_MEM, 0, COPROC_RESERVE_MEM);
|
||||
|
||||
/* ULP co-processor program to read from and write to peripheral registers */
|
||||
const ulp_insn_t program[] = {
|
||||
I_MOVI(R1, 64), // r1 = 64
|
||||
I_RD_REG(RTC_CNTL_STORE1_REG, 0, 15), // r0 = REG_READ(RTC_CNTL_STORE1_REG[15:0])
|
||||
I_ST(R0, R1, 0), // mem[r1 + 0] = r0
|
||||
I_RD_REG(RTC_CNTL_STORE1_REG, 4, 11), // r0 = REG_READ(RTC_CNTL_STORE1_REG[11:4])
|
||||
I_ST(R0, R1, 1), // mem[r1 + 1] = r0
|
||||
I_RD_REG(RTC_CNTL_STORE1_REG, 16, 31), // r0 = REG_READ(RTC_CNTL_STORE1_REG[31:16])
|
||||
I_ST(R0, R1, 2), // mem[r1 + 2] = r0
|
||||
I_RD_REG(RTC_CNTL_STORE1_REG, 20, 27), // r0 = REG_READ(RTC_CNTL_STORE1_REG[27:20])
|
||||
I_ST(R0, R1, 3), // mem[r1 + 3] = r0
|
||||
I_WR_REG(RTC_CNTL_STORE0_REG, 0, 7, 0x89), // REG_WRITE(RTC_CNTL_STORE0_REG[7:0], 0x89)
|
||||
I_WR_REG(RTC_CNTL_STORE0_REG, 8, 15, 0xab), // REG_WRITE(RTC_CNTL_STORE0_REG[15:8], 0xab)
|
||||
I_WR_REG(RTC_CNTL_STORE0_REG, 16, 23, 0xcd), // REG_WRITE(RTC_CNTL_STORE0_REG[23:16], 0xcd)
|
||||
I_WR_REG(RTC_CNTL_STORE0_REG, 24, 31, 0xef), // REG_WRITE(RTC_CNTL_STORE0_REG[31:24], 0xef)
|
||||
I_LD(R0, R1, 4), // r0 = mem[r1 + 4]
|
||||
I_ADDI(R0, R0, 1), // r0 = r0 + 1
|
||||
I_ST(R0, R1, 4), // mem[r1 + 4] = r0
|
||||
I_END(), // stop ULP timer
|
||||
I_HALT() // halt
|
||||
};
|
||||
|
||||
/* Set data in the peripheral register to be read by the ULP co-processor */
|
||||
REG_WRITE(RTC_CNTL_STORE1_REG, 0x89abcdef);
|
||||
|
||||
/* Calculate the size of the ULP co-processor binary, load it and run the ULP coprocessor */
|
||||
size_t size = sizeof(program)/sizeof(ulp_insn_t);
|
||||
TEST_ESP_OK(ulp_process_macros_and_load(0, program, &size));
|
||||
TEST_ESP_OK(ulp_run(0));
|
||||
|
||||
/* Wait for the ULP co-processor to finish up */
|
||||
vTaskDelay(100/portTICK_PERIOD_MS);
|
||||
|
||||
/* Verify the test results */
|
||||
TEST_ASSERT_EQUAL_HEX32(0xefcdab89, REG_READ(RTC_CNTL_STORE0_REG));
|
||||
TEST_ASSERT_EQUAL_HEX16(0xcdef, RTC_SLOW_MEM[64] & 0xffff);
|
||||
TEST_ASSERT_EQUAL_HEX16(0xde, RTC_SLOW_MEM[65] & 0xffff);
|
||||
TEST_ASSERT_EQUAL_HEX16(0x89ab, RTC_SLOW_MEM[66] & 0xffff);
|
||||
TEST_ASSERT_EQUAL_HEX16(0x9a, RTC_SLOW_MEM[67] & 0xffff);
|
||||
TEST_ASSERT_EQUAL_HEX16(1, RTC_SLOW_MEM[68] & 0xffff);
|
||||
}
|
||||
|
||||
TEST_CASE("ULP FSM I_WR_REG instruction test", "[ulp]")
|
||||
{
|
||||
assert(COPROC_RESERVE_MEM >= 260 && "this test needs ULP_COPROC_RESERVE_MEM option set in menuconfig");
|
||||
|
||||
/* Clear the RTC_SLOW_MEM region for the ULP co-processor binary to be loaded */
|
||||
memset(RTC_SLOW_MEM, 0, COPROC_RESERVE_MEM);
|
||||
|
||||
/* Define the test set */
|
||||
typedef struct {
|
||||
int low;
|
||||
int width;
|
||||
} wr_reg_test_item_t;
|
||||
|
||||
const wr_reg_test_item_t test_items[] = {
|
||||
{0, 1}, {0, 2}, {0, 3}, {0, 4}, {0, 5}, {0, 6}, {0, 7}, {0, 8},
|
||||
{3, 1}, {3, 2}, {3, 3}, {3, 4}, {3, 5}, {3, 6}, {3, 7}, {3, 8},
|
||||
{15, 1}, {15, 2}, {15, 3}, {15, 4}, {15, 5}, {15, 6}, {15, 7}, {15, 8},
|
||||
{16, 1}, {16, 2}, {16, 3}, {16, 4}, {16, 5}, {16, 6}, {16, 7}, {16, 8},
|
||||
{18, 1}, {18, 2}, {18, 3}, {18, 4}, {18, 5}, {18, 6}, {18, 7}, {18, 8},
|
||||
{24, 1}, {24, 2}, {24, 3}, {24, 4}, {24, 5}, {24, 6}, {24, 7}, {24, 8},
|
||||
};
|
||||
|
||||
const size_t test_items_count =
|
||||
sizeof(test_items)/sizeof(test_items[0]);
|
||||
for (size_t i = 0; i < test_items_count; ++i) {
|
||||
const uint32_t mask = (uint32_t) (((1ULL << test_items[i].width) - 1) << test_items[i].low);
|
||||
const uint32_t not_mask = ~mask;
|
||||
printf("#%2d: low: %2d width: %2d mask: %08x expected: %08x ", i,
|
||||
test_items[i].low, test_items[i].width,
|
||||
mask, not_mask);
|
||||
|
||||
/* Set all bits in RTC_CNTL_STORE0_REG and reset all bits in RTC_CNTL_STORE1_REG */
|
||||
REG_WRITE(RTC_CNTL_STORE0_REG, 0xffffffff);
|
||||
REG_WRITE(RTC_CNTL_STORE1_REG, 0x00000000);
|
||||
|
||||
/* ULP co-processor program to write to peripheral registers */
|
||||
const ulp_insn_t program[] = {
|
||||
I_WR_REG(RTC_CNTL_STORE0_REG,
|
||||
test_items[i].low,
|
||||
test_items[i].low + test_items[i].width - 1,
|
||||
0),
|
||||
I_WR_REG(RTC_CNTL_STORE1_REG,
|
||||
test_items[i].low,
|
||||
test_items[i].low + test_items[i].width - 1,
|
||||
0xff & ((1 << test_items[i].width) - 1)),
|
||||
I_END(),
|
||||
I_HALT()
|
||||
};
|
||||
|
||||
/* Calculate the size of the ULP co-processor binary, load it and run the ULP coprocessor */
|
||||
size_t size = sizeof(program)/sizeof(ulp_insn_t);
|
||||
TEST_ESP_OK(ulp_process_macros_and_load(0, program, &size));
|
||||
TEST_ESP_OK(ulp_run(0));
|
||||
|
||||
/* Wait for the ULP co-processor to finish up */
|
||||
vTaskDelay(10/portTICK_PERIOD_MS);
|
||||
|
||||
/* Verify the test results */
|
||||
uint32_t clear = REG_READ(RTC_CNTL_STORE0_REG);
|
||||
uint32_t set = REG_READ(RTC_CNTL_STORE1_REG);
|
||||
printf("clear: %08x set: %08x\n", clear, set);
|
||||
TEST_ASSERT_EQUAL_HEX32(not_mask, clear);
|
||||
TEST_ASSERT_EQUAL_HEX32(mask, set);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("ULP FSM controls RTC_IO", "[ulp][ignore]")
|
||||
{
|
||||
assert(COPROC_RESERVE_MEM >= 260 && "this test needs ULP_COPROC_RESERVE_MEM option set in menuconfig");
|
||||
|
||||
/* Clear the RTC_SLOW_MEM region for the ULP co-processor binary to be loaded */
|
||||
memset(RTC_SLOW_MEM, 0, COPROC_RESERVE_MEM);
|
||||
|
||||
/* ULP co-processor program to toggle LED */
|
||||
const ulp_insn_t program[] = {
|
||||
I_MOVI(R0, 0), // r0 is LED state
|
||||
I_MOVI(R2, 16), // loop r2 from 16 down to 0
|
||||
M_LABEL(4), // define label 4
|
||||
I_SUBI(R2, R2, 1), // r2 = r2 - 1
|
||||
M_BXZ(6), // branch to label 6 if r2 = 0
|
||||
I_ADDI(R0, R0, 1), // r0 = (r0 + 1) % 2
|
||||
I_ANDI(R0, R0, 0x1),
|
||||
M_BL(0, 1), // if r0 < 1 goto 0
|
||||
M_LABEL(1), // define label 1
|
||||
I_WR_REG(RTC_GPIO_OUT_REG, 26, 27, 1), // RTC_GPIO12 = 1
|
||||
M_BX(2), // goto 2
|
||||
M_LABEL(0), // define label 0
|
||||
I_WR_REG(RTC_GPIO_OUT_REG, 26, 27, 0), // RTC_GPIO12 = 0
|
||||
M_LABEL(2), // define label 2
|
||||
I_MOVI(R1, 100), // loop R1 from 100 down to 0
|
||||
M_LABEL(3), // define label 3
|
||||
I_SUBI(R1, R1, 1), // r1 = r1 - 1
|
||||
M_BXZ(5), // branch to label 5 if r1 = 0
|
||||
I_DELAY(32000), // delay for a while
|
||||
M_BX(3), // goto 3
|
||||
M_LABEL(5), // define label 5
|
||||
M_BX(4), // loop back to label 4
|
||||
M_LABEL(6), // define label 6
|
||||
I_WAKE(), // wake up the SoC
|
||||
I_END(), // stop ULP program timer
|
||||
I_HALT()
|
||||
};
|
||||
|
||||
/* Configure LED GPIOs */
|
||||
const gpio_num_t led_gpios[] = {
|
||||
GPIO_NUM_2,
|
||||
GPIO_NUM_0,
|
||||
GPIO_NUM_4
|
||||
};
|
||||
for (size_t i = 0; i < sizeof(led_gpios)/sizeof(led_gpios[0]); ++i) {
|
||||
rtc_gpio_init(led_gpios[i]);
|
||||
rtc_gpio_set_direction(led_gpios[i], RTC_GPIO_MODE_OUTPUT_ONLY);
|
||||
rtc_gpio_set_level(led_gpios[i], 0);
|
||||
}
|
||||
|
||||
/* Calculate the size of the ULP co-processor binary, load it and run the ULP coprocessor */
|
||||
size_t size = sizeof(program)/sizeof(ulp_insn_t);
|
||||
TEST_ESP_OK(ulp_process_macros_and_load(0, program, &size));
|
||||
TEST_ESP_OK(ulp_run(0));
|
||||
|
||||
/* Setup wakeup triggers */
|
||||
TEST_ASSERT(esp_sleep_enable_ulp_wakeup() == ESP_OK);
|
||||
|
||||
/* Enter Deep Sleep */
|
||||
esp_deep_sleep_start();
|
||||
UNITY_TEST_FAIL(__LINE__, "Should not get here!");
|
||||
}
|
||||
|
||||
TEST_CASE("ULP FSM power consumption in deep sleep", "[ulp][ignore]")
|
||||
{
|
||||
assert(COPROC_RESERVE_MEM >= 4 && "this test needs ULP_COPROC_RESERVE_MEM option set in menuconfig");
|
||||
|
||||
/* Clear the RTC_SLOW_MEM region for the ULP co-processor binary to be loaded */
|
||||
memset(RTC_SLOW_MEM, 0, COPROC_RESERVE_MEM);
|
||||
|
||||
/* Put the ULP coprocessor in halt state */
|
||||
ulp_insn_t insn = I_HALT();
|
||||
memcpy(&RTC_SLOW_MEM[0], &insn, sizeof(insn));
|
||||
|
||||
/* Set ULP timer */
|
||||
ulp_set_wakeup_period(0, 0x8000);
|
||||
|
||||
/* Run the ULP coprocessor */
|
||||
TEST_ESP_OK(ulp_run(0));
|
||||
|
||||
/* Setup wakeup triggers */
|
||||
TEST_ASSERT(esp_sleep_enable_ulp_wakeup() == ESP_OK);
|
||||
TEST_ASSERT(esp_sleep_enable_timer_wakeup(10 * 1000000) == ESP_OK);
|
||||
|
||||
/* Enter Deep Sleep */
|
||||
esp_deep_sleep_start();
|
||||
UNITY_TEST_FAIL(__LINE__, "Should not get here!");
|
||||
}
|
||||
|
||||
TEST_CASE("ULP FSM timer setting", "[ulp]")
|
||||
{
|
||||
assert(COPROC_RESERVE_MEM >= 32 && "this test needs ULP_COPROC_RESERVE_MEM option set in menuconfig");
|
||||
|
||||
/* Clear the RTC_SLOW_MEM region for the ULP co-processor binary to be loaded */
|
||||
memset(RTC_SLOW_MEM, 0, COPROC_RESERVE_MEM);
|
||||
|
||||
/*
|
||||
* Run a simple ULP program which increments the counter, for one second.
|
||||
* Program calls I_HALT each time and gets restarted by the timer.
|
||||
* Compare the expected number of times the program runs with the actual.
|
||||
*/
|
||||
const int offset = 6;
|
||||
const ulp_insn_t program[] = {
|
||||
I_MOVI(R1, offset), // r1 <- offset
|
||||
I_LD(R2, R1, 0), // load counter
|
||||
I_ADDI(R2, R2, 1), // counter += 1
|
||||
I_ST(R2, R1, 0), // save counter
|
||||
I_HALT(),
|
||||
};
|
||||
|
||||
/* Calculate the size of the ULP co-processor binary, load it and run the ULP coprocessor */
|
||||
size_t size = sizeof(program)/sizeof(ulp_insn_t);
|
||||
TEST_ESP_OK(ulp_process_macros_and_load(0, program, &size));
|
||||
assert(offset >= size && "data offset needs to be greater or equal to program size");
|
||||
TEST_ESP_OK(ulp_run(0));
|
||||
|
||||
/* Disable the ULP program timer — we will enable it later */
|
||||
ulp_timer_stop();
|
||||
|
||||
/* Define the test data */
|
||||
const uint32_t cycles_to_test[] = { 10000, // 10 ms
|
||||
20000, // 20 ms
|
||||
50000, // 50 ms
|
||||
100000, // 100 ms
|
||||
200000, // 200 ms
|
||||
500000, // 500 ms
|
||||
1000000 }; // 1 sec
|
||||
const size_t tests_count = sizeof(cycles_to_test) / sizeof(cycles_to_test[0]);
|
||||
|
||||
for (size_t i = 0; i < tests_count; ++i) {
|
||||
// zero out the counter
|
||||
RTC_SLOW_MEM[offset] = 0;
|
||||
// set the ulp timer period
|
||||
ulp_set_wakeup_period(0, cycles_to_test[i]);
|
||||
// enable the timer and wait for a second
|
||||
ulp_timer_resume();
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
// stop the timer and get the counter value
|
||||
ulp_timer_stop();
|
||||
uint32_t counter = RTC_SLOW_MEM[offset] & 0xffff;
|
||||
// calculate the expected counter value and allow a tolerance of 15%
|
||||
uint32_t expected_counter = 1000000 / cycles_to_test[i];
|
||||
uint32_t tolerance = (expected_counter * 15 / 100);
|
||||
tolerance = tolerance ? tolerance : 1; // Keep a tolerance of at least 1 count
|
||||
printf("expected: %u\t tolerance: +/- %u\t actual: %u\n", expected_counter, tolerance, counter);
|
||||
// Should be within 15%
|
||||
TEST_ASSERT_INT_WITHIN(tolerance, expected_counter, counter);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("ULP FSM can use temperature sensor (TSENS) in deep sleep", "[ulp][ignore]")
|
||||
{
|
||||
assert(COPROC_RESERVE_MEM >= 260 && "this test needs ULP_COPROC_RESERVE_MEM option set in menuconfig");
|
||||
|
||||
/* Clear the RTC_SLOW_MEM region for the ULP co-processor binary to be loaded */
|
||||
memset(RTC_SLOW_MEM, 0, COPROC_RESERVE_MEM);
|
||||
|
||||
// Allow TSENS to be controlled by the ULP
|
||||
SET_PERI_REG_BITS(SENS_SAR_TSENS_CTRL_REG, SENS_TSENS_CLK_DIV, 10, SENS_TSENS_CLK_DIV_S);
|
||||
#if CONFIG_IDF_TARGET_ESP32
|
||||
SET_PERI_REG_BITS(SENS_SAR_MEAS_WAIT2_REG, SENS_FORCE_XPD_SAR, SENS_FORCE_XPD_SAR_FSM, SENS_FORCE_XPD_SAR_S);
|
||||
#elif CONFIG_IDF_TARGET_ESP32S2
|
||||
SET_PERI_REG_BITS(SENS_SAR_POWER_XPD_SAR_REG, SENS_FORCE_XPD_SAR, SENS_FORCE_XPD_SAR_FSM, SENS_FORCE_XPD_SAR_S);
|
||||
SET_PERI_REG_MASK(SENS_SAR_TSENS_CTRL2_REG, SENS_TSENS_CLKGATE_EN);
|
||||
#elif CONFIG_IDF_TARGET_ESP32S3
|
||||
SET_PERI_REG_BITS(SENS_SAR_POWER_XPD_SAR_REG, SENS_FORCE_XPD_SAR, 0, SENS_FORCE_XPD_SAR_S);
|
||||
SET_PERI_REG_MASK(SENS_SAR_PERI_CLK_GATE_CONF_REG, SENS_TSENS_CLK_EN);
|
||||
#endif
|
||||
CLEAR_PERI_REG_MASK(SENS_SAR_TSENS_CTRL_REG, SENS_TSENS_POWER_UP);
|
||||
CLEAR_PERI_REG_MASK(SENS_SAR_TSENS_CTRL_REG, SENS_TSENS_DUMP_OUT);
|
||||
CLEAR_PERI_REG_MASK(SENS_SAR_TSENS_CTRL_REG, SENS_TSENS_POWER_UP_FORCE);
|
||||
|
||||
// data start offset
|
||||
size_t offset = 20;
|
||||
// number of samples to collect
|
||||
RTC_SLOW_MEM[offset] = (COPROC_RESERVE_MEM) / 4 - offset - 8;
|
||||
// sample counter
|
||||
RTC_SLOW_MEM[offset + 1] = 0;
|
||||
|
||||
/* ULP co-processor program to record temperature sensor readings */
|
||||
const ulp_insn_t program[] = {
|
||||
I_MOVI(R1, offset), // r1 <- offset
|
||||
I_LD(R2, R1, 1), // r2 <- counter
|
||||
I_LD(R3, R1, 0), // r3 <- length
|
||||
I_SUBI(R3, R3, 1), // end = length - 1
|
||||
I_SUBR(R3, R3, R2), // r3 = length - counter
|
||||
M_BXF(1), // if overflow goto 1:
|
||||
I_TSENS(R0, 16383), // r0 <- tsens
|
||||
I_ST(R0, R2, offset + 4), // mem[r2 + offset +4] <- r0
|
||||
I_ADDI(R2, R2, 1), // counter += 1
|
||||
I_ST(R2, R1, 1), // save counter
|
||||
I_HALT(), // enter sleep
|
||||
M_LABEL(1), // done with measurements
|
||||
I_END(), // stop ULP timer
|
||||
I_WAKE(), // initiate wakeup
|
||||
I_HALT()
|
||||
};
|
||||
|
||||
size_t size = sizeof(program)/sizeof(ulp_insn_t);
|
||||
TEST_ESP_OK(ulp_process_macros_and_load(0, program, &size));
|
||||
assert(offset >= size);
|
||||
|
||||
/* Run the ULP coprocessor */
|
||||
TEST_ESP_OK(ulp_run(0));
|
||||
|
||||
/* Setup wakeup triggers */
|
||||
TEST_ASSERT(esp_sleep_enable_ulp_wakeup() == ESP_OK);
|
||||
TEST_ASSERT(esp_sleep_enable_timer_wakeup(10 * 1000000) == ESP_OK);
|
||||
|
||||
/* Enter Deep Sleep */
|
||||
esp_deep_sleep_start();
|
||||
UNITY_TEST_FAIL(__LINE__, "Should not get here!");
|
||||
}
|
||||
|
||||
TEST_CASE("ULP FSM can use ADC in deep sleep", "[ulp][ignore]")
|
||||
{
|
||||
assert(COPROC_RESERVE_MEM >= 260 && "this test needs ULP_COPROC_RESERVE_MEM option set in menuconfig");
|
||||
|
||||
const int adc = 0;
|
||||
const int channel = 0;
|
||||
const int atten = 0;
|
||||
|
||||
/* Clear the RTC_SLOW_MEM region for the ULP co-processor binary to be loaded */
|
||||
memset(RTC_SLOW_MEM, 0, COPROC_RESERVE_MEM);
|
||||
|
||||
#if defined(CONFIG_IDF_TARGET_ESP32)
|
||||
// Configure SAR ADCn resolution
|
||||
SET_PERI_REG_BITS(SENS_SAR_START_FORCE_REG, SENS_SAR1_BIT_WIDTH, 3, SENS_SAR1_BIT_WIDTH_S);
|
||||
SET_PERI_REG_BITS(SENS_SAR_START_FORCE_REG, SENS_SAR2_BIT_WIDTH, 3, SENS_SAR2_BIT_WIDTH_S);
|
||||
SET_PERI_REG_BITS(SENS_SAR_READ_CTRL_REG, SENS_SAR1_SAMPLE_BIT, 0x3, SENS_SAR1_SAMPLE_BIT_S);
|
||||
SET_PERI_REG_BITS(SENS_SAR_READ_CTRL2_REG, SENS_SAR2_SAMPLE_BIT, 0x3, SENS_SAR2_SAMPLE_BIT_S);
|
||||
|
||||
// SAR ADCn is started by ULP FSM
|
||||
CLEAR_PERI_REG_MASK(SENS_SAR_MEAS_START2_REG, SENS_MEAS2_START_FORCE);
|
||||
CLEAR_PERI_REG_MASK(SENS_SAR_MEAS_START1_REG, SENS_MEAS1_START_FORCE);
|
||||
|
||||
// Use ULP FSM to power up SAR ADCn
|
||||
SET_PERI_REG_BITS(SENS_SAR_MEAS_WAIT2_REG, SENS_FORCE_XPD_SAR, 0, SENS_FORCE_XPD_SAR_S);
|
||||
SET_PERI_REG_BITS(SENS_SAR_MEAS_WAIT2_REG, SENS_FORCE_XPD_AMP, 2, SENS_FORCE_XPD_AMP_S);
|
||||
|
||||
// SAR ADCn invert result
|
||||
SET_PERI_REG_MASK(SENS_SAR_READ_CTRL_REG, SENS_SAR1_DATA_INV);
|
||||
SET_PERI_REG_MASK(SENS_SAR_READ_CTRL_REG, SENS_SAR2_DATA_INV);
|
||||
|
||||
// Set SAR ADCn pad enable bitmap to be controlled by ULP FSM
|
||||
CLEAR_PERI_REG_MASK(SENS_SAR_MEAS_START1_REG, SENS_SAR1_EN_PAD_FORCE_M);
|
||||
CLEAR_PERI_REG_MASK(SENS_SAR_MEAS_START2_REG, SENS_SAR2_EN_PAD_FORCE_M);
|
||||
#elif defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3)
|
||||
// SAR ADCn is started by ULP FSM
|
||||
CLEAR_PERI_REG_MASK(SENS_SAR_MEAS2_CTRL2_REG, SENS_MEAS2_START_FORCE);
|
||||
CLEAR_PERI_REG_MASK(SENS_SAR_MEAS1_CTRL2_REG, SENS_MEAS1_START_FORCE);
|
||||
|
||||
// Use ULP FSM to power up/down SAR ADCn
|
||||
SET_PERI_REG_BITS(SENS_SAR_POWER_XPD_SAR_REG, SENS_FORCE_XPD_SAR, 0, SENS_FORCE_XPD_SAR_S);
|
||||
SET_PERI_REG_BITS(SENS_SAR_MEAS1_CTRL1_REG, SENS_FORCE_XPD_AMP, 2, SENS_FORCE_XPD_AMP_S);
|
||||
|
||||
// SAR1 invert result
|
||||
SET_PERI_REG_MASK(SENS_SAR_READER1_CTRL_REG, SENS_SAR1_DATA_INV);
|
||||
SET_PERI_REG_MASK(SENS_SAR_READER2_CTRL_REG, SENS_SAR2_DATA_INV);
|
||||
|
||||
// Set SAR ADCn pad enable bitmap to be controlled by ULP FSM
|
||||
CLEAR_PERI_REG_MASK(SENS_SAR_MEAS1_CTRL2_REG, SENS_SAR1_EN_PAD_FORCE_M);
|
||||
CLEAR_PERI_REG_MASK(SENS_SAR_MEAS2_CTRL2_REG, SENS_SAR2_EN_PAD_FORCE_M);
|
||||
|
||||
// Enable SAR ADCn clock gate on esp32s3
|
||||
#if CONFIG_IDF_TARGET_ESP32S3
|
||||
SET_PERI_REG_MASK(SENS_SAR_PERI_CLK_GATE_CONF_REG, SENS_SARADC_CLK_EN);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
SET_PERI_REG_BITS(SENS_SAR_ATTEN1_REG, 3, atten, 2 * channel); //set SAR1 attenuation
|
||||
SET_PERI_REG_BITS(SENS_SAR_ATTEN2_REG, 3, atten, 2 * channel); //set SAR2 attenuation
|
||||
|
||||
// data start offset
|
||||
size_t offset = 20;
|
||||
// number of samples to collect
|
||||
RTC_SLOW_MEM[offset] = (COPROC_RESERVE_MEM) / 4 - offset - 8;
|
||||
// sample counter
|
||||
RTC_SLOW_MEM[offset + 1] = 0;
|
||||
|
||||
const ulp_insn_t program[] = {
|
||||
I_MOVI(R1, offset), // r1 <- offset
|
||||
I_LD(R2, R1, 1), // r2 <- counter
|
||||
I_LD(R3, R1, 0), // r3 <- length
|
||||
I_SUBI(R3, R3, 1), // end = length - 1
|
||||
I_SUBR(R3, R3, R2), // r3 = length - counter
|
||||
M_BXF(1), // if overflow goto 1:
|
||||
I_ADC(R0, adc, channel), // r0 <- ADC
|
||||
I_ST(R0, R2, offset + 4), // mem[r2 + offset +4] = r0
|
||||
I_ADDI(R2, R2, 1), // counter += 1
|
||||
I_ST(R2, R1, 1), // save counter
|
||||
I_HALT(), // enter sleep
|
||||
M_LABEL(1), // done with measurements
|
||||
I_END(), // stop ULP program timer
|
||||
I_HALT()
|
||||
};
|
||||
|
||||
size_t size = sizeof(program)/sizeof(ulp_insn_t);
|
||||
TEST_ESP_OK(ulp_process_macros_and_load(0, program, &size));
|
||||
assert(offset >= size);
|
||||
|
||||
/* Run the ULP coprocessor */
|
||||
TEST_ESP_OK(ulp_run(0));
|
||||
|
||||
/* Setup wakeup triggers */
|
||||
TEST_ASSERT(esp_sleep_enable_ulp_wakeup() == ESP_OK);
|
||||
TEST_ASSERT(esp_sleep_enable_timer_wakeup(10 * 1000000) == ESP_OK);
|
||||
|
||||
/* Enter Deep Sleep */
|
||||
esp_deep_sleep_start();
|
||||
UNITY_TEST_FAIL(__LINE__, "Should not get here!");
|
||||
}
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#include "soc/rtc_cntl_reg.h"
|
||||
#include "soc/rtc_io_reg.h"
|
||||
#include "soc/soc_ulp.h"
|
@ -61,7 +61,13 @@ esp_err_t ulp_run(uint32_t entry_point)
|
||||
SET_PERI_REG_MASK(RTC_CNTL_OPTIONS0_REG, RTC_CNTL_BIAS_SLEEP_FOLW_8M);
|
||||
// enable ULP timer
|
||||
SET_PERI_REG_MASK(RTC_CNTL_STATE0_REG, RTC_CNTL_ULP_CP_SLP_TIMER_EN);
|
||||
#elif defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3)
|
||||
#else
|
||||
|
||||
/* Reset COCPU when power on. */
|
||||
SET_PERI_REG_MASK(RTC_CNTL_ULP_CP_CTRL_REG, RTC_CNTL_ULP_CP_RESET);
|
||||
esp_rom_delay_us(20);
|
||||
CLEAR_PERI_REG_MASK(RTC_CNTL_ULP_CP_CTRL_REG, RTC_CNTL_ULP_CP_RESET);
|
||||
|
||||
// disable ULP timer
|
||||
CLEAR_PERI_REG_MASK(RTC_CNTL_ULP_CP_TIMER_REG, RTC_CNTL_ULP_CP_SLP_TIMER_EN);
|
||||
// wait for at least 1 RTC_SLOW_CLK cycle
|
||||
@ -73,8 +79,10 @@ esp_err_t ulp_run(uint32_t entry_point)
|
||||
SET_PERI_REG_MASK(RTC_CNTL_ULP_CP_CTRL_REG ,RTC_CNTL_ULP_CP_CLK_FO);
|
||||
// ULP FSM sends the DONE signal.
|
||||
CLEAR_PERI_REG_MASK(RTC_CNTL_COCPU_CTRL_REG, RTC_CNTL_COCPU_DONE_FORCE);
|
||||
/* Set the number of cycles of ULP_TIMER sleep, the wait time required to start ULP */
|
||||
REG_SET_FIELD(RTC_CNTL_ULP_CP_TIMER_REG, RTC_CNTL_ULP_CP_TIMER_SLP_CYCLE, 100);
|
||||
#if CONFIG_IDF_TARGET_ESP32S3
|
||||
/* Set the CLKGATE_EN signal on esp32s3 */
|
||||
SET_PERI_REG_MASK(RTC_CNTL_COCPU_CTRL_REG, RTC_CNTL_COCPU_CLKGATE_EN);
|
||||
#endif
|
||||
/* Clear interrupt COCPU status */
|
||||
REG_WRITE(RTC_CNTL_INT_CLR_REG, RTC_CNTL_COCPU_INT_CLR | RTC_CNTL_COCPU_TRAP_INT_CLR | RTC_CNTL_ULP_CP_INT_CLR);
|
||||
// 1: start with timer. wait ULP_TIMER cnt timer.
|
||||
@ -169,3 +177,21 @@ esp_err_t ulp_set_wakeup_period(size_t period_index, uint32_t period_us)
|
||||
#endif
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
void ulp_timer_stop(void)
|
||||
{
|
||||
#if CONFIG_IDF_TARGET_ESP32
|
||||
CLEAR_PERI_REG_MASK(RTC_CNTL_STATE0_REG, RTC_CNTL_ULP_CP_SLP_TIMER_EN);
|
||||
#else
|
||||
CLEAR_PERI_REG_MASK(RTC_CNTL_ULP_CP_TIMER_REG, RTC_CNTL_ULP_CP_SLP_TIMER_EN);
|
||||
#endif
|
||||
}
|
||||
|
||||
void ulp_timer_resume(void)
|
||||
{
|
||||
#if CONFIG_IDF_TARGET_ESP32
|
||||
SET_PERI_REG_MASK(RTC_CNTL_STATE0_REG, RTC_CNTL_ULP_CP_SLP_TIMER_EN);
|
||||
#else
|
||||
SET_PERI_REG_MASK(RTC_CNTL_ULP_CP_TIMER_REG, RTC_CNTL_ULP_CP_SLP_TIMER_EN);
|
||||
#endif
|
||||
}
|
||||
|
@ -16,17 +16,25 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "sdkconfig.h"
|
||||
|
||||
#include "esp_attr.h"
|
||||
#include "esp_err.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp32/ulp.h"
|
||||
#include "ulp_private.h"
|
||||
|
||||
#include "soc/soc.h"
|
||||
#include "soc/rtc_cntl_reg.h"
|
||||
#include "soc/sens_reg.h"
|
||||
|
||||
#include "sdkconfig.h"
|
||||
#if CONFIG_IDF_TARGET_ESP32
|
||||
#include "esp32/ulp.h"
|
||||
#elif CONFIG_IDF_TARGET_ESP32S2
|
||||
#include "esp32s2/ulp.h"
|
||||
#elif CONFIG_IDF_TARGET_ESP32S3
|
||||
#include "esp32s3/ulp.h"
|
||||
#endif
|
||||
|
||||
|
||||
static const char* TAG = "ulp";
|
||||
|
||||
|
@ -57,6 +57,7 @@ get-started-cmake/get-started-pico-kit-v3 hw-reference/esp32/get-started-p
|
||||
api-guides/build-system-cmake api-guides/build-system
|
||||
api-guides/ulp-cmake api-guides/ulp
|
||||
api-guides/unit-tests-cmake api-guides/unit-tests
|
||||
api-guides/ulps2_instruction_set.rst api-guides/ulp_extended_instruction_set.rst
|
||||
|
||||
api-reference/network/tcpip_adapter api-reference/network/esp_netif
|
||||
|
||||
|
@ -24,6 +24,10 @@
|
||||
|
||||
#if CONFIG_IDF_TARGET_ESP32
|
||||
#include "esp32/ulp.h"
|
||||
#elif CONFIG_IDF_TARGET_ESP32S2
|
||||
#include "esp32s2/ulp.h"
|
||||
#elif CONFIG_IDF_TARGET_ESP32S3
|
||||
#include "esp32s3/ulp.h"
|
||||
#endif
|
||||
|
||||
#if SOC_TOUCH_SENSOR_NUM > 0
|
||||
|
@ -1,9 +1,9 @@
|
||||
| Supported Targets | ESP32 |
|
||||
| ----------------- | ----- |
|
||||
| Supported Targets | ESP32 | ESP32-S2 |
|
||||
| ----------------- | ----- | -------- |
|
||||
|
||||
# ULP Pulse Counting Example
|
||||
|
||||
This example demonstrates how to program the ULP coprocessor to count pulses on an IO while the main CPUs are either running some other code or are in deep sleep. See the README.md file in the upper level 'examples' directory for more information about examples.
|
||||
This example demonstrates how to program the ULP FSM coprocessor to count pulses on an IO while the main CPUs are either running some other code or are in deep sleep. See the README.md file in the upper level 'examples' directory for more information about examples.
|
||||
|
||||
ULP program written in assembly can be found across `ulp/pulse_cnt.S` and `ulp/wake_up.S` (demonstrating multiple ULP source files). The build system assembles and links this program, converts it into binary format, and embeds it into the .rodata section of the ESP-IDF application.
|
||||
|
||||
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
/* ULP Example: pulse counting
|
||||
|
||||
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
||||
@ -22,9 +27,11 @@
|
||||
/* ULP assembly files are passed through C preprocessor first, so include directives
|
||||
and C macros may be used in these files
|
||||
*/
|
||||
#include "sdkconfig.h"
|
||||
#include "soc/rtc_cntl_reg.h"
|
||||
#include "soc/rtc_io_reg.h"
|
||||
#include "soc/soc_ulp.h"
|
||||
#include "soc/sens_reg.h"
|
||||
|
||||
/* Define variables, which go into .bss section (zero-initialized data) */
|
||||
.bss
|
||||
@ -70,6 +77,14 @@ entry:
|
||||
move r3, io_number
|
||||
ld r3, r3, 0
|
||||
|
||||
#if CONFIG_IDF_TARGET_ESP32S2
|
||||
/* ESP32S2 powers down RTC periph when entering deep sleep and thus by association SENS_SAR_IO_MUX_CONF_REG */
|
||||
WRITE_RTC_FIELD(SENS_SAR_IO_MUX_CONF_REG, SENS_IOMUX_CLK_GATE_EN, 1)
|
||||
#elif CONFIG_IDF_TARGET_ESP32S3
|
||||
/* ESP32S3 powers down RTC periph when entering deep sleep and thus by association SENS_SAR_PERI_CLK_GATE_CONF_REG */
|
||||
WRITE_RTC_FIELD(SENS_SAR_PERI_CLK_GATE_CONF_REG, SENS_IOMUX_CLK_EN, 1);
|
||||
#endif
|
||||
|
||||
/* Lower 16 IOs and higher need to be handled separately,
|
||||
* because r0-r3 registers are 16 bit wide.
|
||||
* Check which IO this is.
|
||||
|
@ -16,7 +16,15 @@
|
||||
#include "soc/rtc_periph.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "driver/rtc_io.h"
|
||||
|
||||
#if CONFIG_IDF_TARGET_ESP32
|
||||
#include "esp32/ulp.h"
|
||||
#elif CONFIG_IDF_TARGET_ESP32S2
|
||||
#include "esp32s2/ulp.h"
|
||||
#elif CONFIG_IDF_TARGET_ESP32S3
|
||||
#include "esp32s3/ulp.h"
|
||||
#endif
|
||||
|
||||
#include "ulp_main.h"
|
||||
|
||||
extern const uint8_t ulp_main_bin_start[] asm("_binary_ulp_main_bin_start");
|
||||
@ -28,6 +36,7 @@ static void update_pulse_count(void);
|
||||
void app_main(void)
|
||||
{
|
||||
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
|
||||
printf("cause %d\n", cause);
|
||||
if (cause != ESP_SLEEP_WAKEUP_ULP) {
|
||||
printf("Not ULP wakeup, initializing ULP\n");
|
||||
init_ulp_program();
|
||||
@ -74,12 +83,15 @@ static void init_ulp_program(void)
|
||||
rtc_gpio_pullup_dis(gpio_num);
|
||||
rtc_gpio_hold_en(gpio_num);
|
||||
|
||||
#if CONFIG_IDF_TARGET_ESP32
|
||||
/* Disconnect GPIO12 and GPIO15 to remove current drain through
|
||||
* pullup/pulldown resistors.
|
||||
* pullup/pulldown resistors on modules which have these (e.g. ESP32-WROVER)
|
||||
* GPIO12 may be pulled high to select flash voltage.
|
||||
*/
|
||||
rtc_gpio_isolate(GPIO_NUM_12);
|
||||
rtc_gpio_isolate(GPIO_NUM_15);
|
||||
#endif // CONFIG_IDF_TARGET_ESP32
|
||||
|
||||
esp_deep_sleep_disable_rom_logging(); // suppress boot messages
|
||||
|
||||
/* Set ULP wake up period to T = 20ms.
|
||||
|
@ -1,6 +1,3 @@
|
||||
# Enable ULP
|
||||
CONFIG_ESP32_ULP_COPROC_ENABLED=y
|
||||
CONFIG_ESP32_ULP_COPROC_RESERVE_MEM=1024
|
||||
# Set log level to Warning to produce clean output
|
||||
CONFIG_BOOTLOADER_LOG_LEVEL_WARN=y
|
||||
CONFIG_BOOTLOADER_LOG_LEVEL=2
|
||||
|
3
examples/system/ulp_fsm/ulp/sdkconfig.defaults.esp32
Normal file
3
examples/system/ulp_fsm/ulp/sdkconfig.defaults.esp32
Normal file
@ -0,0 +1,3 @@
|
||||
# Enable ULP
|
||||
CONFIG_ESP32_ULP_COPROC_ENABLED=y
|
||||
CONFIG_ESP32_ULP_COPROC_RESERVE_MEM=1024
|
3
examples/system/ulp_fsm/ulp/sdkconfig.defaults.esp32s2
Normal file
3
examples/system/ulp_fsm/ulp/sdkconfig.defaults.esp32s2
Normal file
@ -0,0 +1,3 @@
|
||||
# Enable ULP
|
||||
CONFIG_ESP32S2_ULP_COPROC_ENABLED=y
|
||||
CONFIG_ESP32S2_ULP_COPROC_RESERVE_MEM=1024
|
3
examples/system/ulp_fsm/ulp/sdkconfig.defaults.esp32s3
Normal file
3
examples/system/ulp_fsm/ulp/sdkconfig.defaults.esp32s3
Normal file
@ -0,0 +1,3 @@
|
||||
# Enable ULP
|
||||
CONFIG_ESP32S3_ULP_COPROC_ENABLED=y
|
||||
CONFIG_ESP32S3_ULP_COPROC_RESERVE_MEM=1024
|
Reference in New Issue
Block a user