Skip to content

Commit

Permalink
Merge pull request #6902 from MicroDev1/coproc
Browse files Browse the repository at this point in the history
Add `coproc` module
  • Loading branch information
microdev1 authored Oct 20, 2022
2 parents 7015b73 + 5232e3f commit b5b6498
Show file tree
Hide file tree
Showing 19 changed files with 815 additions and 12 deletions.
17 changes: 13 additions & 4 deletions locale/circuitpython.pot
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,8 @@ msgstr ""
msgid "Array must contain halfwords (type 'H')"
msgstr ""

#: shared-bindings/alarm/SleepMemory.c shared-bindings/nvm/ByteArray.c
#: shared-bindings/alarm/SleepMemory.c shared-bindings/coproc/CoprocMemory.c
#: shared-bindings/nvm/ByteArray.c
msgid "Array values should be single bytes."
msgstr ""

Expand Down Expand Up @@ -913,6 +914,7 @@ msgstr ""

#: py/enum.c shared-bindings/_bleio/__init__.c shared-bindings/aesio/aes.c
#: shared-bindings/alarm/__init__.c shared-bindings/busio/SPI.c
#: shared-bindings/coproc/Coproc.c shared-bindings/coproc/__init__.c
#: shared-bindings/microcontroller/Pin.c
#: shared-bindings/neopixel_write/__init__.c
msgid "Expected a %q"
Expand Down Expand Up @@ -1012,6 +1014,7 @@ msgstr ""
msgid "Firmware is invalid"
msgstr ""

#: ports/espressif/common-hal/coproc/__init__.c
#: ports/espressif/common-hal/dualbank/__init__.c
msgid "Firmware is too big"
msgstr ""
Expand Down Expand Up @@ -1915,7 +1918,8 @@ msgstr ""
msgid "Sleep Memory not available"
msgstr ""

#: shared-bindings/alarm/SleepMemory.c shared-bindings/nvm/ByteArray.c
#: shared-bindings/alarm/SleepMemory.c shared-bindings/coproc/CoprocMemory.c
#: shared-bindings/nvm/ByteArray.c
msgid "Slice and value different lengths."
msgstr ""

Expand Down Expand Up @@ -2159,6 +2163,10 @@ msgstr ""
msgid "Unable to start mDNS query"
msgstr ""

#: shared-bindings/coproc/CoprocMemory.c
msgid "Unable to write"
msgstr ""

#: shared-bindings/nvm/ByteArray.c
msgid "Unable to write to nvm."
msgstr ""
Expand Down Expand Up @@ -2407,7 +2415,7 @@ msgid "array has too many dimensions"
msgstr ""

#: py/objarray.c shared-bindings/alarm/SleepMemory.c
#: shared-bindings/nvm/ByteArray.c
#: shared-bindings/coproc/CoprocMemory.c shared-bindings/nvm/ByteArray.c
msgid "array/bytes required on right side"
msgstr ""

Expand Down Expand Up @@ -3682,7 +3690,8 @@ msgid "only sample_rate=16000 is supported"
msgstr ""

#: py/objarray.c py/objstr.c py/objstrunicode.c py/objtuple.c
#: shared-bindings/alarm/SleepMemory.c shared-bindings/nvm/ByteArray.c
#: shared-bindings/alarm/SleepMemory.c shared-bindings/coproc/CoprocMemory.c
#: shared-bindings/nvm/ByteArray.c
msgid "only slices with step=1 (aka None) are supported"
msgstr ""

Expand Down
2 changes: 1 addition & 1 deletion ports/espressif/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set(ENV{IDF_PATH} ${CMAKE_SOURCE_DIR}/esp-idf)

# The component list here determines what options we get in menuconfig and what the ninja file
# can build.
set(COMPONENTS esptool_py soc driver log main esp-tls mbedtls mdns esp_event esp_adc_cal esp_netif esp_wifi lwip wpa_supplicant freertos bt usb)
set(COMPONENTS esptool_py soc driver log main esp-tls mbedtls mdns esp_event esp_adc_cal esp_netif esp_wifi lwip ulp wpa_supplicant freertos bt usb)

if("${CIRCUITPY_ESP32_CAMERA}")
message("Including esp32-camera")
Expand Down
5 changes: 5 additions & 0 deletions ports/espressif/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ INC += \
-isystem esp-idf/components/soc/include \
-isystem esp-idf/components/soc/$(IDF_TARGET)/include \
-isystem esp-idf/components/spi_flash/include \
-isystem esp-idf/components/ulp/include \
-isystem esp-idf/components/ulp/ulp_riscv/include \
-isystem esp-idf/components/$(IDF_TARGET_ARCH)/include \
-isystem esp-idf/components/$(IDF_TARGET_ARCH)/$(IDF_TARGET)/include

