circuitpython/ports/espressif/mphalport.c

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

75 lines
3.2 KiB
C
Raw Permalink Normal View History

/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2015 Glenn Ruben Bakke
* Copyright (c) 2018 Artur Pacholec
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "py/mphal.h"
#include "supervisor/cpu.h"
2021-09-25 14:30:00 -04:00
2022-06-26 17:45:35 -04:00
#if defined(CONFIG_IDF_TARGET_ESP32)
#include "components/esp_rom/include/esp32/rom/ets_sys.h"
#elif defined(CONFIG_IDF_TARGET_ESP32C3)
2021-09-25 14:30:00 -04:00
#include "components/esp_rom/include/esp32c3/rom/ets_sys.h"
2023-09-19 19:27:00 -04:00
#elif defined(CONFIG_IDF_TARGET_ESP32C6)
#include "components/esp_rom/include/esp32c6/rom/ets_sys.h"
#elif defined(CONFIG_IDF_TARGET_ESP32H2)
#include "components/esp_rom/include/esp32h2/rom/ets_sys.h"
#elif defined(CONFIG_IDF_TARGET_ESP32S2)
2020-09-28 18:59:29 -04:00
#include "components/esp_rom/include/esp32s2/rom/ets_sys.h"
#elif defined(CONFIG_IDF_TARGET_ESP32S3)
#include "components/esp_rom/include/esp32s3/rom/ets_sys.h"
2023-09-19 19:27:00 -04:00
#else
#error Unknown CONFIG_IDF_TARGET_xxx
2021-09-25 14:30:00 -04:00
#endif
void mp_hal_delay_us(mp_uint_t delay) {
ets_delay_us(delay);
}
2021-09-25 14:30:00 -04:00
// This is provided by the esp-idf/components/xtensa/esp32s2/libhal.a binary blob.
2023-09-19 19:27:00 -04:00
#ifndef CONFIG_IDF_TARGET_ARCH_RISCV
extern void xthal_window_spill(void);
2021-09-25 14:30:00 -04:00
#endif
mp_uint_t cpu_get_regs_and_sp(mp_uint_t *regs) {
// xtensa has more registers than an instruction can address. The 16 that
// can be addressed are called the "window". When a function is called or
// returns the window rotates. This allows for more efficient function calls
// because ram doesn't need to be used. It's only used if the window wraps
// around onto itself. At that point values are "spilled" to empty spots in
// the stack that were set aside. When the window rotates back around (on
// function return), the values are restored into the register from ram.
// So, in order to read the values in the stack scan we must make sure all
// of the register values we care about have been spilled to RAM. Luckily,
// there is a HAL call to do it. There is a bit of a race condition here
// because the register value could change after it's been restored but that
// is unlikely to happen with a heap pointer while we do a GC.
2023-09-19 19:27:00 -04:00
#ifndef CONFIG_IDF_TARGET_ARCH_RISCV
xthal_window_spill();
2021-09-25 14:30:00 -04:00
#endif
2021-03-15 09:57:36 -04:00
return (mp_uint_t)__builtin_frame_address(0);
}