mirror of
https://github.com/0xFEEDC0DE64/arduino-esp32.git
synced 2025-07-02 13:30:59 +02:00
v2.0.0 Add support for ESP32S2 and update ESP-IDF to 4.4 (#4996)
This is very much still work in progress and much more will change before the final 2.0.0 Some APIs have changed. New libraries have been added. LittleFS included. Co-authored-by: Seon Rozenblum <seonr@3sprockets.com> Co-authored-by: Me No Dev <me-no-dev@users.noreply.github.com> Co-authored-by: geeksville <kevinh@geeksville.com> Co-authored-by: Mike Dunston <m_dunston@comcast.net> Co-authored-by: Unexpected Maker <seon@unexpectedmaker.com> Co-authored-by: Seon Rozenblum <seonr@3sprockets.com> Co-authored-by: microDev <70126934+microDev1@users.noreply.github.com> Co-authored-by: tobozo <tobozo@users.noreply.github.com> Co-authored-by: bobobo1618 <bobobo1618@users.noreply.github.com> Co-authored-by: lorol <lorolouis@gmail.com> Co-authored-by: geeksville <kevinh@geeksville.com> Co-authored-by: Limor "Ladyada" Fried <limor@ladyada.net> Co-authored-by: Sweety <switi.mhaiske@espressif.com> Co-authored-by: Loick MAHIEUX <loick111@gmail.com> Co-authored-by: Larry Bernstone <lbernstone@gmail.com> Co-authored-by: Valerii Koval <valeros@users.noreply.github.com> Co-authored-by: 快乐的我531 <2302004040@qq.com> Co-authored-by: chegewara <imperiaonline4@gmail.com> Co-authored-by: Clemens Kirchgatterer <clemens@1541.org> Co-authored-by: Aron Rubin <aronrubin@gmail.com> Co-authored-by: Pete Lewis <601236+lewispg228@users.noreply.github.com>
This commit is contained in:
109
tools/sdk/esp32/include/esp_hw_support/include/esp_cpu.h
Normal file
109
tools/sdk/esp32/include/esp_hw_support/include/esp_cpu.h
Normal file
@ -0,0 +1,109 @@
|
||||
// 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.
|
||||
|
||||
#ifndef _ESP_CPU_H
|
||||
#define _ESP_CPU_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "hal/cpu_hal.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define ESP_WATCHPOINT_LOAD 0x40000000
|
||||
#define ESP_WATCHPOINT_STORE 0x80000000
|
||||
#define ESP_WATCHPOINT_ACCESS 0xC0000000
|
||||
|
||||
typedef uint32_t esp_cpu_ccount_t;
|
||||
|
||||
/** @brief Read current stack pointer address
|
||||
*
|
||||
*/
|
||||
static inline void *esp_cpu_get_sp(void)
|
||||
{
|
||||
return cpu_hal_get_sp();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Stall CPU using RTC controller
|
||||
* @param cpu_id ID of the CPU to stall (0 = PRO, 1 = APP)
|
||||
*/
|
||||
void esp_cpu_stall(int cpu_id);
|
||||
|
||||
/**
|
||||
* @brief Un-stall CPU using RTC controller
|
||||
* @param cpu_id ID of the CPU to un-stall (0 = PRO, 1 = APP)
|
||||
*/
|
||||
void esp_cpu_unstall(int cpu_id);
|
||||
|
||||
/**
|
||||
* @brief Reset CPU using RTC controller
|
||||
* @param cpu_id ID of the CPU to reset (0 = PRO, 1 = APP)
|
||||
*/
|
||||
void esp_cpu_reset(int cpu_id);
|
||||
|
||||
/**
|
||||
* @brief Returns true if a JTAG debugger is attached to CPU
|
||||
* OCD (on chip debug) port.
|
||||
*
|
||||
* @note If "Make exception and panic handlers JTAG/OCD aware"
|
||||
* is disabled, this function always returns false.
|
||||
*/
|
||||
bool esp_cpu_in_ocd_debug_mode(void);
|
||||
|
||||
static inline esp_cpu_ccount_t esp_cpu_get_ccount(void)
|
||||
{
|
||||
return cpu_hal_get_cycle_count();
|
||||
}
|
||||
|
||||
static inline void esp_cpu_set_ccount(esp_cpu_ccount_t val)
|
||||
{
|
||||
cpu_hal_set_cycle_count(val);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set a watchpoint to break/panic when a certain memory range is accessed.
|
||||
*
|
||||
* @param no Watchpoint number. On the ESP32, this can be 0 or 1.
|
||||
* @param adr Base address to watch
|
||||
* @param size Size of the region, starting at the base address, to watch. Must
|
||||
* be one of 2^n, with n in [0..6].
|
||||
* @param flags One of ESP_WATCHPOINT_* flags
|
||||
*
|
||||
* @return ESP_ERR_INVALID_ARG on invalid arg, ESP_OK otherwise
|
||||
*
|
||||
* @warning The ESP32 watchpoint hardware watches a region of bytes by effectively
|
||||
* masking away the lower n bits for a region with size 2^n. If adr does
|
||||
* not have zero for these lower n bits, you may not be watching the
|
||||
* region you intended.
|
||||
*/
|
||||
esp_err_t esp_cpu_set_watchpoint(int no, void *adr, int size, int flags);
|
||||
|
||||
/**
|
||||
* @brief Clear a watchpoint
|
||||
*
|
||||
* @param no Watchpoint to clear
|
||||
*
|
||||
*/
|
||||
void esp_cpu_clear_watchpoint(int no);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // _ESP_CPU_H
|
105
tools/sdk/esp32/include/esp_hw_support/include/esp_crc.h
Normal file
105
tools/sdk/esp32/include/esp_hw_support/include/esp_crc.h
Normal file
@ -0,0 +1,105 @@
|
||||
// Copyright 2015-2019 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.
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// This header is only a wrapper on ROM CRC API
|
||||
#include "esp_rom_crc.h"
|
||||
|
||||
/**
|
||||
* @brief CRC32 value in little endian.
|
||||
*
|
||||
* @param crc: Initial CRC value (result of last calculation or 0 for the first time)
|
||||
* @param buf: Data buffer that used to calculate the CRC value
|
||||
* @param len: Length of the data buffer
|
||||
* @return CRC32 value
|
||||
*/
|
||||
static inline uint32_t esp_crc32_le(uint32_t crc, uint8_t const *buf, uint32_t len)
|
||||
{
|
||||
return esp_rom_crc32_le(crc, buf, len);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief CRC32 value in big endian.
|
||||
*
|
||||
* @param crc: Initial CRC value (result of last calculation or 0 for the first time)
|
||||
* @param buf: Data buffer that used to calculate the CRC value
|
||||
* @param len: Length of the data buffer
|
||||
* @return CRC32 value
|
||||
*/
|
||||
static inline uint32_t esp_crc32_be(uint32_t crc, uint8_t const *buf, uint32_t len)
|
||||
{
|
||||
return esp_rom_crc32_be(crc, buf, len);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief CRC16 value in little endian.
|
||||
*
|
||||
* @param crc: Initial CRC value (result of last calculation or 0 for the first time)
|
||||
* @param buf: Data buffer that used to calculate the CRC value
|
||||
* @param len: Length of the data buffer
|
||||
* @return CRC16 value
|
||||
*/
|
||||
static inline uint16_t esp_crc16_le(uint16_t crc, uint8_t const *buf, uint32_t len)
|
||||
{
|
||||
return esp_rom_crc16_le(crc, buf, len);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief CRC16 value in big endian.
|
||||
*
|
||||
* @param crc: Initial CRC value (result of last calculation or 0 for the first time)
|
||||
* @param buf: Data buffer that used to calculate the CRC value
|
||||
* @param len: Length of the data buffer
|
||||
* @return CRC16 value
|
||||
*/
|
||||
static inline uint16_t esp_crc16_be(uint16_t crc, uint8_t const *buf, uint32_t len)
|
||||
{
|
||||
return esp_rom_crc16_be(crc, buf, len);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief CRC8 value in little endian.
|
||||
*
|
||||
* @param crc: Initial CRC value (result of last calculation or 0 for the first time)
|
||||
* @param buf: Data buffer that used to calculate the CRC value
|
||||
* @param len: Length of the data buffer
|
||||
* @return CRC8 value
|
||||
*/
|
||||
static inline uint8_t esp_crc8_le(uint8_t crc, uint8_t const *buf, uint32_t len)
|
||||
{
|
||||
return esp_rom_crc8_le(crc, buf, len);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief CRC8 value in big endian.
|
||||
*
|
||||
* @param crc: Initial CRC value (result of last calculation or 0 for the first time)
|
||||
* @param buf: Data buffer that used to calculate the CRC value
|
||||
* @param len: Length of the data buffer
|
||||
* @return CRC8 value
|
||||
*/
|
||||
static inline uint8_t esp_crc8_be(uint8_t crc, uint8_t const *buf, uint32_t len)
|
||||
{
|
||||
return esp_rom_crc8_be(crc, buf, len);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
99
tools/sdk/esp32/include/esp_hw_support/include/esp_fault.h
Normal file
99
tools/sdk/esp32/include/esp_hw_support/include/esp_fault.h
Normal file
@ -0,0 +1,99 @@
|
||||
// Copyright 2020 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 "sdkconfig.h"
|
||||
#include "soc/rtc_cntl_reg.h"
|
||||
#include "esp_rom_sys.h"
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Assert a condition is true, in a way that should be resistant to fault injection for
|
||||
* single fault attacks.
|
||||
*
|
||||
* - Expands CONDITION multiple times (condition must have no side effects)
|
||||
* - Compiler is told all registers are invalid before evaluating CONDITION each time, to avoid a fault
|
||||
* causing a misread of a register used in all three evaluations of CONDITION.
|
||||
* - If CONDITION is ever false, a system reset is triggered.
|
||||
*
|
||||
* @note Place this macro after a "normal" check of CONDITION that will fail with a normal error
|
||||
* message. This is the fallback in case a fault injection attack skips or corrupts the result of
|
||||
* that check. (Although ensure that an attacker can't use fault injection to skip past the "normal"
|
||||
* error message, to avoid this check entirely.)
|
||||
*
|
||||
* @note This macro increases binary size and is slow and should be used sparingly.
|
||||
*
|
||||
* @note This macro does not guarantee fault injection resistance. In particular CONDITION must be
|
||||
* chosen carefully - a fault injection attack which sets CONDITION to true will not be detected by
|
||||
* this macro. Care must also be taken that an attacker can't use a fault to completely bypass calling
|
||||
* whatever function tests ESP_FAULT_ASSERT.
|
||||
*
|
||||
* @note This is difficult to debug as a failure triggers an instant software reset, and UART output
|
||||
* is often truncated (as FIFO is not flushed). Define the ESP_FAULT_ASSERT_DEBUG macro to debug any
|
||||
* failures of this macro due to software bugs.
|
||||
*
|
||||
* @param CONDITION A condition which will evaluate true unless an attacker used fault injection to skip or corrupt some other critical system calculation.
|
||||
*
|
||||
*/
|
||||
#define ESP_FAULT_ASSERT(CONDITION) do { \
|
||||
asm volatile ("" ::: "memory"); \
|
||||
if(!(CONDITION)) _ESP_FAULT_RESET(); \
|
||||
asm volatile ("" ::: "memory"); \
|
||||
if(!(CONDITION)) _ESP_FAULT_RESET(); \
|
||||
asm volatile ("" ::: "memory"); \
|
||||
if(!(CONDITION)) _ESP_FAULT_RESET(); \
|
||||
} while(0)
|
||||
|
||||
#ifndef CONFIG_IDF_TARGET_ARCH_RISCV
|
||||
#define _ESP_FAULT_ILLEGAL_INSTRUCTION asm volatile("ill.n; ill.n; ill.n; ill.n; ill.n; ill.n; ill.n;")
|
||||
#else
|
||||
#define _ESP_FAULT_ILLEGAL_INSTRUCTION asm volatile("unimp; unimp; unimp; unimp; unimp;")
|
||||
#endif
|
||||
|
||||
// Uncomment this macro to get debug output if ESP_FAULT_ASSERT() fails
|
||||
//
|
||||
// Note that uncommenting this macro reduces the anti-FI effectiveness
|
||||
//
|
||||
//#define ESP_FAULT_ASSERT_DEBUG
|
||||
|
||||
/* Internal macro, purpose is to trigger a system reset if an inconsistency due to fault injection
|
||||
is detected.
|
||||
|
||||
Illegal instruction opcodes are there as a fallback to crash the CPU in case it doesn't
|
||||
reset as expected.
|
||||
*/
|
||||
#ifndef ESP_FAULT_ASSERT_DEBUG
|
||||
|
||||
#define _ESP_FAULT_RESET() do { \
|
||||
REG_WRITE(RTC_CNTL_OPTIONS0_REG, RTC_CNTL_SW_SYS_RST); \
|
||||
_ESP_FAULT_ILLEGAL_INSTRUCTION; \
|
||||
} while(0)
|
||||
|
||||
#else // ESP_FAULT_ASSERT_DEBUG
|
||||
|
||||
#warning "Enabling ESP_FAULT_ASSERT_DEBUG makes ESP_FAULT_ASSERT() less effective"
|
||||
|
||||
#define _ESP_FAULT_RESET() do { \
|
||||
esp_rom_printf("ESP_FAULT_ASSERT %s:%d\n", __FILE__, __LINE__); \
|
||||
_ESP_FAULT_ILLEGAL_INSTRUCTION; \
|
||||
} while(0)
|
||||
|
||||
#endif // ESP_FAULT_ASSERT_DEBUG
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -0,0 +1,37 @@
|
||||
// Copyright 2015-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.
|
||||
|
||||
|
||||
#ifndef __ESP_INTERFACE_H__
|
||||
#define __ESP_INTERFACE_H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
ESP_IF_WIFI_STA = 0, /**< ESP32 station interface */
|
||||
ESP_IF_WIFI_AP, /**< ESP32 soft-AP interface */
|
||||
ESP_IF_ETH, /**< ESP32 ethernet interface */
|
||||
ESP_IF_MAX
|
||||
} esp_interface_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* __ESP_INTERFACE_TYPES_H__ */
|
@ -0,0 +1,50 @@
|
||||
// Copyright 2020 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 "soc/rtc.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief This function is used to enable the digital 8m rtc clock,
|
||||
* to support the peripherals.
|
||||
*
|
||||
* @note If this function is called a number of times, the `periph_rtc_dig_clk8m_disable`
|
||||
* function needs to be called same times to disable.
|
||||
*
|
||||
* @return true: success for enable the rtc 8M clock, false: rtc 8M clock enable failed
|
||||
*/
|
||||
bool periph_rtc_dig_clk8m_enable(void);
|
||||
|
||||
/**
|
||||
* @brief This function is used to disable the rtc digital clock, which should be called
|
||||
* with the `periph_rtc_dig_clk8m_enable` pairedly
|
||||
*
|
||||
* @note If this function is called a number of times, the `periph_rtc_dig_clk8m_disable`
|
||||
* function needs to be called same times to disable.
|
||||
*/
|
||||
void periph_rtc_dig_clk8m_disable(void);
|
||||
|
||||
/**
|
||||
* @brief This function is used to get the real clock frequency value of the rtc clock
|
||||
*
|
||||
* @return The real clock value
|
||||
*/
|
||||
uint32_t periph_rtc_dig_clk8m_get_freq(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -0,0 +1,74 @@
|
||||
// Copyright 2015-2019 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.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "soc/cpu.h"
|
||||
#include "soc/soc_memory_layout.h"
|
||||
|
||||
#if __XTENSA__
|
||||
#include "xtensa/xtruntime.h"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
static inline void __attribute__((always_inline)) compare_and_set_native(volatile uint32_t *addr, uint32_t compare, uint32_t *set)
|
||||
{
|
||||
#if (XCHAL_HAVE_S32C1I > 0)
|
||||
__asm__ __volatile__ (
|
||||
"WSR %2,SCOMPARE1 \n"
|
||||
"S32C1I %0, %1, 0 \n"
|
||||
:"=r"(*set)
|
||||
:"r"(addr), "r"(compare), "0"(*set)
|
||||
);
|
||||
#else
|
||||
uint32_t old_value;
|
||||
|
||||
#ifdef __XTENSA__
|
||||
// No S32C1I, so do this by disabling and re-enabling interrupts (slower)
|
||||
uint32_t intlevel;
|
||||
__asm__ __volatile__ ("rsil %0, " XTSTR(XCHAL_EXCM_LEVEL) "\n"
|
||||
: "=r"(intlevel));
|
||||
#else
|
||||
unsigned old_mstatus = RV_CLEAR_CSR(mstatus, MSTATUS_MIE);
|
||||
#endif
|
||||
|
||||
old_value = *addr;
|
||||
if (old_value == compare) {
|
||||
*addr = *set;
|
||||
}
|
||||
|
||||
#ifdef __XTENSA__
|
||||
__asm__ __volatile__ ("memw \n"
|
||||
"wsr %0, ps\n"
|
||||
:: "r"(intlevel));
|
||||
|
||||
#else
|
||||
RV_SET_CSR(mstatus, old_mstatus & MSTATUS_MIE);
|
||||
#endif
|
||||
|
||||
*set = old_value;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void compare_and_set_extram(volatile uint32_t *addr, uint32_t compare, uint32_t *set);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
66
tools/sdk/esp32/include/esp_hw_support/include/soc/cpu.h
Normal file
66
tools/sdk/esp32/include/esp_hw_support/include/soc/cpu.h
Normal file
@ -0,0 +1,66 @@
|
||||
// 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.
|
||||
|
||||
#ifndef _SOC_CPU_H
|
||||
#define _SOC_CPU_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "esp_cpu.h"
|
||||
|
||||
#if __XTENSA__
|
||||
#include "xt_instr_macros.h"
|
||||
// [refactor-todo] not actually needed in this header now,
|
||||
// but kept for compatibility
|
||||
#include "xtensa/corebits.h"
|
||||
#include "xtensa/config/core.h"
|
||||
|
||||
#include "xtensa/config/specreg.h"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @brief Read current stack pointer address.
|
||||
* Superseded by esp_cpu_get_sp in esp_cpu.h.
|
||||
*/
|
||||
static inline __attribute__((deprecated)) void *get_sp(void)
|
||||
{
|
||||
return esp_cpu_get_sp();
|
||||
}
|
||||
|
||||
static inline uint32_t esp_cpu_process_stack_pc(uint32_t pc)
|
||||
{
|
||||
if (pc & 0x80000000) {
|
||||
//Top two bits of a0 (return address) specify window increment. Overwrite to map to address space.
|
||||
pc = (pc & 0x3fffffff) | 0x40000000;
|
||||
}
|
||||
//Minus 3 to get PC of previous instruction (i.e. instruction executed before return address)
|
||||
return pc - 3;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure CPU to disable access to invalid memory regions
|
||||
*
|
||||
*/
|
||||
void esp_cpu_configure_region_protection(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
198
tools/sdk/esp32/include/esp_hw_support/include/soc/rtc_wdt.h
Normal file
198
tools/sdk/esp32/include/esp_hw_support/include/soc/rtc_wdt.h
Normal file
@ -0,0 +1,198 @@
|
||||
// Copyright 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.
|
||||
|
||||
/* Recommendation of using API RTC_WDT.
|
||||
1) Setting and enabling rtc_wdt:
|
||||
@code
|
||||
rtc_wdt_protect_off();
|
||||
rtc_wdt_disable();
|
||||
rtc_wdt_set_length_of_reset_signal(RTC_WDT_SYS_RESET_SIG, RTC_WDT_LENGTH_3_2us);
|
||||
rtc_wdt_set_stage(RTC_WDT_STAGE0, RTC_WDT_STAGE_ACTION_RESET_SYSTEM); //RTC_WDT_STAGE_ACTION_RESET_SYSTEM or RTC_WDT_STAGE_ACTION_RESET_RTC
|
||||
rtc_wdt_set_time(RTC_WDT_STAGE0, 7000); // timeout rtd_wdt 7000ms.
|
||||
rtc_wdt_enable();
|
||||
rtc_wdt_protect_on();
|
||||
@endcode
|
||||
|
||||
* If you use this option RTC_WDT_STAGE_ACTION_RESET_SYSTEM then after reset you can see these messages.
|
||||
They can help to understand where the CPUs were when the WDT was triggered.
|
||||
W (30) boot: PRO CPU has been reset by WDT.
|
||||
W (30) boot: WDT reset info: PRO CPU PC=0x400xxxxx
|
||||
... function where it happened
|
||||
|
||||
W (31) boot: WDT reset info: APP CPU PC=0x400xxxxx
|
||||
... function where it happened
|
||||
|
||||
* If you use this option RTC_WDT_STAGE_ACTION_RESET_RTC then you will see message (rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT))
|
||||
without description where were CPUs when it happened.
|
||||
|
||||
2) Reset counter of rtc_wdt:
|
||||
@code
|
||||
rtc_wdt_feed();
|
||||
@endcode
|
||||
|
||||
3) Disable rtc_wdt:
|
||||
@code
|
||||
rtc_wdt_disable();
|
||||
@endcode
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "soc/rtc_periph.h"
|
||||
#include "esp_err.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/// List of stage of rtc watchdog. WDT has 4 stage.
|
||||
typedef enum {
|
||||
RTC_WDT_STAGE0 = 0, /*!< Stage 0 */
|
||||
RTC_WDT_STAGE1 = 1, /*!< Stage 1 */
|
||||
RTC_WDT_STAGE2 = 2, /*!< Stage 2 */
|
||||
RTC_WDT_STAGE3 = 3 /*!< Stage 3 */
|
||||
} rtc_wdt_stage_t;
|
||||
|
||||
/// List of action. When the time of stage expires this action will be triggered.
|
||||
typedef enum {
|
||||
RTC_WDT_STAGE_ACTION_OFF = RTC_WDT_STG_SEL_OFF, /*!< Disabled. This stage will have no effects on the system. */
|
||||
RTC_WDT_STAGE_ACTION_INTERRUPT = RTC_WDT_STG_SEL_INT, /*!< Trigger an interrupt. When the stage expires an interrupt is triggered. */
|
||||
RTC_WDT_STAGE_ACTION_RESET_CPU = RTC_WDT_STG_SEL_RESET_CPU, /*!< Reset a CPU core. */
|
||||
RTC_WDT_STAGE_ACTION_RESET_SYSTEM = RTC_WDT_STG_SEL_RESET_SYSTEM, /*!< Reset the main system includes the CPU and all peripherals. The RTC is an exception to this, and it will not be reset. */
|
||||
RTC_WDT_STAGE_ACTION_RESET_RTC = RTC_WDT_STG_SEL_RESET_RTC /*!< Reset the main system and the RTC. */
|
||||
} rtc_wdt_stage_action_t;
|
||||
|
||||
/// Type of reset signal
|
||||
typedef enum {
|
||||
RTC_WDT_SYS_RESET_SIG = 0, /*!< System reset signal length selection */
|
||||
RTC_WDT_CPU_RESET_SIG = 1 /*!< CPU reset signal length selection */
|
||||
} rtc_wdt_reset_sig_t;
|
||||
|
||||
/// Length of reset signal
|
||||
typedef enum {
|
||||
RTC_WDT_LENGTH_100ns = 0, /*!< 100 ns */
|
||||
RTC_WDT_LENGTH_200ns = 1, /*!< 200 ns */
|
||||
RTC_WDT_LENGTH_300ns = 2, /*!< 300 ns */
|
||||
RTC_WDT_LENGTH_400ns = 3, /*!< 400 ns */
|
||||
RTC_WDT_LENGTH_500ns = 4, /*!< 500 ns */
|
||||
RTC_WDT_LENGTH_800ns = 5, /*!< 800 ns */
|
||||
RTC_WDT_LENGTH_1_6us = 6, /*!< 1.6 us */
|
||||
RTC_WDT_LENGTH_3_2us = 7 /*!< 3.2 us */
|
||||
} rtc_wdt_length_sig_t;
|
||||
|
||||
/**
|
||||
* @brief Get status of protect of rtc_wdt.
|
||||
*
|
||||
* @return
|
||||
* - True if the protect of RTC_WDT is set
|
||||
*/
|
||||
bool rtc_wdt_get_protect_status(void);
|
||||
|
||||
/**
|
||||
* @brief Set protect of rtc_wdt.
|
||||
*/
|
||||
void rtc_wdt_protect_on(void);
|
||||
|
||||
/**
|
||||
* @brief Reset protect of rtc_wdt.
|
||||
*/
|
||||
void rtc_wdt_protect_off(void);
|
||||
|
||||
/**
|
||||
* @brief Enable rtc_wdt.
|
||||
*/
|
||||
void rtc_wdt_enable(void);
|
||||
|
||||
/**
|
||||
* @brief Enable the flash boot protection procedure for WDT.
|
||||
*
|
||||
* Do not recommend to use it in the app.
|
||||
* This function was added to be compatibility with the old bootloaders.
|
||||
* This mode is disabled in bootloader or using rtc_wdt_disable() function.
|
||||
*/
|
||||
void rtc_wdt_flashboot_mode_enable(void);
|
||||
|
||||
/**
|
||||
* @brief Disable rtc_wdt.
|
||||
*/
|
||||
void rtc_wdt_disable(void);
|
||||
|
||||
/**
|
||||
* @brief Reset counter rtc_wdt.
|
||||
*
|
||||
* It returns to stage 0 and its expiry counter restarts from 0.
|
||||
*/
|
||||
void rtc_wdt_feed(void);
|
||||
|
||||
/**
|
||||
* @brief Set time for required stage.
|
||||
*
|
||||
* @param[in] stage Stage of rtc_wdt.
|
||||
* @param[in] timeout_ms Timeout for this stage.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK In case of success
|
||||
* - ESP_ERR_INVALID_ARG If stage has invalid value
|
||||
*/
|
||||
esp_err_t rtc_wdt_set_time(rtc_wdt_stage_t stage, unsigned int timeout_ms);
|
||||
|
||||
/**
|
||||
* @brief Get the timeout set for the required stage.
|
||||
*
|
||||
* @param[in] stage Stage of rtc_wdt.
|
||||
* @param[out] timeout_ms Timeout set for this stage. (not elapsed time).
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK In case of success
|
||||
* - ESP_ERR_INVALID_ARG If stage has invalid value
|
||||
*/
|
||||
esp_err_t rtc_wdt_get_timeout(rtc_wdt_stage_t stage, unsigned int* timeout_ms);
|
||||
|
||||
/**
|
||||
* @brief Set an action for required stage.
|
||||
*
|
||||
* @param[in] stage Stage of rtc_wdt.
|
||||
* @param[in] stage_sel Action for this stage. When the time of stage expires this action will be triggered.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK In case of success
|
||||
* - ESP_ERR_INVALID_ARG If stage or stage_sel have invalid value
|
||||
*/
|
||||
esp_err_t rtc_wdt_set_stage(rtc_wdt_stage_t stage, rtc_wdt_stage_action_t stage_sel);
|
||||
|
||||
/**
|
||||
* @brief Set a length of reset signal.
|
||||
*
|
||||
* @param[in] reset_src Type of reset signal.
|
||||
* @param[in] reset_signal_length A length of reset signal.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK In case of success
|
||||
* - ESP_ERR_INVALID_ARG If reset_src or reset_signal_length have invalid value
|
||||
*/
|
||||
esp_err_t rtc_wdt_set_length_of_reset_signal(rtc_wdt_reset_sig_t reset_src, rtc_wdt_length_sig_t reset_signal_length);
|
||||
|
||||
/**
|
||||
* @brief Return true if rtc_wdt is enabled.
|
||||
*
|
||||
* @return
|
||||
* - True rtc_wdt is enabled
|
||||
*/
|
||||
bool rtc_wdt_is_on(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
164
tools/sdk/esp32/include/esp_hw_support/include/soc/spinlock.h
Normal file
164
tools/sdk/esp32/include/esp_hw_support/include/soc/spinlock.h
Normal file
@ -0,0 +1,164 @@
|
||||
// Copyright 2015-2019 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.
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "sdkconfig.h"
|
||||
#include "soc/cpu.h"
|
||||
#include "hal/cpu_hal.h"
|
||||
#include "soc/soc_memory_layout.h"
|
||||
#include "soc/compare_set.h"
|
||||
|
||||
#if __XTENSA__
|
||||
#include "xtensa/xtruntime.h"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SPIRAM_WORKAROUND_NEED_VOLATILE_SPINLOCK
|
||||
#define NEED_VOLATILE_MUX volatile
|
||||
#else
|
||||
#define NEED_VOLATILE_MUX
|
||||
#endif
|
||||
|
||||
#define SPINLOCK_FREE 0xB33FFFFF
|
||||
#define SPINLOCK_WAIT_FOREVER (-1)
|
||||
#define SPINLOCK_NO_WAIT 0
|
||||
#define SPINLOCK_INITIALIZER {.owner = SPINLOCK_FREE,.count = 0}
|
||||
#define CORE_ID_REGVAL_XOR_SWAP (0xCDCD ^ 0xABAB)
|
||||
|
||||
typedef struct {
|
||||
NEED_VOLATILE_MUX uint32_t owner;
|
||||
NEED_VOLATILE_MUX uint32_t count;
|
||||
}spinlock_t;
|
||||
|
||||
/**
|
||||
* @brief Initialize a lock to its default state - unlocked
|
||||
* @param lock - spinlock object to initialize
|
||||
*/
|
||||
static inline void __attribute__((always_inline)) spinlock_initialize(spinlock_t *lock)
|
||||
{
|
||||
assert(lock);
|
||||
#if !CONFIG_FREERTOS_UNICORE
|
||||
lock->owner = SPINLOCK_FREE;
|
||||
lock->count = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Top level spinlock acquire function, spins until get the lock
|
||||
* @param lock - target spinlock object
|
||||
* @param timeout - cycles to wait, passing SPINLOCK_WAIT_FOREVER blocs indefinitely
|
||||
*/
|
||||
static inline bool __attribute__((always_inline)) spinlock_acquire(spinlock_t *lock, int32_t timeout)
|
||||
{
|
||||
#if !CONFIG_FREERTOS_UNICORE && !BOOTLOADER_BUILD
|
||||
uint32_t result;
|
||||
uint32_t irq_status;
|
||||
uint32_t ccount_start;
|
||||
uint32_t core_id, other_core_id;
|
||||
|
||||
assert(lock);
|
||||
irq_status = XTOS_SET_INTLEVEL(XCHAL_EXCM_LEVEL);
|
||||
|
||||
if(timeout != SPINLOCK_WAIT_FOREVER){
|
||||
RSR(CCOUNT, ccount_start);
|
||||
}
|
||||
|
||||
/*spin until we own a core */
|
||||
RSR(PRID, core_id);
|
||||
|
||||
/* Note: coreID is the full 32 bit core ID (CORE_ID_REGVAL_PRO/CORE_ID_REGVAL_APP) */
|
||||
|
||||
other_core_id = CORE_ID_REGVAL_XOR_SWAP ^ core_id;
|
||||
do {
|
||||
|
||||
/* lock->owner should be one of SPINLOCK_FREE, CORE_ID_REGVAL_PRO,
|
||||
* CORE_ID_REGVAL_APP:
|
||||
* - If SPINLOCK_FREE, we want to atomically set to 'core_id'.
|
||||
* - If "our" core_id, we can drop through immediately.
|
||||
* - If "other_core_id", we spin here.
|
||||
*/
|
||||
result = core_id;
|
||||
|
||||
#if defined(CONFIG_ESP32_SPIRAM_SUPPORT)
|
||||
if (esp_ptr_external_ram(lock)) {
|
||||
compare_and_set_extram(&lock->owner, SPINLOCK_FREE, &result);
|
||||
} else {
|
||||
#endif
|
||||
compare_and_set_native(&lock->owner, SPINLOCK_FREE, &result);
|
||||
#if defined(CONFIG_ESP32_SPIRAM_SUPPORT)
|
||||
}
|
||||
#endif
|
||||
if(result != other_core_id) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (timeout != SPINLOCK_WAIT_FOREVER) {
|
||||
uint32_t ccount_now;
|
||||
ccount_now = cpu_hal_get_cycle_count();
|
||||
if (ccount_now - ccount_start > (unsigned)timeout) {
|
||||
XTOS_RESTORE_INTLEVEL(irq_status);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}while(1);
|
||||
|
||||
/* any other value implies memory corruption or uninitialized mux */
|
||||
assert(result == core_id || result == SPINLOCK_FREE);
|
||||
assert((result == SPINLOCK_FREE) == (lock->count == 0)); /* we're first to lock iff count is zero */
|
||||
assert(lock->count < 0xFF); /* Bad count value implies memory corruption */
|
||||
|
||||
lock->count++;
|
||||
XTOS_RESTORE_INTLEVEL(irq_status);
|
||||
return true;
|
||||
|
||||
#else // !CONFIG_FREERTOS_UNICORE
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Top level spinlock unlock function, unlocks a previously locked spinlock
|
||||
* @param lock - target, locked before, spinlock object
|
||||
*/
|
||||
static inline void __attribute__((always_inline)) spinlock_release(spinlock_t *lock)
|
||||
{
|
||||
#if !CONFIG_FREERTOS_UNICORE && !BOOTLOADER_BUILD
|
||||
uint32_t irq_status;
|
||||
uint32_t core_id;
|
||||
|
||||
assert(lock);
|
||||
irq_status = XTOS_SET_INTLEVEL(XCHAL_EXCM_LEVEL);
|
||||
|
||||
RSR(PRID, core_id);
|
||||
assert(core_id == lock->owner); // This is a mutex we didn't lock, or it's corrupt
|
||||
lock->count--;
|
||||
|
||||
if(!lock->count) {
|
||||
lock->owner = SPINLOCK_FREE;
|
||||
} else {
|
||||
assert(lock->count < 0x100); // Indicates memory corruption
|
||||
}
|
||||
|
||||
XTOS_RESTORE_INTLEVEL(irq_status);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
51
tools/sdk/esp32/include/esp_hw_support/include/soc_log.h
Normal file
51
tools/sdk/esp32/include/esp_hw_support/include/soc_log.h
Normal file
@ -0,0 +1,51 @@
|
||||
// Copyright 2016-2017 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.
|
||||
|
||||
#pragma once
|
||||
#include "esp_rom_sys.h"
|
||||
|
||||
/**
|
||||
* @file soc_log.h
|
||||
* @brief SOC library logging functions
|
||||
*
|
||||
* To make SOC library compatible with environments which don't use ESP-IDF,
|
||||
* this header file provides wrappers for logging functions.
|
||||
*/
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
#include "esp_log.h"
|
||||
#define SOC_LOGE(tag, fmt, ...) ESP_EARLY_LOGE(tag, fmt, ##__VA_ARGS__)
|
||||
#define SOC_LOGW(tag, fmt, ...) ESP_EARLY_LOGW(tag, fmt, ##__VA_ARGS__)
|
||||
#define SOC_LOGI(tag, fmt, ...) ESP_EARLY_LOGI(tag, fmt, ##__VA_ARGS__)
|
||||
#define SOC_LOGD(tag, fmt, ...) ESP_EARLY_LOGD(tag, fmt, ##__VA_ARGS__)
|
||||
#define SOC_LOGV(tag, fmt, ...) ESP_EARLY_LOGV(tag, fmt, ##__VA_ARGS__)
|
||||
|
||||
#else
|
||||
#include "sdkconfig.h"
|
||||
#ifdef CONFIG_IDF_TARGET_ESP32
|
||||
#include "esp32/rom/ets_sys.h" // will be removed in idf v5.0
|
||||
#elif CONFIG_IDF_TARGET_ESP32S2
|
||||
#include "esp32s2/rom/ets_sys.h"
|
||||
#elif CONFIG_IDF_TARGET_ESP32S3
|
||||
#include "esp32s3/rom/ets_sys.h"
|
||||
#elif CONFIG_IDF_TARGET_ESP32C3
|
||||
#include "esp32c3/rom/ets_sys.h"
|
||||
#endif
|
||||
|
||||
#define SOC_LOGE(tag, fmt, ...) esp_rom_printf("%s(err): " fmt, tag, ##__VA_ARGS__)
|
||||
#define SOC_LOGW(tag, fmt, ...) esp_rom_printf("%s(warn): " fmt, tag, ##__VA_ARGS__)
|
||||
#define SOC_LOGI(tag, fmt, ...) esp_rom_printf("%s(info): " fmt, tag, ##__VA_ARGS__)
|
||||
#define SOC_LOGD(tag, fmt, ...) esp_rom_printf("%s(dbg): " fmt, tag, ##__VA_ARGS__)
|
||||
#define SOC_LOGV(tag, fmt, ...) esp_rom_printf("%s: " fmt, tag, ##__VA_ARGS__)
|
||||
#endif //ESP_PLATFORM
|
@ -0,0 +1,135 @@
|
||||
// Copyright 2015-2017 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.
|
||||
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* @file regi2c_apll.h
|
||||
* @brief Register definitions for audio PLL (APLL)
|
||||
*
|
||||
* This file lists register fields of APLL, located on an internal configuration
|
||||
* bus. These definitions are used via macros defined in regi2c_ctrl.h, by
|
||||
* rtc_clk_apll_enable function in rtc_clk.c.
|
||||
*/
|
||||
|
||||
#define I2C_APLL 0X6D
|
||||
#define I2C_APLL_HOSTID 3
|
||||
|
||||
#define I2C_APLL_IR_CAL_DELAY 0
|
||||
#define I2C_APLL_IR_CAL_DELAY_MSB 3
|
||||
#define I2C_APLL_IR_CAL_DELAY_LSB 0
|
||||
|
||||
#define I2C_APLL_IR_CAL_RSTB 0
|
||||
#define I2C_APLL_IR_CAL_RSTB_MSB 4
|
||||
#define I2C_APLL_IR_CAL_RSTB_LSB 4
|
||||
|
||||
#define I2C_APLL_IR_CAL_START 0
|
||||
#define I2C_APLL_IR_CAL_START_MSB 5
|
||||
#define I2C_APLL_IR_CAL_START_LSB 5
|
||||
|
||||
#define I2C_APLL_IR_CAL_UNSTOP 0
|
||||
#define I2C_APLL_IR_CAL_UNSTOP_MSB 6
|
||||
#define I2C_APLL_IR_CAL_UNSTOP_LSB 6
|
||||
|
||||
#define I2C_APLL_OC_ENB_FCAL 0
|
||||
#define I2C_APLL_OC_ENB_FCAL_MSB 7
|
||||
#define I2C_APLL_OC_ENB_FCAL_LSB 7
|
||||
|
||||
#define I2C_APLL_IR_CAL_EXT_CAP 1
|
||||
#define I2C_APLL_IR_CAL_EXT_CAP_MSB 4
|
||||
#define I2C_APLL_IR_CAL_EXT_CAP_LSB 0
|
||||
|
||||
#define I2C_APLL_IR_CAL_ENX_CAP 1
|
||||
#define I2C_APLL_IR_CAL_ENX_CAP_MSB 5
|
||||
#define I2C_APLL_IR_CAL_ENX_CAP_LSB 5
|
||||
|
||||
#define I2C_APLL_OC_LBW 1
|
||||
#define I2C_APLL_OC_LBW_MSB 6
|
||||
#define I2C_APLL_OC_LBW_LSB 6
|
||||
|
||||
#define I2C_APLL_IR_CAL_CK_DIV 2
|
||||
#define I2C_APLL_IR_CAL_CK_DIV_MSB 3
|
||||
#define I2C_APLL_IR_CAL_CK_DIV_LSB 0
|
||||
|
||||
#define I2C_APLL_OC_DCHGP 2
|
||||
#define I2C_APLL_OC_DCHGP_MSB 6
|
||||
#define I2C_APLL_OC_DCHGP_LSB 4
|
||||
|
||||
#define I2C_APLL_OC_ENB_VCON 2
|
||||
#define I2C_APLL_OC_ENB_VCON_MSB 7
|
||||
#define I2C_APLL_OC_ENB_VCON_LSB 7
|
||||
|
||||
#define I2C_APLL_OR_CAL_CAP 3
|
||||
#define I2C_APLL_OR_CAL_CAP_MSB 4
|
||||
#define I2C_APLL_OR_CAL_CAP_LSB 0
|
||||
|
||||
#define I2C_APLL_OR_CAL_UDF 3
|
||||
#define I2C_APLL_OR_CAL_UDF_MSB 5
|
||||
#define I2C_APLL_OR_CAL_UDF_LSB 5
|
||||
|
||||
#define I2C_APLL_OR_CAL_OVF 3
|
||||
#define I2C_APLL_OR_CAL_OVF_MSB 6
|
||||
#define I2C_APLL_OR_CAL_OVF_LSB 6
|
||||
|
||||
#define I2C_APLL_OR_CAL_END 3
|
||||
#define I2C_APLL_OR_CAL_END_MSB 7
|
||||
#define I2C_APLL_OR_CAL_END_LSB 7
|
||||
|
||||
#define I2C_APLL_OR_OUTPUT_DIV 4
|
||||
#define I2C_APLL_OR_OUTPUT_DIV_MSB 4
|
||||
#define I2C_APLL_OR_OUTPUT_DIV_LSB 0
|
||||
|
||||
#define I2C_APLL_OC_TSCHGP 4
|
||||
#define I2C_APLL_OC_TSCHGP_MSB 6
|
||||
#define I2C_APLL_OC_TSCHGP_LSB 6
|
||||
|
||||
#define I2C_APLL_EN_FAST_CAL 4
|
||||
#define I2C_APLL_EN_FAST_CAL_MSB 7
|
||||
#define I2C_APLL_EN_FAST_CAL_LSB 7
|
||||
|
||||
#define I2C_APLL_OC_DHREF_SEL 5
|
||||
#define I2C_APLL_OC_DHREF_SEL_MSB 1
|
||||
#define I2C_APLL_OC_DHREF_SEL_LSB 0
|
||||
|
||||
#define I2C_APLL_OC_DLREF_SEL 5
|
||||
#define I2C_APLL_OC_DLREF_SEL_MSB 3
|
||||
#define I2C_APLL_OC_DLREF_SEL_LSB 2
|
||||
|
||||
#define I2C_APLL_SDM_DITHER 5
|
||||
#define I2C_APLL_SDM_DITHER_MSB 4
|
||||
#define I2C_APLL_SDM_DITHER_LSB 4
|
||||
|
||||
#define I2C_APLL_SDM_STOP 5
|
||||
#define I2C_APLL_SDM_STOP_MSB 5
|
||||
#define I2C_APLL_SDM_STOP_LSB 5
|
||||
|
||||
#define I2C_APLL_SDM_RSTB 5
|
||||
#define I2C_APLL_SDM_RSTB_MSB 6
|
||||
#define I2C_APLL_SDM_RSTB_LSB 6
|
||||
|
||||
#define I2C_APLL_OC_DVDD 6
|
||||
#define I2C_APLL_OC_DVDD_MSB 4
|
||||
#define I2C_APLL_OC_DVDD_LSB 0
|
||||
|
||||
#define I2C_APLL_DSDM2 7
|
||||
#define I2C_APLL_DSDM2_MSB 5
|
||||
#define I2C_APLL_DSDM2_LSB 0
|
||||
|
||||
#define I2C_APLL_DSDM1 8
|
||||
#define I2C_APLL_DSDM1_MSB 7
|
||||
#define I2C_APLL_DSDM1_LSB 0
|
||||
|
||||
#define I2C_APLL_DSDM0 9
|
||||
#define I2C_APLL_DSDM0_MSB 7
|
||||
#define I2C_APLL_DSDM0_LSB 0
|
@ -0,0 +1,207 @@
|
||||
// Copyright 2015-2017 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.
|
||||
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* @file regi2c_apll.h
|
||||
* @brief Register definitions for digital PLL (BBPLL)
|
||||
*
|
||||
* This file lists register fields of BBPLL, located on an internal configuration
|
||||
* bus. These definitions are used via macros defined in regi2c_ctrl.h, by
|
||||
* rtc_clk_cpu_freq_set function in rtc_clk.c.
|
||||
*/
|
||||
|
||||
#define I2C_BBPLL 0x66
|
||||
#define I2C_BBPLL_HOSTID 4
|
||||
|
||||
#define I2C_BBPLL_IR_CAL_DELAY 0
|
||||
#define I2C_BBPLL_IR_CAL_DELAY_MSB 3
|
||||
#define I2C_BBPLL_IR_CAL_DELAY_LSB 0
|
||||
|
||||
#define I2C_BBPLL_IR_CAL_CK_DIV 0
|
||||
#define I2C_BBPLL_IR_CAL_CK_DIV_MSB 7
|
||||
#define I2C_BBPLL_IR_CAL_CK_DIV_LSB 4
|
||||
|
||||
#define I2C_BBPLL_IR_CAL_EXT_CAP 1
|
||||
#define I2C_BBPLL_IR_CAL_EXT_CAP_MSB 3
|
||||
#define I2C_BBPLL_IR_CAL_EXT_CAP_LSB 0
|
||||
|
||||
#define I2C_BBPLL_IR_CAL_ENX_CAP 1
|
||||
#define I2C_BBPLL_IR_CAL_ENX_CAP_MSB 4
|
||||
#define I2C_BBPLL_IR_CAL_ENX_CAP_LSB 4
|
||||
|
||||
#define I2C_BBPLL_IR_CAL_RSTB 1
|
||||
#define I2C_BBPLL_IR_CAL_RSTB_MSB 5
|
||||
#define I2C_BBPLL_IR_CAL_RSTB_LSB 5
|
||||
|
||||
#define I2C_BBPLL_IR_CAL_START 1
|
||||
#define I2C_BBPLL_IR_CAL_START_MSB 6
|
||||
#define I2C_BBPLL_IR_CAL_START_LSB 6
|
||||
|
||||
#define I2C_BBPLL_IR_CAL_UNSTOP 1
|
||||
#define I2C_BBPLL_IR_CAL_UNSTOP_MSB 7
|
||||
#define I2C_BBPLL_IR_CAL_UNSTOP_LSB 7
|
||||
|
||||
#define I2C_BBPLL_OC_REF_DIV 2
|
||||
#define I2C_BBPLL_OC_REF_DIV_MSB 3
|
||||
#define I2C_BBPLL_OC_REF_DIV_LSB 0
|
||||
|
||||
#define I2C_BBPLL_OC_DIV_10_8 2
|
||||
#define I2C_BBPLL_OC_DIV_10_8_MSB 6
|
||||
#define I2C_BBPLL_OC_DIV_10_8_LSB 4
|
||||
|
||||
#define I2C_BBPLL_OC_LREF 2
|
||||
#define I2C_BBPLL_OC_LREF_MSB 7
|
||||
#define I2C_BBPLL_OC_LREF_LSB 7
|
||||
|
||||
#define I2C_BBPLL_OC_DIV_7_0 3
|
||||
#define I2C_BBPLL_OC_DIV_7_0_MSB 7
|
||||
#define I2C_BBPLL_OC_DIV_7_0_LSB 0
|
||||
|
||||
#define I2C_BBPLL_OC_ENB_FCAL 4
|
||||
#define I2C_BBPLL_OC_ENB_FCAL_MSB 0
|
||||
#define I2C_BBPLL_OC_ENB_FCAL_LSB 0
|
||||
|
||||
#define I2C_BBPLL_OC_DCHGP 4
|
||||
#define I2C_BBPLL_OC_DCHGP_MSB 3
|
||||
#define I2C_BBPLL_OC_DCHGP_LSB 1
|
||||
|
||||
#define I2C_BBPLL_OC_DHREF_SEL 4
|
||||
#define I2C_BBPLL_OC_DHREF_SEL_MSB 5
|
||||
#define I2C_BBPLL_OC_DHREF_SEL_LSB 4
|
||||
|
||||
#define I2C_BBPLL_OC_DLREF_SEL 4
|
||||
#define I2C_BBPLL_OC_DLREF_SEL_MSB 7
|
||||
#define I2C_BBPLL_OC_DLREF_SEL_LSB 6
|
||||
|
||||
#define I2C_BBPLL_OC_DCUR 5
|
||||
#define I2C_BBPLL_OC_DCUR_MSB 2
|
||||
#define I2C_BBPLL_OC_DCUR_LSB 0
|
||||
|
||||
#define I2C_BBPLL_OC_BST_DIV 5
|
||||
#define I2C_BBPLL_OC_BST_DIV_MSB 3
|
||||
#define I2C_BBPLL_OC_BST_DIV_LSB 3
|
||||
|
||||
#define I2C_BBPLL_OC_BST_E2C 5
|
||||
#define I2C_BBPLL_OC_BST_E2C_MSB 4
|
||||
#define I2C_BBPLL_OC_BST_E2C_LSB 4
|
||||
|
||||
#define I2C_BBPLL_OC_TSCHGP 5
|
||||
#define I2C_BBPLL_OC_TSCHGP_MSB 5
|
||||
#define I2C_BBPLL_OC_TSCHGP_LSB 5
|
||||
|
||||
#define I2C_BBPLL_OC_BW 5
|
||||
#define I2C_BBPLL_OC_BW_MSB 7
|
||||
#define I2C_BBPLL_OC_BW_LSB 6
|
||||
|
||||
#define I2C_BBPLL_OR_LOCK1 6
|
||||
#define I2C_BBPLL_OR_LOCK1_MSB 0
|
||||
#define I2C_BBPLL_OR_LOCK1_LSB 0
|
||||
|
||||
#define I2C_BBPLL_OR_LOCK2 6
|
||||
#define I2C_BBPLL_OR_LOCK2_MSB 1
|
||||
#define I2C_BBPLL_OR_LOCK2_LSB 1
|
||||
|
||||
#define I2C_BBPLL_OR_CAL_CAP 7
|
||||
#define I2C_BBPLL_OR_CAL_CAP_MSB 3
|
||||
#define I2C_BBPLL_OR_CAL_CAP_LSB 0
|
||||
|
||||
#define I2C_BBPLL_OR_CAL_UDF 7
|
||||
#define I2C_BBPLL_OR_CAL_UDF_MSB 4
|
||||
#define I2C_BBPLL_OR_CAL_UDF_LSB 4
|
||||
|
||||
#define I2C_BBPLL_OR_CAL_OVF 7
|
||||
#define I2C_BBPLL_OR_CAL_OVF_MSB 5
|
||||
#define I2C_BBPLL_OR_CAL_OVF_LSB 5
|
||||
|
||||
#define I2C_BBPLL_OR_CAL_END 7
|
||||
#define I2C_BBPLL_OR_CAL_END_MSB 6
|
||||
#define I2C_BBPLL_OR_CAL_END_LSB 6
|
||||
|
||||
#define I2C_BBPLL_BBADC_DELAY1 8
|
||||
#define I2C_BBPLL_BBADC_DELAY1_MSB 1
|
||||
#define I2C_BBPLL_BBADC_DELAY1_LSB 0
|
||||
|
||||
#define I2C_BBPLL_BBADC_DELAY2 8
|
||||
#define I2C_BBPLL_BBADC_DELAY2_MSB 3
|
||||
#define I2C_BBPLL_BBADC_DELAY2_LSB 2
|
||||
|
||||
#define I2C_BBPLL_BBADC_DELAY3 8
|
||||
#define I2C_BBPLL_BBADC_DELAY3_MSB 5
|
||||
#define I2C_BBPLL_BBADC_DELAY3_LSB 4
|
||||
|
||||
#define I2C_BBPLL_BBADC_DELAY4 8
|
||||
#define I2C_BBPLL_BBADC_DELAY4_MSB 7
|
||||
#define I2C_BBPLL_BBADC_DELAY4_LSB 6
|
||||
|
||||
#define I2C_BBPLL_BBADC_DELAY5 9
|
||||
#define I2C_BBPLL_BBADC_DELAY5_MSB 1
|
||||
#define I2C_BBPLL_BBADC_DELAY5_LSB 0
|
||||
|
||||
#define I2C_BBPLL_BBADC_DELAY6 9
|
||||
#define I2C_BBPLL_BBADC_DELAY6_MSB 3
|
||||
#define I2C_BBPLL_BBADC_DELAY6_LSB 2
|
||||
|
||||
#define I2C_BBPLL_BBADC_DSMP 9
|
||||
#define I2C_BBPLL_BBADC_DSMP_MSB 7
|
||||
#define I2C_BBPLL_BBADC_DSMP_LSB 4
|
||||
|
||||
#define I2C_BBPLL_DTEST 10
|
||||
#define I2C_BBPLL_DTEST_MSB 1
|
||||
#define I2C_BBPLL_DTEST_LSB 0
|
||||
|
||||
#define I2C_BBPLL_ENT_ADC 10
|
||||
#define I2C_BBPLL_ENT_ADC_MSB 3
|
||||
#define I2C_BBPLL_ENT_ADC_LSB 2
|
||||
|
||||
#define I2C_BBPLL_BBADC_DIV 10
|
||||
#define I2C_BBPLL_BBADC_DIV_MSB 5
|
||||
#define I2C_BBPLL_BBADC_DIV_LSB 4
|
||||
|
||||
#define I2C_BBPLL_ENT_PLL 10
|
||||
#define I2C_BBPLL_ENT_PLL_MSB 6
|
||||
#define I2C_BBPLL_ENT_PLL_LSB 6
|
||||
|
||||
#define I2C_BBPLL_OC_ENB_VCON 10
|
||||
#define I2C_BBPLL_OC_ENB_VCON_MSB 7
|
||||
#define I2C_BBPLL_OC_ENB_VCON_LSB 7
|
||||
|
||||
#define I2C_BBPLL_DIV_DAC 11
|
||||
#define I2C_BBPLL_DIV_DAC_MSB 0
|
||||
#define I2C_BBPLL_DIV_DAC_LSB 0
|
||||
|
||||
#define I2C_BBPLL_DIV_CPU 11
|
||||
#define I2C_BBPLL_DIV_CPU_MSB 1
|
||||
#define I2C_BBPLL_DIV_CPU_LSB 1
|
||||
|
||||
#define I2C_BBPLL_BBADC_INPUT_SHORT 11
|
||||
#define I2C_BBPLL_BBADC_INPUT_SHORT_MSB 2
|
||||
#define I2C_BBPLL_BBADC_INPUT_SHORT_LSB 2
|
||||
|
||||
#define I2C_BBPLL_BBADC_CAL_9_8 11
|
||||
#define I2C_BBPLL_BBADC_CAL_9_8_MSB 4
|
||||
#define I2C_BBPLL_BBADC_CAL_9_8_LSB 3
|
||||
|
||||
#define I2C_BBPLL_BBADC_DCM 11
|
||||
#define I2C_BBPLL_BBADC_DCM_MSB 6
|
||||
#define I2C_BBPLL_BBADC_DCM_LSB 5
|
||||
|
||||
#define I2C_BBPLL_ENDIV5 11
|
||||
#define I2C_BBPLL_ENDIV5_MSB 7
|
||||
#define I2C_BBPLL_ENDIV5_LSB 7
|
||||
|
||||
#define I2C_BBPLL_BBADC_CAL_7_0 12
|
||||
#define I2C_BBPLL_BBADC_CAL_7_0_MSB 7
|
||||
#define I2C_BBPLL_BBADC_CAL_7_0_LSB 0
|
@ -0,0 +1,58 @@
|
||||
// Copyright 2015-2017 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.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include "regi2c_apll.h"
|
||||
#include "regi2c_bbpll.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Analog function control register */
|
||||
#define ANA_CONFIG_REG 0x6000E044
|
||||
#define ANA_CONFIG_S (8)
|
||||
#define ANA_CONFIG_M (0x3FF)
|
||||
/* Clear to enable APLL */
|
||||
#define I2C_APLL_M (BIT(14))
|
||||
/* Clear to enable BBPLL */
|
||||
#define I2C_BBPLL_M (BIT(17))
|
||||
|
||||
/* ROM functions which read/write internal control bus */
|
||||
uint8_t rom_i2c_readReg(uint8_t block, uint8_t host_id, uint8_t reg_add);
|
||||
uint8_t rom_i2c_readReg_Mask(uint8_t block, uint8_t host_id, uint8_t reg_add, uint8_t msb, uint8_t lsb);
|
||||
void rom_i2c_writeReg(uint8_t block, uint8_t host_id, uint8_t reg_add, uint8_t data);
|
||||
void rom_i2c_writeReg_Mask(uint8_t block, uint8_t host_id, uint8_t reg_add, uint8_t msb, uint8_t lsb, uint8_t data);
|
||||
|
||||
/* Convenience macros for the above functions, these use register definitions
|
||||
* from regi2c_apll.h/regi2c_bbpll.h header files.
|
||||
*/
|
||||
#define REGI2C_WRITE_MASK(block, reg_add, indata) \
|
||||
rom_i2c_writeReg_Mask(block, block##_HOSTID, reg_add, reg_add##_MSB, reg_add##_LSB, indata)
|
||||
|
||||
#define REGI2C_READ_MASK(block, reg_add) \
|
||||
rom_i2c_readReg_Mask(block, block##_HOSTID, reg_add, reg_add##_MSB, reg_add##_LSB)
|
||||
|
||||
#define REGI2C_WRITE(block, reg_add, indata) \
|
||||
rom_i2c_writeReg(block, block##_HOSTID, reg_add, indata)
|
||||
|
||||
#define REGI2C_READ(block, reg_add) \
|
||||
rom_i2c_readReg(block, block##_HOSTID, reg_add)
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -0,0 +1,48 @@
|
||||
// Copyright 2015-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.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define MHZ (1000000)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void rtc_clk_cpu_freq_to_xtal(int freq, int div);
|
||||
|
||||
/* Values of RTC_XTAL_FREQ_REG and RTC_APB_FREQ_REG are stored as two copies in
|
||||
* lower and upper 16-bit halves. These are the routines to work with such a
|
||||
* representation.
|
||||
*/
|
||||
static inline bool clk_val_is_valid(uint32_t val) {
|
||||
return (val & 0xffff) == ((val >> 16) & 0xffff) &&
|
||||
val != 0 &&
|
||||
val != UINT32_MAX;
|
||||
}
|
||||
|
||||
static inline uint32_t reg_val_to_clk_val(uint32_t val) {
|
||||
return val & UINT16_MAX;
|
||||
}
|
||||
|
||||
static inline uint32_t clk_val_to_reg_val(uint32_t val) {
|
||||
return (val & UINT16_MAX) | ((val & UINT16_MAX) << 16);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
Reference in New Issue
Block a user