Expand Down Expand Up @@ -399,6 +401,9 @@ ifneq ($(CIRCUITPY_BLEIO),0)
BINARY_BLOBS += esp-idf/components/esp_phy/lib/$(IDF_TARGET)/libbtbb.a \
esp-idf/components/bt/controller/lib_esp32c3_family/$(IDF_TARGET)/libbtdm_app.a
endif
ifneq ($(CIRCUITPY_COPROC),0)
ESP_IDF_COMPONENTS_LINK += ulp
endif

ESP_IDF_COMPONENTS_EXPANDED = $(foreach component, $(ESP_IDF_COMPONENTS_LINK), $(BUILD)/esp-idf/esp-idf/$(component)/lib$(component).a)

Expand Down
52 changes: 52 additions & 0 deletions ports/espressif/common-hal/coproc/Coproc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* This file is part of the Micro Python project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2022 microDev
*
* 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 "shared-bindings/coproc/Coproc.h"
#include "shared-bindings/coproc/CoprocMemory.h"

void common_hal_coproc_coproc_construct(coproc_coproc_obj_t *self,
const uint8_t *buf, const size_t buf_len, coproc_memory_obj_t *coproc_memory) {
// set CoprocMemory object
self->coproc_memory = coproc_memory;

// load buffer
self->buf_len = buf_len;
self->buf = (uint8_t *)m_malloc(self->buf_len, false);
memcpy(self->buf, buf, self->buf_len);
}

bool common_hal_coproc_coproc_deinited(coproc_coproc_obj_t *self) {
return self->buf == NULL;
}

void common_hal_coproc_coproc_deinit(coproc_coproc_obj_t *self) {
if (common_hal_coproc_coproc_deinited(self)) {
return;
}
m_free(self->buf);
self->buf = NULL;
self->coproc_memory = NULL;
}
40 changes: 40 additions & 0 deletions ports/espressif/common-hal/coproc/Coproc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* This file is part of the Micro Python project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2022 microDev
*
* 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.
*/

#ifndef MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_COPROC_COPROC_H
#define MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_COPROC_COPROC_H

#include "py/obj.h"
#include "common-hal/coproc/CoprocMemory.h"

typedef struct {
mp_obj_base_t base;
uint8_t *buf;
size_t buf_len;
coproc_memory_obj_t *coproc_memory;
} coproc_coproc_obj_t;

#endif // MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_COPROC_COPROC_H
52 changes: 52 additions & 0 deletions ports/espressif/common-hal/coproc/CoprocMemory.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* This file is part of the Micro Python project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2022 microDev
*
* 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 "shared-bindings/coproc/CoprocMemory.h"

uint32_t common_hal_coproc_memory_get_length(coproc_memory_obj_t *self) {
return self->len;
}

bool common_hal_coproc_memory_set_bytes(coproc_memory_obj_t *self,
uint32_t start_index, const uint8_t *values, uint32_t len) {

if (start_index + len > self->len) {
return false;
}

memcpy((uint8_t *)(self->address + start_index), values, len);
return true;
}

void common_hal_coproc_memory_get_bytes(coproc_memory_obj_t *self,
uint32_t start_index, uint8_t *values, uint32_t len) {

if (start_index + len > self->len) {
return;
}

memcpy(values, (uint8_t *)(self->address + start_index), len);
}
38 changes: 38 additions & 0 deletions ports/espressif/common-hal/coproc/CoprocMemory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* This file is part of the Micro Python project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2022 microDev
*
* 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.
*/

#ifndef MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_COPROC_COPROCMEMORY_H
#define MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_COPROC_COPROCMEMORY_H

#include "py/obj.h"

typedef struct {
mp_obj_base_t base;
uint32_t address;
uint16_t len;
} coproc_memory_obj_t;

#endif // MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_COPROC_COPROCMEMORY_H
69 changes: 69 additions & 0 deletions ports/espressif/common-hal/coproc/__init__.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* This file is part of the Micro Python project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2022 microDev
*
* 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 "shared-bindings/coproc/__init__.h"

#include "py/runtime.h"

#if defined(CONFIG_IDF_TARGET_ESP32S2)
#include "esp32s2/ulp.h"
#include "esp32s2/ulp_riscv.h"
#elif defined(CONFIG_IDF_TARGET_ESP32S3)
#include "esp32s3/ulp.h"
#include "esp32s3/ulp_riscv.h"
#endif

// To-do idf v5.0: remove following include
#include "soc/rtc_cntl_reg.h"

void common_hal_coproc_run(coproc_coproc_obj_t *self) {
if (ulp_riscv_load_binary(self->buf, self->buf_len) != ESP_OK) {
mp_raise_RuntimeError(translate("Firmware is too big"));
}
m_free(self->buf);
self->buf = (uint8_t *)RTC_SLOW_MEM;
ulp_riscv_run();
}

void common_hal_coproc_halt(coproc_coproc_obj_t *self) {
self->buf = (uint8_t *)m_malloc(self->buf_len, false);
memcpy(self->buf, (uint8_t *)RTC_SLOW_MEM, self->buf_len);

// To-do idf v5.0: use following functions
// ulp_riscv_timer_stop();
// ulp_riscv_halt();

// stop the ulp timer
CLEAR_PERI_REG_MASK(RTC_CNTL_ULP_CP_TIMER_REG, RTC_CNTL_ULP_CP_SLP_TIMER_EN);
// suspends the ulp operation
SET_PERI_REG_MASK(RTC_CNTL_COCPU_CTRL_REG, RTC_CNTL_COCPU_DONE);
// Resets the processor
SET_PERI_REG_MASK(RTC_CNTL_COCPU_CTRL_REG, RTC_CNTL_COCPU_SHUT_RESET_EN);
}

mp_obj_t common_hal_coproc_memory(coproc_coproc_obj_t *self) {
return (self->coproc_memory) ? MP_OBJ_FROM_PTR(self->coproc_memory) : mp_const_none;
}
7 changes: 4 additions & 3 deletions ports/espressif/esp-idf-config/sdkconfig-esp32s2.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ CONFIG_ESP32S2_DATA_CACHE_LINE_32B=y

# CONFIG_ESP32S2_TRAX is not set
CONFIG_ESP32S2_TRACEMEM_RESERVE_DRAM=0x0
# CONFIG_ESP32S2_ULP_COPROC_ENABLED is not set
CONFIG_ESP32S2_ULP_COPROC_RESERVE_MEM=0
CONFIG_ESP32S2_ULP_COPROC_ENABLED=y
CONFIG_ESP32S2_ULP_COPROC_RESERVE_MEM=4096
CONFIG_ESP32S2_ULP_COPROC_RISCV=y
CONFIG_ESP32S2_DEBUG_OCDAWARE=y
# CONFIG_ESP32S2_DEBUG_STUBS_ENABLE is not set
CONFIG_ESP32S2_BROWNOUT_DET=y
Expand All @@ -65,7 +66,7 @@ CONFIG_ESP32S2_RTC_CLK_SRC_INT_RC=y
CONFIG_ESP32S2_RTC_CLK_CAL_CYCLES=576
# CONFIG_ESP32S2_NO_BLOBS is not set
# CONFIG_ESP32S2_KEEP_USB_ALIVE is not set
# CONFIG_ESP32S2_RTCDATA_IN_FAST_MEM is not set
CONFIG_ESP32S2_RTCDATA_IN_FAST_MEM=y
# CONFIG_ESP32S2_USE_FIXED_STATIC_RAM_SIZE is not set
#
# MAC Config
Expand Down
8 changes: 4 additions & 4 deletions ports/espressif/esp-idf-config/sdkconfig-esp32s3.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ CONFIG_ESP32S3_DATA_CACHE_LINE_SIZE=32

# CONFIG_ESP32S3_TRAX is not set
CONFIG_ESP32S3_TRACEMEM_RESERVE_DRAM=0x0
# CONFIG_ESP32S3_ULP_COPROC_ENABLED is not set
CONFIG_ESP32S3_ULP_COPROC_RESERVE_MEM=0
CONFIG_ESP32S3_ULP_COPROC_ENABLED=y
CONFIG_ESP32S3_ULP_COPROC_RESERVE_MEM=4096
CONFIG_ESP32S3_ULP_COPROC_RISCV=y
CONFIG_ESP32S3_BROWNOUT_DET=y
CONFIG_ESP32S3_BROWNOUT_DET_LVL_SEL_7=y
# CONFIG_ESP32S3_BROWNOUT_DET_LVL_SEL_6 is not set
Expand All @@ -88,7 +89,7 @@ CONFIG_ESP32S3_RTC_CLK_SRC_INT_RC=y
# CONFIG_ESP32S3_RTC_CLK_SRC_INT_8MD256 is not set
CONFIG_ESP32S3_RTC_CLK_CAL_CYCLES=1024
CONFIG_ESP32S3_DEEP_SLEEP_WAKEUP_DELAY=2000
# CONFIG_ESP32S3_RTCDATA_IN_FAST_MEM is not set
CONFIG_ESP32S3_RTCDATA_IN_FAST_MEM=y
# CONFIG_ESP32S3_USE_FIXED_STATIC_RAM_SIZE is not set
# end of ESP32S3-Specific

Expand Down Expand Up @@ -218,4 +219,3 @@ CONFIG_CAMERA_DMA_BUFFER_SIZE_MAX=32768
# CONFIG_CAMERA_CONVERTER_ENABLED is not set
# end of Camera configuration
# end of Component config

Loading

0 comments on commit b5b6498

Please sign in to comment.